From 0cd383b2c444936dc2290c850c02a0cae11187cd Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Sun, 30 Jun 2024 23:54:36 +0300 Subject: Updated C headers library --- include/packet.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'include/packet.h') diff --git a/include/packet.h b/include/packet.h index 224469e..4e73040 100644 --- a/include/packet.h +++ b/include/packet.h @@ -1,6 +1,7 @@ #ifndef KV_PACKET_H #define KV_PACKET_H + #define KV_PACKET_SIZE 512 #ifdef DEBUG @@ -11,29 +12,25 @@ #endif enum system_operation { - do_nothing = 0, - join_channel = -1, - leave_channel = -2, - acknowledgement = -4, -}; -struct user { - unsigned int ip; - unsigned short port; - int id; -}; -struct channel_handle { - int sockfd; - struct user* users; + keepalive = (int) 0x80000000, // -2^31 + join_channel, // 1 - 2^31 + leave_channel, // 2 - 2^31 + acknowledgement, // 3 - 2^31 }; + struct kv_packet { int id; unsigned char data[KV_PACKET_SIZE - sizeof(unsigned int)]; }; struct kv_system_packet { + // as in system_operation enum. int operation_id; + // could be ignored int user_id; + // calculated with system_packet_checksum function unsigned int checksum; - unsigned char sentinel[KV_PACKET_SIZE - 4 * sizeof(int) - sizeof(short)]; + + unsigned char sentinel[KV_PACKET_SIZE - 3 * sizeof(int)]; }; unsigned int system_packet_checksum(struct kv_system_packet *packet); -- cgit v1.2.3-70-g09d2