Remove libircclient from client (pokerth_game no longer depends on it).

This commit is contained in:
lotodore
2011-03-11 21:56:24 +00:00
parent c47e74d427
commit c877e0ef74
11 changed files with 304 additions and 98 deletions
+18 -35
View File
@@ -25,6 +25,7 @@
#include <net/serverexception.h>
#include <net/socket_msg.h>
#include <net/socket_startup.h>
#include <net/serverircbotcallback.h>
#include <core/loghelper.h>
#include <boost/bind.hpp>
@@ -32,12 +33,24 @@
using namespace std;
ServerManager::ServerManager(GuiInterface &gui, ConfigFile &config, AvatarManager &avatarManager)
: m_gui(gui), m_playerConfig(config), m_avatarManager(avatarManager)
class GenericIrcCallback : public ServerIrcBotCallback
{
virtual void SignalLobbyMessage(unsigned /*playerId*/, const std::string &/*playerName*/, const std::string &/*msg*/) {}
};
static GenericIrcCallback g_ircCallback;
ServerManager::ServerManager(ConfigFile &config, GuiInterface &gui)
: m_playerConfig(config), m_gui(gui)
{
m_ioService.reset(new boost::asio::io_service);
m_adminBot.reset(new ServerAdminBot);
m_lobbyBot.reset(new ServerLobbyBot);
}
ServerManager::ServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager)
: m_playerConfig(config), m_gui(gui)
{
m_ioService.reset(new boost::asio::io_service);
m_lobbyThread.reset(new ServerLobbyThread(gui, mode, g_ircCallback, config, avatarManager, m_ioService));
}
ServerManager::~ServerManager()
@@ -52,14 +65,10 @@ ServerManager::~ServerManager()
}
void
ServerManager::Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, ServerMode mode, const string &logDir, boost::shared_ptr<IrcThread> ircAdminThread, boost::shared_ptr<IrcThread> ircLobbyThread)
ServerManager::Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, const string &logDir)
{
m_lobbyThread.reset(new ServerLobbyThread(GetGui(), mode, *m_lobbyBot, m_playerConfig, m_avatarManager, m_ioService));
GetLobbyThread().Init(logDir);
m_adminBot->Init(m_lobbyThread, ircAdminThread);
m_lobbyBot->Init(m_lobbyThread, ircLobbyThread);
if (proto & TRANSPORT_PROTOCOL_TCP) {
boost::shared_ptr<ServerAcceptInterface> tcpAcceptHelper(new ServerAcceptHelper<boost::asio::ip::tcp>(GetGui(), m_ioService));
tcpAcceptHelper->Listen(serverPort, ipv6, logDir, m_lobbyThread);
@@ -73,52 +82,26 @@ ServerManager::Init(unsigned serverPort, bool ipv6, ServerTransportProtocol prot
}*/
}
GuiInterface &
ServerManager::GetGui()
{
return m_gui;
}
ServerAdminBot &
ServerManager::GetAdminBot()
{
return *m_adminBot;
}
ServerLobbyBot &
ServerManager::GetLobbyBot()
{
return *m_lobbyBot;
}
void
ServerManager::RunAll()
{
m_adminBot->Run();
m_lobbyBot->Run();
GetLobbyThread().Run();
}
void
ServerManager::Process()
{
m_adminBot->Process();
m_lobbyBot->Process();
}
void
ServerManager::SignalTerminationAll()
{
m_adminBot->SignalTermination();
m_lobbyBot->SignalTermination();
GetLobbyThread().SignalTermination();
}
bool
ServerManager::JoinAll(bool wait)
{
m_adminBot->Join(wait);
m_lobbyBot->Join(wait);
return GetLobbyThread().Join(wait ? NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC : 0);
}
@@ -0,0 +1,27 @@
/***************************************************************************
* Copyright (C) 2011 by Lothar May *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <net/servermanagerfactory.h>
boost::shared_ptr<ServerManager>
ServerManagerFactory::CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager)
{
return boost::shared_ptr<ServerManager>(new ServerManager(config, gui, mode, avatarManager));
}
@@ -0,0 +1,29 @@
/***************************************************************************
* Copyright (C) 2011 by Lothar May *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <net/servermanagerfactory.h>
#include <net/servermanagerirc.h>
boost::shared_ptr<ServerManager>
ServerManagerFactory::CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager)
{
return boost::shared_ptr<ServerManager>(new ServerManagerIrc(config, gui, mode, avatarManager));
}
+108
View File
@@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (C) 2011 by Lothar May *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <boost/asio.hpp>
#include <net/servermanagerirc.h>
#include <net/serveradminbot.h>
#include <net/serverlobbybot.h>
#include <net/serverlobbythread.h>
#include <net/ircthread.h>
#include <config/configfile.h>
using namespace std;
ServerManagerIrc::ServerManagerIrc(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager)
: ServerManager(config, gui)
{
m_adminBot.reset(new ServerAdminBot);
m_lobbyBot.reset(new ServerLobbyBot);
m_lobbyThread.reset(new ServerLobbyThread(gui, mode, *m_lobbyBot, config, avatarManager, m_ioService));
}
ServerManagerIrc::~ServerManagerIrc()
{
}
void
ServerManagerIrc::Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, const string &logDir)
{
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
ConfigFile &myConfig = GetConfig();
if (myConfig.readConfigInt("UseAdminIRC")) {
tmpIrcAdminThread = boost::shared_ptr<IrcThread>(new IrcThread(m_adminBot.get()));
tmpIrcAdminThread->Init(
myConfig.readConfigString("AdminIRCServerAddress"),
myConfig.readConfigInt("AdminIRCServerPort"),
myConfig.readConfigInt("AdminIRCServerUseIpv6") == 1,
myConfig.readConfigString("AdminIRCServerNick"),
myConfig.readConfigString("AdminIRCChannel"),
myConfig.readConfigString("AdminIRCChannelPassword"));
}
if (myConfig.readConfigInt("UseLobbyIRC")) {
tmpIrcLobbyThread = boost::shared_ptr<IrcThread>(new IrcThread(m_lobbyBot.get()));
tmpIrcLobbyThread->Init(
myConfig.readConfigString("LobbyIRCServerAddress"),
myConfig.readConfigInt("LobbyIRCServerPort"),
myConfig.readConfigInt("LobbyIRCServerUseIpv6") == 1,
myConfig.readConfigString("LobbyIRCServerNick"),
myConfig.readConfigString("LobbyIRCChannel"),
myConfig.readConfigString("LobbyIRCChannelPassword"));
}
m_adminBot->Init(m_lobbyThread, tmpIrcAdminThread);
m_lobbyBot->Init(m_lobbyThread, tmpIrcLobbyThread);
ServerManager::Init(serverPort, ipv6, proto, logDir);
}
void
ServerManagerIrc::RunAll()
{
m_adminBot->Run();
m_lobbyBot->Run();
ServerManager::RunAll();
}
void
ServerManagerIrc::Process()
{
m_adminBot->Process();
m_lobbyBot->Process();
ServerManager::Process();
}
void
ServerManagerIrc::SignalTerminationAll()
{
m_adminBot->SignalTermination();
m_lobbyBot->SignalTermination();
ServerManager::SignalTerminationAll();
}
bool
ServerManagerIrc::JoinAll(bool wait)
{
m_adminBot->Join(wait);
m_lobbyBot->Join(wait);
return ServerManager::JoinAll(wait);
}
+18 -21
View File
@@ -22,8 +22,6 @@
#define _SERVERMANAGER_H_
#include <boost/asio.hpp>
#include <net/serveradminbot.h>
#include <net/serverlobbybot.h>
#include <string>
#include <list>
@@ -31,7 +29,6 @@
#include <gui/guiinterface.h>
class ServerLobbyThread;
class IrcThread;
class ServerAcceptInterface;
class SenderThread;
class ConfigFile;
@@ -40,39 +37,39 @@ class AvatarManager;
class ServerManager
{
public:
ServerManager(GuiInterface &gui, ConfigFile &config, AvatarManager &avatarManager);
ServerManager(ConfigFile &config, GuiInterface &gui);
ServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager);
virtual ~ServerManager();
// Set the parameters.
void Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, ServerMode mode, const std::string &logDir, boost::shared_ptr<IrcThread> ircAdminThread, boost::shared_ptr<IrcThread> ircLobbyThread);
virtual void Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, const std::string &logDir);
// Main start function.
void RunAll();
virtual void RunAll();
// Let the server manager perform processing.
void Process();
virtual void Process();
void SignalTerminationAll();
bool JoinAll(bool wait);
GuiInterface &GetGui();
ServerAdminBot &GetAdminBot();
ServerLobbyBot &GetLobbyBot();
virtual void SignalTerminationAll();
virtual bool JoinAll(bool wait);
protected:
typedef std::list<boost::shared_ptr<ServerAcceptInterface> > AcceptHelperList;
ServerLobbyThread &GetLobbyThread();
private:
GuiInterface &m_gui;
ConfigFile &m_playerConfig;
AvatarManager &m_avatarManager;
ConfigFile &GetConfig() {
return m_playerConfig;
}
GuiInterface &GetGui() {
return m_gui;
}
boost::shared_ptr<boost::asio::io_service> m_ioService;
boost::shared_ptr<ServerLobbyThread> m_lobbyThread;
boost::shared_ptr<ServerAdminBot> m_adminBot;
boost::shared_ptr<ServerLobbyBot> m_lobbyBot;
private:
ConfigFile &m_playerConfig;
GuiInterface &m_gui;
AcceptHelperList m_acceptHelperPool;
};
+32
View File
@@ -0,0 +1,32 @@
/***************************************************************************
* Copyright (C) 2011 by Lothar May *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/* Factory method for the server manager. */
#ifndef _SERVERMANAGERFACTORY_H_
#define _SERVERMANAGERFACTORY_H_
#include <net/servermanager.h>
class ServerManagerFactory
{
public:
static boost::shared_ptr<ServerManager> CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager);
};
#endif // SERVERMANAGERFACTORY_H
+55
View File
@@ -0,0 +1,55 @@
/***************************************************************************
* Copyright (C) 2011 by Lothar May *
* *
* 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 *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/* Manager thread for the server, with irc bots. */
#ifndef _SERVERMANAGERIRC_H_
#define _SERVERMANAGERIRC_H_
#include <net/servermanager.h>
class ServerAdminBot;
class ServerLobbyBot;
class ServerManagerIrc : public ServerManager
{
public:
ServerManagerIrc(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager);
virtual ~ServerManagerIrc();
// Set the parameters.
virtual void Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, const std::string &logDir);
// Main start function.
virtual void RunAll();
// Let the server manager perform processing.
virtual void Process();
virtual void SignalTerminationAll();
virtual bool JoinAll(bool wait);
GuiInterface &GetGui();
private:
boost::shared_ptr<ServerAdminBot> m_adminBot;
boost::shared_ptr<ServerLobbyBot> m_lobbyBot;
};
#endif
+6 -35
View File
@@ -28,9 +28,8 @@
#include <localenginefactory.h>
#include <clientenginefactory.h>
#include <net/clientthread.h>
#include <net/servermanager.h>
#include <net/ircthread.h>
#include <core/avatarmanager.h>
#include <net/servermanagerfactory.h>
#include <sstream>
@@ -288,34 +287,6 @@ void Session::startNetworkServer(bool dedicated)
return;
}
myNetServer.reset(new ServerManager(*myGui, *myConfig, *myAvatarManager));
boost::shared_ptr<IrcThread> tmpIrcAdminThread;
boost::shared_ptr<IrcThread> tmpIrcLobbyThread;
if (myConfig->readConfigInt("UseAdminIRC")) {
tmpIrcAdminThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetAdminBot()));
tmpIrcAdminThread->Init(
myConfig->readConfigString("AdminIRCServerAddress"),
myConfig->readConfigInt("AdminIRCServerPort"),
myConfig->readConfigInt("AdminIRCServerUseIpv6") == 1,
myConfig->readConfigString("AdminIRCServerNick"),
myConfig->readConfigString("AdminIRCChannel"),
myConfig->readConfigString("AdminIRCChannelPassword"));
}
if (myConfig->readConfigInt("UseLobbyIRC")) {
tmpIrcLobbyThread = boost::shared_ptr<IrcThread>(new IrcThread(&myNetServer->GetLobbyBot()));
tmpIrcLobbyThread->Init(
myConfig->readConfigString("LobbyIRCServerAddress"),
myConfig->readConfigInt("LobbyIRCServerPort"),
myConfig->readConfigInt("LobbyIRCServerUseIpv6") == 1,
myConfig->readConfigString("LobbyIRCServerNick"),
myConfig->readConfigString("LobbyIRCChannel"),
myConfig->readConfigString("LobbyIRCChannelPassword"));
}
ServerMode mode;
if (dedicated) {
#ifdef POKERTH_OFFICIAL_SERVER
@@ -323,17 +294,17 @@ void Session::startNetworkServer(bool dedicated)
#else
mode = SERVER_MODE_INTERNET_NOAUTH;
#endif
} else
} else {
mode = SERVER_MODE_LAN;
}
myNetServer = ServerManagerFactory::CreateServerManager(*myConfig, *myGui, mode, *myAvatarManager);
myNetServer->Init(
myConfig->readConfigInt("ServerPort"),
myConfig->readConfigInt("ServerUseIpv6") == 1,
myConfig->readConfigInt("ServerUseSctp") == 1 ? TRANSPORT_PROTOCOL_TCP_SCTP : TRANSPORT_PROTOCOL_TCP,
mode,
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")),
tmpIrcAdminThread,
tmpIrcLobbyThread
myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir"))
);
myNetServer->RunAll();