diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 3c4a4af3..93225071 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -82,6 +82,7 @@ HEADERS += \ src/net/serverbanmanager.h \ src/net/servercallback.h \ src/net/serverircbot.h \ + src/net/serverircbotcallback.h \ src/net/sessiondata.h \ src/net/sessiondatacallback.h \ src/net/sessionmanager.h \ @@ -185,6 +186,7 @@ SOURCES += \ src/net/common/serverbanmanager.cpp \ src/net/common/servercallback.cpp \ src/net/common/serverircbot.cpp \ + src/net/common/serverircbotcallback.cpp \ src/net/common/sessiondata.cpp \ src/net/common/sessiondatacallback.cpp \ src/net/common/sessionmanager.cpp \ diff --git a/src/net/common/serverircbot.cpp b/src/net/common/serverircbot.cpp index ea09265c..31a77caf 100644 --- a/src/net/common/serverircbot.cpp +++ b/src/net/common/serverircbot.cpp @@ -59,7 +59,6 @@ ServerIrcBot::SignalIrcSelfJoined(const std::string &nickName, const std::string { LOG_MSG("Joined IRC channel " << channel << " as user " << nickName << "."); m_ircNick = nickName; - m_ircThread->SendPing(); } void @@ -253,6 +252,20 @@ ServerIrcBot::SignalIrcServerError(int errorCode) LOG_MSG("IRC server error " << errorCode << "."); } +void +ServerIrcBot::SignalLobbyMessage(unsigned playerId, const std::string &playerName, const std::string &msg) +{ + if (m_ircThread && !msg.empty()) + { + ostringstream ircMsg; + if (playerId) + ircMsg << playerName << " (" << playerId << "): " << msg; + else + ircMsg << playerName << ": " << msg; + m_ircThread->SendChatMessage(ircMsg.str()); + } +} + void ServerIrcBot::Run() { diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 27cbd9a9..810a9c07 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -94,9 +95,9 @@ private: }; -ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager, +ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ServerIrcBotCallback &ircBotCb, ConfigFile *playerConfig, AvatarManager &avatarManager, boost::shared_ptr ioService) -: m_ioService(ioService), m_gui(gui), m_avatarManager(avatarManager), +: m_ioService(ioService), m_gui(gui), m_ircBotCb(ircBotCb), m_avatarManager(avatarManager), m_playerConfig(playerConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1), m_statDataChanged(false), m_removeGameTimer(*ioService), m_removePlayerTimer(*ioService), m_sessionTimeoutTimer(*ioService), m_avatarCleanupTimer(*ioService), @@ -467,6 +468,11 @@ ServerLobbyThread::SendChatBotMsg(const std::string &message) m_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established); m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game); + + GetIrcBotCallback().SignalLobbyMessage( + 0, + "(chat bot)", + message); } void @@ -1141,10 +1147,18 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat 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(), - STL_STRING_FROM_OCTET_STRING(chatRequest.chatText)); + session.playerData->GetUniqueId(), + session.playerData->GetName(), + chatMsg); + // Send the message to the irc bot. + GetIrcBotCallback().SignalLobbyMessage( + session.playerData->GetUniqueId(), + session.playerData->GetName(), + chatMsg); } } @@ -1669,6 +1683,12 @@ ServerLobbyThread::GetCallback() return m_gui; } +ServerIrcBotCallback & +ServerLobbyThread::GetIrcBotCallback() +{ + return m_ircBotCb; +} + ReceiverHelper & ServerLobbyThread::GetReceiver() { diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 405372d1..415526e5 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -46,7 +46,7 @@ ServerManager::~ServerManager() void ServerManager::Init(unsigned serverPort, bool ipv6, ServerNetworkMode mode, const string &pwd, const string &logDir, boost::shared_ptr ircThread) { - m_lobbyThread.reset(new ServerLobbyThread(GetGui(), m_playerConfig, m_avatarManager, m_ioService)); + m_lobbyThread.reset(new ServerLobbyThread(GetGui(), *m_ircBot, m_playerConfig, m_avatarManager, m_ioService)); GetLobbyThread().Init(pwd, logDir); m_ircBot->Init(m_lobbyThread, ircThread); diff --git a/src/net/serverircbot.h b/src/net/serverircbot.h index bf9478a2..bbbc5f23 100644 --- a/src/net/serverircbot.h +++ b/src/net/serverircbot.h @@ -27,6 +27,7 @@ #include #include +#include #include class ServerLobbyThread; @@ -36,7 +37,7 @@ class ConfigFile; class AvatarManager; class IrcThread; -class ServerIrcBot : public IrcCallback +class ServerIrcBot : public IrcCallback, public ServerIrcBotCallback { public: ServerIrcBot(); @@ -63,6 +64,8 @@ public: virtual void SignalIrcError(int errorCode); virtual void SignalIrcServerError(int errorCode); + virtual void SignalLobbyMessage(unsigned playerId, const std::string &playerName, const std::string &msg); + protected: ServerLobbyThread &GetLobbyThread(); diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index 1af09be6..bcb74aca 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -38,6 +38,7 @@ class SenderHelper; class ReceiverHelper; class ServerSenderCallback; +class ServerIrcBotCallback; class ServerGame; class ServerBanManager; class ConfigFile; @@ -49,7 +50,7 @@ class Game; class ServerLobbyThread : public Thread, public boost::enable_shared_from_this { public: - ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager, + ServerLobbyThread(GuiInterface &gui, ServerIrcBotCallback &ircBotCb, ConfigFile *playerConfig, AvatarManager &avatarManager, boost::shared_ptr ioService); virtual ~ServerLobbyThread(); @@ -165,6 +166,7 @@ protected: ServerSenderCallback &GetSenderCallback(); GuiInterface &GetGui(); + ServerIrcBotCallback &GetIrcBotCallback(); bool IsPlayerConnected(const std::string &name) const; @@ -199,6 +201,7 @@ private: GameMap m_gameMap; GuiInterface &m_gui; + ServerIrcBotCallback &m_ircBotCb; AvatarManager &m_avatarManager; std::string m_password;