summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-06 17:35:30 +0800
committervictor <victor@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-10-06 17:35:30 +0800
commit56fc75de9e90f4984366bfde6d737490ac4d60b2 (patch)
tree8119c8641423c8db346838bd7572d783c35133f6
parent4ed294b254b2dcb27519d6e4173b7019e6e56303 (diff)
downloadpttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar.gz
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar.bz2
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar.lz
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar.xz
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.tar.zst
pttbbs-56fc75de9e90f4984366bfde6d737490ac4d60b2.zip
remove unused uflag: MIND_FLAG, COLOR_FLAG
disable chinese chess watching git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2224 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/pttstruct.h6
-rw-r--r--mbbsd/chc.c82
-rw-r--r--mbbsd/mbbsd.c2
-rw-r--r--mbbsd/register.c2
4 files changed, 68 insertions, 24 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 7ae3c97a..c170e6ee 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -107,8 +107,10 @@ typedef struct userec_t {
#define FRIEND_FLAG 0x10 /* true if show friends only */
#define BRDSORT_FLAG 0x20 /* true if the boards sorted alphabetical */
#define MOVIE_FLAG 0x40 /* true if show movie */
-#define COLOR_FLAG 0x80 /* true if the color mode open */
-#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/
+/* useless flag */
+//#define COLOR_FLAG 0x80 /* true if the color mode open */
+//#define MIND_FLAG 0x100 /* true if mind search mode open <-Heat*/
+
/* these are flags in userec_t.uflag2 */
#define WATER_MASK 000003 /* water mask */
#define WATER_ORIG 0x0
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index a0154e6c..8f0f37d5 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -92,17 +92,26 @@ chc_sendmove(int s)
return 1;
}
+// XXX return value
+// XXX die because of SIGPIPE !?
+
+/* return false if your adversary is off-line */
static void
-chc_broadcast(chc_act_list *p, board_t board){
- while(p){
- if (chc_sendmove(p->sock) < 0) {
- if (p->next->next == NULL)
- p = NULL;
- else {
- chc_act_list *tmp = p->next->next;
- p->next = tmp;
- }
+chc_broadcast(chc_act_list **head, board_t board){
+ chc_act_list *p = *head;
+
+ if (!p)
+ return;
+
+ if (!chc_sendmove(p->sock)) {
+ /* do nothing */
+ }
+
+ while(p->next){
+ if (!chc_sendmove(p->next->sock)) {
+ chc_act_list *tmp = p->next->next;
free(p->next);
+ p->next = tmp;
}
p = p->next;
}
@@ -112,13 +121,14 @@ static int
chc_broadcast_recv(chc_act_list *act_list, board_t board){
if (!chc_recvmove(act_list->sock))
return 0;
- chc_broadcast(act_list->next, board);
+ chc_broadcast(&act_list->next, board);
return 1;
}
-static void
+static int
chc_broadcast_send(chc_act_list *act_list, board_t board){
- chc_broadcast(act_list, board);
+ chc_broadcast(&act_list, board);
+ return 1;
}
/*
@@ -836,6 +846,10 @@ static void
chc_watch_request(int signo)
{
chc_act_list *tmp;
+#if _TO_SYNC_
+ sigset_t mask;
+#endif
+
if (!(currstat & CHC))
return;
for(tmp = act_list; tmp->next != NULL; tmp = tmp->next);
@@ -850,6 +864,13 @@ chc_watch_request(int signo)
tmp = tmp->next;
tmp->next = NULL;
+#if _TO_SYNC_
+ /* 借用 SIGALRM */
+ sigfillset(&mask);
+ sigdelset(&mask, SIGALRM);
+ sigsuspend(&mask);
+#endif
+
/* what if the spectator get off-line intentionally !? (SIGPIPE) */
write(tmp->sock, chc_bp, sizeof(board_t));
write(tmp->sock, &chc_my, sizeof(chc_my));
@@ -859,7 +880,7 @@ chc_watch_request(int signo)
write(tmp->sock, &chc_mode, sizeof(chc_mode));
}
-static void
+static int
chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t play_func[2])
{
userinfo_t *my = currutmp;
@@ -883,6 +904,13 @@ chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t pla
}
else {
char mode;
+ userinfo_t *uin = &SHM->uinfo[currutmp->destuip];
+ if (uin == NULL)
+ return -1;
+#if _TO_SYNC_
+ // choose one signal execpt SIGUSR1
+ kill(uin->pid, SIGALRM);
+#endif
read(s, board, sizeof(board_t));
read(s, &chc_my, sizeof(chc_my));
read(s, &chc_turn, sizeof(chc_turn));
@@ -902,10 +930,12 @@ chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t pla
chc_redraw(user1, user2, board);
add_io(s, 0);
- Signal(SIGUSR1, chc_watch_request);
+ if (!(chc_mode & CHC_WATCH)) {
+ Signal(SIGUSR1, chc_watch_request);
+ }
- if (my->turn && !(chc_mode & CHC_WATCH))
- chc_broadcast_recv(act_list, board);
+// if (my->turn && !(chc_mode & CHC_WATCH))
+// chc_broadcast_recv(act_list, board);
user1->lose++;
@@ -921,6 +951,8 @@ chc_init(int s, chcusr_t *user1, chcusr_t *user2, board_t board, play_func_t pla
user2->lose++;
}
chc_redraw(user1, user2, board);
+
+ return 0;
}
void
@@ -932,12 +964,20 @@ chc(int s, int mode)
char mode0 = currutmp->mode;
char file[80];
- Signal(SIGUSR1, SIG_IGN);
+ /* CHC_WATCH is unstable!! */
+ if (mode & CHC_WATCH) {
+ vmsg("觀棋功能不穩定,暫時停止使用。");
+ return;
+ }
chc_mode = mode;
- chc_bp = &board;
- chc_init(s, &user1, &user2, board, play_func);
+ if (!(chc_mode & CHC_WATCH))
+ Signal(SIGUSR1, SIG_IGN);
+
+ chc_bp = &board;
+ if (chc_init(s, &user1, &user2, board, play_func) < 0)
+ return;
setuserfile(file, CHC_LOG);
if (chc_log_open(&user1, &user2, file) < 0)
@@ -969,7 +1009,9 @@ chc(int s, int mode)
}
else
chc_log_close();
- Signal(SIGUSR1, talk_request);
+
+ if (!(chc_mode & CHC_WATCH))
+ Signal(SIGUSR1, talk_request);
}
static userinfo_t *
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index eb6ae50f..ad35eef2 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -590,7 +590,7 @@ login_query()
} else { /* guest */
if (initcuser(uid)< 1) exit (0) ;
cuser.userlevel = 0;
- cuser.uflag = COLOR_FLAG | PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG;
+ cuser.uflag = PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG;
mkuserdir(cuser.userid);
break;
}
diff --git a/mbbsd/register.c b/mbbsd/register.c
index e33a5098..42edfe94 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -252,7 +252,7 @@ new_register()
break;
}
newuser.userlevel = PERM_DEFAULT;
- newuser.uflag = COLOR_FLAG | BRDSORT_FLAG | MOVIE_FLAG;
+ newuser.uflag = BRDSORT_FLAG | MOVIE_FLAG;
newuser.uflag2 = 0;
newuser.firstlogin = newuser.lastlogin = now;
newuser.money = 0;