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
+3 -2
View File
@@ -50,7 +50,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
myConfigState = OK; myConfigState = OK;
// !!!! Revisionsnummer der Configdefaults !!!!! // !!!! Revisionsnummer der Configdefaults !!!!!
configRev = 89; configRev = 90;
//standard defaults //standard defaults
logOnOffDefault = "1"; logOnOffDefault = "1";
@@ -203,7 +203,8 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
configList.push_back(ConfigInfo("ServerPutAvatarsUser", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("ServerPutAvatarsUser", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ServerPutAvatarsPassword", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("ServerPutAvatarsPassword", CONFIG_TYPE_STRING, ""));
configList.push_back(ConfigInfo("ServerDoNotAutoKickSmallDelaySec", CONFIG_TYPE_STRING, "10")); configList.push_back(ConfigInfo("ServerDoNotAutoKickSmallDelaySec", CONFIG_TYPE_STRING, "10"));
configList.push_back(ConfigInfo("InternetServerConfigMode", CONFIG_TYPE_INT, "0")); configList.push_back(ConfigInfo("ServerBruteForceProtection", CONFIG_TYPE_INT, "1"));
configList.push_back(ConfigInfo("InternetServerConfigMode", CONFIG_TYPE_INT, "0"));
configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z")); configList.push_back(ConfigInfo("InternetServerListAddress", CONFIG_TYPE_STRING, "pokerth.net/serverlist.xml.z"));
configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org")); configList.push_back(ConfigInfo("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
configList.push_back(ConfigInfo("InternetServerPort", CONFIG_TYPE_INT, "7234")); configList.push_back(ConfigInfo("InternetServerPort", CONFIG_TYPE_INT, "7234"));
+1
View File
@@ -72,6 +72,7 @@ public:
void SendPlayerAction(); void SendPlayerAction();
void SendGameChatMessage(const std::string &msg); void SendGameChatMessage(const std::string &msg);
void SendLobbyChatMessage(const std::string &msg); void SendLobbyChatMessage(const std::string &msg);
void SendPrivateChatMessage(unsigned targetPlayerId, const std::string &msg);
void SendJoinFirstGame(const std::string &password); void SendJoinFirstGame(const std::string &password);
void SendJoinGame(unsigned gameId, const std::string &password); void SendJoinGame(unsigned gameId, const std::string &password);
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password); void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
+19
View File
@@ -209,6 +209,25 @@ ClientThread::SendLobbyChatMessage(const std::string &msg)
m_ioService->post(boost::bind(&ClientThread::SendSessionPacket, shared_from_this(), packet)); 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 void
ClientThread::SendJoinFirstGame(const std::string &password) 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. // Forward chat text to all players.
// TODO: Some limitation needed. // TODO: Some limitation needed.
ChatRequestMessage_t *netChatRequest = &packet->GetMsg()->choice.chatRequestMessage; 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()) if (!server->IsRunning())
server->GetLobbyThread().HandleChatRequest(session, *netChatRequest); 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.major = POKERTH_VERSION_MAJOR;
netAnnounce->latestGameVersion.minor = POKERTH_VERSION_MINOR; netAnnounce->latestGameVersion.minor = POKERTH_VERSION_MINOR;
netAnnounce->latestBetaRevision = POKERTH_BETA_REVISION; netAnnounce->latestBetaRevision = POKERTH_BETA_REVISION;
switch (m_mode) switch (GetServerMode())
{ {
case SERVER_MODE_LAN: case SERVER_MODE_LAN:
netAnnounce->serverType = serverType_serverTypeLAN; netAnnounce->serverType = serverType_serverTypeLAN;
@@ -996,18 +996,21 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
// Before any other processing, perform some denial of service and // Before any other processing, perform some denial of service and
// brute force attack prevention by checking whether the user recently sent an // brute force attack prevention by checking whether the user recently sent an
// Init packet. // Init packet.
bool recentlySentInit = false; if (m_serverConfig->readConfigInt("ServerBruteForceProtection") != 0)
{ {
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex); bool recentlySentInit = false;
if (m_timerClientAddressMap.find(session.sessionData->GetClientAddr()) != m_timerClientAddressMap.end()) {
recentlySentInit = true; boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
else if (m_timerClientAddressMap.find(session.sessionData->GetClientAddr()) != m_timerClientAddressMap.end())
m_timerClientAddressMap[session.sessionData->GetClientAddr()] = boost::timers::portable::microsec_timer(); recentlySentInit = true;
} else
if (recentlySentInit) m_timerClientAddressMap[session.sessionData->GetClientAddr()] = boost::timers::portable::microsec_timer();
{ }
SessionError(session, ERR_NET_INIT_BLOCKED); if (recentlySentInit)
return; {
SessionError(session, ERR_NET_INIT_BLOCKED);
return;
}
} }
// Check the protocol version. // Check the protocol version.
@@ -1414,35 +1417,66 @@ ServerLobbyThread::HandleNetPacketJoinGame(SessionWrapper session, const std::st
void void
ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest) ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const ChatRequestMessage_t &chatRequest)
{ {
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby // Guests are not allowed to chat.
&& session.playerData if (session.playerData && session.playerData->GetRights() != PLAYER_RIGHTS_GUEST)
&& session.playerData->GetRights() != PLAYER_RIGHTS_GUEST) // Guests are not allowed to chat.
{ {
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc)); if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby)
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; {
ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
netChat->chatType.present = chatType_PR_chatTypeLobby; packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
ChatTypeLobby_t *netLobbyChat = &netChat->chatType.choice.chatTypeLobby; ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage;
netLobbyChat->playerId = session.playerData->GetUniqueId(); netChat->chatType.present = chatType_PR_chatTypeLobby;
OCTET_STRING_fromBuf( ChatTypeLobby_t *netLobbyChat = &netChat->chatType.choice.chatTypeLobby;
&netChat->chatText, netLobbyChat->playerId = session.playerData->GetUniqueId();
(char *)chatRequest.chatText.buf, OCTET_STRING_fromBuf(
chatRequest.chatText.size); &netChat->chatText,
(char *)chatRequest.chatText.buf,
chatRequest.chatText.size);
m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established); m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText); string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText);
// Send the message to the chat cleaner bot. // Send the message to the chat cleaner bot.
m_chatCleanerManager->HandleChatText( m_chatCleanerManager->HandleChatText(
session.playerData->GetUniqueId(), session.playerData->GetUniqueId(),
session.playerData->GetName(), session.playerData->GetName(),
chatMsg); chatMsg);
// Send the message to the irc bot. // Send the message to the irc bot.
GetIrcBotCallback().SignalLobbyMessage( GetIrcBotCallback().SignalLobbyMessage(
session.playerData->GetUniqueId(), session.playerData->GetUniqueId(),
session.playerData->GetName(), session.playerData->GetName(),
chatMsg); 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);
}
}
}
} }
} }
+8
View File
@@ -379,6 +379,14 @@ void Session::sendLobbyChatMessage(const std::string &message)
myNetClient->SendLobbyChatMessage(message); myNetClient->SendLobbyChatMessage(message);
} }
void Session::sendPrivateChatMessage(unsigned targetPlayerId, const std::string &message)
{
if (!myNetClient)
return;
myNetClient->SendPrivateChatMessage(targetPlayerId, message);
}
void Session::kickPlayer(unsigned playerId) void Session::kickPlayer(unsigned playerId)
{ {
if (!myNetClient) if (!myNetClient)
+1
View File
@@ -80,6 +80,7 @@ public:
void sendGameChatMessage(const std::string &message); void sendGameChatMessage(const std::string &message);
void sendLobbyChatMessage(const std::string &message); void sendLobbyChatMessage(const std::string &message);
void sendPrivateChatMessage(unsigned targetPlayerId, const std::string &message);
void kickPlayer(unsigned playerId); void kickPlayer(unsigned playerId);
void kickPlayer(const std::string &playerName); void kickPlayer(const std::string &playerName);
void startVoteKickPlayer(unsigned playerId); void startVoteKickPlayer(unsigned playerId);