From dd68df08748b9fd6c8e849e6403459d444a8fb5f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 27 Oct 2024 14:05:51 +0100 Subject: Added protocol Use a protocol defined in `README.md` and `chatty.h` for sending messages. Another big change is the clientsArena which now stores metadata for the connection such as the author's name. Misc: - Merged arena.h and common.h into chatty.h - removed all the unused code from arena.h as it was not very useful and would not win me any time. - Added compile_flag.txt - Changed formatting - Added more log messages - Added more asserts - Added bool type via enum --- common.h | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 common.h (limited to 'common.h') diff --git a/common.h b/common.h deleted file mode 100644 index 700d741..0000000 --- a/common.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef COMMON_H -#define COMMON_H - -#include -#include -#include -#include -#include -#include -#include - -#define AUTHOR_LEN 13 -#define TIMESTAMP_LEN 9 -// port to listen on -#define PORT 9983 -// How much bytes can be sent at once over the stream -// This is also Intial size for buffer used to send and receive data, -// "initial" because the buffer is tied to an arena and can grow. -// Note: must be greater than sizeof(Message) - sizeof(Message.text) -#define STREAM_LIMIT 64 - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; - -struct Message { - u8 author[AUTHOR_LEN]; - u8 timestamp[TIMESTAMP_LEN]; - // includes null terminator - u16 text_len; - wchar_t *text; -} typedef Message; - -#define MESSAGELEN(m) (AUTHOR_LEN + TIMESTAMP_LEN + sizeof(m.text_len)*sizeof(wchar_t) + m.text_len) -#define MESSAGELENP(m) (AUTHOR_LEN + TIMESTAMP_LEN + sizeof(m->text_len) + m->text_len*(sizeof(wchar_t))) - -void message_timestamp(u8 str[TIMESTAMP_LEN]) -{ - time_t now; - struct tm *ltime; - time(&now); - ltime = localtime(&now); - strftime((char *)str, TIMESTAMP_LEN, "%H:%M:%S", ltime); -} - -#endif -- cgit v1.2.3-70-g09d2