Esempio n. 1
0
/* deal with a new player command in dungeon or city mode*/
void p_process(void)
{
  static int searchval=0;

  if (Player.status[BERSERK]) 
    if (goberserk()) {
    setgamestatus(SKIP_PLAYER);
    drawvision(Player.x,Player.y);
  }
  if (! gamestatusp(SKIP_PLAYER)) {
    if (searchval > 0) {
      searchval--;
      if (searchval == 0) resetgamestatus(FAST_MOVE);
    }
    drawvision(Player.x,Player.y);
    if (! gamestatusp(FAST_MOVE)) {
      searchval = 0;
      Cmd = mgetc();
      clear_if_necessary();
    }
    Command_Duration = 0;
    switch (Cmd) {
    case ' ': 
    case 13: setgamestatus(SKIP_MONSTERS); break; /*no op on space or return*/
    case 6: abortshadowform(); break; /* ^f */
    case 7: wizard(); break; /* ^g */
    case 4: player_dump(); break; /* ^d */
    case 9: display_pack(); morewait(); xredraw(); break; /* ^i */
    case 11: if (gamestatusp(CHEATED)) frobgamestatus();
    case 12: xredraw(); setgamestatus(SKIP_MONSTERS); break; /* ^l */
#ifndef MSDOS_SUPPORTED_ANTIQUE
    case 16: bufferprint(); setgamestatus(SKIP_MONSTERS); break; /* ^p */ 
#else
    case 15: bufferprint(); setgamestatus(SKIP_MONSTERS); break; /* ^o */ 
#endif
    case 18: redraw();  setgamestatus(SKIP_MONSTERS); break; /* ^r */
    case 23: if (gamestatusp(CHEATED)) drawscreen();  break; /* ^w */
    case 24: /* ^x */ 
      if (gamestatusp(CHEATED) || 
	  Player.rank[ADEPT]) 
	wish(1);
      Command_Duration = 5;
      break;
    case 'a': zapwand();
      Command_Duration = Player.speed*8/5; 
      break;
    case 'c': closedoor();  
      Command_Duration = Player.speed*2/5; 
      break;
    case 'd': drop();
      Command_Duration = Player.speed*5/5; 
      break;
    case 'e': eat();
      Command_Duration = 30;
      break;
    case 'f': fire();
      Command_Duration = Player.speed*5/5; 
      break;
    case 'g': pickup();
      Command_Duration = Player.speed*10/5; 
      break;
    case 'i': 
      do_inventory_control();
      break;
    case 'm': magic();
      Command_Duration = 12;
      break;
    case 'o': opendoor();
      Command_Duration = Player.speed*5/5; 
      break;
    case 'p': pickpocket();
      Command_Duration = Player.speed*20/5; 
      break;
    case 'q': quaff();
      Command_Duration = 10;
      break;
    case 'r': peruse();
      Command_Duration = 20;
      break;
    case 's': search(&searchval);
      Command_Duration = 20;
      break;
    case 't': talk();
      Command_Duration = 10;
      break;
    case 'v': vault();
      Command_Duration = Player.speed*10/5; 
      break;
    case 'x': examine();
      Command_Duration = 1;
      break;
    case 'z': bash_location();
      Command_Duration = Player.speed*10/5; 
      break;
    case 'A': activate();
      Command_Duration = 10;
      break;
    case 'C': callitem();
      break;
    case 'D': disarm();
      Command_Duration = 30;
      break;
    case 'E': dismount_steed();
      Command_Duration = Player.speed*10/5; 
      break;
    case 'F': tacoptions();
      break;
    case 'G': give();
      Command_Duration = 10;
      break;
    case 'I':
      if (! optionp(TOPINV)) top_inventory_control();
      else {
	display_possessions();
	inventory_control();
      }
      break;
    case 'M': city_move();
      Command_Duration = 10;
      break;
    case 'O': setoptions();
#if defined(AMIGA) || defined(MSDOS_SUPPORTED_ANTIQUE)
      show_screen();
      xredraw();
#endif
      break;
    case 'P': show_license();
      break; /* actually show_license is in file.c */
    case 'Q': quit(); 
      break;
    case 'R': rename_player();
      break;
    case 'S': save(optionp(COMPRESS_OPTION), FALSE);
      break;
    case 'T': tunnel(); 
      Command_Duration =  Player.speed*30/5; 
      break;
    case 'V': version(); 
      break;
#ifdef MSDOS_SUPPORTED_ANTIQUE
    case 'X': check_memory(); break;
#endif
    case 'Z': bash_item();
      Command_Duration = Player.speed*10/5; 
      break;
    case '.': rest();
      Command_Duration = 10;
      break;
    case ',': 
      Command_Duration = 10;
      nap();
      break;
    case '>': 
      downstairs();
      break;
    case '<':
      upstairs();
      break;
    case '@': 
      p_movefunction(Level->site[Player.x][Player.y].p_locf);
      Command_Duration = 5; 
      break;
    case '#': if (gamestatusp(CHEATED)) editstats(); break; /* RAC - char editor */
    case '/': charid(); setgamestatus(SKIP_MONSTERS);
      break;
    case '?': help(); setgamestatus(SKIP_MONSTERS);
      break;
    case '4':	       
    case 'h': moveplayer(-1,0);
      Command_Duration = Player.speed*5/5; 
      break;
    case '2':
    case 'j': moveplayer(0,1);  
      Command_Duration = Player.speed*5/5; 
      break;
    case '8':
    case 'k': moveplayer(0,-1);
      Command_Duration = Player.speed*5/5; 
      break;
    case '6':
    case 'l': moveplayer(1,0);
      Command_Duration = Player.speed*5/5; 
      break;
    case '1':
    case 'b': moveplayer(-1,1);
      Command_Duration = Player.speed*5/5; 
      break;
    case '3':	      
    case 'n': moveplayer(1,1); 
      Command_Duration = Player.speed*5/5; 
      break;
    case '7':
    case 'y': moveplayer(-1,-1);  
      Command_Duration = Player.speed*5/5; 
      break;
    case '9':
    case 'u': moveplayer(1,-1);  
      Command_Duration = Player.speed*5/5; 
      break;
    case '5': 
      setgamestatus(SKIP_MONSTERS); /* don't do anything; a dummy turn */
      Cmd = mgetc();
      while ((Cmd != ESCAPE) &&
	     ((Cmd < '1') || (Cmd > '9') || (Cmd=='5'))) {
	print3("Run in keypad direction [ESCAPE to abort]: ");
	Cmd = mgetc();
      }
      if (Cmd != ESCAPE) setgamestatus(FAST_MOVE);
      break;
    case 'H': setgamestatus(FAST_MOVE); Cmd = 'h'; moveplayer(-1,0);
      Command_Duration = Player.speed*4/5; 
      break; 
    case 'J': setgamestatus(FAST_MOVE); Cmd = 'j'; moveplayer(0,1);
      Command_Duration = Player.speed*4/5; 
      break;  
    case 'K': setgamestatus(FAST_MOVE); Cmd = 'k'; moveplayer(0,-1);
      Command_Duration = Player.speed*4/5; 
      break; 
    case 'L': setgamestatus(FAST_MOVE); Cmd = 'l'; moveplayer(1,0);
      Command_Duration = Player.speed*4/5; 
      break;  
    case 'B': setgamestatus(FAST_MOVE); Cmd = 'b'; moveplayer(-1,1);
      Command_Duration = Player.speed*4/5; 
      break; 
    case 'N': setgamestatus(FAST_MOVE); Cmd = 'n'; moveplayer(1,1);
      Command_Duration = Player.speed*4/5; 
      break;  
    case 'Y': setgamestatus(FAST_MOVE); Cmd = 'y'; moveplayer(-1,-1);  
      Command_Duration = Player.speed*4/5; 
      break;
    case 'U': setgamestatus(FAST_MOVE); Cmd = 'u'; moveplayer(1,-1);
      Command_Duration = Player.speed*4/5; 
      break;
    default: commanderror();  setgamestatus(SKIP_MONSTERS); break;
    }
  }
  if (Current_Environment != E_COUNTRYSIDE) roomcheck();
  screencheck(Player.x,Player.y);
}
Esempio n. 2
0
void client(struct vtun_host *host)
{
     struct sockaddr_in my_addr,svr_addr;
     struct sigaction sa;
     int s, opt, reconnect;	

     vtun_syslog(LOG_INFO,"VTun client ver %s started",VTUN_VER);

     memset(&sa,0,sizeof(sa));     
     sa.sa_handler=SIG_IGN;
     sa.sa_flags = SA_NOCLDWAIT;
     sigaction(SIGHUP,&sa,NULL);
     sigaction(SIGQUIT,&sa,NULL);
     sigaction(SIGPIPE,&sa,NULL);
     sigaction(SIGCHLD,&sa,NULL);

     sa.sa_handler=sig_term;
     sigaction(SIGTERM,&sa,NULL);
     sigaction(SIGINT,&sa,NULL);
 
     client_term = 0; reconnect = 0;
     while( (!client_term) || (client_term == VTUN_SIG_HUP) ){
	if( reconnect && (client_term != VTUN_SIG_HUP) ){
	   if( vtun.persist || host->persist ){
	      /* Persist mode. Sleep and reconnect. */
	      sleep(5);
           } else {
	      /* Exit */
	      break;
	   }
	} else {
	   reconnect = 1;
        }

	set_title("%s init initializing", host->host);

	/* Set server address */
        if( server_addr(&svr_addr, host) < 0 )
	   continue;

	/* Set local address */
	if( local_addr(&my_addr, host, 0) < 0 )
	   continue;

	/* We have to create socket again every time
	 * we want to connect, since STREAM sockets 
	 * can be successfully connected only once.
	 */
        if( (s = socket(AF_INET,SOCK_STREAM,0))==-1 ){
	   vtun_syslog(LOG_ERR,"Can't create socket. %s(%d)", 
		strerror(errno), errno);
	   continue;
        }

	/* Required when client is forced to bind to specific port */
        opt=1;
        setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); 

        if( bind(s,(struct sockaddr *)&my_addr,sizeof(my_addr)) ){
	   vtun_syslog(LOG_ERR,"Can't bind socket. %s(%d)",
		strerror(errno), errno);
	   continue;
        }

        /* 
         * Clear speed and flags which will be supplied by server. 
         */
        host->spd_in = host->spd_out = 0;
        host->flags &= VTUN_CLNT_MASK;

	io_init();

	set_title("%s connecting to %s", host->host, vtun.svr_name);
	if (!vtun.quiet)
	   vtun_syslog(LOG_INFO,"Connecting to %s", vtun.svr_name);

        if( connect_t(s,(struct sockaddr *) &svr_addr, host->timeout) ){
	   if (!vtun.quiet || errno != ETIMEDOUT)
	      vtun_syslog(LOG_INFO,"Connect to %s failed. %s(%d)", vtun.svr_name,
					strerror(errno), errno);
        } else {
	   if( auth_client(s, host) ){   
	      vtun_syslog(LOG_INFO,"Session %s[%s] opened",host->host,vtun.svr_name);

 	      host->rmt_fd = s;

	      /* Start the tunnel */
	      client_term = tunnel(host);

	      vtun_syslog(LOG_INFO,"Session %s[%s] closed",host->host,vtun.svr_name);
	   } else {
	      vtun_syslog(LOG_INFO,"Connection denied by %s",vtun.svr_name);
	   }
	}
	close(s);
	free_sopt(&host->sopt);
     }

     vtun_syslog(LOG_INFO, "Exit");
     return;
}