From 40fafbfba1a53581e9318c71d6366a24470173be Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 9 Sep 2004 04:42:53 +0000 Subject: fix chc bug, but still buggy git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2184 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/chc.c | 20 +++++++++++++------- mbbsd/more.c | 2 ++ mbbsd/talk.c | 26 ++++++++++++++++++-------- 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/chc.c b/mbbsd/chc.c index 5ab93a00..759c9749 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -5,8 +5,6 @@ #define CHC_TIMEOUT 300 #define CHC_LOG "chc_log" /* log file name */ -extern userinfo_t *uip; - typedef int (*play_func_t) (int, chcusr_t *, chcusr_t *, board_t, board_t); typedef struct drc_t { @@ -197,14 +195,16 @@ chc_drawline(board_t board, chcusr_t *user1, chcusr_t *user2, int line) j = board[RTL(line)][i]; if ((line & 1) == 1 && j) { if (chc_selected && - chc_select.r == RTL(line) && chc_select.c == i) + chc_select.r == RTL(line) && chc_select.c == i) { prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_REVERSE : RED_REVERSE, chess_str[CHE_O(j)][CHE_P(j)]); - else + } + else { prints("%s%s\033[m", CHE_O(j) == 0 ? BLACK_COLOR : RED_COLOR, chess_str[CHE_O(j)][CHE_P(j)]); + } } else prints("%c%c", chess_brd[line - 3][i * 4], chess_brd[line - 3][i * 4 + 1]); @@ -840,11 +840,17 @@ chc_watch_request(int signo) return; for(tmp = act_list; tmp->next != NULL; tmp = tmp->next); tmp->next = (chc_act_list *)malloc(sizeof(chc_act_list)); + tmp->next->sock = establish_talk_connection(&SHM->uinfo[currutmp->destuip]); + if (tmp->next->sock < 0) { + free(tmp->next); + tmp->next = NULL; + return; + } + tmp = tmp->next; - tmp->sock = reply_connection_request(uip); - if (tmp->sock < 0) - return; tmp->next = NULL; + + /* 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)); write(tmp->sock, &chc_turn, sizeof(chc_turn)); diff --git a/mbbsd/more.c b/mbbsd/more.c index 5feb34b7..80f59947 100644 --- a/mbbsd/more.c +++ b/mbbsd/more.c @@ -1,5 +1,7 @@ /* $Id$ */ #include "bbs.h" + +/* §â³o¨â­Ó size ½Õ¨ì¤@­¶ªº½d³ò¬O¤£¬O¯à­°§C¤£¥²­nªº IO ? */ #define MORE_BUFSIZE 4096 #define MORE_WINSIZE 4096 #define STR_ANSICODE "[0123456789;," diff --git a/mbbsd/talk.c b/mbbsd/talk.c index e96ed86e..eb51d4f4 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2697,10 +2697,7 @@ t_talk() int reply_connection_request(userinfo_t *uip) { - int a; char buf[4], genbuf[200]; - struct hostent *h; - struct sockaddr_in sin; if (uip->mode != PAGE) { snprintf(genbuf, sizeof(genbuf), @@ -2708,6 +2705,16 @@ reply_connection_request(userinfo_t *uip) getdata(0, 0, genbuf, buf, sizeof(buf), LCECHO); return -1; } + return establish_talk_connection(uip); +} + +int +establish_talk_connection(userinfo_t *uip) +{ + int a; + struct hostent *h; + struct sockaddr_in sin; + currutmp->msgcount = 0; strlcpy(save_page_requestor, page_requestor, sizeof(save_page_requestor)); memset(page_requestor, 0, sizeof(page_requestor)); @@ -2719,7 +2726,10 @@ reply_connection_request(userinfo_t *uip) sin.sin_family = h->h_addrtype; memcpy(&sin.sin_addr, h->h_addr, h->h_length); sin.sin_port = uip->sockaddr; - a = socket(sin.sin_family, SOCK_STREAM, 0); + if ((a = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) { + perror("connect err"); + return -1; + } if ((connect(a, (struct sockaddr *) & sin, sizeof(sin)))) { perror("connect err"); return -1; @@ -2980,14 +2990,14 @@ AngelNotOnline(){ outs("\nÍ¢¯d¨¥µ¹§A¡G\n"); outs("\033[1;31;44m¡ó¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢t\033[37m" "¤p¤Ñ¨Ï¯d¨¥\033[31m¢u¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¡ó\033[m\n"); - outs("\033[1;31mùú¢t\033[32m ¤p¤Ñ¨Ï " - " \033[31m¢uùû\033[m\n"); + outs("\033[1;31m¢~¢t\033[32m ¤p¤Ñ¨Ï " + " \033[31m¢u¢¡\033[m\n"); while (fgets(buf, sizeof(buf), fp)) { buf[strlen(buf) - 1] = 0; prints("\033[1;31m¢x\033[m%-74.74s\033[1;31m¢x\033[m\n", buf); } - outs("\033[1;31mùü¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" - "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢sùý\033[m\n"); + outs("\033[1;31m¢¢¢s¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" + "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢s¢£\033[m\n"); outs("\033[1;31;44m¡ó¢r¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w" "¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢w¢r¡ó\033[m\n"); -- cgit v1.2.3