diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-12-10 18:21:22 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-12-10 18:21:22 +0000 |
| commit | fbfd169581af5495f72af8693561dd6a221702b8 (patch) | |
| tree | d29d5537998e84cba7dd1845958e71813fb9fcb0 /src/engine | |
| parent | 2219b61920d0148e77790eb0294212c058863de9 (diff) | |
| download | zcatch-fbfd169581af5495f72af8693561dd6a221702b8.tar.gz zcatch-fbfd169581af5495f72af8693561dd6a221702b8.zip | |
crash fix that occurs when compressed snapshot spans several packets. crash fix caused but ids running out when chaning maps often
Diffstat (limited to 'src/engine')
| -rw-r--r-- | src/engine/client/client.c | 19 | ||||
| -rw-r--r-- | src/engine/protocol.h | 1 | ||||
| -rw-r--r-- | src/engine/server/server.c | 64 |
3 files changed, 58 insertions, 26 deletions
diff --git a/src/engine/client/client.c b/src/engine/client/client.c index b862e65a..b3cc57ec 100644 --- a/src/engine/client/client.c +++ b/src/engine/client/client.c @@ -645,17 +645,24 @@ static void client_process_packet(NETPACKET *packet) client_disconnect_with_reason(error); } } - else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPEMPTY) + else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSINGLE || msg == NETMSG_SNAPEMPTY) { /*dbg_msg("client/network", "got snapshot"); */ + int num_parts = 1; + int part = 0; int game_tick = msg_unpack_int(); int delta_tick = game_tick-msg_unpack_int(); int input_predtick = msg_unpack_int(); int time_left = msg_unpack_int(); - int num_parts = 1; - int part = 0; int part_size = 0; int crc = 0; + int complete_size = 0; + + if(msg == NETMSG_SNAP) + { + num_parts = msg_unpack_int(); + part = msg_unpack_int(); + } if(msg != NETMSG_SNAPEMPTY) { @@ -703,6 +710,8 @@ static void client_process_packet(NETPACKET *packet) unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE]; unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE]; int snapsize; + + complete_size = (num_parts-1) * MAX_SNAPSHOT_PACKSIZE + part_size; snapshot_part = 0; @@ -733,9 +742,9 @@ static void client_process_packet(NETPACKET *packet) deltadata = snapshot_empty_delta(); deltasize = sizeof(int)*3; - if(part_size) + if(complete_size) { - int compsize = zerobit_decompress(snapshot_incomming_data, part_size, tmpbuffer); + int compsize = zerobit_decompress(snapshot_incomming_data, complete_size, tmpbuffer); int intsize = intpack_decompress(tmpbuffer, compsize, tmpbuffer2); deltadata = tmpbuffer2; deltasize = intsize; diff --git a/src/engine/protocol.h b/src/engine/protocol.h index 6cc52726..e85ecf9f 100644 --- a/src/engine/protocol.h +++ b/src/engine/protocol.h @@ -36,6 +36,7 @@ enum NETMSG_MAP, NETMSG_SNAP, NETMSG_SNAPEMPTY, + NETMSG_SNAPSINGLE, NETMSG_SNAPSMALL, /* sent by client */ diff --git a/src/engine/server/server.c b/src/engine/server/server.c index 319ac363..962ba650 100644 --- a/src/engine/server/server.c +++ b/src/engine/server/server.c @@ -48,8 +48,8 @@ typedef struct int timeout_tick; } SNAP_ID; -static const int MAX_IDS = 8*1024; /* should be lowered */ -static SNAP_ID snap_ids[8*1024]; +static const int MAX_IDS = 16*1024; /* should be lowered */ +static SNAP_ID snap_ids[16*1024]; static int snap_first_free_id; static int snap_first_timed_id; static int snap_last_timed_id; @@ -113,6 +113,23 @@ static void snap_init_id() snap_id_inited = 1; } +static void snap_remove_first_timeout() +{ + int next_timed = snap_ids[snap_first_timed_id].next; + + /* add it to the free list */ + snap_ids[snap_first_timed_id].next = snap_first_free_id; + snap_ids[snap_first_timed_id].state = 0; + snap_first_free_id = snap_first_timed_id; + + /* remove it from the timed list */ + snap_first_timed_id = next_timed; + if(snap_first_timed_id == -1) + snap_last_timed_id = -1; + + snap_id_usage--; +} + int snap_new_id() { int id; @@ -120,21 +137,7 @@ int snap_new_id() /* process timed ids */ while(snap_first_timed_id != -1 && snap_ids[snap_first_timed_id].timeout_tick < server_tick()) - { - int next_timed = snap_ids[snap_first_timed_id].next; - - /* add it to the free list */ - snap_ids[snap_first_timed_id].next = snap_first_free_id; - snap_ids[snap_first_timed_id].state = 0; - snap_first_free_id = snap_first_timed_id; - - /* remove it from the timed list */ - snap_first_timed_id = next_timed; - if(snap_first_timed_id == -1) - snap_last_timed_id = -1; - - snap_id_usage--; - } + snap_remove_first_timeout(); id = snap_first_free_id; dbg_assert(id != -1, "id error"); @@ -145,6 +148,13 @@ int snap_new_id() return id; } +void snap_timeout_ids() +{ + /* process timed ids */ + while(snap_first_timed_id != -1) + snap_remove_first_timeout(); +} + void snap_free_id(int id) { dbg_assert(snap_ids[id].state == 1, "id is not alloced"); @@ -329,19 +339,28 @@ static void server_do_snap() const int max_size = MAX_SNAPSHOT_PACKSIZE; int numpackets = (snapshot_size+max_size-1)/max_size; int n, left; - - (void)numpackets; - + for(n = 0, left = snapshot_size; left; n++) { int chunk = left < max_size ? left : max_size; left -= chunk; - msg_pack_start_system(NETMSG_SNAP, 0); + if(numpackets == 1) + msg_pack_start_system(NETMSG_SNAPSINGLE, 0); + else + msg_pack_start_system(NETMSG_SNAP, 0); + msg_pack_int(current_tick); msg_pack_int(current_tick-delta_tick); /* compressed with */ msg_pack_int(input_predtick); msg_pack_int((timeleft*1000)/time_freq()); + + if(numpackets != 1) + { + msg_pack_int(numpackets); + msg_pack_int(n); + } + msg_pack_int(crc); msg_pack_int(chunk); msg_pack_raw(&compdata[n*max_size], chunk); @@ -648,6 +667,9 @@ static int server_load_map(const char *mapname) if(!df) return 0; + /* reinit snapshot ids */ + snap_timeout_ids(); + /* get the crc of the map */ current_map_crc = datafile_crc(buf); dbg_msg("server", "%s crc is %08x", buf, current_map_crc); |