i must test these before calling them good - as gcc isn't on the windows

machine i push, test, fix, and then push again - pvs studio <3
This commit is contained in:
DarthArgus
2016-07-24 20:37:39 -07:00
parent 5217465f67
commit d2c830306f
19 changed files with 7743 additions and 7936 deletions
@@ -13,260 +13,255 @@
using namespace std;
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
namespace NAMESPACE
{
#endif
//----------------------------------------
ServerTrackObject::ServerTrackObject(unsigned mapped_track, unsigned real_track, GenericConnection *con)
: m_mappedTrack(mapped_track), m_realTrack(real_track), m_connection(con)
//----------------------------------------
{
}
//----------------------------------------
ServerTrackObject::ServerTrackObject(unsigned mapped_track, unsigned real_track, GenericConnection *con)
: m_mappedTrack(mapped_track), m_realTrack(real_track), m_connection(con)
//----------------------------------------
{
}
//----------------------------------------
GenericAPICore::GenericAPICore(const char *host,
short port,
unsigned reqTimeout,
unsigned reconnectTimeout,
unsigned noDataTimeoutSecs,
unsigned noAckTimeoutSecs,
unsigned incomingBufSizeInKB,
unsigned outgoingBufSizeInKB,
unsigned keepAlive,
unsigned maxRecvMessageSizeInKB)
: m_currTrack(0),
m_reconnectTimeout(0),
m_outCount(0),
m_pendingCount(0),
m_requestTimeout(reqTimeout),
m_currentConnections(0), m_maxConnections(0),
m_suspended(false),
m_nextConnectionIndex(0)
//----------------------------------------
{
GenericConnection *con = new GenericConnection(host, port, this, reconnectTimeout, noDataTimeoutSecs, noAckTimeoutSecs, incomingBufSizeInKB, outgoingBufSizeInKB, keepAlive, maxRecvMessageSizeInKB);
m_serverConnections.push_back(con);
}
//----------------------------------------
GenericAPICore::GenericAPICore(const char *game, const char *hosts[],
const short port[],
unsigned arraySize,
unsigned reqTimeout,
unsigned reconnectTimeout,
unsigned noDataTimeoutSecs,
unsigned noAckTimeoutSecs,
unsigned incomingBufSizeInKB,
unsigned outgoingBufSizeInKB,
unsigned keepAlive,
unsigned maxRecvMessageSizeInKB)
: m_currTrack(0),
m_reconnectTimeout(0),
m_outCount(0),
m_pendingCount(0),
m_requestTimeout(reqTimeout),
m_currentConnections(0), m_maxConnections(0),
m_suspended(false),
m_nextConnectionIndex(0),
m_game(game)
//----------------------------------------
{
for (unsigned i=0; i<arraySize; i++)
{
GenericConnection *con = new GenericConnection(hosts[i], port[i], this, reconnectTimeout, noDataTimeoutSecs, noAckTimeoutSecs, incomingBufSizeInKB, outgoingBufSizeInKB, keepAlive, maxRecvMessageSizeInKB);
//----------------------------------------
GenericAPICore::GenericAPICore(const char *host,
short port,
unsigned reqTimeout,
unsigned reconnectTimeout,
unsigned noDataTimeoutSecs,
unsigned noAckTimeoutSecs,
unsigned incomingBufSizeInKB,
unsigned outgoingBufSizeInKB,
unsigned keepAlive,
unsigned maxRecvMessageSizeInKB)
: m_currTrack(0),
m_reconnectTimeout(0),
m_outCount(0),
m_pendingCount(0),
m_requestTimeout(reqTimeout),
m_currentConnections(0), m_maxConnections(0),
m_suspended(false),
m_nextConnectionIndex(0)
//----------------------------------------
{
GenericConnection *con = new GenericConnection(host, port, this, reconnectTimeout, noDataTimeoutSecs, noAckTimeoutSecs, incomingBufSizeInKB, outgoingBufSizeInKB, keepAlive, maxRecvMessageSizeInKB);
m_serverConnections.push_back(con);
}
}
//----------------------------------------
GenericAPICore::~GenericAPICore()
//----------------------------------------
{
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
delete con;
}
m_serverConnections.clear();
for(map<unsigned, GenericResponse *>::iterator iter = m_pending.begin(); iter != m_pending.end(); ++iter)
{
delete (*iter).second;
}
m_pending.empty();
while(m_outCount > 0)
//----------------------------------------
GenericAPICore::GenericAPICore(const char *game, const char *hosts[],
const short port[],
unsigned arraySize,
unsigned reqTimeout,
unsigned reconnectTimeout,
unsigned noDataTimeoutSecs,
unsigned noAckTimeoutSecs,
unsigned incomingBufSizeInKB,
unsigned outgoingBufSizeInKB,
unsigned keepAlive,
unsigned maxRecvMessageSizeInKB)
: m_currTrack(0),
m_reconnectTimeout(0),
m_outCount(0),
m_pendingCount(0),
m_requestTimeout(reqTimeout),
m_currentConnections(0), m_maxConnections(0),
m_suspended(false),
m_nextConnectionIndex(0),
m_game(game)
//----------------------------------------
{
delete m_outboundQueue.front().second;
delete m_outboundQueue.front().first;
m_outboundQueue.pop();
--m_outCount;
}
}
//----------------------------------------
unsigned GenericAPICore::submitRequest(GenericRequest *req, GenericResponse *res)
//----------------------------------------
{
++m_outCount;
if(m_currTrack == 0)
{
m_currTrack++;
}
req->setTrack(m_currTrack);
res->setTrack(m_currTrack);
time_t timeout = time(nullptr) + m_requestTimeout;
req->setTimeout(timeout);
res->setTimeout(timeout);
m_outboundQueue.push(pair<GenericRequest *, GenericResponse *>(req, res));
return(m_currTrack++);
}
//----------------------------------------
void GenericAPICore::process()
//----------------------------------------
{
GenericRequest *req;
GenericResponse *res;
if (!m_suspended)
{
// Process timeout on pending requests
while((m_outCount > 0) && ((req = m_outboundQueue.front().first)->getTimeout() <= time(nullptr)))
for (unsigned i = 0; i < arraySize; i++)
{
--m_outCount;
res = m_outboundQueue.front().second;
GenericConnection *con = new GenericConnection(hosts[i], port[i], this, reconnectTimeout, noDataTimeoutSecs, noAckTimeoutSecs, incomingBufSizeInKB, outgoingBufSizeInKB, keepAlive, maxRecvMessageSizeInKB);
m_serverConnections.push_back(con);
}
}
//----------------------------------------
GenericAPICore::~GenericAPICore()
//----------------------------------------
{
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
delete con;
}
m_serverConnections.clear();
for (map<unsigned, GenericResponse *>::iterator iter = m_pending.begin(); iter != m_pending.end(); ++iter)
{
delete (*iter).second;
}
m_pending.clear();
while (m_outCount > 0)
{
delete m_outboundQueue.front().second;
delete m_outboundQueue.front().first;
m_outboundQueue.pop();
responseCallback(res);
delete res;
delete req;
--m_outCount;
}
}
// Process timeout on pending responses
while((m_pendingCount > 0) && ((res = (*m_pending.begin()).second)->getTimeout() <= time(nullptr)))
//----------------------------------------
unsigned GenericAPICore::submitRequest(GenericRequest *req, GenericResponse *res)
//----------------------------------------
{
++m_outCount;
if (m_currTrack == 0)
{
--m_pendingCount;
m_pending.erase(m_pending.begin());
responseCallback(res);
delete res;
m_currTrack++;
}
req->setTrack(m_currTrack);
res->setTrack(m_currTrack);
time_t timeout = time(nullptr) + m_requestTimeout;
while(m_outCount > 0)
req->setTimeout(timeout);
res->setTimeout(timeout);
m_outboundQueue.push(pair<GenericRequest *, GenericResponse *>(req, res));
return(m_currTrack++);
}
//----------------------------------------
void GenericAPICore::process()
//----------------------------------------
{
GenericRequest *req;
GenericResponse *res;
if (!m_suspended)
{
pair<GenericRequest *, GenericResponse *> out_pair = m_outboundQueue.front();
req = out_pair.first;
res = out_pair.second;
GenericConnection *con = nullptr;
if (req->getMappedServerTrack() == 0) // request has no originating "owner" server
// Process timeout on pending requests
while ((m_outCount > 0) && ((req = m_outboundQueue.front().first)->getTimeout() <= time(nullptr)))
{
con = getNextActiveConnection(); // it does not matter which server we send this to
--m_outCount;
res = m_outboundQueue.front().second;
m_outboundQueue.pop();
responseCallback(res);
delete res;
delete req;
}
else
// Process timeout on pending responses
while ((m_pendingCount > 0) && ((res = (*m_pending.begin()).second)->getTimeout() <= time(nullptr)))
{
ServerTrackObject *stobj = findServer(req->getMappedServerTrack());
if (stobj)
--m_pendingCount;
m_pending.erase(m_pending.begin());
responseCallback(res);
delete res;
}
while (m_outCount > 0)
{
pair<GenericRequest *, GenericResponse *> out_pair = m_outboundQueue.front();
req = out_pair.first;
res = out_pair.second;
GenericConnection *con = nullptr;
if (req->getMappedServerTrack() == 0) // request has no originating "owner" server
{
con = stobj->getConnection(); // the server connection to respond to
req->setServerTrack(stobj->getRealServerTrack()); // map server track back to REAL server track
//printf("\nUnmapping %d to %d", stobj->getMappedServerTrack(), req->getMappedServerTrack()); //debug
delete stobj;
con = getNextActiveConnection(); // it does not matter which server we send this to
}
else
{
ServerTrackObject *stobj = findServer(req->getMappedServerTrack());
if (stobj)
{
con = stobj->getConnection(); // the server connection to respond to
req->setServerTrack(stobj->getRealServerTrack()); // map server track back to REAL server track
//printf("\nUnmapping %d to %d", stobj->getMappedServerTrack(), req->getMappedServerTrack()); //debug
delete stobj;
}
}
if (con != nullptr)
{
Base::ByteStream msg;
req->pack(msg);
con->Send(msg);
m_pending.insert(pair<unsigned, GenericResponse *>(res->getTrack(), res));
--m_outCount;
++m_pendingCount;
m_outboundQueue.pop();
delete req;
}
else
{
//no active connections
break; //from while loop
}
}
}
if (con != nullptr)
{
Base::ByteStream msg;
req->pack(msg);
con->Send(msg);
m_pending.insert(pair<unsigned, GenericResponse *>(res->getTrack(), res));
--m_outCount;
++m_pendingCount;
m_outboundQueue.pop();
delete req;
}
else
{
//no active connections
break; //from while loop
}
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
con->process();
}
}
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
con->process();
}
}
//----------------------------------------
GenericConnection *GenericAPICore::getNextActiveConnection()
//----------------------------------------
{
unsigned startIndex = m_nextConnectionIndex;
unsigned maxIndex = m_serverConnections.size() - 1;
GenericConnection *con = nullptr;
//----------------------------------------
GenericConnection *GenericAPICore::getNextActiveConnection()
//----------------------------------------
{
unsigned startIndex = m_nextConnectionIndex;
unsigned maxIndex = m_serverConnections.size() - 1;
//loop until we find an active connection, or until we get back
// to where we started
do
{
if (m_serverConnections[m_nextConnectionIndex]->isConnected())
{
con = m_serverConnections[m_nextConnectionIndex];
if (m_nextConnectionIndex == maxIndex)
m_nextConnectionIndex = 0;
else
m_nextConnectionIndex++;
}
else if (++m_nextConnectionIndex > maxIndex)
{
//went past end of vector, start back at 0
m_nextConnectionIndex = 0;
}
} while (con == nullptr && m_nextConnectionIndex != startIndex);
GenericConnection *con = nullptr;
return con;
}
//loop until we find an active connection, or until we get back
// to where we started
do
{
if (m_serverConnections[m_nextConnectionIndex]->isConnected())
{
con = m_serverConnections[m_nextConnectionIndex];
if (m_nextConnectionIndex == maxIndex)
m_nextConnectionIndex = 0;
else
m_nextConnectionIndex++;
}
else if (++m_nextConnectionIndex > maxIndex)
{
//went past end of vector, start back at 0
m_nextConnectionIndex = 0;
}
}while (con == nullptr && m_nextConnectionIndex != startIndex);
//----------------------------------------
void GenericAPICore::countOpenConnections()
//----------------------------------------
{
m_currentConnections = 0;
m_maxConnections = m_serverConnections.size();
return con;
}
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
if (con->isConnected())
++m_currentConnections;
}
}
//----------------------------------------
void GenericAPICore::countOpenConnections()
//----------------------------------------
{
m_currentConnections = 0;
m_maxConnections = m_serverConnections.size();
for (std::vector<GenericConnection *>::iterator conIter = m_serverConnections.begin(); conIter != m_serverConnections.end(); conIter++)
{
GenericConnection *con = *conIter;
if (con->isConnected())
++m_currentConnections;
}
}
//----------------------------------------
ServerTrackObject *GenericAPICore::findServer(unsigned server_track)
//----------------------------------------
{
std::map<unsigned, ServerTrackObject *>::iterator iter = m_serverTracks.find(server_track);
if (iter == m_serverTracks.end())
return nullptr;
ServerTrackObject *stobj = (*iter).second;
m_serverTracks.erase(server_track);
return stobj;
}
//----------------------------------------
ServerTrackObject *GenericAPICore::findServer(unsigned server_track)
//----------------------------------------
{
std::map<unsigned, ServerTrackObject *>::iterator iter = m_serverTracks.find(server_track);
if (iter == m_serverTracks.end())
return nullptr;
ServerTrackObject *stobj = (*iter).second;
m_serverTracks.erase(server_track);
return stobj;
}
#ifdef EXTERNAL_DISTRO
};
#endif
#endif
@@ -15,187 +15,188 @@
#define GAME_RESOURCE 1
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
namespace NAMESPACE
{
#endif
using namespace std;
using namespace Base;
using namespace std;
using namespace Base;
GenericConnection::GenericConnection(const char *host, short port, GenericAPICore *apiCore, unsigned reconnectTimeout, unsigned noDataTimeoutSecs, unsigned, unsigned incomingBufSizeInKB, unsigned outgoingBufSizeInKB, unsigned keepAlive, unsigned maxRecvMessageSizeInKB)
: m_bConnected(CON_NONE),
m_apiCore(apiCore),
m_con(nullptr),
m_host(host),
m_port(port),
m_conState(CON_DISCONNECT),
m_reconnectTimeout(reconnectTimeout)
{
TcpManager::TcpParams params;
params.incomingBufferSize = incomingBufSizeInKB * 1024;
params.outgoingBufferSize = outgoingBufSizeInKB * 1024;
params.maxConnections = 1;
params.port = 0;
params.maxRecvMessageSize = maxRecvMessageSizeInKB*1024;
params.keepAliveDelay = keepAlive * 1000;
params.noDataTimeout = noDataTimeoutSecs * 1000;
//params.oldestUnacknowledgedTimeout = noAckTimeoutSecs * 1000;
m_manager = new TcpManager(params);
}
GenericConnection::~GenericConnection()
{
if(m_con)
GenericConnection::GenericConnection(const char *host, short port, GenericAPICore *apiCore, unsigned reconnectTimeout, unsigned noDataTimeoutSecs, unsigned, unsigned incomingBufSizeInKB, unsigned outgoingBufSizeInKB, unsigned keepAlive, unsigned maxRecvMessageSizeInKB)
: m_bConnected(CON_NONE),
m_apiCore(apiCore),
m_con(nullptr),
m_host(host),
m_port(port),
m_conState(CON_DISCONNECT),
m_reconnectTimeout(reconnectTimeout),
m_conTimeout(0)
{
m_con->SetHandler(nullptr);
m_con->Disconnect();//don't worry about onterminated being called, we've set it's handler to nullptr, so it wont
m_con->Release();
TcpManager::TcpParams params;
params.incomingBufferSize = incomingBufSizeInKB * 1024;
params.outgoingBufferSize = outgoingBufSizeInKB * 1024;
params.maxConnections = 1;
params.port = 0;
params.maxRecvMessageSize = maxRecvMessageSizeInKB * 1024;
params.keepAliveDelay = keepAlive * 1000;
params.noDataTimeout = noDataTimeoutSecs * 1000;
//params.oldestUnacknowledgedTimeout = noAckTimeoutSecs * 1000;
m_manager = new TcpManager(params);
}
m_manager->Release();
}
void GenericConnection::disconnect()
{
if (m_con)
GenericConnection::~GenericConnection()
{
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
if (m_con)
{
m_con->SetHandler(nullptr);
m_con->Disconnect();//don't worry about onterminated being called, we've set it's handler to nullptr, so it wont
m_con->Release();
}
m_manager->Release();
}
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
void GenericConnection::OnTerminated(TcpConnection *)
{
// m_apiCore->OnDisconnect(m_host.c_str(), m_port);
m_apiCore->OnDisconnect(this);
if(m_con)
void GenericConnection::disconnect()
{
m_con->Release();
m_con = nullptr;
if (m_con)
{
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
}
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
void GenericConnection::OnRoutePacket(TcpConnection *, const unsigned char *data, int dataLen)
{
short type;
unsigned track;
ByteStream msg(data, dataLen);
ByteStream::ReadIterator iter = msg.begin();
get(iter, type);
get(iter, track);
GenericResponse *res = nullptr;
if(track == 0) // notification message from the server, not as a response to a request from this API
void GenericConnection::OnTerminated(TcpConnection *)
{
if (type == ATGAME_REQUEST_CONNECT)
{ // this is a special case, for when we have identified our game code to server
m_bConnected = CON_IDENTIFIED;
m_apiCore->OnConnect(this);
// m_apiCore->OnDisconnect(m_host.c_str(), m_port);
m_apiCore->OnDisconnect(this);
if (m_con)
{
m_con->Release();
m_con = nullptr;
}
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
void GenericConnection::OnRoutePacket(TcpConnection *, const unsigned char *data, int dataLen)
{
short type;
unsigned track;
ByteStream msg(data, dataLen);
ByteStream::ReadIterator iter = msg.begin();
get(iter, type);
get(iter, track);
GenericResponse *res = nullptr;
if (track == 0) // notification message from the server, not as a response to a request from this API
{
if (type == ATGAME_REQUEST_CONNECT)
{ // this is a special case, for when we have identified our game code to server
m_bConnected = CON_IDENTIFIED;
m_apiCore->OnConnect(this);
}
else
{
m_apiCore->responseCallback(type, iter, this);
}
}
else
{
m_apiCore->responseCallback(type, iter, this);
map<unsigned, GenericResponse *>::iterator mapIter = m_apiCore->m_pending.find(track);
if (mapIter != m_apiCore->m_pending.end())
{
res = (*mapIter).second;
iter = msg.begin();
res->unpack(iter);
m_apiCore->responseCallback(res);
m_apiCore->m_pendingCount--;
m_apiCore->m_pending.erase(mapIter);
delete res;
}
}
}
else
void GenericConnection::process()
{
map<unsigned, GenericResponse *>::iterator mapIter = m_apiCore->m_pending.find(track);
if(mapIter != m_apiCore->m_pending.end())
switch (m_conState)
{
res = (*mapIter).second;
iter = msg.begin();
res->unpack(iter);
m_apiCore->responseCallback(res);
m_apiCore->m_pendingCount--;
m_apiCore->m_pending.erase(mapIter);
delete res;
}
}
}
case CON_DISCONNECT:
// create connection object, attempting to connect and
// checking for connection in next state, CON_NEGOTIATE
m_con = m_manager->EstablishConnection(m_host.c_str(), m_port);
if (m_con)
{
m_con->SetHandler(this);
m_conState = CON_NEGOTIATE;
m_conTimeout = time(nullptr) + m_reconnectTimeout;
}
break;
case CON_NEGOTIATE:
// check for connection
void GenericConnection::process()
{
switch(m_conState)
{
case CON_DISCONNECT:
// create connection object, attempting to connect and
// checking for connection in next state, CON_NEGOTIATE
m_con = m_manager->EstablishConnection(m_host.c_str(), m_port);
if(m_con)
{
m_con->SetHandler(this);
m_conState = CON_NEGOTIATE;
m_conTimeout = time(nullptr) + m_reconnectTimeout;
}
break;
case CON_NEGOTIATE:
// check for connection
if (m_con->GetStatus() == TcpConnection::StatusConnected)
{
// we're connected
m_conState = CON_CONNECT;
m_bConnected = CON_CONNECTED;
// instead of calling OnConnect() right now, we are going to submit a connection packet
// identifying us
// m_apiCore->OnConnect(this);
Base::ByteStream msg;
put(msg, (short)REQUEST_SET_API);
put(msg, (unsigned)0); // track
put(msg, (unsigned)API_VERSION_CODE);
put(msg, GAME_RESOURCE); // identify us as a game connection resource
if(m_con->GetStatus() == TcpConnection::StatusConnected)
{
// we're connected
m_conState = CON_CONNECT;
m_bConnected = CON_CONNECTED;
// instead of calling OnConnect() right now, we are going to submit a connection packet
// identifying us
// m_apiCore->OnConnect(this);
Base::ByteStream msg;
put(msg, (short)REQUEST_SET_API);
put(msg, (unsigned)0); // track
put(msg, (unsigned)API_VERSION_CODE);
put(msg, GAME_RESOURCE); // identify us as a game connection resource
// now add in the game identifiers
put(msg, (unsigned)m_apiCore->m_gameIdentifiers.size()); // number of strings to read
for(unsigned index = 0; index < m_apiCore->m_gameIdentifiers.size(); index++)
put(msg, std::string(m_apiCore->m_gameIdentifiers[index]));
Send(msg);
}
else if(time(nullptr) > m_conTimeout)
{
// we did not connect
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
// now add in the game identifiers
put(msg, (unsigned)m_apiCore->m_gameIdentifiers.size()); // number of strings to read
for (unsigned index = 0; index < m_apiCore->m_gameIdentifiers.size(); index++)
put(msg, std::string(m_apiCore->m_gameIdentifiers[index]));
Send(msg);
}
else if (time(nullptr) > m_conTimeout)
{
// we did not connect
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
break;
case CON_CONNECT:
// do nothing
break;
default:
// this should not occur, but we revert to CON_DISCONNECT if it does
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
}
break;
case CON_CONNECT:
// do nothing
break;
default:
// this should not occur, but we revert to CON_DISCONNECT if it does
m_conState = CON_DISCONNECT;
m_bConnected = CON_NONE;
if (m_con)
{
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
m_bConnected = CON_NONE;
if (m_con)
{
m_con->Disconnect();
//no need to release, since callback to onTerminated releases it, and callback is allways made m_con->Release();
m_con = nullptr;
}
}
m_manager->GiveTime();
}
m_manager->GiveTime();
}
void GenericConnection::Send(Base::ByteStream &msg)
{
if(m_con && m_con->GetStatus() == TcpConnection::StatusConnected)
void GenericConnection::Send(Base::ByteStream &msg)
{
m_con->Send((const char *)msg.getBuffer(), msg.getSize());
if (m_con && m_con->GetStatus() == TcpConnection::StatusConnected)
{
m_con->Send((const char *)msg.getBuffer(), msg.getSize());
}
}
}
#ifdef EXTERNAL_DISTRO
};
#endif
#endif
@@ -9,36 +9,35 @@
//----------------------------------------
#ifdef EXTERNAL_DISTRO
namespace NAMESPACE
namespace NAMESPACE
{
#endif
using namespace Base;
using namespace Base;
//-------------------------------------------
GenericRequest::GenericRequest(short type, unsigned server_track)
: m_type(type), m_server_track(server_track)
//-------------------------------------------
{
}
//-------------------------------------------
GenericRequest::GenericRequest(short type, unsigned server_track)
: m_type(type), m_server_track(server_track), m_track(0), m_timeout(0)
//-------------------------------------------
{
}
//-------------------------------------------
GenericResponse::GenericResponse(short type, unsigned result, void *user)
: m_type(type), m_result(result), m_user(user)
//-------------------------------------------
{
}
//-------------------------------------------
GenericResponse::GenericResponse(short type, unsigned result, void *user)
: m_type(type), m_result(result), m_user(user), m_track(0), m_timeout(0)
//-------------------------------------------
{
}
//-----------------------------------------
void GenericResponse::unpack(ByteStream::ReadIterator &iter)
//-----------------------------------------
{
get(iter, m_type);
get(iter, m_track);
get(iter, m_result);
}
//-----------------------------------------
void GenericResponse::unpack(ByteStream::ReadIterator &iter)
//-----------------------------------------
{
get(iter, m_type);
get(iter, m_track);
get(iter, m_result);
}
#ifdef EXTERNAL_DISTRO
};
#endif
#endif
@@ -16,28 +16,27 @@ class StructureListMessage;
#define DECLARE_CS_CMD( _name ) void handle_##_name( GameServerCSRequestMessage & message );
class CentralCSHandler
{
public:
static void install();
static void remove();
static CentralCSHandler & getInstance();
void handle( const CSToolRequest& msg, uint32 loginServerId );
void handle(const CSToolRequest& msg, uint32 loginServerId);
~CentralCSHandler();
void handleFindObjectResponse( int iIndex, bool bFound );
void handleStructureListResponse( StructureListMessage& msg );
void handleFindObjectResponse(int iIndex, bool bFound);
void handleStructureListResponse(StructureListMessage& msg);
// only need to DECLARE_CS_CMD for commands handled at the CentralServer.
DECLARE_CS_CMD( list_structures );
DECLARE_CS_CMD( login_character );
DECLARE_CS_CMD( warp_player );
DECLARE_CS_CMD(list_structures);
DECLARE_CS_CMD(login_character);
DECLARE_CS_CMD(warp_player);
protected:
static CentralCSHandler * smp_instance;
typedef void( CentralCSHandler::*CentralCSHandlerFunc )( GameServerCSRequestMessage & );
typedef void(CentralCSHandler::*CentralCSHandlerFunc)(GameServerCSRequestMessage &);
class HandlerEntry
{
@@ -52,75 +51,70 @@ protected:
TYPE_ARBITRARY_GAME_SERVER // send to a game server, we don't care which one. This is used
// if all game servers have what we're looking for, so we don't care who gets it.
};
HandlerEntry( const std::string & in_name, CentralCSHandlerFunc in_func, EntryType in_type ) :
name( in_name ),
type( in_type ),
func( in_func )
HandlerEntry(const std::string & in_name, CentralCSHandlerFunc in_func, EntryType in_type) :
name(in_name),
type(in_type),
func(in_func)
{
}
HandlerEntry( const std::string & in_name, EntryType in_type ) :
name(in_name),
type( in_type )
HandlerEntry(const std::string & in_name, EntryType in_type) :
name(in_name),
type(in_type),
func(nullptr)
{
}
std::string name;
EntryType type;
CentralCSHandlerFunc func; // will be nullptr unless it's of TYPE_CENTRAL.
};
class CSCharacterFindInfo
{
public:
CSCharacterFindInfo( NetworkId & id, int numServers, GameServerCSRequestMessage &req, bool bHandleAtCentral ) :
commandLine( req.getCommandString() ),
command( req.getCommandName() ),
iAccessLevel( req.getAccessLevel() ),
user(req.getUserName() ),
iToolId( req.getToolId() ),
iAccount( req.getAccountId() ),
responsesWaiting( numServers ),
iLoginServerId( req.getLoginServerID() ),
bCentral( bHandleAtCentral )
CSCharacterFindInfo(NetworkId & id, int numServers, GameServerCSRequestMessage &req, bool bHandleAtCentral) :
commandLine(req.getCommandString()),
command(req.getCommandName()),
iAccessLevel(req.getAccessLevel()),
user(req.getUserName()),
iToolId(req.getToolId()),
iAccount(req.getAccountId()),
responsesWaiting(numServers),
iLoginServerId(req.getLoginServerID()),
bCentral(bHandleAtCentral)
{
}
std::string commandLine;
std::string command;
uint32 iAccessLevel;
std::string user;
uint32 iToolId;
int iAccount;
int responsesWaiting;
int responsesWaiting;
int iLoginServerId;
bool bCentral; // if offline, should we handle this at the Central Server or the DB?
protected:
};
typedef std::map< int, CSCharacterFindInfo * > CentralCharFindMap;
CentralCharFindMap m_findMap;
typedef std::map< std::string, HandlerEntry * > CentralCSHandlerMap;
CentralCSHandlerMap m_entries;
private:
CentralCSHandler() :
m_findMap(),
m_entries()
m_findMap(),
m_entries()
{
};
};
@@ -1,8 +1,6 @@
// ConnectionServerConnection.cpp
// copyright 2001 Verant Interactive
//-----------------------------------------------------------------------
#include "FirstCentralServer.h"
@@ -40,48 +38,50 @@ struct OnConnectionServerConnectionClosed {};
//-----------------------------------------------------------------------
ConnectionServerConnection::ConnectionServerConnection(const std::string & a, const uint16 p) :
ServerConnection (a, p, NetworkSetupData()),
m_chatServicePort (0),
m_csServicePort (0),
m_clientServicePortPrivate (0),
m_clientServicePortPublic (0),
m_gameServicePort (0),
m_id (0),
m_pingPort (0),
m_connectionServerNumber (0),
m_gameServiceAddress (),
m_playerCount (0),
m_freeTrialCount (0),
m_emptySceneCount (0),
m_tutorialSceneCount (0),
m_falconSceneCount (0),
m_clientServiceAddress (),
m_chatServiceAddress (),
m_customerServiceAddress ()
ServerConnection(a, p, NetworkSetupData()),
m_chatServicePort(0),
m_csServicePort(0),
m_clientServicePortPrivate(0),
m_clientServicePortPublic(0),
m_gameServicePort(0),
m_id(0),
m_pingPort(0),
m_connectionServerNumber(0),
m_gameServiceAddress(),
m_playerCount(0),
m_freeTrialCount(0),
m_emptySceneCount(0),
m_tutorialSceneCount(0),
m_falconSceneCount(0),
m_clientServiceAddress(),
m_chatServiceAddress(),
m_customerServiceAddress(),
m_voiceChatServicePort(0)
{
}
//-----------------------------------------------------------------------
ConnectionServerConnection::ConnectionServerConnection(UdpConnectionMT * u, TcpClient * t) :
ServerConnection (u, t),
m_chatServicePort (0),
m_csServicePort (0),
m_clientServicePortPrivate (0),
m_clientServicePortPublic (0),
m_gameServicePort (0),
m_id (0),
m_pingPort (0),
m_connectionServerNumber (0),
m_gameServiceAddress (),
m_playerCount (0),
m_freeTrialCount (0),
m_emptySceneCount (0),
m_tutorialSceneCount (0),
m_falconSceneCount (0),
m_clientServiceAddress (),
m_chatServiceAddress (),
m_customerServiceAddress ()
ServerConnection(u, t),
m_chatServicePort(0),
m_csServicePort(0),
m_clientServicePortPrivate(0),
m_clientServicePortPublic(0),
m_gameServicePort(0),
m_id(0),
m_pingPort(0),
m_connectionServerNumber(0),
m_gameServiceAddress(),
m_playerCount(0),
m_freeTrialCount(0),
m_emptySceneCount(0),
m_tutorialSceneCount(0),
m_falconSceneCount(0),
m_clientServiceAddress(),
m_chatServiceAddress(),
m_customerServiceAddress(),
m_voiceChatServicePort(0)
{
}
@@ -89,12 +89,12 @@ m_customerServiceAddress ()
ConnectionServerConnection::~ConnectionServerConnection()
{
// remove ConnectionServerConnection *'s from the
// remove ConnectionServerConnection *'s from the
// s_pseudoClientConnectionMap
std::map<unsigned int, std::pair<TransferRequestMoveValidation::TransferRequestSource, ConnectionServerConnection *> >::iterator i;
for(i = s_pseudoClientConnectionMap.begin(); i != s_pseudoClientConnectionMap.end();)
for (i = s_pseudoClientConnectionMap.begin(); i != s_pseudoClientConnectionMap.end();)
{
if(i->second.second == this)
if (i->second.second == this)
{
if (i->second.first == TransferRequestMoveValidation::TRS_transfer_server)
{
@@ -121,7 +121,7 @@ bool ConnectionServerConnection::sendToPseudoClientConnection(unsigned int stati
{
bool result = false;
std::map<unsigned int, std::pair<TransferRequestMoveValidation::TransferRequestSource, ConnectionServerConnection *> >::iterator f = s_pseudoClientConnectionMap.find(stationId);
if(f != s_pseudoClientConnectionMap.end())
if (f != s_pseudoClientConnectionMap.end())
{
result = true;
f->second.second->send(message, true);
@@ -166,9 +166,9 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
{
Archive::ReadIterator ri = message.begin();
GameNetworkMessage m(ri);
ri = message.begin();
ri = message.begin();
if(m.isType("NewCentralConnectionServer"))
if (m.isType("NewCentralConnectionServer"))
{
const NewCentralConnectionServer ncs(ri);
@@ -178,7 +178,7 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
m_clientServicePortPrivate = ncs.getClientServicePortPrivate();
m_clientServicePortPublic = ncs.getClientServicePortPublic();
m_gameServicePort = ncs.getGameServicePort();
m_pingPort = ncs.getPingPort ();
m_pingPort = ncs.getPingPort();
m_connectionServerNumber = ncs.getConnectionServerNumber();
m_gameServiceAddress = ncs.getGameServiceAddress();
m_clientServiceAddress = ncs.getClientServiceAddress();
@@ -207,8 +207,8 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
//Send to CS servers
const EnumerateServers e2(true, getCustomerServiceAddress(), getCustomerServicePort(), ct);
if ( !getCustomerServiceAddress().empty()
&& (getCustomerServicePort() != 0))
if (!getCustomerServiceAddress().empty()
&& (getCustomerServicePort() != 0))
{
CentralServer::getInstance().broadcastToCustomerServiceServers(e2);
}
@@ -218,10 +218,10 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
}
//Send to login Servers
if ( (getClientServicePortPrivate() != 0) || (getClientServicePortPublic() != 0) )
if ((getClientServicePortPrivate() != 0) || (getClientServicePortPublic() != 0))
{
const LoginConnectionServerAddress csa(m_id, getClientServiceAddress(), getClientServicePortPrivate(),
getClientServicePortPublic(), getPlayerCount(), getPingPort ());
getClientServicePortPublic(), getPlayerCount(), getPingPort());
CentralServer::getInstance().sendToAllLoginServers(csa);
}
}
@@ -235,12 +235,12 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
CentralServer::getInstance().sendToAllLoginServers(ulc);
}
else if(m.isType("TaskSpawnProcess"))
else if (m.isType("TaskSpawnProcess"))
{
const TaskSpawnProcess spawn(ri);
CentralServer::getInstance().sendTaskMessage(spawn);
}
else if(m.isType("NewPseudoClientConnection"))
else if (m.isType("NewPseudoClientConnection"))
{
const GenericValueTypeMessage<std::pair<unsigned int, int8> > info(ri);
s_pseudoClientConnectionMap[info.getValue().first] = std::make_pair(static_cast<TransferRequestMoveValidation::TransferRequestSource>(info.getValue().second), this);
@@ -248,20 +248,20 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
// remove corresponding "non pseudo client connection"
CentralServer::getInstance().removeFromAccountConnectionMap(static_cast<StationId>(info.getValue().first));
}
else if(m.isType("DestroyPseudoClientConnection"))
else if (m.isType("DestroyPseudoClientConnection"))
{
const GenericValueTypeMessage<unsigned int> info(ri);
std::map<unsigned int, std::pair<TransferRequestMoveValidation::TransferRequestSource, ConnectionServerConnection *> >::iterator f = s_pseudoClientConnectionMap.find(info.getValue());
if(f != s_pseudoClientConnectionMap.end())
if (f != s_pseudoClientConnectionMap.end())
{
s_pseudoClientConnectionMap.erase(f);
}
}
else if(m.isType("TransferReceiveDataFromGameServer"))
else if (m.isType("TransferReceiveDataFromGameServer"))
{
const GenericValueTypeMessage<TransferCharacterData> transferReply(ri);
if(transferReply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (transferReply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(transferReply);
}
@@ -275,7 +275,7 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
LOG("CustomerService", ("CharacterTransfer: Sending TransferLoginCharacterToDestinationServer to CentralServer (via LoginServer) (%s) for (%s)", transferReply.getValue().getDestinationGalaxy().c_str(), login.getValue().toString().c_str()));
}
}
else if(m.isType("ApplyTransferDataSuccess"))
else if (m.isType("ApplyTransferDataSuccess"))
{
const GenericValueTypeMessage<TransferCharacterData> success(ri);
@@ -290,7 +290,7 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
// send the message back to the transfer server, which then
// sends a disable login request to the source central server,
// "removing" the account on the source galaxy.
if(success.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (success.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(success);
}
@@ -303,14 +303,14 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(toggleLoginStatus));
}
}
else if(m.isType("ApplyTransferDataFail"))
else if (m.isType("ApplyTransferDataFail"))
{
const GenericValueTypeMessage<TransferCharacterData> fail(ri);
// send the message back to the transfer server, which then
// sends a delete request to the destination central server,
// "removing" the account on the destination galaxy.
if(fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(fail);
}
@@ -329,11 +329,11 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget));
}
}
else if(m.isType("TransferCreateCharacterFailed"))
else if (m.isType("TransferCreateCharacterFailed"))
{
const GenericValueTypeMessage<TransferCharacterData> fail(ri);
if(fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(fail);
}
@@ -348,11 +348,11 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget));
}
}
else if(m.isType("ReplyTransferDataFail"))
else if (m.isType("ReplyTransferDataFail"))
{
const GenericValueTypeMessage<TransferCharacterData> reply(ri);
if(reply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (reply.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(reply);
}
@@ -367,11 +367,11 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget));
}
}
else if(m.isType("TransferFailGameServerClosedConnectionWithConnectionServer"))
else if (m.isType("TransferFailGameServerClosedConnectionWithConnectionServer"))
{
const GenericValueTypeMessage<TransferCharacterData> fail(ri);
if(fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
if (fail.getValue().getTransferRequestSource() == TransferRequestMoveValidation::TRS_transfer_server)
{
CentralServer::getInstance().sendToTransferServer(fail);
}
@@ -386,12 +386,12 @@ void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
IGNORE_RETURN(CentralServer::getInstance().sendToArbitraryLoginServer(closeRequestTarget));
}
}
else if(m.isType("AccountFeatureIdRequest"))
else if (m.isType("AccountFeatureIdRequest"))
{
const AccountFeatureIdRequest msg(ri);
CentralServer::getInstance().sendToArbitraryLoginServer(msg);
}
else if(m.isType("AdjustAccountFeatureIdRequest"))
else if (m.isType("AdjustAccountFeatureIdRequest"))
{
const AdjustAccountFeatureIdRequest msg(ri);
CentralServer::getInstance().sendToArbitraryLoginServer(msg);
@@ -408,7 +408,7 @@ ConnectionServerConnection * ConnectionServerConnection::getConnectionForAccount
{
ConnectionServerConnection * result = 0;
std::map<unsigned int, std::pair<TransferRequestMoveValidation::TransferRequestSource, ConnectionServerConnection *> >::iterator f = s_pseudoClientConnectionMap.find(stationId);
if(f != s_pseudoClientConnectionMap.end())
if (f != s_pseudoClientConnectionMap.end())
{
result = f->second.second;
}
@@ -424,4 +424,4 @@ void ConnectionServerConnection::removeFromAccountConnectionMap(unsigned int sta
{
s_pseudoClientConnectionMap.erase(f);
}
}
}
@@ -223,7 +223,7 @@ bool ConnectionServer::decryptToken(const KeyShare::Token & token, char* session
uint32 len = apiSessionIdWidth + sizeof(StationId);
unsigned char * keyBuffer = new unsigned char[len + 1];
unsigned char * keyBufferPointer = keyBuffer;
memset(keyBuffer, 0, len);
memset(keyBuffer, 0, sizeof(*keyBuffer));
bool retval = cs.loginServerKeys->decipherToken(token, keyBuffer, len);