From c877e0ef743bda7700403ebbb614ea0fb0a75325 Mon Sep 17 00:00:00 2001 From: lotodore Date: Fri, 11 Mar 2011 21:56:24 +0000 Subject: [PATCH] Remove libircclient from client (pokerth_game no longer depends on it). --- pokerth_game.pro | 6 +- pokerth_lib.pro | 4 +- pokerth_server.pro | 8 +- src/net/common/servermanager.cpp | 53 +++------ src/net/common/servermanagerfactoryclient.cpp | 27 +++++ src/net/common/servermanagerfactoryserver.cpp | 29 +++++ src/net/common/servermanagerirc.cpp | 108 ++++++++++++++++++ src/net/servermanager.h | 39 +++---- src/net/servermanagerfactory.h | 32 ++++++ src/net/servermanagerirc.h | 55 +++++++++ src/session.cpp | 41 +------ 11 files changed, 304 insertions(+), 98 deletions(-) create mode 100644 src/net/common/servermanagerfactoryclient.cpp create mode 100644 src/net/common/servermanagerfactoryserver.cpp create mode 100644 src/net/common/servermanagerirc.cpp create mode 100644 src/net/servermanagerfactory.h create mode 100644 src/net/servermanagerirc.h diff --git a/pokerth_game.pro b/pokerth_game.pro index 507c2887..91c88c7d 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -263,7 +263,8 @@ SOURCES += src/pokerth.cpp \ src/gui/qt/gamelobbydialog/mygamelistsortfilterproxymodel.cpp \ src/gui/qt/internetgamelogindialog/internetgamelogindialogimpl.cpp \ src/engine/local_engine/replay.cpp \ - src/gui/qt/gamelobbydialog/mynicklistsortfilterproxymodel.cpp + src/gui/qt/gamelobbydialog/mynicklistsortfilterproxymodel.cpp \ + src/net/common/servermanagerfactoryclient.cpp TRANSLATIONS = ts/pokerth_af.ts \ ts/pokerth_bg.ts \ ts/pokerth_zhcn.ts \ @@ -293,8 +294,7 @@ TRANSLATIONS = ts/pokerth_af.ts \ LIBS += -lpokerth_lib \ -lpokerth_db \ -lpokerth_protocol \ - -lcurl \ - -lircclient + -lcurl win32 { DEFINES += CURL_STATICLIB diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 8f26e860..615beeeb 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -128,7 +128,8 @@ HEADERS += \ src/gui/qttoolsinterface.h \ src/gui/generic/serverguiwrapper.h \ src/net/receivebuffer.h \ - src/net/sendbuffer.h + src/net/sendbuffer.h \ + src/net/servermanagerfactory.h SOURCES += \ src/game.cpp \ @@ -194,7 +195,6 @@ SOURCES += \ src/net/common/netcontext.cpp \ src/net/common/netexception.cpp \ src/net/common/irccallback.cpp \ - src/net/common/ircthread.cpp \ src/net/common/servermanager.cpp \ src/net/common/transferhelper.cpp \ src/net/common/uploaderthread.cpp \ diff --git a/pokerth_server.pro b/pokerth_server.pro index 5edf750e..7039ced9 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -99,14 +99,18 @@ HEADERS += \ src/gui/qttoolsinterface.h \ src/gui/qt/qttools/nonqttoolswrapper.h \ src/gui/qt/qttools/nonqthelper/nonqthelper.h \ - src/gui/generic/serverguiwrapper.h + src/gui/generic/serverguiwrapper.h \ + src/net/servermanagerirc.h SOURCES += \ src/pokerth_server.cpp \ src/gui/qt/qttools/nonqttoolswrapper.cpp \ src/gui/qt/qttools/nonqthelper/nonqthelper.cpp \ src/net/common/net_helper_server.cpp \ - src/core/common/loghelper_server.cpp + src/core/common/loghelper_server.cpp \ + src/net/common/ircthread.cpp \ + src/net/common/servermanagerirc.cpp \ + src/net/common/servermanagerfactoryserver.cpp LIBS += -lpokerth_lib \ -lpokerth_db \ diff --git a/src/net/common/servermanager.cpp b/src/net/common/servermanager.cpp index 317a5876..85830c77 100644 --- a/src/net/common/servermanager.cpp +++ b/src/net/common/servermanager.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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 ircAdminThread, boost::shared_ptr 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 tcpAcceptHelper(new ServerAcceptHelper(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); } diff --git a/src/net/common/servermanagerfactoryclient.cpp b/src/net/common/servermanagerfactoryclient.cpp new file mode 100644 index 00000000..be81a6ce --- /dev/null +++ b/src/net/common/servermanagerfactoryclient.cpp @@ -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 + +boost::shared_ptr +ServerManagerFactory::CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager) +{ + return boost::shared_ptr(new ServerManager(config, gui, mode, avatarManager)); +} + diff --git a/src/net/common/servermanagerfactoryserver.cpp b/src/net/common/servermanagerfactoryserver.cpp new file mode 100644 index 00000000..16ced557 --- /dev/null +++ b/src/net/common/servermanagerfactoryserver.cpp @@ -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 +#include + +boost::shared_ptr +ServerManagerFactory::CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager) +{ + return boost::shared_ptr(new ServerManagerIrc(config, gui, mode, avatarManager)); +} + + diff --git a/src/net/common/servermanagerirc.cpp b/src/net/common/servermanagerirc.cpp new file mode 100644 index 00000000..c31a23ec --- /dev/null +++ b/src/net/common/servermanagerirc.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +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 tmpIrcAdminThread; + boost::shared_ptr tmpIrcLobbyThread; + ConfigFile &myConfig = GetConfig(); + if (myConfig.readConfigInt("UseAdminIRC")) { + tmpIrcAdminThread = boost::shared_ptr(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(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); +} + diff --git a/src/net/servermanager.h b/src/net/servermanager.h index 8de8f36c..aa3b7a8f 100644 --- a/src/net/servermanager.h +++ b/src/net/servermanager.h @@ -22,8 +22,6 @@ #define _SERVERMANAGER_H_ #include -#include -#include #include #include @@ -31,7 +29,6 @@ #include 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 ircAdminThread, boost::shared_ptr 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 > 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 m_ioService; boost::shared_ptr m_lobbyThread; - boost::shared_ptr m_adminBot; - boost::shared_ptr m_lobbyBot; + +private: + ConfigFile &m_playerConfig; + GuiInterface &m_gui; + AcceptHelperList m_acceptHelperPool; }; diff --git a/src/net/servermanagerfactory.h b/src/net/servermanagerfactory.h new file mode 100644 index 00000000..6bd41c25 --- /dev/null +++ b/src/net/servermanagerfactory.h @@ -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 + +class ServerManagerFactory +{ +public: + static boost::shared_ptr CreateServerManager(ConfigFile &config, GuiInterface &gui, ServerMode mode, AvatarManager &avatarManager); +}; + +#endif // SERVERMANAGERFACTORY_H diff --git a/src/net/servermanagerirc.h b/src/net/servermanagerirc.h new file mode 100644 index 00000000..24b14ae5 --- /dev/null +++ b/src/net/servermanagerirc.h @@ -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 + +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 m_adminBot; + boost::shared_ptr m_lobbyBot; +}; + +#endif diff --git a/src/session.cpp b/src/session.cpp index 59a2b4a2..5e59b68c 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -28,9 +28,8 @@ #include #include #include -#include -#include #include +#include #include @@ -288,34 +287,6 @@ void Session::startNetworkServer(bool dedicated) return; } - myNetServer.reset(new ServerManager(*myGui, *myConfig, *myAvatarManager)); - - boost::shared_ptr tmpIrcAdminThread; - boost::shared_ptr tmpIrcLobbyThread; - if (myConfig->readConfigInt("UseAdminIRC")) { - tmpIrcAdminThread = boost::shared_ptr(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(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();