From 3544db49270f6d99c8b2126f294d38267e2899cb Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Wed, 8 Oct 2008 20:47:56 +0000 Subject: [PATCH] fixed #490 (insert the player info in the sv_setinfo message into the snapshot instead) --- datasrc/network.py | 24 +++++---- src/engine/client/ec_client.c | 8 --- src/engine/e_if_modc.h | 2 - src/game/client/clienthooks.cpp | 1 - src/game/client/gameclient.cpp | 96 +++++++++++++-------------------- src/game/client/gameclient.hpp | 1 - src/game/gamecore.hpp | 35 ++++++++++++ src/game/server/gamecontext.cpp | 37 ------------- src/game/server/gamecontext.hpp | 1 - src/game/server/hooks.cpp | 11 ---- src/game/server/player.cpp | 14 ++--- 11 files changed, 95 insertions(+), 135 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 2d71abe39..c1fc974af 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -144,6 +144,21 @@ Objects = [ NetIntAny("latency"), NetIntAny("latency_flux"), ]), + + NetObject("Client_Info", [ + # 4*6 = 24 charachters + NetIntAny("name0"), NetIntAny("name1"), NetIntAny("name2"), + NetIntAny("name3"), NetIntAny("name4"), NetIntAny("name5"), + + # 4*6 = 24 charachters + NetIntAny("skin0"), NetIntAny("skin1"), NetIntAny("skin2"), + NetIntAny("skin3"), NetIntAny("skin4"), NetIntAny("skin5"), + + NetIntRange("use_custom_color", 0, 1), + + NetIntAny("color_body"), + NetIntAny("color_feet"), + ]), ## Events @@ -192,15 +207,6 @@ Messages = [ NetString("message"), ]), - NetMessage("sv_setinfo", [ - NetIntRange("cid", 0, 'MAX_CLIENTS-1'), - NetString("name"), - NetString("skin"), - NetBool("use_custom_color"), - NetIntAny("color_body"), - NetIntAny("color_feet"), - ]), - NetMessage("sv_killmsg", [ NetIntRange("killer", 0, 'MAX_CLIENTS-1'), NetIntRange("victim", 0, 'MAX_CLIENTS-1'), diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 7e5c55ae2..ece501ab0 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -1142,14 +1142,6 @@ static void client_process_packet(NETCHUNK *packet) swap_endian(&marker, sizeof(int), sizeof(marker)/sizeof(int)); demorec_record_write("TICK", sizeof(marker), &marker); - /* build snap and possibly add some messages */ - modc_recordkeyframe(); - - /* - snapbuild_init(&builder); - mods_snap(-1); - snapshot_size = snapbuild_finish(&builder, data);*/ - /* write snapshot */ demorec_record_write("SNAP", snapsize, tmpbuffer3); } diff --git a/src/engine/e_if_modc.h b/src/engine/e_if_modc.h index 14ab9ded6..8839d5f11 100644 --- a/src/engine/e_if_modc.h +++ b/src/engine/e_if_modc.h @@ -142,6 +142,4 @@ int modc_snap_input(int *data); */ const char *modc_net_version(); - -void modc_recordkeyframe(); #endif diff --git a/src/game/client/clienthooks.cpp b/src/game/client/clienthooks.cpp index 1611b00df..88a7722a6 100644 --- a/src/game/client/clienthooks.cpp +++ b/src/game/client/clienthooks.cpp @@ -17,7 +17,6 @@ extern "C" void modc_init() { gameclient.on_init(); } extern "C" void modc_connected() { gameclient.on_connected(); } extern "C" void modc_predict() { gameclient.on_predict(); } extern "C" void modc_newsnapshot() { gameclient.on_snapshot(); } -extern "C" void modc_recordkeyframe() { gameclient.on_recordkeyframe(); } extern "C" int modc_snap_input(int *data) { return gameclient.on_snapinput(data); } extern "C" void modc_statechange(int state, int old) { gameclient.on_statechange(state, old); } extern "C" void modc_render() { gameclient.on_render(); } diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 6fc478b09..7c9a1ed62 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -424,44 +424,7 @@ void GAMECLIENT::on_message(int msgtype) for(int i = 0; i < all.num; i++) all.components[i]->on_message(msgtype, rawmsg); - // handle core messages - if(msgtype == NETMSGTYPE_SV_SETINFO) - { - NETMSG_SV_SETINFO *msg = (NETMSG_SV_SETINFO *)rawmsg; - - str_copy(clients[msg->cid].name, msg->name, 64); - str_copy(clients[msg->cid].skin_name, msg->skin, 64); - - // make sure that we don't set a special skin on the client - if(clients[msg->cid].skin_name[0] == 'x' || clients[msg->cid].skin_name[1] == '_') - str_copy(clients[msg->cid].skin_name, "default", 64); - - clients[msg->cid].color_body = msg->color_body; - clients[msg->cid].color_feet = msg->color_feet; - - clients[msg->cid].skin_info.color_body = skins->get_color(msg->color_body); - clients[msg->cid].skin_info.color_feet = skins->get_color(msg->color_feet); - clients[msg->cid].skin_info.size = 64; - - // find new skin - clients[msg->cid].skin_id = gameclient.skins->find(clients[msg->cid].skin_name); - if(clients[msg->cid].skin_id < 0) - clients[msg->cid].skin_id = 0; - - clients[msg->cid].use_custom_color = msg->use_custom_color; - - if(msg->use_custom_color) - clients[msg->cid].skin_info.texture = gameclient.skins->get(clients[msg->cid].skin_id)->color_texture; - else - { - clients[msg->cid].skin_info.texture = gameclient.skins->get(clients[msg->cid].skin_id)->org_texture; - clients[msg->cid].skin_info.color_body = vec4(1,1,1,1); - clients[msg->cid].skin_info.color_feet = vec4(1,1,1,1); - } - - clients[msg->cid].update_render_info(); - } - else if(msgtype == NETMSGTYPE_SV_READYTOENTER) + if(msgtype == NETMSGTYPE_SV_READYTOENTER) { client_entergame(); } @@ -579,7 +542,43 @@ void GAMECLIENT::on_snapshot() SNAP_ITEM item; const void *data = snap_get_item(SNAP_CURRENT, i, &item); - if(item.type == NETOBJTYPE_PLAYER_INFO) + if(item.type == NETOBJTYPE_CLIENT_INFO) + { + const NETOBJ_CLIENT_INFO *info = (const NETOBJ_CLIENT_INFO *)data; + int cid = item.id; + ints_to_str(&info->name0, 6, clients[cid].name); + ints_to_str(&info->skin0, 6, clients[cid].skin_name); + + clients[cid].use_custom_color = info->use_custom_color; + clients[cid].color_body = info->color_body; + clients[cid].color_feet = info->color_feet; + + // prepare the info + if(clients[cid].skin_name[0] == 'x' || clients[cid].skin_name[1] == '_') + str_copy(clients[cid].skin_name, "default", 64); + + clients[cid].skin_info.color_body = skins->get_color(clients[cid].color_body); + clients[cid].skin_info.color_feet = skins->get_color(clients[cid].color_feet); + clients[cid].skin_info.size = 64; + + // find new skin + clients[cid].skin_id = gameclient.skins->find(clients[cid].skin_name); + if(clients[cid].skin_id < 0) + clients[cid].skin_id = 0; + + if(clients[cid].use_custom_color) + clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->color_texture; + else + { + clients[cid].skin_info.texture = gameclient.skins->get(clients[cid].skin_id)->org_texture; + clients[cid].skin_info.color_body = vec4(1,1,1,1); + clients[cid].skin_info.color_feet = vec4(1,1,1,1); + } + + clients[cid].update_render_info(); + + } + else if(item.type == NETOBJTYPE_PLAYER_INFO) { const NETOBJ_PLAYER_INFO *info = (const NETOBJ_PLAYER_INFO *)data; @@ -808,25 +807,6 @@ void GAMECLIENT::send_kill(int client_id) client_send_msg(); } -void GAMECLIENT::on_recordkeyframe() -{ - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(!snap.player_infos[i]) - continue; - - NETMSG_SV_SETINFO msg; - msg.cid = i; - msg.name = clients[i].name; - msg.skin = clients[i].skin_name; - msg.use_custom_color = clients[i].use_custom_color; - msg.color_body = clients[i].color_body; - msg.color_feet = clients[i].color_feet; - msg.pack(MSGFLAG_NOSEND|MSGFLAG_RECORD); - client_send_msg(); - } -} - void GAMECLIENT::con_team(void *result, void *user_data) { ((GAMECLIENT*)user_data)->send_switch_team(console_arg_int(result, 0)); diff --git a/src/game/client/gameclient.hpp b/src/game/client/gameclient.hpp index b9ee325ed..d2a120992 100644 --- a/src/game/client/gameclient.hpp +++ b/src/game/client/gameclient.hpp @@ -119,7 +119,6 @@ public: void on_snapshot(); void on_predict(); int on_snapinput(int *data); - void on_recordkeyframe(); // actions // TODO: move these diff --git a/src/game/gamecore.hpp b/src/game/gamecore.hpp index 0e0c1c4af..5db5207b2 100644 --- a/src/game/gamecore.hpp +++ b/src/game/gamecore.hpp @@ -53,6 +53,41 @@ inline float get_angle(vec2 dir) return a; } +inline void str_to_ints(int *ints, int num, const char *str) +{ + int index = 0; + while(num) + { + char buf[4] = {0,0,0,0}; + for(int c = 0; c < 4 && str[index]; c++, index++) + buf[c] = str[index]; + *ints = (buf[0]<<24)|(buf[1]<<16)|(buf[2]<<8)|buf[3]; + ints++; + num--; + } + + // null terminate + ints[-1] &= 0xffffff00; +} + +inline void ints_to_str(const int *ints, int num, char *str) +{ + while(num) + { + str[0] = ((*ints)>>24)&0xff; + str[1] = ((*ints)>>16)&0xff; + str[2] = ((*ints)>>8)&0xff; + str[3] = (*ints)&0xff; + str += 4; + ints++; + num--; + } + + // null terminate + str[-1] = 0; +} + + inline vec2 calc_pos(vec2 p, vec2 v, float curvature, float speed, float t) { diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 0cdd4227c..a36a9144e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -170,29 +170,6 @@ void GAMECONTEXT::send_chat(int chatter_cid, int team, const char *text) } } - -void GAMECONTEXT::send_info(int who, int to_who, bool recordonly) -{ - NETMSG_SV_SETINFO msg; - msg.cid = who; - msg.name = server_clientname(who); - msg.skin = players[who]->skin_name; - msg.use_custom_color = players[who]->use_custom_color; - msg.color_body = players[who]->color_body; - msg.color_feet = players[who]->color_feet; - - if(recordonly) - { - msg.pack(MSGFLAG_NOSEND); - server_send_msg(to_who); - } - else - { - msg.pack(MSGFLAG_VITAL); - server_send_msg(to_who); - } -} - void GAMECONTEXT::send_emoticon(int cid, int emoticon) { NETMSG_SV_EMOTICON msg; @@ -219,8 +196,6 @@ void GAMECONTEXT::send_broadcast(const char *text, int cid) server_send_msg(cid); } - - // void GAMECONTEXT::start_vote(const char *desc, const char *command) { @@ -341,18 +316,6 @@ void GAMECONTEXT::tick() void GAMECONTEXT::snap(int client_id) { - // check if we are recording a demo - if(client_id == -1) - { - // we are recording, make sure that we set - // the info for all players all the time - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - send_info(i, -1, true); - } - } - world.snap(client_id); controller->snap(client_id); events.snap(client_id); diff --git a/src/game/server/gamecontext.hpp b/src/game/server/gamecontext.hpp index 8a1ff9188..6e833178d 100644 --- a/src/game/server/gamecontext.hpp +++ b/src/game/server/gamecontext.hpp @@ -77,7 +77,6 @@ public: void send_emoticon(int cid, int emoticon); void send_weapon_pickup(int cid, int weapon); void send_broadcast(const char *text, int cid); - void send_info(int who, int to_who, bool recordonly = false); }; diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp index b3425694b..d8e6c9bbb 100644 --- a/src/game/server/hooks.cpp +++ b/src/game/server/hooks.cpp @@ -281,15 +281,6 @@ void mods_message(int msgtype, int client_id) if(msgtype == NETMSGTYPE_CL_STARTINFO) { - // a client that connected! - - // send all info to this client - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - game.send_info(i, client_id); - } - // send tuning parameters to client send_tuning_params(client_id); @@ -306,8 +297,6 @@ void mods_message(int msgtype, int client_id) m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH); server_send_msg(client_id); } - - game.send_info(client_id, -1); } else if (msgtype == NETMSGTYPE_CL_EMOTICON) { diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 45d56388a..b2f72d0ed 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -62,6 +62,13 @@ void PLAYER::tick() void PLAYER::snap(int snaping_client) { + NETOBJ_CLIENT_INFO *client_info = (NETOBJ_CLIENT_INFO *)snap_new_item(NETOBJTYPE_CLIENT_INFO, client_id, sizeof(NETOBJ_CLIENT_INFO)); + str_to_ints(&client_info->name0, 6, server_clientname(client_id)); + str_to_ints(&client_info->skin0, 6, skin_name); + client_info->use_custom_color = use_custom_color; + client_info->color_body = color_body; + client_info->color_feet = color_feet; + NETOBJ_PLAYER_INFO *info = (NETOBJ_PLAYER_INFO *)snap_new_item(NETOBJTYPE_PLAYER_INFO, client_id, sizeof(NETOBJ_PLAYER_INFO)); info->latency = latency.min; @@ -151,13 +158,6 @@ void PLAYER::set_team(int new_team) dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team); game.controller->on_player_info_change(game.players[client_id]); - - // send all info to this client - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(game.players[i]) - game.send_info(i, -1); - } } void PLAYER::try_respawn()