Seek-Graph bugfix: disappearing output in ICS console
authorH.G. Muller <h.g.muller@hccnet.nl>
Fri, 19 Feb 2010 21:32:35 +0000 (22:32 +0100)
committerArun Persaud <arun@nubati.net>
Sun, 21 Feb 2010 00:35:01 +0000 (16:35 -0800)
Suppression of output to the cosole was handled fundamentally wrong: it
was not enough to set next_out to after the unit that should be
suppressed, as there can be a backlog in printing of previous units that
came in the same packet. So this has to be flushed first, or it will be
lost. -autoKibitz probably got away with that, because it comes in a
separate packet. But seek ads are often suffixed to other output, and
then that output disappeared! Now we flush everywhere before suppressing.
We now totally rely on the prompt to restart the printing, so that
acknowledgements following the echo of the sent message are also
suppressed. Also suppress LF before diverted chat messages.
  Also fixed is the 'mamer bug' in Chat Boxes, due to false parsing of
a "* (*): " pattern in tell messages, because of a missing continue.

backend.c

index f0811fd..90b9269 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2542,6 +2542,7 @@ read_from_ics(isr, closure, data, count, error)
                        sprintf(mess, "%s%s", talker, parse);
                        OutputChatMessage(chattingPartner, mess);
                        chattingPartner = -1;
+                       next_out = i+1; // [HGM] suppress printing in ICS window
                    } else
                    if(!suppressKibitz) // [HGM] kibitz
                        AppendComment(forwardMostMove, StripHighlight(parse), TRUE);
@@ -2565,12 +2566,12 @@ read_from_ics(isr, closure, data, count, error)
                                pvInfoList[forwardMostMove-1].score = 100*score;
                            }
                            OutputKibitz(suppressKibitz, parse);
-                           next_out = i+1; // [HGM] suppress printing in ICS window
                        } else {
                            char tmp[MSG_SIZ];
                            sprintf(tmp, _("your opponent kibitzes: %s"), parse);
                            SendToPlayer(tmp, strlen(tmp));
                        }
+                       next_out = i+1; // [HGM] suppress printing in ICS window
                    }
                    started = STARTED_NONE;
                } else {
@@ -2586,6 +2587,7 @@ read_from_ics(isr, closure, data, count, error)
                    continue;
                }
                started = STARTED_NONE;
+               if(suppressKibitz) next_out = i+1;
            }
 
             /* Kludge to deal with rcmd protocol */
@@ -2643,10 +2645,12 @@ read_from_ics(isr, closure, data, count, error)
              continue;
            }
 
+           oldi = i;
            // [HGM] seekgraph: recognize sought lines and end-of-sought message
            if(appData.seekGraph) {
                if(soughtPending && MatchSoughtLine(buf+i)) {
                    i = strstr(buf+i, "rated") - buf;
+                   if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
                    next_out = leftover_start = i;
                    started = STARTED_CHATTER;
                    suppressKibitz = TRUE;
@@ -2666,16 +2670,19 @@ read_from_ics(isr, closure, data, count, error)
                        AddAd(star_match[0], star_match[1], atoi(star_match[2+s]), atoi(star_match[3+s]), 
                              star_match[4+s][0], star_match[5-3*s], atoi(star_match[7]), TRUE);
                        looking_at(buf, &i, "*% "); // eat prompt
+                       if(oldi > 0 && buf[oldi-1] == '\n') oldi--; // suppress preceding LF, if any
+                       if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
                        next_out = i; // suppress
                        continue;
                    }
-                   if(looking_at(buf, &i, "Ads removed: *\n") || looking_at(buf, &i, "\031(51 * *\031)")) {
+                   if(looking_at(buf, &i, "\nAds removed: *\n") || looking_at(buf, &i, "\031(51 * *\031)")) {
                        char *p = star_match[0];
                        while(*p) {
                            if(seekGraphUp) RemoveSeekAd(atoi(p));
                            while(*p && *p++ != ' '); // next
                        }
                        looking_at(buf, &i, "*% "); // eat prompt
+                       if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
                        next_out = i;
                        continue;
                    }
@@ -2690,7 +2697,6 @@ read_from_ics(isr, closure, data, count, error)
              continue;
            }
 
-           oldi = i;
            // [HGM] kibitz: try to recognize opponent engine-score kibitzes, to divert them to engine-output window
            if (appData.autoKibitz && started == STARTED_NONE && 
                 !appData.icsEngineAnalyze &&                     // [HGM] [DM] ICS analyze
@@ -2699,6 +2705,8 @@ read_from_ics(isr, closure, data, count, error)
                   (StrStr(star_match[0], gameInfo.white) == star_match[0] || 
                    StrStr(star_match[0], gameInfo.black) == star_match[0]   )) { // kibitz of self or opponent
                        suppressKibitz = TRUE;
+                       if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
+                       next_out = i;
                        if((StrStr(star_match[0], gameInfo.white) == star_match[0]
                                && (gameMode == IcsPlayingWhite)) ||
                           (StrStr(star_match[0], gameInfo.black) == star_match[0]
@@ -2713,18 +2721,21 @@ read_from_ics(isr, closure, data, count, error)
                        } 
                        continue;
                } else
-               if(looking_at(buf, &i, "kibitzed to *\n") && atoi(star_match[0])) {
+               if((looking_at(buf, &i, "\nkibitzed to *\n") || looking_at(buf, &i, "kibitzed to *\n") ||
+                   looking_at(buf, &i, "\n(kibitzed to *\n") || looking_at(buf, &i, "(kibitzed to *\n"))
+                        && atoi(star_match[0])) {
                    // suppress the acknowledgements of our own autoKibitz
                    char *p;
+                   if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
                    if(p = strchr(star_match[0], ' ')) p[1] = NULLCHAR; // clip off "players)" on FICS
                    SendToPlayer(star_match[0], strlen(star_match[0]));
-                   looking_at(buf, &i, "*% "); // eat prompt
+                   if(looking_at(buf, &i, "*% ")) // eat prompt
+                       suppressKibitz = FALSE;
                    next_out = i;
+                   continue;
                }
            } // [HGM] kibitz: end of patch
 
-//if(appData.debugMode) fprintf(debugFP, "hunt for tell, buf = %s\n", buf+i);
-
            // [HGM] chat: intercept tells by users for which we have an open chat window
            channel = -1;
            if(started == STARTED_NONE && (looking_at(buf, &i, "* tells you:") || looking_at(buf, &i, "* says:") || 
@@ -2757,10 +2768,13 @@ read_from_ics(isr, closure, data, count, error)
                    chattingPartner = p; break;
                }
                if(chattingPartner<0) i = oldi; else {
+                   if(oldi > 0 && buf[oldi-1] == '\n') oldi--;
+                   if (oldi > next_out) SendToPlayer(&buf[next_out], oldi - next_out);
                    started = STARTED_COMMENT;
                    parse_pos = 0; parse[0] = NULLCHAR;
                    savingComment = 3 + chattingPartner; // counts as TRUE
                    suppressKibitz = TRUE;
+                   continue;
                }
            } // [HGM] chat: end of patch