From d11cca6989b6560f46810d3c4358c9c06e3d0244 Mon Sep 17 00:00:00 2001 From: Daniel Carbonell Fraj Date: Mon, 17 Mar 2003 15:59:00 +0000 Subject: [PATCH] added support for the tetrinet java server --- ChangeLog | 8 +++++ src/partyline.c | 79 ++++++++++++++++++++++++++++++-------------- src/tetrinet.c | 88 +++++++++++++++++++++++++++---------------------- 3 files changed, 112 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2251f3c..1b49c53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-03-17 Daniel Carbonell Fraj + + * 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 * TODO: Updated for 0.7.0. diff --git a/src/partyline.c b/src/partyline.c index df2f224..62b67de 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -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); diff --git a/src/tetrinet.c b/src/tetrinet.c index f5b8e6d..cb8f434 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -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 { -- 2.50.1