Пример #1
0
int kick_user( struct user_info *userinfo )
{
    int     id, ind;
    struct user_info uin;
    struct userec kuinfo;
    char    kickuser[40], buffer[40];

    if (uinfo.mode != LUSERS && uinfo.mode != OFFLINE && uinfo.mode != FRIEND)
    {
        modify_user_mode(ADMIN);
        stand_title("踢使用者下站");
        move(1, 0);
        usercomplete("输入使用者帐号: ", kickuser);
        if (*kickuser == '\0')
        {
            clear();
            return 0;
        }
        if (!(id = getuser(kickuser)))
        {
            move(3, 0);
            prints("无效的用户 ID!");
            clrtoeol();
            pressreturn();
            clear();
            return 0;
        }
        move(1, 0);
        clrtoeol();
        sprintf(genbuf,"踢掉使用者 : [%s].", kickuser);
        move(2, 0);
        if (askyn(genbuf, NA, NA) == NA)
        {
            move(2, 0);
            prints("取消踢使用者..\n");
            pressreturn();
            clear();
            return 0;
        }
        search_record(PASSFILE, &kuinfo, sizeof(kuinfo), cmpuids, kickuser);
        ind = search_ulist(&uin, t_cmpuids, id);
    }
    else
    {
        uin = *userinfo;
        strcpy(kickuser, uin.userid);
        ind = YEA;
    }
    if (!ind||!uin.active||(uin.pid && kill(uin.pid, 0)==-1))
    {
        if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND)
        {
            move(3, 0);
            prints("用户 [%s] 不在线上",kickuser);
            clrtoeol();
            pressreturn();
            clear();
        }
        return 0;
    }
    kill(uin.pid, SIGHUP);
    //sprintf(buffer, "kicked %s", kickuser);
    //report(buffer);
    if(strcmp(currentuser.userid , kickuser))
    {
        char    secu[STRLEN];
        sprintf(secu, "将用户[%s]踢下站", kickuser);
        securityreport(secu);
    }
    sprintf(genbuf, "%s (%s)", kuinfo.userid, kuinfo.username);
    log_usies("KICK ", genbuf);
    move(2, 0);
    if(uinfo.mode!=LUSERS&&uinfo.mode!=OFFLINE&&uinfo.mode!=FRIEND)
    {
        prints("用户 [%s] 已经被踢下站.\n",kickuser);
        pressreturn();
        clear();
    }
    return 1;
}
Пример #2
0
int mainNum(int fighting /* Thor.990317: 對戰模式 */)
{
  Num myNumber;
  char buf[80];
  int money;
  /* 倍率        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}; 
  /* initialize variables */
#if 1
  if(!hisList) hisList = (His *)malloc(sizeof(His)); /* pseudo */
  if(!numSet) numSet = (char *)malloc(10*9*8*7*sizeof(char));
#endif

  hisNum = 0;       

  numNum = 10*9*8*7;
  memset(numSet, 0, numNum*sizeof(char));

  srand(time(NULL));

  /* Thor.990317:對戰模式 */
  stand_title(fighting ? "猜數字大戰" :"傻瓜猜數字"); /* clear(); */

  do{
    move(0,0);
    prints("您身上還有 %d 元",cuser.silvermoney);
    getdata(1, 0, "要押注多少錢(1 - 250000)? ", buf, 7, DOECHO,0);
    money=atoi(buf);
    if(!buf[0])return;
    if(check_money(money,SILVER)) return;
  }while((money<1)||(money>250000));

  /* Thor.990221: 有人反應離不開 */
  if(answer("想好您的數字了嗎?[y/N]")!='y')
  {
    pressanykey("不玩了啊? 下次再來哦! ^_^");
    return 0;
  }

  if(fighting)
    ord2Num(rand() % numNum, myNumber); /* Thor.990317:對戰模式 */

  demoney(money);
  /* while there is possibility */
  for(;;)
  {
    Num myGuess, yourGuess;
    int youA,youB, myA, myB;

    if(fighting)  /* Thor.990317:對戰模式 */
    {
      int i , a , b;
      char tmp[50];
     do{
      getdata(b_lines-3, 0, "您猜我的數字是[????]:", tmp, 5, DOECHO,0);
      /* Thor.990317: 為簡化, 不作checking */
      if(!tmp[0]) goto abort_game;
      if(tmp[0] == '!' && HAS_PERM(PERM_SYSOP))
        pressanykey("%d%d%d%d",myNumber[0],myNumber[1],myNumber[2],myNumber[3]);
      for (a=0;a<3;a++)
      for (b=a+1;b<4;b++)
      if(tmp[a]==tmp[b])
        tmp[0]=0;
      if(!tmp[0])
      {
        pressanykey("輸入數字有問題!!"); 
      }
      
      }while  (!tmp[0]);    
      for(i=0;i<4;i++) 
        yourGuess[i] = tmp[i] - '0';
      AB(myNumber,yourGuess, &myA, &myB);
      move(b_lines-2,0); clrtoeol();
      move(b_lines-2,0);
      prints("我說 \033[1m%dA%dB \033[m", myA, myB);
     
      if(myA==4)
      {
        int m = money ,e = ba ;
        /* you win  */
#if 1
        game_log(NumFight,"猜了%d次,贏了%d元,EXP %d 點"
          , hisNum,(int)bet[hisNum]*money,(int)bet[hisNum]*ba);
#endif
        if(hisNum > 10) hisNum = 10;
        m *= bet[hisNum]; e *= bet[hisNum];
        inmoney(m);
//        inexp(e); 
//        pressanykey("您贏了! 好崇拜 ^O^,獎金 %d 元,經驗值 %d 點!",m,e);
        pressanykey("您贏了! 好崇拜 ^O^,獎金 %d 元!",m);
        return 0;
      }  
    }

    /* pickup a candidate number */
    for(;;)
    {
      int i;
      /* pickup by random */
      if(numNum<=0) 
        goto foolme;
      i = rand() % numNum;
      i = getth(i, numSet); /* i-th ordering num */
      numSet[i] = 1; numNum--; /* filtered out */
      ord2Num(i, myGuess); /* convert ordering num to Num */

      /* check history */
      if(matchHis(myGuess))
        break;
    }

    /* show the picked number */
    move(b_lines - 1, 0); clrtoeol();
    move(b_lines - 1, 0); 
    prints("我猜您的數字是 \033[1;37m%d%d%d%d\033[m",myGuess[0], myGuess[1], myGuess[2], myGuess[3]);

    /* get ?A?B */
    for(;;)
    {
      char buf[5];
      /* get response */
      getdata(b_lines, 0, "您的回答[?A?B]:", buf, 5, DOECHO,0);

      if(!buf[0])
      {
abort_game:
        /* abort */
        pressanykey("不玩了啊? 下次再來哦! ^_^");
#if 1
        game_log(NumFight,"猜了%d次,不想玩了!", hisNum);
#endif
        return 0;
      }
      if(isdigit(buf[0]) && (buf[1]|0x20) == 'a'
       &&isdigit(buf[2]) && (buf[3]|0x20) == 'b' )
      {
        youA = buf[0] - '0';
        youB = buf[2] - '0';
        /* check legimate */
        if(youA >= 0 && youA <=4
          && youB >=0 && youB <= 4
          && youA + youB <= 4)
        {
          /* if 4A, end the game */
          if(youA == 4)
          {
           int m=money,e=ba;   
#if 1
           game_log(NumFight,"猜了%d次,輸給電腦!", hisNum);
#endif
           /* I win  */
           if(hisNum > 10) hisNum = 10;  
           m *= bet[10 - hisNum]*0.1; e *= bet[10 - hisNum];
//           pressanykey("我贏了! 厲害吧 ^O^,賠你 %d 元,得到 %d 點經驗值",m,e);
	   pressanykey("我贏了! 厲息a ^O^,賠你 %d 元!",m);
           inmoney(m); 
//           inexp(e); 
           return 0;
          }
          else
            break;
        }
      }
      /* err A B */
      outmsg("輸入格式有誤");
    }
    /* put in history */
    hisNum ++;
    hisList = (His *) realloc(hisList, hisNum * sizeof(His)); /* assume must succeeded */
    memcpy(hisList[hisNum - 1].n, myGuess, sizeof(Num));
    hisList[hisNum - 1].A=youA;
    hisList[hisNum - 1].B=youB;

    move(2+hisNum,0);
    if(fighting) /* Thor.990317: 對戰模式 */
      prints("第 \033[1;37m%d\033[m 次, 你猜 \033[1;36m%d%d%d%d\033[m, 我說 \033[1;33m%dA%dB\033[m; 我猜 \033[1;33m%d%d%d%d\033[m, 你說 \033[1;36m%dA%dB\033[m", hisNum, yourGuess[0], yourGuess[1], yourGuess[2], yourGuess[3], myA, myB, myGuess[0], myGuess[1], myGuess[2], myGuess[3], youA, youB);
    else
      prints("第 \033[1;37m%d\033[m 次, 我猜 \033[1;33m%d%d%d%d\033[m, 你說 \033[1;36m%dA%dB\033[m", hisNum, myGuess[0], myGuess[1], myGuess[2], myGuess[3], youA, youB);
  }
foolme:
  /* there is no posibility, show "you fool me" */
  pressanykey("你騙我! 不跟你玩了 ~~~>_<~~~");
#if 1
      game_log(NumFight,"猜了%d次,耍電腦,被趕出去!", hisNum);
#endif
  return 0;
}
Пример #3
0
int scan_register_form(char* regfile)
{
    static char *field[] = {"usernum", "userid", "realname", "dept",
                            "addr", "phone", "regip", NULL
                           };
    static char *finfo[] = {"帐号位置", "申请帐号", "真实姓名", "学校系级",
                            "目前住址", "连络电话", "注册ip  ", NULL
                           };
    static char *reason[] = {"请确实填写真实姓名(不可使用拼音).",
                             "请详填学校院系与年级 (注明系和年级或者工作单位和工作部门).",
                             "请填写完整的住址资料 (完整详细,能够通信).",
                             "请详填连络电话 (固定电话需填写区号).",
                             "请勿穿梭注册.",
                             "请如实详细填写注册申请表.",
                             "请用中文填写申请表.",
                             "同一个用户注册了过多ID.", NULL
                            };
    struct userec uinfo;
    FILE   *fn, *fout, *freg;
    char    fdata[7][STRLEN];
    char    fname[STRLEN], buf[STRLEN];
    char    ans[5], *ptr, *uid;
    int     n, unum;
    uid = currentuser.userid;
    char numofreason[2];//tdhlshx for refuse.
    int total;
    int iis;
    int realnumofrea[8];//add end

    stand_title("依序设定所有新注册资料");
    sprintf(fname, "%s.tmp", regfile);
    move(2, 0);
    if (dashf(fname))
    {
        move(1, 0);
        prints("其他 SYSOP 正在查看注册申请单, 请检查使用者状态.\n");
        getdata(2, 0, "你确定没有其他 SYSOP 在审核注册单吗 ? [y/N]: ", ans, 2, DOECHO, YEA);
        if (ans[0] == 'Y' || ans[0] == 'y')
            f_cp(fname, regfile, O_APPEND);
        else
        {
            pressreturn();
            return -1;
        }
    }
    rename(regfile, fname);
    if ((fn = fopen(fname, "r")) == NULL)
    {
        move(2, 0);//请管理员输入未通过原因:
        prints("系统错误, 无法读取注册资料档: %s\n", fname);
        pressreturn();
        return -1;
    }
    memset(fdata, 0, sizeof(fdata));
    while (fgets(genbuf, STRLEN, fn) != NULL)
    {
        if ((ptr = (char *) strstr(genbuf, ": ")) != NULL)
        {
            *ptr = '\0';
            for (n = 0; field[n] != NULL; n++)
            {
                if (strcmp(genbuf, field[n]) == 0)
                {
                    strcpy(fdata[n], ptr + 2);
                    if ((ptr = (char *) strchr(fdata[n], '\n')) != NULL)
                        *ptr = '\0';
                }
            }
        }
        else if ((unum = getuser(fdata[1])) == 0)
        {
            move(2, 0);
            clrtobot();
            prints("系统错误, 查无此帐号.\n\n");
            for (n = 0; field[n] != NULL; n++)
                prints("%s     : %s\n", finfo[n], fdata[n]);
            pressreturn();
            memset(fdata, 0, sizeof(fdata));
        }
        else
        {
            memcpy(&uinfo, &lookupuser, sizeof(uinfo));
            move(1, 0);
            prints("帐号位置     : %d\n", unum);
            disply_userinfo(&uinfo);
            move(15, 0);
            printdash(NULL);
            for (n = 0; field[n] != NULL; n++)
                prints("%s     : %s\n", finfo[n], fdata[n]);
            if (uinfo.userlevel & PERM_LOGINOK)
            {
                move(t_lines - 1, 0);
                prints("此帐号不需再填写注册单.\n");
                igetkey();
                ans[0] = 'D';
            }
            else
            {
                getdata(t_lines - 1, 0, "是否接受此资料 (Y/N/Q/Del/Skip)? [S]: ",
                        ans, 3, DOECHO, YEA);
            }
            move(1, 0);
            clrtobot();
            switch (ans[0])
            {
            case 'D':
            case 'd':
                break;
            case 'Y':
            case 'y':
                prints("以下使用者资料已经更新:\n");
                n = strlen(fdata[5]);
                if (n + strlen(fdata[3]) > 60)
                {
                    if (n > 40)
                        fdata[5][n = 40] = '\0';
                    fdata[3][60 - n] = '\0';
                }
                strncpy(uinfo.realname, fdata[2], NAMELEN);
                strncpy(uinfo.address, fdata[4], NAMELEN);
                sprintf(genbuf, "%s$%s@%s", fdata[3], fdata[5], uid);
                genbuf[STRLEN - 16] = '\0';
                strncpy(uinfo.reginfo, genbuf, STRLEN - 17);
#ifdef ALLOWGAME

                uinfo.money = 1000;
#endif

                uinfo.lastjustify = time(0);
                substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
                sethomefile(buf, uinfo.userid, "register");
                if (dashf(buf))
                {
                    sethomefile(genbuf, uinfo.userid, "register.old");
                    rename(buf, genbuf);
                }
                if ((fout = fopen(buf, "w")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(fout, "%s: %s\n", field[n], fdata[n]);
                    n = time(NULL);
                    getdatestring(n,NA);
                    fprintf(fout, "Date: %s\n", datestring);
                    fprintf(fout, "Approved: %s\n", uid);
                    fclose(fout);
                }
                mail_file("etc/s_fill", uinfo.userid, "恭禧你,你已经完成注册。");
                mail_file("etc/fornewcomers",uinfo.userid,"欢迎加入 "BBSNAME" 大家庭");//tdhlshx 新手FAQ信件
                sethomefile(buf, uinfo.userid, "mailcheck");
                unlink(buf);
                sprintf(genbuf, "让 %s 通过身份确认.", uinfo.userid);
                securityreport4(genbuf);
                break;
            case 'Q':
            case 'q':
                if ((freg = fopen(regfile, "a")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(freg, "%s: %s\n", field[n], fdata[n]);
                    fprintf(freg, "----\n");
                    while (fgets(genbuf, STRLEN, fn) != NULL)
                        fputs(genbuf, freg);
                    fclose(freg);
                }
                break;
            case 'N':
            case 'n':
                for(total=0; total<8; total++)
                    realnumofrea[total]=0;
                for (n = 0; field[n] != NULL; n++)
                    prints("%s: %s\n", finfo[n], fdata[n]);
                printdash(NULL);
                move(9, 0);
                prints("请依次输入退回申请表原因的序号并回车确认,直接回车结束.\n\n");
                //	prints("请选择/输入退回申请表原因, 按 <enter> 取消.\n\n");
                for (n = 0; reason[n] != NULL; n++)
                    prints("%d) %s\n", n, reason[n]);
                getdata(12+n,0,"退回原因:",numofreason,2,DOECHO,YEA);
                //	getdata(12 + n, 0, "退回原因: ", buf, 60, DOECHO, YEA);
                if(numofreason[0]!='\0'&&numofreason[0]>='0'&&numofreason[0]<='7')
                {
                    total=atoi(numofreason);
                    realnumofrea[total]=1;
                    move(14+n,0);
                    prints("您已经选择的理由有:\n%d  ",total);
                }
                while(numofreason[0]!='\0')
                {
                    getdata(12+n,0,"退回原因:",numofreason,2,DOECHO,YEA);
                    if(numofreason[0]>='0'&&numofreason[0]<='7')
                    {
                        total=atoi(numofreason);
                        if(realnumofrea[total]==0)
                            realnumofrea[total]=1;
                        else
                            realnumofrea[total]=0;
                        move(14+n,0);
                        clrtobot();
                        prints("您已经选择的理由有:\n");
                        for(iis=0; iis<8; iis++)
                        {
                            if(realnumofrea[iis]==1)
                                prints("%d  ",iis);
                        }
                    }
                }
                system("cp /home/bbs/etc/f_fill  /home/bbs/tmp/fletter");
                char FL[STRLEN];
                sprintf(FL,"/home/bbs/tmp/fletter");
                FILE * fail=fopen(FL,"a");
                if(fail==NULL)
                {
                    prints("Error,创建临时文件错误.请与系统维护联系或再次尝试!");
                    pressanykey();
                    return -1;
                }

                {
                    fprintf(fail,"\n\n您被拒绝注册的原因大概如下:\n");
                    for(total=0; total<8; total++)
                    {
                        if(realnumofrea[total]==1)
                        {
                            strcpy(buf,reason[total]);
                            fprintf(fail,"\n%s",buf);
                        }
                    }
                    sprintf(genbuf,"很抱歉的告诉您,您这次注册失败.:(");
                    strncpy(uinfo.address, genbuf, NAMELEN);
                    substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
                    fclose(fail);
                    mail_file(FL,uinfo.userid, uinfo.address);
                    system("rm -f /home/bbs/tmp/fletter");

                }
                break;
            /*if (buf[0] != '\0') {
            if (buf[0] >= '0' && buf[0] < '0' + n) {
            	strcpy(buf, reason[buf[0] - '0']);
            }
            sprintf(genbuf, "<注册失败> - %s", buf);
            strncpy(uinfo.address, genbuf, NAMELEN);
            substitute_record(PASSFILE, &uinfo, sizeof(uinfo), unum);
            mail_file("etc/f_fill", uinfo.userid, uinfo.address);*/
            /* user_display( &uinfo, 1 ); */
            /* pressreturn(); */
            /*	break;
            }
            move(10, 0);
            clrtobot();
            prints("取消退回此注册申请表.\n");*/
            /* run default -- put back to regfile */
            default:
                if ((freg = fopen(regfile, "a")) != NULL)
                {
                    for (n = 0; field[n] != NULL; n++)
                        fprintf(freg, "%s: %s\n", field[n], fdata[n]);
                    fprintf(freg, "----\n");
                    fclose(freg);
                }
            }
            memset(fdata, 0, sizeof(fdata));
        }
    }
    fclose(fn);
    unlink(fname);
    return (0);
}