Esempio n. 1
0
int handle_quit_req() {
    int ret = 0; 
    printf("Quitting server.\n");
    ret = generic_command(QUIT_REQUEST, NULL, buf);
    shutdown_clean(0); /* exits */
    return ret;
}
Esempio n. 2
0
int handle_create_room_req(char *room_name)
{
    int ret = generic_command(CREATE_ROOM_REQUEST, room_name, buf);
    switch (ret) {
        case COMMAND_SUCC:
            printf("Room '%s' created.\n", room_name);
            break;
        case COMMAND_FAIL:
            printf("Could not create room '%s': %s\n",
                room_name, (char *) (cmh->msgdata));

            /* Classify the failure... */
            if ((strstr((char *) (cmh->msgdata), "Number of rooms"))
                == (char *) (cmh->msgdata))
            {   /* "Number of rooms reached maximum!" */
                ret = MAX_ROOMS;
            } else if ((strstr((char *) (cmh->msgdata), "Room exists"))
                == (char *) (cmh->msgdata))
            {   /* "Room exists!" */
                ret = ROOM_EXISTS;
            } else { /* Only other possibility based on server code */
                ret = ROOM_NAME_TOOOO_LOOOONG;
            }
            break;
        default:
            return ret;
    }
    return 0;
}
Esempio n. 3
0
int handle_switch_room_req(char *room_name)
{
    int ret = generic_command(SWITCH_ROOM_REQUEST, room_name, buf);
    switch (ret) {
        case COMMAND_SUCC:
            printf("Switched to room '%s'\n", room_name);
            update_room_state(room_name);
            break;
        case COMMAND_FAIL:
            printf("Could not switch to room '%s': %s\n",
                room_name, (char *) (cmh->msgdata));

            /* Classify the failure... */
            if ((strstr((char *) (cmh->msgdata), "No room avail"))
                == (char *) (cmh->msgdata))
            {   /* "No room available yet!" */
                return ZERO_ROOMS;
            } else if ((strstr((char *) (cmh->msgdata), "Room not found"))
                == (char *) (cmh->msgdata))
            {   /* "Room not found!" */
                return ROOM_NOT_FOUND;
            } else if ((strstr((char *) (cmh->msgdata), "Room is full"))
                == (char *) (cmh->msgdata))
            {   /* "Room is full!" */
                return ROOM_FULL;
            }
            break;
        default:
            return ret;
    }
    return 0;
}
Esempio n. 4
0
int handle_register_req()
{
    int ret = generic_command(REGISTER_REQUEST, NULL, buf);
    debug_sub_print(DBG_TCP, "%s: Registering with server...\n",
        __func__);

    switch (ret) {
        case COMMAND_SUCC:
            printf("Successfully registered '%s' as member #%d\n",
                member_name, (member_id = /*ntohs*/(cmh->member_id)));
            break;
        case COMMAND_FAIL:
            fprintf(stderr, "Registration failed: %s\n",
                (char *) (cmh->msgdata));
            /* Determine cause of failure with a great big smelly
             * HAAAAAAAAAAAAAAAAAAAAAAAAAAACK. A nice protocol would
             * allow us to distinguish these cases without string-
             * compares */
            if ((strstr((char *) (cmh->msgdata), "Name"))
                == (char *) (cmh->msgdata))
            {
                /* If we find "Name" at the beginning of the message
                 * our name is in use. */
                ret = NAME_IN_USE;
            } else {
                /* Only other case for rejection (based on examination
                 * of the server code) is if the server is full. */
                ret = SERVER_FULL;
            }
        default:
            return ret;
    }
    return ret;
}
Esempio n. 5
0
int mps_player_pause() 
{
  int rv=MPS_SUCCESS;
  MPS_DBG_PRINT("Entering %s()\n", __func__);
  rv=generic_command(OPCODE_PAUSE, STATE_PAUSED);
  MPS_DBG_PRINT("Leaving %s() - return value %d\n", __func__, rv);
  return rv;
}
Esempio n. 6
0
int handle_room_list_req() {
    int ret = generic_command(ROOM_LIST_REQUEST, NULL, buf);
    switch(ret) {
        case COMMAND_SUCC:
            printf("%s\n", (char *) (cmh->msgdata));
            break;
        case COMMAND_FAIL:
            printf("Could not list rooms: %s\n", (char *) (cmh->msgdata));
            break;
        default:
            return ret;
    }
    return 0;
}
Esempio n. 7
0
int handle_member_list_req(char *room_name) {
    int ret = generic_command(MEMBER_LIST_REQUEST, room_name, buf);
    switch (ret) {
        case COMMAND_SUCC:
            printf("%s\n", (char *) (cmh->msgdata));
            break;
        case COMMAND_FAIL:
            printf("Could not list members in room '%s': %s\n",
                room_name, (char *) (cmh->msgdata));
            break;
        default:
            return ret;
    }
    return 0;
}
Esempio n. 8
0
/* If the send of this packet is successful, generic_command will
 * have updated the last_seen time. */
int handle_keepalive() {
    int ret = generic_command(MEMBER_KEEP_ALIVE, NULL, buf);
    debug_sub_print(DBG_ACTIVE, "Ah, ah, ah, ah, staying alive\n");
    return ret;
}