Use own lobby chat instead of IRC. First steps, still incomplete.
This commit is contained in:
@@ -809,18 +809,29 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
|
||||
ChatMessage_t *netMessage = &tmpPacket->GetMsg()->choice.chatMessage;
|
||||
|
||||
string playerName;
|
||||
if (netMessage->playerId == 0)
|
||||
if (netMessage->chatType.present == chatType_PR_chatTypeBroadcast)
|
||||
{
|
||||
playerName = "(global notice)";
|
||||
client->GetCallback().SignalNetClientGameChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
||||
client->GetCallback().SignalNetClientLobbyChatMsg("(global notice)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
||||
}
|
||||
else
|
||||
else if (netMessage->chatType.present == chatType_PR_chatTypeGame)
|
||||
{
|
||||
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(netMessage->playerId);
|
||||
unsigned playerId = netMessage->chatType.choice.chatTypeGame.playerId;
|
||||
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
|
||||
if (tmpPlayer.get())
|
||||
playerName = tmpPlayer->GetName();
|
||||
if (!playerName.empty())
|
||||
client->GetCallback().SignalNetClientGameChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
||||
}
|
||||
else if (netMessage->chatType.present == chatType_PR_chatTypeLobby)
|
||||
{
|
||||
unsigned playerId = netMessage->chatType.choice.chatTypeLobby.playerId;
|
||||
boost::shared_ptr<PlayerData> tmpPlayer = client->GetPlayerDataByUniqueId(playerId);
|
||||
if (tmpPlayer.get())
|
||||
playerName = tmpPlayer->GetName();
|
||||
if (!playerName.empty())
|
||||
client->GetCallback().SignalNetClientLobbyChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
||||
}
|
||||
if (!playerName.empty())
|
||||
client->GetCallback().SignalNetClientChatMsg(playerName, STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
|
||||
}
|
||||
else if (tmpPacket->GetMsg()->present == PokerTHMessage_PR_dialogMessage)
|
||||
{
|
||||
|
||||
@@ -172,18 +172,38 @@ ClientThread::SendPlayerAction()
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SendChatMessage(const std::string &msg)
|
||||
ClientThread::SendGameChatMessage(const std::string &msg)
|
||||
{
|
||||
// Warning: This function is called in the context of the GUI thread.
|
||||
// Create a network packet containing the chat message.
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage;
|
||||
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage;
|
||||
netChat->gameId = GetGameId();
|
||||
OCTET_STRING_fromBuf(&netChat->chatText,
|
||||
msg.c_str(),
|
||||
msg.length());
|
||||
|
||||
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeGame;
|
||||
netChat->chatRequestType.choice.chatRequestTypeGame.gameId = GetGameId();
|
||||
|
||||
// Just dump the packet.
|
||||
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::SendLobbyChatMessage(const std::string &msg)
|
||||
{
|
||||
// Warning: This function is called in the context of the GUI thread.
|
||||
// Create a network packet containing the chat message.
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatRequestMessage;
|
||||
ChatRequestMessage_t *netChat = &packet->GetMsg()->choice.chatRequestMessage;
|
||||
OCTET_STRING_fromBuf(&netChat->chatText,
|
||||
msg.c_str(),
|
||||
msg.length());
|
||||
|
||||
netChat->chatRequestType.present = chatRequestType_PR_chatRequestTypeLobby;
|
||||
|
||||
// Just dump the packet.
|
||||
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
|
||||
}
|
||||
|
||||
@@ -240,8 +240,10 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
||||
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
||||
netChat->gameId = server->GetId();
|
||||
netChat->playerId = session.playerData->GetUniqueId();
|
||||
netChat->chatType.present = chatType_PR_chatTypeGame;
|
||||
ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame;
|
||||
netGameChat->gameId = server->GetId();
|
||||
netGameChat->playerId = session.playerData->GetUniqueId();
|
||||
OCTET_STRING_fromBuf(
|
||||
&netChat->chatText,
|
||||
(char *)netChatRequest->chatText.buf,
|
||||
|
||||
@@ -399,14 +399,13 @@ ServerLobbyThread::SendGlobalChat(const string &message)
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
||||
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
||||
// TODO proper game id handling.
|
||||
netChat->gameId = 0;
|
||||
netChat->playerId = 0;
|
||||
netChat->chatType.present = chatType_PR_chatTypeBroadcast;
|
||||
OCTET_STRING_fromBuf(
|
||||
&netChat->chatText,
|
||||
message.c_str(),
|
||||
message.length());
|
||||
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
@@ -747,6 +746,8 @@ ServerLobbyThread::HandlePacket(SessionWrapper session, boost::shared_ptr<NetPac
|
||||
else if (joinRequest->joinGameAction.present == joinGameAction_PR_joinExistingGame)
|
||||
HandleNetPacketJoinGame(session, password, joinRequest->joinGameAction.choice.joinExistingGame);
|
||||
}
|
||||
else if (packet->GetMsg()->present == PokerTHMessage_PR_chatRequestMessage)
|
||||
HandleNetPacketChatRequest(session, packet->GetMsg()->choice.chatRequestMessage);
|
||||
else
|
||||
SessionError(session, ERR_SOCK_INVALID_STATE);
|
||||
}
|
||||
@@ -1070,6 +1071,26 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest)
|
||||
{
|
||||
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby && session.playerData)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
||||
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
|
||||
netChat->chatType.present = chatType_PR_chatTypeLobby;
|
||||
ChatTypeLobby_t *netLobbyChat = &netChat->chatType.choice.chatTypeLobby;
|
||||
netLobbyChat->playerId = session.playerData->GetUniqueId();
|
||||
OCTET_STRING_fromBuf(
|
||||
&netChat->chatText,
|
||||
(char *)chatRequest.chatText.buf,
|
||||
chatRequest.chatText.size);
|
||||
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::EstablishSession(SessionWrapper session)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user