2010-08-11 15:23:10 +02:00
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Reality - The Matrix Online Server Emulator
|
2009-08-11 12:17:38 +00:00
|
|
|
// Copyright (C) 2006-2010 Rajko Stojadinovic
|
2010-08-11 15:23:10 +02:00
|
|
|
// http://mxoemu.info
|
2009-08-11 12:17:38 +00:00
|
|
|
//
|
2010-08-11 15:23:10 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
2009-08-11 12:17:38 +00:00
|
|
|
//
|
2010-08-11 15:23:10 +02: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
|
2010-08-11 15:23:10 +02:00
|
|
|
// 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
|
|
|
//
|
2010-08-11 15:23:10 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
2009-08-11 12:17:38 +00:00
|
|
|
//
|
2010-08-11 15:23:10 +02: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()
|
|
|
|
|
{
|
2010-08-31 03:00:04 +02:00
|
|
|
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)
|
|
|
|
|
{
|
2010-02-08 14:51:16 +00:00
|
|
|
marginSocketHandler.Select(0, 100000);// 100 ms
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 17:37:59 +01:00
|
|
|
vector<MarginSocket*> MarginServer::GetSocketsForCharacterUID( uint64 charUID )
|
2010-02-08 14:51:16 +00:00
|
|
|
{
|
|
|
|
|
return marginSocketHandler.FindByCharacterUID(charUID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MarginSocket *MarginServer::GetSocketBySessionId( uint32 sessionId )
|
|
|
|
|
{
|
|
|
|
|
return marginSocketHandler.FindBySessionId(sessionId);
|
2010-02-16 06:52:49 +00:00
|
|
|
}
|