Make that two bots. One for administration and one to forward the lobby chat.
This commit is contained in:
+4
-2
@@ -81,7 +81,8 @@ HEADERS += \
|
|||||||
src/net/serverlobbythread.h \
|
src/net/serverlobbythread.h \
|
||||||
src/net/serverbanmanager.h \
|
src/net/serverbanmanager.h \
|
||||||
src/net/servercallback.h \
|
src/net/servercallback.h \
|
||||||
src/net/serverircbot.h \
|
src/net/serveradminbot.h \
|
||||||
|
src/net/serverlobbybot.h \
|
||||||
src/net/serverircbotcallback.h \
|
src/net/serverircbotcallback.h \
|
||||||
src/net/sessiondata.h \
|
src/net/sessiondata.h \
|
||||||
src/net/sessiondatacallback.h \
|
src/net/sessiondatacallback.h \
|
||||||
@@ -185,7 +186,8 @@ SOURCES += \
|
|||||||
src/net/common/serverlobbythread.cpp \
|
src/net/common/serverlobbythread.cpp \
|
||||||
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/serveradminbot.cpp \
|
||||||
|
src/net/common/serverlobbybot.cpp \
|
||||||
src/net/common/serverircbotcallback.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 \
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2007 by Lothar May *
|
* Copyright (C) 2009 by Lothar May *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <net/serverircbot.h>
|
#include <net/serveradminbot.h>
|
||||||
#include <net/ircthread.h>
|
#include <net/ircthread.h>
|
||||||
#include <net/serverlobbythread.h>
|
#include <net/serverlobbythread.h>
|
||||||
#include <net/serverbanmanager.h>
|
#include <net/serverbanmanager.h>
|
||||||
@@ -33,38 +33,38 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ServerIrcBot::ServerIrcBot()
|
ServerAdminBot::ServerAdminBot()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerIrcBot::~ServerIrcBot()
|
ServerAdminBot::~ServerAdminBot()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::Init(boost::shared_ptr<ServerLobbyThread> lobbyThread, boost::shared_ptr<IrcThread> ircThread)
|
ServerAdminBot::Init(boost::shared_ptr<ServerLobbyThread> lobbyThread, boost::shared_ptr<IrcThread> ircAdminThread)
|
||||||
{
|
{
|
||||||
m_lobbyThread = lobbyThread;
|
m_lobbyThread = lobbyThread;
|
||||||
m_ircThread = ircThread;
|
m_ircAdminThread = ircAdminThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalIrcConnect(const std::string &server)
|
ServerAdminBot::SignalIrcConnect(const std::string &server)
|
||||||
{
|
{
|
||||||
LOG_MSG("Connected to IRC server " << server << ".");
|
LOG_MSG("Admin bot: Connected to IRC server " << server << ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalIrcSelfJoined(const std::string &nickName, const std::string &channel)
|
ServerAdminBot::SignalIrcSelfJoined(const std::string &nickName, const std::string &channel)
|
||||||
{
|
{
|
||||||
LOG_MSG("Joined IRC channel " << channel << " as user " << nickName << ".");
|
LOG_MSG("Admin bot: Joined IRC channel " << channel << " as user " << nickName << ".");
|
||||||
m_ircNick = nickName;
|
m_ircNick = nickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &msg)
|
ServerAdminBot::SignalIrcChatMsg(const std::string &nickName, const std::string &msg)
|
||||||
{
|
{
|
||||||
if (m_ircThread)
|
if (m_ircAdminThread)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -83,15 +83,15 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
if (!playerName.empty())
|
if (!playerName.empty())
|
||||||
{
|
{
|
||||||
if (GetLobbyThread().KickPlayerByName(playerName))
|
if (GetLobbyThread().KickPlayerByName(playerName))
|
||||||
m_ircThread->SendChatMessage(nickName + ": Successfully kicked player \"" + playerName + "\" from the server.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Successfully kicked player \"" + playerName + "\" from the server.");
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": Player \"" + playerName + "\" was not found on the server.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Player \"" + playerName + "\" was not found on the server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "cleaner-reconnect")
|
else if (command == "cleaner-reconnect")
|
||||||
{
|
{
|
||||||
GetLobbyThread().ReconnectChatBot();
|
GetLobbyThread().ReconnectChatBot();
|
||||||
m_ircThread->SendChatMessage(nickName + ": Cleaner bot reconnect initiated.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Cleaner bot reconnect initiated.");
|
||||||
}
|
}
|
||||||
else if (command == "showip")
|
else if (command == "showip")
|
||||||
{
|
{
|
||||||
@@ -102,9 +102,9 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
{
|
{
|
||||||
string ipAddress(GetLobbyThread().GetPlayerIPAddress(playerName));
|
string ipAddress(GetLobbyThread().GetPlayerIPAddress(playerName));
|
||||||
if (!ipAddress.empty())
|
if (!ipAddress.empty())
|
||||||
m_ircThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is: \"" + ipAddress + "\"");
|
m_ircAdminThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is: \"" + ipAddress + "\"");
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is unknown.");
|
m_ircAdminThread->SendChatMessage(nickName + ": The IP address of player \"" + playerName + "\" is unknown.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "bannick")
|
else if (command == "bannick")
|
||||||
@@ -115,7 +115,7 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
if (!playerRegex.empty())
|
if (!playerRegex.empty())
|
||||||
{
|
{
|
||||||
GetLobbyThread().GetBanManager().BanPlayerRegex(playerRegex);
|
GetLobbyThread().GetBanManager().BanPlayerRegex(playerRegex);
|
||||||
m_ircThread->SendChatMessage(nickName + ": The regex \"" + playerRegex + "\" was added to the player ban list.");
|
m_ircAdminThread->SendChatMessage(nickName + ": The regex \"" + playerRegex + "\" was added to the player ban list.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "banip")
|
else if (command == "banip")
|
||||||
@@ -134,7 +134,7 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
ostringstream durationStr;
|
ostringstream durationStr;
|
||||||
durationStr << durationHours;
|
durationStr << durationHours;
|
||||||
GetLobbyThread().GetBanManager().BanIPAddress(ipAddress, durationHours);
|
GetLobbyThread().GetBanManager().BanIPAddress(ipAddress, durationHours);
|
||||||
m_ircThread->SendChatMessage(nickName + ": The IP address \"" + ipAddress + "\" was added to the IP address ban list for " + durationStr.str() + (durationHours == 1 ? " hour." : " hours."));
|
m_ircAdminThread->SendChatMessage(nickName + ": The IP address \"" + ipAddress + "\" was added to the IP address ban list for " + durationStr.str() + (durationHours == 1 ? " hour." : " hours."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "listban")
|
else if (command == "listban")
|
||||||
@@ -145,27 +145,27 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
list<string>::const_iterator end = banList.end();
|
list<string>::const_iterator end = banList.end();
|
||||||
while (i != end)
|
while (i != end)
|
||||||
{
|
{
|
||||||
m_ircThread->SendChatMessage(*i);
|
m_ircAdminThread->SendChatMessage(*i);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
ostringstream banListStream;
|
ostringstream banListStream;
|
||||||
banListStream
|
banListStream
|
||||||
<< nickName << ": Total count of bans: " << banList.size();
|
<< nickName << ": Total count of bans: " << banList.size();
|
||||||
m_ircThread->SendChatMessage(banListStream.str());
|
m_ircAdminThread->SendChatMessage(banListStream.str());
|
||||||
}
|
}
|
||||||
else if (command == "removeban")
|
else if (command == "removeban")
|
||||||
{
|
{
|
||||||
unsigned banId = 0;
|
unsigned banId = 0;
|
||||||
msgStream >> banId;
|
msgStream >> banId;
|
||||||
if (GetLobbyThread().GetBanManager().UnBan(banId))
|
if (GetLobbyThread().GetBanManager().UnBan(banId))
|
||||||
m_ircThread->SendChatMessage(nickName + ": The ban was successfully removed.");
|
m_ircAdminThread->SendChatMessage(nickName + ": The ban was successfully removed.");
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": This ban does not exist.");
|
m_ircAdminThread->SendChatMessage(nickName + ": This ban does not exist.");
|
||||||
}
|
}
|
||||||
else if (command == "clearban")
|
else if (command == "clearban")
|
||||||
{
|
{
|
||||||
GetLobbyThread().GetBanManager().ClearBanList();
|
GetLobbyThread().GetBanManager().ClearBanList();
|
||||||
m_ircThread->SendChatMessage(nickName + ": All ban lists were cleared.");
|
m_ircAdminThread->SendChatMessage(nickName + ": All ban lists were cleared.");
|
||||||
}
|
}
|
||||||
else if (command == "stat")
|
else if (command == "stat")
|
||||||
{
|
{
|
||||||
@@ -175,33 +175,33 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
ostringstream statStream;
|
ostringstream statStream;
|
||||||
statStream
|
statStream
|
||||||
<< "Server uptime................ " << timeDiff.hours() / 24 << " days " << timeDiff.hours() % 24 << " hours " << timeDiff.minutes() << " minutes " << timeDiff.seconds() << " seconds";
|
<< "Server uptime................ " << timeDiff.hours() / 24 << " days " << timeDiff.hours() % 24 << " hours " << timeDiff.minutes() << " minutes " << timeDiff.seconds() << " seconds";
|
||||||
m_ircThread->SendChatMessage(statStream.str());
|
m_ircAdminThread->SendChatMessage(statStream.str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ostringstream statStream;
|
ostringstream statStream;
|
||||||
statStream
|
statStream
|
||||||
<< "Players currently on Server.. " << tmpStats.numberOfPlayersOnServer;
|
<< "Players currently on Server.. " << tmpStats.numberOfPlayersOnServer;
|
||||||
m_ircThread->SendChatMessage(statStream.str());
|
m_ircAdminThread->SendChatMessage(statStream.str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ostringstream statStream;
|
ostringstream statStream;
|
||||||
statStream
|
statStream
|
||||||
<< "Games currently open......... " << tmpStats.numberOfGamesOpen;
|
<< "Games currently open......... " << tmpStats.numberOfGamesOpen;
|
||||||
m_ircThread->SendChatMessage(statStream.str());
|
m_ircAdminThread->SendChatMessage(statStream.str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ostringstream statStream;
|
ostringstream statStream;
|
||||||
statStream
|
statStream
|
||||||
<< "Total players ever logged in. " << tmpStats.totalPlayersEverLoggedIn
|
<< "Total players ever logged in. " << tmpStats.totalPlayersEverLoggedIn
|
||||||
<< " (Max at a time: " << tmpStats.maxPlayersLoggedIn << ")";
|
<< " (Max at a time: " << tmpStats.maxPlayersLoggedIn << ")";
|
||||||
m_ircThread->SendChatMessage(statStream.str());
|
m_ircAdminThread->SendChatMessage(statStream.str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ostringstream statStream;
|
ostringstream statStream;
|
||||||
statStream
|
statStream
|
||||||
<< "Total games ever open........ " << tmpStats.totalGamesEverCreated
|
<< "Total games ever open........ " << tmpStats.totalGamesEverCreated
|
||||||
<< " (Max at a time: " << tmpStats.maxGamesOpen << ")";
|
<< " (Max at a time: " << tmpStats.maxGamesOpen << ")";
|
||||||
m_ircThread->SendChatMessage(statStream.str());
|
m_ircAdminThread->SendChatMessage(statStream.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "chat")
|
else if (command == "chat")
|
||||||
@@ -212,10 +212,10 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
if (!chat.empty() && chat.size() < MAX_CHAT_TEXT_SIZE)
|
if (!chat.empty() && chat.size() < MAX_CHAT_TEXT_SIZE)
|
||||||
{
|
{
|
||||||
GetLobbyThread().SendGlobalChat(chat);
|
GetLobbyThread().SendGlobalChat(chat);
|
||||||
m_ircThread->SendChatMessage(nickName + ": Global chat message sent.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Global chat message sent.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": Invalid message.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid message.");
|
||||||
}
|
}
|
||||||
else if (command == "msg")
|
else if (command == "msg")
|
||||||
{
|
{
|
||||||
@@ -225,67 +225,53 @@ ServerIrcBot::SignalIrcChatMsg(const std::string &nickName, const std::string &m
|
|||||||
if (!message.empty() && message.size() < MAX_CHAT_TEXT_SIZE)
|
if (!message.empty() && message.size() < MAX_CHAT_TEXT_SIZE)
|
||||||
{
|
{
|
||||||
GetLobbyThread().SendGlobalMsgBox(message);
|
GetLobbyThread().SendGlobalMsgBox(message);
|
||||||
m_ircThread->SendChatMessage(nickName + ": Global message box sent.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Global message box sent.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": Invalid message.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid message.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
m_ircAdminThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
||||||
}
|
}
|
||||||
} catch (...)
|
} catch (...)
|
||||||
{
|
{
|
||||||
m_ircThread->SendChatMessage(nickName + ": Syntax error. Please check the command.");
|
m_ircAdminThread->SendChatMessage(nickName + ": Syntax error. Please check the command.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalIrcError(int errorCode)
|
ServerAdminBot::SignalIrcError(int errorCode)
|
||||||
{
|
{
|
||||||
LOG_MSG("IRC error " << errorCode << ".");
|
LOG_MSG("Admin bot: IRC error " << errorCode << ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalIrcServerError(int errorCode)
|
ServerAdminBot::SignalIrcServerError(int errorCode)
|
||||||
{
|
{
|
||||||
LOG_MSG("IRC server error " << errorCode << ".");
|
LOG_MSG("Admin bot: IRC server error " << errorCode << ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalLobbyMessage(unsigned playerId, const std::string &playerName, const std::string &msg)
|
ServerAdminBot::Run()
|
||||||
{
|
{
|
||||||
if (m_ircThread && !msg.empty())
|
if (m_ircAdminThread)
|
||||||
{
|
m_ircAdminThread->Run();
|
||||||
ostringstream ircMsg;
|
|
||||||
if (playerId)
|
|
||||||
ircMsg << playerName << " (" << playerId << "): " << msg;
|
|
||||||
else
|
|
||||||
ircMsg << playerName << ": " << msg;
|
|
||||||
m_ircThread->SendChatMessage(ircMsg.str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::Run()
|
ServerAdminBot::Process()
|
||||||
{
|
|
||||||
if (m_ircThread)
|
|
||||||
m_ircThread->Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ServerIrcBot::Process()
|
|
||||||
{
|
{
|
||||||
if (m_ircRestartTimer.elapsed().total_seconds() > SERVER_RESTART_IRC_BOT_INTERVAL_SEC)
|
if (m_ircRestartTimer.elapsed().total_seconds() > SERVER_RESTART_IRC_BOT_INTERVAL_SEC)
|
||||||
{
|
{
|
||||||
if (m_ircThread)
|
if (m_ircAdminThread)
|
||||||
{
|
{
|
||||||
m_ircThread->SignalTermination();
|
m_ircAdminThread->SignalTermination();
|
||||||
if (m_ircThread->Join(NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC))
|
if (m_ircAdminThread->Join(NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC))
|
||||||
{
|
{
|
||||||
boost::shared_ptr<IrcThread> tmpIrcThread(new IrcThread(*m_ircThread));
|
boost::shared_ptr<IrcThread> tmpIrcThread(new IrcThread(*m_ircAdminThread));
|
||||||
tmpIrcThread->Run();
|
tmpIrcThread->Run();
|
||||||
m_ircThread = tmpIrcThread;
|
m_ircAdminThread = tmpIrcThread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_ircRestartTimer.reset();
|
m_ircRestartTimer.reset();
|
||||||
@@ -294,23 +280,23 @@ ServerIrcBot::Process()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerIrcBot::SignalTermination()
|
ServerAdminBot::SignalTermination()
|
||||||
{
|
{
|
||||||
if (m_ircThread)
|
if (m_ircAdminThread)
|
||||||
m_ircThread->SignalTermination();
|
m_ircAdminThread->SignalTermination();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerIrcBot::Join(bool wait)
|
ServerAdminBot::Join(bool wait)
|
||||||
{
|
{
|
||||||
bool terminated = true;
|
bool terminated = true;
|
||||||
if (m_ircThread)
|
if (m_ircAdminThread)
|
||||||
terminated = m_ircThread->Join(wait ? NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC : 0);
|
terminated = m_ircAdminThread->Join(wait ? NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC : 0);
|
||||||
return terminated;
|
return terminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerLobbyThread &
|
ServerLobbyThread &
|
||||||
ServerIrcBot::GetLobbyThread()
|
ServerAdminBot::GetLobbyThread()
|
||||||
{
|
{
|
||||||
assert(m_lobbyThread.get());
|
assert(m_lobbyThread.get());
|
||||||
return *m_lobbyThread;
|
return *m_lobbyThread;
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
#include <net/socket_helper.h>
|
#include <net/socket_helper.h>
|
||||||
#include <net/servermanager.h>
|
#include <net/servermanager.h>
|
||||||
#include <net/serverlobbythread.h>
|
#include <net/serverlobbythread.h>
|
||||||
#include <net/serverircbot.h>
|
|
||||||
#include <net/serveraccepthelper.h>
|
#include <net/serveraccepthelper.h>
|
||||||
#include <net/serverexception.h>
|
#include <net/serverexception.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
@@ -36,7 +35,8 @@ ServerManager::ServerManager(GuiInterface &gui, ConfigFile *config, AvatarManage
|
|||||||
: m_gui(gui), m_playerConfig(config), m_avatarManager(avatarManager)
|
: m_gui(gui), m_playerConfig(config), m_avatarManager(avatarManager)
|
||||||
{
|
{
|
||||||
m_ioService.reset(new boost::asio::io_service);
|
m_ioService.reset(new boost::asio::io_service);
|
||||||
m_ircBot.reset(new ServerIrcBot);
|
m_adminBot.reset(new ServerAdminBot);
|
||||||
|
m_lobbyBot.reset(new ServerLobbyBot);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerManager::~ServerManager()
|
ServerManager::~ServerManager()
|
||||||
@@ -44,12 +44,13 @@ 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> ircAdminThread, boost::shared_ptr<IrcThread> ircLobbyThread)
|
||||||
{
|
{
|
||||||
m_lobbyThread.reset(new ServerLobbyThread(GetGui(), *m_ircBot, m_playerConfig, m_avatarManager, m_ioService));
|
m_lobbyThread.reset(new ServerLobbyThread(GetGui(), *m_lobbyBot, m_playerConfig, m_avatarManager, m_ioService));
|
||||||
GetLobbyThread().Init(pwd, logDir);
|
GetLobbyThread().Init(pwd, logDir);
|
||||||
|
|
||||||
m_ircBot->Init(m_lobbyThread, ircThread);
|
m_adminBot->Init(m_lobbyThread, ircAdminThread);
|
||||||
|
m_lobbyBot->Init(m_lobbyThread, ircLobbyThread);
|
||||||
|
|
||||||
if (mode & NETWORK_MODE_TCP)
|
if (mode & NETWORK_MODE_TCP)
|
||||||
{
|
{
|
||||||
@@ -71,36 +72,46 @@ ServerManager::GetGui()
|
|||||||
return m_gui;
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerIrcBot &
|
ServerAdminBot &
|
||||||
ServerManager::GetIrcBot()
|
ServerManager::GetAdminBot()
|
||||||
{
|
{
|
||||||
return *m_ircBot;
|
return *m_adminBot;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerLobbyBot &
|
||||||
|
ServerManager::GetLobbyBot()
|
||||||
|
{
|
||||||
|
return *m_lobbyBot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerManager::RunAll()
|
ServerManager::RunAll()
|
||||||
{
|
{
|
||||||
m_ircBot->Run();
|
m_adminBot->Run();
|
||||||
|
m_lobbyBot->Run();
|
||||||
GetLobbyThread().Run();
|
GetLobbyThread().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerManager::Process()
|
ServerManager::Process()
|
||||||
{
|
{
|
||||||
m_ircBot->Process();
|
m_adminBot->Process();
|
||||||
|
m_lobbyBot->Process();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerManager::SignalTerminationAll()
|
ServerManager::SignalTerminationAll()
|
||||||
{
|
{
|
||||||
m_ircBot->SignalTermination();
|
m_adminBot->SignalTermination();
|
||||||
|
m_lobbyBot->SignalTermination();
|
||||||
GetLobbyThread().SignalTermination();
|
GetLobbyThread().SignalTermination();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerManager::JoinAll(bool wait)
|
ServerManager::JoinAll(bool wait)
|
||||||
{
|
{
|
||||||
m_ircBot->Join(wait);
|
m_adminBot->Join(wait);
|
||||||
|
m_lobbyBot->Join(wait);
|
||||||
return GetLobbyThread().Join(wait ? NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC : 0);
|
return GetLobbyThread().Join(wait ? NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
* Free Software Foundation, Inc., *
|
* Free Software Foundation, Inc., *
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
/* IRC bot for the server. */
|
/* IRC admin bot for the server. */
|
||||||
|
|
||||||
#ifndef _SERVERIRCBOT_H_
|
#ifndef _SERVERADMINBOT_H_
|
||||||
#define _SERVERIRCBOT_H_
|
#define _SERVERADMINBOT_H_
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <third_party/boost/timers.hpp>
|
#include <third_party/boost/timers.hpp>
|
||||||
@@ -37,13 +37,13 @@ class ConfigFile;
|
|||||||
class AvatarManager;
|
class AvatarManager;
|
||||||
class IrcThread;
|
class IrcThread;
|
||||||
|
|
||||||
class ServerIrcBot : public IrcCallback, public ServerIrcBotCallback
|
class ServerAdminBot : public IrcCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerIrcBot();
|
ServerAdminBot();
|
||||||
virtual ~ServerIrcBot();
|
virtual ~ServerAdminBot();
|
||||||
|
|
||||||
void Init(boost::shared_ptr<ServerLobbyThread> lobbyThread, boost::shared_ptr<IrcThread> ircThread);
|
void Init(boost::shared_ptr<ServerLobbyThread> lobbyThread, boost::shared_ptr<IrcThread> ircAdminThread);
|
||||||
|
|
||||||
// Main start function.
|
// Main start function.
|
||||||
void Run();
|
void Run();
|
||||||
@@ -64,8 +64,6 @@ 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();
|
||||||
|
|
||||||
@@ -73,7 +71,7 @@ private:
|
|||||||
std::string m_ircNick;
|
std::string m_ircNick;
|
||||||
|
|
||||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
boost::shared_ptr<IrcThread> m_ircThread;
|
boost::shared_ptr<IrcThread> m_ircAdminThread;
|
||||||
boost::timers::portable::microsec_timer m_ircRestartTimer;
|
boost::timers::portable::microsec_timer m_ircRestartTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
#define _SERVERMANAGER_H_
|
#define _SERVERMANAGER_H_
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <net/serverircbot.h>
|
#include <net/serveradminbot.h>
|
||||||
|
#include <net/serverlobbybot.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ public:
|
|||||||
virtual ~ServerManager();
|
virtual ~ServerManager();
|
||||||
|
|
||||||
// Set the parameters.
|
// Set the parameters.
|
||||||
void Init(unsigned serverPort, bool ipv6, ServerNetworkMode mode, const std::string &pwd, const std::string &logDir, boost::shared_ptr<IrcThread> ircThread);
|
void Init(unsigned serverPort, bool ipv6, ServerNetworkMode mode, const std::string &pwd, const std::string &logDir, boost::shared_ptr<IrcThread> ircAdminThread, boost::shared_ptr<IrcThread> ircLobbyThread);
|
||||||
|
|
||||||
// Main start function.
|
// Main start function.
|
||||||
void RunAll();
|
void RunAll();
|
||||||
@@ -55,7 +56,8 @@ public:
|
|||||||
bool JoinAll(bool wait);
|
bool JoinAll(bool wait);
|
||||||
|
|
||||||
GuiInterface &GetGui();
|
GuiInterface &GetGui();
|
||||||
ServerIrcBot &GetIrcBot();
|
ServerAdminBot &GetAdminBot();
|
||||||
|
ServerLobbyBot &GetLobbyBot();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::list<boost::shared_ptr<ServerAcceptHelper> > AcceptHelperList;
|
typedef std::list<boost::shared_ptr<ServerAcceptHelper> > AcceptHelperList;
|
||||||
@@ -69,7 +71,8 @@ private:
|
|||||||
|
|
||||||
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
boost::shared_ptr<boost::asio::io_service> m_ioService;
|
||||||
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
boost::shared_ptr<ServerIrcBot> m_ircBot;
|
boost::shared_ptr<ServerAdminBot> m_adminBot;
|
||||||
|
boost::shared_ptr<ServerLobbyBot> m_lobbyBot;
|
||||||
AcceptHelperList m_acceptHelperPool;
|
AcceptHelperList m_acceptHelperPool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -276,12 +276,23 @@ void Session::startNetworkServer()
|
|||||||
|
|
||||||
myNetServer.reset(new ServerManager(*myGui, myConfig, *myAvatarManager));
|
myNetServer.reset(new ServerManager(*myGui, myConfig, *myAvatarManager));
|
||||||
|
|
||||||
boost::shared_ptr<IrcThread> tmpIrcThread;
|
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
|
||||||
|
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
|
||||||
if (myConfig->readConfigInt("UseAdminIRC"))
|
if (myConfig->readConfigInt("UseAdminIRC"))
|
||||||
{
|
{
|
||||||
tmpIrcThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetIrcBot()));
|
tmpIrcAdminThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetAdminBot()));
|
||||||
|
|
||||||
tmpIrcThread->Init(
|
tmpIrcAdminThread->Init(
|
||||||
|
myConfig->readConfigString("AdminIRCServerAddress"),
|
||||||
|
myConfig->readConfigInt("AdminIRCServerPort"),
|
||||||
|
myConfig->readConfigInt("AdminIRCServerUseIpv6") == 1,
|
||||||
|
myConfig->readConfigString("AdminIRCServerNick"),
|
||||||
|
myConfig->readConfigString("AdminIRCChannel"),
|
||||||
|
myConfig->readConfigString("AdminIRCChannelPassword"));
|
||||||
|
|
||||||
|
tmpIrcLobbyThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetLobbyBot()));
|
||||||
|
|
||||||
|
tmpIrcLobbyThread->Init(
|
||||||
myConfig->readConfigString("AdminIRCServerAddress"),
|
myConfig->readConfigString("AdminIRCServerAddress"),
|
||||||
myConfig->readConfigInt("AdminIRCServerPort"),
|
myConfig->readConfigInt("AdminIRCServerPort"),
|
||||||
myConfig->readConfigInt("AdminIRCServerUseIpv6") == 1,
|
myConfig->readConfigInt("AdminIRCServerUseIpv6") == 1,
|
||||||
@@ -296,7 +307,8 @@ void Session::startNetworkServer()
|
|||||||
myConfig->readConfigInt("ServerUseSctp") == 1 ? NETWORK_MODE_TCP_SCTP : NETWORK_MODE_TCP,
|
myConfig->readConfigInt("ServerUseSctp") == 1 ? NETWORK_MODE_TCP_SCTP : NETWORK_MODE_TCP,
|
||||||
myConfig->readConfigString("ServerPassword"),
|
myConfig->readConfigString("ServerPassword"),
|
||||||
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")),
|
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")),
|
||||||
tmpIrcThread
|
tmpIrcAdminThread,
|
||||||
|
tmpIrcLobbyThread
|
||||||
);
|
);
|
||||||
|
|
||||||
myNetServer->RunAll();
|
myNetServer->RunAll();
|
||||||
|
|||||||
Reference in New Issue
Block a user