summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h2
-rw-r--r--mbbsd/bbs.c3
-rw-r--r--mbbsd/ch_go.c31
-rw-r--r--mbbsd/ch_gomo.c31
-rw-r--r--mbbsd/chc.c37
-rw-r--r--mbbsd/passwd.c107
6 files changed, 128 insertions, 83 deletions
diff --git a/include/proto.h b/include/proto.h
index 6b14f475..1276c1f1 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -706,6 +706,8 @@ int pwcuSetLoginView (unsigned int bits);
int pwcuSetLastSongTime (time4_t clk);
int pwcuSetMyAngel (const char *angel_uid);
int pwcuSetNickname (const char *nickname);
+int pwcuChessResult (int sigType, ChessGameResult);
+int pwcuSetChessEloRating(uint16_t elo_rating);
// non-important based variables (only save on exit)
int pwcuSetSignature (unsigned char newsig);
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index f0356a46..aeffdc27 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -2428,9 +2428,6 @@ recommend(int ent, fileheader_t * fhdr, const char *direct)
int isGuest = (strcmp(cuser.userid, STR_GUEST) == EQUSTR);
int logIP = 0;
int ymsg = b_lines -1;
-#ifdef ASSESS
- char oldrecom = fhdr->recommend;
-#endif // ASSESS
if (!fhdr || !fhdr->filename[0])
return DONOTHING;
diff --git a/mbbsd/ch_go.c b/mbbsd/ch_go.c
index a9e68005..308061b8 100644
--- a/mbbsd/ch_go.c
+++ b/mbbsd/ch_go.c
@@ -793,35 +793,14 @@ go_post_game(ChessInfo* info)
}
static void
-go_usr_put(userec_t* userec, const ChessUser* user)
-{
- userec->go_win = user->win;
- userec->go_lose = user->lose;
- userec->go_tie = user->tie;
-}
-
-static void
go_gameend(ChessInfo* info, ChessGameResult result)
{
if (info->mode == CHESS_MODE_VERSUS) {
- ChessUser* const user1 = &info->user1;
- /* ChessUser* const user2 = &info->user2; */
-
- user1->lose--;
- if (result == CHESS_RESULT_WIN) {
- user1->win++;
- currutmp->go_win++;
- } else if (result == CHESS_RESULT_LOST) {
- user1->lose++;
- currutmp->go_lose++;
- } else {
- user1->tie++;
- currutmp->go_tie++;
- }
- go_usr_put(cuser_ref, user1);
+ // lost was already initialized
+ if (result != CHESS_RESULT_LOST)
+ pwcuChessResult(SIG_GO, result);
- passwd_sync_update(usernum, cuser_ref);
} else if (info->mode == CHESS_MODE_REPLAY) {
free(info->board);
free(info->tag);
@@ -936,9 +915,7 @@ gochess(int s, ChessGameMode mode)
if (info->mode == CHESS_MODE_VERSUS) {
/* Assume that info->user1 is me. */
info->user1.lose++;
- passwd_sync_query(usernum, cuser_ref);
- go_usr_put(cuser_ref, &info->user1);
- passwd_sync_update(usernum, cuser_ref);
+ pwcuChessResult(SIG_GO, CHESS_RESULT_LOST);
}
if (mode == CHESS_MODE_WATCH)
diff --git a/mbbsd/ch_gomo.c b/mbbsd/ch_gomo.c
index 0bffe04a..fb1a4182 100644
--- a/mbbsd/ch_gomo.c
+++ b/mbbsd/ch_gomo.c
@@ -230,14 +230,6 @@ gomo_move_warn(int style, char buf[])
return NULL;
}
-static void
-gomoku_usr_put(userec_t* userec, const ChessUser* user)
-{
- userec->five_win = user->win;
- userec->five_lose = user->lose;
- userec->five_tie = user->tie;
-}
-
static char*
gomo_getstep(const gomo_step_t* step, char buf[])
{
@@ -395,24 +387,11 @@ static void
gomo_gameend(ChessInfo* info, ChessGameResult result)
{
if (info->mode == CHESS_MODE_VERSUS) {
- ChessUser* const user1 = &info->user1;
- /* ChessUser* const user2 = &info->user2; */
-
- user1->lose--;
- if (result == CHESS_RESULT_WIN) {
- user1->win++;
- currutmp->five_win++;
- } else if (result == CHESS_RESULT_LOST) {
- user1->lose++;
- currutmp->five_lose++;
- } else {
- user1->tie++;
- currutmp->five_tie++;
- }
- gomoku_usr_put(cuser_ref, user1);
+ // lost was already initialized
+ if (result != CHESS_RESULT_LOST)
+ pwcuChessResult(SIG_GOMO, result);
- passwd_sync_update(usernum, cuser_ref);
} else if (info->mode == CHESS_MODE_REPLAY) {
free(info->board);
free(info->tag);
@@ -535,9 +514,7 @@ gomoku(int s, ChessGameMode mode)
if (info->mode == CHESS_MODE_VERSUS) {
/* Assume that info->user1 is me. */
info->user1.lose++;
- passwd_sync_query(usernum, cuser_ref);
- gomoku_usr_put(cuser_ref, &info->user1);
- passwd_sync_update(usernum, cuser_ref);
+ pwcuChessResult(SIG_GOMO, CHESS_RESULT_LOST);
}
if (mode == CHESS_MODE_WATCH)
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index 2a52f43b..6d4a2f4e 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -658,15 +658,6 @@ chc_ischeck(board_t board, int turn)
*/
static void
-chcusr_put(userec_t* userec, const ChessUser* user)
-{
- userec->chc_win = user->win;
- userec->chc_lose = user->lose;
- userec->chc_tie = user->tie;
- userec->chess_elo_rating = user->rating;
-}
-
-static void
chc_init_user(const userinfo_t *uinfo, ChessUser *user)
{
strlcpy(user->userid, uinfo->userid, sizeof(user->userid));
@@ -848,9 +839,7 @@ chc(int s, ChessGameMode mode)
/* Assume that info->user1 is me. */
info->user1.lose++;
count_chess_elo_rating(&info->user1, &info->user2, 0.0);
- passwd_sync_query(usernum, cuser_ref);
- chcusr_put(cuser_ref, &info->user1);
- passwd_sync_update(usernum, cuser_ref);
+ pwcuChessResult(SIG_CHC, CHESS_RESULT_LOST);
}
if (mode == CHESS_MODE_WATCH)
@@ -876,36 +865,38 @@ chc_gameend(ChessInfo* info, ChessGameResult result)
/* NOTE, 若紅方斷線則無 log */
time_t t = time(NULL);
char buf[100];
+ uint16_t lose1 = user1->lose, lose2 = user2->lose;
+ if (lose1 > 0) lose1--;
+ if (lose2 > 0) lose2--;
sprintf(buf, "%s %s(%d,W%d/D%d/L%d) %s %s(%d,W%d/D%d/L%d)\n",
ctime(&t),
user1->userid, user1->rating, user1->win,
- user1->tie, user1->lose - 1,
+ user1->tie, lose1,
(result == CHESS_RESULT_TIE ? "和" :
result == CHESS_RESULT_WIN ? "勝" : "負"),
user2->userid, user2->rating, user2->win,
- user2->tie, user2->lose - 1);
+ user2->tie, lose2);
buf[24] = ' '; // replace '\n'
log_file(BBSHOME "/log/chc.log", LOG_CREAT, buf);
}
+ // lost was already initialized
+ if (result != CHESS_RESULT_LOST)
+ pwcuChessResult(SIG_CHC, result);
+
user1->rating = user1->orig_rating;
- user1->lose--;
+
+ // TODO update and save the elo rating
if (result == CHESS_RESULT_WIN) {
count_chess_elo_rating(user1, user2, 1.0);
- user1->win++;
- currutmp->chc_win++;
} else if (result == CHESS_RESULT_LOST) {
count_chess_elo_rating(user1, user2, 0.0);
- user1->lose++;
- currutmp->chc_lose++;
} else {
count_chess_elo_rating(user1, user2, 0.5);
- user1->tie++;
- currutmp->chc_tie++;
}
currutmp->chess_elo_rating = user1->rating;
- chcusr_put(cuser_ref, user1);
- passwd_sync_update(usernum, cuser_ref);
+ pwcuSetChessEloRating(user1->rating);
+
} else if (info->mode == CHESS_MODE_REPLAY) {
free(info->board);
free(info->tag);
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index 2bdc93fd..61e472a8 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -111,7 +111,8 @@ pwcuFinalCUser(userec_t *u)
#define PWCU_END() if (pwcuFinalCUser(&u) != 0) return -1; return 0
#define _ENABLE_BIT( var,mask) var |= (mask)
-#define _DISABLE_BIT(var,mask) var &= ~(mask)
+#define _DISABLE_BIT(var,mask) var &= ~(mask)
+#define _SETBY_BIT(var,mask,val) if (val) { _ENABLE_BIT(var, (mask)); } else { _DISABLE_BIT(var, (mask)); }
int pwcuBitEnableLevel (unsigned int mask)
{
@@ -207,8 +208,8 @@ pwcuToggleOutMail()
{
PWCU_START();
u.uflag2 ^= REJ_OUTTAMAIL;
- cuser.uflag2 &= ~REJ_OUTTAMAIL;
- cuser.uflag2 |= (REJ_OUTTAMAIL & u.uflag2);
+ _SETBY_BIT(cuser.uflag2, REJ_OUTTAMAIL,
+ u.uflag2 & REJ_OUTTAMAIL);
PWCU_END();
}
@@ -221,6 +222,106 @@ pwcuSetLoginView(unsigned int bits)
PWCU_END();
}
+#include "chess.h"
+int
+pwcuChessResult(int sigType, ChessGameResult r)
+{
+ uint16_t *utmp_win = NULL, *cuser_win = NULL, *u_win = NULL,
+ *utmp_lose= NULL, *cuser_lose= NULL, *u_lose= NULL,
+ *utmp_tie = NULL, *cuser_tie = NULL, *u_tie = NULL;
+
+ PWCU_START();
+
+ // verify variable size
+ assert(sizeof(* utmp_win) == sizeof(currutmp->chc_win));
+ assert(sizeof(*cuser_lose)== sizeof( cuser.five_lose));
+ assert(sizeof(* u_tie) == sizeof( u.go_tie));
+
+ // determine variables
+ switch(sigType)
+ {
+ case SIG_CHC:
+ utmp_win = &(currutmp->chc_win);
+ utmp_lose = &(currutmp->chc_lose);
+ utmp_tie = &(currutmp->chc_tie);
+ cuser_win = &( cuser.chc_win);
+ cuser_lose= &( cuser.chc_lose);
+ cuser_tie = &( cuser.chc_tie);
+ u_win = &( u.chc_win);
+ u_lose = &( u.chc_lose);
+ u_tie = &( u.chc_tie);
+ break;
+
+ case SIG_GO:
+ utmp_win = &(currutmp->go_win);
+ utmp_lose = &(currutmp->go_lose);
+ utmp_tie = &(currutmp->go_tie);
+ cuser_win = &( cuser.go_win);
+ cuser_lose= &( cuser.go_lose);
+ cuser_tie = &( cuser.go_tie);
+ u_win = &( u.go_win);
+ u_lose = &( u.go_lose);
+ u_tie = &( u.go_tie);
+ break;
+
+ case SIG_GOMO:
+ utmp_win = &(currutmp->five_win);
+ utmp_lose = &(currutmp->five_lose);
+ utmp_tie = &(currutmp->five_tie);
+ cuser_win = &( cuser.five_win);
+ cuser_lose= &( cuser.five_lose);
+ cuser_tie = &( cuser.five_tie);
+ u_win = &( u.five_win);
+ u_lose = &( u.five_lose);
+ u_tie = &( u.five_tie);
+ break;
+
+ default:
+ assert(!"unknown sigtype");
+ break;
+ }
+
+ // perform action
+ switch(r)
+ {
+ case CHESS_RESULT_WIN:
+ *utmp_win = *cuser_win =
+ ++(*u_win);
+ // recover init lose
+ if (*u_lose > 0)
+ *utmp_lose = *cuser_lose =
+ --(*u_lose);
+ break;
+
+ case CHESS_RESULT_TIE:
+ *utmp_tie = *cuser_tie =
+ ++*u_tie;
+ // recover init lose
+ if (*u_lose > 0)
+ *utmp_lose = *cuser_lose =
+ --(*u_lose);
+ break;
+
+ case CHESS_RESULT_LOST:
+ *utmp_lose = *cuser_lose =
+ ++(*u_lose);
+ break;
+
+ default:
+ assert(!"unknown result");
+ return -1;
+ }
+
+ PWCU_END();
+}
+
+int
+pwcuSetChessEloRating(uint16_t elo_rating)
+{
+ PWCU_START();
+ cuser.chess_elo_rating = u.chess_elo_rating = elo_rating;
+ PWCU_END();
+}
// non-important variables (only save on exit)