Adding code for private chat messages (server side). These messages are not allowed within a game. Adding config option to disable brute force protection.

This commit is contained in:
lotodore
2010-11-07 08:24:31 +00:00
parent 6b179cd8ca
commit 0cb1d75ce3
7 changed files with 106 additions and 41 deletions
+19
View File
@@ -209,6 +209,25 @@ ClientThread::SendLobbyChatMessage(const std::string &msg)
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
void
ClientThread::SendPrivateChatMessage(unsigned targetPlayerId, 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_chatRequestTypePrivate;
netChat->chatRequestType.choice.chatRequestTypePrivate.targetPlayerId = targetPlayerId;
// Just dump the packet.
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet));
}
void
ClientThread::SendJoinFirstGame(const std::string &password)
{
+2 -1
View File
@@ -270,7 +270,8 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
// Forward chat text to all players.
// TODO: Some limitation needed.
ChatRequestMessage_t *netChatRequest = &packet->GetMsg()->choice.chatRequestMessage;
if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby)
if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby
|| netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypePrivate)
{
if (!server->IsRunning())
server->GetLobbyThread().HandleChatRequest(session, *netChatRequest);
+72 -38
View File
@@ -253,7 +253,7 @@ ServerLobbyThread::AddConnection(boost::shared_ptr<tcp::socket> sock)
netAnnounce->latestGameVersion.major = POKERTH_VERSION_MAJOR;
netAnnounce->latestGameVersion.minor = POKERTH_VERSION_MINOR;
netAnnounce->latestBetaRevision = POKERTH_BETA_REVISION;
switch (m_mode)
switch (GetServerMode())
{
case SERVER_MODE_LAN:
netAnnounce->serverType = serverType_serverTypeLAN;
@@ -996,18 +996,21 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
// Before any other processing, perform some denial of service and
// brute force attack prevention by checking whether the user recently sent an
// Init packet.
bool recentlySentInit = false;
if (m_serverConfig->readConfigInt("ServerBruteForceProtection") != 0)
{
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
if (m_timerClientAddressMap.find(session.sessionData->GetClientAddr()) != m_timerClientAddressMap.end())
recentlySentInit = true;
else
m_timerClientAddressMap[session.sessionData->GetClientAddr()] = boost::timers::portable::microsec_timer();
}
if (recentlySentInit)
{
SessionError(session, ERR_NET_INIT_BLOCKED);
return;
bool recentlySentInit = false;
{
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
if (m_timerClientAddressMap.find(session.sessionData->GetClientAddr()) != m_timerClientAddressMap.end())
recentlySentInit = true;
else
m_timerClientAddressMap[session.sessionData->GetClientAddr()] = boost::timers::portable::microsec_timer();
}
if (recentlySentInit)
{
SessionError(session, ERR_NET_INIT_BLOCKED);
return;
}
}
// Check the protocol version.
@@ -1414,35 +1417,66 @@ 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
&& session.playerData->GetRights() != PLAYER_RIGHTS_GUEST) // Guests are not allowed to chat.
// Guests are not allowed to chat.
if (session.playerData && session.playerData->GetRights() != PLAYER_RIGHTS_GUEST)
{
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);
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby)
{
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.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText);
// Send the message to the chat cleaner bot.
m_chatCleanerManager->HandleChatText(
session.playerData->GetUniqueId(),
session.playerData->GetName(),
chatMsg);
// Send the message to the irc bot.
GetIrcBotCallback().SignalLobbyMessage(
session.playerData->GetUniqueId(),
session.playerData->GetName(),
chatMsg);
string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText);
// Send the message to the chat cleaner bot.
m_chatCleanerManager->HandleChatText(
session.playerData->GetUniqueId(),
session.playerData->GetName(),
chatMsg);
// Send the message to the irc bot.
GetIrcBotCallback().SignalLobbyMessage(
session.playerData->GetUniqueId(),
session.playerData->GetName(),
chatMsg);
}
else if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypePrivate)
{
const ChatRequestTypePrivate_t *netPrivateChat = &chatRequest.chatRequestType.choice.chatRequestTypePrivate;
SessionWrapper targetSession = m_sessionManager.GetSessionByUniquePlayerId(netPrivateChat->targetPlayerId);
if (!targetSession.sessionData)
targetSession = m_gameSessionManager.GetSessionByUniquePlayerId(netPrivateChat->targetPlayerId);
if (targetSession.sessionData && targetSession.playerData)
{
// Only allow private messages to players which are not in running games.
// TODO: Send chat reject message if private message was not sent.
unsigned gameId = targetSession.sessionData->GetGameId();
GameMap::const_iterator pos = m_gameMap.find(gameId);
if (pos == m_gameMap.end() || !pos->second->IsRunning())
{
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);
GetSender().Send(targetSession.sessionData, packet);
}
}
}
}
}