[Freeciv-Dev] Re: (PR#10917) connect to LAN game - GUI bug
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10917 >
here's hack to fix it.
-mike
? client/.clinet.c.swp
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 pages.c
--- client/gui-gtk-2.0/pages.c 1 Nov 2004 22:02:58 -0000 1.1.2.10
+++ client/gui-gtk-2.0/pages.c 7 Nov 2004 01:49:00 -0000
@@ -296,24 +296,85 @@
struct server_list *server_list = get_lan_server_list();
if (server_list) {
- gtk_list_store_clear(lan_store);
+ GtkTreeIter it;
+ bool valid;
+
+ /* first pass: find matching servers already in the lan_store */
+ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(lan_store), &it);
+
+ while (valid) {
+ char *host, *port;
+ bool found = FALSE;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(lan_store),
+ &it, 0, &host, 1, &port, -1);
+
+ server_list_iterate(*server_list, pserver) {
+ /* the lan_store already has this server, don't delete it. */
+ if (strncmp(host, pserver->host, strlen(host)) == 0
+ && strncmp(port, pserver->port, strlen(port)) == 0) {
+ found = TRUE;
+ break;
+ }
+ } server_list_iterate_end;
+
+ /* if the server is not found, delete it from the lan_store */
+ if (!found) {
+ gtk_list_store_remove(lan_store, &it);
+ }
+ free(host);
+ free(port);
+
+ valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(lan_store), &it);
+ }
+
+ /* second pass: add all the new servers to the lan_store */
server_list_iterate(*server_list, pserver) {
GtkTreeIter it;
- gchar *row[6];
+ bool valid;
+ bool found = FALSE;
+
+ valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(lan_store), &it);
- row[0] = pserver->host;
- row[1] = pserver->port;
- row[2] = pserver->version;
- row[3] = _(pserver->state);
- row[4] = pserver->nplayers;
- row[5] = pserver->message;
-
- gtk_list_store_append(lan_store, &it);
- gtk_list_store_set(lan_store, &it,
- 0, row[0], 1, row[1], 2, row[2],
- 3, row[3], 4, row[4], 5, row[5], -1);
+ while (valid) {
+ char *host, *port;
+
+ gtk_tree_model_get(GTK_TREE_MODEL(lan_store),
+ &it, 0, &host, 1, &port, -1);
+
+ /* the lan_store already has this server, don't delete it. */
+ if (strncmp(host, pserver->host, strlen(host)) == 0
+ && strncmp(port, pserver->port, strlen(port)) == 0) {
+ found = TRUE;
+ }
+
+ free(host);
+ free(port);
+
+ valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(lan_store), &it);
+ }
+
+ /* if the server is not found, add it to the lan_store */
+ if (!found) {
+ GtkTreeIter it2;
+ gchar *row[6];
+
+ row[0] = pserver->host;
+ row[1] = pserver->port;
+ row[2] = pserver->version;
+ row[3] = _(pserver->state);
+ row[4] = pserver->nplayers;
+ row[5] = pserver->message;
+
+ gtk_list_store_append(lan_store, &it2);
+ gtk_list_store_set(lan_store, &it2,
+ 0, row[0], 1, row[1], 2, row[2],
+ 3, row[3], 4, row[4], 5, row[5], -1);
+ }
} server_list_iterate_end;
+ } else {
+ gtk_list_store_clear(lan_store);
}
num_lanservers_timer++;
|
|