Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] PATCH: client: correct sorting, player slot info, server c
Home

[Freeciv-Dev] PATCH: client: correct sorting, player slot info, server c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] PATCH: client: correct sorting, player slot info, server cmd interface
From: mueller <mueller@xxxxxxxx>
Date: Sat, 23 Sep 2000 21:39:36 +0200

This patch 
- keeps the sorting from the metaserver page in the metaserver lists
- remembers which player names are available in which game
- provides a function for sending commands to the server (as in command
line)
Index: clinet.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v
retrieving revision 1.32
diff -u -r1.32 clinet.c
--- clinet.c    2000/09/18 20:36:13     1.32
+++ clinet.c    2000/09/23 19:18:46
@@ -238,6 +238,8 @@
  The result must be free'd with delete_server_list() when no
  longer used
 **************************************************************************/
+#define MAXSERVERS 100
+
 struct server_list *create_server_list(char *errbuf, int n_errbuf)
 {
   struct server_list *server_list;
@@ -251,6 +253,8 @@
   char *server;
   int port;
   char str[512];
+  char *servers[MAXSERVERS];
+  int  numservers=0;
 
   if ((proxy_url = getenv("http_proxy"))) {
     if (strncmp(proxy_url,"http://",strlen("http://";))) {
@@ -355,34 +359,50 @@
 
   server_list = fc_malloc(sizeof(struct server_list));
   server_list_init(server_list);
-
-  while(fgets(str, 512, f) != NULL) {
-    if((0 == strncmp(str, "<TR BGCOLOR",11)) && strchr(str, '\n')) {
-      char *name,*port,*version,*status,*players,*metastring;
-      char *p;
-      struct server *pserver = (struct server*)fc_malloc(sizeof(struct 
server));
-
-      p=strstr(str,"<a"); if(p==NULL) continue;
-      p=strchr(p,'>');    if(p==NULL) continue;
-      name=++p;
-      p=strstr(p,"</a>"); if(p==NULL) continue;
-      *p++='\0';
-
-      GET_FIELD(port);
-      GET_FIELD(version);
-      GET_FIELD(status);
-      GET_FIELD(players);
-      GET_FIELD(metastring);
-
-      pserver->name = mystrdup(name);
-      pserver->port = mystrdup(port);
-      pserver->version = mystrdup(version);
-      pserver->status = mystrdup(status);
-      pserver->players = mystrdup(players);
-      pserver->metastring = mystrdup(metastring);
 
-      server_list_insert(server_list, pserver);
-    }
+  while(fgets(str, 512, f) != NULL && numservers<MAXSERVERS)
+    if((0 == strncmp(str, "<TR BGCOLOR",11)) && strchr(str, '\n'))
+      servers[numservers++]=strdup(str);
+
+  for ( numservers--; numservers>=0; numservers--) {
+    char *name,*port,*version,*status,*players,*metastring, *lastturn, *joinas;
+    char *p;
+    int  minutes;
+    struct server *pserver = (struct server*)fc_malloc(sizeof(struct server));
+
+    strcpy(str, servers[numservers]);
+    free(servers[numservers]);
+
+    p=strstr(str,"<a"); if(p==NULL) continue;
+    p=strchr(p,'>');    if(p==NULL) continue;
+    name=++p;
+    p=strstr(p,"</a>"); if(p==NULL) continue;
+    *p++='\0';
+
+    GET_FIELD(port);
+    GET_FIELD(version);
+    GET_FIELD(status);
+    GET_FIELD(players);
+    GET_FIELD(metastring);
+    GET_FIELD(lastturn);
+    GET_FIELD(joinas);
+
+    if (!strcmp(joinas,"-"))
+      joinas="";
+
+    minutes=200;
+    if (strchr(lastturn,'m')) minutes=atoi(lastturn);
+    if (strchr(lastturn,'h')) minutes=atoi(lastturn)*60;
+
+    pserver->name = mystrdup(name);
+    pserver->port = mystrdup(port);
+    pserver->version = mystrdup(version);
+    pserver->status = mystrdup(status);
+    pserver->players = mystrdup(players);
+    pserver->metastring = mystrdup(metastring);
+    pserver->lastturn = minutes;
+    pserver->joinas = mystrdup(joinas);
+    server_list_insert(server_list, pserver);
   }
   fclose(f);
 
@@ -410,3 +430,13 @@
        free(server_list);
 }
 
+/**************************************************************************
+...
+**************************************************************************/
+void server_command(char *str)
+{
+  struct packet_generic_message apacket;
+
+  mystrlcpy(apacket.message, str, MAX_LEN_MSG-MAX_LEN_USERNAME+1);
+  send_packet_generic_message(&aconnection, PACKET_CHAT_MSG, &apacket);
+}
Index: clinet.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/clinet.h,v
retrieving revision 1.11
diff -u -r1.11 clinet.h
--- clinet.h    2000/01/02 11:55:22     1.11
+++ clinet.h    2000/09/23 19:18:46
@@ -34,6 +34,8 @@
   char *status;
   char *players;
   char *metastring;
+  int   lastturn;
+  char *joinas;
 };
 
 #define SPECLIST_TAG server
@@ -46,5 +48,6 @@
 
 struct server_list *create_server_list(char *errbuf, int n_errbuf);
 void delete_server_list(struct server_list *server_list);
+void server_command(char *str);
 
 #endif  /* FC__CLINET_H */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] PATCH: client: correct sorting, player slot info, server cmd interface, mueller <=