Example #1
0
File: newio.c Project: zhouqt/kbs
int multi_getdata(int line, int col, int maxcol, char *prompt, char *buf, int len, int maxline, int clearlabel, int textmode)
{
    int ch, x, y, startx, starty, now, i, j, k, i0, chk, cursorx, cursory;
    char savebuffer[25][LINELEN*3];
    bool init=true;
    char tmp[1024];
    extern int RMSG;

    /*************stiger************
     * textmode 0 :  ctrl+q换行,enter发表
     * textmode 1 :  enter换行,ctrl+w发送
     *********************************/

    if (uinfo.mode!=MSGING && uinfo.mode != POSTTMPL)
        ingetdata = true;
    if (clearlabel == true) {
        buf[0] = 0;
    }
    move(line, col);
    if (prompt)
        prints("%s", prompt);
    getyx(&starty, &startx);
    now = strlen(buf);
    for (i=0; i<=24; i++)
        saveline(i, 0, savebuffer[i]);
    strncpy(tmp, buf, 1024);
    tmp[1023]=0;
    cursory = starty;
    cursorx = startx;

    while (1) {
        y = starty; x = startx;
        move(y, x);
        chk = 0;
        if (now==0) {
            cursory = y;
            cursorx = x;
        }
        for (i=0; i<strlen(buf); i++) {
            if (chk) chk=0;
            else if (buf[i]<0) chk=1;
            if (chk&&x>=maxcol) x++;
            if (buf[i]!=13&&buf[i]!=10) {
                if (x>maxcol) {
                    clrtoeol();
                    x = 0;
                    y++;
                    if (y>=scr_lns) {
                        scroll();
                        starty--;
                        cursory--;
                        y--;
                    }
                    move(y, x);
                }
                if (init) prints("\x1b[4m");
                prints("%c", buf[i]);
                resetcolor();
                x++;
            } else {
                clrtoeol();
                x = 0;
                y++;
                if (y>=scr_lns) {
                    scroll();
                    starty--;
                    cursory--;
                    y--;
                }
                move(y, x);
            }
            if (i==now-1) {
                cursory = y;
                cursorx = x;
            }
        }
        clrtoeol();
        move(cursory, cursorx);
        ch = igetkey();
        if (textmode == 0) {
            if ((ch == '\n' || ch == '\r'))
                break;
        } else {
            if (ch == Ctrl('W'))
                break;
        }
        for (i=starty; i<=y; i++)
            saveline(i, 1, savebuffer[i]);
        if (true == RMSG && (KEY_UP == ch || KEY_DOWN == ch) && (!buf[0])) {
            ingetdata = false;
            return -ch;
        }
        if (true == UPDOWN && (KEY_UP == ch || KEY_DOWN == ch)) {
            ingetdata = false;
            return -ch;
        }
#if 0 //#ifdef NINE_BUILD
        if (RMSG && (ch == Ctrl('Z')) && (!buf[0])) {
            ingetdata = false;
            return -ch;
        }
#endif
#ifdef CHINESE_CHARACTER
        if (ch == Ctrl('R')) {
            init=false;
            SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
            continue;
        }
#endif
        switch (ch) {
            case KEY_ESC:
                init=true;
                strncpy(buf, tmp, Min(len,STRLEN));
                buf[Min(len,1024-1)]=0;
                now=strlen(buf);
                break;
            case Ctrl('W'):
            case Ctrl('Q'):
            case '\n':
            case '\r':
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (UPDOWN) break;
                if (y-starty+1<maxline) {
                    for (i=strlen(buf)+1; i>now; i--)
                        buf[i]=buf[i-1];
                    buf[now++]='\n';
                }
                break;
            case KEY_UP:
                init=false;
                if (cursory>starty) {
                    y = starty; x = startx;
                    chk = 0;
                    if (y==cursory-1&&x<=cursorx)
                        now=0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
#ifdef CHINESE_CHARACTER
                        if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                            if (y==cursory-1&&x<=cursorx)
                                now=i+1;
                    }
                }
                break;
            case KEY_DOWN:
                init=false;
                if (cursory<y) {
                    y = starty; x = startx;
                    chk = 0;
                    if (y==cursory+1&&x<=cursorx)
                        now=0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
#ifdef CHINESE_CHARACTER
                        if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                            if (y==cursory+1&&x<=cursorx)
                                now=i+1;
                    }
                }
                break;
            case '\177':
            case Ctrl('H'):
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (now>0) {
                    for (i=now-1; i<strlen(buf); i++)
                        buf[i]=buf[i+1];
                    now--;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) {
                            for (i=now-1; i<strlen(buf); i++)
                                buf[i]=buf[i+1];
                            now--;
                        }
                    }
#endif
                }
                break;
            case KEY_DEL:
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                if (now<strlen(buf)) {
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now+1; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk)
                            for (i=now; i<strlen(buf); i++)
                                buf[i]=buf[i+1];
                    }
#endif
                    for (i=now; i<strlen(buf); i++)
                        buf[i]=buf[i+1];
                }
                break;
            case KEY_LEFT:
                init=false;
                if (now>0) {
                    now--;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) now--;
                    }
#endif
                }
                break;
            case KEY_RIGHT:
                init=false;
                if (now<strlen(buf)) {
                    now++;
#ifdef CHINESE_CHARACTER
                    if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                        chk = 0;
                        for (i=0; i<now; i++) {
                            if (chk) chk=0;
                            else if (buf[i]<0) chk=1;
                        }
                        if (chk) now++;
                    }
#endif
                }
                break;
            case KEY_HOME:
            case Ctrl('A'):
                init=false;
                now--;
                while (now>=0&&buf[now]!='\n'&&buf[now]!='\r') now--;
                now++;
                break;
            case KEY_END:
            case Ctrl('E'):
                init=false;
                while (now<strlen(buf)&&buf[now]!='\n'&&buf[now]!='\r') now++;
                break;
            case KEY_PGUP:
                init=false;
                now=0;
                break;
            case KEY_PGDN:
                init=false;
                now = strlen(buf);
                break;
            case Ctrl('Y'):
                if (init) {
                    init=false;
                    buf[0]=0;
                    now=0;
                }
                i0 = strlen(buf);
                i=now-1;
                while (i>=0&&buf[i]!='\n'&&buf[i]!='\r') i--;
                i++;
                if (!buf[i]) break;
                j=now;
                while (j<i0-1&&buf[j]!='\n'&&buf[j]!='\r') j++;
                if (j>=i0-1) j=i0-1;
                j=j-i+1;
                if (j<0) j=0;
                for (k=0; k<i0-i-j+1; k++)
                    buf[i+k]=buf[i+j+k];

                y = starty; x = startx;
                chk = 0;
                if (y==cursory&&x<=cursorx)
                    now=0;
                for (i=0; i<strlen(buf); i++) {
                    if (chk) chk=0;
                    else if (buf[i]<0) chk=1;
                    if (chk&&x>=maxcol) x++;
                    if (buf[i]!=13&&buf[i]!=10) {
                        if (x>maxcol) {
                            x = col;
                            y++;
                        }
                        x++;
                    } else {
                        x = col;
                        y++;
                    }
#ifdef CHINESE_CHARACTER
                    if (!DEFINE(getCurrentUser(), DEF_CHCHAR)||!chk)
#endif
                        if (y==cursory&&x<=cursorx)
                            now=i+1;
                }

                if (now>strlen(buf)) now=strlen(buf);
                break;
            default:
                if (isprint2(ch)&&strlen(buf)<len-1) {
                    if (init) {
                        init=false;
                        buf[0]=0;
                        now=0;
                    }
                    for (i=strlen(buf)+1; i>now; i--)
                        buf[i]=buf[i-1];
                    buf[now++]=ch;
                    y = starty; x = startx;
                    chk = 0;
                    for (i=0; i<strlen(buf); i++) {
                        if (chk) chk=0;
                        else if (buf[i]<0) chk=1;
                        if (chk&&x>=maxcol) x++;
                        if (buf[i]!=13&&buf[i]!=10) {
                            if (x>maxcol) {
                                x = col;
                                y++;
                            }
                            x++;
                        } else {
                            x = col;
                            y++;
                        }
                    }
                    if (y-starty+1>maxline) {
                        for (i=now-1; i<strlen(buf); i++)
                            buf[i]=buf[i+1];
                        now--;
                    }
                }
                init=false;
                break;
        }
    }

    ingetdata = false;
    return y-starty+1;
}
Example #2
0
int
pip_play_guess()
{    /* 猜拳程式 */
    int com;
    int pipkey;
    struct tm *qtime;
    time_t now;

    time(&now);
    qtime = localtime(&now);
    d.satisfy += (rand() % 3 + 2);
    count_tired(2, 2, "Y", 100, 1);
    d.shit += rand() % 3 + 2;
    do {
        if (d.death == 1 || d.death == 2 || d.death == 3)
            return 0;
        if (pip_mainmenu(0))
            return 0;
        move(b_lines - 2, 0);
        clrtoeol();
        move(b_lines, 0);
        clrtoeol();
        move(b_lines, 0);
        prints
        ("\033[1;44;37m  猜拳选单  \033[46m[1]我出剪刀 [2]我出石头 [3]我出布啦 [4]猜拳记录 [Q]跳出:         \033[m");
        move(b_lines - 1, 0);
        clrtoeol();
        pipkey = igetkey();
        switch (pipkey) {
#ifdef MAPLE
            case Ctrl('R'):
                if (currutmp->msgs[0].last_pid) {
                    show_last_call_in();
                    my_write(currutmp->msgs[0].last_pid,
                             "水球丢回去:");
                }
                break;
#endif    // END MAPLE
            case '4':
                situ();
                break;
        }
    } while ((pipkey != '1') && (pipkey != '2') && (pipkey != '3')
             && (pipkey != 'q') && (pipkey != 'Q'));

    com = rand() % 3;
    move(18, 0);
    clrtobot();
    switch (com) {
        case 0:
            outs("小鸡:剪刀\n");
            break;
        case 1:
            outs("小鸡:石头\n");
            break;
        case 2:
            outs("小鸡:布\n");
            break;
    }

    move(17, 0);

    switch (pipkey) {
        case '1':
            outs("你  :剪刀\n");
            if (com == 0)
                tie();
            else if (com == 1)
                lose();
            else if (com == 2)
                win();
            break;
        case '2':
            outs("你 :石头\n");
            if (com == 0)
                win();
            else if (com == 1)
                tie();
            else if (com == 2)
                lose();
            break;
        case '3':
            outs("你 :布\n");
            if (com == 0)
                lose();
            else if (com == 1)
                win();
            else if (com == 2)
                tie();
            break;
        case 'q':
            break;
    }
    return 0;
}
Example #3
0
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;
}
Example #4
0
static int bbs_main(char *argv)
{
#define BBS_MAIN_EXIT(time)     do{local_Net_Sleep(time);shutdown(0,2);close(0);return -1;}while(0)
    FILE *fp;
    struct stat st;
    struct rlimit rl;
    char buf[256];
#ifndef DEBUG
    if (strcmp(getSession()->fromhost,"0.0.0.0")&&strcmp(getSession()->fromhost,"127.0.0.1")
            &&((fp=fopen("NOLOGIN","r")))) {
        while (fgets(buf,256,fp))
            local_prints("%s",buf);
        fclose(fp);
        BBS_MAIN_EXIT(20);
    }
#endif /* ! DEBUG */
#ifdef LOAD_LIMIT
    if (!stat("NO_LOAD_LIMIT",&st)&&S_ISREG(st.st_mode)) {
        double load,cpu_load[3];
        get_load(cpu_load);
        load=cpu_load[0];
        local_prints("CPU 最近 (1,10,15) 分钟的平均负荷分别为 %.2f, %.2f, %.2f (目前上限 = %d)\r\n",
                     cpu_load[0],cpu_load[1],cpu_load[2],max_load);
        if ((load<0)||(load>max_load)) {
            local_prints("%s\r\n\r\n%s\r\n%s\r\n",
                         "很抱歉, 目前 CPU 负荷过重, 请稍候再来",
                         "因为重复连接对本站冲击太大, 请您配合, 不要重复多次连接",
                         "请您先休息 10 分钟, 然后再连接本站, 非常感谢!");
            BBS_MAIN_EXIT(((time_t)load));
        }
#ifdef AIX
        {
            int free=psdanger(-1);
            int safe=psdanger(SIGDANGER);
            int danger=125000;
            local_prints("RAM 当前空闲页数高出警戒阈值 %d (警戒阈值 = %d)\r\n\r\n",safe,(free-safe));
            if (safe<danger) {
                if ((server_pid!=-1)&&(!heavy_load))
                    kill(server_pid,SIGUSR1);
                local_prints("%s\r\n\r\n%s\r\n%s\r\n",
                             "很抱歉, 目前 RAM 被过度使用, 请稍候再来",
                             "因为重复连接对本站冲击太大, 请您配合, 不要重复多次连接",
                             "请您先休息 10 分钟, 然后再连接本站, 非常感谢!");
                BBS_MAIN_EXIT(60);
            }
            if ((server_pid!=-1)&&heavy_load)
                kill(server_pid,SIGUSR2);
        }
#endif /* AIX */
    }
#endif /* LOAD_LIMIT */
#ifdef BBSRF_CHROOT
    if (chroot(BBSHOME)==-1) {
        local_prints("Error while chroot to %s, exiting ...\r\n",BBSHOME);
        return -1;
    }
#endif /* BBSRF_CHROOT */

#ifdef SECONDSITE
#define deg(x...)
    if (!strncmp(getSession()->fromhost, "10.", 3)) {
        char ipbuf[16];
        int len=0;
        while ((ipbuf[len] = igetkey()) != '\n') {
            deg("%d:%d\n",getpid(), ipbuf[len]);
            len++;
            if (len >= 15) break;
        }
        ipbuf[len]='\0';
        strcpy(getSession()->fromhost, ipbuf);
        frommain=1;
    }
#endif /* SECONDSITE */

    getSession()->fromhost[IPLEN-1]=0;
    *buf = 0;
    if (check_ban_IP(getSession()->fromhost,buf)>0) {
        local_prints("本站目前不欢迎来自 %s 访问!\r\n原因: %s\r\n\r\n",getSession()->fromhost,buf);
        BBS_MAIN_EXIT(60);
    }
#ifdef HAVE_REVERSE_DNS
    getremotehost(getSession()->fromhost,IPLEN);
#endif /* HAVE_REVERSE_DNS */

    if (stat("core",&st)==-1) {
        rl.rlim_cur=125829120;  /* 120M */
        rl.rlim_max=209715200;  /* 200M */
        setrlimit(RLIMIT_CORE,&rl);
    }
    main_bbs(0,argv);
    return -1;

#undef BBS_MAIN_EXIT
}
Example #5
0
static int fplayer(int race)
{
  int l;
    while(-1)
    {
      gotoxy(48,15); prints("目前位置(%2d,%2d)",m,n);
      put_box(mm,nn,0);
      put_box(m,n,race);
      mm=m; nn=n;
      l=igetkey();
      switch(l)
      {
//      case '1':
        case '2':
         if(role[l-'1']==1)
         {
           role[l-'1']=2; 
           attack[l-'1']=0;
         }
         else if(attack[l-'1']==0)
           attack[l-'1']=1;
         else
           role[l-'1']=1;

         who(l-'1');
         break;
        case 'q': return 2;
        case 'r': return 1;
        case 'b':
         if(sum>2)
         {
           int i;
           for(i=0;i<2;i++)
           {
             int x=repent[sum-1][1],y=repent[sum-1][2];
             put_chess(x,y,0);
             move(y+1,x*2); outs("┼");
             sum-=2;
           }
           for(i=sum;i>=sum-5;i--)
           {
             gotoxy(48,i-sum+13);
             if(i>0)
               prints("第%d步: %s (%2d,%2d)  ",i,(repent[i-1][0]==1)?"●":"○",
                 repent[i-1][1],repent[i-1][2]);
             else
               outs("                  ");
           }
         }
         break;
        case ' ':
         if(!chess[m-1][n-1])
         {
           int hk=put_chess(m,n,race);
           if(hk)
           {
             int dk = show_win(hk);
             if(dk=='n'||dk=='q') return 2;
             return 1;
           }
           return 0;
         }
         break;
        case KEY_DOWN:  //down
          if(legal(m,n+1)) n++; 
          break; 
        case KEY_UP:	//up
          if(legal(m,n-1)) n--; 
          break;
        case KEY_RIGHT:	//right
          if(legal(m+1,n)) m++; 
          break;
        case KEY_LEFT:	//left
          if(legal(m-1,n)) m--; 
          break;
      }
    }
}
Example #6
0
int 
getdata(int line, int col, char *prompt, char *buf, int len, int echo, char *ans)
{
  register int ch;
  int clen;
  int x, y;
  int off_set = 0; /*add color*/
#define MAXLASTCMD 6
  static char lastcmd[MAXLASTCMD][80];

  if (prompt)
  {
    move(line, col);
    clrtoeol();
    outs(prompt);
    off_set=offset_count(prompt); /*add color*/
  }
  else
    clrtoeol();

  if (echo == NOECHO)
  {
    len--;              /* 下面這段程式碼是沒有反白 (!echo) */
    clen = 0;
    while ((ch = igetkey()) != '\r')
    {
      if (ch == '\n')
        break;
      if (ch == KEY_BKSP || ch == Ctrl('H'))
      {
        if (!clen)
          bell();
        else
          clen--;
          
        continue;
      }

#ifdef BIT8
      if (!isprint2(ch))
#else
      if (!isprint(ch))
#endif
      {
        continue;
      }

      if (clen >= len)
        continue;

      buf[clen++] = ch;
    }
    buf[clen] = '\0';
    outc('\n');
    oflush();
  }
  else
  {
   int cmdpos = MAXLASTCMD -1;
   int currchar = 0;
   int keydown;
   int dirty, i;

    getyx(&y, &x);
    x=x-off_set;  /*add color by hialan*/
    standout();
    for (clen = len; clen; clen--)
      outc(' ');
    standend();

    if (ans != NULL) 
    {
       str_ansi(buf, ans, len);
       move(y, x);
       edit_outs(buf);
       clen = currchar = strlen(buf);
    }
    
    /* 因為 buf 有可能會和 ans 相同 , 所以先把初始字串完成後 */
    /* 再根據 clen 將字串後面清空 */
    memset(buf+clen, 0, len-clen);

    len--;
    dirty = 0;
    while (move(y, x + currchar), (ch = igetkey()) != '\r')
    {
       keydown = 0;
       switch (ch) 
       {
       case Ctrl('Y'): 
       {
          if (clen && dirty) 
          {
             for (i = MAXLASTCMD - 1; i; i--)
                strcpy(lastcmd[i], lastcmd[i - 1]);
             strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
          }

          move(y, x);
          for (clen = len; clen; clen--)
            outc(' ');
          memset(buf, '\0', len);
          clen = currchar = 0;
          continue;
       }

       case KEY_DOWN:
       case Ctrl('N'):
          keydown = 1;
       case Ctrl('P'):
       case KEY_UP: 
       {
          if (clen && dirty) 
          {
             for (i = MAXLASTCMD - 1; i; i--)
                strcpy(lastcmd[i], lastcmd[i - 1]);
             strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
          }

          i = cmdpos;
          do 
          {
             if (keydown)
                --cmdpos;
             else
                ++cmdpos;
             if (cmdpos < 0)
                cmdpos = MAXLASTCMD - 1;
             else if (cmdpos == MAXLASTCMD)
                cmdpos = 0;
          } while (cmdpos != i && (!*lastcmd[cmdpos] || !strncmp(buf, lastcmd[cmdpos], len)));
          if (cmdpos == i)
             continue;

          strncpy(buf, lastcmd[cmdpos], len);
          buf[len] = 0;

          move(y, x);                   /* clrtoeof */
          for (i = 0; i <= clen; i++)
             outc(' ');
          move(y, x);

          if (echo == PASS)
            passwd_outs(buf);
          else
            edit_outs(buf);
          clen = currchar = strlen(buf);
          dirty = 0;
          continue;
       }
       case KEY_ESC:
         if(currutmp)
         {
           if (KEY_ESC_arg == 'c')
              capture_screen();
              
           if (KEY_ESC_arg == 'n')
              edit_note();
         }
         continue;

       /* yagami.000504 : 游標可到最前或最後 */ 
       case Ctrl('A'):
       case KEY_HOME:
         currchar = 0;
         break;
       case Ctrl('E'):
       case KEY_END:
         currchar = clen;
         break;

       case KEY_LEFT:
          if (currchar)
             --currchar;
          continue;
       case KEY_RIGHT:
          if (buf[currchar])
             ++currchar;
          continue;
       case Ctrl('K'):
       {
         buf[currchar] = 0;
         move(y, x + currchar);
         for (i = currchar; i < clen; i++)
            outc(' ');
         clen = currchar;
         dirty = 1;
         continue;
       }
 
       case Ctrl('D'): 
       {
         if (buf[currchar]) 
         {
            clen--;
            for (i = currchar; i <= clen; i++)
               buf[i] = buf[i + 1];
            move(y, x + clen);
            outc(' ');
            move(y, x);
            if (echo == PASS)
              passwd_outs(buf);
            else
              edit_outs(buf);
            dirty = 1;
         }
         continue;
       }       
       
       case KEY_BKSP:
       case Ctrl('H'):
       {
         if (currchar) 
         {
            currchar--;
            clen--;
            for (i = currchar; i <= clen; i++)
               buf[i] = buf[i + 1];
            move(y, x + clen);
            outc(' ');
            move(y, x);
            if (echo == PASS)
              passwd_outs(buf);
            else
              edit_outs(buf);
            dirty = 1;
         }
         continue;
       }       
       
       case Ctrl('I'):
         if(currstat != IDLE && !(currutmp->mode == 0 &&
            (currutmp->chatid[0] == 2 || currutmp->chatid[0] == 3))) 
         {
           t_idle();
         }
         continue;

       } /* switch(ch) */

      if (ch == '\n' || ch == '\r')
         break;

      if (!(isprint2(ch)) || clen >= len || x + clen >= scr_cols)
        continue;

      if (buf[currchar]) 
      {     		                /* insert */
         for (i = currchar; buf[i] && i < len && i < 80; i++)
            ;
         buf[i + 1] = 0;
         for (; i > currchar; i--)
            buf[i] = buf[i - 1];
      }
      else                              /* append */
         buf[currchar + 1] = '\0';

      buf[currchar] = ch;
      move(y, x + currchar);
      if (echo == PASS)
        passwd_outs(buf + currchar);
      else
      /* shakalaca.990422: 原本只有下面那行, 這是為了輸入 passwd 有反白 */
        edit_outs(buf + currchar);
      currchar++;
      clen++;
      dirty = 1;
    }
    buf[clen] = '\0';

    if (clen > 1 && echo != PASS) 
    /* shaklaaca.990514: ^^^^^^^ 不讓輸入的 password 留下紀錄 */
    {
       for (cmdpos = MAXLASTCMD - 1; cmdpos; cmdpos--)
          strcpy(lastcmd[cmdpos], lastcmd[cmdpos - 1]);
       strlcpy(lastcmd[0], buf, sizeof(lastcmd[0]) );
    }

    move(y, x + clen);
    outc('\n');
    refresh();
  }

  if(echo == LCECHO)
    buf[0] = tolower(buf[0]);

  return clen;
}
Example #7
0
char 
getans2(int line, int col, char *prompt, char **s, int many, char def)
{
  int point = 0;        /*指標*/
  int i, ch;
  char bar_color[50], buf2[128];
  char *p;      	/*訊息的指標*/

  /*預設值*/
  if(!s) s = msg_choose;
  
  if(many <= 0) 
    return 0;	/* 錯誤: 沒有選項 */
  else if(many == 1) 
    return *(s[0]);	/* 只有一個選項選什麼? */
  
  for(i = 0;i < many;i++)
  {
    p = s[i];
    if(def == *p)
    {
      point = i;
      break;
    }
  }
  
  /* 改用 getdata */                                                                              
  if(!HAVE_HABIT(HABIT_LIGHTBAR))
  {
    char tmp[128],tmp2[2];
                                                                                
    buf2[0] = '\0';
    tmp2[0] = (char) toupper(*(s[point]));
    tmp2[1] = '\0';
                                                                                
    strcpy(tmp,prompt);
                                                                                
    for(i = 0; i < many; i++)
    {
      p = s[i];
      strcat(tmp, p+1);
      strcat(tmp, " ");
    }
                                                                                
    sprintf(tmp,"%s[%c] ", tmp, tmp2[0]);
    getdata(line, col, tmp, buf2, 4, LCECHO, 0);
                                                                                
    if(*buf2 == '\0')
      return *tmp2;
    else
      return *buf2;
  }
                                                                                
  get_lightbar_color(bar_color);
  
  /*清空螢幕*/
  move(line, 0);
  clrtoeol();
                                                                                
  do
  {
    move(line, col);
    clrtoeol();
    if (prompt) outs(prompt);
    
    for(i = 0;i < many;i++)
    {
      p = s[i];
      if(i == point)
        prints("\033[1m[\033[m%s%s\033[0;1m]\033[m",bar_color,p+1);
      else
        prints(" %s ",p+1);
    }

    move(b_lines,0);
                                                                                
    ch = igetkey();
    switch(ch)
    {
      case KEY_TAB:
      case KEY_DOWN:
      case KEY_RIGHT:
        point++;
        if(point >= many)
          point = 0;
        break;
      case KEY_UP:
      case KEY_LEFT:
        point--;
        if(point < 0)
          point = many - 1;
        break;
                                                                                
      default:
        ch = tolower(ch);
        
        for(i = 0;i < many;i++)
        {
          p = s[i];
          if(ch == tolower(*p))
            point = i;
        }
        break;
    }
  }while(ch != '\r');
                                                                                
  return *(s[point]);
}
Example #8
0
int pip_weapon_doing_menu(int variance,int type,const struct weapon *p)
{
    time_t now;
    register int n = 0;
    register char *s;
    char buf[256];
    char ans[5];
    char shortbuf[100];
    const static char menutitle[5][11] = { "头部装备区", "右手装备区", "左手装备区", "身体装备区",
                                           "足部装备区"
                                         };
    int pipkey;
    char choicekey[5];
    int choice;

    do {
        clear();
        showtitle(menutitle[type], BBS_FULL_NAME);
        show_weapon_pic(0);
        /*   move(10,2);
           sprintf(buf,"\033[1;37m现今能力:体力Max:\033[36m%-5d\033[37m  法力Max:\033[36m%-5d\033[37m  攻击:\033[36m%-5d\033[37m  防御:\033[36m%-5d\033[37m  速度:\033[36m%-5d \033[m",
                   d.maxhp,d.maxmp,d.attack,d.resist,d.speed);
           prints(buf);*/
        move(11, 2);
        sprintf(buf,
                "\033[1;37;41m [NO]  [器具名]  [体力]  [法力]  [速度]  [攻击]  [防御]  [速度]  [售  价] \033[m");
        prints(buf);
        move(12, 2);
        sprintf(buf,
                " \033[1;31m——\033[37m白色 可以购买\033[31m——\033[32m绿色 拥有装备\033[31m——\033[33m黄色 钱钱不够\033[31m——\033[35m紫色 能力不足\033[31m——\033[m");
        prints(buf);

        n = 0;
        while ((s = p[n].name)!=0) {
            move(13 + n, 2);
            if (variance != 0 && variance == (n)) { /*本身有的 */
                sprintf(buf,
                        "\033[1;32m (%2d)  %-10s %4d    %4d    %4d    %4d    %4d    %4d    %6d\033[m",
                        n, p[n].name, p[n].needmaxhp,
                        p[n].needmaxmp, p[n].needspeed,
                        p[n].attack, p[n].resist, p[n].speed,
                        p[n].cost);
            } else if (d.maxhp < p[n].needmaxhp || d.maxmp < p[n].needmaxmp || d.speed < p[n].needspeed) { /*能力不足 */
                sprintf(buf,
                        "\033[1;35m (%2d)  %-10s %4d    %4d    %4d    %4d    %4d    %4d    %6d\033[m",
                        n, p[n].name, p[n].needmaxhp,
                        p[n].needmaxmp, p[n].needspeed,
                        p[n].attack, p[n].resist, p[n].speed,
                        p[n].cost);
            }

            else if (d.money < p[n].cost) { /*钱不够的 */
                sprintf(buf,
                        "\033[1;33m (%2d)  %-10s %4d    %4d    %4d    %4d    %4d    %4d    %6d\033[m",
                        n, p[n].name, p[n].needmaxhp,
                        p[n].needmaxmp, p[n].needspeed,
                        p[n].attack, p[n].resist, p[n].speed,
                        p[n].cost);
            } else {
                sprintf(buf,
                        "\033[1;37m (%2d)  %-10s %4d    %4d    %4d    %4d    %4d    %4d    %6d\033[m",
                        n, p[n].name, p[n].needmaxhp,
                        p[n].needmaxmp, p[n].needspeed,
                        p[n].attack, p[n].resist, p[n].speed,
                        p[n].cost);
            }
            prints(buf);
            n++;
        }
        move(b_lines, 0);
        sprintf(buf,
                "\033[1;44;37m  武器购买选单  \033[46m  [B]购买武器  [S]卖掉装备  [W]个人资料  [Q]跳出:            \033[m");
        prints(buf);
        now = time(0);
        pip_time_change(now);
        pipkey = igetkey();
        pip_time_change(now);

        switch (pipkey) {
            case 'B':
            case 'b':
                move(b_lines - 1, 1);
                sprintf(shortbuf, "想要购买啥呢? 你的钱钱[%d]元:[数字]",
                        d.money);
                prints(shortbuf);
#ifdef MAPLE
                getdata(b_lines - 1, 1, shortbuf, choicekey, 4, LCECHO,
                        "0");
#else
                getdata(b_lines-1,1,shortbuf,choicekey,4,DOECHO,NULL,true);
                if ((choicekey[0] >= 'A') && (choicekey[0] <= 'Z'))
                    choicekey[0] = choicekey[0] | 32;
#endif    // END MAPLE
                choice = atoi(choicekey);
                if (choice >= 0 && choice <= n) {
                    move(b_lines - 1, 0);
                    clrtoeol();
                    move(b_lines - 1, 1);
                    if (choice == 0) { /*解除 */
                        sprintf(shortbuf, "放弃购买...");
                        temppress(shortbuf);
                    }

                    else if (variance == choice) { /*早已经有啦 */
                        sprintf(shortbuf, "你早已经有 %s 罗",
                                p[variance].name);
                        temppress(shortbuf);
                    }

                    else if (p[choice].cost >= (d.money + p[variance].sell)) { /*钱不够 */
                        sprintf(shortbuf,
                                "这个要 %d 元,你的钱不够啦!",
                                p[choice].cost);
                        temppress(shortbuf);
                    }

                    else if (d.maxhp < p[choice].needmaxhp || d.maxmp < p[choice].needmaxmp || d.speed < p[choice].needspeed) { /*能力不足 */
                        sprintf(shortbuf,
                                "需要HP %d MP %d SPEED %d 喔",
                                p[choice].needmaxhp,
                                p[choice].needmaxmp,
                                p[choice].needspeed);
                        temppress(shortbuf);
                    } else { /*顺利购买 */

                        sprintf(shortbuf,
                                "你确定要购买 %s 吗?($%d) [y/N]",
                                p[choice].name, p[choice].cost);
#ifdef MAPLE
                        getdata(b_lines - 1, 1, shortbuf, ans,
                                2, 1, 0);
#else
                        getdata(b_lines-1,1,shortbuf,ans,2,DOECHO,NULL,true);
#endif    // END MAPLE
                        if (ans[0] == 'y' || ans[0] == 'Y') {
                            sprintf(shortbuf,
                                    "小鸡已经装配上 %s 了",
                                    p[choice].name);
                            temppress(shortbuf);
                            d.attack +=
                                (p[choice].attack -
                                 p[variance].attack);
                            d.resist +=
                                (p[choice].resist -
                                 p[variance].resist);
                            d.speed +=
                                (p[choice].speed -
                                 p[variance].speed);
                            d.money -=
                                (p[choice].cost -
                                 p[variance].sell);
                            variance = choice;
                        } else {
                            sprintf(shortbuf,
                                    "放弃购买.....");
                            temppress(shortbuf);
                        }
                    }
                }
                break;

            case 'S':
            case 's':
                if (variance != 0) {
                    sprintf(shortbuf,
                            "你确定要卖掉%s吗? 卖价:%d [y/N]",
                            p[variance].name, p[variance].sell);
#ifdef MAPLE
                    getdata(b_lines - 1, 1, shortbuf, ans, 2, 1, 0);
#else
                    getdata(b_lines-1,1,shortbuf,ans,2,DOECHO,NULL,true);
#endif    // END MAPLE
                    if (ans[0] == 'y' || ans[0] == 'Y') {
                        sprintf(shortbuf, "装备 %s 卖了 %d",
                                p[variance].name,
                                p[variance].sell);
                        d.attack -= p[variance].attack;
                        d.resist -= p[variance].resist;
                        d.speed -= p[variance].speed;
                        d.money += p[variance].sell;
                        temppress(shortbuf);
                        variance = 0;
                    } else {
                        sprintf(shortbuf,
                                "ccc..我回心转意了...");
                        temppress(shortbuf);
                    }
                } else if (variance == 0) {
                    sprintf(shortbuf, "你本来就没有装备了...");
                    temppress(shortbuf);
                    variance = 0;
                }
                break;

            case 'W':
            case 'w':
                pip_data_list();
                break;

#ifdef MAPLE
            case Ctrl('R'):
                if (currutmp->msgs[0].last_pid) {
                    show_last_call_in();
                    my_write(currutmp->msgs[0].last_pid,
                             "水球丢回去:");
                }
                break;
#endif    // END MAPLE
        }
    } while ((pipkey != 'Q') && (pipkey != 'q') && (pipkey != KEY_LEFT));

    return variance;
}
Example #9
0
int pip_buy_goods_new(int mode,const struct goodsofpip *p,int *oldnum)
{
    const static char *shopname[4] = { "店名", "便利商店", "星空药铺", "夜里书局" };
    char inbuf[256];
    char genbuf[20];
    long smoney;
    int oldmoney;
    int i, pipkey, choice;

    oldmoney = d.money;
    do {
        clrchyiuan(6, 18);
        move(6, 0);
        sprintf(inbuf,
                "\033[1;31m  —\033[41;37m 编号 \033[0;1;31m—\033[41;37m 商      品 \033[0;1;31m——\033[41;37m 效            能 \033[0;1;31m——\033[41;37m 价     格 \033[0;1;31m—\033[37;41m 拥有数量 \033[0;1;31m—\033[0m  ");
        prints(inbuf);
        for (i = 1; i <= oldnum[0]; i++) {
            move(7 + i, 0);
            sprintf(inbuf,
                    "     \033[1;35m[\033[37m%2d\033[35m]     \033[36m%-10s      \033[37m%-14s        \033[1;33m%-10d   \033[1;32m%-9d    \033[0m",
                    p[i].num, p[i].name, p[i].msgbuy, p[i].money,
                    oldnum[i]);
            prints(inbuf);
        }
        clrchyiuan(19, 24);
        move(b_lines, 0);
        sprintf(inbuf,
                "\033[1;44;37m  %8s选单  \033[46m  [B]买入物品  [S]卖出物品  [Q]跳出:                         \033[m",
                shopname[mode]);
        prints(inbuf);
        pipkey = igetkey();
        switch (pipkey) {
            case 'B':
            case 'b':
                move(b_lines - 1, 1);
                sprintf(inbuf,
                        "想要买入啥呢? [0]放弃买入 [1~%d]物品商号",
                        oldnum[0]);
#ifdef MAPLE
                getdata(b_lines - 1, 1, inbuf, genbuf, 3, LCECHO, "0");
#else
                getdata(b_lines-1,1,inbuf,genbuf,3,DOECHO,NULL,true);
                if ((genbuf[0] >= 'A') && (genbuf[0] <= 'Z'))
                    genbuf[0] = genbuf[0] | 32;
#endif    // END MAPLE

                choice = atoi(genbuf);
                if (choice >= 1 && choice <= oldnum[0]) {
                    clrchyiuan(6, 18);
                    if (rand() % 2 > 0)
                        show_buy_pic(p[choice].pic1);
                    else
                        show_buy_pic(p[choice].pic2);
                    move(b_lines - 1, 0);
                    clrtoeol();
                    move(b_lines - 1, 1);
                    smoney = 0;
                    if (mode == 3)
                        smoney = 1;
                    else {
                        sprintf(inbuf,
                                "你要买入物品 [%s] 多少个呢?(上限 %d)",
                                p[choice].name,
                                d.money / p[choice].money);
#ifdef MAPLE
                        getdata(b_lines - 1, 1, inbuf, genbuf,
                                6, 1, 0);
#else
                        getdata(b_lines-1,1,inbuf,genbuf,6,DOECHO,NULL,true);
#endif    // END MAPLE
                        smoney = atoi(genbuf);
                    }
                    if (smoney < 0) {
                        temppress("放弃买入...");
                    } else if (d.money < smoney * p[choice].money) {
                        temppress("你的钱没有那麽多喔..");
                    } else {
                        sprintf(inbuf,"确定买入物品 [%s] 数量 %ld 个吗?(店家卖价 %ld) [y/N]:",p[choice].name,smoney,smoney*p[choice].money);
#ifdef MAPLE
                        getdata(b_lines - 1, 1, inbuf, genbuf,
                                2, 1, 0);
#else
                        getdata(b_lines-1,1,inbuf,genbuf,2,DOECHO,NULL,true);
#endif    // END MAPLE
                        if (genbuf[0] == 'y'
                                || genbuf[0] == 'Y') {
                            oldnum[choice] += smoney;
                            d.money -=
                                smoney * p[choice].money;
                            sprintf(inbuf,"老板给了你%ld个%s",smoney,p[choice].name);
                            temppress(inbuf);
                            temppress(p[choice].msguse);
                            if (mode == 3 && choice == 1) {
                                d.happy +=
                                    rand() % 10 +
                                    20 * smoney;
                                d.satisfy +=
                                    rand() % 10 +
                                    20 * smoney;
                            }
                            if (mode == 3 && choice == 2) {
                                d.happy +=
                                    (rand() % 2 +
                                     2) * smoney;
                                d.wisdom +=
                                    (2 +
                                     10 / (d.wisdom /
                                           100 +
                                           1)) * smoney;
                                d.character +=
                                    (rand() % 4 +
                                     2) * smoney;
                                d.art +=
                                    (rand() % 2 +
                                     1) * smoney;
                            }
                        } else {
                            temppress("放弃买入...");
                        }
                    }
                } else {
                    sprintf(inbuf, "放弃买入.....");
                    temppress(inbuf);
                }
                break;

            case 'S':
            case 's':
                if (mode == 3) {
                    temppress("这些东西不能卖喔....");
                    break;
                }
                move(b_lines - 1, 1);
                sprintf(inbuf,
                        "想要卖出啥呢? [0]放弃卖出 [1~%d]物品商号",
                        oldnum[0]);
#ifdef MAPLE
                getdata(b_lines - 1, 1, inbuf, genbuf, 3, LCECHO, "0");
#else
                getdata(b_lines-1,1,inbuf,genbuf,3,DOECHO,NULL,true);
                if ((genbuf[0] >= 'A') && (genbuf[0] <= 'Z'))
                    genbuf[0] = genbuf[0] | 32;
#endif    // END MAPLE
                choice = atoi(genbuf);
                if (choice >= 1 && choice <= oldnum[0]) {
                    clrchyiuan(6, 18);
                    if (rand() % 2 > 0)
                        show_buy_pic(p[choice].pic1);
                    else
                        show_buy_pic(p[choice].pic2);
                    move(b_lines - 1, 0);
                    clrtoeol();
                    move(b_lines - 1, 1);
                    smoney = 0;
                    sprintf(inbuf,
                            "你要卖出物品 [%s] 多少个呢?(上限 %d)",
                            p[choice].name, oldnum[choice]);
#ifdef MAPLE
                    getdata(b_lines - 1, 1, inbuf, genbuf, 6, 1, 0);
#else
                    getdata(b_lines-1,1,inbuf,genbuf,6,DOECHO,NULL,true);
#endif    // END MAPLE
                    smoney = atoi(genbuf);
                    if (smoney < 0) {
                        temppress("放弃卖出...");
                    } else if (smoney > oldnum[choice]) {
                        sprintf(inbuf,
                                "你的 [%s] 没有那麽多个喔",
                                p[choice].name);
                        temppress(inbuf);
                    } else {
                        sprintf(inbuf,"确定卖出物品 [%s] 数量 %ld 个吗?(店家买价 %ld) [y/N]:",
                                p[choice].name,smoney,smoney*p[choice].money*8/10);
#ifdef MAPLE
                        getdata(b_lines - 1, 1, inbuf, genbuf,
                                2, 1, 0);
#else
                        getdata(b_lines-1,1,inbuf,genbuf,2,DOECHO,NULL,true);
#endif    // END MAPLE
                        if (genbuf[0] == 'y'
                                || genbuf[0] == 'Y') {
                            oldnum[choice] -= smoney;
                            d.money +=
                                smoney * p[choice].money *
                                8 / 10;
                            sprintf(inbuf,"老板拿走了你的%ld个%s",smoney,p[choice].name);
                            temppress(inbuf);
                        } else {
                            temppress("放弃卖出...");
                        }
                    }
                } else {
                    sprintf(inbuf, "放弃卖出.....");
                    temppress(inbuf);
                }
                break;
            case 'Q':
            case 'q':
                sprintf(inbuf, "金钱交易共 %d 元,离开 %s ",
                        d.money - oldmoney, shopname[mode]);
                temppress(inbuf);
                break;
#ifdef MAPLE
            case Ctrl('R'):
                if (currutmp->msgs[0].last_pid) {
                    show_last_call_in();
                    my_write(currutmp->msgs[0].last_pid,
                             "水球丢回去:");
                }
                break;
#endif    // END MAPLE
        }
    } while ((pipkey != 'Q') && (pipkey != 'q') && (pipkey != KEY_LEFT));
    return 0;
}
Example #10
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);
}
Example #11
0
static int set_keydefine_key(struct _select_def *conf, int key)
{
    int oldmode;

    switch (key) {
        case KEY_TAB:
            ask_define();
            return SHOW_DIRCHANGE;
        case 'a':                  /* add new user */
            if (keymem_total < MAX_KEY_DEFINE) {
                int i,j;
                struct key_struct k;
                char buf[120];

                clear();
                move(1, 0);
                prints("请键入自定义键: ");
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) return SHOW_DIRCHANGE;
                prints("%s\n", buf);
                k.key = i;
                move(2, 0);
                prints("请输入替换序列(最多10个),按一次ESC结束: ");
                j=0;
                do {
                    do {
                        i = igetkey();
                        get_key_name(i, buf);
                    } while (!buf[0]&&i!=KEY_ESC);
                    if (i==KEY_ESC) break;
                    prints("%s ", buf);
                    k.mapped[j] = i;
                    j++;
                    if (j>=10) break;
                } while (1);
                if (j<10) k.mapped[j]=0;
                if (j==0) return SHOW_DIRCHANGE;

                k.status[0] = -1;
                add_key(&k);

                return SHOW_DIRCHANGE;
            }
            break;
        case 'e':
            set_modes(keymem[conf->pos-1].status);
            return SHOW_DIRCHANGE;
        case 's': {
            int i,j,x,y;
            struct key_struct k;
            char buf[120];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1, 0);
            prints("请键入自定义键: ");
            do {
                i = igetkey();
                get_key_name(i, buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC) return SHOW_DIRCHANGE;
            prints("%s\n", buf);
            k.key = i;
            move(2, 0);
            prints("请输入替换序列(最多10个),按一次ESC结束: ");
            j=0;
            do {
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j] = i;
                j++;
                if (j>=10) break;
            } while (1);
            if (j<10) k.mapped[j]=0;
            if (j==0) return SHOW_DIRCHANGE;

            memcpy(keymem+conf->pos-1, &k, sizeof(struct key_struct));

            return SHOW_DIRCHANGE;
        }
        break;
        case 'x': {
            struct key_struct k;
            int i;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请键入自定义键: ");
            do {
                i=igetkey();
                get_key_name(i,buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC)
                return SHOW_DIRCHANGE;
            k.key=i;
            prints("%s",buf);
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 't': {
            struct key_struct k;
            int i,j,x,y;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请输入替换序列(最多10个), 按一次ESC结束: ");
            for (j=0; j<10; j++) {
                do {
                    i=igetkey();
                    get_key_name(i,buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC)
                    break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j]=i;
            }
            if (!j)
                return SHOW_DIRCHANGE;
            if (j<10)
                k.mapped[j]=0;
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 'd':                  /* delete existed user */
            if (keymem_total > 0) {
                char ans[3];

                getdata(t_lines - 1, 0, "确实要删除该定义键吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
                if (ans[0] == 'Y' || ans[0] == 'y') {
                    remove_key(conf->pos-1);
                    if (keymem_total==0) {
                        struct key_struct key;
                        key.key = 'A';
                        key.mapped[0] = 'A';
                        key.mapped[1] = 0;
                        key.status[0] = 0;
                        add_key(&key);
                    }
                }
                return SHOW_DIRCHANGE;
            }
            break;
        case 'L':
        case 'l':
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'W':
        case 'w':
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':
            oldmode = uinfo.mode;
            clear();
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            clear();
            return SHOW_REFRESH;
    }

    return SHOW_CONTINUE;
}
Example #12
0
int
pip_results_show()
{				/*收获季 */
	const static char *showname[5] =
	    { "  ", "武斗大会", "艺术大展", "皇家舞会", "烹饪大赛" };
	char buf[256];
	int pipkey, i = 0;
	int winorlost = 0;
	int a, b[3][2], c[3];

	clear();
	move(10, 14);
	prints("\033[1;33m叮咚叮咚~ 辛苦的邮差帮我们送信来了喔...\033[0m");
	temppress("嗯  把信打开看看吧...");
	clear();
	show_resultshow_pic(0);
	sprintf(buf, "[A]%s [B]%s [C]%s [D]%s [Q]放弃:", showname[1],
		showname[2], showname[3], showname[4]);
	move(b_lines, 0);
	prints(buf);
	do {
		pipkey = igetkey();
	}
	while (pipkey != 'q' && pipkey != 'Q' && pipkey != 'A' && pipkey != 'a'
	       && pipkey != 'B' && pipkey != 'b' && pipkey != 'C'
	       && pipkey != 'c' && pipkey != 'D' && pipkey != 'd');
	a = rand() % 4 + 1;
	b[0][0] = a - 1;
	b[1][0] = a + 1;
	b[2][0] = a;
	switch (pipkey) {
	case 'A':
	case 'a':
		temppress("今年共有四人参赛~现在比赛开始");
		for (i = 0; i < 3; i++) {
			a = 0;
			b[i][1] = 0;
			sprintf(buf, "你的第%d个对手是%s", i + 1,
				resultmanlist[b[i][0]].name);
			temppress(buf);
			a = pip_vs_man(b[i][0], resultmanlist, 2);
			if (a == 1)
				b[i][1] = 1;	/*对方输了 */
			winorlost += a;
			d.death = 0;
		}
		switch (winorlost) {
		case 3:
			pip_results_show_ending(3, 1, b[1][0], b[0][0],
						b[2][0]);
			d.hexp += rand() % 10 + 50;
			break;
		case 2:
			if (b[0][1] != 1) {
				c[0] = b[0][0];
				c[1] = b[1][0];
				c[2] = b[2][0];
			} else if (b[1][1] != 1) {
				c[0] = b[1][0];
				c[1] = b[2][0];
				c[2] = b[0][0];
			} else if (b[2][1] != 1) {
				c[0] = b[2][0];
				c[1] = b[0][0];
				c[2] = b[1][0];
			}
            else
                break;
			pip_results_show_ending(2, 1, c[0], c[1], c[2]);
			d.hexp += rand() % 10 + 30;
			break;
		case 1:
			if (b[0][1] == 1) {
				c[0] = b[2][0];
				c[1] = b[1][0];
				c[2] = b[0][0];
			} else if (b[1][1] == 1) {
				c[0] = b[0][0];
				c[1] = b[2][0];
				c[2] = b[1][0];
			} else if (b[2][1] == 1) {
				c[0] = b[1][0];
				c[1] = b[0][0];
				c[2] = b[2][0];
			}
            else
                break;
			pip_results_show_ending(1, 1, c[0], c[1], c[2]);
			d.hexp += rand() % 10 + 10;
			break;
		case 0:
			pip_results_show_ending(0, 1, b[0][0], b[1][0],
						b[2][0]);
			d.hexp -= rand() % 10 + 10;
			break;
		}
		break;
	case 'B':
	case 'b':
		temppress("今年共有四人参赛~现在比赛开始");
		show_resultshow_pic(21);
		temppress("比赛情形");
		if ((d.art * 2 + d.character) / 400 >= 5) {
			winorlost = 3;
		} else if ((d.art * 2 + d.character) / 400 >= 4) {
			winorlost = 2;
		} else if ((d.art * 2 + d.character) / 400 >= 3) {
			winorlost = 1;
		} else {
			winorlost = 0;
		}
		pip_results_show_ending(winorlost, 2, rand() % 2,
					rand() % 2 + 2, rand() % 2 + 4);
		d.art += rand() % 10 + 20 * winorlost;
		d.character += rand() % 10 + 20 * winorlost;
		break;
	case 'C':
	case 'c':
		temppress("今年共有四人参赛~现在比赛开始");
		if ((d.art * 2 + d.charm) / 400 >= 5) {
			winorlost = 3;
		} else if ((d.art * 2 + d.charm) / 400 >= 4) {
			winorlost = 2;
		} else if ((d.art * 2 + d.charm) / 400 >= 3) {
			winorlost = 1;
		} else {
			winorlost = 0;
		}
		d.art += rand() % 10 + 20 * winorlost;
		d.charm += rand() % 10 + 20 * winorlost;
		pip_results_show_ending(winorlost, 3, rand() % 2,
					rand() % 2 + 4, rand() % 2 + 2);
		break;
	case 'D':
	case 'd':
		temppress("今年共有四人参赛~现在比赛开始");
		if ((d.affect + d.cookskill * 2) / 200 >= 4) {
			winorlost = 3;
		} else if ((d.affect + d.cookskill * 2) / 200 >= 3) {
			winorlost = 2;
		} else if ((d.affect + d.cookskill * 2) / 200 >= 2) {
			winorlost = 1;
		} else {
			winorlost = 0;
		}
		d.cookskill += rand() % 10 + 20 * winorlost;
		d.family += rand() % 10 + 20 * winorlost;
		pip_results_show_ending(winorlost, 4, rand() % 2 + 2,
					rand() % 2, rand() % 2 + 4);
		break;
	case 'Q':
	case 'q':
		temppress("今年不参加啦.....:(");
		d.happy -= rand() % 10 + 10;
		d.satisfy -= rand() % 10 + 10;
		d.relation -= rand() % 10;
		break;
	}
	if (pipkey != 'Q' && pipkey != 'q') {
		d.tired = 0;
		d.hp = d.maxhp;
		d.happy += rand() % 20;
		d.satisfy += rand() % 20;
		d.relation += rand() % 10;
	}
	return 0;
}