diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-18 13:49:40 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-18 13:49:40 +0800 |
commit | c77c6cf22be895bb34192df420a9a141fe4a9d2c (patch) | |
tree | ffbb5a3bc61d8d8a181853ffceacb2eb7f8c59a0 | |
parent | 18f83795218bf3ea80255e9e84781ffa306921c5 (diff) | |
download | pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.gz pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.bz2 pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.lz pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.xz pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.tar.zst pttbbs-c77c6cf22be895bb34192df420a9a141fe4a9d2c.zip |
- xchat: fix "waterball exists forever" issue, and prevent printing mail alerts all the time.
- visio: improve history navigation ordering
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4187 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/visio.h | 7 | ||||
-rw-r--r-- | mbbsd/chat.c | 29 | ||||
-rw-r--r-- | mbbsd/visio.c | 39 | ||||
-rw-r--r-- | util/xchatd.c | 61 |
5 files changed, 58 insertions, 82 deletions
diff --git a/include/config.h b/include/config.h index 76b393a3..26e1acfd 100644 --- a/include/config.h +++ b/include/config.h @@ -294,8 +294,8 @@ #define PASSWDSEM_KEY 2010 /* semaphore key */ -#define NEW_CHATPORT 3838 -#define CHATPORT 5722 +// #define NEW_CHATPORT 3838 +#define XCHATD_ADDR ":3838" #define MAX_ROOM 16 /* 最多有幾間包廂? */ diff --git a/include/visio.h b/include/visio.h index bfc9c945..37aa9cce 100644 --- a/include/visio.h +++ b/include/visio.h @@ -90,9 +90,10 @@ void prints(const char *fmt, ...) GCC_CHECK_FORMAT(1,2); void mvouts(int y, int x, const char *str); // input history -int InputHistoryAdd (const char *s); -void InputHistoryPrev(char *s, int sz); -void InputHistoryNext(char *s, int sz); +int InputHistoryAdd (const char *s); +int InputHistoryExists (const char *s); +void InputHistoryPrev (char *s, int sz); +void InputHistoryNext (char *s, int sz); // v*: primitive rendering void vpad (int n, const char *pattern); /// pad n fields by pattern diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 4e931199..915ff749 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -312,10 +312,10 @@ t_chat(void) char chatroom[IDLEN+1] = "";/* Chat-Room Name */ char inbuf[80], chatid[20] = "", *ptr = ""; - struct sockaddr_in sin; + char hasnewmail = 0; + char fpath[PATHLEN]; int cfd; int chatting = YEA; - char fpath[PATHLEN]; struct ChatBuf chatbuf; ChatCbParam vgetparam = {0}; @@ -347,20 +347,12 @@ t_chat(void) memset(&chatbuf, 0, sizeof(chatbuf)); outs(" 驅車前往 請梢候........ "); - memset(&sin, 0, sizeof sin); -#ifdef __FreeBSD__ - sin.sin_len = sizeof(sin); -#endif - sin.sin_family = PF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sin.sin_port = htons(NEW_CHATPORT); - cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if (connect(cfd, (struct sockaddr *) & sin, sizeof sin) != 0) { + cfd = toconnect(XCHATD_ADDR); + if (cfd < 0) { outs("\n " "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); system("bin/xchatd"); pressanykey(); - close(cfd); return -1; } @@ -428,7 +420,7 @@ t_chat(void) vgetparam.chatting = &chatting; while (chatting) { - print_chatid(chatid); + print_chatid(chatid); clrtobot(); move(b_lines-1, chatid_len); // chatid_len = 10, quote(:) occupies 1, so 79-11=68 @@ -481,7 +473,16 @@ t_chat(void) // print mail message if possible. if (ISNEWMAIL(currutmp)) - printchatline("◆ 噹!郵差又來了..."); + { + if (!hasnewmail) + { + printchatline("◆ 您有未讀的新信件。"); + hasnewmail = 1; + } + } else { + if (hasnewmail) + hasnewmail = 0; + } } close(cfd); diff --git a/mbbsd/visio.c b/mbbsd/visio.c index 5a72b698..35384ab8 100644 --- a/mbbsd/visio.c +++ b/mbbsd/visio.c @@ -726,7 +726,8 @@ vs_cols(const VCOL *cols, const VCOLW *ws, int n, ...) // History Helpers //////////////////////////////////////////////////////////////////////// // -#define IH_MAX_ENTRIES (12) +#define IH_MAX_ENTRIES (12) // buffer size = approx. 1k +#define IH_MIN_SIZE (2) // only keep string >= 2 bytes typedef struct { int icurr; // current retrival pointer @@ -737,21 +738,42 @@ typedef struct { static InputHistory ih; // everything intialized to zero. int -InputHistoryAdd(const char *s) +InputHistoryExists(const char *s) { int i = 0; - if (!s || !*s || !*(s+1)) - return 0; - // TODO if already in queue, change order...? for (i = 0; i < IH_MAX_ENTRIES; i++) if (strcmp(s, ih.buf[i]) == 0) - return 0; + return i+1; + + return 0; +} + +int +InputHistoryAdd(const char *s) +{ + int i = 0; + int l = strlen(s); + + if (l < IH_MIN_SIZE) + return 0; + + i = InputHistoryExists(s); + if (i > 0) // found + { + i--; // i points to valid index + assert(i < IH_MAX_ENTRIES); + // change order: just delete it. + ih.buf[i][0] = 0; + } + + // now append s. strlcpy(ih.buf[ih.iappend], s, sizeof(ih.buf[ih.iappend])); - ih.icurr = ih.iappend; ih.iappend ++; ih.iappend %= IH_MAX_ENTRIES; + ih.icurr = ih.iappend; + return 1; } @@ -901,7 +923,8 @@ vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBA } // NOECHO is already checked... - InputHistoryAdd(buf); + if (!InputHistoryExists(buf)) + InputHistoryAdd(buf); if (c == KEY_DOWN) InputHistoryNext(buf, len); diff --git a/util/xchatd.c b/util/xchatd.c index c9abac2e..fb339e4d 100644 --- a/util/xchatd.c +++ b/util/xchatd.c @@ -2635,7 +2635,6 @@ start_daemon() { int fd, value; char buf[80]; - struct sockaddr_in fsin; struct linger ld; struct rlimit limit; time_t dummy; @@ -2690,22 +2689,6 @@ start_daemon() limit.rlim_cur = limit.rlim_max; setrlimit(RLIMIT_NOFILE, &limit); -#if 0 - while (fd) - { - close(--fd); - } - - value = getpid(); - setpgrp(0, value); - - if ((fd = open("/dev/tty", O_RDWR)) >= 0) - { - ioctl(fd, TIOCNOTTY, 0); /* Thor : 為什麼還要用 tty? */ - close(fd); - } -#endif - fd = open(CHAT_PIDFILE, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (fd >= 0) { @@ -2715,47 +2698,15 @@ start_daemon() close(fd); } -#if 0 - /* ------------------------------ */ - /* trap signals */ - /* ------------------------------ */ - - for (fd = 1; fd < NSIG; fd++) - { - - Signal(fd, SIG_IGN); - } -#endif - - fd = socket(PF_INET, SOCK_STREAM, 0); - -#if 0 - value = fcntl(fd, F_GETFL, 0); - fcntl(fd, F_SETFL, value | O_NDELAY); -#endif - value = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &value, sizeof(value)); - -#if 0 - setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &value, sizeof(value)); - - value = 81920; - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &value, sizeof(value)); -#endif + fd = tobind(XCHATD_ADDR); ld.l_onoff = ld.l_linger = 0; - setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof(ld)); - - memset((char *) &fsin, 0, sizeof(fsin)); - fsin.sin_family = AF_INET; - fsin.sin_port = htons(NEW_CHATPORT); - fsin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - - if (bind(fd, (struct sockaddr *) & fsin, sizeof(fsin)) < 0) - exit(1); - - listen(fd, SOCK_QLEN); + if (setsockopt(fd, SOL_SOCKET, SO_LINGER, (char *) &ld, sizeof(ld)) == -1) + { + perror("setsockopt"); + exit(-1); + } return fd; } |