From 9528c0c69dba57117f38f84f576af2c81a3b435b Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 12 Dec 2022 18:06:53 +0100 Subject: multiplayer --- src/protocol.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/protocol.c') diff --git a/src/protocol.c b/src/protocol.c index 256e85d..f833d3a 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -13,10 +13,42 @@ network_message create_protocol_get_id_down(u32 id) { return network_create_message(network_buffer, sizeof(protocol_get_id_downstream), MAX_NETWORK_BUFFER_SIZE); } +network_message create_protocol_user_list() { + protocol_user_list* buf = (protocol_user_list*)network_buffer; + buf->type = MESSAGE_USER_LIST; + memcpy(buf->players, players, sizeof(players)); + return network_create_message(network_buffer, sizeof(protocol_user_list), MAX_NETWORK_BUFFER_SIZE); +} + +network_message create_protocol_zombie_list() { + protocol_zombie_list* buf = (protocol_zombie_list*)network_buffer; + buf->type = MESSAGE_ZOMBIE_LIST; + memcpy(buf->zombies, zombies, sizeof(zombies)); + return network_create_message(network_buffer, sizeof(protocol_zombie_list), MAX_NETWORK_BUFFER_SIZE); +} + +network_message create_protocol_user_moved(protocol_move_type move, u32 id) { + protocol_move* buf = (protocol_move*)network_buffer; + buf->type = MESSAGE_USER_MOVED; + buf->move = move; + buf->id = id; + return network_create_message(network_buffer, sizeof(protocol_move), MAX_NETWORK_BUFFER_SIZE); +} + +network_message create_protocol_user_look(u32 id, float gunx, float guny) { + protocol_user_look* buf = (protocol_user_look*)network_buffer; + buf->type = MESSAGE_USER_LOOK; + buf->id = id; + buf->gunx = gunx; + buf->guny = guny; + return network_create_message(network_buffer, sizeof(protocol_user_look), 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); + protocol_generic_message* allocated_buf = mem_alloc(sizeof(protocol_generic_message)); + allocated_buf->client = client; + allocated_buf->message = mem_alloc(length); + memcpy(allocated_buf->message, buffer + 4, length-4); array_push(&messages_received_on_server, (u8*)&allocated_buf); } -- cgit v1.2.3-70-g09d2