diff options
| author | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-12 15:31:26 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@amftech.nl> | 2022-12-12 15:31:26 +0100 |
| commit | 10ae402862df4337772fe8e35f68ee8ab5bfc224 (patch) | |
| tree | 1ac5fda82a2dd01f7f5ffdc2b337947c569afc15 /src/protocol.c | |
| parent | ec3796faff12ba7bf5f775d757ac25834549903d (diff) | |
networking
Diffstat (limited to 'src/protocol.c')
| -rw-r--r-- | src/protocol.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/protocol.c b/src/protocol.c new file mode 100644 index 0000000..256e85d --- /dev/null +++ b/src/protocol.c @@ -0,0 +1,27 @@ +#include "../include/protocol.h" + +network_message create_protocol_get_id_up() { + protocol_get_id_upstream* buf = (protocol_get_id_upstream*)network_buffer; + buf->type = MESSAGE_GET_ID_UPSTREAM; + return network_create_message(network_buffer, sizeof(protocol_get_id_upstream), MAX_NETWORK_BUFFER_SIZE); +} + +network_message create_protocol_get_id_down(u32 id) { + protocol_get_id_downstream* buf = (protocol_get_id_downstream*)network_buffer; + buf->type = MESSAGE_GET_ID_DOWNSTREAM; + buf->id = id; + return network_create_message(network_buffer, sizeof(protocol_get_id_downstream), MAX_NETWORK_BUFFER_SIZE); +} + +void server_on_message_received(u8* buffer, u32 length, network_client client) { + u8* allocated_buf = mem_alloc(length + sizeof(network_client)); + memcpy(allocated_buf, &client, sizeof(network_client)); + memcpy(allocated_buf + sizeof(network_client), buffer + 4, length-4); + array_push(&messages_received_on_server, (u8*)&allocated_buf); +} + +void client_on_message_received(u8* buffer, u32 length) { + u8* allocated_buf = mem_alloc(length); + memcpy(allocated_buf, buffer+4, length-4); + array_push(&messages_received_on_client, (u8*)&allocated_buf); +} |
