void AbstractClient::processProtocolItem(ProtocolItem *item) { ProtocolResponse *response = qobject_cast<ProtocolResponse *>(item); if (response) { CommandContainer *cmdCont = pendingCommands.value(response->getCmdId(), 0); if (!cmdCont) return; pendingCommands.remove(cmdCont->getCmdId()); cmdCont->processResponse(response); if (response->getReceiverMayDelete()) delete response; cmdCont->deleteLater(); return; } GenericEvent *genericEvent = qobject_cast<GenericEvent *>(item); if (genericEvent) { switch (genericEvent->getItemId()) { case ItemId_Event_UserJoined: emit userJoinedEventReceived(qobject_cast<Event_UserJoined *>(item)); break; case ItemId_Event_UserLeft: emit userLeftEventReceived(qobject_cast<Event_UserLeft *>(item)); break; case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break; case ItemId_Event_ListRooms: emit listRoomsEventReceived(qobject_cast<Event_ListRooms *>(item)); break; case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break; case ItemId_Event_Message: emit messageEventReceived(qobject_cast<Event_Message *>(item)); break; } if (genericEvent->getReceiverMayDelete()) delete genericEvent; return; } GameEventContainer *gameEventContainer = qobject_cast<GameEventContainer *>(item); if (gameEventContainer) { emit gameEventContainerReceived(gameEventContainer); if (gameEventContainer->getReceiverMayDelete()) delete gameEventContainer; return; } RoomEvent *roomEvent = qobject_cast<RoomEvent *>(item); if (roomEvent) { emit roomEventReceived(roomEvent); if (roomEvent->getReceiverMayDelete()) delete roomEvent; return; } }
void AbstractClient::processProtocolItem(const ServerMessage &item) { switch (item.message_type()) { case ServerMessage::RESPONSE: { const Response &response = item.response(); const int cmdId = response.cmd_id(); PendingCommand *pend = pendingCommands.value(cmdId, 0); if (!pend) return; pendingCommands.remove(cmdId); pend->processResponse(response); pend->deleteLater(); break; } case ServerMessage::SESSION_EVENT: { const SessionEvent &event = item.session_event(); switch ((SessionEvent::SessionEventType) getPbExtension(event)) { case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break; case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break; case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break; case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break; case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break; case SessionEvent::NOTIFY_USER: emit notifyUserEventReceived(event.GetExtension(Event_NotifyUser::ext)); break; case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break; case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break; case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break; case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break; case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break; case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break; case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break; default: break; } break; } case ServerMessage::GAME_EVENT_CONTAINER: { emit gameEventContainerReceived(item.game_event_container()); break; } case ServerMessage::ROOM_EVENT: { emit roomEventReceived(item.room_event()); break; } } }