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:
@@ -50,7 +50,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
||||
myConfigState = OK;
|
||||
|
||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||
configRev = 89;
|
||||
configRev = 90;
|
||||
|
||||
//standard defaults
|
||||
logOnOffDefault = "1";
|
||||
@@ -203,6 +203,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
||||
configList.push_back(ConfigInfo("ServerPutAvatarsUser", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("ServerPutAvatarsPassword", CONFIG_TYPE_STRING, ""));
|
||||
configList.push_back(ConfigInfo("ServerDoNotAutoKickSmallDelaySec", CONFIG_TYPE_STRING, "10"));
|
||||
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("InternetServerAddress", CONFIG_TYPE_STRING, "pokerth.6dns.org"));
|
||||
|
||||
@@ -72,6 +72,7 @@ public:
|
||||
void SendPlayerAction();
|
||||
void SendGameChatMessage(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 SendJoinGame(unsigned gameId, const std::string &password);
|
||||
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,6 +996,8 @@ 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.
|
||||
if (m_serverConfig->readConfigInt("ServerBruteForceProtection") != 0)
|
||||
{
|
||||
bool recentlySentInit = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_timerClientAddressMapMutex);
|
||||
@@ -1009,6 +1011,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const InitMessage
|
||||
SessionError(session, ERR_NET_INIT_BLOCKED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check the protocol version.
|
||||
if (initMessage.requestedVersion.major != NET_VERSION_MAJOR
|
||||
@@ -1414,9 +1417,10 @@ 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)
|
||||
{
|
||||
if (chatRequest.chatRequestType.present == chatRequestType_PR_chatRequestTypeLobby)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacket(NetPacket::Alloc));
|
||||
packet->GetMsg()->present = PokerTHMessage_PR_chatMessage;
|
||||
@@ -1444,6 +1448,36 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -379,6 +379,14 @@ void Session::sendLobbyChatMessage(const std::string &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)
|
||||
{
|
||||
if (!myNetClient)
|
||||
|
||||
@@ -80,6 +80,7 @@ public:
|
||||
|
||||
void sendGameChatMessage(const std::string &message);
|
||||
void sendLobbyChatMessage(const std::string &message);
|
||||
void sendPrivateChatMessage(unsigned targetPlayerId, const std::string &message);
|
||||
void kickPlayer(unsigned playerId);
|
||||
void kickPlayer(const std::string &playerName);
|
||||
void startVoteKickPlayer(unsigned playerId);
|
||||
|
||||
Reference in New Issue
Block a user