Forward all lobby chat messages to irc admin bot. Game chat is still private, so don't worry :-).
This commit is contained in:
@@ -82,6 +82,7 @@ HEADERS += \
|
|||||||
src/net/serverbanmanager.h \
|
src/net/serverbanmanager.h \
|
||||||
src/net/servercallback.h \
|
src/net/servercallback.h \
|
||||||
src/net/serverircbot.h \
|
src/net/serverircbot.h \
|
||||||
|
src/net/serverircbotcallback.h \
|
||||||
src/net/sessiondata.h \
|
src/net/sessiondata.h \
|
||||||
src/net/sessiondatacallback.h \
|
src/net/sessiondatacallback.h \
|
||||||
src/net/sessionmanager.h \
|
src/net/sessionmanager.h \
|
||||||
@@ -185,6 +186,7 @@ SOURCES += \
|
|||||||
src/net/common/serverbanmanager.cpp \
|
src/net/common/serverbanmanager.cpp \
|
||||||
src/net/common/servercallback.cpp \
|
src/net/common/servercallback.cpp \
|
||||||
src/net/common/serverircbot.cpp \
|
src/net/common/serverircbot.cpp \
|
||||||
|
src/net/common/serverircbotcallback.cpp \
|
||||||
src/net/common/sessiondata.cpp \
|
src/net/common/sessiondata.cpp \
|
||||||
src/net/common/sessiondatacallback.cpp \
|
src/net/common/sessiondatacallback.cpp \
|
||||||
src/net/common/sessionmanager.cpp \
|
src/net/common/sessionmanager.cpp \
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ ServerIrcBot::SignalIrcSelfJoined(const std::string &nickName, const std::string
|
|||||||
{
|
{
|
||||||
LOG_MSG("Joined IRC channel " << channel << " as user " << nickName << ".");
|
LOG_MSG("Joined IRC channel " << channel << " as user " << nickName << ".");
|
||||||
m_ircNick = nickName;
|
m_ircNick = nickName;
|
||||||
m_ircThread->SendPing();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -253,6 +252,20 @@ ServerIrcBot::SignalIrcServerError(int errorCode)
|
|||||||
LOG_MSG("IRC server error " << 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
|
void
|
||||||
ServerIrcBot::Run()
|
ServerIrcBot::Run()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <net/serverexception.h>
|
#include <net/serverexception.h>
|
||||||
#include <net/senderhelper.h>
|
#include <net/senderhelper.h>
|
||||||
#include <net/sendercallback.h>
|
#include <net/sendercallback.h>
|
||||||
|
#include <net/serverircbotcallback.h>
|
||||||
#include <net/receiverhelper.h>
|
#include <net/receiverhelper.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
#include <net/chatcleanermanager.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)
|
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_playerConfig(playerConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
||||||
m_statDataChanged(false), m_removeGameTimer(*ioService), m_removePlayerTimer(*ioService),
|
m_statDataChanged(false), m_removeGameTimer(*ioService), m_removePlayerTimer(*ioService),
|
||||||
m_sessionTimeoutTimer(*ioService), m_avatarCleanupTimer(*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_sessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Established);
|
||||||
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
m_gameSessionManager.SendLobbyMsgToAllSessions(GetSender(), packet, SessionData::Game);
|
||||||
|
|
||||||
|
GetIrcBotCallback().SignalLobbyMessage(
|
||||||
|
0,
|
||||||
|
"(chat bot)",
|
||||||
|
message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1141,10 +1147,18 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat
|
|||||||
|
|
||||||
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);
|
||||||
|
// 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(),
|
||||||
STL_STRING_FROM_OCTET_STRING(chatRequest.chatText));
|
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;
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerIrcBotCallback &
|
||||||
|
ServerLobbyThread::GetIrcBotCallback()
|
||||||
|
{
|
||||||
|
return m_ircBotCb;
|
||||||
|
}
|
||||||
|
|
||||||
ReceiverHelper &
|
ReceiverHelper &
|
||||||
ServerLobbyThread::GetReceiver()
|
ServerLobbyThread::GetReceiver()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ ServerManager::~ServerManager()
|
|||||||
void
|
void
|
||||||
ServerManager::Init(unsigned serverPort, bool ipv6, ServerNetworkMode mode, const string &pwd, const string &logDir, boost::shared_ptr<IrcThread> ircThread)
|
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);
|
GetLobbyThread().Init(pwd, logDir);
|
||||||
|
|
||||||
m_ircBot->Init(m_lobbyThread, ircThread);
|
m_ircBot->Init(m_lobbyThread, ircThread);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <game_defs.h>
|
#include <game_defs.h>
|
||||||
|
#include <net/serverircbotcallback.h>
|
||||||
#include <gui/guiinterface.h>
|
#include <gui/guiinterface.h>
|
||||||
|
|
||||||
class ServerLobbyThread;
|
class ServerLobbyThread;
|
||||||
@@ -36,7 +37,7 @@ class ConfigFile;
|
|||||||
class AvatarManager;
|
class AvatarManager;
|
||||||
class IrcThread;
|
class IrcThread;
|
||||||
|
|
||||||
class ServerIrcBot : public IrcCallback
|
class ServerIrcBot : public IrcCallback, public ServerIrcBotCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerIrcBot();
|
ServerIrcBot();
|
||||||
@@ -63,6 +64,8 @@ public:
|
|||||||
virtual void SignalIrcError(int errorCode);
|
virtual void SignalIrcError(int errorCode);
|
||||||
virtual void SignalIrcServerError(int errorCode);
|
virtual void SignalIrcServerError(int errorCode);
|
||||||
|
|
||||||
|
virtual void SignalLobbyMessage(unsigned playerId, const std::string &playerName, const std::string &msg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ServerLobbyThread &GetLobbyThread();
|
ServerLobbyThread &GetLobbyThread();
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
class SenderHelper;
|
class SenderHelper;
|
||||||
class ReceiverHelper;
|
class ReceiverHelper;
|
||||||
class ServerSenderCallback;
|
class ServerSenderCallback;
|
||||||
|
class ServerIrcBotCallback;
|
||||||
class ServerGame;
|
class ServerGame;
|
||||||
class ServerBanManager;
|
class ServerBanManager;
|
||||||
class ConfigFile;
|
class ConfigFile;
|
||||||
@@ -49,7 +50,7 @@ class Game;
|
|||||||
class ServerLobbyThread : public Thread, public boost::enable_shared_from_this<ServerLobbyThread>
|
class ServerLobbyThread : public Thread, public boost::enable_shared_from_this<ServerLobbyThread>
|
||||||
{
|
{
|
||||||
public:
|
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);
|
boost::shared_ptr<boost::asio::io_service> ioService);
|
||||||
virtual ~ServerLobbyThread();
|
virtual ~ServerLobbyThread();
|
||||||
|
|
||||||
@@ -165,6 +166,7 @@ protected:
|
|||||||
|
|
||||||
ServerSenderCallback &GetSenderCallback();
|
ServerSenderCallback &GetSenderCallback();
|
||||||
GuiInterface &GetGui();
|
GuiInterface &GetGui();
|
||||||
|
ServerIrcBotCallback &GetIrcBotCallback();
|
||||||
|
|
||||||
bool IsPlayerConnected(const std::string &name) const;
|
bool IsPlayerConnected(const std::string &name) const;
|
||||||
|
|
||||||
@@ -199,6 +201,7 @@ private:
|
|||||||
GameMap m_gameMap;
|
GameMap m_gameMap;
|
||||||
|
|
||||||
GuiInterface &m_gui;
|
GuiInterface &m_gui;
|
||||||
|
ServerIrcBotCallback &m_ircBotCb;
|
||||||
AvatarManager &m_avatarManager;
|
AvatarManager &m_avatarManager;
|
||||||
|
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
|
|||||||
Reference in New Issue
Block a user