void putwe(int w, FILE *iob) { obuf[oblen++] = w; if (oblen >= sizeof(obuf)) oflush(iob); obuf[oblen++] = w >> 8; if (oblen >= sizeof(obuf)) oflush(iob); }
// from Maple-hightman // added by flyriver, 2001.3.3 int telnetopt(int fd, char* buf, int max) { unsigned char c,d,e; int pp=0; unsigned char tmp[30]; while (pp<max) { c=buf[pp++]; if (c==255) { d=buf[pp++]; e=buf[pp++]; oflush(); if ((d==253)&&(e==3||e==24)) { tmp[0]=255; tmp[1]=251; tmp[2]=e; write(fd,tmp,3); continue; } if ((d==251||d==252)&&(e==1||e==3||e==24)) { tmp[0]=255; tmp[1]=253; tmp[2]=e; write(fd,tmp,3); continue; } if (d==251||d==252) { tmp[0]=255; tmp[1]=254; tmp[2]=e; write(fd,tmp,3); continue; } if (d==253||d==254) { tmp[0]=255; tmp[1]=252; tmp[2]=e; write(fd,tmp,3); continue; } if (d==250) { while (e!=240&&pp<max) e=buf[pp++]; tmp[0]=255; tmp[1]=250; tmp[2]=24; tmp[3]=0; tmp[4]=65; tmp[5]=78; tmp[6]=83; tmp[7]=73; tmp[8]=255; tmp[9]=240; write(fd,tmp,10); } } else ochar(c); } oflush(); return 0; }
void ochar(char c) { if (obufsize > OBUFSIZE - 1) { /* doin a oflush */ oflush(); } outbuf[obufsize++] = c; /* * need to change IAC to IAC IAC */ if (((unsigned char) c) == IAC) { if (obufsize > OBUFSIZE - 1) { /* doin a oflush */ oflush(); } outbuf[obufsize++] = c; } }
static void select_wrong(struct _select_def *conf) { if (conf->flag & LF_BELL) { bell(); oflush(); } }
void output(const char *s, int len) { /* * need to change IAC to IAC IAC * if(obufsize+len > OBUFSIZE) { * #ifdef SSHBBS * ssh_write(0,outbuf,obufsize) ; * #else * write(0,outbuf,obufsize) ; * #endif * obufsize = 0 ; * } * memcpy(outbuf+obufsize, s, len) ; * obufsize+=len ; */ int i; while (obufsize+len>OBUFSIZE - 1) { i=OBUFSIZE-obufsize; memcpy(outbuf+obufsize, s, i); obufsize += i; s+=i; len-=i; oflush(); } i=len; memcpy(outbuf+obufsize, s, i); obufsize += i; }
/** * compile one file if filename is NULL redirect do to stdin/stdout * @param file filename * @return */ void compile(char *file) { if (file == NULL || filename_typeof(file) == 'c') { global_table_index = 0; local_table_index = NUMBER_OF_GLOBALS; while_table_index = 0; tag_table_index = 0; inclsp = iflevel = skiplevel = swstp = litptr = stkp = errcnt = ncmp = lastst = //quote[1] = 0; input2 = -1; //quote[0] = '"'; cmode = 1; glbflag = 1; nxtlab = 0; litlab = getlabel(); defmac("end\tmemory"); //add_global("memory", ARRAY, CCHAR, 0, EXTERN); //add_global("stack", ARRAY, CCHAR, 0, EXTERN); rglobal_table_index = global_table_index; //rglbptr = glbptr; //add_global("etext", ARRAY, CCHAR, 0, EXTERN); //add_global("edata", ARRAY, CCHAR, 0, EXTERN); defmac("short\tint"); initmac(); // compiler body if (file == NULL) { input = 0; } else if (!openin(file)) return; if (file == NULL) { output = 1; } else if (!openout()) return; header(); code_segment_gtext(); parse(); close(input); data_segment_gdata(); dumplits(); dumpglbs(); errorsummary(); trailer(); oflush(); close(output); pl(""); errs = errs || errfile; } else { writee("Don't understand file "); writee(file); errs = 1; } }
void ochar(char c) { if (obufsize > OBUFSIZE - 1) oflush(); outbuf[obufsize++] = c; }
static int hisplay(int s, board_t board, board_t tmpbrd) { int start_time; int endgame = 0, endturn = 0; start_time = time(NULL); while(!endturn) { chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); if(chc_lefttime < 0) { chc_lefttime = 0; /* to make him break out igetkey() */ chc_from.r = -2; chc_sendmove(s); } chc_drawline(board, TIME_ROW); move(1, 0); oflush(); switch(igetkey()) { case 'q': endgame = 2; endturn = 1; break; case 'p': if(chc_hepass) { chc_from.r = -1; chc_sendmove(s); endgame = 3; endturn = 1; } break; case I_OTHERDATA: if(chc_recvmove(s)) { /* disconnect */ endturn = 1; endgame = 1; } else { if(chc_from.r == -1) { chc_hepass = 1; strcpy(chc_warnmsg, "\033[1;33m要求和局!\033[m"); chc_drawline(board, WARN_ROW); } else { chc_from.r = 9 - chc_from.r, chc_from.c = 8 - chc_from.c; chc_to.r = 9 - chc_to.r, chc_to.c = 8 - chc_to.c; chc_cursor = chc_to; if(CHE_P(board[chc_to.r][chc_to.c]) == 1) endgame = 2; endturn = 1; chc_hepass = 0; chc_drawline(board, STEP_ROW); chc_movechess(board); chc_drawline(board, LTR(chc_from.r)); chc_drawline(board, LTR(chc_to.r)); } } break; } } return endgame; }
int main(int argc, char **argv) { FILE *fi; char sobuf[BUFSIZ]; char *cp; int nofile; char *locale; outp = NOSTR; setbuf(stdout, sobuf); setlocale(LC_ALL, ""); locale = setlocale(LC_CTYPE, ""); if (strcmp(locale, "C") == 0) { split = csplit; } else { split = msplit; _wckind_init(); } if (argc < 2) { single: fmt(stdin); oflush(); exit(0); } nofile = 1; while (--argc) { cp = *++argv; if (setopt(cp)) continue; nofile = 0; if ((fi = fopen(cp, "r")) == NULL) { perror(cp); errs++; continue; } fmt(fi); fclose(fi); } if (nofile) goto single; oflush(); fclose(stdout); return (errs); }
/* called by signal interrupt or terminate to clean things up */ void bibi(int n) { canit(0); oflush(); io_mode(io_mode_fd, 0); if (n == SIGQUIT) abort(); exit(128 + n); }
static void output(char *s, int len) { /* Invalid if len >= OBUFSIZE */ if (obufsize + len > OBUFSIZE) oflush(); memcpy(outbuf + obufsize, s, len); obufsize += len; }
void redrawwin(void) { register screenline_t *bp; register int i, j; int len; o_clear(); for (tc_col = tc_line = i = 0, j = roll; i < t_lines; i++, j++) { if (j >= t_lines) j = 0; bp = &big_picture[j]; if ((len = bp->len)) { rel_move(tc_col, tc_line, 0, i); #ifdef DBCSAWARE if (!(bp->mode & STANDOUT) && (HasUserFlag(UF_DBCS_NOINTRESC)) && DBCS_RemoveIntrEscape(bp->data, &len)) { // if anything changed, dirty whole line. bp->len = len; } #endif // DBCSAWARE if (bp->mode & STANDOUT) { standoutput((char *)bp->data, 0, len, bp->sso, bp->eso); } else output((char *)bp->data, len); tc_col += len; if (tc_col >= t_columns) { if (automargins) tc_col = t_columns - 1; else { tc_col -= t_columns; tc_line++; if (tc_line >= t_lines) tc_line = b_lines; } } bp->mode &= ~(MODIFIED); bp->oldlen = len; } } rel_move(tc_col, tc_line, cur_col, cur_ln); docls = scrollcnt = 0; oflush(); }
const char *generate_verify_num() { /* Declare the image */ gdImagePtr im; /* Declare output files */ //FILE *gifout; /* Declare color indexes */ int black; int white; int x, y, z; int rd; static char s[10]; /* Allocate the image: 64 pixels across by 64 pixels tall */ im = gdImageCreate(40, 16); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); white = gdImageColorAllocate(im, 255, 255, 255); srandom(time(0)%getpid()); rd=random()%(100000); sprintf(s, "%05d", rd); gdImageString(im, gdFontGetLarge(), 0, 0, s, white); for (z=0; z<20; z++) { x=random()%(im->sx); y=random()%(im->sy); gdImageSetPixel(im, x, y, white); } for (y=0; y<im->sy; y++) { for (x=0; x<im->sx; x++) { if (gdImageGetPixel(im, x, y)) outc('o'); else outc(' '); } outc('\n'); } gdImageDestroy(im); oflush(); return s; }
static void putchr(int cc) { char c; c = cc; if (!NP) { c |= partab[c&0177] & 0200; if (OP) c ^= 0200; } if (!UB) { outbuf[obufcnt++] = c; if (obufcnt >= OBUFSIZ) oflush(); } else write(STDOUT_FILENO, &c, 1); }
void redoscr() { register screenline *bp; register int i, j, len; o_clear(); for (tc_col = tc_line = i = 0, j = roll; i < scr_lns; i++, j++) { if (j >= scr_lns) j = 0; bp = &big_picture[j]; if (len = bp->len) { rel_move(0, i); if (bp->mode & STANDOUT) standoutput(bp->data, 0, len, bp->sso, bp->eso); else output(bp->data, len); tc_col += len; if (tc_col >= scr_cols) { if (automargins) tc_col = scr_cols - 1; else { tc_col -= scr_cols; tc_line++; if (tc_line >= t_lines) tc_line = b_lines; } } bp->mode &= ~(MODIFIED); bp->oldlen = len; } } rel_move(cur_col, cur_ln); docls = scrollcnt = 0; oflush(); }
static void pack(wchar_t word[]) { wchar_t *cp; int s, t; if (outp == NOSTR) leadin(); t = wscol(word); *outp = L'\0'; s = wscol(outbuf); if (t+s <= width) { for (cp = word; *cp; *outp++ = *cp++); return; } if (s > filler) { oflush(); leadin(); } for (cp = word; *cp; *outp++ = *cp++); }
static void mainloop(int s, board_t board) { int endgame; board_t tmpbrd; play_func_t play_func[2]; play_func[chc_my] = myplay; play_func[chc_my ^ 1] = hisplay; for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { chc_firststep = 0; chc_drawline(board, TURN_ROW); if(chc_ischeck(board, chc_turn)) { strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m"); bell(); } else chc_warnmsg[0] = 0; chc_drawline(board, WARN_ROW); endgame = play_func[chc_turn](s, board, tmpbrd); } if(endgame == 1) { strcpy(chc_warnmsg, "對方認輸了!"); my.chc_win++; chc_hislose++; } else if(endgame == 2) { strcpy(chc_warnmsg, "你認輸了!"); my.chc_lose++; chc_hiswin++; } else { strcpy(chc_warnmsg, "和棋"); my.chc_tie++; chc_histie++; } chc_save(cuser.userid,1); chc_save(uin->userid,2); chc_drawline(board, WARN_ROW); bell(); oflush(); }
static void multi_user_check() { register user_info *ui; register pid_t pid; int cmpuids (); if (HAS_PERM(PERM_SYSOP)) return; /* wildcat:站長不限制 */ if (cuser.userlevel) { if (!(ui = (user_info *) search_ulist(cmpuids, usernum))) return; /* user isn't logged in */ pid = ui->pid; if (!pid || (kill(pid, 0) == -1)) return; /* stale entry in utmp file */ if (getans2(b_lines, 0, "您想刪除其他重複的 login 嗎?", 0, 2, 'y') != 'n') { kill(pid, SIGHUP); log_usies("KICK ", cuser.username); } else { int nums = MULTI_NUMS; if (HAS_PERM(PERM_BM)) nums += 2; if (count_multi() >= nums) system_abort(); } } else { /* guest的話 */ if (count_multi() > 512) { pressanykey("抱歉,目前已有太多 guest, 請稍後再試。"); oflush(); exit(1); } } }
static void mainloop(int s, board_t board) { int endgame; board_t tmpbrd; play_func_t play_func[2]; play_func[chc_my] = myplay; play_func[chc_my ^ 1] = hisplay; for(chc_turn = 1, endgame = 0; !endgame; chc_turn ^= 1) { chc_firststep = 0; chc_drawline(board, TURN_ROW); if(chc_ischeck(board, chc_turn)) { strcpy(chc_warnmsg, "\033[1;31m將軍!\033[m"); bell(); } else chc_warnmsg[0] = 0; chc_drawline(board, WARN_ROW); endgame = play_func[chc_turn](s, board, tmpbrd); } if(endgame == 1) { strcpy(chc_warnmsg, "對方認輸了!"); cuser.chc_win++; } else if(endgame == 2) { strcpy(chc_warnmsg, "你認輸了!"); cuser.chc_lose++; } else { strcpy(chc_warnmsg, "和棋"); cuser.chc_tie++; } cuser.chc_lose--; reload_money(); passwd_update(usernum, &cuser); chc_drawline(board, WARN_ROW); bell(); oflush(); }
static void multi_user_check() { register userinfo_t *ui; register pid_t pid; char genbuf[3]; if(HAS_PERM(PERM_SYSOP)) return; /* don't check sysops */ if(cuser.userlevel) { if(!(ui = (userinfo_t *)search_ulist(cmpuids, usernum))) return; /* user isn't logged in */ pid = ui->pid; if(!pid /*|| (kill(pid, 0) == -1)*/) return; /* stale entry in utmp file */ getdata(b_lines - 1, 0, "您想刪除其他重複的 login (Y/N)嗎?[Y] ", genbuf, 3, LCECHO); if(genbuf[0] != 'n') { if(pid > 0) kill(pid, SIGHUP); log_usies("KICK ", cuser.username); } else { if(count_multi() >= 3) system_abort(); /* Goodbye(); */ } } else { /* allow multiple guest user */ if(count_multi() > 32) { outs("\n抱歉,目前已有太多 guest, 請稍後再試。\n"); pressanykey(); oflush(); exit(1); } } }
int bbsnet(struct _select_def *conf, int n) { time_t now; struct hostent *pHost = NULL; struct sockaddr_in remote; unsigned char buf[BUFSIZ]; int rc; int rv; int maxfdp1; fd_set readset; struct timeval tv; int tos = 020; /* Low delay bit */ int i; sig_t oldsig; int ret; int key; char buf1[40], buf2[40], c, buf3[40]; //增加的变量 int l; //判断是不是port int j; if (strcmp(host2[n], "般若波羅密") == 0) { //如果是自定义站点,等待输入ip或域名 memset(buf1, 0, sizeof(buf1)); move(22,2); prints("\033[1;32m连往: \033[m"); refresh(); j = 0; l = 0; for (i = 0; i < 30;) { c = igetch(); if (c == ' ' || c == '\015' || c == '\0' || c == '\n') break; if (c == ':') { l = 1; sprintf(buf3, "%c", c); prints("\033[0;1m"); prints(buf3); prints("\033[1;33m"); refresh(); strncpy(ip_zdh, buf1, 40); strncpy(ip[n], ip_zdh, 40); memset(buf1, 0, sizeof(buf1)); j = 0; i++; } if ((c >= '0' && c <= '9') || (((c == '.') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) && !l)) { sprintf(buf3, "%c", c); sprintf(buf2, "%s%c", buf1, c); sprintf(buf1, "%s", buf2); prints(buf3); refresh(); j++; i++; } if ((c == 8) && (j >= 1)) { buf1[j - 1] = '\0'; sprintf(buf3, "\033[D\033[1;33m_\033[%sm\033[D", l ? "1;33" : "0"); prints(buf3); refresh(); i--; j--; } } if (l == 0) { strncpy(ip_zdh, buf1, 40); strcpy(ip[n], ip_zdh); } else { port[n] = atoi(buf1); } } now = time(NULL); clear(); prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n", host2[n], ip[n]); prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\n", TIME_OUT); if (setjmp(jb) == 0) { oldsig = signal(SIGALRM, bbsnet_timeout); alarm(TIME_OUT); pHost = gethostbyname(ip[n]); alarm(0); signal(SIGALRM, oldsig); } if (pHost == NULL) { prints("\033[1;31m查找主机名失败!\033[m\n"); pressreturn(); return -1; } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { prints("\033[1;31m无法创建socket!\033[m\n"); pressreturn(); return -1; } bzero(&remote, sizeof(remote)); remote.sin_family = AF_INET; remote.sin_port = htons(port[n]); remote.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n"); process_bar(0, MAX_PROCESS_BAR_LEN); for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) { if (i == 0) rv = NonBlockConnectEx(sockfd, (struct sockaddr *)&remote, sizeof(remote), 500, 1); else rv = NonBlockConnectEx(sockfd, (struct sockaddr *)&remote, sizeof(remote), 500, 0); if (rv == ERR_TCPLIB_TIMEOUT) { process_bar(i+1, MAX_PROCESS_BAR_LEN); continue; } else if (rv == 0) break; else { prints("\033[1;31m连接失败!\033[m\n"); pressreturn(); ret = -1; goto on_error; } } if (i == MAX_PROCESS_BAR_LEN) { prints("\033[1;31m连接超时!\033[m\n"); pressreturn(); ret = -1; goto on_error; } setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); prints("\033[1;31m连接成功!\033[m\n"); bbsnet_report(host2[n], ip[n], now, 0); clear(); refresh(); bbsnet_send_winsize(sockfd); for (;;) { FD_ZERO(&readset); FD_SET(0, &readset); FD_SET(sockfd, &readset); maxfdp1 = sockfd + 1; tv.tv_sec = 1200; tv.tv_usec = 0; /*if ((rv = SignalSafeSelect(maxfdp1, &readset, NULL, NULL, &tv)) == -1)*/ if ((rv = select(maxfdp1, &readset, NULL, NULL, &tv)) == -1) { if (errno == EINTR) { while (msg_count) { msg_count--; r_msg(); } continue; } ret = -1; goto on_error; } if (rv == 0) { ret = -1; goto on_error; } if (FD_ISSET(sockfd, &readset)) { if ((rc = read(sockfd, buf, BUFSIZ)) < 0) { ret = -1; goto on_error; } else if (rc == 0) break; else if (strchr((void*)buf, 255)) /* 查找是否含有TELNET命令IAC */ telnetopt(sockfd, (void*)buf, rc); else { output((void*)buf, rc); oflush(); } } if (FD_ISSET(0, &readset)) { if ((rc = bbsnet_read(0, (void*)buf, BUFSIZ)) < 0) { ret = -1; goto on_error; } if (rc == 0) break; if ((key = list_select_remove_key(conf)) != KEY_INVALID) { if (key == KEY_ONSIZE) { bbsnet_send_winsize(sockfd); } } write(sockfd, buf, rc); } } bbsnet_report(host2[n], ip[n], now, 1); ret = 0; on_error: close(sockfd); clear(); redoscr(); return ret; }
/* * ret: -1: user cancel input */ int getdata(int line, int col, char *prompt, char *buf, int len, int echo, void *nouse, int clearlabel) { int ch, clen = 0, curr = 0, x, y; bool init=true; char tmp[STRLEN],save[STRLEN]; extern int scr_cols; extern int RMSG; if (clearlabel == true) { buf[0] = 0; } if (scrint) move(line, col); if (prompt) prints("%s", prompt); if (scrint) getyx(&y, &x); clen = strlen(buf); if (clen>=len) clen = len - 1; curr = clen; buf[curr] = '\0'; strncpy(save, buf, STRLEN); save[STRLEN-1]=0; if (!scrint) { prints("%s", buf); while ((ch = igetkey()) != '\r') { /* * TODO: add KEY_REFRESH support */ if (ch == '\n') break; if (ch == '\177' || ch == Ctrl('H')) { if (clen == 0) continue; clen--; ochar(Ctrl('H')); ochar(' '); ochar(Ctrl('H')); oflush(); continue; } if (!isprint2(ch)) continue; if (clen >= len - 1) continue; buf[clen++] = ch; if (echo) ochar(ch); else ochar('*'); } buf[clen] = '\0'; prints("\n"); oflush(); return clen; } ingetdata = true; clrtoeol(); while (1) { int i; move(y, x); if (init) prints("\x1b[4m"); for (i=0; i<clen; i++) if (!echo||buf[i]==KEY_ESC||!isprint2(buf[i])) outc('*'); else outc(buf[i]); resetcolor(); clrtoeol(); move(y, x+curr); ch = igetkey(); if (kicked) { ingetdata = false; return 0; } if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch)) { ingetdata = false; return -ch; /* Leeward 98.07.30 supporting msgX */ } if ((uinfo.mode == KILLER && (!buf[0]) && (ch==KEY_UP||ch==KEY_DOWN||ch==KEY_PGUP||ch==KEY_PGDN))||(ch>=Ctrl('S')&&ch<=Ctrl('W'))) { ingetdata = false; return -ch; } #if 0 //#ifdef NINE_BUILD if (true == RMSG && ch == Ctrl('Z') && clen == 0) break; #endif if (ch == '\n' || ch == '\r') break; #ifdef CHINESE_CHARACTER if (ch == Ctrl('R')) { SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR); init=false; continue; } #endif if (ch == '\177' || ch == Ctrl('H')) { if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (curr == 0) { continue; } strcpy(tmp, &buf[curr]); buf[--curr] = '\0'; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) { buf[--curr] = '\0'; clen--; } } #endif (void) strcat(buf, tmp); clen--; continue; } if (ch == KEY_ESC&&!enableESC) { strncpy(buf, save, Min(len,STRLEN)); buf[Min(len,STRLEN-1)]=0; curr = strlen(buf); clen = curr; init=true; continue; } if (ch == Ctrl('C')) { buf[0]='\0'; outc('\n'); ingetdata = false; return -1; } if (ch == KEY_DEL) { if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (curr >= clen) { curr = clen; continue; } strcpy(tmp, &buf[curr + 1]); #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr+1; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) { strcpy(tmp, &buf[curr + 2]); clen--; } } #endif buf[curr] = '\0'; (void) strcat(buf, tmp); clen--; continue; } if (ch == KEY_LEFT) { init=false; if (curr == 0) { continue; } curr--; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) curr--; } #endif move(y, x + curr); continue; } if (ch == Ctrl('E') || ch == KEY_END) { init=false; curr = clen; move(y, x + curr); continue; } if (ch == Ctrl('A') || ch == KEY_HOME) { init=false; curr = 0; move(y, x + curr); continue; } if (ch == KEY_RIGHT) { init=false; if (curr >= clen) { curr = clen; continue; } curr++; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0; i<curr; i++) if (j) j=0; else if (buf[i]<0) j=1; if (j) curr++; } #endif move(y, x + curr); continue; } if (!isprint2(ch)&&(ch!=KEY_ESC||!enableESC)) { init=false; continue; } if (x + clen >= scr_cols || clen >= len - 1) { if (!init) continue; } if (init) { init=false; buf[0]=0; curr=0; clen=0; } if (!buf[curr]) { buf[curr + 1] = '\0'; buf[curr] = ch; } else { int i; for (i = len - 2; i >= curr; i--) buf[i + 1] = buf[i]; buf[curr] = ch; } curr++; clen++; } buf[clen] = '\0'; outc('\n'); ingetdata = false; return clen; }
static int getname(void) { int c; char *np; unsigned char cs; int ppp_state = 0; int ppp_connection = 0; /* * Interrupt may happen if we use CBREAK mode */ if (setjmp(intrupt)) { signal(SIGINT, SIG_IGN); return (0); } signal(SIGINT, interrupt); set_flags(1); prompt(); oflush(); if (PF > 0) { sleep(PF); PF = 0; } if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) { syslog(LOG_ERR, "%s: %m", ttyn); exit(1); } crmod = digit = lower = upper = 0; np = name; for (;;) { oflush(); if (read(STDIN_FILENO, &cs, 1) <= 0) exit(0); if ((c = cs&0177) == 0) return (0); /* PPP detection state machine.. Look for sequences: PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED or PPP_FRAME, PPP_STATION, PPP_CONTROL (deviant from RFC) See RFC1662. Derived from code from Michael Hancock, <*****@*****.**> and Erik 'PPP' Olson, <*****@*****.**> */ if (PP && (cs == PPP_FRAME)) { ppp_state = 1; } else if (ppp_state == 1 && cs == PPP_STATION) { ppp_state = 2; } else if (ppp_state == 2 && cs == PPP_ESCAPE) { ppp_state = 3; } else if ((ppp_state == 2 && cs == PPP_CONTROL) || (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) { ppp_state = 4; } else if (ppp_state == 4 && cs == PPP_LCP_HI) { ppp_state = 5; } else if (ppp_state == 5 && cs == PPP_LCP_LOW) { ppp_connection = 1; break; } else { ppp_state = 0; } if (c == EOT || c == CTRL('d')) exit(0); if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) { putf("\r\n"); break; } if (islower(c)) lower = 1; else if (isupper(c)) upper = 1; else if (c == ERASE || c == '\b' || c == 0177) { if (np > name) { np--; if (cfgetospeed(&tmode) >= 1200) puts("\b \b"); else putchr(cs); } continue; } else if (c == KILL || c == CTRL('u')) { putchr('\r'); if (cfgetospeed(&tmode) < 1200) putchr('\n'); /* this is the way they do it down under ... */ else if (np > name) puts(" \r"); prompt(); digit = lower = upper = 0; np = name; continue; } else if (isdigit(c)) digit = 1; if (IG && (c <= ' ' || c > 0176)) continue; *np++ = c; putchr(cs); } signal(SIGINT, SIG_IGN); *np = 0; if (c == '\r') crmod = 1; if ((upper && !lower && !LC) || UC) for (np = name; *np; np++) if (isupper(*np)) *np = tolower(*np); return (1 + ppp_connection); }
int main(int argc, char *argv[]) { extern char **environ; int first_sleep = 1, first_time = 1; struct rlimit limit; int rval; signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH); gethostname(hostname, sizeof(hostname) - 1); hostname[sizeof(hostname) - 1] = '\0'; if (hostname[0] == '\0') strcpy(hostname, "Amnesiac"); /* * Limit running time to deal with broken or dead lines. */ (void)signal(SIGXCPU, timeoverrun); limit.rlim_max = RLIM_INFINITY; limit.rlim_cur = GETTY_TIMEOUT; (void)setrlimit(RLIMIT_CPU, &limit); gettable("default", defent); gendefaults(); tname = "default"; if (argc > 1) tname = argv[1]; /* * The following is a work around for vhangup interactions * which cause great problems getting window systems started. * If the tty line is "-", we do the old style getty presuming * that the file descriptors are already set up for us. * J. Gettys - MIT Project Athena. */ if (argc <= 2 || strcmp(argv[2], "-") == 0) strcpy(ttyn, ttyname(STDIN_FILENO)); else { strcpy(ttyn, dev); strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev)); if (strcmp(argv[0], "+") != 0) { chown(ttyn, 0, 0); chmod(ttyn, 0600); revoke(ttyn); /* * Do the first scan through gettytab. * Terminal mode parameters will be wrong until * defttymode() called, but they're irrelevant for * the initial setup of the terminal device. */ dogettytab(); /* * Init or answer modem sequence has been specified. */ if (IC || AC) { if (!opentty(ttyn, O_RDWR|O_NONBLOCK)) exit(1); defttymode(); setttymode(1); } if (IC) { if (getty_chat(IC, CT, DC) > 0) { syslog(LOG_ERR, "modem init problem on %s", ttyn); (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode); exit(1); } } if (AC) { int i, rfds; struct timeval to; rfds = 1 << 0; /* FD_SET */ to.tv_sec = RT; to.tv_usec = 0; i = select(32, (fd_set*)&rfds, (fd_set*)NULL, (fd_set*)NULL, RT ? &to : NULL); if (i < 0) { syslog(LOG_ERR, "select %s: %m", ttyn); } else if (i == 0) { syslog(LOG_NOTICE, "recycle tty %s", ttyn); (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode); exit(0); /* recycle for init */ } i = getty_chat(AC, CT, DC); if (i > 0) { syslog(LOG_ERR, "modem answer problem on %s", ttyn); (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode); exit(1); } } else { /* maybe blocking open */ if (!opentty(ttyn, O_RDWR | (NC ? O_NONBLOCK : 0 ))) exit(1); } } } defttymode(); for (;;) { /* * if a delay was specified then sleep for that * number of seconds before writing the initial prompt */ if (first_sleep && DE) { sleep(DE); /* remove any noise */ (void)tcflush(STDIN_FILENO, TCIOFLUSH); } first_sleep = 0; setttymode(0); if (AB) { tname = autobaud(); dogettytab(); continue; } if (PS) { tname = portselector(); dogettytab(); continue; } if (CL && *CL) putpad(CL); edithost(HE); /* if this is the first time through this, and an issue file has been given, then send it */ if (first_time && IF) { int fd; if ((fd = open(IF, O_RDONLY)) != -1) { char * cp; while ((cp = getline(fd)) != NULL) { putf(cp); } close(fd); } } first_time = 0; if (IM && *IM && !(PL && PP)) putf(IM); if (setjmp(timeout)) { cfsetispeed(&tmode, B0); cfsetospeed(&tmode, B0); (void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode); exit(1); } if (TO) { signal(SIGALRM, dingdong); alarm(TO); } rval = 0; if (AL) { const char *p = AL; char *q = name; while (*p && q < &name[sizeof name - 1]) { if (isupper(*p)) upper = 1; else if (islower(*p)) lower = 1; else if (isdigit(*p)) digit = 1; *q++ = *p++; } } else if (!(PL && PP)) rval = getname(); if (rval == 2 || (PL && PP)) { oflush(); alarm(0); limit.rlim_max = RLIM_INFINITY; limit.rlim_cur = RLIM_INFINITY; (void)setrlimit(RLIMIT_CPU, &limit); execle(PP, "ppplogin", ttyn, (char *) 0, env); syslog(LOG_ERR, "%s: %m", PP); exit(1); } else if (rval || AL) { int i; oflush(); alarm(0); signal(SIGALRM, SIG_DFL); if (name[0] == '\0') continue; if (name[0] == '-') { puts("user names may not start with '-'."); continue; } if (!(upper || lower || digit)) { if (AL) { syslog(LOG_ERR, "invalid auto-login name: %s", AL); exit(1); } else continue; } set_flags(2); if (crmod) { tmode.c_iflag |= ICRNL; tmode.c_oflag |= ONLCR; } #if REALLY_OLD_TTYS if (upper || UC) tmode.sg_flags |= LCASE; if (lower || LC) tmode.sg_flags &= ~LCASE; #endif if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) { syslog(LOG_ERR, "tcsetattr %s: %m", ttyn); exit(1); } signal(SIGINT, SIG_DFL); for (i = 0; environ[i] != (char *)0; i++) env[i] = environ[i]; makeenv(&env[i]); limit.rlim_max = RLIM_INFINITY; limit.rlim_cur = RLIM_INFINITY; (void)setrlimit(RLIMIT_CPU, &limit); execle(LO, "login", AL ? "-fp" : "-p", name, (char *) 0, env); syslog(LOG_ERR, "%s: %m", LO); exit(1); } alarm(0); signal(SIGALRM, SIG_DFL); signal(SIGINT, SIG_IGN); if (NX && *NX) { tname = NX; dogettytab(); } } }
int bbsnet(struct _select_def *conf, int n) { time_t now; struct hostent *pHost = NULL; struct sockaddr_in remote; unsigned char buf[BUFSIZ]; int rc; int rv; int maxfdp1; fd_set readset; struct timeval tv; int tos = 020; /* Low delay bit */ int i; sig_t oldsig; int ret; int key; now = time(NULL); clear(); prints("\033[1;32m正在测试往 %s (%s) 的连接,请稍候... \033[m\n", host1[n], ip[n]); prints("\033[1;32m如果在 %d 秒内无法连上,穿梭程序将放弃连接。\033[m\n", TIME_OUT); if (setjmp(jb) == 0) { oldsig = signal(SIGALRM, bbsnet_timeout); alarm(TIME_OUT); pHost = gethostbyname(ip[n]); alarm(0); signal(SIGALRM, oldsig); } if (pHost == NULL) { prints("\033[1;31m查找主机名失败!\033[m\n"); pressreturn(); return -1; } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { prints("\033[1;31m无法创建socket!\033[m\n"); pressreturn(); return -1; } bzero(&remote, sizeof(remote)); remote.sin_family = AF_INET; remote.sin_port = htons(port[n]); remote.sin_addr = *(struct in_addr *)pHost->h_addr_list[0]; prints("\033[1;32m穿梭进度条提示您当前已使用的时间。\033[m\n"); process_bar(0, MAX_PROCESS_BAR_LEN); for (i = 0; i < MAX_PROCESS_BAR_LEN; i++) { if (i == 0) rv = NonBlockConnectEx(sockfd, (struct sockaddr *)&remote, sizeof(remote), 500, 1); else rv = NonBlockConnectEx(sockfd, (struct sockaddr *)&remote, sizeof(remote), 500, 0); if (rv == ERR_TCPLIB_TIMEOUT) { process_bar(i+1, MAX_PROCESS_BAR_LEN); continue; } else if (rv == 0) break; else { prints("\033[1;31m连接失败!\033[m\n"); pressreturn(); ret = -1; goto on_error; } } if (i == MAX_PROCESS_BAR_LEN) { prints("\033[1;31m连接超时!\033[m\n"); pressreturn(); ret = -1; goto on_error; } setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(int)); prints("\033[1;31m连接成功!\033[m\n"); bbsnet_report(host1[n], ip[n], now, 0); clear(); refresh(); bbsnet_send_winsize(sockfd); for (;;) { FD_ZERO(&readset); FD_SET(0, &readset); FD_SET(sockfd, &readset); maxfdp1 = sockfd + 1; tv.tv_sec = 1200; tv.tv_usec = 0; /*if ((rv = SignalSafeSelect(maxfdp1, &readset, NULL, NULL, &tv)) == -1)*/ if ((rv = select(maxfdp1, &readset, NULL, NULL, &tv)) == -1) { if (errno == EINTR) { while (msg_count) { msg_count--; r_msg(); } continue; } ret = -1; goto on_error; } if (rv == 0) { ret = -1; goto on_error; } if (FD_ISSET(sockfd, &readset)) { if ((rc = read(sockfd, buf, BUFSIZ)) < 0) { ret = -1; goto on_error; } else if (rc == 0) break; else if (strchr((void*)buf, 255)) /* 查找是否含有TELNET命令IAC */ telnetopt(sockfd, (void*)buf, rc); else { output((void*)buf, rc); oflush(); } } if (FD_ISSET(0, &readset)) { if ((rc = bbsnet_read(0, (void*)buf, BUFSIZ)) < 0) { ret = -1; goto on_error; } if (rc == 0) break; if ((key = list_select_remove_key(conf)) != KEY_INVALID) if (key == KEY_ONSIZE) bbsnet_send_winsize(sockfd); write(sockfd, buf, rc); } } bbsnet_report(host1[n], ip[n], now, 1); ret = 0; on_error: close(sockfd); clear(); redoscr(); return ret; }
void new_register() { struct userec newuser; int allocid, do_try, flag; char buf[STRLEN]; /* temp !!!!!*/ #ifdef SECONDSITE prints("不接受新帐号注册!!!\n"); oflush(); sleep(2); exit(-1); #else /* prints("Sorry, we don't accept newusers due to system problem, we'll fixit ASAP\n"); oflush(); sleep(2); exit(-1); */ memset(&newuser, 0, sizeof(newuser)); getdata(0, 0, "使用GB编码阅读?(\xa8\xcf\xa5\xce BIG5\xbd\x58\xbe\x5c\xc5\xaa\xbd\xd0\xbf\xefN)(Y/N)? [Y]: ", buf, 4, DOECHO, NULL, true); if (*buf == 'n' || *buf == 'N') if (!convcode) switch_code(); ansimore("etc/register", false); do_try = 0; while (1) { if (++do_try >= 10) { prints("\n掰掰,按太多下 <Enter> 了...\n"); refresh(); longjmp(byebye, -1); } getdata(0, 0, "请输入代号: ", newuser.userid, IDLEN + 1, DOECHO, NULL, true); flag = 1; if (id_invalid(newuser.userid) == 1) { prints("帐号必须由英文字母或数字组成,并且第一个字符必须是英文字母!\n"); /* prints("帐号必须由英文字母或数字,而且帐号第一个字是英文字母!\n"); */ flag = 0; } if (flag) { if (strlen(newuser.userid) < 2) { prints("代号至少需有两个英文字母!\n"); } else if ((strcasecmp(newuser.userid, "SYSOP") == 0) && (strcmp(newuser.userid, "SYSOP") != 0) && searchuser("SYSOP") == 0) { prints("抱歉,本站只允许注册*全部*大写的SYSOP用户ID。\n"); } else if (!strcasecmp(newuser.userid, "guest") && strcmp(newuser.userid, "guest") && !searchuser("guest")) { prints("抱歉,本站只允许注册*全部*小写的guest用户ID。\n"); } else if ((*newuser.userid == '\0') || bad_user_id(newuser.userid) || (strcasecmp(newuser.userid, "SYSOPS") == 0) || (strcasecmp(newuser.userid, "BMS") == 0)) { prints("抱歉,本站暂不提供此帐号注册。\n"); } else if (searchuser(newuser.userid) != 0) { /*( dosearchuser( newuser.userid ) ) midified by dong , 1998.12.2, change getuser -> searchuser , 1999.10.26 */ prints("此帐号已经有人使用\n"); } else { /*--- ---*/ struct stat lst; time_t lnow; lnow = time(NULL); sethomepath(genbuf, newuser.userid); if (!stat(genbuf, &lst) && S_ISDIR(lst.st_mode) && (lnow - lst.st_ctime < SEC_DELETED_OLDHOME /* 3600*24*30 */)) { prints("目前无法注册帐号%s,请与系统管理人员联系。\n", newuser.userid); sprintf(genbuf, "IP %s new id %s failed[home changed in past 30 days]", getSession()->fromhost, newuser.userid); bbslog("user","%s",genbuf); } else { /* etnlegend, 2006.10.14, 新用户可能继承原有同名用户信件... */ sethomepath(genbuf,newuser.userid); my_f_rm(genbuf); setmailpath(genbuf,newuser.userid); my_f_rm(genbuf); break; } } } } newuser.firstlogin = newuser.lastlogin = time(NULL) - 13 * 60 * 24; do_try = 0; while (1) { char passbuf[STRLEN], passbuf2[STRLEN]; if (++do_try >= 10) { prints("\n掰掰,按太多下 <Enter> 了...\n"); refresh(); longjmp(byebye, -1); } getdata(0, 0, "请设定您的密码: ", passbuf, 39, NOECHO, NULL, true); if (strlen(passbuf) < 4 || !strcmp(passbuf, newuser.userid)) { prints("密码太短或与使用者代号相同, 请重新输入\n"); continue; } getdata(0, 0, "请再输入一次你的密码: ", passbuf2, 39, NOECHO, NULL, true); if (strcmp(passbuf, passbuf2) != 0) { prints("密码输入错误, 请重新输入密码.\n"); continue; } setpasswd(passbuf, &newuser); #ifdef NEWSMTH strcpy(getSession()->passwd, passbuf); #endif break; } if (searchuser(newuser.userid) != 0) { prints("此帐号已经有人使用\n"); refresh(); longjmp(byebye, -1); } newuser.userlevel = PERM_BASIC; newuser.userdefine[0] = -1; newuser.userdefine[1] = -1; /* newuser.userdefine&=~DEF_MAILMSG; newuser.userdefine&=~DEF_EDITMSG; */ SET_UNDEFINE(&newuser, DEF_NOTMSGFRIEND); if (convcode) SET_UNDEFINE(&newuser, DEF_USEGB); SET_UNDEFINE(&newuser, DEF_SHOWREALUSERDATA); newuser.exittime = time(NULL) - 100; /*newuser.unuse2 = -1;*/ newuser.flags |= PAGER_FLAG; newuser.title = 0; newuser.firstlogin = newuser.lastlogin = time(NULL); allocid = getnewuserid2(newuser.userid); if (allocid > MAXUSERS || allocid <= 0) { prints("抱歉, 由于某些系统原因, 无法注册新的帐号.\n\r"); oflush(); sleep(2); exit(1); } newbbslog(BBSLOG_USIES, "APPLY: %s uid %d from %s", newuser.userid, allocid, getSession()->fromhost); update_user(&newuser, allocid, 1); if (!dosearchuser(newuser.userid)) { /* change by KCN 1999.09.08 fprintf(stderr,"User failed to create\n") ; */ prints("User failed to create %d-%s\n", allocid, newuser.userid); oflush(); exit(1); } bbslog("user","%s","new account"); #endif /* SECONDSITE */ }
static int ent_chat(int chatnum) { /* 进入聊天室 */ chatcontext *pthis; char inbuf[128]; int ch, cmdpos; int currchar; int modified; /* the line is modified? -- wwj */ int newmail; int page_pending = false; int chatting = true; #ifdef NEW_HELP int oldhelpmode=helpmode; #endif if (!strcmp(getCurrentUser()->userid, "guest")) return -1; pthis = (chatcontext *) malloc(sizeof(chatcontext)); bzero(pthis, sizeof(chatcontext)); if (!pthis) return -1; modify_user_mode(CHAT1); ch = ent_chat_conn(pthis, chatnum); if (ch != 1) { free(pthis); return ch; } #ifdef NEW_HELP helpmode=HELP_CHAT; #endif add_io(pthis->cfd, 0); modified = newmail = cmdpos = currchar = 0; /* update uinfo */ uinfo.in_chat = true; strcpy(uinfo.chatid, pthis->chatid); UPDATE_UTMP(in_chat, uinfo); UPDATE_UTMP_STR(chatid, uinfo); /* initiate screen */ clear(); pthis->chatline = 2; move(s_lines, 0); outs(msg_seperator); move(1, 0); outs(msg_seperator); print_chatid(pthis); memset(inbuf, 0, 80); /* chat begin */ while (chatting) { if (chat_checkparse(pthis) == 0) break; move(b_lines, currchar + 10); pthis->outputcount = 0; ch = igetkey(); if (ch==KEY_TALK) { int talkpage = servicepage(0, pthis->buf); if (talkpage != page_pending) { bell(); oflush(); printchatline(pthis, pthis->buf); page_pending = talkpage; } } if (chat_checkparse(pthis) == 0) break; if (ch == I_OTHERDATA) continue; switch (ch) { case KEY_UP: case KEY_DOWN: if (cmdpos == pthis->cmdpos) { strcpy(pthis->lastcmd[cmdpos], inbuf); modified = 0; } if (ch == KEY_UP) { if (cmdpos != (pthis->cmdpos + 1) % MAXLASTCMD) { int i = (cmdpos + MAXLASTCMD - 1) % MAXLASTCMD; if (pthis->lastcmd[i][0]) cmdpos = i; } } if (ch == KEY_DOWN) { if (cmdpos != pthis->cmdpos) cmdpos = (cmdpos + 1) % MAXLASTCMD; } strcpy(inbuf, pthis->lastcmd[cmdpos]); if (cmdpos == pthis->cmdpos) { modified = 1; } move(b_lines, 10); clrtoeol(); ch = inbuf[69]; inbuf[69] = 0; outs(inbuf); inbuf[69] = ch; currchar = strlen(inbuf); continue; #ifdef CHINESE_CHARACTER case Ctrl('R'): SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR); continue; #endif case KEY_LEFT: if (currchar) --currchar; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0;i<currchar;i++) if (j) j=0; else if (inbuf[i]<0) j=1; if (j) { currchar--; } } #endif continue; case KEY_RIGHT: if (inbuf[currchar]) ++currchar; #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0;i<currchar;i++) if (j) j=0; else if (inbuf[i]<0) j=1; if (j) { if (inbuf[currchar]) ++currchar; } } #endif continue; case KEY_ESC: case Ctrl('X'): inbuf[0] = 0; currchar = 0; move(b_lines, currchar + 10); clrtoeol(); modified = 1; continue; case Ctrl('A'): currchar = 0; continue; case Ctrl('E'): currchar = strlen(inbuf); continue; } if (!newmail && chkmail(0)) { /* check mail */ newmail = 1; printchatline(pthis, "\033[32m*** \033[31m当!你有新信来啦...\033[m"); } if (isprint2(ch)) { if (currchar < 126) { /* 未满一行,print it */ modified = 1; if (inbuf[currchar]) { /* insert */ int i; for (i = currchar; inbuf[i] && i < 127; i++); inbuf[i + 1] = '\0'; for (; i > currchar; i--) inbuf[i] = inbuf[i - 1]; } else { /* append */ inbuf[currchar + 1] = '\0'; } inbuf[currchar] = ch; ch = inbuf[69]; /* save the end of line */ inbuf[69] = 0; move(b_lines, currchar + 10); outs(&inbuf[currchar++]); inbuf[69] = ch; } continue; } if (ch == '\n' || ch == '\r') { if (currchar) { if (modified) { /* add to command history */ ch = sizeof(pthis->lastcmd[pthis->cmdpos]) - 1; strncpy(pthis->lastcmd[pthis->cmdpos], inbuf, ch); pthis->lastcmd[pthis->cmdpos][ch] = 0; pthis->cmdpos = (pthis->cmdpos + 1) % MAXLASTCMD; cmdpos = pthis->cmdpos; } else { /* use history, so can +1 */ cmdpos = (cmdpos + 1) % MAXLASTCMD; } if (inbuf[0] == '/' && Isspace(inbuf[1])) { /* discard / b */ printchatline(pthis, "\x1b[37m*** \x1b[32m请输入正确的指令,使用/h寻求帮助\x1b[37m ***\x1b[m"); } else { chatting = chat_cmd(pthis, inbuf); /*local命令处理 */ if (chatting == 0) chatting = chat_send(pthis, inbuf); if (inbuf[0] == '/') { ch = 1; while (inbuf[ch] != '\0' && inbuf[ch] != ' ') ch++; if (ch > 1) { if (!strncasecmp(inbuf, "/bye", ch)) break; if (!strncasecmp(inbuf, "/exit", ch)) break; /*added by alex, 96.9.5 */ } } } modified = 0; inbuf[0] = '\0'; currchar = 0; move(b_lines, 10); clrtoeol(); } continue; } if (ch == Ctrl('H') || ch == '\177') { /*Backspace */ if (currchar) { currchar--; inbuf[127] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 127 - currchar); move(b_lines, currchar + 10); clrtoeol(); ch = inbuf[69]; /* save the end of line */ inbuf[69] = 0; outs(&inbuf[currchar]); inbuf[69] = ch; } #ifdef CHINESE_CHARACTER if (DEFINE(getCurrentUser(), DEF_CHCHAR)) { int i,j=0; for (i=0;i<currchar;i++) if (j) j=0; else if (inbuf[i]<0) j=1; if (j) { currchar--; inbuf[127] = '\0'; memcpy(&inbuf[currchar], &inbuf[currchar + 1], 127 - currchar); move(b_lines, currchar + 10); clrtoeol(); ch = inbuf[69]; /* save the end of line */ inbuf[69] = 0; outs(&inbuf[currchar]); inbuf[69] = ch; } } #endif continue; } if (ch == Ctrl('Z')) { r_lastmsg(); /* Leeward 98.07.30 support msgX */ inbuf[0] = '\0'; currchar = 0; move(b_lines, 10); clrtoeol(); continue; } if (ch == Ctrl('C') /*|| ch == Ctrl('D') */) { /* ^C 退出 */ chat_send(pthis, "/b"); if (pthis->rec) set_rec(pthis,NULL); break; } } /* chat end */ if (pthis->rec)set_rec(pthis,NULL); close(pthis->cfd); add_io(0, 0); uinfo.in_chat = false; uinfo.chatid[0] = '\0'; UPDATE_UTMP(in_chat, uinfo); UPDATE_UTMP(chatid[0], uinfo); clear(); free(pthis); #ifdef NEW_HELP helpmode=oldhelpmode; #endif return 0; }
void doupdate(void) { /* TODO remove unnecessary refresh() call, to save CPU time */ register screenline_t *bp = big_picture; register int i, j; int len; if ((docls) || (abs(scrollcnt) >= (t_lines - 3))) { redrawwin(); return; } if (scrollcnt < 0) { if (!scrollrevlen) { redrawwin(); return; } rel_move(tc_col, tc_line, 0, 0); do { o_scrollrev(); } while (++scrollcnt); } else if (scrollcnt > 0) { rel_move(tc_col, tc_line, 0, b_lines); do { ochar('\n'); } while (--scrollcnt); } for (i = 0, j = roll; i < t_lines; i++, j++) { if (j >= t_lines) j = 0; bp = &big_picture[j]; len = bp->len; if (bp->mode & MODIFIED && bp->smod < len) { bp->mode &= ~(MODIFIED); #ifdef DBCSAWARE if (!(bp->mode & STANDOUT) && (HasUserFlag(UF_DBCS_NOINTRESC)) && DBCS_RemoveIntrEscape(bp->data, &len)) { // if anything changed, dirty whole line. bp->len = len; bp->smod = 0; bp->emod = len; } #endif // DBCSAWARE // disable this if you encounter some bugs. // bug history: // (1) input number (goto) in bbs list (search_num) [solved: search_num merged to vget] // (2) some empty lines becomes weird (eg, b_config) [not seen anymore?] #if 1 if (bp->smod > 0) { // more effort to determine ANSI smod int iesc; for (iesc = bp->smod-1; iesc >= 0; iesc--) { if (bp->data[iesc] == ESC_CHR) { bp->smod = 0;// iesc; bp->emod =len -1; break; } } } #endif if (bp->emod >= len) bp->emod = len - 1; rel_move(tc_col, tc_line, bp->smod, i); if (bp->mode & STANDOUT) standoutput((char *)bp->data, bp->smod, bp->emod + 1, bp->sso, bp->eso); else output((char *)&bp->data[bp->smod], bp->emod - bp->smod + 1); tc_col = bp->emod + 1; if (tc_col >= t_columns) { if (automargins) tc_col = t_columns - 1; else { tc_col -= t_columns; tc_line++; if (tc_line >= t_lines) tc_line = b_lines; } } } if (bp->oldlen > len) { /* XXX len/oldlen also count the length of escape sequence, * before we fix it, we must print ANSI_CLRTOEND everywhere */ rel_move(tc_col, tc_line, len, i); o_cleol(); } bp->oldlen = len; } rel_move(tc_col, tc_line, cur_col, cur_ln); oflush(); }
int bbs_zsendfile(char *filename, char *remote) { struct stat f; if (stat(filename, &f) != 0) return ERROR; Totalleft = f.st_size; Filesleft = 1; calc_blklen(Totalleft); protocol = ZM_ZMODEM; io_mode_fd = 1; blklen = start_blklen = 1024; if (setjmp(zmodemjmp) == 0) { zsendline_init(); io_mode(io_mode_fd, 1); readline_setup(io_mode_fd, 128, 256); raw_write(0, "rz\r", 3); /* TODO : throw away received input */ purgeline(io_mode_fd); stohdr(0L); zshhdr(ZRQINIT, Txhdr); zrqinits_sent++; oflush(); Crcflg = FALSE; firstsec = TRUE; bytcnt = (size_t) - 1; Totsecs = 0; if (wcs(filename, remote) == ERROR) { readline_clean(); return ERROR; } if (zmodem_requested) saybibi(); else if (protocol != ZM_XMODEM) { struct zm_fileinfo zi; char *pa; pa = (char *)malloc(PATH_MAX + 1); *pa = '\0'; zi.fname = pa; zi.modtime = 0; zi.mode = 0; zi.bytes_total = 0; zi.bytes_sent = 0; zi.bytes_received = 0; zi.bytes_skipped = 0; wctxpn(&zi); free(pa); } oflush(); /* here needs a oflush */ /* eat avalible input */ /* better to eat some input here */ io_mode(io_mode_fd, 0); readline_clean(); } else { oflush(); signal(SIGALRM, SIG_IGN); alarm(0); return ERROR; } return OK; }
static int myplay(int s, board_t board, board_t tmpbrd) { int ch, start_time; int endgame = 0, endturn = 0; chc_ipass = 0, chc_selected = 0; start_time = time(NULL); chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); bell(); while(!endturn) { chc_drawline(board, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); ch = igetkey(); chc_lefttime = CHC_TIMEOUT - (time(NULL) - start_time); if(chc_lefttime < 0) ch = 'q'; switch(ch) { case I_OTHERDATA: if(chc_recvmove(s)) { /* disconnect */ endgame = 1; endturn = 1; } else if(chc_from.r == -1 && chc_ipass) { endgame = 3; endturn = 1; } break; case KEY_UP: chc_cursor.r--; if(chc_cursor.r < 0) chc_cursor.r = BRD_ROW - 1; break; case KEY_DOWN: chc_cursor.r++; if(chc_cursor.r >= BRD_ROW) chc_cursor.r = 0; break; case KEY_LEFT: chc_cursor.c--; if(chc_cursor.c < 0) chc_cursor.c = BRD_COL - 1; break; case KEY_RIGHT: chc_cursor.c++; if(chc_cursor.c >= BRD_COL) chc_cursor.c = 0; break; case 'q': endgame = 2; endturn = 1; break; case 'p': chc_ipass = 1; chc_from.r = -1; chc_sendmove(s); strcpy(chc_warnmsg, "\033[1;33m要求和棋!\033[m"); chc_drawline(board, WARN_ROW); bell(); break; case '\r': case '\n': case ' ': if(chc_selected) { if(chc_cursor.r == chc_select.r && chc_cursor.c == chc_select.c) { chc_selected = 0; chc_drawline(board, LTR(chc_cursor.r)); } else if(chc_canmove(board, chc_select, chc_cursor)) { if(CHE_P(board[chc_cursor.r][chc_cursor.c]) == 1) endgame = 1; chc_from = chc_select; chc_to = chc_cursor; if(!endgame) { memcpy(tmpbrd, board, sizeof(board_t)); chc_movechess(tmpbrd); } if(endgame || !chc_iskfk(tmpbrd)) { chc_drawline(board, STEP_ROW); chc_movechess(board); chc_sendmove(s); chc_selected = 0; chc_drawline(board, LTR(chc_from.r)); chc_drawline(board, LTR(chc_to.r)); endturn = 1; } else { strcpy(chc_warnmsg, "\033[1;33m不可以王見王\033[m"); bell(); chc_drawline(board, WARN_ROW); } } } else if(board[chc_cursor.r][chc_cursor.c] && CHE_O(board[chc_cursor.r][chc_cursor.c]) == chc_turn) { chc_selected = 1; chc_select = chc_cursor; chc_drawline(board, LTR(chc_cursor.r)); } break; } } return endgame; }