コード例 #1
0
ファイル: server.c プロジェクト: mely91/FloppyDisk
int 
docmd(char cmd)
{
  int rc = 1;

  switch (cmd) {
  case 'd':
    proto_debug_on();
    break;
  case 'D':
    proto_debug_off();
    break;
  case 'u':
    rc = doUpdateClients();
    break;
  case 'q':
    rc=-1;
    break;
  case '\n':
  case ' ':
    rc=1;
    break;
  default:
    printf("Unkown Command\n");
  }
  return rc;
}
コード例 #2
0
ファイル: client.c プロジェクト: mely91/FloppyDisk
int 
docmd(Client *C, char cmd)
{
  int rc = 1;

  switch (cmd) {
  case 'd':
    proto_debug_on();
    break;
  case 'D':
    proto_debug_off();
    break;
  case 'r':
    rc = doRPC(C);
    break;
  case 'q':
    rc=-1;
    break;
  case '\n':
    rc=1;
    break;
  default:
    printf("Unkown Command\n");
  }
  return rc;
}
コード例 #3
0
ファイル: client.c プロジェクト: bxscikai/hackers
int 
docmd(Client *C, char *cmd)
{
  int rc = 1;
  Proto_Client *client = (Proto_Client *) C->ph;

  // If this is a connect attempt
  char input[50];
  strcpy(input, cmd);
  int connectAttempt = check_if_connect(input);

  if (connectAttempt==1) {
  // Ok startup our connection to the server
      if (startConnection(C, globals.host, globals.port, update_event_handler)<0) {
        fprintf(stderr, "ERROR: startConnection failed\n");
        return -1;
      }
      else  {
        fprintf(stderr, "Successfully connected to <%s:%d>\n", globals.host, globals.port);      
        proto_client_hello(C->ph);
        doRPCCmd(C, 'q'); //query for the map

        return 1;
      }
      return 1;
  }
  strcpy(input,cmd);
  if (strcmp(cmd, "disconnect\n")==0) {
    doRPCCmd(C, 'g');
    rc=-1;
  }
  else if (strcmp(cmd, "where\n")==0) 
    where();
  else if (strcmp(cmd, "numhome 1\n")==0) {
    doRPCCmd(C, 'q');  // query map
    if (client->game.map.numHome1!=0)
      fprintf(stderr, "%d\n", client->game.map.numHome1);
  }
  else if (strcmp(cmd, "numhome 2\n")==0) {
    doRPCCmd(C, 'q');  // query map
    if (client->game.map.numHome2!=0)
      fprintf(stderr, "%d\n", client->game.map.numHome2);    
  }
  else if (strcmp(cmd, "numjail 1\n")==0) {
    doRPCCmd(C, 'q');  // query map
    if (client->game.map.numJail1!=0)
      fprintf(stderr, "%d\n", client->game.map.numJail1);    
  }
  else if (strcmp(cmd, "numjail 2\n")==0) {
    doRPCCmd(C, 'q');  // query map
    if (client->game.map.numHome2!=0)
      fprintf(stderr, "%d\n", client->game.map.numJail2);    
  }
  else if (strcmp(cmd, "numwall\n")==0) {
    doRPCCmd(C, 'q');  // query map
    if (client->game.map.numFixedWall!=0 && client->game.map.numNonfixedWall!=0)
      fprintf(stderr, "%d\n", client->game.map.numFixedWall + client->game.map.numNonfixedWall);    
  }
  else if (strcmp(cmd, "numfloor\n")==0) {
    doRPCCmd(C, 'q');  // query map       
    if (client->game.map.numFloor1!=0 && client->game.map.numFloor2!=0)
      fprintf(stderr, "%d\n", client->game.map.numFloor1+client->game.map.numFloor2);    
  }       
  else if (strcmp(cmd, "dim\n")==0) {
    doRPCCmd(C, 'q');  // query map  
    if (client->game.map.dimension.x!=0 && client->game.map.dimension.y!=0)
      fprintf(stderr, "%dx%d\n", client->game.map.dimension.x, client->game.map.dimension.y);    
  }                  
  else if (strcmp(cmd, "dump\n")==0) {
    doRPCCmd(C, 'q');  // query map   
    printMap(&client->game.map);
    if (DISPLAYUI==1)
      ui_update(ui);
  }                 
  else if (containsString(input, "cinfo")>0) {
    doRPCCmd(C, 'q');  // query map     
    cinfo(cmd, C);
  }
  else if (strcmp(cmd, "start\n")==0) {
      doRPCCmd(C, 's');  // query map 
  }
  else if (strcmp(cmd, "test\n")==0)  {
      if (STRESS_TEST == 1)
      {
          pid_t myChild;
          myChild = fork();
	  if (myChild == 0)
          {
	      Wander(C, 0);
          }
          else{} 
      }
  }
  // MOVEMENT
  else if (strcmp(cmd, "w\n")==0) {
      Proto_Client *client = C->ph;
      client->rpc_session.shdr.returnCode = UP;
      doRPCCmd(C, 'm');  // query map   
  }
  else if (strcmp(cmd, "a\n")==0) {
      Proto_Client *client = C->ph;
      client->rpc_session.shdr.returnCode = LEFT;
      doRPCCmd(C, 'm');  // query map   
  }
  else if (strcmp(cmd, "d\n")==0) {
      Proto_Client *client = C->ph;
      client->rpc_session.shdr.returnCode = RIGHT;
      doRPCCmd(C, 'm');  // query map   
  }
  else if (strcmp(cmd, "s\n")==0) {
      Proto_Client *client = C->ph;
      client->rpc_session.shdr.returnCode = DOWN;
      doRPCCmd(C, 'm');  // query map   
  }
  // END OF MOVEMENT  
  
  //PICKUP
  else if (strcmp(cmd, "f\n")==0){
      Proto_Client *client = C->ph;
      doRPCCmd(C, 'f');
  }
  
  //END PICKUP
  else if (strcmp(cmd, "O\n")==0)     
    proto_debug_on();  
  else if (strcmp(cmd, "o\n")==0) 
    proto_debug_off();
  else if (strcmp(cmd, "rh\n")==0)
    rc = proto_client_hello(C->ph);
  else if (strcmp(cmd, "q\n")==0) {
    fprintf(stderr, "Game Over: You Quit\n");    
    doRPCCmd(C, 'g');
    rc=-1;
  }  
  else if (strcmp(cmd, "quit\n")==0) {
    doRPCCmd(C, 'g');
    fprintf(stderr, "Game Over: You Quit\n");
    rc=-1;
  }    
  else if (strcmp(cmd, "\n")==0) {
    rc = proto_client_update(C->ph);
    rc=1;
  }
  else {
    fprintf(stderr, "Unknown command\n");
  }
    
  return rc;
}