From cbaa24d062e1ecebc90fd8b671a1c68daa70664b Mon Sep 17 00:00:00 2001 From: scw Date: Fri, 2 Sep 2005 13:15:30 +0000 Subject: * refine chess framework IO routines * don't write data to user socket when there is no opposite git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3124 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/chess.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'mbbsd/chess.c') diff --git a/mbbsd/chess.c b/mbbsd/chess.c index 900b39c7..72632357 100644 --- a/mbbsd/chess.c +++ b/mbbsd/chess.c @@ -254,28 +254,17 @@ ChessSendMove(ChessInfo* info, int sock, const void *step) return 1; } -ChessStepType -ChessStepReceive(ChessInfo* info, void* step) -{ - ChessStepType result = ChessRecvMove(info, info->sock, step); - - /* automatical routing */ - if (result != CHESS_STEP_FAILURE) - ChessStepBroadcast(info, step); - - /* and logging */ - if (result == CHESS_STEP_NORMAL) - ChessHistoryAppend(info, step); - - return result; -} - -int +inline static int ChessStepSendOpposite(ChessInfo* info, const void* step) { void (*orig_handler)(int); int result = 1; - + + /* fd 0 is the socket to user, it means no oppisite available. + * (Might be personal play) */ + if (info->sock == 0) + return 1; + orig_handler = Signal(SIGPIPE, SIG_IGN); if (!ChessSendMove(info, info->sock, step)) @@ -285,7 +274,7 @@ ChessStepSendOpposite(ChessInfo* info, const void* step) return result; } -void +inline static void ChessStepBroadcast(ChessInfo* info, const void *step) { ChessBroadcastListNode *p = &(info->broadcast_list.head); @@ -325,6 +314,22 @@ ChessMessageSend(ChessInfo* info, ChessStepType type) return ChessStepSend(info, &type); } +ChessStepType +ChessStepReceive(ChessInfo* info, void* step) +{ + ChessStepType result = ChessRecvMove(info, info->sock, step); + + /* automatical routing */ + if (result != CHESS_STEP_FAILURE) + ChessStepBroadcast(info, step); + + /* and logging */ + if (result == CHESS_STEP_NORMAL) + ChessHistoryAppend(info, step); + + return result; +} + inline static void ChessReplayUntil(ChessInfo* info, int n) { -- cgit v1.2.3