From aee14baf8d702ae560a8253efb6388b58c2740a7 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 8 Nov 2008 12:58:39 +0000 Subject: [PATCH] fixed the favorite button in the server info --- src/engine/client/ec_client.c | 1 + src/engine/client/ec_srvbrowse.c | 12 ++++++++++++ src/engine/e_if_client.h | 12 ++++++++++++ src/game/client/components/menus_ingame.cpp | 6 +++--- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index a9e3f6c86..1c8ea26dc 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -849,6 +849,7 @@ static void client_process_packet(NETCHUNK *packet) if(net_addr_comp(&server_address, &packet->address) == 0) { mem_copy(¤t_server_info, &info, sizeof(current_server_info)); + current_server_info.netaddr = server_address; current_server_info_requesttime = -1; } diff --git a/src/engine/client/ec_srvbrowse.c b/src/engine/client/ec_srvbrowse.c index 94d9f7e3d..cf36f62be 100644 --- a/src/engine/client/ec_srvbrowse.c +++ b/src/engine/client/ec_srvbrowse.c @@ -647,6 +647,18 @@ void client_serverbrowse_update() } +int client_serverbrowse_isfavorite(NETADDR addr) +{ + /* search for the address */ + int i; + for(i = 0; i < num_favorite_servers; i++) + { + if(net_addr_comp(&addr, &favorite_servers[i]) == 0) + return 1; + } + return 0; +} + void client_serverbrowse_addfavorite(NETADDR addr) { int i; diff --git a/src/engine/e_if_client.h b/src/engine/e_if_client.h index d1a5941e9..39974ffec 100644 --- a/src/engine/e_if_client.h +++ b/src/engine/e_if_client.h @@ -306,6 +306,18 @@ void client_serverbrowse_update(); */ int client_serverbrowse_lan(); +/* + Function: client_serverbrowse_isfavorite + Asks the server browser is a netaddr is in the favorite list + + Arguments: + addr - Address of the server to ask about. + + Returns: + Returns zero if it's not in the list, non-zero if it is. +*/ +int client_serverbrowse_isfavorite(NETADDR addr); + /* Function: client_serverbrowse_addfavorite Adds a server to the favorite list diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 1cf359baf..1aaf3d8d1 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -209,15 +209,15 @@ void MENUS::render_serverinfo(RECT main_view) { RECT button; + int is_favorite = client_serverbrowse_isfavorite(current_server_info.netaddr); ui_hsplit_b(&serverinfo, 20.0f, &serverinfo, &button); static int add_fav_button = 0; - if (ui_do_button(&add_fav_button, "Favorite", current_server_info.favorite, &button, ui_draw_checkbox, 0)) + if (ui_do_button(&add_fav_button, "Favorite", is_favorite, &button, ui_draw_checkbox, 0)) { - if(current_server_info.favorite) + if(is_favorite) client_serverbrowse_removefavorite(current_server_info.netaddr); else client_serverbrowse_addfavorite(current_server_info.netaddr); - current_server_info.favorite = !current_server_info.favorite; } }