From 5f05bf2e58fab151886184643c75f9d9b677b0a3 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sun, 27 Sep 2009 12:00:51 -0700 Subject: [PATCH] fix for keepalive and chat window 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 | 20 +++++++++++++++++--- winboard/wchat.c | 10 +++++++--- winboard/winboard.c | 1 + xboard.c | 9 ++++++++- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index 94d0e81..d7c764b 100644 --- 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= 0) // channel broadcast; look if there is a chatbox for this channel + for(p=0; p %s\n", mess); // echo only tells, not whispers + if(!strcmp("WHISPER", chatPartner[partner])) + sprintf(buf, "whisper %s\n", mess); // WHISPER box uses "whisper" to send + else { + if(!atoi(chatPartner[partner])) { + sprintf(buf, "> %s\n", mess); // echo only tells to handle, not channel InsertIntoMemo(hDlg, buf); + } sprintf(buf, "tell %s %s\n", chatPartner[partner], mess); - } else sprintf(buf, "whisper %s\n", mess); // SAY box uses "say" to send + } SendToICS(buf); break; diff --git a/winboard/winboard.c b/winboard/winboard.c index e270565..6452a5b 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -9872,6 +9872,7 @@ ScheduleDelayedEvent(DelayedEventCallback cb, long millisec) } KillTimer(hwndMain, delayedTimerEvent); delayedTimerEvent = 0; + if(delayedTimerCallback != cb) // [HGM] alive: do not "flush" same event, just postpone it delayedTimerCallback(); } delayedTimerCallback = cb; diff --git a/xboard.c b/xboard.c index cb6317f..c6ef883 100644 --- 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, -- 1.7.0.4