diff --git a/protocol b/protocol index 371e9c6..8d435c9 100644 --- a/protocol +++ b/protocol @@ -1,22 +1,19 @@ PROTOCOL -this is almost a carbon copy of every other tcp/ip protocol i write -don't care enough to make it fancy - all numbers are packed unless stated otherwise packed values are msb +strings and blobs are prefixed with a packed ushort length + byte n is b.n region n is r.n --- -byte the zero: packet id -byte the one: region count -for 0 <= n < b.1 - byte the byte after the previous byte byte: - region length < 128: one byte - region length >= 128: two bytes, highest bit on msb always 1 +byte the zero: 0xDE +byte the one: 0xAD +byte the two: packet id +byte the 3-6: total body length - uint byte the bytes after the header octet bytes bytes: raw body data shoved next to each other with no separation diff --git a/src/packet.c b/src/packet.c index e69de29..7eb5324 100644 --- a/src/packet.c +++ b/src/packet.c @@ -0,0 +1,2 @@ +#include "packet.h" + diff --git a/src/packet.h b/src/packet.h index e69de29..97b5d2a 100644 --- a/src/packet.h +++ b/src/packet.h @@ -0,0 +1,23 @@ +#ifndef PACKET_H +#define PACKET_H + +#include +#include +#include "list.h" + +#define PCK_ID_REGISTER 0 +#define PCK_ID_LOGIN 1 +#define PCK_ID_CHANGE_CTX 2 + +typedef struct packet_t packet_t; +struct packet_t { + uint8_t id; + uint32_t length; + uint8_t **regions; + const uint8_t *region_lengths; + uint8_t region_count; +}; + + + +#endif \ No newline at end of file diff --git a/src/queue.c b/src/queue.c index d4f4543..5b264f5 100644 --- a/src/queue.c +++ b/src/queue.c @@ -70,8 +70,7 @@ void queue_nodes_free(queue_t *queue) { queue_node_t *ptr = queue->front, *next; while(ptr != NULL) { next = ptr->next; - if(ptr->data != NULL) - free(ptr->data); + free(ptr->data); free(ptr); ptr = next; diff --git a/src/server/server.c b/src/server/server.c index 0ef4da9..b6e24f4 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -1,6 +1,7 @@ #include "server.h" void server() { + user_context_init(); server_context_start(); socket_t *sock = sock_server_init("6770"); @@ -30,6 +31,8 @@ void server() { printf("got %s\r\n", in); server_context_stop(); + user_context_free(); + sock_stop(sock); sock_free(sock); } diff --git a/src/server/user.c b/src/server/user.c index 96a07be..a39d33c 100644 --- a/src/server/user.c +++ b/src/server/user.c @@ -5,7 +5,7 @@ struct { user_t **users; } ctx; -void user_ctx_init() { +void user_context_init() { ctx.active_users = list_init(); ctx.users = (user_t**)malloc(MAX_CONNS * sizeof(user_t*)); @@ -14,13 +14,12 @@ void user_ctx_init() { ctx.users[i] = NULL; } -void user_ctx_free() { +void user_context_free() { list_free(ctx.active_users); int i; for(i = 0; i < MAX_CONNS; ++i) - if(ctx.users[i] != NULL) - free(ctx.users[i]); + free(ctx.users[i]); free(ctx.users); } \ No newline at end of file diff --git a/src/server/user.h b/src/server/user.h index 7c388ae..c1716da 100644 --- a/src/server/user.h +++ b/src/server/user.h @@ -14,12 +14,14 @@ struct user_t { pthread_mutex_t mx_out_packets; socket_t *sock; - uint16_t context_id; + uint16_t user_id, context_id; uint16_t x, y; }; -void user_ctx_init(); +void user_context_init(); -void user_ctx_free(); + + +void user_context_free(); #endif \ No newline at end of file diff --git a/src/stack.c b/src/stack.c index c7bf14d..5a1102f 100644 --- a/src/stack.c +++ b/src/stack.c @@ -54,8 +54,7 @@ void stack_nodes_free(stack_t *stack) { stack_t *ptr = stack, *next; while(ptr != NULL) { next = ptr->next; - if(ptr->data != NULL) - free(ptr->data); + free(ptr->data); free(ptr); ptr = next;