/*ARGSUSED*/ AllUsersFunc( int indx, ACCOUNT *acct, struct enum_info *info ) { if (info->topline == info->currline) { move(info->topline-1, 0); prints("%-14s %-30s %s\n","User Id", "User Name", "Last Login"); } prints("%-14s %-30s %c %s", acct->userid, acct->username, BITISSET(acct->flags, FLG_EXEMPT) ? 'X': ' ', (acct->lastlogin == 0) ? "\n":ctime((time_t *)&acct->lastlogin)); info->currline++; info->count++; if (info->currline > info->bottomline) { int ch; standout(); prints("--MORE--"); standend(); clrtoeol(); while((ch = igetch()) != EOF) { if(ch == '\n' || ch == '\r' || ch == ' ') break; if(toupper(ch) == 'Q') { move(info->currline, 0); clrtoeol(); return ENUM_QUIT; } else bell(); } info->currline = info->topline; } return S_OK; }
Monitor() { void (*asig)(); char ch; int saved_alarm; if (global_modechar_key[0] == '\0') form_modechar_key(); clear(); prints("Monitor Mode Press CTRL-C \ or CTRL-D to exit.\n"); prints("%s\n", global_modechar_key); prints("-----------------------------------------------------------\ ------------------\n"); if (global_ulist == NULL) { if (SetupGlobalList() == -1) return PARTUPDATE; } monitor_idle = 0; bbs_set_mode(M_MONITOR); saved_alarm = alarm(0); asig = signal(SIGALRM, SIG_IGN); monitor_refresh(0); while (1) { ch = igetch(); monitor_idle = 0; if (ch == CTRL('C') || ch == CTRL('D')) break; } alarm(0); signal(SIGALRM, asig); if (saved_alarm) alarm(saved_alarm); bbs_set_mode(M_UNDEFINED); memset(global_ulist, 0, global_ulist_sz * sizeof(*global_ulist)); return FULLUPDATE; }
dumbreturn() { int ch ; prints("Press [RETURN] to continue") ; while((ch = igetch()) != EOF) if(ch == '\n' || ch == '\r') break ; }
static int do_terminal_getchar(void) { int ch = igetch(); // Handle messages. if (ch == Ctrl('Z')) { if (!msg_num) RMSG = true; } return ch; }
static int show_win(int hk) { char buf[50]; // gotoxy(48,16); if(hk>0) { sprintf(buf ,"%s贏了!再來一場? ",!fturn?"●":"○"); return getans2(16, 48, buf, 0, 2, 'y'); } else return getans2(16, 48, "平手!再來一場? ", 0, 2, 'y'); return igetch(); }
int igetkey() { int mode; int ch, last; mode = last = 0; while (1) { ch = igetch(); if (mode == 0) { if (ch == KEY_ESC) mode = 1; else return ch; /* Normal Key */ } else if (mode == 1) { /* Escape sequence */ if (ch == '[' || ch == 'O') mode = 2; else if (ch == '1' || ch == '4') mode = 3; else { KEY_ESC_arg = ch; return KEY_ESC; } } else if (mode == 2) { /* Cursor key */ if (ch >= 'A' && ch <= 'D') return KEY_UP + (ch - 'A'); else if (ch >= '1' && ch <= '6') mode = 3; else return ch; } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ if (ch == '~') return KEY_HOME + (last - '1'); else return ch; } last = ch; } }
/*ARGSUSED*/ OnlineUsersFunc( int indx, USEREC *urec, struct enum_info *info ) { if (info->topline == info->currline) { move(info->topline-1, 0); prints("%-12s %-25s %-25s %s %s\n", "User Id", "User Name", "From", "P", "Mode"); } prints("%-12s %c %-25s %-25s %c %s\n", urec->userid, BITISSET(urec->flags, FLG_CLOAK) ? '#': ' ', urec->username, urec->fromhost, BITISSET(urec->flags, FLG_NOPAGE) ? 'N': ' ', ModeToString(urec->mode)); info->currline++; info->count++; if (info->currline > info->bottomline) { int ch; standout(); prints("--MORE--"); standend(); clrtoeol(); while((ch = igetch()) != EOF) { if(ch == '\n' || ch == '\r' || ch == ' ') break; if(toupper(ch) == 'Q') { move(info->currline, 0); clrtoeol(); return ENUM_QUIT; } else bell(); } info->currline = info->topline; } return S_OK; }
Chat() { CHATID chatid; char cbuf[CHATLINE_TEXT_MAX+1]; int cfd; int rc; int done_chatting = 0; int margin, curspos, maxpos, endpos; int ch, i; int metakey = 0; int shift, shiftdelta; move(2, 0); clrtobot(); do { if (getdata(2,0,"Enter chatid: ",chatid,sizeof chatid,DOECHO,1)==-1) return FULLUPDATE; if (*chatid == '\0') { strncpy(chatid, myinfo.userid, CHATID_MAX); chatid[CHATID_MAX] = '\0'; } rc = bbs_chat(chatid, (LONG *)&cfd); switch (rc) { case S_OK: break; case S_BADCHATID: case S_CHATIDINUSE: bbperror(rc, NULL); break; default: bbperror(rc, "Error entering chat"); return PARTUPDATE; } } while (rc != S_OK); add_io(cfd, 0); chat_resetscreen(chatid); memset(cbuf, '\0', sizeof cbuf); margin = CHATID_MAX+2; maxpos = sizeof(cbuf) - margin - 1; curspos = 0; endpos = 0; shift = 0; shiftdelta = (t_columns - margin) / 2; while (!done_chatting) { move(g_echatwin+1, margin+(curspos-shift)); ch = igetch(); if (NewPagePending()) { chat_show_page_request(); } if (ch == -1) done_chatting = 1; else if (ch == I_OTHERDATA) { /* Incoming! */ if (chat_process_incoming(cfd, chatid) == -1) done_chatting = 1; } else if (metakey) { switch (ch) { case 'b': case 'B': if (curspos == 0) bell(); else { while (curspos && isspace(cbuf[curspos-1])) curspos--; while (curspos && !isspace(cbuf[curspos-1])) curspos--; } break; case 'f': case 'F': if (curspos == endpos) bell(); else { while (curspos < endpos && isspace(cbuf[curspos])) curspos++; while (curspos < endpos && !isspace(cbuf[curspos])) curspos++; } break; default: bell(); } metakey = 0; } else switch (ch) { case '\r': case '\n': if (endpos > 0) { cbuf[endpos] = '\n'; done_chatting = chat_process_local(cbuf, chatid); if (done_chatting == -1) { done_chatting = (bbs_chat_send(cbuf) != S_OK); } } memset(cbuf, '\0', sizeof cbuf); endpos = curspos = 0; move(g_echatwin+1, margin); clrtoeol(); break; case CTRL('A'): if (curspos == 0) bell(); else curspos = 0; break; case CTRL('B'): if (curspos == 0) bell(); else curspos--; break; case CTRL('C'): bbs_chat_send("/e\n"); done_chatting = 1; break; case CTRL('D'): if (curspos == endpos) bell(); else { for (i=curspos; i<endpos; i++) cbuf[i] = cbuf[i+1]; endpos--; move(g_echatwin+1, margin+(curspos-shift)); prints("%s", cbuf+curspos); clrtoeol(); } break; case CTRL('E'): if (curspos == endpos) bell(); else curspos = endpos; break; case CTRL('F'): if (curspos == endpos) bell(); else curspos++; break; case CTRL('H'): case 127: if (curspos == 0) bell(); else { for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i]; endpos--; curspos--; move(g_echatwin+1, margin+(curspos-shift)); prints("%s", cbuf+curspos); clrtoeol(); } break; case CTRL('U'): if (endpos == 0) bell(); else { memset(cbuf, '\0', sizeof cbuf); curspos = endpos = 0; move(g_echatwin+1, margin); clrtoeol(); } break; case CTRL('W'): if (curspos == 0) bell(); else { while (curspos && isspace(cbuf[curspos-1])) { for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i]; curspos--, endpos--; } while (curspos && !isspace(cbuf[curspos-1])) { for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i]; curspos--, endpos--; } move(g_echatwin+1, margin+(curspos-shift)); prints("%s", cbuf+curspos); clrtoeol(); } break; case 27: /* ESC */ metakey = 1; break; default: if (isprint(ch) && endpos < maxpos) { for (i=endpos; i>curspos; i--) cbuf[i] = cbuf[i-1]; cbuf[curspos] = ch; move(g_echatwin+1, margin+(curspos-shift)); prints("%s", cbuf+curspos); curspos++; endpos++; } else bell(); } if (curspos-shift >= (t_columns-margin)) { while (curspos-shift >= (t_columns-margin)) shift += shiftdelta; move(g_echatwin+1, margin); prints("%s", cbuf+shift); clrtoeol(); } else if (curspos < shift) { while (curspos < shift) shift -= shiftdelta; move(g_echatwin+1, margin); prints("%s", cbuf+shift); clrtoeol(); } } bbs_exit_chat(); g_you_have_mail = 0; add_io(0, 0); return FULLUPDATE; }
int main_dice() { int money; /* 押金 */ int i; /* 亂數 */ char choice; /* 記錄選項 */ char dice[3]; /* 三個骰子的值 */ char total; /* 三個骰子的和 */ char buf[60]; if (HAS_STATUS(STATUS_COINLOCK)) { vmsg(msg_coinlock); return XEASY; } vs_bar("ㄒㄧ ㄅㄚ ㄌㄚ 下注"); outs("\n\n\n" "┌────────────────────────────────────┐\n" "│ 2倍 1. 大 2. 小 │\n" "│ 14倍 3. 三點 4. 四點 5. 五點 6. 六點 7. 七點 │\n" "│ 8倍 8. 八點 9. 九點 10. 十點 11. 十一點 12. 十二點 13. 十三點│\n" "│ 14倍 14. 十四點 15. 十五點 16. 十六點 17. 十七點 18. 十八點 │\n" "│216倍 19. 一一一 20. 二二二 21. 三三三 22. 四四四 23. 五五五 24. 六六六│\n" "└────────────────────────────────────┘\n"); #if 0 /* 擲骰子每 216 次各總數出現的次數機率 */ ┌──┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┐ │總數│3 │4 │5 │6 │7 │8 │9 │10│11│12│13│14│15│16│17│18│ ├──┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ │次數│1 │3 │6 │10│15│21│25│27│27│25│21│15│10│6 │3 │1 │ / 216 次 └──┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ #endif out_song(); while (1) { vget(2, 0, "請問要下注多少呢?(1 ~ 50000) ", buf, 6, DOECHO); money = atoi(buf); if (money < 1 || money > 50000 || money > cuser.money) break; /* 離開賭場 */ vget(12, 0, "要押哪一項呢?(請輸入號碼) ", buf, 3, DOECHO); choice = atoi(buf); if (choice < 1 || choice > 24) break; /* 離開賭場 */ outs("\n按任一鍵擲出骰子 \033[5m....\033[m\n"); igetch(); /* 決定三個骰子點數 */ total = 0; for (i = 0; i < 3; i++) { dice[i] = rnd(6) + 1; total += dice[i]; } /* 處理結果 */ if ((choice == 1 && total > 10) || (choice == 2 && total <= 10)) /* 處理大小 */ { sprintf(buf, "中了!得到2倍獎金 %d 元", money * 2); addmoney(money); } else if (choice <= 18 && total == choice) /* 處理總和 */ { if (choice >= 8 && choice <= 13) { sprintf(buf, "中了!得到8倍獎金 %d 元", money * 8); addmoney(money * 7); } else { sprintf(buf, "中了!得到14倍獎金 %d 元", money * 14); addmoney(money * 13); } } else if ((choice - 18) == dice[0] && (dice[0] == dice[1]) && (dice[1] == dice[2]))/* 處理三個一樣 */ { sprintf(buf, "中了!得到216倍獎金 %d 元", money * 216); addmoney(money * 215); } else /* 處理沒中 */ { strcpy(buf, "很可惜沒有押中!"); cuser.money -= money; } /* 印出骰子結果 */ outs("╭────╮╭────╮╭────╮\n"); for (i = 0; i < 3; i++) { prints("│%s││%s││%s│\n", pic[dice[0] - 1][i], pic[dice[1] - 1][i], pic[dice[2] - 1][i]); } outs("╰────╯╰────╯╰────╯\n\n"); out_song(); vmsg(buf); } return 0; }
void usercomplete(char *prompt, char *data) { char *temp; char *cwbuf, *cwlist; int cwnum, x, y, origx, origy; int clearbot = NA, count = 0, morenum = 0; char ch; cwbuf = malloc(MAX_USERS * (IDLEN + 1)); cwlist = u_namearray((arrptr)cwbuf, &cwnum, ""); temp = data; outs(prompt); clrtoeol(); getyx(&y, &x); getyx(&origy, &origx); standout(); prints("%*s", IDLEN + 1, ""); standend(); move(y, x); while((ch = igetch()) != EOF) { if(ch == '\n' || ch == '\r') { int i; char *ptr; *temp = '\0'; outc('\n'); ptr = (char *)cwlist; for(i = 0; i < cwnum; i++) { if(strncasecmp(data, ptr, IDLEN + 1) == 0) strcpy(data, ptr); ptr += IDLEN + 1; } break; } else if(ch == ' ') { int col, len; if(cwnum == 1) { strcpy(data, (char *)cwlist); move(y, x); outs(data + count); count = strlen(data); temp = data + count; getyx(&y, &x); continue; } clearbot = YEA; col = 0; len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); move(2, 0); clrtobot(); printdash("使用者代號一覽表"); while(len + col < 79) { int i; for(i = 0; morenum < cwnum && i < p_lines; i++) { move(3 + i, col); prints("%s ", cwlist + (IDLEN + 1) * morenum++); } col += len + 2; if(morenum >= cwnum) break; len = UserMaxLen((arrptr)cwlist, cwnum, morenum, p_lines); } if(morenum < cwnum) { move(b_lines, 0); outs(msg_more); } else morenum = 0; move(y, x); continue; } else if(ch == '\177' || ch == '\010') { if(temp == data) continue; temp--; count--; *temp = '\0'; cwlist = u_namearray((arrptr)cwbuf, &cwnum, data); morenum = 0; x--; move(y, x); outc(' '); move(y, x); continue; } else if(count < STRLEN && isprint(ch)) { int n; *temp++ = ch; *temp = '\0'; n = UserSubArray((arrptr)cwbuf, (arrptr)cwlist, cwnum, ch, count); if(n == 0) { temp--; *temp = '\0'; continue; } cwlist = cwbuf; count++; cwnum = n; morenum = 0; move(y, x); outc(ch); x++; } } free(cwbuf); if(ch == EOF) /* longjmp(byebye, -1); */ raise(SIGHUP); /* jochang: don't know if this is necessary */ outc('\n'); refresh(); if(clearbot) { move(2, 0); clrtobot(); } if(*data) { move(origy, origx); outs(data); outc('\n'); } }
void namecomplete(char *prompt, char *data) { char *temp; word_t *cwlist, *morelist; int x, y, origx, origy; int ch; int count = 0; int clearbot = NA; if(toplev == NULL) AddNameList(""); cwlist = GetSubList("", toplev); morelist = NULL; temp = data; outs(prompt); clrtoeol(); getyx(&y, &x); getyx(&origy, &origx); standout(); prints("%*s", IDLEN + 1, ""); standend(); move(y, x); refresh(); while((ch = igetch()) != EOF) { if(ch == '\n' || ch == '\r') { *temp = '\0'; outc('\n'); if(NumInList(cwlist) == 1) strcpy(data, cwlist->word); ClearSubList(cwlist); break; } if(ch == ' ') { int col, len; if(NumInList(cwlist) == 1) { strcpy(data, cwlist->word); move(y, x); outs(data + count); count = strlen(data); temp = data + count; getyx(&y, &x); continue; } clearbot = YEA; col = 0; if(!morelist) morelist = cwlist; len = MaxLen(morelist, p_lines); move(2, 0); clrtobot(); printdash("相關資訊一覽表"); while(len + col < 80) { int i; for(i = p_lines; (morelist) && (i > 0); i--) { move(3 + (p_lines - i), col); outs(morelist->word); morelist = morelist->next; } col += len + 2; if(!morelist) break; len = MaxLen(morelist, p_lines); } if(morelist) { move(b_lines, 0); outs(msg_more); } move(y, x); continue; } if(ch == '\177' || ch == '\010') { if(temp == data) continue; temp--; count--; *temp = '\0'; ClearSubList(cwlist); cwlist = GetSubList(data, toplev); morelist = NULL; x--; move(y, x); outc(' '); move(y, x); continue; } if(count < STRLEN && isprint(ch)) { word_t *node; *temp++ = ch; count++; *temp = '\0'; node = GetSubList(data, cwlist); if(node == NULL) { temp--; *temp = '\0'; count--; continue; } ClearSubList(cwlist); cwlist = node; morelist = NULL; move(y, x); outc(ch); x++; } } if(ch == EOF) /* longjmp(byebye, -1); */ raise(SIGHUP); /* jochang: don't know if this is necessary... */ outc('\n'); refresh(); if(clearbot) { move(2, 0); clrtobot(); } if(*data) { move(origy, origx); outs(data); outc('\n'); } }
int use_dict() { FILE *fp; char lang[150], word[80] = ""; char j, f, buf[120], sys[] = "|\033[31me\033[m:編籍字典"; int i = 0; setutmpmode(DICT); if(!HAS_PERM(PERM_SYSOP)) sys[0]=0; clear(); sprintf(buf,"\033[45m ●\033[1;44;33m" " %-14s\033[3;45m ● ", dict); strcpy(&buf[100],"\033[m\n"); for(;;) { move(0, 0); sprintf(lang, " 請輸入關鍵字串(%s) 或指令(h,t,a)\n", dict); outs(lang); sprintf(lang, "[\033[32m<關鍵字>\033[m|\033[32mh\033[m:help|\033[32m" "t\033[m:所有資料|\033[32ma\033[m:新增資料%s]\n:", sys); outs(lang); getdata(2, 0, ":", word, 18, DOECHO); outs("資料搜尋中請稍候...."); strcpy(word,lower(word)); if(word[0] == 0) return 0; clear(); move(4, 0); outs(buf); if(strlen(word) == 1) { if(word[0] == 'a') { clear(); move(4,0); outs(buf); addword(word); continue; } else if(word[0] == 't') word[0] = 0; else if(word[0] == 'h') { more("etc/dict.hlp",YEA); clear(); continue; } else if(word[0]=='e') { vedit(database,NA, NULL); clear(); continue; } else { outs("字串太短,請輸入多一點關鍵字"); continue; } } if((fp = fopen(database,"r"))) { i = 0; while(fgets(lang,150,fp) != NULL) { if(lang[65] == '[') { lang[65] = 0; f = 1; } else f = 0; if(strstr(lower(lang),word)) { if(f == 1) lang[65] = '['; outs(lang); i++; if(!((i+1)%17)) { move(23, 0); outs("\033[45m " "任意鍵繼續 Q:離開 " "\033[m "); j = igetch(); if(j == 'q') break; else { clear(); move(4,0); outs(buf); } } } } } fclose(fp); if(i == 0) { getdata(5, 0, "沒這個資料耶,新增嗎?(y/N)", lang, 3, LCECHO); if(lang[0] == 'y') { clear(); move(4,0); outs(buf); addword(word); } } } }
int igetkey() { int mode; int ch, last, llast; int ret=0; if (keybuffer_count) { ret = *keybuffer; keybuffer++; keybuffer_count--; return ret; } mode = last = llast = 0; // if (ibufsize == icurrchar) // refresh(); while (1) { ch = igetch(); if (kicked) return KEY_TIMEOUT; if (check_calltime()) { mode = 0; continue; } #if defined(SMTH) || defined(FREE) if (scrint&&ch==Ctrl('V')) { if (getCurrentUser()&&HAS_PERM(getCurrentUser(),PERM_BASIC)&&!HAS_PERM(getCurrentUser(),PERM_DENYRELAX)&&uinfo.mode!=LOCKSCREEN&&!dicting) { dicting=1; exec_mbem("@mod:service/libdict.so#dict_main"); dicting=0; } continue; } #endif if (scrint&&(ch == KEY_TALK) && talkrequest) { if (uinfo.mode != CHAT1 && uinfo.mode != CHAT2 && uinfo.mode != CHAT3 && uinfo.mode != CHAT4 && uinfo.mode != TALK && uinfo.mode != PAGE) { talkreply(); return KEY_REFRESH; } else return KEY_TALK; } if (mode == 0) { if (ch == KEY_ESC) { if (ibufsize==icurrchar) { switch (uinfo.mode) { case POSTING: case SMAIL: case EDITUFILE: case EDITSFILE: case NOTEPAD: case EDIT: case EDITANN: case RMAIL: case CALENEDIT: case CSIE_ANNOUNCE: case POSTCROSS: break; default: return KEY_ESC; } } mode = 1; } else { ret = ch; break; /* Normal Key */ } } else if (mode == 1) { /* Escape sequence */ if (ch == '[' || ch == 'O') mode = 2; else if (ch == '1' || ch == '4') mode = 3; else { KEY_ESC_arg = ch; return KEY_ESC; } } else if (mode == 2) { /* Cursor key */ if (ch >= 'A' && ch <= 'D') { ret = KEY_UP + (ch - 'A'); break; } else if (ch >= 'P' && ch <= 'S') { ret = KEY_F1+ch-'P'; break; } else if (ch >= '1' && ch <= '6') mode = 3; else { ret = ch; break; } } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ if (ch == '~') { ret = KEY_HOME + (last - '1'); break; } else if (ch >= '0' && ch <= '9') mode = 4; else { ret = ch; break; } } else if (mode == 4) { if (ch == '~') { int k=(llast-'1')*10+(last-'1'); if (k<=3) ret = KEY_F1+k; else ret = KEY_F1+k-1; if (scrint&&ret==KEY_F10&&!incalendar) { mode=0; if (getCurrentUser()&&!HAS_PERM(getCurrentUser(),PERM_DENYRELAX)&&uinfo.mode!=LOCKSCREEN) exec_mbem("@mod:service/libcalendar.so#calendar_main"); continue; } else if (scrint&&ret==KEY_F6) { mode=0; auto_chinese(); continue; } else if (scrint&&ret==KEY_F9) { mode=0; if (getCurrentUser()&& (check_mail_perm(getCurrentUser(),NULL) == 0)) mailscr(); continue; } break; } else { ret = ch; break; } } llast = last; last = ch; } #ifdef NEW_HELP if (scrint && ret == KEY_F1 && uinfo.mode != LOCKSCREEN && !f1ing) { int oldmode = uinfo.mode; modify_user_mode(HELP); f1ing=1; newhelp(helpmode); f1ing=0; modify_user_mode(oldmode); return igetkey(); } #endif if (scrint&&keymem_total&&!skip_key&&!ingetdata) { int i,j,p; for (i=0; i<keymem_total; i++) { p=!keymem[i].status[0]; if (keymem[i].status[0]==-1) continue; j=0; while (keymem[i].status[j]&&j<10) { if (keymem[i].status[j]==uinfo.mode) p=1; j++; } if (p&&ret==keymem[i].key) { j=0; while (keymem[i].mapped[j]&&j<10) j++; if (j==0) continue; ret = keymem[i].mapped[0]; keybuffer_count = j-1; keybuffer = keymem[i].mapped+1; break; } } } return ret; }
int _getdata(int line, int col, const char *prompt, char *buf, int len, int echo, char *prefix) { unsigned char ch; int clen = 0; int x, y; int pre_len = (prefix) ? strlen(prefix) : 0; if (prompt) { move(line, col); clrtoeol(); /* lthuang */ outs(prompt); } if (!dumb_term) { clrtoeol(); getyx(&y, &x); } while (1) { if (pre_len) { ch = prefix[clen]; pre_len--; } else ch = igetch(); #ifndef _BBS_UTIL_ #if 1 if (dumb_term && !init_enter) { fflush(stdout); if (ch == 255) { /* 255 == IAC */ while (ch == 255) { if ((ch = igetch()) == 250) { /* 250 == SB */ while ((ch = igetch()) != 240); /* 240 == SE */ ch = igetch(); continue; } else if (ch == 255) /* if really send 255 * char */ break; igetch(); /* DO, DONT, WILL, WONT * on */ ch = igetch(); } } } #endif #endif if (ch == '\n' || ch == '\r') break; else if (ch == ' ') { if (echo & XNOSP) continue; /* chang */ } #if 1 else if (ch == 0x1b) /* 0x1b is ESC */ { /* chang */ ch = igetch(); if (ch == '1' || ch == '4') /* lthuang */ igetch(); else if (ch == '[' || ch == 'O') /* lthuang */ { ch = igetch(); if (ch >= '1' && ch <= '6') igetch(); } continue; } #endif else if (ch == '\177' || ch == CTRL('H')) { if (clen == 0) { bell(); continue; } clen--; x--; if (dumb_term) { ochar(CTRL('H')); outc(' '); ochar(CTRL('H')); } else { move(y, x); outc(' '); move(y, x); refresh(); } continue; } else if (!isprint2(ch)) { bell(); continue; } if (!dumb_term && x >= (t_columns - 1)) { bell(); continue; } if (clen >= len - 1) { bell(); continue; } buf[clen++] = (echo & XLCASE) ? tolower(ch) : ch; outc((echo & XECHO) ? ch : '*'); #ifdef _BBS_UTIL_ refresh(); #endif x++; } buf[clen] = '\0'; outc('\n'); return clen; }
int gagb() { int money; char genbuf[200], buf[80]; char ans[5] = ""; /* ±¶ÂÊ 0 1 2 3 4 5 6 7 8 9 10 */ float bet[11] = {0, 100, 50, 10, 3, 1.5, 1.2, 0.9, 0.8, 0.5, 0.1}; int a, b, c, count; modify_user_mode(M_XAXB); srandom(time(0)); money = get_money(0,"game/gagb.welcome"); if(!money) return 0; move(6, 0); prints("[36m%s[m", MSG_SEPERATOR); move(17, 0); prints("[36m%s[m", MSG_SEPERATOR); do { itoa(random() % 10000, ans); for (a = 0; a < 3; a++) for (b = a + 1; b < 4; b++) if (ans[a] == ans[b]) ans[0] = 0; } while (!ans[0]); for (count = 1; count < 11; count++) { do { getdata(5, 0, "Çë²Â[q - Í˳ö] ¡ú ", genbuf, 5, DOECHO, YEA); if (!strcmp(genbuf, "Good")) { prints("[%s]", ans); sprintf(genbuf,"²ÂÊý×Ö×÷±×, ÏÂ×¢ %d Ôª", money); gamelog(genbuf); igetch(); } if ( genbuf[0] == 'q' || genbuf[0] == 'Q' ) { sprintf(buf,"·ÅÆú²Â²â, ¿Û³ýѹע½ð¶î %d Ôª.", money); gamelog(buf); return; } c = atoi(genbuf); itoa(c, genbuf); for (a = 0; a < 3; a++) for (b = a + 1; b < 4; b++) if (genbuf[a] == genbuf[b]) genbuf[0] = 0; if (!genbuf[0]) { move ( 18,3 ); prints("ÊäÈëÊý×ÖÓÐÎÊÌâ!!"); pressanykey(); move ( 18,3 ); prints(" "); } } while (!genbuf[0]); move(count + 6, 0); prints(" [1;31mµÚ [37m%2d [31m´Î£º [37m%s -> [33m%dA [36m%dB [m", count, genbuf, an(genbuf, ans), bn(genbuf, ans)); if (an(genbuf, ans) == 4) break; } if (count > 10) { sprintf(buf, "ÄãÊäÁËßÏ£¡ÕýÈ·´ð°¸ÊÇ %s£¬Ï´ÎÔÙ¼ÓÓÍ°É!!", ans); sprintf(genbuf,"[1;31m¿ÉÁ¯Ã»²Âµ½£¬ÊäÁË %d Ôª£¡[m", money); gamelog(genbuf); } else { int oldmoney = money; money *= bet[count]; inmoney(money); if (money - oldmoney > 0) sprintf(buf, "¹§Ï²£¡×ܹ²²ÂÁË %d ´Î£¬¾»×¬½±½ð %d Ôª", count, money - oldmoney); else if (money - oldmoney == 0) sprintf(buf, "°¦¡«¡«×ܹ²²ÂÁË %d ´Î£¬Ã»ÊäûӮ£¡", count); else sprintf(buf, "°¡¡«¡«×ܹ²²ÂÁË %d ´Î£¬ÅâÇ® %d Ôª£¡", count, oldmoney - money); } gamelog(buf); move(22, 0); clrtobot(); prints(buf); pressanykey(); return 0; }
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; }
static void write_request(int sig) { struct tm *ptime; time_t now; extern char watermode; time(&now); ptime = localtime(&now); if(currutmp->pager != 0 && cuser.userlevel != 0 && currutmp->msgcount != 0 && currutmp->mode != TALK && currutmp->mode != EDITING && currutmp->mode != CHATING && currutmp->mode != PAGE && currutmp->mode != IDLE && currutmp->mode != MAILALL && currutmp->mode != MONITOR) { int i; char c0 = currutmp->chatid[0]; int currstat0 = currstat; unsigned char mode0 = currutmp->mode; currutmp->mode = 0; currutmp->chatid[0] = 2; currstat = XMODE; do { bell(); show_last_call_in(1); igetch(); currutmp->msgcount--; if(currutmp->msgcount>=MAX_MSGS) { /* this causes chaos... jochang */ raise(SIGFPE); } memcpy(&oldmsg[(int)no_oldmsg], &currutmp->msgs[0], sizeof(msgque_t)); no_oldmsg++; no_oldmsg %= MAX_REVIEW; if(oldmsg_count < MAX_REVIEW) oldmsg_count++; for(i = 0; i < currutmp->msgcount; i++) currutmp->msgs[i] = currutmp->msgs[i + 1]; } while(currutmp->msgcount); currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; } else { bell(); show_last_call_in(1); memcpy(&oldmsg[(int)no_oldmsg], &currutmp->msgs[0], sizeof(msgque_t)); no_oldmsg++; no_oldmsg %= MAX_REVIEW; if(oldmsg_count < MAX_REVIEW) oldmsg_count++; if(watermode > 0) { if(watermode < oldmsg_count) watermode++; t_display_new(); } refresh(); currutmp->msgcount = 0; } }