]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
added support for the tetrinet java server
authorDaniel Carbonell Fraj <bocata@src.gnome.org>
Mon, 17 Mar 2003 15:59:00 +0000 (15:59 +0000)
committerDaniel Carbonell Fraj <bocata@src.gnome.org>
Mon, 17 Mar 2003 15:59:00 +0000 (15:59 +0000)
ChangeLog
src/partyline.c
src/tetrinet.c

index 2251f3c00a3370ea905482291d1aee5c52803f74..1b49c53703ce80b23c80911d60e9408bf9691bc2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-03-17  Daniel Carbonell Fraj  <bocata@panete.net>
+
+       * src/partyline.c (partyline_add_channel): changed the parsing code, so 
+       now it can parse the lines sent by the tetrinet java server.
+
+       * src/tetrinet.c (tetrinet_inmessage): added support for the
+       tetrinet java server.
+
 2003-03-17  Jordi Mallach  <jordi@sindominio.net>
 
        * TODO: Updated for 0.7.0.
index df2f224526884ad8bf883c408105492ae90d23b0..62b67de1fe07cb432742de15f41c382ddd4ece76 100644 (file)
@@ -407,42 +407,73 @@ void partyline_add_channel (gchar *line)
   
   while ((g_scanner_get_next_token (scan) != G_TOKEN_INT) && !g_scanner_eof (scan));
   num = scan->value.v_int;
-  
-  while ((g_scanner_get_next_token (scan) != G_TOKEN_COMMENT_SINGLE) && !g_scanner_eof (scan));
-  utf8 = g_locale_to_utf8 (scan->value.v_comment, -1, NULL, NULL, NULL);
-  name = g_strconcat ("#", utf8, NULL);
-  
-  while ((g_scanner_get_next_token (scan) != G_TOKEN_IDENTIFIER) && !g_scanner_eof (scan));
-  players = g_strdup (scan->value.v_identifier);
 
-  if (strncmp (players, "FULL", 4))
+  g_scanner_get_next_token (scan); /* dump the ')' */
+  
+  if (g_scanner_peek_next_token (scan) == G_TOKEN_LEFT_BRACE)
   {
+    scan->config->cpair_comment_single = "# ";
+    
     while ((g_scanner_get_next_token (scan) != G_TOKEN_INT) && !g_scanner_eof (scan));
     actual = scan->value.v_int;
-
+    
     while ((g_scanner_get_next_token (scan) != G_TOKEN_INT) && !g_scanner_eof (scan));
     max = scan->value.v_int;
 
-    g_snprintf (final, 1024, "%d/%d %s", actual, max, players);
+    while ((g_scanner_get_next_token (scan) != G_TOKEN_COMMENT_SINGLE) && !g_scanner_eof (scan));
+    utf8 = g_locale_to_utf8 (scan->value.v_comment, -1, NULL, NULL, NULL);
+    name = g_strconcat ("#", utf8, NULL);
+    
+    g_snprintf (final, 1024, "%d/%d", actual, max);
+
+    scan->config->cpair_comment_single = "{}";
+    while ((g_scanner_get_next_token (scan) != G_TOKEN_COMMENT_SINGLE) && !g_scanner_eof (scan));
+    if (!g_scanner_eof (scan))
+      state = g_strdup (scan->value.v_comment);
+    else
+      state = g_strdup ("IDLE");
+
+    desc = g_strdup ("");
+    players = g_strdup ("");
   }
   else
-    g_snprintf (final, 1024, "6/6 %s", players);
+  {
+    while ((g_scanner_get_next_token (scan) != G_TOKEN_COMMENT_SINGLE) && !g_scanner_eof (scan));
+    utf8 = g_locale_to_utf8 (scan->value.v_comment, -1, NULL, NULL, NULL);
+    name = g_strconcat ("#", utf8, NULL);
   
-  g_scanner_get_next_token (scan); /* dump the ')' */
+    while ((g_scanner_get_next_token (scan) != G_TOKEN_IDENTIFIER) && !g_scanner_eof (scan));
+    players = g_strdup (scan->value.v_identifier);
+
+    if (strncmp (players, "FULL", 4))
+    {
+      while ((g_scanner_get_next_token (scan) != G_TOKEN_INT) && !g_scanner_eof (scan));
+      actual = scan->value.v_int;
+
+      while ((g_scanner_get_next_token (scan) != G_TOKEN_INT) && !g_scanner_eof (scan));
+      max = scan->value.v_int;
+
+      g_snprintf (final, 1024, "%d/%d %s", actual, max, players);
+    }
+    else
+      g_snprintf (final, 1024, "6/6 %s", players);
   
-  if (g_scanner_get_next_token (scan) == G_TOKEN_LEFT_CURLY)
-  {
-    g_scanner_get_next_token (scan);
-    state = g_strdup (scan->value.v_identifier);
-  }
-  else
-    state = g_strdup ("IDLE");
+    g_scanner_get_next_token (scan); /* dump the ')' */
   
-  while ((g_scanner_get_next_token (scan) != G_TOKEN_RIGHT_PAREN) && !g_scanner_eof (scan));
-  if (line[scan->position] != 0)
-    desc = g_strstrip (g_locale_to_utf8 (&line[scan->position], -1, NULL, NULL, NULL));
-  else
-    desc = g_strdup ("");
+    if (g_scanner_get_next_token (scan) == G_TOKEN_LEFT_CURLY)
+    {
+      g_scanner_get_next_token (scan);
+      state = g_strdup (scan->value.v_identifier);
+    }
+    else
+      state = g_strdup ("IDLE");
+  
+    while ((g_scanner_get_next_token (scan) != G_TOKEN_RIGHT_PAREN) && !g_scanner_eof (scan));
+    if (line[scan->position] != 0)
+      desc = g_strstrip (g_locale_to_utf8 (&line[scan->position], -1, NULL, NULL, NULL));
+    else
+      desc = g_strdup ("");
+  }
   
   
   gtk_list_store_append (work_model, &iter);
index f5b8e6d0ee3648f2f613042b2647849e01582c34..cb8f434b3e6c5815f1d290e5ea425dfaa9121525 100644 (file)
@@ -185,6 +185,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data)
     case IN_CONNECT:
         list_issued = 0;
         up_chan_list_source = g_timeout_add (30000, (GSourceFunc) partyline_update_channel_list, NULL);
+        partyline_joining_channel ("");
         break;
     case IN_DISCONNECT:
         if (!connected) {
@@ -280,6 +281,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data)
             }
         }
         /* show partyline on successful connect */
+        partyline_update_channel_list ();
         show_partyline_page ();
         break;
     case IN_PLAYERJOIN:
@@ -399,62 +401,70 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data)
               break;
             token = strtok (NULL, "");
             if (token == NULL) token = "";
+            //printf ("* %s\n", token);
             if (pnum == 0) {
                 if (strncmp (token, "\04\04\04\04\04\04\04\04", 8) == 0) {
                     /* tetrix identification string */
                     tetrix = TRUE;
                 }
-                else if (tetrix) {
-                    gchar *line = nocolor (token);
+                else
+                {
+                  gchar *line = nocolor (token);
                       
-                    if (list_issued > 0)
+                  if (list_issued > 0)
+                  {
+                    if (*line == '(')
                     {
-                      if (*line == '(')
-                      {
-                        partyline_add_channel (line);
-                        break;
-                      }
-                      
-                      if (!strncmp ("List", line, 4))
-                      {
-                        partyline_more_channel_lines ();
-                        break;
-                      }
-                      
-                      if (!strncmp ("TetriNET", line, 8))
-                        break;
-                      
-                      if (!strncmp ("You", line, 3))
-                      {
-                        /* we will use the error message as list stopper */
-                        list_issued--;
-                        if (list_issued <= 0)
-                          stop_list();
-                        break;
-                      }
-                      
-                      //if (line != NULL) g_free (line);
+                      partyline_add_channel (line);
+                      break;
                     }
-                    /* detect whenever we have joined a channel */
-                    if (!strncmp ("has joined", &line[strlen (playernames[playernum])+1], 10))
-                    {
-                      partyline_joining_channel (&line[strlen (playernames[playernum])+20]);
-                    }
-                    else if (!strncmp ("Joined existing Channel", line, 23))
+                      
+                    if (!strncmp ("List", line, 4))
                     {
-                      partyline_joining_channel (&line[26]);
+                      partyline_more_channel_lines ();
+                      break;
                     }
-                    else if (!strncmp ("Created new Channel", line, 19))
+                      
+                    if (!strncmp ("TetriNET", line, 8))
+                      break;
+                      
+                    if (!strncmp ("You do NOT", line, 10))
                     {
-                      partyline_joining_channel (&line[22]);
+                      /* we will use the error message as list stopper */
+                      list_issued--;
+                      if (list_issued <= 0)
+                        stop_list();
+                      break;
                     }
+                      
+                    //if (line != NULL) g_free (line);
+                  }
+                  /* detect whenever we have joined a channel */
+                  if (!strncmp ("has joined", &line[strlen (playernames[playernum])+1], 10))
+                  {
+                    partyline_joining_channel (&line[strlen (playernames[playernum])+20]);
+                  }
+                  else if (!strncmp ("Joined existing Channel", line, 23))
+                  {
+                    partyline_joining_channel (&line[26]);
+                  }
+                  else if (!strncmp ("Created new Channel", line, 19))
+                  {
+                    partyline_joining_channel (&line[22]);
+                  }
+                  else if (!strncmp ("You have joined", line, 15))
+                  {
+                    partyline_joining_channel (&line[16]);
+                  }
                     
+                  if (tetrix) {
                     g_snprintf (buf, sizeof(buf), "*** %s", token);
                     partyline_text (buf);
                     break;
+                  }
+                  else
+                    plinemsg ("Server", token);
                 }
-                else
-                  plinemsg ("Server", token);
             }
             else
             {