static void chc_init(int s, board_t board) { userinfo_t *my = currutmp; setutmpmode(CHC); clear(); chc_warnmsg[0] = 0; chc_my = my->turn; chc_mateid = my->mateid; chc_firststep = 1; chc_init_board(board); chc_redraw(board); chc_cursor.r = 9, chc_cursor.c = 0; add_io(s, 0); if(my->turn) chc_recvmove(s); passwd_query(usernum, &xuser); cuser.chc_win = xuser.chc_win; cuser.chc_lose = xuser.chc_lose + 1; cuser.chc_tie = xuser.chc_tie; cuser.money = xuser.money; passwd_update(usernum, &cuser); getuser(chc_mateid); chc_hiswin = xuser.chc_win; chc_hislose = xuser.chc_lose; chc_histie = xuser.chc_tie; if(!my->turn) { chc_sendmove(s); chc_hislose++; } chc_redraw(board); }
void u_exit(char *mode) { userec_t xuser; int diff = (time(0) - login_start_time) / 60; passwd_query(usernum, &xuser); auto_backup(); setflags(PAGER_FLAG, currutmp->pager != 1); setflags(CLOAK_FLAG, currutmp->invisible); xuser.invisible = currutmp->invisible % 2; xuser.pager = currutmp->pager % 5; if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) do_aloha("<<下站通知>> -- 我走囉!"); purge_utmp(currutmp); if((cuser.uflag != enter_uflag) || (currmode & MODE_DIRTY) || !diff) { xuser.uflag = cuser.uflag; xuser.numposts = cuser.numposts; if(!diff && cuser.numlogins) xuser.numlogins = --cuser.numlogins; /* Leeym 上站停留時間限制式 */ reload_money(); passwd_update(usernum, &xuser); } log_usies(mode, NULL); }
int cmd_passwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { int ret; ret = passwd_update(argv[1], argv[2]); if (ret < 0) { nsh_output(vtbl, g_fmtcmdfailed, argv[0], "passwd_update", NSH_ERRNO_OF(-ret)); return ERROR; } return OK; }
int passwd_sync_update(int num, userec_t * buf) { if (num < 1 || num > MAX_USERS) return -1; // money update should be done before everything. buf->money = moneyof(num); if (passwd_update(num, buf) != 0) return -1; if (num == usernum) cuser.money = moneyof(num); return 0; }
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 user_login() { char ans[4], i; char genbuf[200]; struct tm *ptime, *tmp; time_t now; int a; /*** Heat:廣告詞 char *ADV[17] = { "記得唷!! 5/12在台大二活地下室見~~~", "你知道Ptt之夜是什麼嗎? 5/12號就要上演耶 快去問吧!", "5/12 Ptt之夜即將引爆 能不去嗎? 在台大二活地下室咩", "不來就落伍了 啥? 就Ptt之夜啊 很棒的晚會唷 時間:5/12", "差點忘了提醒你 5/12我們有約 就台大二活地下室咩!!", "Ptt是啥 想知嗎? 5/12在台大二活地下室告訴你唷", "來來來....5/12快到台大二活地下室去拿獎品吧~~", "去去去...到台大二活地下室去 就5/12麻 有粉多獎品耶", "喂喂喂 怎還楞在這!!快呼朋引伴大鬧ptt", "Ptt最佳豬腳 換你幹幹看 5/12來吧....*^_^*", "幹什麼幹什麼?? 你怎麼不曉得啥是Ptt之夜..老土唷", "累了嗎? 讓我們來為你來一段精采表演吧.. 5/12 Ptt之夜", "世紀末最屁力的晚會 就在台大二活地下室 5/12不見不散 gogo", "到底誰比較帥(美) 來比比吧 5/12Ptt之夜 一較高下", "台大二活地下室 5/12 聽說會有一場很棒的晚會唷 Ptt之夜", "台大二活地下室 5/12 你能不來嗎?粉多網友等著你耶", "5/12 台大二活地下室 是各約網友見面的好地方呢", }; char *ADV[] = { "7/17 @LIVE 亂彈, 何欣穗 的 入場卷要送給 ptt 的愛用者!", "欲知詳情請看 PttAct 板!!", }; ***/ log_usies("ENTER", getenv("RFC931") /* fromhost */ ); setproctitle("%s: %s", margs, cuser.userid); /* resolve all cache */ resolve_garbage(); /* get ptt cache */ resolve_fcache(); resolve_boards(); /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); mysrand(); /* 初始化: random number 增加user跟時間的差異 */ currmode = MODE_STARTED; enter_uflag = cuser.uflag; /* get local time */ time(&now); ptime = localtime(&now); tmp = localtime(&cuser.lastlogin); if((a = utmpshm->number) > fcache->max_user) { sem_init(FROMSEM_KEY, &fcache_semid); sem_lock(SEM_ENTER, fcache_semid); fcache->max_user = a; fcache->max_time = now; sem_lock(SEM_LEAVE, fcache_semid); } #ifdef INITIAL_SETUP if(!getbnum(DEFAULT_BOARD)) { strcpy(currboard, "尚未選定"); } else #endif { brc_initial(DEFAULT_BOARD); set_board(); } /* 畫面處理開始 */ if(!(HAS_PERM(PERM_SYSOP) && HAS_PERM(PERM_DENYPOST))) do_aloha("<<上站通知>> -- 我來啦!"); if(ptime->tm_mday == cuser.day && ptime->tm_mon + 1 == cuser.month) { more("etc/Welcome_birth", NA); currutmp->birth = 1; } else { more("etc/Welcome_login", NA); // pressanykey(); // more("etc/CSIE_Week", NA); currutmp->birth = 0; } if(cuser.userlevel) { /* not guest */ move(t_lines - 4, 0); prints(" 歡迎您第 \033[1;33m%d\033[0;37m 度拜訪本站," "上次您是從 \033[1;33m%s\033[0;37m 連往本站,\n" " 我記得那天是 \033[1;33m%s\033[0;37m。\n", ++cuser.numlogins, cuser.lasthost, Cdate(&cuser.lastlogin)); currutmp->mind=rand()%8; /* 初始心情 */ pressanykey(); if(currutmp->birth && tmp->tm_mday != ptime->tm_mday) { more("etc/birth.post", YEA); brc_initial("WhoAmI"); set_board(); do_post(); } setuserfile(genbuf, str_badlogin); if(more(genbuf, NA) != -1) { getdata(b_lines - 1, 0, "您要刪除以上錯誤嘗試的記錄嗎(Y/N)?[Y]", ans, 3, LCECHO); if(*ans != 'n') unlink(genbuf); } check_register(); strncpy(cuser.lasthost, fromhost, 16); cuser.lasthost[15] = '\0'; restore_backup(); } else if(!strcmp(cuser.userid, STR_GUEST)) { char *nick[13] = { "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", "鐵罐", "考卷", "大美女"}; char *name[13] = { "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲"}; char *addr[13] = { "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", "遠方", "原本海", "NIKE", "蘇聯", "男八618室", "愛之味", "天上", "藍色珊瑚礁"}; i = login_start_time % 13; sprintf(cuser.username, "海邊漂來的%s", nick[(int)i]); sprintf(currutmp->username, cuser.username); sprintf(cuser.realname, name[(int)i]); sprintf(currutmp->realname, cuser.realname); sprintf(cuser.address, addr[(int)i]); cuser.sex = i % 8; currutmp->pager = 2; pressanykey(); } else pressanykey(); if(!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; reload_money(); passwd_update(usernum, &cuser); for(i = 0; i < NUMVIEWFILE; i++) if((cuser.loginview >> i) & 1) more(loginview_file[(int)i][0], YEA); }
int m_sob(void) { char genbuf[256], buf[256], userid[25], passbuf[24], msg[2048]=""; int count=0, i, isimported=0, corrected; FILE *fp; sobuserec man; time4_t d; clear(); move(1,0); outs( " 請注意 這是只給陽光沙灘使用者!\n" " 讓沙灘的使用者轉移個人資產以及重要信用資料, 享有平等安全的環境.\n" " 如果您不需要, 請直離開.\n" " -----------------------------------------------------------------\n" " 特別叮嚀:\n" " 為了帳號安全,您只有連續十次密碼錯誤的機會,請小心輸入.\n" " 連續次錯誤您的變身功\能就會被開罰單並直接通知站長.\n" " 請不要在變身過程中不正常斷線, 刻意斷線變半獸人站長不救唷.\n" ); if(getkey("是否要繼續?(y/N)")!='y') return 0; if(search_ulistn(usernum,2)) {vmsg("請登出其他視窗, 以免變身失敗"); return 0;} do { if(!getdata(10,0, " 沙灘的ID [大小寫要完全正確]:", userid, 20, DOECHO)) return 0; if(bad_user_id(userid)) continue; sprintf(genbuf, "sob/passwd/%c/%s.inf",userid[0], userid); if(!(fp=fopen(genbuf, "r"))) { isimported = 1; strcat(genbuf, ".done"); if(!(fp=fopen(genbuf, "r"))) { vmsg("查無此人或已經匯入過..請注意大小寫 "); isimported = 0; continue; } } count = fread(&man, sizeof(man), 1, fp); fclose(fp); }while(!count); count = 0; do{ if(!getdata(11,0, " 沙灘的密碼:", passbuf, sizeof(passbuf), NOECHO)) return 0; if(++count>=10) { cuser.userlevel |= PERM_VIOLATELAW; cuser.vl_count++; passwd_update(usernum, &cuser); post_violatelaw(cuser.userid, "[PTT警察]", "測試帳號錯誤十次", "違法觀察"); mail_violatelaw(cuser.userid, "[PTT警察]", "測試帳號錯誤十次", "違法觀察"); return 0; } if(!(corrected = checkpasswd(man.passwd, passbuf))) vmsg("密碼錯誤"); } while(!corrected); move(12,0); clrtobot(); if(!isimported) { if(!dashf(genbuf)) // avoid multi-login { vmsg("請不要嘗試多重id踹匯入"); return 0; } sprintf(buf,"%s.done",genbuf); rename(genbuf,buf); #ifdef MERGEMONEY reload_money(); sprintf(buf, "您的沙灘鸚鵡螺 %10d 換算成 " MONEYNAME " 幣為 %9d (匯率 22:1), \n" " 沙灘貝殼有 %10d 換算為 " MONEYNAME " 幣為 %9d (匯率 222105:1), \n" " 原有 %10d 匯入後共有 %d\n", (int)man.goldmoney, (int)man.goldmoney/22, (int)man.silvermoney, (int)man.silvermoney/222105, cuser.money, (int)(cuser.money + man.goldmoney/22 + man.silvermoney/222105)); demoney(man.goldmoney/22 + man.silvermoney/222105 ); strcat(msg, buf); #endif i = cuser.exmailbox + man.exmailbox + man.exmailboxk/2000; if (i > MAX_EXKEEPMAIL) i = MAX_EXKEEPMAIL; sprintf(buf, "您的沙灘信箱有 %d (%dk), 原有 %d 匯入後共有 %d\n", man.exmailbox, man.exmailboxk, cuser.exmailbox, i); strcat(msg, buf); cuser.exmailbox = i; if(man.userlevel & PERM_MAILLIMIT) { sprintf(buf, "開啟信箱無上限\n"); strcat(msg, buf); cuser.userlevel |= PERM_MAILLIMIT; } if (cuser.firstlogin > man.firstlogin) d = man.firstlogin; else d = cuser.firstlogin; cuser.firstlogin = d; if (cuser.numlogins < man.numlogins) i = man.numlogins; else i = cuser.numlogins; sprintf(buf, "沙灘進站次數 %d 此帳號 %d 將取 %d \n", man.numlogins, cuser.numlogins, i); strcat(msg,buf); cuser.numlogins = i; if (cuser.numposts < man.numposts ) i = man.numposts; else i = cuser.numposts; sprintf(buf, "沙灘文章次數 %d 此帳號 %d 將取 %d\n", man.numposts,cuser.numposts,i); strcat(msg,buf); cuser.numposts = i; outs(msg); while (search_ulistn(usernum,2)) {vmsg("請將重覆上站其他線關閉! 再繼續");} passwd_update(usernum, &cuser); } sethomeman(genbuf, cuser.userid); mkdir(genbuf, 0755); sprintf(buf, "tar zxvf %c/%s.tar.gz>/dev/null", userid[0], userid); chdir("sob/home"); system(buf); chdir(BBSHOME); if (getans("是否匯入個人信箱? (Y/n)")!='n') { sethomedir(buf, cuser.userid); sprintf(genbuf, "sob/home/%c/%s/.DIR", userid[0], userid); merge_dir(buf, genbuf, 1); strcat(msg, "匯入個人信箱\n"); } if(getans("是否匯入個人信箱精華區(個人作品集)? (會覆蓋\現有設定) (y/N)")=='y') { fileheader_t fh; sprintf(buf, "rm -rd home/%c/%s/man>/dev/null ; " "mv sob/home/%c/%s/man home/%c/%s>/dev/null;" "mv sob/home/%c/%s/gem home/%c/%s/man>/dev/null", cuser.userid[0], cuser.userid, userid[0], userid, cuser.userid[0], cuser.userid, userid[0], userid, cuser.userid[0], cuser.userid); system(buf); strcat(msg, "匯入個人信箱精華區(個人作品集)\n"); sprintf(buf,"home/%c/%s/man/gem", cuser.userid[0], cuser.userid); if(dashd(buf)) { strcat(fh.title, "◆ 個人作品集"); strcat(fh.filename, "gem"); sprintf(fh.owner, cuser.userid); sprintf(buf, "home/%c/%s/man/.DIR", cuser.userid[0], cuser.userid); append_record(buf, &fh, sizeof(fh)); } }
int main(int argc, char *argv[]) { int bmid, i, j=0; FILE *inf, *firef; time4_t now=time(NULL); attach_SHM(); resolve_boards(); if(passwd_init()) exit(1); memcpy(allbrd,bcache,numboards*sizeof(boardheader_t)); /* write out the target file */ inf = fopen(OUTFILE, "w+"); if (inf == NULL) { printf("open file error : %s\n", OUTFILE); exit(1); } firef = fopen(FIREFILE, "w+"); if (firef == NULL) { printf("open file error : %s\n", FIREFILE); exit(1); } fprintf(inf, "警告: 板主若超過(不包含) %d天未上站,將予於免職\n", LAZY_BM_LIMIT_DAYS); fprintf(inf, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "--------------------------\n"); fprintf(firef, "免職板主\n"); fprintf(firef, "看板名稱 " " 板主 幾天沒來啦\n" "---------------------------------------------------" "--------------------------\n"); j = 0; for (i = 0; i < numboards; i++) { char *p, bmbuf[IDLEN * 3 + 3]; int index = 0, flag = 0, k, n; userec_t xuser; p = allbrd[i].BM; if (*p == '[') p++; if (allbrd[i].brdname[0] == '\0' || !isalpha(allbrd[i].brdname[0]) ) continue; p = strtok(p,"/ ]"); for(index=0; p && index<5; index++) { int diff; // XXX what if bmid is invalid? if(!p[0] || (bmid = passwd_load_user(p, &xuser)) < 1) { index--; p=strtok(NULL,"/ ]"); continue; } strlcpy(bms[index].bmname, p, sizeof(bms[index].bmname)); bms[index].flag = 0; diff = now - xuser.lastlogin; if (diff < 0) diff = 0; if (diff >= 45 * 86400 && !(xuser.userlevel & PERM_SYSOPHIDE) && !(xuser.userlevel & PERM_SYSOP)) { strlcpy(lostbms[j].bmname, p, sizeof(bms[index].bmname)); lostbms[j].title = allbrd[i].brdname; lostbms[j].ctitle = allbrd[i].title; lostbms[j].lostdays = diff / 86400; //超過 LAZY_BM_LIMIT_DAYS 天 免職 if (lostbms[j].lostdays > LAZY_BM_LIMIT_DAYS) { xuser.userlevel &= ~PERM_BM; bms[index].flag = 1; flag = 1; // NOTE: 好像不改也無所謂,目前拔 BM 是自動的。 passwd_update(bmid, &xuser); } j++; } p = strtok(NULL,"/ ]"); } if (flag == 1) { boardheader_t *bp = getbcache(i+1); // 確認我們沒搞錯 cache. 如果 cache 炸了就別用了 if (strcmp(bp->brdname, allbrd[i].brdname) != 0) { printf("ERROR: unmatched cache!!! (%s - %s)\n", bp->brdname, allbrd[i].brdname); bp = NULL; exit(1); // sync to latest memcpy(&allbrd[i], bp, sizeof(boardheader_t)); } bmbuf[0] = '\0'; for (k = 0, n = 0; k < index; k++) { if (!bms[k].flag) { if (n++ != 0) strcat(bmbuf, "/"); strcat(bmbuf, bms[k].bmname); } } strcpy(allbrd[i].BM, bmbuf); printf("board %s: %s -> %s\n", allbrd[i].brdname, bp->BM, allbrd[i].BM); strcpy(bp->BM, allbrd[i].BM); if (substitute_record(BBSHOME"/"FN_BOARD, &allbrd[i], sizeof(boardheader_t), i+1) == -1) { printf("Update Board Failed: %s\n", allbrd[i].brdname); } reset_board(i+1); } } qsort(lostbms, j, sizeof(lostbm), bmlostdays_cmp); //write to the etc/toplazyBM for (i = 0; i < j; i++) { if (lostbms[i].lostdays > LAZY_BM_LIMIT_DAYS) { fprintf(firef, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, lostbms[i].bmname,lostbms[i].lostdays); } else { fprintf(inf, "%-*.*s%-*.*s%-*.*s%3d天沒上站\n", IDLEN, IDLEN, lostbms[i].title, BTLEN-10, BTLEN-10, lostbms[i].ctitle, IDLEN,IDLEN, lostbms[i].bmname,lostbms[i].lostdays); } } fclose(inf); fclose(firef); //printf("Total %d boards.\n", count); //mail to the users for (i=0; i<j; i++) { fileheader_t mymail; char genbuf[200]; int lostdays; lostdays = lostbms[i].lostdays; if (lostdays != LAZY_BM_LIMIT_DAYS/2 && lostdays != LAZY_BM_LIMIT_DAYS*2/3 && lostdays != LAZY_BM_LIMIT_DAYS*5/6 && lostdays <= LAZY_BM_LIMIT_DAYS) continue; sprintf(genbuf, BBSHOME "/home/%c/%s", lostbms[i].bmname[0], lostbms[i].bmname); stampfile(genbuf, &mymail); strcpy(mymail.owner, "[" BBSMNAME "警察局]"); if (lostdays <= LAZY_BM_LIMIT_DAYS) sprintf(mymail.title, ANSI_COLOR(32) "版主通知" ANSI_RESET " %s版版主%s", lostbms[i].title, lostbms[i].bmname); else sprintf(mymail.title, ANSI_COLOR(32) "版主自動免職通知" ANSI_RESET " %s 版主 %s", lostbms[i].title, lostbms[i].bmname); unlink(genbuf); if (lostdays <= LAZY_BM_LIMIT_DAYS) Link(OUTFILE, genbuf); else Link(FIREFILE, genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname); append_record(genbuf, &mymail, sizeof(mymail)); } return 0; }