diff options
-rw-r--r-- | FICS/gameproc.c | 134 |
1 files changed, 75 insertions, 59 deletions
diff --git a/FICS/gameproc.c b/FICS/gameproc.c index 1277955..2666e2d 100644 --- a/FICS/gameproc.c +++ b/FICS/gameproc.c @@ -1237,67 +1237,83 @@ PUBLIC int com_takeback(int p, param_list param) return COM_OK; } - -PUBLIC int com_switch(int p, param_list param) +PUBLIC int +com_switch(int p, param_list param) { - int g = parray[p].game; - int tmp, now; - int p1; - char *strTmp; + char *strTmp; + int g = parray[p].game; + int p1; + int tmp, now; - if (!pIsPlaying(p)) { - return COM_OK; - } - p1 = parray[p].opponent; - if (parray[p1].simul_info.numBoards && - parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] != g) { - pprintf(p, "You can only make requests when the simul player is at your board.\n"); - return COM_OK; - } - if (garray[g].link >= 0) { - pprintf(p, "Switch not implemented for bughouse games.\n"); - return COM_OK; - } - if (player_find_pendfrom(p, parray[p].opponent, PEND_SWITCH) >= 0) { - player_remove_request(parray[p].opponent, p, PEND_SWITCH); - /* Doing the switch */ - player_decline_offers(p, -1, -PEND_SIMUL); - - tmp = garray[g].white; - garray[g].white = garray[g].black; - garray[g].black = tmp; - parray[p].side = (parray[p].side == WHITE) ? BLACK : WHITE; - strTmp = xstrdup(garray[g].white_name); - strcpy(garray[g].white_name, garray[g].black_name); - strcpy(garray[g].black_name, strTmp); - strfree(strTmp); - - parray[parray[p].opponent].side = - (parray[parray[p].opponent].side == WHITE) ? BLACK : WHITE; - /* Roll back the time */ - if (garray[g].game_state.onMove == WHITE) { - garray[g].wTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } else { - garray[g].bTime += (garray[g].lastDecTime - garray[g].lastMoveTime); - } - now = tenth_secs(); - if (garray[g].numHalfMoves == 0) - garray[g].timeOfStart = now; - garray[g].lastMoveTime = now; - garray[g].lastDecTime = now; - send_boards(g); - return COM_OK; - } - if (garray[g].rated && garray[g].numHalfMoves > 0) { - pprintf(p, "You cannot switch sides once a rated game is underway.\n"); - return COM_OK; - } - pprintf(parray[p].opponent, "\n"); - pprintf_highlight(parray[p].opponent, "%s", parray[p].name); - pprintf_prompt(parray[p].opponent, " would like to switch sides.\nType \"accept\" to switch sides, or \"decline\" to refuse.\n"); - pprintf(p, "Switch request sent.\n"); - player_add_request(p, parray[p].opponent, PEND_SWITCH, 0); - return COM_OK; + if (!pIsPlaying(p)) + return COM_OK; + + p1 = parray[p].opponent; + + if (parray[p1].simul_info.numBoards && + parray[p1].simul_info.boards[parray[p1].simul_info.onBoard] != g) { + pprintf(p, "You can only make requests when the simul player " + "is at your board.\n"); + return COM_OK; + } + + if (garray[g].link >= 0) { + pprintf(p, "Switch not implemented for bughouse games.\n"); + return COM_OK; + } + + if (player_find_pendfrom(p, parray[p].opponent, PEND_SWITCH) >= 0) { + player_remove_request(parray[p].opponent, p, PEND_SWITCH); + player_decline_offers(p, -1, -PEND_SIMUL); + + tmp = garray[g].white; + garray[g].white = garray[g].black; + garray[g].black = tmp; + parray[p].side = (parray[p].side == WHITE ? BLACK : WHITE); + + strTmp = xstrdup(garray[g].white_name); + strcpy(garray[g].white_name, garray[g].black_name); + strcpy(garray[g].black_name, strTmp); + strfree(strTmp); + + parray[parray[p].opponent].side = + (parray[parray[p].opponent].side == WHITE ? BLACK : WHITE); + + // Roll back the time + if (garray[g].game_state.onMove == WHITE) { + garray[g].wTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } else { + garray[g].bTime += (garray[g].lastDecTime - + garray[g].lastMoveTime); + } + + now = tenth_secs(); + + if (garray[g].numHalfMoves == 0) + garray[g].timeOfStart = now; + + garray[g].lastMoveTime = now; + garray[g].lastDecTime = now; + + send_boards(g); + return COM_OK; + } + + if (garray[g].rated && garray[g].numHalfMoves > 0) { + pprintf(p, "You cannot switch sides once a rated game is " + "underway.\n"); + return COM_OK; + } + + pprintf(parray[p].opponent, "\n"); + pprintf_highlight(parray[p].opponent, "%s", parray[p].name); + pprintf_prompt(parray[p].opponent, " would like to switch sides.\n" + "Type \"accept\" to switch sides, or \"decline\" to refuse.\n"); + pprintf(p, "Switch request sent.\n"); + player_add_request(p, parray[p].opponent, PEND_SWITCH, 0); + + return COM_OK; } PUBLIC int |