summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-08-10 09:47:34 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-08-10 09:47:34 +0800
commit4fe6fa6ea16743f6e6f265e1131df3bff3767116 (patch)
tree06fe4785b0e53dc726d3d720e31de1b998d8a231
parentb9f694e971dd74723e1cf3cd837b385c02820194 (diff)
downloadpttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar.gz
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar.bz2
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar.lz
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar.xz
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.tar.zst
pttbbs-4fe6fa6ea16743f6e6f265e1131df3bff3767116.zip
* fix chc watching SEGV bug
* chc.[ch] and chess.[ch] code clean up git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3022 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/bbs.h1
-rw-r--r--include/chc.h34
-rw-r--r--include/chess.h18
-rw-r--r--mbbsd/chc.c18
-rw-r--r--mbbsd/chess.c3
5 files changed, 24 insertions, 50 deletions
diff --git a/include/bbs.h b/include/bbs.h
index 81be4808..4931ef99 100644
--- a/include/bbs.h
+++ b/include/bbs.h
@@ -51,7 +51,6 @@ typedef time_t time4_t;
#include "common.h"
#include "perm.h"
#include "modes.h"
-#include "chc.h"
#include "chess.h"
#include "proto.h"
diff --git a/include/chc.h b/include/chc.h
index f6512563..900d4dd1 100644
--- a/include/chc.h
+++ b/include/chc.h
@@ -1,11 +1,3 @@
-/* 象棋
- * 雙人對戰時,雙方都會有一個 chc_act_list 的 linked-list,紀錄著每下一步
- * 棋,必須將這個訊息丟給那些人(socket)。
- * 一開始當然就是對手一個,每當一個觀棋者加入(觀棋可以從紅方或黑方的觀點
- * 進行),其中一方的下棋者的 act_list 就會多一筆記錄,之後就會將下的或收
- * 到對方下的每一步棋傳給 act_list 中所有需要的人,達到觀棋的效果。
- */
-
#define SIDE_ROW 7
#define REAL_TURN_ROW 8
#define STEP_ROW 9
@@ -20,16 +12,6 @@
#define PHOTO_TIME_ROW2 21
#define PHOTO_WARN_ROW 22
-/* virtual lines */
-#define TURN_ROW 128
-#define TIME_ROW 129
-#define WARN_ROW 130
-
-#define CHC_VERSUS 1 /* 雙人 */
-#define CHC_WATCH 2 /* 觀棋 */
-#define CHC_PERSONAL 4 /* 打譜 */
-#define CHC_WATCH_PERSONAL 8 /* 觀人打譜 */
-
#define CHE_O(c) ((c) >> 3)
#define CHE_P(c) ((c) & 7)
#define dim(x) (sizeof(x) / sizeof(x[0]))
@@ -46,22 +28,6 @@
#define RED_REVERSE ANSI_COLOR(1;37;41)
#define TURN_COLOR ANSI_COLOR(1;33)
-typedef struct chcusr_t{
- char userid[IDLEN + 1];
- int win;
- int lose;
- int tie;
- unsigned short rating;
- unsigned short orig_rating; // 原始 rating, 因為遊戲開始先算輸一場, rating 值就跑掉了
-} chcusr_t;
-
-#define CHC_ACT_BOARD 0x1 /* set if transfered board to this sock */
-
-typedef struct chc_act_list{
- int sock;
- struct chc_act_list *next;
-} chc_act_list;
-
#define BRD_ROW 10
#define BRD_COL 9
diff --git a/include/chess.h b/include/chess.h
index 766486aa..bf9443ce 100644
--- a/include/chess.h
+++ b/include/chess.h
@@ -35,6 +35,14 @@ private typedef struct {
void *body;
} ChessHistory;
+/* 棋類觀戰
+ *
+ * 雙人對戰時,雙方都會有一個 broadcast_list 的 linked-list,紀錄著每下一
+ * 步棋,必須將這個訊息丟給那些人(sock)。
+ * 每當一個觀棋者加入(觀棋可以從紅方或黑方的觀點進行),其中一方的下棋者
+ * 的 broadcast_list 就會多一筆記錄,之後就會將下的或收到對方下的每一步棋
+ * 傳給 broadcast_list 中所有需要的人,達到觀棋的效果。
+ */
private typedef struct ChessBroadcastListNode {
int sock;
struct ChessBroadcastListNode *next;
@@ -112,7 +120,7 @@ typedef struct ChessInfo {
typedef struct ChessActions {
/* initial */
- void (*init_user) (const userec_t* rec, ChessUser* user);
+ void (*init_user) (const userinfo_t* uinfo, ChessUser* user);
void (*init_board) (void* board);
/* playing */
@@ -135,10 +143,10 @@ typedef struct ChessConstants {
int traditional_timeout;
int board_height;
int board_width;
- char *photo_file_name;
- char *log_board;
- char *turn_color[2];
- char *turn_str[2];
+ const char *photo_file_name;
+ const char *log_board;
+ const char *turn_color[2];
+ const char *turn_str[2];
} ChessConstants;
typedef enum {
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index efed0041..6f53bc8b 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -1,6 +1,6 @@
/* $Id$ */
#include "bbs.h"
-#include "chess.h"
+#include "chc.h"
#define assert_not_reached() assert(!"Should never be here!!!")
@@ -37,8 +37,8 @@ typedef struct {
} chc_tag_data_t;
/* chess framework action functions */
-static void chc_init_user(const userinfo_t *userec, ChessUser *user);
-static void chc_init_board(const ChessInfo* info, board_t board);
+static void chc_init_user(const userinfo_t *uinfo, ChessUser *user);
+static void chc_init_board(board_t board);
static void chc_drawline(const ChessInfo* info, int line);
static void chc_movecur(int r, int c);
static void chc_prepare_play(ChessInfo* info);
@@ -435,7 +435,7 @@ chc_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
else
fprintf(fp, "%s V.S. %s\n", info->user2.userid, info->user1.userid);
- chc_init_board(info, board);
+ chc_init_board(board);
for (i = 0; i < nStep; ++i) {
const drc_t *move = (const drc_t*) ChessHistoryRetrieve(info, i);
chc_log_step(fp, board, move);
@@ -465,7 +465,7 @@ chc_genlog(ChessInfo* info, FILE* fp, ChessGameResult result)
* Start of the rule function.
*/
static void
-chc_init_board(const ChessInfo* info, board_t board)
+chc_init_board(board_t board)
{
memset(board, 0, sizeof(board_t));
board[0][4] = CHE(KIND_K, BLK); /* 將 */
@@ -777,9 +777,7 @@ chc_select(ChessInfo* info, rc_t scrloc, ChessGameResult* result)
chc_drawline(info, LTR(info, moving.to.r));
ChessHistoryAppend(info, &moving);
- ChessStepBroadcast(info, &moving);
-
- ChessStepSendOpposite(info, &moving);
+ ChessStepSend(info, &moving);
tag->selected = 0;
return 1;
@@ -789,7 +787,7 @@ chc_select(ChessInfo* info, rc_t scrloc, ChessGameResult* result)
ANSI_COLOR(1;33) "不可以王見王" ANSI_RESET,
sizeof(info->warnmsg));
bell();
- chc_drawline(info, WARN_ROW);
+ chc_drawline(info, REAL_WARN_ROW);
return 0;
}
} else
@@ -857,7 +855,7 @@ chc(int s, ChessGameMode mode)
board_t board;
chc_tag_data_t tag;
- chc_init_board(info, board);
+ chc_init_board(board);
tag.selected = 0;
info->board = board;
diff --git a/mbbsd/chess.c b/mbbsd/chess.c
index 04a05f03..d6b1a292 100644
--- a/mbbsd/chess.c
+++ b/mbbsd/chess.c
@@ -1089,6 +1089,9 @@ NewChessInfo(const ChessActions* actions, const ChessConstants* constants,
ChessInfo* info =
(ChessInfo*) calloc(1, sizeof(ChessInfo) + constants->step_entry_size);
+ if (mode == CHESS_MODE_PERSONAL)
+ strcpy(currutmp->mateid, cuser.userid);
+
/* compiler don't know it's actually const... */
info->actions = (ChessActions*) actions;
info->constants = (ChessConstants*) constants;