From a91fecae920e1b6d9ca3dbdbf6251c11bd751d7c Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Fri, 17 Oct 2008 21:16:23 +0000 Subject: [PATCH] fixed fetching of server info and corrected some spelling errors --- src/engine/client/ec_client.c | 24 +++++++++++++++++++++ src/engine/client/ec_srvbrowse.c | 10 +++++++-- src/engine/e_if_client.h | 3 ++- src/engine/server/es_server.c | 23 ++++++++++++++++---- src/game/client/components/menus.hpp | 1 - src/game/client/components/menus_ingame.cpp | 4 ++++ src/game/server/entities/character.cpp | 6 +++--- src/game/server/entities/character.hpp | 2 +- src/game/server/player.cpp | 4 ++-- src/game/server/player.hpp | 2 +- 10 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 3a9390fc6..e6d26e37d 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -87,6 +87,7 @@ static int mapdownload_totalsize = -1; /* */ static SERVER_INFO current_server_info = {0}; +static int64 current_server_info_requesttime = -1; /* >= 0 should request, == -1 got info */ /* current time */ static int current_tick = 0; @@ -510,6 +511,7 @@ void client_connect(const char *server_address_str) dbg_msg("client", "connecting to '%s'", server_address_str); mem_zero(¤t_server_info, sizeof(current_server_info)); + current_server_info_requesttime = 0; str_copy(buf, server_address_str, sizeof(buf)); for(k = 0; buf[k]; k++) @@ -573,6 +575,12 @@ void client_disconnect() client_disconnect_with_reason(0); } + +void client_serverinfo(SERVER_INFO *serverinfo) +{ + mem_copy(serverinfo, ¤t_server_info, sizeof(current_server_info)); +} + static int client_load_data() { debug_font = gfx_load_texture("debug_font.png", IMG_AUTO, TEXLOAD_NORESAMPLE); @@ -838,6 +846,13 @@ static void client_process_packet(NETCHUNK *packet) { /* sort players */ qsort(info.players, info.num_players, sizeof(*info.players), player_score_comp); + + if(net_addr_comp(&server_address, &packet->address) == 0) + { + mem_copy(¤t_server_info, &info, sizeof(current_server_info)); + current_server_info_requesttime = -1; + } + if(packet_type == 2) client_serverbrowse_set(&packet->address, BROWSESET_TOKEN, token, &info); else @@ -1402,6 +1417,15 @@ static void client_update() if(current_predtick > current_tick && current_predtick < current_tick+50) modc_predict(); } + + /* fetch server info if we don't have it */ + if(client_state() >= CLIENTSTATE_LOADING && + current_server_info_requesttime >= 0 && + time_get() > current_server_info_requesttime) + { + client_serverbrowse_request(&server_address); + current_server_info_requesttime = time_get()+time_freq()*2; + } } /* STRESS TEST: join the server again */ diff --git a/src/engine/client/ec_srvbrowse.c b/src/engine/client/ec_srvbrowse.c index 9d2ed1957..f1dc97019 100644 --- a/src/engine/client/ec_srvbrowse.c +++ b/src/engine/client/ec_srvbrowse.c @@ -512,7 +512,7 @@ void client_serverbrowse_refresh(int type) } } -static void client_serverbrowse_request(NETADDR *addr, SERVERENTRY *entry) +static void client_serverbrowse_request_impl(NETADDR *addr, SERVERENTRY *entry) { /*unsigned char buffer[sizeof(SERVERBROWSE_GETINFO)+1];*/ NETCHUNK p; @@ -543,6 +543,12 @@ static void client_serverbrowse_request(NETADDR *addr, SERVERENTRY *entry) entry->request_time = time_get(); } +void client_serverbrowse_request(NETADDR *addr) +{ + client_serverbrowse_request_impl(addr, 0); +} + + void client_serverbrowse_update() { int64 timeout = time_freq(); @@ -611,7 +617,7 @@ void client_serverbrowse_update() break; if(entry->request_time == 0) - client_serverbrowse_request(&entry->addr, entry); + client_serverbrowse_request_impl(&entry->addr, entry); count++; entry = entry->next_req; diff --git a/src/engine/e_if_client.h b/src/engine/e_if_client.h index 7aef86e93..d1a5941e9 100644 --- a/src/engine/e_if_client.h +++ b/src/engine/e_if_client.h @@ -561,5 +561,6 @@ void client_demoplayer_setpos(float percent); void client_demoplayer_setpause(int paused); void client_demoplayer_setspeed(float speed); const char *client_user_directory(); - +void client_serverinfo(SERVER_INFO *serverinfo); +void client_serverbrowse_request(NETADDR *addr); #endif diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c index 5ff58dbef..2ef676a34 100644 --- a/src/engine/server/es_server.c +++ b/src/engine/server/es_server.c @@ -852,11 +852,19 @@ static void server_send_serverinfo(NETADDR *addr, int token) } packer_reset(&p); - packer_add_raw(&p, SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO)); - /* token */ - str_format(buf, sizeof(buf), "%d", token); - packer_add_string(&p, buf, 6); + if(token >= 0) + { + /* new token based format */ + packer_add_raw(&p, SERVERBROWSE_INFO, sizeof(SERVERBROWSE_INFO)); + str_format(buf, sizeof(buf), "%d", token); + packer_add_string(&p, buf, 6); + } + else + { + /* old format */ + packer_add_raw(&p, SERVERBROWSE_OLD_INFO, sizeof(SERVERBROWSE_OLD_INFO)); + } packer_add_string(&p, mods_version(), 32); packer_add_string(&p, config.sv_name, 64); @@ -921,6 +929,13 @@ static void server_pump_network() { server_send_serverinfo(&packet.address, ((unsigned char *)packet.data)[sizeof(SERVERBROWSE_GETINFO)]); } + + + if(packet.data_size == sizeof(SERVERBROWSE_OLD_GETINFO) && + memcmp(packet.data, SERVERBROWSE_OLD_GETINFO, sizeof(SERVERBROWSE_OLD_GETINFO)) == 0) + { + server_send_serverinfo(&packet.address, -1); + } } } else diff --git a/src/game/client/components/menus.hpp b/src/game/client/components/menus.hpp index 51090b937..35864a1f7 100644 --- a/src/game/client/components/menus.hpp +++ b/src/game/client/components/menus.hpp @@ -132,7 +132,6 @@ class MENUS : public COMPONENT void render_servercontrol_map(RECT main_view); // found in menus_browser.cpp - SERVER_INFO current_server_info; // should this be here? int selected_index; void render_serverbrowser_serverlist(RECT view); void render_serverbrowser_serverdetail(RECT view); diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index cfd92daab..29067e413 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -144,6 +144,10 @@ void MENUS::render_game(RECT main_view) void MENUS::render_serverinfo(RECT main_view) { + // fetch server info + SERVER_INFO current_server_info; + client_serverinfo(¤t_server_info); + // count players for server info-box int num_players = 0; for(int i = 0; i < snap_num_items(SNAP_CURRENT); i++) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 539e250df..4ef7cc786 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -833,9 +833,9 @@ bool CHARACTER::take_damage(vec2 force, int dmg, int from, int weapon) return true; } -void CHARACTER::snap(int snaping_client) +void CHARACTER::snap(int snapping_client) { - if(networkclipped(snaping_client)) + if(networkclipped(snapping_client)) return; NETOBJ_CHARACTER *character = (NETOBJ_CHARACTER *)snap_new_item(NETOBJTYPE_CHARACTER, player->client_id, sizeof(NETOBJ_CHARACTER)); @@ -862,7 +862,7 @@ void CHARACTER::snap(int snaping_client) character->direction = input.direction; - if(player->client_id == snaping_client) + if(player->client_id == snapping_client) { character->health = health; character->armor = armor; diff --git a/src/game/server/entities/character.hpp b/src/game/server/entities/character.hpp index 818cebdf4..bfb9d8c26 100644 --- a/src/game/server/entities/character.hpp +++ b/src/game/server/entities/character.hpp @@ -118,7 +118,7 @@ public: virtual void tick(); virtual void tick_defered(); - virtual void snap(int snaping_client); + virtual void snap(int snapping_client); bool increase_health(int amount); bool increase_armor(int amount); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index b31c4d2fc..cc12c48aa 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -61,7 +61,7 @@ void PLAYER::tick() try_respawn(); } -void PLAYER::snap(int snaping_client) +void PLAYER::snap(int snapping_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)); @@ -79,7 +79,7 @@ void PLAYER::snap(int snaping_client) info->score = score; info->team = team; - if(client_id == snaping_client) + if(client_id == snapping_client) info->local = 1; } diff --git a/src/game/server/player.hpp b/src/game/server/player.hpp index e88ce8589..a1aed5941 100644 --- a/src/game/server/player.hpp +++ b/src/game/server/player.hpp @@ -64,7 +64,7 @@ public: void set_team(int team); void tick(); - void snap(int snaping_client); + void snap(int snapping_client); void on_direct_input(NETOBJ_PLAYER_INPUT *new_input); void on_predicted_input(NETOBJ_PLAYER_INPUT *new_input);