-
Notifications
You must be signed in to change notification settings - Fork 4
/
chatroom_utils.h
70 lines (55 loc) · 1.14 KB
/
chatroom_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
*
* Chatroom - a simple linux commandline client/server C program for group chat.
* Author: Andrew Herriot
* License: Public Domain
*
*/
#ifndef CHATROOM_UTILS_H_
#define CHATROOM_UTILS_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
//color codes
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define RESET "\033[0m"
//Enum of different messages possible.
typedef enum
{
CONNECT,
DISCONNECT,
GET_USERS,
SET_USERNAME,
PUBLIC_MESSAGE,
PRIVATE_MESSAGE,
TOO_FULL,
USERNAME_ERROR,
SUCCESS,
ERROR
} message_type;
//message structure
typedef struct
{
message_type type;
char username[21];
char data[256];
} message;
//structure to hold client connection information
typedef struct connection_info
{
int socket;
struct sockaddr_in address;
char username[20];
} connection_info;
// Removes the trailing newline character from a string.
void trim_newline(char *text);
// discard any remaining data on stdin buffer.
void clear_stdin_buffer();
#endif