fix for keepalive and chat window
authorH.G. Muller <h.g.muller@hccnet.nl>
Sun, 27 Sep 2009 19:00:51 +0000 (12:00 -0700)
committerArun Persaud <arun@nubati.net>
Wed, 30 Sep 2009 05:17:58 +0000 (22:17 -0700)
I made a fix to the keepAlive option so it does not send the date command
to the ICS after every move. This required changing ScheduleDelayedEvent()
so that it does not execute the event if a new identical one gets scheduled.
I also added the option to XBoard. Affects
xboard.c (DOS!) and winboard.c

(This also cures the regression of the winboard.c copyright patch)

I extended the chatbox patch to also listen to channel tells, and divert
them to a chatbox for that channel number. Affects
backend.c and wchat.c

That should make those patches fully operational. No docs for either of them
yet, though.

backend.c
winboard/wchat.c
winboard/winboard.c
xboard.c

index 94d0e81..d7c764b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2093,6 +2093,7 @@ read_from_ics(isr, closure, data, count, error)
     int backup;    /* [DM] For zippy color lines */
     char *p;
     char talker[MSG_SIZ]; // [HGM] chat
+    int channel;
 
     if (appData.debugMode) {
       if (!error) {
@@ -2418,15 +2419,28 @@ read_from_ics(isr, closure, data, count, error)
 //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:") || 
-                                          looking_at(buf, &i, "* whispers:"))) {
+                                          looking_at(buf, &i, "* whispers:") ||
+                                          looking_at(buf, &i, "*(*):") && (sscanf(star_match[1], "%d", &channel),1) ||
+                                          looking_at(buf, &i, "*(*)(*):") && sscanf(star_match[2], "%d", &channel) == 1 )) {
                int p;
                sscanf(star_match[0], "%[^(]", talker+1); // strip (C) or (U) off ICS handle
                chattingPartner = -1;
-               if(buf[i-3] == 'r') // whisper; look if there is a WHISPER chatbox
-               for(p=0; p<MAX_CHAT; p++) if(!strcmp("WHISPER", chatPartner[p])) {
+
+               if(channel >= 0) // channel broadcast; look if there is a chatbox for this channel
+               for(p=0; p<MAX_CHAT; p++) {
+                   if(channel == atoi(chatPartner[p])) {
                    talker[0] = '['; strcat(talker, "]");
                    chattingPartner = p; break;
+                   }
+               } else
+               if(buf[i-3] == 'r') // whisper; look if there is a WHISPER chatbox
+               for(p=0; p<MAX_CHAT; p++) {
+                   if(!strcmp("WHISPER", chatPartner[p])) {
+                       talker[0] = '['; strcat(talker, "]");
+                       chattingPartner = p; break;
+                   }
                }
                if(chattingPartner<0) // if not, look if there is a chatbox for this indivdual
                for(p=0; p<MAX_CHAT; p++) if(!strcasecmp(talker+1, chatPartner[p])) {
index 0fd5e08..a837a86 100644 (file)
@@ -177,11 +177,15 @@ LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam
            GetDlgItemText(hDlg, OPT_ChatInput, mess, MSG_SIZ);\r
            SetDlgItemText(hDlg, OPT_ChatInput, "");\r
            // from here on it could be back-end\r
-           if(strcmp("WHISPER", chatPartner[partner])) {\r
-               sprintf(buf, "> %s\n", mess); // echo only tells, not whispers\r
+           if(!strcmp("WHISPER", chatPartner[partner]))\r
+               sprintf(buf, "whisper %s\n", mess); // WHISPER box uses "whisper" to send\r
+           else {\r
+               if(!atoi(chatPartner[partner])) {\r
+                   sprintf(buf, "> %s\n", mess); // echo only tells to handle, not channel\r
                InsertIntoMemo(hDlg, buf);\r
+               }\r
                sprintf(buf, "tell %s %s\n", chatPartner[partner], mess);\r
-           } else sprintf(buf, "whisper %s\n", mess); // SAY box uses "say" to send\r
+           }\r
            SendToICS(buf);\r
            break;\r
 \r
index e270565..6452a5b 100644 (file)
@@ -9872,6 +9872,7 @@ ScheduleDelayedEvent(DelayedEventCallback cb, long millisec)
     }\r
     KillTimer(hwndMain, delayedTimerEvent);\r
     delayedTimerEvent = 0;\r
+    if(delayedTimerCallback != cb) // [HGM] alive: do not "flush" same event, just postpone it\r
     delayedTimerCallback();\r
   }\r
   delayedTimerCallback = cb;\r
index cb6317f..c6ef883 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -1401,6 +1401,9 @@ XtResource clientResources[] = {
     { "delayAfterQuit", "delayAfterQuit", XtRInt,
        sizeof(int), XtOffset(AppDataPtr, delayAfterQuit),
        XtRImmediate, (XtPointer) 0},
+    { "keepAlive", "keepAlive", XtRInt,
+       sizeof(int), XtOffset(AppDataPtr, keepAlive),
+       XtRImmediate, (XtPointer) 0},
 };
 
 XrmOptionDescRec shellOptions[] = {
@@ -1768,6 +1771,7 @@ XrmOptionDescRec shellOptions[] = {
     { "-secondOptions", "secondOptions", XrmoptionSepArg, NULL },
     { "-firstNeedsNoncompliantFEN", "firstNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
     { "-secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
+    { "-keepAlive", "keepAlive", XrmoptionSepArg, NULL },
 };
 
 
@@ -2419,7 +2423,7 @@ main(argc, argv)
            j = fprintf(stderr, "  %s%s", shellOptions[i].option,
                        (shellOptions[i].argKind == XrmoptionSepArg
                         ? " ARG" : ""));
-           if (i++ < XtNumber(shellOptions)) {
+           if (i++ < XtNumber(shellOptions)) {         
                fprintf(stderr, "%*c%s%s\n", 40 - j, ' ',
                        shellOptions[i].option,
                        (shellOptions[i].argKind == XrmoptionSepArg
@@ -8140,6 +8144,9 @@ void
 ScheduleDelayedEvent(cb, millisec)
      DelayedEventCallback cb; long millisec;
 {
+    if(delayedEventTimerXID && delayedEventCallback == cb)
+       // [HGM] alive: replace, rather than add or flush identical event
+       XtRemoveTimeOut(delayedEventTimerXID);
     delayedEventCallback = cb;
     delayedEventTimerXID =
       XtAppAddTimeOut(appContext, millisec,