コード例 #1
0
void Server_ProtocolHandler::processCommandContainer(const CommandContainer &cont)
{
	// Command processing must be disabled after prepareDestroy() has been called.
	if (deleted)
		return;
	
	lastDataReceived = timeRunning;
	
	ResponseContainer responseContainer(cont.has_cmd_id() ? cont.cmd_id() : -1);
	Response::ResponseCode finalResponseCode;
	
	if (cont.game_command_size())
		finalResponseCode = processGameCommandContainer(cont, responseContainer);
	else if (cont.room_command_size())
		finalResponseCode = processRoomCommandContainer(cont, responseContainer);
	else if (cont.session_command_size())
		finalResponseCode = processSessionCommandContainer(cont, responseContainer);
	else if (cont.moderator_command_size())
		finalResponseCode = processModeratorCommandContainer(cont, responseContainer);
	else if (cont.admin_command_size())
		finalResponseCode = processAdminCommandContainer(cont, responseContainer);
	else
		finalResponseCode = Response::RespInvalidCommand;
	
	if ((finalResponseCode != Response::RespNothing))
		sendResponseContainer(responseContainer, finalResponseCode);
}
コード例 #2
0
ファイル: server.cpp プロジェクト: GuillaumeSeren/Cockatrice
void Server::externalJoinGameCommandReceived(const Command_JoinGame &cmd, int cmdId, int roomId, int serverId, qint64 sessionId)
{
    // This function is always called from the main thread via signal/slot.

    try {
        QReadLocker roomsLocker(&roomsLock);
        QReadLocker clientsLocker(&clientsLock);

        Server_Room *room = rooms.value(roomId);
        if (!room) {
            qDebug() << "externalJoinGameCommandReceived: room id=" << roomId << "not found";
            throw Response::RespNotInRoom;
        }
        Server_AbstractUserInterface *userInterface = externalUsersBySessionId.value(sessionId);
        if (!userInterface) {
            qDebug() << "externalJoinGameCommandReceived: session id=" << sessionId << "not found";
            throw Response::RespNotInRoom;
        }

        ResponseContainer responseContainer(cmdId);
        Response::ResponseCode responseCode = room->processJoinGameCommand(cmd, responseContainer, userInterface);
        userInterface->sendResponseContainer(responseContainer, responseCode);
    } catch (Response::ResponseCode code) {
        Response response;
        response.set_cmd_id(cmdId);
        response.set_response_code(code);

        sendIsl_Response(response, serverId, sessionId);
    }
}
コード例 #3
0
ファイル: server.cpp プロジェクト: GuillaumeSeren/Cockatrice
void Server::externalGameCommandContainerReceived(const CommandContainer &cont, int playerId, int serverId, qint64 sessionId)
{
    // This function is always called from the main thread via signal/slot.

    try {
        ResponseContainer responseContainer(cont.cmd_id());
        Response::ResponseCode finalResponseCode = Response::RespOk;

        QReadLocker roomsLocker(&roomsLock);
        Server_Room *room = rooms.value(cont.room_id());
        if (!room) {
            qDebug() << "externalGameCommandContainerReceived: room id=" << cont.room_id() << "not found";
            throw Response::RespNotInRoom;
        }

        QReadLocker roomGamesLocker(&room->gamesLock);
        Server_Game *game = room->getGames().value(cont.game_id());
        if (!game) {
            qDebug() << "externalGameCommandContainerReceived: game id=" << cont.game_id() << "not found";
            throw Response::RespNotInRoom;
        }

        QMutexLocker gameLocker(&game->gameMutex);
        Server_Player *player = game->getPlayers().value(playerId);
        if (!player) {
            qDebug() << "externalGameCommandContainerReceived: player id=" << playerId << "not found";
            throw Response::RespNotInRoom;
        }

        GameEventStorage ges;
        for (int i = cont.game_command_size() - 1; i >= 0; --i) {
            const GameCommand &sc = cont.game_command(i);
            qDebug() << "[ISL]" << QString::fromStdString(sc.ShortDebugString());

            Response::ResponseCode resp = player->processGameCommand(sc, responseContainer, ges);

            if (resp != Response::RespOk)
                finalResponseCode = resp;
        }
        ges.sendToGame(game);

        if (finalResponseCode != Response::RespNothing) {
            player->playerMutex.lock();
            player->getUserInterface()->sendResponseContainer(responseContainer, finalResponseCode);
            player->playerMutex.unlock();
        }
    } catch (Response::ResponseCode code) {
        Response response;
        response.set_cmd_id(cont.cmd_id());
        response.set_response_code(code);

        sendIsl_Response(response, serverId, sessionId);
    }
}