Forward all lobby chat messages to irc admin bot. Game chat is still private, so don't worry :-).

This commit is contained in:
lotodore
2009-08-20 11:42:13 +00:00
parent 0aa285621b
commit 460090e383
6 changed files with 50 additions and 9 deletions
+2
View File
@@ -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 \
+14 -1
View File
@@ -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()
{
+25 -5
View File
@@ -23,6 +23,7 @@
#include <net/serverexception.h>
#include <net/senderhelper.h>
#include <net/sendercallback.h>
#include <net/serverircbotcallback.h>
#include <net/receiverhelper.h>
#include <net/socket_msg.h>
#include <net/chatcleanermanager.h>
@@ -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<boost::asio::io_service> 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()
{
+1 -1
View File
@@ -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> 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);
+4 -1
View File
@@ -27,6 +27,7 @@
#include <list>
#include <game_defs.h>
#include <net/serverircbotcallback.h>
#include <gui/guiinterface.h>
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();
+4 -1
View File
@@ -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<ServerLobbyThread>
{
public:
ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager,
ServerLobbyThread(GuiInterface &gui, ServerIrcBotCallback &ircBotCb, ConfigFile *playerConfig, AvatarManager &avatarManager,
boost::shared_ptr<boost::asio::io_service> 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;