示例#1
0
int 
doRPCCmd(Client *C, char c) 
{
  int rc=-1;

  switch (c) {
  case 'h':  
    {
      rc = proto_client_hello(C->ph);
      printf("hello: rc=%x\n", rc);
      if (rc > 0) game_process_reply(C);
    }
    break;
  case 'm':
    scanf("%c", &c);
    rc = proto_client_move(C->ph, c);
    break;
  case 'g':
    rc = proto_client_goodbye(C->ph);
    break;
  default:
    printf("%s: unknown command %c\n", __func__, c);
  }
  // NULL MT OVERRIDE ;-)
  printf("%s: rc=0x%x\n", __func__, rc);
  if (rc == 0xdeadbeef) rc=1;
  return rc;
}
示例#2
0
文件: client.c 项目: bxscikai/hackers
int 
doRPCCmd(Client *C, char c) 
{
  int rc=-1;

  switch (c) {
  case 'h':  
    {
      if (PROTO_PRINT_DUMPS==1) printf("hello: rc=%x\n", rc);
      rc = proto_client_hello(C->ph);
      if (rc > 0) game_process_reply(C);
    }
    break;
  case 'm':
    gettimeofday(&rpc_start, NULL);
    if (PROTO_PRINT_DUMPS==1) printf("move: rc=%x\n", rc);
    rc = proto_client_move(C->ph, c);
    break;
  case 'f':
    gettimeofday(&rpc_pickup_start, NULL);  
    if (PROTO_PRINT_DUMPS==1) printf("pickup: rc=%x\n", rc);
    rc = proto_client_pickup(C->ph);
    break;
  case 'g':
    if (PROTO_PRINT_DUMPS==1) printf("goodbye: rc=%x\n", rc);
    rc = proto_client_goodbye(C->ph);
    // We are done, exit the client
    exit(1);
    rc = -1;

    break;
  case 's':
    if (PROTO_PRINT_DUMPS==1) printf("start: rc=%x\n", rc);
    rc = proto_client_startgame(C->ph);
    break;    
  case 'q':
    if (PROTO_PRINT_DUMPS==1) printf("query map: rc=%x\n", rc);
    rc = proto_client_querymap(C->ph);
    break;

  default:
    printf("%s: unknown command %c\n", __func__, c);
  }
  // NULL MT OVERRIDE ;-)
  if (PROTO_PRINT_DUMPS==1) printf("%s: rc=0x%x\n", __func__, rc);
  if (rc == 0xdeadbeef) rc=1;
  return rc;
}
示例#3
0
文件: client.c 项目: al3jandr0/FE
int doCMDS(Client *C, char *cmdInput)
{
    int rc = 1;

    char **tokens;
    int k = 0;
    tokens = str_split(cmdInput, ' ');

    if (tokens)
    {
        for (k = 0; * (tokens + k); k++)
        {
            if (proto_debug())
                printf("%d - %s\n", k, *(tokens + k));
        }
    }

    if (proto_debug())
        printf("Total commands - %d\n", k);

    if (connectFLAG == FALSE)
    {
        if (strcmp(*(tokens + 0), "connect") != 0)
        {
            printf("%s\n", "Please do a connect first - connect <IP> <PORT>");
            return rc;
        }
    }

    if (tokens)
    {
        if ( strcmp(*(tokens + 0), "pickup") == 0 )
        {
            if (k == 2)
            {
                if (strcmp(*(tokens + 1), "shovel") == 0)
                   rc = proto_item_action(C->ph, 'S', 'p'); 
                else if (strcmp(*(tokens + 1), "flag") == 0)
                   rc = proto_item_action(C->ph, 'F', 'p'); 
                else
                   printf("%s\n", "Error - usage of pickup: pickup <shovel|flag>");
            }
	    else 
               printf("%s\n", "Error - usage of pickup: pickup <shovel|flag>");
            return rc;
        }
        if ( strcmp(*(tokens + 0), "drop") == 0 )
        {
            if (k == 2)
            {
                if (strcmp(*(tokens + 1), "shovel") == 0)
                   rc = proto_item_action(C->ph, 'S', 'd'); 
                else if (strcmp(*(tokens + 1), "flag") == 0)
                   rc = proto_item_action(C->ph, 'F', 'd'); 
                else
                   printf("%s\n", "Error - usage of drop: drop <shovel|flag>");
            }
	    else 
               printf("%s\n", "Error - usage of drop: drop <shovel|flag>");
            return rc;
        }
        if ( strcmp(*(tokens + 0), "move") == 0 )
        {
            if (k == 2)
            {
                if (strcmp(*(tokens + 1), "U") == 0)
                   rc = proto_client_move(C->ph, 'U'); 
                else if (strcmp(*(tokens + 1), "D") == 0)
                   rc = proto_client_move(C->ph, 'D'); 
                else if (strcmp(*(tokens + 1), "L") == 0)
                   rc = proto_client_move(C->ph, 'L'); 
                else if (strcmp(*(tokens + 1), "R") == 0)
                   rc = proto_client_move(C->ph, 'R'); 
                else
                   printf("%s\n", "Error - usage of move: move <U|D|L|R>");
            }
	    else 
                printf("%s\n", "Error - usage of move: move <U|D|L|R>");
            return rc;
        }
        if ( strcmp(*(tokens + 0), "join") == 0 )
        {
            rc = proto_client_hello(C->ph); 
            return rc;
        }
        if ( strcmp(*(tokens + 0), "printdata") == 0 )
        {
            rc = print_client_data(); 
            return rc;
        }
        if ( strcmp(*(tokens + 0), "connect") == 0 )
        {
            //rc = doRPCCmd(C, 'h');
            //return rc;
            //rc = proto_client_hello(C->ph);
            //printf("hello: rc=%x\n", rc);
            //if (rc > 0) game_process_reply(C);
            if (connectFLAG == TRUE)
            {
                //fprintf(stderr, "Are are already connected.");
            }
            return rc;
        }

        else if (strcmp(*(tokens + 0), "numhome") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc;
            if (k == 2)
            {
                rc = proto_client_numhome(C->ph, atoi(*(tokens + 1)));

                if ((strcmp(*(tokens + 1), "1") == 0) || (strcmp(*(tokens + 1), "2") == 0 ))
                    printf("The number of home cells that team %s has - %d\n", *(tokens + 1), rc);
                else
                    printf("%s\n", "Error - usage of numhome: numhome <1|2>");
            }
            else
                printf("%s\n", "Error - usage of numhome: numhome <1|2>");

            rc = 1;

            return rc;
        }

        else if (strcmp(*(tokens + 0), "numjail") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc

            if (k == 2)
            {
                rc = proto_client_numjail(C->ph, atoi(*(tokens + 1)));

                if (strcmp(*(tokens + 1), "1") == 0 || strcmp(*(tokens + 1), "2") == 0 )
                    printf("The number of jail cells that team %s has - %d\n", *(tokens + 1), rc);
                else
                    printf("%s\n", "Error - usage of numjail: numjail <1|2>");
            }
            else
                printf("%s\n", "Error - usage of numjail: numjail <1|2>");
            rc = 1;

            return rc;
        }

        else if (strcmp(*(tokens + 0), "numwall") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc;
            rc = proto_client_numwall(C->ph);
            printf("The number of wall cells - %d\n", rc);

            rc = 1;

            return rc;
        }

        else if (strcmp(*(tokens + 0), "numfloor") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc;
            //rc = proto_client_numfloor(C->ph);

            rc = proto_client_numfloor(C->ph);
            printf("The number of floor cells - %d\n", rc);
            rc = 1;

            return rc;
        }

        else if (strcmp(*(tokens + 0), "dim") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc;
            rc = proto_client_dim(C->ph);

            short x = getA(rc);
            short y = getB(rc);

            printf("The dimensions of the maze - %hd by %hd\n", x, y);

            rc = 1;

            return rc;
        }

        else if (strcmp(*(tokens + 0), "cinfo") == 0)
        {
            //rc = docmd(C, 'q');
            //return rc;

            if (k == 3)
            {
                rc = proto_client_cinfo(C->ph, atoi(*(tokens + 1)), atoi(*(tokens + 2)));

                if (atoi(*(tokens + 1)) > 0 && atoi(*(tokens + 2)) > 0 )
                {
                    if (proto_debug())
                        printf("%s\n", "Good");

                    int cell = (rc >> (8 * 1)) & 0xff;
                    printf("The cell is a - %c\n", (char) cell);

                    int team = (rc >> (8 * 2)) & 0xff;
                    printf("The team is - %c\n", (char) team);

                    int occupied = (rc >> (8 * 3)) & 0xff;
                    printf("Is the cell occupied - %c\n", (char) occupied);
                }
                else
                    printf("%s\n", "Error - usage of cinfo: cinfo <X> <Y>");

            }
            else