summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-12 19:25:53 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2006-03-12 19:25:53 +0800
commitb729272d521985d2656660d2f83a3a29c8f6ec8f (patch)
treee3e9d4dd1ddf67e5499cab0479d52af52c721264
parent097b557f8d8698c6992a4fdb510f76fd07229b64 (diff)
downloadpttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar.gz
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar.bz2
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar.lz
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar.xz
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.tar.zst
pttbbs-b729272d521985d2656660d2f83a3a29c8f6ec8f.zip
GO scoring and displaying on userlist.
!!!NOTE: shared memory changed!!! git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3276 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/pttstruct.h12
-rw-r--r--mbbsd/cache.c6
-rw-r--r--mbbsd/go.c36
-rw-r--r--mbbsd/talk.c16
-rw-r--r--mbbsd/user.c8
-rw-r--r--mbbsd/var.c1
-rw-r--r--util/shmctl.c30
7 files changed, 83 insertions, 26 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 362f3dd0..575dd76d 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -97,7 +97,10 @@ typedef struct userec_t {
unsigned short chc_tie; /* 象棋戰績 和 */
int mobile; /* 手機號碼 */
char mind[4]; /* 心情 not a null-terminate string */
- char pad0[11]; /* 從前放 ident 身份證字號,現在可以拿來做別的事了,
+ unsigned short go_win; /* 圍祺戰績 勝 */
+ unsigned short go_lose; /* 圍祺戰績 敗 */
+ unsigned short go_tie; /* 圍祺戰績 和 */
+ char pad0[5]; /* 從前放 ident 身份證字號,現在可以拿來做別的事了,
不過最好記得要先清成 0 */
unsigned char signature; /* 慣用簽名檔 */
@@ -411,6 +414,9 @@ typedef struct userinfo_t {
unsigned short int chc_lose;
unsigned short int chc_tie;
unsigned short int chess_elo_rating;
+ unsigned short int go_win;
+ unsigned short int go_lose;
+ unsigned short int go_tie;
/* misc */
unsigned int withme;
@@ -486,7 +492,7 @@ typedef struct keeploc_t {
/* MAX_BMs is dirty hardcode 4 in mbbsd/cache.c:is_BM_cache() */
#define MAX_BMs 4 /* for BMcache, 一個看板最多幾板主 */
-#define SHM_VERSION 2582
+#define SHM_VERSION 3276
typedef struct {
int version;
/* uhash */
@@ -509,7 +515,7 @@ typedef struct {
/* utmpshm */
userinfo_t uinfo[USHM_SIZE];
char gap_6[sizeof(userinfo_t)];
- int sorted[2][8][USHM_SIZE];
+ int sorted[2][9][USHM_SIZE];
/* 第一維double buffer 由currsorted指向目前使用的
第二維sort type */
char gap_7[sizeof(int)];
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index a3bace26..8063d80c 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -319,7 +319,7 @@ search_ulist_pid(int pid)
register userinfo_t *u;
if (end == -1)
return NULL;
- ulist = SHM->sorted[SHM->currsorted][7];
+ ulist = SHM->sorted[SHM->currsorted][8];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
u = &SHM->uinfo[ulist[i]];
j = pid - u->pid;
@@ -347,7 +347,7 @@ search_ulistn(int uid, int unum)
register userinfo_t *u;
if (end == -1)
return NULL;
- ulist = SHM->sorted[SHM->currsorted][6];
+ ulist = SHM->sorted[SHM->currsorted][7];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
u = &SHM->uinfo[ulist[i]];
j = uid - u->uid;
@@ -410,7 +410,7 @@ count_logins(int uid, int show)
userinfo_t *u;
if (end == -1)
return 0;
- ulist = SHM->sorted[SHM->currsorted][6];
+ ulist = SHM->sorted[SHM->currsorted][7];
for (i = ((start + end) / 2);; i = (start + end) / 2) {
u = &SHM->uinfo[ulist[i]];
j = uid - u->uid;
diff --git a/mbbsd/go.c b/mbbsd/go.c
index 4611fb49..87d849e0 100644
--- a/mbbsd/go.c
+++ b/mbbsd/go.c
@@ -451,18 +451,18 @@ static void
go_init_user(const userinfo_t* uinfo, ChessUser* user)
{
strlcpy(user->userid, uinfo->userid, sizeof(user->userid));
- user->win = 0;
- user->lose = 0;
- user->tie = 0;
+ user->win = uinfo->go_win;
+ user->lose = uinfo->go_lose;
+ user->tie = uinfo->go_tie;
}
static void
go_init_user_userec(const userec_t* urec, ChessUser* user)
{
strlcpy(user->userid, urec->userid, sizeof(user->userid));
- user->win = 0;
- user->lose = 0;
- user->tie = 0;
+ user->win = urec->go_win;
+ user->lose = urec->go_lose;
+ user->tie = urec->go_tie;
}
static void
@@ -793,8 +793,28 @@ go_post_game(ChessInfo* info)
static void
go_gameend(ChessInfo* info, ChessGameResult result)
{
- /* TODO: implement */
- if (info->mode == CHESS_MODE_REPLAY) {
+ 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++;
+ }
+
+ cuser.go_win = user1->win;
+ cuser.go_lose = user1->lose;
+ cuser.go_tie = user1->tie;
+
+ passwd_update(usernum, &cuser);
+ } else if (info->mode == CHESS_MODE_REPLAY) {
free(info->board);
free(info->tag);
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index f53476b3..f5e0f9ad 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -13,7 +13,7 @@ static char * const withme_str[] = {
"談天", "下五子棋", "鬥寵物", "下象棋", "下暗棋", "下圍棋", NULL
};
-#define MAX_SHOW_MODE 5
+#define MAX_SHOW_MODE 6
#define M_INT 15 /* monitor mode update interval */
#define P_INT 20 /* interval to check for page req. in
* talk/chat */
@@ -31,7 +31,7 @@ typedef struct pickup_t {
/* 記錄 friend 的 user number */
//
-#define PICKUP_WAYS 7
+#define PICKUP_WAYS 8
static char * const fcolor[11] = {
"", ANSI_COLOR(36), ANSI_COLOR(32), ANSI_COLOR(1;32),
@@ -1842,6 +1842,12 @@ descript(int show_mode, const userinfo_t * uentp, int diff)
"%4d %s", uentp->chess_elo_rating,
(uentp->withme&WITHME_CHESS)?"找我下棋":(uentp->withme&WITHME_NOCHESS)?"別找我":"");
return description;
+ case 5:
+ snprintf(description, sizeof(description),
+ "%4d/%4d/%2d %c", uentp->go_win,
+ uentp->go_lose, uentp->go_tie,
+ (uentp->withme&WITHME_GO)?'o':(uentp->withme&WITHME_NOGO)?'x':' ');
+ return description;
default:
syslog(LOG_WARNING, "damn!!! what's wrong?? show_mode = %d",
show_mode);
@@ -2069,10 +2075,10 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way,
int show_pid, int myfriend, int friendme, int bfriend, int badfriend)
{
char *msg_pickup_way[PICKUP_WAYS] = {
- "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", " 五子棋 ", " 象棋 "
+ "嗨! 朋友", "網友代號", "網友動態", "發呆時間", "來自何方", " 五子棋 ", " 象棋 ", " 圍棋 ",
};
char *MODE_STRING[MAX_SHOW_MODE] = {
- "故鄉", "好友描述", "五子棋戰績", "象棋戰績", "象棋等級分",
+ "故鄉", "好友描述", "五子棋戰績", "象棋戰績", "象棋等級分", "圍棋戰績",
};
char pagerchar[5] = "* -Wf";
@@ -2656,6 +2662,8 @@ userlist(void)
user_query_mode = 1;
else if (show_mode == 3 || show_mode == 4)
user_query_mode = 2;
+ else if (show_mode == 5)
+ user_query_mode = 3;
else
user_query_mode = 0;
#endif /* defined(CHESSCOUNTRY) */
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 0cc785b9..fa4de3c1 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -6,12 +6,12 @@ static char * const sex[8] = {
};
#ifdef CHESSCOUNTRY
-static const char * const chess_photo_name[2] = {
- "photo_fivechess", "photo_cchess"
+static const char * const chess_photo_name[3] = {
+ "photo_fivechess", "photo_cchess", "photo_go",
};
-static const char * const chess_type[2] = {
- "五子棋", "象棋"
+static const char * const chess_type[3] = {
+ "五子棋", "象棋", "圍棋",
};
#endif
diff --git a/mbbsd/var.c b/mbbsd/var.c
index e44abd9d..3dc46b82 100644
--- a/mbbsd/var.c
+++ b/mbbsd/var.c
@@ -398,6 +398,7 @@ int user_query_mode;
* user_query_mode = 0 simple data
* = 1 gomoku chess country data
* = 2 chc chess country data
+ * = 3 go chess country data
*/
#endif /* defined(CHESSCOUNTRY) */
diff --git a/util/shmctl.c b/util/shmctl.c
index 0699d601..a1dabe31 100644
--- a/util/shmctl.c
+++ b/util/shmctl.c
@@ -338,6 +338,25 @@ cmputmpchc(const void * i, const void * j)
}
static int
+cmputmpgo(const void * i, const void * j)
+{
+ userinfo_t *a=&SHM->uinfo[*(int*)i],*b=&SHM->uinfo[*(int*)j];
+ int played_a=(a->go_win+a->go_lose+a->go_tie)!=0;
+ int played_b=(b->go_win+b->go_lose+b->go_tie)!=0;
+ int type;
+
+ if ((type = played_b - played_a))
+ return type;
+ if (played_a == 0)
+ return 0;
+ if ((type = b->go_win - a->go_win))
+ return type;
+ if ((type = a->go_lose - b->go_lose))
+ return type;
+ return a->go_tie - b->go_tie;
+}
+
+static int
cmputmppid(const void * i, const void * j)
{
return SHM->uinfo[*(int*)i].pid - SHM->uinfo[*(int*)j].pid;
@@ -376,12 +395,12 @@ inline void utmpsort(int sortall)
}
SHM->UTMPnumber = count;
qsort(SHM->sorted[ns][0], count, sizeof(int), cmputmpuserid);
- memcpy(SHM->sorted[ns][6],
- SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][7],
SHM->sorted[ns][0], sizeof(int) * count);
- qsort(SHM->sorted[ns][6], count, sizeof(int), cmputmpuid);
- qsort(SHM->sorted[ns][7], count, sizeof(int), cmputmppid);
+ memcpy(SHM->sorted[ns][8],
+ SHM->sorted[ns][0], sizeof(int) * count);
+ qsort(SHM->sorted[ns][7], count, sizeof(int), cmputmpuid);
+ qsort(SHM->sorted[ns][8], count, sizeof(int), cmputmppid);
if( sortall ){
memcpy(SHM->sorted[ns][1],
SHM->sorted[ns][0], sizeof(int) * count);
@@ -393,11 +412,14 @@ inline void utmpsort(int sortall)
SHM->sorted[ns][0], sizeof(int) * count);
memcpy(SHM->sorted[ns][5],
SHM->sorted[ns][0], sizeof(int) * count);
+ memcpy(SHM->sorted[ns][6],
+ SHM->sorted[ns][0], sizeof(int) * count);
qsort(SHM->sorted[ns][1], count, sizeof(int), cmputmpmode);
qsort(SHM->sorted[ns][2], count, sizeof(int), cmputmpidle);
qsort(SHM->sorted[ns][3], count, sizeof(int), cmputmpfrom);
qsort(SHM->sorted[ns][4], count, sizeof(int), cmputmpfive);
qsort(SHM->sorted[ns][5], count, sizeof(int), cmputmpchc);
+ qsort(SHM->sorted[ns][6], count, sizeof(int), cmputmpgo);
memset(nusers, 0, sizeof(nusers));
for (i = 0; i < count; ++i) {
uentp = &SHM->uinfo[SHM->sorted[ns][0][i]];