diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2024-06-22 01:00:16 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2024-06-22 01:00:16 +0300 |
commit | b9251a3c950e75f0d69d5799da42d06dd3e41a63 (patch) | |
tree | ca957ec1baf547279138a93814337402db879743 /include | |
parent | b0af12b287a7c7e3cc5ba39869835126e700f792 (diff) |
Я ночью плачу и дрочу, я лишь с тобою быть хочу...
Diffstat (limited to 'include')
-rw-r--r-- | include/kv.h | 9 | ||||
-rw-r--r-- | include/packet.c | 12 | ||||
-rw-r--r-- | include/packet.h | 43 |
3 files changed, 64 insertions, 0 deletions
diff --git a/include/kv.h b/include/kv.h new file mode 100644 index 0000000..b5f9842 --- /dev/null +++ b/include/kv.h @@ -0,0 +1,9 @@ +#ifndef JUSTANOTHERCATGIRL_KV_H +#define JUSTANOTHERCATGIRL_KV_H + +#include "packet.h" + +#define KV_SERVER_ADDRESS_STRING "95.164.2.199" +#define KV_SERVER_ADDRESS_INT ((95 << 24) | (164 << 16) | (2 << 8) | (199 << 0)) + +#endif // JUSTANOTHERCATGIRL_KV_H diff --git a/include/packet.c b/include/packet.c new file mode 100644 index 0000000..db20a12 --- /dev/null +++ b/include/packet.c @@ -0,0 +1,12 @@ +#include "packet.h" + +unsigned int system_packet_checksum(struct kv_system_packet *packet) { + return (packet->user_id << 8) ^ + (packet->operation_id | (177013 << 10)); +} + +int __user_cmp(const void* a, const void* b) { + struct user *_a = (struct user*)a, + *_b = (struct user*)b; + return _a->id - _b->id; +} diff --git a/include/packet.h b/include/packet.h new file mode 100644 index 0000000..224469e --- /dev/null +++ b/include/packet.h @@ -0,0 +1,43 @@ +#ifndef KV_PACKET_H +#define KV_PACKET_H + +#define KV_PACKET_SIZE 512 + +#ifdef DEBUG +#define DEBUGF(fmt, ...) fprintf(stderr, "DEBUG: %s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__) +#else +#define DEBUGF(fmt, ...) \ + do { } while (0) +#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; +}; +struct kv_packet { + int id; + unsigned char data[KV_PACKET_SIZE - sizeof(unsigned int)]; +}; +struct kv_system_packet { + int operation_id; + int user_id; + unsigned int checksum; + unsigned char sentinel[KV_PACKET_SIZE - 4 * sizeof(int) - sizeof(short)]; +}; + +unsigned int system_packet_checksum(struct kv_system_packet *packet); +int __user_cmp(const void* a, const void* b); + +#endif // KV_PACKET_H + |