diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2013-06-26 00:04:21 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2013-06-26 00:04:21 +0800 |
commit | 58ea65d223336b5b34117c5b4ac1b246b387310a (patch) | |
tree | cd0c9e33d80eba4f26fe2221cef546bfd0063583 | |
parent | 61565ee62d5d618c647030f1beb5971ecb2bc1f3 (diff) | |
download | pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar.gz pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar.bz2 pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar.lz pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar.xz pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.tar.zst pttbbs-58ea65d223336b5b34117c5b4ac1b246b387310a.zip |
Fix reversi log writing and reading mishandling passes.
Reported by winsoy@ptt.cc, #1HmsFTVD & #1HmyOca7 (PttBug)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5848 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/mbbsd/ch_reversi.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/pttbbs/mbbsd/ch_reversi.c b/pttbbs/mbbsd/ch_reversi.c index 1a4a6d1f..3e5a4869 100644 --- a/pttbbs/mbbsd/ch_reversi.c +++ b/pttbbs/mbbsd/ch_reversi.c @@ -227,11 +227,18 @@ reversi_prepare_play(ChessInfo* info) if (result) { reversi_step_t step = { .type = CHESS_STEP_SPECIAL, .color = TURN_TO_COLOR(info->turn) }; if (info->turn == info->myturn) { - ChessStepSend(info, &step); - ChessHistoryAppend(info, &step); + if (info->mode == CHESS_MODE_VERSUS || + info->mode == CHESS_MODE_PERSONAL) { + ChessStepSend(info, &step); + ChessHistoryAppend(info, &step); + } strcpy(info->last_movestr, "你必須放棄這一步!!"); } else { - ChessStepReceive(info, &step); + if (info->mode == CHESS_MODE_VERSUS || + info->mode == CHESS_MODE_PERSONAL) { + ChessStepReceive(info, &step); + ChessHistoryAppend(info, &step); + } strcpy(info->last_movestr, "對方必須放棄這一步!!"); } } @@ -405,14 +412,26 @@ reversi_loadlog(FILE *fp, ChessInfo *info) reversi_init_user_userec(&rec, user); } else if (buf[0] == '[') { /* "[ 1]● ==> C4 [ 2]○ ==> C5" */ - reversi_step_t step = { .type = CHESS_STEP_NORMAL }; int c, r; const char *p = buf; int i; for(i=0; i<2; i++) { - p = strchr(p, '>'); + reversi_step_t step = { .type = CHESS_STEP_NORMAL }; + + p = strchr(p, ']'); + if (p == NULL) break; + + ++p; /* skip ']' */ + while (*p && isspace(*p)) ++p; + if (!*p) break; + + if (strncmp(WHITE_CHESS, p, strlen(WHITE_CHESS)) == 0) + step.color = WHITE; + else /* strncmp(BLACK_CHESS, p, 2) == 0 */ + step.color = BLACK; + p = strchr(p, '>'); if (p == NULL) break; ++p; /* skip '>' */ @@ -436,7 +455,6 @@ reversi_loadlog(FILE *fp, ChessInfo *info) step.loc.c = c; } - step.color = i==0 ? BLACK : WHITE; ChessHistoryAppend(info, &step); } } |