tGraphical server now "works" with the new metaserver - vaccinewars - be a doctor and try to vaccinate the world
git clone git://src.adamsgaard.dk/vaccinewars
Log
Files
Refs
README
LICENSE
---
commit 3088bfbc9025eba238f99baf604f946717a24ff3
parent d24cffd2fc68fbbff1b5bb82700e108b4f9d3e81
Author: Ben Webb 
Date:   Sun, 17 Jun 2001 22:50:55 +0000

Graphical server now "works" with the new metaserver


Diffstat:
  M src/dopewars.h                      |       1 +
  M src/message.c                       |      23 +++++++++++++++++------
  M src/message.h                       |       2 ++
  M src/serverside.c                    |      36 +++++++++++++++++++++++++++++++

4 files changed, 56 insertions(+), 6 deletions(-)
---
diff --git a/src/dopewars.h b/src/dopewars.h
t@@ -287,6 +287,7 @@ typedef struct tagConnBuf {
 /* Handles reading and writing messages from/to a network connection */
 typedef struct tagNetworkBuffer {
    int fd;                /* File descriptor of the socket */
+   gint InputTag;         /* Identifier for gdk_input routines */
    char Terminator;       /* Character that separates messages */
    char StripChar;        /* Character that should be removed from messages */
    ConnBuf ReadBuf;       /* New data, waiting for the application */
diff --git a/src/message.c b/src/message.c
t@@ -402,19 +402,31 @@ gboolean RespondToSelect(NetworkBuffer *NetBuf,fd_set *readfds,
    return DataWaiting;
 }
 
+gboolean NetBufHandleNetwork(NetworkBuffer *NetBuf,gboolean ReadReady,
+                             gboolean WriteReady,gboolean *DoneOK) {
+   gboolean ReadOK,WriteOK,ErrorOK;
+   gboolean DataWaiting=FALSE;
+
+   *DoneOK=TRUE;
+   if (!NetBuf || NetBuf->fd<=0) return DataWaiting;
+
+   DataWaiting=DoNetworkBufferStuff(NetBuf,ReadReady,WriteReady,FALSE,
+                                    &ReadOK,&WriteOK,&ErrorOK);
+
+   *DoneOK=(WriteOK && ErrorOK && ReadOK);
+   return DataWaiting;
+}
+
 gboolean PlayerHandleNetwork(Player *Play,gboolean ReadReady,
                              gboolean WriteReady,gboolean *DoneOK) {
 /* Reads and writes player data from/to the network if it is ready.  */
 /* If any data were read, TRUE is returned. "DoneOK" is set TRUE     */
 /* unless a fatal error (i.e. the connection was broken) occurred.   */
-   gboolean ReadOK,WriteOK,ErrorOK;
    gboolean DataWaiting=FALSE;
 
    *DoneOK=TRUE;
-   if (!Play || Play->NetBuf.fd<=0) return DataWaiting;
-
-   DataWaiting=DoNetworkBufferStuff(&Play->NetBuf,ReadReady,WriteReady,FALSE,
-                                    &ReadOK,&WriteOK,&ErrorOK);
+   if (!Play) return DataWaiting;
+   DataWaiting=NetBufHandleNetwork(&Play->NetBuf,ReadReady,WriteReady,DoneOK);
 
 /* If we've written out everything, then ask not to be notified of
    socket write-ready status in future */
t@@ -423,7 +435,6 @@ gboolean PlayerHandleNetwork(Player *Play,gboolean ReadReady,
       (*SocketWriteTestPt)(Play,FALSE);
    }
 
-   *DoneOK=(WriteOK && ErrorOK && ReadOK);
    return DataWaiting;
 }
 
diff --git a/src/message.h b/src/message.h
t@@ -130,6 +130,8 @@ void SetSelectForNetworkBuffer(NetworkBuffer *NetBuf,fd_set *readfds,
 gboolean RespondToSelect(NetworkBuffer *NetBuf,fd_set *readfds,
                          fd_set *writefds,fd_set *errorfds,
                          gboolean *DoneOK);
+gboolean NetBufHandleNetwork(NetworkBuffer *NetBuf,gboolean ReadReady,
+                             gboolean WriteReady,gboolean *DoneOK);
 gboolean PlayerHandleNetwork(Player *Play,gboolean ReadReady,
                              gboolean WriteReady,gboolean *DoneOK);
 gboolean ReadPlayerDataFromWire(Player *Play);
diff --git a/src/serverside.c b/src/serverside.c
t@@ -82,6 +82,7 @@ static GScanner *Scanner;
 
 /* Data waiting to be sent to/read from the metaserver */
 NetworkBuffer MetaNetBuf;
+gint MetaInputTag=0;
 
 /* Handle to the high score file */
 static FILE *ScoreFP=NULL;
t@@ -110,6 +111,11 @@ static char HelpText[] = {
 int SendSingleHighScore(Player *Play,struct HISCORE *Score,
                         int index,char Bold);
 
+#ifdef GUI_SERVER
+static void GuiHandleMeta(gpointer data,gint socket,
+                          GdkInputCondition condition);
+#endif
+
 void RegisterWithMetaServer(gboolean Up,gboolean SendData,
                             gboolean RespectTimeout) {
 /* Sends server details to the metaserver, if specified. If "Up" is  */
t@@ -152,6 +158,11 @@ void RegisterWithMetaServer(gboolean Up,gboolean SendData,
       dopelog(2,_("Waiting for metaserver connect to %s:%d..."),MetaName,
               MetaPort);
    } else return;
+#ifdef GUI_SERVER
+   if (MetaInputTag) gdk_input_remove(MetaInputTag);
+   MetaInputTag=gdk_input_add(MetaNetBuf.fd,GDK_INPUT_READ|GDK_INPUT_WRITE,
+                              GuiHandleMeta,NULL);
+#endif
    MetaPlayerPending=FALSE;
    text=g_string_new("");
    query=g_string_new("");
t@@ -979,6 +990,31 @@ static void GuiDoCommand(GtkWidget *widget,gpointer data) {
    if (IsServerShutdown()) GuiQuitServer();
 }
 
+void GuiHandleMeta(gpointer data,gint socket,GdkInputCondition condition) {
+   gboolean DoneOK;
+   gchar *buf;
+   static gboolean ReadingHeaders=TRUE;
+
+   if (MetaNetBuf.WaitConnect) ReadingHeaders=TRUE;
+   if (NetBufHandleNetwork(&MetaNetBuf,condition&GDK_INPUT_READ,
+                           condition&GDK_INPUT_WRITE,&DoneOK)) {
+      while ((buf=GetWaitingMessage(&MetaNetBuf))) {
+         if (buf[0] || ReadingHeaders) {
+            dopelog(ReadingHeaders ? 4 : 2,"MetaServer: %s",buf);
+         }
+         if (buf[0]==0) ReadingHeaders=FALSE;
+         g_free(buf);
+      }
+   }
+   if (!DoneOK) {
+      dopelog(4,"MetaServer: (closed)\n");
+      ShutdownNetworkBuffer(&MetaNetBuf);
+      gdk_input_remove(MetaInputTag);
+      MetaInputTag=0;
+      if (IsServerShutdown()) GuiQuitServer();
+   }
+}
+
 static void GuiHandleSocket(gpointer data,gint socket,
                             GdkInputCondition condition) {
    Player *Play;