2007-11-16 22:34:38 +00:00
|
|
|
/***************************************************************************
|
2010-10-11 20:57:23 +00:00
|
|
|
* Copyright (C) 2007-2010 by Lothar May *
|
2007-11-16 22:34:38 +00:00
|
|
|
* *
|
|
|
|
|
* 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. *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2008-04-16 20:38:11 +00:00
|
|
|
#include <net/socket_helper.h>
|
2007-11-16 22:34:38 +00:00
|
|
|
#include <net/servermanager.h>
|
|
|
|
|
#include <net/serverlobbythread.h>
|
2009-05-10 22:21:20 +00:00
|
|
|
#include <net/serveraccepthelper.h>
|
2007-11-16 22:34:38 +00:00
|
|
|
#include <net/serverexception.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
|
|
|
|
#include <net/socket_startup.h>
|
|
|
|
|
#include <core/loghelper.h>
|
|
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
ServerManager::ServerManager(GuiInterface &gui, ConfigFile *config, AvatarManager &avatarManager)
|
|
|
|
|
: m_gui(gui), m_playerConfig(config), m_avatarManager(avatarManager)
|
|
|
|
|
{
|
2009-06-14 22:07:41 +00:00
|
|
|
m_ioService.reset(new boost::asio::io_service);
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot.reset(new ServerAdminBot);
|
|
|
|
|
m_lobbyBot.reset(new ServerLobbyBot);
|
2007-11-16 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerManager::~ServerManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-11-08 09:48:01 +00:00
|
|
|
ServerManager::Init(unsigned serverPort, bool ipv6, ServerTransportProtocol proto, ServerMode mode, const string &logDir, boost::shared_ptr<IrcThread> ircAdminThread, boost::shared_ptr<IrcThread> ircLobbyThread)
|
2007-11-16 22:34:38 +00:00
|
|
|
{
|
2009-11-08 09:48:01 +00:00
|
|
|
m_lobbyThread.reset(new ServerLobbyThread(GetGui(), mode, *m_lobbyBot, m_playerConfig, m_avatarManager, m_ioService));
|
|
|
|
|
GetLobbyThread().Init(logDir);
|
2007-11-16 22:34:38 +00:00
|
|
|
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot->Init(m_lobbyThread, ircAdminThread);
|
|
|
|
|
m_lobbyBot->Init(m_lobbyThread, ircLobbyThread);
|
2009-08-20 11:02:05 +00:00
|
|
|
|
2009-11-08 09:48:01 +00:00
|
|
|
if (proto & TRANSPORT_PROTOCOL_TCP)
|
2007-11-16 22:34:38 +00:00
|
|
|
{
|
2009-05-10 22:21:20 +00:00
|
|
|
boost::shared_ptr<ServerAcceptHelper> tcpAcceptHelper(new ServerAcceptHelper(GetGui(), m_ioService));
|
2009-09-26 16:05:35 +00:00
|
|
|
tcpAcceptHelper->Listen(serverPort, ipv6, false, logDir, m_lobbyThread);
|
2009-05-10 22:21:20 +00:00
|
|
|
m_acceptHelperPool.push_back(tcpAcceptHelper);
|
2007-11-16 22:34:38 +00:00
|
|
|
}
|
2009-11-08 09:48:01 +00:00
|
|
|
// TODO: Re-add SCTP support once asio supports SCTP.
|
|
|
|
|
/* if (mode & TRANSPORT_PROTOCOL_SCTP)
|
2007-11-16 22:34:38 +00:00
|
|
|
{
|
2009-05-10 22:21:20 +00:00
|
|
|
boost::shared_ptr<ServerAcceptHelper> sctpAcceptHelper(new ServerAcceptHelper(GetGui(), m_ioService));
|
2009-09-26 16:05:35 +00:00
|
|
|
sctpAcceptHelper->Listen(serverPort, ipv6, true, logDir, m_lobbyThread);
|
2009-05-10 22:21:20 +00:00
|
|
|
m_acceptHelperPool.push_back(sctpAcceptHelper);
|
2009-07-22 20:26:29 +00:00
|
|
|
}*/
|
2007-11-16 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GuiInterface &
|
|
|
|
|
ServerManager::GetGui()
|
|
|
|
|
{
|
|
|
|
|
return m_gui;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-20 15:19:41 +00:00
|
|
|
ServerAdminBot &
|
|
|
|
|
ServerManager::GetAdminBot()
|
2007-11-16 22:34:38 +00:00
|
|
|
{
|
2009-08-20 15:19:41 +00:00
|
|
|
return *m_adminBot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerLobbyBot &
|
|
|
|
|
ServerManager::GetLobbyBot()
|
|
|
|
|
{
|
|
|
|
|
return *m_lobbyBot;
|
2007-11-16 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ServerManager::RunAll()
|
|
|
|
|
{
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot->Run();
|
|
|
|
|
m_lobbyBot->Run();
|
2007-11-16 22:34:38 +00:00
|
|
|
GetLobbyThread().Run();
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-02 21:25:42 +00:00
|
|
|
void
|
|
|
|
|
ServerManager::Process()
|
|
|
|
|
{
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot->Process();
|
|
|
|
|
m_lobbyBot->Process();
|
2008-11-02 21:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-16 22:34:38 +00:00
|
|
|
void
|
|
|
|
|
ServerManager::SignalTerminationAll()
|
|
|
|
|
{
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot->SignalTermination();
|
|
|
|
|
m_lobbyBot->SignalTermination();
|
2007-11-16 22:34:38 +00:00
|
|
|
GetLobbyThread().SignalTermination();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
ServerManager::JoinAll(bool wait)
|
|
|
|
|
{
|
2009-08-20 15:19:41 +00:00
|
|
|
m_adminBot->Join(wait);
|
|
|
|
|
m_lobbyBot->Join(wait);
|
2009-05-10 14:57:51 +00:00
|
|
|
return GetLobbyThread().Join(wait ? NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC : 0);
|
2007-11-16 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerLobbyThread &
|
|
|
|
|
ServerManager::GetLobbyThread()
|
|
|
|
|
{
|
|
|
|
|
assert(m_lobbyThread.get());
|
|
|
|
|
return *m_lobbyThread;
|
|
|
|
|
}
|
|
|
|
|
|