mxoemu/Reality/Source/MarginServer.cpp

101 lines
2.6 KiB
C++
Raw Permalink Normal View History

// ***************************************************************************
//
// Reality - The Matrix Online Server Emulator
2009-08-11 12:17:38 +00:00
// Copyright (C) 2006-2010 Rajko Stojadinovic
// http://mxoemu.info
2009-08-11 12:17:38 +00:00
//
// ---------------------------------------------------------------------------
2009-08-11 12:17:38 +00:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
2009-08-11 12:17:38 +00:00
//
// 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-08-11 12:17:38 +00:00
//
// ---------------------------------------------------------------------------
2009-08-11 12:17:38 +00:00
//
// ***************************************************************************
2009-08-11 12:17:38 +00:00
#include "Common.h"
#include "MarginServer.h"
#include "MarginSocket.h"
#include "Log.h"
#include "Config.h"
initialiseSingleton( MarginServer );
MarginServer::MarginServer()
{
listenSocketInst = NULL;
}
MarginServer::~MarginServer()
{
if (listenSocketInst != NULL)
{
delete listenSocketInst;
}
}
void MarginServer::Start()
{
string Interface = sConfig.GetStringDefault("MarginServer.IP","0.0.0.0");
2009-08-11 12:17:38 +00:00
int Port = sConfig.GetIntDefault("MarginServer.Port",10000);
2010-02-13 14:32:04 +00:00
INFO_LOG(format("Starting Margin server on port %1%") % Port);
2009-08-11 12:17:38 +00:00
if (listenSocketInst != NULL)
{
delete listenSocketInst;
}
listenSocketInst = new MarginListenSocket(marginSocketHandler);
2010-02-16 06:52:49 +00:00
bool bindFailed=false;
try
{
if (listenSocketInst->Bind(Port)!=0)
bindFailed=true;
}
catch (Exception)
{
bindFailed=true;
}
if (bindFailed)
{
ERROR_LOG(format("Error binding MarginServer to port %1%") % Port);
return;
}
2009-08-11 12:17:38 +00:00
marginSocketHandler.Add(listenSocketInst);
}
void MarginServer::Stop()
{
INFO_LOG("Margin Server shutdown");
if (listenSocketInst != NULL)
{
delete listenSocketInst;
listenSocketInst = NULL;
}
}
void MarginServer::Loop(void)
{
marginSocketHandler.Select(0, 100000);// 100 ms
}
vector<MarginSocket*> MarginServer::GetSocketsForCharacterUID( uint64 charUID )
{
return marginSocketHandler.FindByCharacterUID(charUID);
}
MarginSocket *MarginServer::GetSocketBySessionId( uint32 sessionId )
{
return marginSocketHandler.FindBySessionId(sessionId);
2010-02-16 06:52:49 +00:00
}