X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=c33c164ba9f9727a66827376321884eba9888b07;hb=ba19c79e683860fba8cafa5ca24b0f8191b4c1d5;hp=449157d651cfdecdcf5a437f4619ed771bf54f5a;hpb=c5dcdc1244715170a3837053879655dcadb524da;p=xboard.git diff --git a/backend.c b/backend.c index 449157d..c33c164 100644 --- a/backend.c +++ b/backend.c @@ -4551,6 +4551,73 @@ SendMoveToICS(moveType, fromX, fromY, toX, toY) } void +UploadGameEvent() +{ // [HGM] upload: send entire stored game to ICS as long-algebraic moves. + int i, last = forwardMostMove; // make sure ICS reply cannot pre-empt us by clearing fmm + static char *castlingStrings[4] = { "none", "kside", "qside", "both" }; + if(gameMode == IcsObserving || gameMode == IcsPlayingBlack || gameMode == IcsPlayingWhite) { + DisplayError("You cannot do this while you are playing or observing", 0); + return; + } + if(gameMode != IcsExamining) { // is this ever not the case? + char buf[MSG_SIZ], *p, *fen, command[MSG_SIZ], bsetup = 0; + + if(ics_type == ICS_ICC) { // on ICC match ourselves in applicable variant + sprintf(command, "match %s", ics_handle); + } else { // on FICS we must first go to general examine mode + strcpy(command, "examine\nbsetup"); // and specify variant within it with bsetups + } + if(gameInfo.variant != VariantNormal) { + // try figure out wild number, as xboard names are not always valid on ICS + for(i=1; i<=36; i++) { + sprintf(buf, "wild/%d", i); + if(StringToVariant(buf) == gameInfo.variant) break; + } + if(i<=36 && ics_type == ICS_ICC) sprintf(buf, "%s w%d\n", command, i); + else if(i == 22) sprintf(buf, "%s fr\n", command); + else sprintf(buf, "%s %s\n", command, VariantName(gameInfo.variant)); + } else sprintf(buf, "%s\n", ics_type == ICS_ICC ? command : "examine\n"); // match yourself or examine + SendToICS(ics_prefix); + SendToICS(buf); + if(startedFromSetupPosition || backwardMostMove != 0) { + fen = PositionToFEN(backwardMostMove, NULL); + if(ics_type == ICS_ICC) { // on ICC we can simply send a complete FEN to set everything + sprintf(buf, "loadfen %s\n", fen); + SendToICS(buf); + } else { // FICS: everything has to set by separate bsetup commands + p = strchr(fen, ' '); p[0] = NULLCHAR; // cut after board + sprintf(buf, "bsetup fen %s\n", fen); + SendToICS(buf); + if(!WhiteOnMove(backwardMostMove)) { + SendToICS("bsetup tomove black\n"); + } + i = (strchr(p+3, 'K') != NULL) + 2*(strchr(p+3, 'Q') != NULL); + sprintf(buf, "bsetup wcastle %s\n", castlingStrings[i]); + SendToICS(buf); + i = (strchr(p+3, 'k') != NULL) + 2*(strchr(p+3, 'q') != NULL); + sprintf(buf, "bsetup bcastle %s\n", castlingStrings[i]); + SendToICS(buf); + i = boards[backwardMostMove][EP_STATUS]; + if(i >= 0) { // set e.p. + sprintf(buf, "bsetup eppos %c\n", i+AAA); + SendToICS(buf); + } + bsetup++; + } + } + if(bsetup || ics_type != ICS_ICC && gameInfo.variant != VariantNormal) + SendToICS("bsetup done\n"); // switch to normal examining. + } + for(i = backwardMostMove; i