void IslInterface::processSessionEvent(const SessionEvent &event, qint64 sessionId) { switch (getPbExtension(event)) { case SessionEvent::SERVER_COMPLETE_LIST: sessionEvent_ServerCompleteList(event.GetExtension(Event_ServerCompleteList::ext)); break; case SessionEvent::USER_JOINED: sessionEvent_UserJoined(event.GetExtension(Event_UserJoined::ext)); break; case SessionEvent::USER_LEFT: sessionEvent_UserLeft(event.GetExtension(Event_UserLeft::ext)); break; case SessionEvent::GAME_JOINED: { QReadLocker clientsLocker(&server->clientsLock); Server_AbstractUserInterface *client = server->getUsersBySessionId().value(sessionId); if (!client) { qDebug() << "IslInterface::processSessionEvent: session id" << sessionId << "not found"; break; } const Event_GameJoined &gameJoined = event.GetExtension(Event_GameJoined::ext); client->playerAddedToGame(gameJoined.game_info().game_id(), gameJoined.game_info().room_id(), gameJoined.player_id()); client->sendProtocolItem(event); break; } case SessionEvent::USER_MESSAGE: case SessionEvent::REPLAY_ADDED: { QReadLocker clientsLocker(&server->clientsLock); Server_AbstractUserInterface *client = server->getUsersBySessionId().value(sessionId); if (!client) { qDebug() << "IslInterface::processSessionEvent: session id" << sessionId << "not found"; break; } client->sendProtocolItem(event); break; } default: ; } }
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); } }