fixed fetching of server info and corrected some spelling errors

This commit is contained in:
Magnus Auvinen 2008-10-17 21:16:23 +00:00
parent eb47aa385b
commit a91fecae92
10 changed files with 64 additions and 15 deletions

View file

@ -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(&current_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, &current_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(&current_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 */

View file

@ -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;

View file

@ -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

View file

@ -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 */
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

View file

@ -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);

View file

@ -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(&current_server_info);
// count players for server info-box
int num_players = 0;
for(int i = 0; i < snap_num_items(SNAP_CURRENT); i++)

View file

@ -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;

View file

@ -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);

View file

@ -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;
}

View file

@ -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);