Ejemplo n.º 1
0
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: ;
	}
}
Ejemplo n.º 2
0
Response::ResponseCode Server_ProtocolHandler::cmdMessage(const Command_Message &cmd, ResponseContainer &rc)
{
	if (authState == NotLoggedIn)
		return Response::RespLoginNeeded;
	
	QReadLocker locker(&server->clientsLock);
	
	QString receiver = QString::fromStdString(cmd.user_name());
	Server_AbstractUserInterface *userInterface = server->findUser(receiver);
	if (!userInterface)
		return Response::RespNameNotFound;
	if (databaseInterface->isInIgnoreList(receiver, QString::fromStdString(userInfo->name())))
		return Response::RespInIgnoreList;
	
	Event_UserMessage event;
	event.set_sender_name(userInfo->name());
	event.set_receiver_name(cmd.user_name());
	event.set_message(cmd.message());
	
	SessionEvent *se = prepareSessionEvent(event);
	userInterface->sendProtocolItem(*se);
	rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, se);
	
	return Response::RespOk;
}