Exemplo n.º 1
0
Arquivo: chat.c Projeto: wyat/kbs
/********************snow*/
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif

#ifdef SOLARIS
#include <sys/filio.h>
#endif

#include "chat.h"
extern char page_requestor[];
extern char *modestring();
extern struct UTMPFILE *utmpshm;

#define s_lines         (t_lines-2)
#define b_lines         (t_lines-1)
#define screen_lines    (t_lines-4)
int chat_cmd(chatcontext * pthis, char *buf);
static void set_rec(chatcontext * pthis, const char *arg);

#define CHAT_LOGIN_OK       "OK"
#define CHAT_LOGIN_EXISTS   "EX"
#define CHAT_LOGIN_INVALID  "IN"
#define CHAT_LOGIN_BOGUS    "BG"
static const char *msg_seperator =
    "———————————————————————————————————————";
static const char *msg_shortulist =
    "\033[33m\033[44m 使用者代号    目前状态  │ 使用者代号    目前状态  │ 使用者代号    目前状态 \033[m";
static int ent_chat(int chatnum);       /* 进入聊天室 */
int chat_waitkey(chatcontext * pthis)
{
    char ch;

    outs("           \033[5;31m◆ 按空格键继续,Q键取消 ◆\033[m");
    add_io(0, 0);
    ch = igetkey();
    add_io(pthis->cfd, 0);
    return strchr(" \r\n", ch) != NULL;
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
static void chc_init(int s, board_t board) {

    user_info *my = uin;
    setutmpmode(CHESS);
    clear();
    chc_warnmsg[0] = 0;
    chc_my = currutmp->turn;

    chc_firststep = 1;
    chc_init_board(board);
    chc_redraw(board);
    chc_cursor.r = 9, chc_cursor.c = 0;
    add_io(s, 0);
    chc_load(cuser.userid,1);

    if(my->turn) chc_recvmove(s);
    chc_load(uin->userid,2);

//    if(!currutmp->turn) {
        chc_sendmove(s);
//        chc_hislose++;
//    }

    chc_redraw(board);
}
Exemplo n.º 4
0
void chc(int s) {
    board_t board;
    
    chc_init(s, board);
    mainloop(s, board);
    close(s);
    add_io(0, 0);
    if(chc_my) pressanykey();
}
Exemplo n.º 5
0
int chc(int s,user_info *uin2) {
    board_t board;
    uin = uin2;
    chc_init(s, board);
    mainloop(s, board);
    close(s);
    add_io(0, 0);
    if(chc_my) pressanykey("下次再來繼續對決吧....:p"); 
}
Exemplo n.º 6
0
static char *get_tok (char *buf, int doall, FILE *fp_net) {

/* Figures out which, if any token is at the start of this line and *
 * takes the appropriate action.  It always returns a pointer to    *
 * the next line (I need to do this so I can do some lookahead).    */

 char *ptr; 
 
 ptr = my_strtok(buf,TOKENS,fp_net,buf);

 if (ptr == NULL) {                       /* Empty line.  Skip. */
    ptr = my_fgets(buf, BUFSIZE, fp_net);
    return (ptr);
 }
 
 if (strcmp(ptr,".clb") == 0) {
    ptr = add_clb (doall, fp_net, buf);
    return (ptr);
 }

 if (strcmp(ptr,".input") == 0) {
    add_io (doall, INPAD, fp_net, buf);
    ptr = my_fgets(buf, BUFSIZE, fp_net);
    return (ptr);
 }

 if (strcmp(ptr,".output") == 0) {
    add_io (doall, OUTPAD, fp_net, buf);
    ptr = my_fgets(buf, BUFSIZE, fp_net);
    return (ptr);
 }

 if (strcmp(ptr,".global") == 0) {
    add_global (doall, fp_net, buf);
    ptr = my_fgets(buf, BUFSIZE, fp_net);
    return (ptr);
 }

 printf ("Error in get_tok while parsing netlist file.\n");
 printf ("Line %d starts with an invalid token (%s).\n", linenum, ptr);
 exit (1);
}
Exemplo n.º 7
0
int Epoll_Watcher::add(Event_Handler *evh, int op, Time_Value *tv) {
	if (evh == 0)
		return -1;

/*	if (((op & EVENT_TIMEOUT) && tv == 0) || ((op & EVENT_TIMEOUT) && *tv == Time_Value::zero))
		return -1;*/
	if ((op & EVENT_TIMEOUT) && tv == 0) return -1;

	if ((op & EVENT_INPUT) || (op & EVENT_OUTPUT))
		add_io(evh, op);

	if (op & EVENT_TIMEOUT)
		add_timer(evh, op, tv);

	return 0;
}
Exemplo n.º 8
0
Chat()
{
  CHATID chatid;
  char cbuf[CHATLINE_TEXT_MAX+1];
  int cfd;
  int rc;
  int done_chatting = 0;
  int margin, curspos, maxpos, endpos;
  int ch, i;
  int metakey = 0;
  int shift, shiftdelta;

  move(2, 0);
  clrtobot();

  do {  
    if (getdata(2,0,"Enter chatid: ",chatid,sizeof chatid,DOECHO,1)==-1)
      return FULLUPDATE;

    if (*chatid == '\0') {
      strncpy(chatid, myinfo.userid, CHATID_MAX);
      chatid[CHATID_MAX] = '\0';
    }
    rc = bbs_chat(chatid, (LONG *)&cfd);
    switch (rc) {
    case S_OK: break;
    case S_BADCHATID:
    case S_CHATIDINUSE:
      bbperror(rc, NULL);
      break;
    default:
      bbperror(rc, "Error entering chat");
      return PARTUPDATE;
    }
  } while (rc != S_OK);

  add_io(cfd, 0);
  chat_resetscreen(chatid);

  memset(cbuf, '\0', sizeof cbuf);
  margin = CHATID_MAX+2;
  maxpos = sizeof(cbuf) - margin - 1;
  curspos = 0;
  endpos = 0;
  shift = 0;
  shiftdelta = (t_columns - margin) / 2;
    
  while (!done_chatting) {
    move(g_echatwin+1, margin+(curspos-shift));

    ch = igetch();
    if (NewPagePending()) {
      chat_show_page_request();
    }      
    if (ch == -1) done_chatting = 1;
    else if (ch == I_OTHERDATA) {
      /* Incoming! */
      if (chat_process_incoming(cfd, chatid) == -1)
        done_chatting = 1;
    }
    else if (metakey) {
      switch (ch) {
      case 'b': case 'B':
	if (curspos == 0) bell();
	else {
	  while (curspos && isspace(cbuf[curspos-1])) curspos--;
	  while (curspos && !isspace(cbuf[curspos-1])) curspos--;
	}
	break;
      case 'f': case 'F':
	if (curspos == endpos) bell();
	else {
	  while (curspos < endpos && isspace(cbuf[curspos])) curspos++;
	  while (curspos < endpos && !isspace(cbuf[curspos])) curspos++;
	}
	break;
      default: 
	bell();
      }
      metakey = 0;
    }
    else switch (ch) {
    case '\r': 
    case '\n':
      if (endpos > 0) {
        cbuf[endpos] = '\n';
        done_chatting = chat_process_local(cbuf, chatid);
        if (done_chatting == -1) {
          done_chatting = (bbs_chat_send(cbuf) != S_OK);
        }
      }
      memset(cbuf, '\0', sizeof cbuf);
      endpos = curspos = 0;
      move(g_echatwin+1, margin);
      clrtoeol();
      break;
    case CTRL('A'):
      if (curspos == 0) bell();
      else curspos = 0;
      break;
    case CTRL('B'):
      if (curspos == 0) bell();
      else curspos--;
      break;
    case CTRL('C'):
      bbs_chat_send("/e\n");
      done_chatting = 1;
      break;
    case CTRL('D'):
      if (curspos == endpos) bell();
      else {
        for (i=curspos; i<endpos; i++) cbuf[i] = cbuf[i+1];        
        endpos--;
        move(g_echatwin+1, margin+(curspos-shift));
        prints("%s", cbuf+curspos);
        clrtoeol();
      }
      break;
    case CTRL('E'):
      if (curspos == endpos) bell();
      else curspos = endpos;
      break;
    case CTRL('F'):
      if (curspos == endpos) bell();
      else curspos++;
      break;
    case CTRL('H'):
    case 127:
      if (curspos == 0) bell();
      else {
        for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i];        
        endpos--;
        curspos--;
        move(g_echatwin+1, margin+(curspos-shift));
        prints("%s", cbuf+curspos);
	clrtoeol();
      }
      break;
    case CTRL('U'):
      if (endpos == 0) bell();
      else {
        memset(cbuf, '\0', sizeof cbuf);
        curspos = endpos = 0;
        move(g_echatwin+1, margin);
        clrtoeol();
      }
      break;
    case CTRL('W'):
      if (curspos == 0) bell();
      else {
        while (curspos && isspace(cbuf[curspos-1])) {
          for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i];
	  curspos--, endpos--;
	}
        while (curspos && !isspace(cbuf[curspos-1])) {
          for (i=curspos; i<=endpos; i++) cbuf[i-1] = cbuf[i];
	  curspos--, endpos--;
	}
        move(g_echatwin+1, margin+(curspos-shift));
        prints("%s", cbuf+curspos);
        clrtoeol();
      }
      break;
    case 27:   /* ESC */
      metakey = 1;
      break;
    default:
      if (isprint(ch) && endpos < maxpos) {
        for (i=endpos; i>curspos; i--) cbuf[i] = cbuf[i-1];
        cbuf[curspos] = ch;        
        move(g_echatwin+1, margin+(curspos-shift));
        prints("%s", cbuf+curspos);
        curspos++;
        endpos++;
      }
      else bell();      
    }                              
    if (curspos-shift >= (t_columns-margin)) {
      while (curspos-shift >= (t_columns-margin)) shift += shiftdelta;
      move(g_echatwin+1, margin);
      prints("%s", cbuf+shift);
      clrtoeol();
    }
    else if (curspos < shift) {
      while (curspos < shift) shift -= shiftdelta;
      move(g_echatwin+1, margin);
      prints("%s", cbuf+shift);
      clrtoeol();
    }
  }

  bbs_exit_chat();
  g_you_have_mail = 0;
  add_io(0, 0);
  return FULLUPDATE;
}
Exemplo n.º 9
0
Arquivo: lvmtsd.c Projeto: Auboo/lvmts
struct extent_info_t* read_stdin(uint64_t start_time, struct extent_info_t *extent_info)
{
    char in_buf[8192]= {0};
    char blk_dev_num[4096]= {0};
    int cpu_id=0;
    uint64_t seq_num=0;
    double time_stamp=0;
    int proc_id=0;
    char action_id[8]= {0};
    char rwbs[8]= {0};
    uint64_t offset=0;
    char plus_sgn[8]= {0};
    uint64_t len=0;
    char err_val[16];
    // number of sectors in extent
    init_le_to_pe();
    uint64_t sec_in_ext = get_pe_size(vg_name);

    if (sec_in_ext == 0) {
        fprintf(stderr, "No volume group named %s\n", vg_name);
        exit(1);
    }

    FILE *btrace;

    // offset in extents
    uint64_t extent_num=0;
    int r;

    uint64_t last_print = 0;

    char cmd[8192]= {0};

    sprintf(cmd, "btrace -t -a complete /dev/%s/%s", vg_name, lv_name);

    // XXX UGLY!!
    btrace = popen(cmd, "r");
    if(!btrace) {
        fprintf(stderr, "can't invoke btrace");
        exit(1);
    }

    while (fgets(in_buf, 8191, btrace)) {
        r = sscanf(in_buf,
                   "%4095s %100i %" SCNu64 " %64lf %64i %7s %7s %" SCNu64 " %4s "
                   "%" SCNu64 " %15s",
                   blk_dev_num, &cpu_id, &seq_num, &time_stamp, &proc_id,
                   action_id, rwbs, &offset, plus_sgn, &len, err_val);

        // ignore all non Complete events
        if (strcmp(action_id,"C"))
            continue;

        // print current stats every 5 minutes
        if (last_print+60*5<time_stamp) {
            print_extents(extent_info);
            last_print = time_stamp;
        }

        // round up
        extent_num=(offset+(sec_in_ext-1))/sec_in_ext;

        if (extents<=extent_num) {
            extent_info = realloc(extent_info,
                                  sizeof(struct extent_info_t)*(extent_num+100));
            if (!extent_info) {
                fprintf(stderr, "out of memory\n");
                exit(1);
            }

            memset(&extent_info[extents], 0,
                   (extent_num+100-extents)*sizeof(struct extent_info_t));

            extents=extent_num+100;
        }

        if (rwbs[0] == 'R')
            add_io(&extent_info[(size_t)extent_num],
                   start_time + time_stamp, READ);

        if (rwbs[0] == 'W')
            add_io(&extent_info[(size_t)extent_num],
                   start_time + time_stamp, WRITE);
    }

    pclose(btrace);

    return extent_info;
}
Exemplo n.º 10
0
Arquivo: dark.c Projeto: yrchen/Athena
int
dark(int fd, user_info *uin, int t)
                                      {
 char x=0,y=0,turn=0,xx,yy,mark=0,color=-1;
 char data[100],shown[2]={0,0},result=0,peace=0;
 time_t rest,init=time(0);
 int key,datac;
//       screenline *screen; //for save the scre
 
 data[0]=0;
 start(uin);
 add_io(fd, 0);
 t=t?1:0;
 
 if(!t) { /* 兩邊棋盤資料同步 */
  for(yy=0; yy<8; yy++)
   strncat(data, chess[yy], 4);
  do {
   datac=send(fd, data, strlen(data), 0);
  } while(datac<0);
 }
 else {
  do {
   key=igetkey();
   if (key == I_OTHERDATA) {
     datac= recv(fd, data, sizeof(data), 0);
     if(datac<=0) {add_io(0, 0); return;}
     for(yy=0; yy<8; yy++)
      strncpy(chess[yy], data+yy*4, 4);
   }
  } while(key != I_OTHERDATA);
 }
 move(18,0); clrtoeol();
 
 do {
  printtt(19, 56, "%s",t==turn?"自己":"對方"); 
  refresh();
  rest=time(0);
  
  do {
    if(t==turn) {
      show_cursor(y, x, 1);
      move(18, 0);
    }
    key=time(0)-init;
    datac=ttt+rest-time(0);

    if(datac<1 && turn==t) {
      change_record(1);
      add_io(0,0); bell();
      pressanykey("時間到囉!!..這局輸囉.. :~(");
      return 0;
    }
    else if(datac<1) {
      change_record(0);
      add_io(0,0); bell();
      pressanykey("對方可能睡著啦~ so算你贏了!! ^^Y");
      return 0;
    }
    
    move(22,34); 
    prints("%2d:%2d:%2d",key/3600,(key%3600)/60,key%60);
    printtt(21,47,"4%d;1m  %d:%2d",datac<30?1:4,datac/60,datac%60);
    move(b_lines,0); clrtoeol();
    prints(" 說明  [←↑↓→/jikl]移動 \
[Enter/Space]確定 [w]傳訊 [p]和棋 [q]\
投降 [h]Help ");
    refresh();
    key=igetkey();
    peace=0;

     if(key==I_OTHERDATA) {
       bell();
       datac= recv(fd, data, sizeof(data), 0);
       if(datac<=0) {add_io(0, 0); return;}
       
       if(*data=='P') {
         getdata(18, 0, "對方提出和棋的要求..答應和棋嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18,0); clrtoeol();
         do {
          datac=send(fd, data, 1, 0);
         } while(datac<0);
         if(*data=='y') {
           change_record(2);
           add_io(0, 0);
           pressanykey("雙方握手言和 :)");
           return 0;
         }
         key=0;
       }
       else if(*data=='Q') {
         change_record(0);
         add_io(0, 0);
         pressanykey("耶耶耶..對方投降了.. ^^Y");
         return 0;
       }
       else {
         yy=data[0]-1; xx=data[1]-1;
         y=data[2]-1; x=data[3]-1;

         if(darked(chess[y][x])) { /* 對方翻棋 */
           if(color<0) {
             color=nexturn(red(chess[y][x]));
             show_color(color);
           }
           show_chess(y, x, chess[y][x], 0);
           chess[y][x]--;
           turn=nexturn(turn);
         }
         else {
           if(chess[y][x]) 
             result=show_eaten(chess[y][x],shown[t]++,0);
           move_chess(y,x,yy,xx,&mark,&turn);
         }
       }
     }

   switch(key) {
     case 'h':
      {
       extern screenline* big_picture;
       screenline* screen0 = calloc(t_lines, sizeof(screenline));
       memcpy(screen0, big_picture, t_lines * sizeof(screenline));
       more("game/dark.help",YEA); //* 改成自己的路徑
       memcpy(big_picture, screen0, t_lines * sizeof(screenline));
       free(screen0);
       redoscr();
      }
       break;
     case 'w':
      {
       extern screenline* big_picture;
       screenline* screen0 = calloc(2, sizeof(screenline));
       memcpy(screen0, big_picture, 2 * sizeof(screenline));
       my_write(uin->pid, "傳訊息: ");
       memcpy(big_picture, screen0, 2 * sizeof(screenline));
       free(screen0);
       redoscr();
      }
       break;
     case 'p':
       if(t==turn) {
         int keyy;
         if(peace) break;
         bell();
         getdata(18, 0, "真的要和棋嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18, 0); clrtoeol(); 
         if(*data!='y') break;
         prints("詢問對手是否同意和棋..請稍後... :)"); refresh();
         peace=1;
         do {
          datac=send(fd, "P", 1, 0);
         } while(datac<0);

         do {
           keyy=igetkey();
           if(keyy==I_OTHERDATA) {
             datac= recv(fd, data, sizeof(data), 0);
             if(datac<=0) {add_io(0, 0); return 0;}
             move(18, 0); clrtoeol(); 
             if(*data=='y') {
               change_record(2);
               add_io(0, 0);
               pressanykey("雙方握手言和 :)");
               return 0;
             }
             else 
               pressanykey("對方不同意和棋.. :~");
           }
         } while (keyy!=I_OTHERDATA);
       }
       break;
     case 'q':
       if(t==turn) {
         bell();
         getdata(18, 0, "真的要投降嗎?? (y/n) [n]", data, 4, LCECHO, 0);
         move(18,0); clrtoeol();
         if(*data!='y') break;
         do {
          datac=send(fd, "Q", 1, 0);
         } while(datac<0);
         change_record(1);
         add_io(0, 0);
         pressanykey("啊啊啊..我不行了..投降~ ^^;");
         return 0;
       }
       break;
     default:
      if(t!=turn) key=0;
      break;
   }

   if(t!=turn) continue;
   switch(key) {
    case ' ':
    case 13:
     if(!mark && darked(chess[y][x])) { /* 翻棋 */
       if(color<0) {
        color=red(chess[y][x]);
        show_color(color);
       }
       show_chess(y, x, chess[y][x], 0);
       chess[y][x]--;
       turn=nexturn(turn);
     }
     
     else if(mark) { /* 已 mark 的處理 */
       if(!chess[y][x] && nexto(x-xx,y-yy)) /* 移動 */
        move_chess(y,x,yy,xx,&mark,&turn);
       else if(!mychess(y,x,color) && !darked(chess[y][x])) { /* 吃對方的棋子 */
         if(nexto2(x-xx,y-yy) && mark==6) { /* mark 起來的棋子不在隔壁(炮) */
          char i,tmp=0;
          if(x==xx)
           for(i=min(y,yy)+1; i<max(y,yy); i++)
            tmp+=(chess[i][x]!=0);  
          else
           for(i=min(x,xx)+1; i<max(x,xx); i++)
            tmp+=(chess[y][i]!=0);  
          if(tmp==1 && chess[y][x]) {
            result=show_eaten(chess[y][x],shown[nexturn(t)]++,1);
            move_chess(y,x,yy,xx,&mark,&turn);
          }
          else cancel_mark(yy,xx,&mark,&key);
         }
         else { /* mark 起來的棋子在隔壁 */
           if( nexto(x-xx,y-yy) &&
              ((mark==7 && rank(chess[y][x])==1) || /* 小兵立大功 */
               ( mark<=rank(chess[y][x]) &&
                 rank(chess[y][x])-mark!=6  ))  ) { /* 將軍怕小兵 */
             result=show_eaten(chess[y][x],shown[nexturn(t)]++,1);
             move_chess(y,x,yy,xx,&mark,&turn);
           }
           else cancel_mark(yy,xx,&mark,&key);
         }
       }
       else cancel_mark(yy,xx,&mark,&key); /* 不能移不能吃 */
     }
     
     /* mark 起來 */     
     else if(!mark && chess[y][x] && mychess(y,x,color)) { /* mark 起來 */
       show_chess(y, x, chess[y][x], 1);
       mark=rank(chess[y][x]);
       xx=x; yy=y;
       key=0;
     }
     else key=0;
     break;
     
    case 'u':
     if(mark) cancel_mark(yy, xx, &mark, &key);
     break;
    case KEY_LEFT:
    case 'j':
     show_cursor(y, x, 0);
     y=y==0?7:y-1;
     break;
    case KEY_RIGHT:
    case 'l':
     show_cursor(y, x, 0);
     y=y==7?0:y+1;
     break;
    case KEY_UP:
    case 'i':
     show_cursor(y, x, 0);
     x=x==0?3:x-1;
     break;
    case KEY_DOWN:
    case 'k':
     show_cursor(y, x, 0);
     x=x==3?0:x+1;
     break;
   } 
   
  } while(key!=' ' && key!=13 && key!=I_OTHERDATA);
  
  show_cursor(y, x, 0);
  
  if(t==turn) continue; /* turn已經動過..so是相反的值 */
  data[0]=yy+1; data[1]=xx+1; 
  data[2]=y+1; data[3]=x+1;
  do {
    datac=send(fd, data, 4, 0);
  } while(datac<0);
  
 } while(!result);
 add_io(0, 0);  
 if(!turn) 
 {
   FILE *fs;
   init=time(0)-init;
   if(fs=fopen("log/dark.log","a+")) //* 可改成自己想要的路徑
   {
     fprintf(fs,"%s win %s %d:%d\n",currutmp->userid,uin->userid,init/60,init%60);
     fclose(fs); 
   }
 }
 change_record(1);
 pressanykey("恭禧你%s了 ^^Y",t==turn?"輸":"贏");
}
Exemplo n.º 11
0
bool Loop::add_io(std::shared_ptr<IO>& io)
{
    return add_io(io, true);
}
Exemplo n.º 12
0
Arquivo: chat.c Projeto: wyat/kbs
static int ent_chat(int chatnum)
{                               /* 进入聊天室 */
    chatcontext *pthis;
    char inbuf[128];
    int ch, cmdpos;
    int currchar;
    int modified;               /* the line is modified? -- wwj */
    int newmail;
    int page_pending = false;
    int chatting = true;
#ifdef NEW_HELP
    int oldhelpmode=helpmode;
#endif

    if (!strcmp(getCurrentUser()->userid, "guest"))
        return -1;
    pthis = (chatcontext *) malloc(sizeof(chatcontext));
    bzero(pthis, sizeof(chatcontext));
    if (!pthis)
        return -1;
    modify_user_mode(CHAT1);
    ch = ent_chat_conn(pthis, chatnum);
    if (ch != 1) {
        free(pthis);
        return ch;
    }
#ifdef NEW_HELP
    helpmode=HELP_CHAT;
#endif
    add_io(pthis->cfd, 0);
    modified = newmail = cmdpos = currchar = 0;
    /* update uinfo */
    uinfo.in_chat = true;
    strcpy(uinfo.chatid, pthis->chatid);
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP_STR(chatid, uinfo);
    /* initiate screen */
    clear();
    pthis->chatline = 2;
    move(s_lines, 0);
    outs(msg_seperator);
    move(1, 0);
    outs(msg_seperator);
    print_chatid(pthis);
    memset(inbuf, 0, 80);
    /* chat begin */
    while (chatting) {
        if (chat_checkparse(pthis) == 0)
            break;
        move(b_lines, currchar + 10);
        pthis->outputcount = 0;
        ch = igetkey();
        if (ch==KEY_TALK) {
            int talkpage = servicepage(0, pthis->buf);

            if (talkpage != page_pending) {
                bell();
                oflush();
                printchatline(pthis, pthis->buf);
                page_pending = talkpage;
            }
        }
        if (chat_checkparse(pthis) == 0)
            break;
        if (ch == I_OTHERDATA)
            continue;
        switch (ch) {
            case KEY_UP:
            case KEY_DOWN:
                if (cmdpos == pthis->cmdpos) {
                    strcpy(pthis->lastcmd[cmdpos], inbuf);
                    modified = 0;
                }
                if (ch == KEY_UP) {
                    if (cmdpos != (pthis->cmdpos + 1) % MAXLASTCMD) {
                        int i = (cmdpos + MAXLASTCMD - 1) % MAXLASTCMD;

                        if (pthis->lastcmd[i][0])
                            cmdpos = i;
                    }
                }
                if (ch == KEY_DOWN) {
                    if (cmdpos != pthis->cmdpos)
                        cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                strcpy(inbuf, pthis->lastcmd[cmdpos]);
                if (cmdpos == pthis->cmdpos) {
                    modified = 1;
                }
                move(b_lines, 10);
                clrtoeol();
                ch = inbuf[69];
                inbuf[69] = 0;
                outs(inbuf);
                inbuf[69] = ch;
                currchar = strlen(inbuf);
                continue;
#ifdef CHINESE_CHARACTER
            case Ctrl('R'):
                SET_CHANGEDEFINE(getCurrentUser(), DEF_CHCHAR);
                continue;
#endif
            case KEY_LEFT:
                if (currchar)
                    --currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        currchar--;
                    }
                }
#endif
                continue;
            case KEY_RIGHT:
                if (inbuf[currchar])
                    ++currchar;
#ifdef CHINESE_CHARACTER
                if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                    int i,j=0;
                    for (i=0;i<currchar;i++)
                        if (j) j=0;
                        else if (inbuf[i]<0) j=1;
                    if (j) {
                        if (inbuf[currchar])
                            ++currchar;
                    }
                }
#endif
                continue;
            case KEY_ESC:
            case Ctrl('X'):
                inbuf[0] = 0;
                currchar = 0;
                move(b_lines, currchar + 10);
                clrtoeol();
                modified = 1;
                continue;
            case Ctrl('A'):
                currchar = 0;
                continue;
            case Ctrl('E'):
                currchar = strlen(inbuf);
                continue;
        }
        if (!newmail && chkmail(0)) {   /* check mail */
            newmail = 1;
            printchatline(pthis, "\033[32m*** \033[31m当!你有新信来啦...\033[m");
        }
        if (isprint2(ch)) {
            if (currchar < 126) {       /* 未满一行,print it */
                modified = 1;
                if (inbuf[currchar]) {  /* insert */
                    int i;

                    for (i = currchar; inbuf[i] && i < 127; i++);
                    inbuf[i + 1] = '\0';
                    for (; i > currchar; i--)
                        inbuf[i] = inbuf[i - 1];
                } else {        /* append */
                    inbuf[currchar + 1] = '\0';
                }
                inbuf[currchar] = ch;
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                move(b_lines, currchar + 10);
                outs(&inbuf[currchar++]);
                inbuf[69] = ch;
            }
            continue;
        }
        if (ch == '\n' || ch == '\r') {
            if (currchar) {
                if (modified) {
                    /* add to command history */
                    ch = sizeof(pthis->lastcmd[pthis->cmdpos]) - 1;
                    strncpy(pthis->lastcmd[pthis->cmdpos], inbuf, ch);
                    pthis->lastcmd[pthis->cmdpos][ch] = 0;
                    pthis->cmdpos = (pthis->cmdpos + 1) % MAXLASTCMD;
                    cmdpos = pthis->cmdpos;
                } else {        /* use history, so can +1 */
                    cmdpos = (cmdpos + 1) % MAXLASTCMD;
                }
                if (inbuf[0] == '/' && Isspace(inbuf[1])) {     /* discard / b */
                    printchatline(pthis,
                                  "\x1b[37m*** \x1b[32m请输入正确的指令,使用/h寻求帮助\x1b[37m ***\x1b[m");
                } else {
                    chatting = chat_cmd(pthis, inbuf);  /*local命令处理 */
                    if (chatting == 0)
                        chatting = chat_send(pthis, inbuf);
                    if (inbuf[0] == '/') {
                        ch = 1;
                        while (inbuf[ch] != '\0' && inbuf[ch] != ' ')
                            ch++;
                        if (ch > 1) {
                            if (!strncasecmp(inbuf, "/bye", ch))
                                break;
                            if (!strncasecmp(inbuf, "/exit", ch))
                                break;  /*added by alex, 96.9.5 */
                        }
                    }
                }
                modified = 0;
                inbuf[0] = '\0';
                currchar = 0;
                move(b_lines, 10);
                clrtoeol();
            }
            continue;
        }
        if (ch == Ctrl('H') || ch == '\177') {  /*Backspace */
            if (currchar) {
                currchar--;
                inbuf[127] = '\0';
                memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                       127 - currchar);
                move(b_lines, currchar + 10);
                clrtoeol();
                ch = inbuf[69]; /* save the end of line */
                inbuf[69] = 0;
                outs(&inbuf[currchar]);
                inbuf[69] = ch;
            }
#ifdef CHINESE_CHARACTER
            if (DEFINE(getCurrentUser(), DEF_CHCHAR)) {
                int i,j=0;
                for (i=0;i<currchar;i++)
                    if (j) j=0;
                    else if (inbuf[i]<0) j=1;
                if (j) {
                    currchar--;
                    inbuf[127] = '\0';
                    memcpy(&inbuf[currchar], &inbuf[currchar + 1],
                           127 - currchar);
                    move(b_lines, currchar + 10);
                    clrtoeol();
                    ch = inbuf[69]; /* save the end of line */
                    inbuf[69] = 0;
                    outs(&inbuf[currchar]);
                    inbuf[69] = ch;
                }
            }
#endif
            continue;
        }
        if (ch == Ctrl('Z')) {
            r_lastmsg();        /* Leeward 98.07.30 support msgX */
            inbuf[0] = '\0';
            currchar = 0;
            move(b_lines, 10);
            clrtoeol();
            continue;
        }
        if (ch == Ctrl('C') /*|| ch == Ctrl('D') */) {  /* ^C 退出 */
            chat_send(pthis, "/b");
            if (pthis->rec)
                set_rec(pthis,NULL);
            break;
        }
    }
    /* chat end */
    if (pthis->rec)set_rec(pthis,NULL);
    close(pthis->cfd);
    add_io(0, 0);
    uinfo.in_chat = false;
    uinfo.chatid[0] = '\0';
    UPDATE_UTMP(in_chat, uinfo);
    UPDATE_UTMP(chatid[0], uinfo);
    clear();
    free(pthis);
#ifdef NEW_HELP
    helpmode=oldhelpmode;
#endif
    return 0;
}
Exemplo n.º 13
0
static void dochatcommand(char *cmd)
{
	char *para;

	strtok(cmd, " \n");
	if ((para = strtok(NULL, "\n")) == NULL)
		para = cmd + strlen(cmd);

	if (*cmd == 'h')
	{
		printchatline(_msg_chat_41);
		printchatline("  /leave                  - Â÷¶}¥»ÀW¹D            [/le]");
		if (curuser.userlevel >= PERM_CLOAK)
			printchatline("  /cloak                  - Áô¨­                  [/cl]");
		printchatline(_msg_chat_43);
		return;
	}
	else if (!strcmp(cmd, "who") || !strcmp(cmd, "w"))
	{
		dowho(para, ac);
		return;
	}
	else if (!strcmp(cmd, "ws") || !strcmp(cmd, "whoall"))
	{
		dowhoall(ac);
		return;
	}
	else if (!strcmp(cmd, "list") || !strcmp(cmd, "l"))
	{
		dolist(ac);
		return;
	}
	else if (!strcmp(cmd, "leave") || !strcmp(cmd, "le"))
	{
		net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	}
	else if (!strcmp(cmd, "nopasswd") || !strcmp(cmd, "nps"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", NOPASSWORD);
	}
	else if (!strcmp(cmd, "nick") || !strcmp(cmd, "n"))
	{

		fixchatid(para);

		net_printf(ac, "NICKNAME\t%s\r\n", para);
		net_gets(ac, genbuf, sizeof(genbuf));
		if (!strncmp(genbuf, "-ERR", 4))
			printchatline(genbuf + 5);
		else
		{
			xstrncpy(uinfo.chatid, para, sizeof(uinfo.chatid));
			update_ulist(cutmp, &uinfo);

			/* set prompt */
			strcpy(prompt, uinfo.chatid);
			strcat(prompt, ":           ");
			prompt[SAYWORD_POINT] = '\0';
		}
		return;
	}
	else if (!strcmp(cmd, "me"))
	{
		if (*para)
		{
			sprintf(genbuf, "*** %s ***", para);
			net_printf(ac, "SPEAK\t%s\r\n", genbuf);
			printchatline(genbuf);
		}
		else
			printchatline(_msg_chat_45);
		return;
	}
	else if (!strcmp(cmd, "pager") || !strcmp(cmd, "p"))
	{
#if 1
		add_io(0, 0);
#endif
		toggle_pager();
		printchatline(pagerstring(&uinfo));
#if 1
		add_io(ac, 0);
#endif
		return;
	}
	else if (!strcmp(cmd, "cloak") || !strcmp(cmd, "cl"))
	{
		if (HAS_PERM(PERM_CLOAK))
		{
			net_printf(ac, "CLOAK\r\n");
			net_gets(ac, genbuf, sizeof(genbuf));
			if (!strncmp(genbuf, "-ERR", 4))
				printchatline(genbuf + 5);
			else
			{
				uinfo.invisible = (uinfo.invisible) ? FALSE : TRUE;
				update_ulist(cutmp, &uinfo);
				if (!uinfo.invisible)
					printchatline("*** Cloak has been deactivated");
				else
					printchatline("*** Cloak has been activated");
			}
		}
		else
			printchatline("*** ERROR: unknown special chat command");
		return;
	}
	else if (!strcmp(cmd, "clear") || !strcmp(cmd, "c"))
	{
		clear();
		move(ECHATWIN, 0);
		outs("________________________________________________________________________________");
		chat_line = 0;	/* reset */
		printchatline(_msg_chat_46);
		return;
	}
	else if (!strcmp(cmd, "ignore") || !strcmp(cmd, "i"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (!cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_37, para);
				printchatline(genbuf);
				add_wlist(&iglist, para, malloc_str);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "unignore") || !strcmp(cmd, "ui"))
	{
		if (*para)
		{
			if (strlen(para) >= IDLEN)
				para[IDLEN - 1] = '\0';
			if (cmp_wlist(iglist, para, strcmp))
			{
				sprintf(genbuf, _msg_chat_36, para);
				printchatline(genbuf);
				cmpd_wlist(&iglist, para, strcmp, free);
			}
		}
		return;
	}
	else if (!strcmp(cmd, "j") || !strcmp(cmd, "join"))
	{
		char *para2;

		para = strtok(para, " \n");
		if (!para)
			return;

		para2 = strtok(NULL, " \n");
		if (!para2)
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, NOPASSWORD);
		else
			net_printf(ac, "JOIN\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "m") || !strcmp(cmd, "msg"))
	{
		char *para2;

		para = strtok(para, " \n");
		para2 = strtok(NULL, "");
		if (!para || !para2)
			return;

		net_printf(ac, "MSG\t%s\t%s\r\n", para, para2);
	}
	else if (!strcmp(cmd, "t") || !strcmp(cmd, "topic"))
	{
		net_printf(ac, "TOPIC\t%s\r\n", para);
	}
	else if (!strcmp(cmd, "ps") || !strcmp(cmd, "passwd"))
	{
		net_printf(ac, "PASSWD\t%s\r\n", para);
	}
	else
	{
		printchatline("*** ERROR: unknown special chat command");
		return;
	}

	net_gets(ac, genbuf, sizeof(genbuf));
	if (!strncmp(genbuf, "-ERR", 4))
	{
		genbuf[strlen(genbuf) - 1] = '\0';
		printchatline(genbuf + 5);
	}
}
Exemplo n.º 14
0
int t_chat2()
{
	int currchar;
	char inbuf[120];
	BOOL page_pending = FALSE;
	int ch;
	char seedstr[STRLEN];
	long seed;
	char rcvbuf[512];
	int chatport;
	char *mycrypt();


	if (check_page_perm() < 0)
		return C_FOOT;

	chatport = CHATPORT;
#if 1
	if (chatport == 0)
		chatport = 6177;
#endif

#if 0
#if	defined(NSYSUBBS1)
	getdata(1, 0, _msg_chat_1, genbuf, 2, ECHONOSP);
	if (genbuf[0] == '2')
		chatport = CHATPORT + 1;
#endif
#endif

	/* initialize */
	inbuf[0] = '\0';
	currchar = 0;
	chat_line = 0;

	if (!getdata(1, 0, "Enter Chat id: ", mychatid, CHATIDLEN, ECHONOSP))
		xstrncpy(mychatid, curuser.userid, CHATIDLEN);

	fixchatid(mychatid);

	if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
	{
		move(2, 0);
		outs(_msg_chat_3);
		refresh();
		sprintf(genbuf, "bbschatd %d", chatport);
		outdoor(genbuf);
		sleep(2);
		if ((ac = ConnectServer(CHAT_SERVER, chatport)) < 0)
		{
			perror("connect failed");
			pressreturn();
			return C_FULL;
		}
	}

	/* receive ChatServer Hello Welcome VersionInfo */
	net_gets(ac, genbuf, sizeof(genbuf));
	/* receive Random Number for Checksum */
	net_gets(ac, seedstr, sizeof(seedstr));
	seed = atol(mycrypt(seedstr));
	net_printf(ac, "USRID\t%s\t%ld\r\n", curuser.userid, seed);
	net_gets(ac, genbuf, sizeof(genbuf));
	if (strncmp(genbuf, "+OK", 3))	/* lthuang */
	{
		outs(_msg_chat_4);
		pressreturn();
		return C_FULL;
	}

	uinfo.mode = CHATROOM;
	xstrncpy(uinfo.chatid, mychatid, sizeof(uinfo.chatid));
	update_ulist(cutmp, &uinfo);

	/* set prompt */
	strcpy(prompt, mychatid);
	strcat(prompt, ":           ");
	prompt[SAYWORD_POINT] = '\0';

	draw_chat_screen();

	add_io(ac, 0);

	net_gets(ac, genbuf, sizeof(genbuf));	/* welcome !! */
	genbuf[strlen(genbuf) - 1] = '\0';
	printchatline(genbuf);
#if 0
	net_printf(ac, "JOIN\t%s\t%s\r\n", DEFAULT_CHANNAME, NOPASSWORD);
	net_gets(ac, genbuf, sizeof(genbuf));
#endif
	if (strcmp(mychatid, curuser.userid))
	{
		net_printf(ac, "NICKNAME\t%s\r\n", mychatid);
		net_gets(ac, genbuf, sizeof(genbuf));
	}

	/* Chat Main */
	while (1)
	{
		ch = getkey();
		if (PLINE != CUR_PLINE) {
			draw_chat_screen();
			continue;
		}
		if (talkrequest)
			page_pending = TRUE;
		if (page_pending)
			page_pending = servicepage(0);
		if (msqrequest)
		{
			add_io(0, 0);
			msqrequest = FALSE;
			msq_reply();
			add_io(ac, 0);
			continue;
		}

		if (ch == I_OTHERDATA)
		{
			if (!net_gets(ac, rcvbuf, sizeof(rcvbuf)))
				break;
			rcvbuf[strlen(rcvbuf) - 1] = '\0';	/* lthuang */
			if (rcvbuf[0] == '/')
			{
				char *p, *nick;

				if ((p = strchr(rcvbuf, '\t')) != NULL)
				{
					*p = '\0';
					if (cmp_wlist(iglist, rcvbuf + 1, strcmp))
						continue;

					nick = p + 1;
					if ((p = strchr(nick, '\t')) != NULL)
					{
						*p = '\0';

						if (cmp_wlist(iglist, nick, strcmp))
							continue;

						strcpy(genbuf, nick);
						strcat(genbuf, ":           ");
						genbuf[SAYWORD_POINT] = '\0';
						strcat(genbuf, ++p);
						printchatline(genbuf);
					}
				}
			}
#if 0
			else if (rcvbuf[0] == '*')
			{
				sprintf(genbuf, "%s", rcvbuf);
				printchatline(genbuf);
			}
#endif
			else
				printchatline(rcvbuf);
		}
		else if (isprint2(ch))
		{
			if (SAYWORD_POINT + currchar - 1 >= t_columns - 3)
			{
				bell();
				continue;
			}
			inbuf[currchar++] = ch;
			inbuf[currchar] = '\0';
			move(PLINE, SAYWORD_POINT + currchar - 1);
			outc(ch);
		}
		else if (ch == '\n' || ch == '\r')
		{
			char *p = inbuf;

			currchar = 0;

			while (*p != '\0' && isspace((int)(*p)))
				p++;
			if (*p == '\0')
				continue;
			if (inbuf[0] == '/')
				dochatcommand(inbuf + 1);
			else
			{
				net_printf(ac, "SPEAK\t%s\r\n", inbuf);
				sprintf(genbuf, "%s%s", prompt, inbuf);
				printchatline(genbuf);
			}

			inbuf[0] = '\0';

			/* show prompt */
			move(PLINE, 0);
			clrtoeol();
			outs(prompt);
		}
		else if (ch == CTRL('H') || ch == '\177')
		{
			if (currchar == 0)
			{
				bell();
				continue;
			}
			move(PLINE, SAYWORD_POINT + --currchar);
			outs(" ");
			inbuf[currchar] = '\0';
		}
		else if (ch == CTRL('C') || ch == CTRL('D'))
		{
			net_printf(ac, "QUIT\r\n");	/* lthuang */
			break;
		}
		else if (ch == CTRL('R'))
		{
			msq_reply();
			continue;
		}
		else if (ch == CTRL('Q'))
		{
			add_io(0, 0);
			t_query();
			add_io(ac, 0);
			continue;
		}
		move(PLINE, currchar + SAYWORD_POINT);
	}
	add_io(0, 0);
	close(ac);
	uinfo.chatid[0] = '\0';
	update_ulist(cutmp, &uinfo);
	free_wlist(&iglist, free);

	return C_FULL;
}
Exemplo n.º 15
0
int five_pk(int fd,int first)
{
    int cx, ch, cy,datac,fdone,x /* ,y */;
    char genbuf[100],data[90],xy_po[5],genbuf1[20] /* ,x1[1],y1[1],done[1] */;
    /*    struct user_info *opponent; */
    /*     char fname[50]; */
    int i,j /* ,k */,fway,banf,idone;


    /*
     *      Ôö¼ÓÁÄÌ칦ÄÜ. Added by satan. 99.04.02
     */

#define START    17
#define END      21
#define PROMPT   23
#undef MAX
#define MAX      (END - START)
#define BSIZE    60


    char chatbuf[80], *cbuf;
    int ptr = 0, chating = 0 /*, over = 0 */;

    setutmpmode(FIVE);       /*Óû§×´Ì¬ÉèÖÃ*/
    clear ();
    InitScreen();
    five_chat (NULL, 1);

    cbuf = chatbuf + 19;
    chatbuf[0] = '\0';
    chatbuf[79] = '\0';
    cbuf[0] = '\0';
    sprintf (chatbuf + 1, "%-16s: ", cuser.username);

    add_io(fd, 0);

begin:
    for(i=0; i<=14; i++)
        for(j=0; j<=14; j++)
            playboard[i][j]=0;


    hand=1;
    winner=0;
    quitf=0;
    px=14;
    py=7;
    fway = 1;
    banf = 1;
    idone = 0;


    sprintf(genbuf, "%s (%s)", cuser.userid, cuser.username);

    if(first)
    {
        move(1,33);
        prints("ºÚ¡ñÏÈÊÖ %s  ",genbuf);
        move(2,33);
        prints("°×¡ðºóÊÖ %s  ",save_page_requestor);
    }
    else
    {
        move(1,33);
        prints("°×¡ðºóÊÖ %s  ",genbuf);
        move(2,33);
        prints("ºÚ¡ñÏÈÊÖ %s  ",save_page_requestor);
    }


    move(15,35);
    if(first)
        outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï");
    else
        outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô");
    move(7,14);
    outs("¡ñ");
    player=white;
    playboard[7][7]=black;
    chess[1][0]=14; /*¼Í¼ËùÏÂλַ*/
    chess[1][1]=7;
    move(4,35);
    outs("µÚ 1ÊÖ ¡ñH 8");

    if(!first)
    {   /*³¬¹Ö!*/
        move (7, 14);
        fdone=1;
    }
    else
        fdone=0;    /*¶ÔÊÖÍê³É*/

    while (1)
    {
        ch=igetkey();

        if (ch == I_OTHERDATA)
        {
            datac = recv(fd, data, sizeof(data), 0);
            if (datac <= 0)
            {
                move(17,30);
                outs(" ¶Ô·½Í¶½µÁË...@_@ ");
                break;
            }
            if (data[0] == '\0')
            {
                five_chat (data + 1, 0);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (data[0] == '\1')
            {
                bell ();
                RMSG = YEA;
                saveline (PROMPT, 0);
                sprintf (genbuf, "%s ˵: ÖØÀ´Ò»Å̺ÃÂð? (Y/N)[Y]:", save_page_requestor);
                getdata (PROMPT, 0, genbuf, genbuf1, 2, LCECHO, YEA);
                RMSG = NA;
                if (genbuf1[0] == 'n' || genbuf1[0] == 'N')
                {
                    saveline (PROMPT, 1);
                    send (fd, "\3", 1, 0);
                    continue;
                }
                else
                {
                    saveline (PROMPT, 1);
                    InitScreen ();
                    first = 0;
                    send (fd, "\2", 1, 0);
                    goto begin;
                }
            }
            else if (data[0] == '\2')
            {
                bell ();
                saveline (PROMPT, 0);
                move (PROMPT, 0);
                clrtoeol ();
                prints ("%s ½ÓÊÜÁËÄãµÄÇëÇó :-)", save_page_requestor);
                refresh ();
                sleep (1);
                saveline (PROMPT, 1);
                InitScreen ();
                first = 1;
                goto begin;
            }
            else if (data[0] == '\3')
            {
                bell ();
                saveline (PROMPT, 0);
                move (PROMPT, 0);
                clrtoeol ();
                prints ("%s ¾Ü¾øÁËÄãµÄÇëÇó :-(", save_page_requestor);
                refresh ();
                sleep (1);
                saveline (PROMPT, 1);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (data[0] == '\xff')
            {
                move (PROMPT, 0);
                quit ();
                break;
            }
            i=atoi(data);
            cx=i/1000;   /*½âÒëdata³ÉÆåÅÌ×ÊÁÏ*/
            cy=(i%1000)/10;
            fdone=i%10;
            hand+=1;

            if(hand%2==0)
                move(((hand-1)%20)/2+4,48);
            else
                move(((hand-1)%19)/2+4,35);

            prints("µÚ%2dÊÖ %s%c%2d",hand,
                   (player==black)?"¡ñ":"¡ð",abcd[cx/2],15-cy);


            move(cy,cx);
            x=cx/2;
            playboard[x][cy]=player;
            if(player==black)
            {
                outs("¡ñ");
                player=white;
            }
            else
            {
                outs("¡ð");
                player=black;
            }
            move (cy, cx);
            refresh ();
            bell ();
            move(15,35);
            outs("¡ôÏÖÔÚ¸Ã×Ô¼ºÏ¡ô");
            haha (5);

            tdeadf=tlivef=livethree=threefour=0;
            for(j=0; j<=10; j++)
                calvalue(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4);
            for(i=0; i<=10; i++) /*ºáÏò*/
                calvalue(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy);
            for(i=-4; i<=0; i++) /*бÓÒÏÂ*/
                calvalue(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2,
                         cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4);
            for(i=-4; i<=0; i++) /*б×óÏÂ*/
                calvalue(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3,
                         cy+i+3,cx/2-i-4,cy+i+4);

            for(j=0; j<=9; j++)
                callfour(cx/2,j,cx/2,j+1,cx/2,j+2,cx/2,j+3,cx/2,j+4,cx/2,j+5);
            for(i=0; i<=9; i++) /*ËĺáÏò*/
                callfour(i,cy,i+1,cy,i+2,cy,i+3,cy,i+4,cy,i+5,cy);
            for(i=-5; i<=0; i++)
            {   /*ËÄбÓÒÏÂ*/
                callfour(cx/2+i,cy+i,cx/2+i+1,cy+i+1,cx/2+i+2,cy+i+2,
                         cx/2+i+3,cy+i+3,cx/2+i+4,cy+i+4,cx/2+i+5,cy+i+5);
                /*ËÄб×óÏÂ*/
                callfour(cx/2-i,cy+i,cx/2-i-1,cy+i+1,cx/2-i-2,cy+i+2,cx/2-i-3,
                         cy+i+3,cx/2-i-4,cy+i+4,cx/2-i-5,cy+i+5);
            }

            py = cy;
            px = cx;
            if(tlivef>=2 && winner==0)
                bandhand(4);
            if(livethree>=2 && tlivef ==0)
                bandhand(3);
            if(threefour==black)
                haha(1);
            else if(threefour==white)
                haha(1);
            if (chating)
            {
                sleep (1);
                move (PROMPT, ptr + 6);
            }
            else
                move (py, px);
            if (winner)
            {
                InitScreen ();
                goto begin;
            }
        }
        else
        {
            if (ch == Ctrl('X'))
            {
                quitf = 1;
            }
            else if (ch==Ctrl('C') || ((ch=='Q' || ch=='q') && !chating))
            {
                RMSG = YEA;
                saveline (PROMPT, 0);
                getdata(PROMPT, 0, "ÄúÈ·¶¨ÒªÀ뿪Âð? (Y/N)?[N] ", genbuf1, 2, LCECHO, YEA);
                if (genbuf1[0] == 'Y' || genbuf1[0] == 'y')
                    quitf = 1;
                else
                    quitf = 0;
                saveline (PROMPT, 1);
                RMSG = NA;
            }
            else if (ch==Ctrl('N') || ((ch=='N' || ch=='n') && !chating))
            {
                saveline (PROMPT, 0);
                RMSG = YEA;
                getdata(PROMPT,0,"ÄúÈ·¶¨ÒªÖØпªÊ¼Âð? (Y/N)?[N] ",genbuf1,2,LCECHO, YEA);
                if (genbuf1[0] == 'Y' || genbuf1[0] == 'y')
                {
                    send (fd, "\1", 1, 0);
                    move (PROMPT, 0);
                    bell ();
                    clrtoeol ();
                    move (PROMPT, 0);
                    outs ("ÒѾ­ÒѾ­ÌæÄú·¢³öÇëÇóÁË");
                    refresh ();
                    sleep (1);
                }
                RMSG = NA;
                saveline (PROMPT, 1);
                if (chating)
                    move (PROMPT, ptr + 6);
                else
                    move (py, px);
                continue;
            }
            else if (ch == '\t')
            {
                if (chating)
                {
                    chating = 0;
                    move (py, px);
                }
                else
                {
                    chating = 1;
                    move (PROMPT, 6 + ptr);
                }
                continue;
            }
            else if (ch == '\0')
                continue;
            else if (chating)
            {
                if (ch == '\n' || ch == '\r')
                {
                    if (!cbuf[0])
                        continue;
                    ptr = 0;
                    five_chat (chatbuf + 1, 0);
                    send (fd, chatbuf, strlen (chatbuf + 1) + 2, 0);
                    cbuf[0] = '\0';
                    move (PROMPT, 6);
                    clrtoeol ();
                }
                else if (ch == KEY_LEFT)
                {
                    if (ptr)
                        ptr --;
                }
                else if (ch == KEY_RIGHT)
                {
                    if (cbuf[ptr])
                        ptr ++;
                }
                else if (ch == Ctrl ('H') || ch == '\177')
                {
                    if (ptr)
                    {
                        ptr --;
                        memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr);
                        move (PROMPT, ptr+6);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (ch == KEY_DEL)
                {
                    if (cbuf[ptr])
                    {
                        memcpy (&cbuf[ptr], &cbuf[ptr+1], BSIZE-ptr);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (ch == Ctrl ('A'))
                {
                    ptr = 0;
                }
                else if (ch == Ctrl ('E'))
                {
                    while (cbuf[++ptr])
                        ;
                }
                else if (ch == Ctrl ('K'))
                {
                    ptr = 0;
                    cbuf[ptr] = '\0';
                    move (PROMPT, ptr+6);
                    clrtoeol ();
                }
                else if (ch == Ctrl ('U'))
                {
                    memmove (cbuf, &cbuf[ptr], BSIZE - ptr + 1);
                    ptr = 0;
                    move (PROMPT, ptr+6);
                    clrtoeol ();
                    prints ("%s",cbuf);
                }
                else if (ch == Ctrl ('W'))
                {
                    if (ptr)
                    {
                        int optr;

                        optr = ptr;
                        ptr --;
                        do
                        {
                            if (cbuf[ptr] != ' ')
                                break;
                        }
                        while (-- ptr);
                        do
                        {
                            if (cbuf[ptr] == ' ')
                            {
                                if (cbuf[ptr+1] != ' ')
                                    ptr ++;
                                break;
                            }
                        }
                        while (-- ptr);
                        memcpy (&cbuf[ptr], &cbuf[optr], BSIZE-optr+1);
                        move (PROMPT, ptr+6);
                        clrtoeol ();
                        prints ("%s",&cbuf[ptr]);
                    }
                }
                else if (isprint2 (ch))
                {
                    if (ptr == BSIZE)
                        continue;
                    if (!cbuf[ptr])
                    {
                        cbuf[ptr] = ch;
                        move (PROMPT, 6 + ptr);
                        outc (ch);
                        cbuf[++ptr] = 0;
                    }
                    else
                    {
                        memmove (&cbuf[ptr+1], &cbuf[ptr], BSIZE-ptr+1);
                        cbuf[ptr] = ch;
                        move (PROMPT, 6 + ptr);
                        prints ("%s",&cbuf[ptr]);
                        ptr ++;
                    }
                }
                move (PROMPT, 6 + ptr);
                continue;
            }
        }

        if(fdone==1 && !chating && ch != I_OTHERDATA)/*»»ÎÒ*/
        {

            move(py,px);
            switch (ch)
            {

            case KEY_DOWN:
            case 'j':
            case 'J':
                py=py+1;
                if(py>14)
                    py=0;
                break;

            case KEY_UP:
            case 'k':
            case 'K':
                py=py-1;
                if(py<0)
                    py=14;
                break;

            case KEY_LEFT:
            case 'h':
            case 'H':
                px=px-1;
                if(px<0)
                    px=28;
                break;

            case KEY_RIGHT:
            case 'l':
            case 'L':
                px=px+1;
                if(px>28)
                {
                    px=0;
                    px=px-1;
                }                      /*»áÌø¸ñßÖ*/
                break;
            case ' ':
                if(banf==1)
                    break;

                if((px%2)==1)
                    px=px-1; /*½â¾önetterm²»ºÏÎÊÌâ*/
                move(py,px);
                hand+=1;
                playboard[x][py]=player;
                if(player==black)
                {
                    outs("¡ñ");
                    player=white;
                }
                else
                {
                    outs("¡ð");
                    player=black;
                }
                chess[hand][0]=px;
                chess[hand][1]=py;
                if(hand%2==0)
                    move(((hand-1)%20)/2+4,48);
                else
                    move(((hand-1)%19)/2+4,35);

                prints("µÚ%2dÊÖ %s%c%2d",hand,
                       (hand%2==1)?"¡ñ":"¡ð",abcd[px/2],15-py);
                idone=1;
                move (py, px);
                refresh ();
                break;
            default:
                break;
            }
            move(py,px);
            x=px/2;
            if(playboard[x][py]!=0)
                banf=1;
            else
                banf=0;

            if(idone==1)
            {
                xy_po[0] = px/10 + '0';
                xy_po[1] = px%10 + '0';
                xy_po[2] = py/10 + '0';
                xy_po[3] = py%10 + '0';
                fdone=0;
                xy_po[4]='1';
                if(send(fd,xy_po,sizeof(xy_po),0)==-1)
                    break;

                move(15,35);
                outs("¡ïµÈ´ý¶Ô·½ÏÂ×Ó¡ï");
                haha (5);

                tdeadf=tlivef=livethree=threefour=0;
                for(j=0; j<=10; j++)
                    calvalue(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4);
                for(i=0; i<=10; i++) /*ºáÏò*/
                    calvalue(i,py,i+1,py,i+2,py,i+3,py,i+4,py);
                for(i=-4; i<=0; i++) /*бÓÒÏÂ*/
                    calvalue(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2,
                             px/2+i+3,py+i+3,px/2+i+4,py+i+4);
                for(i=-4; i<=0; i++) /*б×óÏÂ*/
                    calvalue(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3,
                             py+i+3,px/2-i-4,py+i+4);

                for(j=0; j<=9; j++)
                    callfour(px/2,j,px/2,j+1,px/2,j+2,px/2,j+3,px/2,j+4,px/2,j+5);
                for(i=0; i<=9; i++) /*ËĺáÏò*/
                    callfour(i,py,i+1,py,i+2,py,i+3,py,i+4,py,i+5,py);
                for(i=-5; i<=0; i++)
                {   /*ËÄбÓÒÏÂ*/
                    callfour(px/2+i,py+i,px/2+i+1,py+i+1,px/2+i+2,py+i+2,
                             px/2+i+3,py+i+3,px/2+i+4,py+i+4,px/2+i+5,py+i+5);
                    /*ËÄб×óÏÂ*/
                    callfour(px/2-i,py+i,px/2-i-1,py+i+1,px/2-i-2,py+i+2,px/2-i-3,
                             py+i+3,px/2-i-4,py+i+4,px/2-i-5,py+i+5);
                }

                if(tlivef>=2 && winner==0)
                    bandhand(4);
                if(livethree>=2 && tlivef ==0)
                    bandhand(3);
                if(threefour==black)
                    haha(1);
                else if(threefour==white)
                    haha(1);

            }
            idone=0;
        }
        if (quitf)
        {
            genbuf1[0] = '\xff';
            send (fd, genbuf1, 1, 0);
            press ();
            break;
        }
        if (winner)
        {
            InitScreen ();
            goto begin;
        }
    }

    add_io(0, 0);
    close(fd);
    return;
}