Added MonAPI2

This commit is contained in:
Anonymous
2014-01-16 14:41:17 -07:00
parent bb542af614
commit 138826b6d6
9 changed files with 1962 additions and 0 deletions
@@ -84,11 +84,31 @@ endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCommandParser/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCompression/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDatabaseInterface/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedGame/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMessageDispatch/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetworkMessages/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedSynchronization/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public
${SWG_ENGINE_SOURCE_DIR}/server/library/serverKeyShare/include/public
${SWG_ENGINE_SOURCE_DIR}/server/library/serverNetworkMessages/include/public
${SWG_ENGINE_SOURCE_DIR}/server/library/serverUtility/include/public
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include
${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/projects
${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/utils
)
add_executable(LoginServer
+1
View File
@@ -1,2 +1,3 @@
add_subdirectory(MonAPI2)
add_subdirectory(Session)
@@ -0,0 +1,12 @@
include_directories(
${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/udplibrary
${ZLIB_INCLUDE_DIR}
)
add_library(MonAPI2
MonitorAPI.cpp
MonitorAPI.h
MonitorData.cpp
MonitorData.h
)
@@ -0,0 +1,642 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "zlib.h"
#include "MonitorAPI.h"
// **********************************************************************************************
// **********************************************************************************************
// ********************************** DO NOT EDIT THIS FILE ***********************************
// **********************************************************************************************
// **********************************************************************************************
void set_bit( unsigned char p[], int bit){ p[bit >> 3] |= 1 << (bit & 0x7); }
void unset_bit(unsigned char p[], int bit){ p[bit >> 3] &= ~(1 << (bit & 0x7)); }
int get_bit( unsigned char p[], int bit){ return (p[bit >> 3] >> (bit & 0x7)) & 1; }
int ZEXPORT uncompress2( Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
////////////////////////////////////////
// Player implementation
////////////////////////////////////////
MonitorObject::MonitorObject(UdpConnection *con,CMonitorData *_gamedata, char *passwd, char **addressList,bool _bprint)
{
mbprint = _bprint;
mMonitorData = _gamedata;
mbAuthenticated = false;
mPasswd = passwd;
mAddressList = addressList;
mHierarchySent = false;
mSequence = 1;
mlastUpdateTime = 0;
mConnection = con;
mConnection->AddRef();
mConnection->SetHandler(this);
// Flag all the descriptions
mMark = new unsigned char [ (mMonitorData->DataMax()/8)+2];
memset(mMark,0,(mMonitorData->DataMax()/8)+2);
char hold[256];
if( mbprint )
{
fprintf(stderr,"MONITOR API CONNECTED: %s:%d\n",
mConnection->GetDestinationIp().GetAddress(hold),
mConnection->GetDestinationPort());
}
}
MonitorObject::~MonitorObject()
{
if( mMark )
delete [] mMark;
if( mConnection )
{
mConnection->SetHandler(NULL);
mConnection->Disconnect();
mConnection->Release();
}
}
void MonitorObject::OnTerminated( UdpConnection * /* con */)
{
char hold[214];
if( mConnection )
{
if( mbprint )
{
mConnection->GetDestinationIp().GetAddress(hold);
if( mbprint )
{
fprintf(stderr,"MONITOR API TERMINATE %s:%d %s - %s\n",
hold,
mConnection->GetDestinationPort(),
UdpConnection::DisconnectReasonText( mConnection->GetDisconnectReason()),
UdpConnection::DisconnectReasonText( mConnection->GetOtherSideDisconnectReason()));
}
}
mConnection->SetHandler(NULL);
mConnection->Disconnect();
mConnection->Release();
mConnection = NULL;
}
}
void MonitorObject::OnRoutePacket( UdpConnection * con, const unsigned char *data, int dataLen)
{
if( dataLen < 6 )
{
if( mbprint )
fprintf(stderr,"MONITOR API: This should not happen, line %d\n",__LINE__);
}
simpleMessage msg(data);
if( con == NULL )
{
if( mbprint)
fprintf(stderr,"MONITOR API: MonitorObject.OnRoutePacket, recived a NULL connection.?\n");
return;
}
// ************************* Login Process ***************************
if ( mbAuthenticated == false )
{
if ( msg.getCommand() != MON_MSG_AUTH )
return;
if( processAuthRequest(data, dataLen) == false )
return;
mbAuthenticated = true;
return;
}
// ************************* Process Commands ***********************
switch(msg.getCommand())
{
// *********************** Game Server Processing ******************
case MON_MSG_QUERY_ELEMENTS:
if( mHierarchySent == true )
{
mMonitorData->processElementsRequest(con,mSequence,(char *)&data[6],dataLen,mlastUpdateTime );
mlastUpdateTime = (long)time(NULL);
break;
}
// When the hierarchy has changed, fall through
case MON_MSG_QUERY_HIERARCHY_BLOCK:
if( mMonitorData->processHierarchyRequestBlock(con,mSequence) == false)
{
break;
}
mHierarchySent = true;
break;
case MON_MSG_QUERY_DESCRIPTION:
mMonitorData->processDescriptionRequest(con,mSequence,(char *)&data[6], dataLen,mMark);
break;
case MON_MSG_ERROR:
processError(data);
break;
default:
fprintf(stderr,"MONITOR API: unknown message type received from client [%x]\n",msg.getCommand());
break;
}
}
bool MonitorObject::checkAddress(const char * address)
{
int x = 0;
while( mAddressList[x] )
{
if (strncmp(mAddressList[x], address, strlen(mAddressList[x]))== 0)
return true;
x++;
}
return false;
}
bool MonitorObject::checkPasswd( const char *passwd)
{
if (strcmp(mPasswd,passwd)== 0 )
return true;
return false;
}
bool MonitorObject::processAuthRequest(const unsigned char * data, int /* dataLen */)
{
char reply;
stringMessage strMsg(data);
char addBuff[16] = {0};
char sendBuf[32];
int len;
reply = '1';
if ( checkAddress(mConnection->GetDestinationIp().GetAddress(addBuff)) == false)
{
reply = '3';
}
else if (checkPasswd(strMsg.getData()) == false)
{
reply = '2';
}
memset(sendBuf, 0, sizeof(sendBuf));
len = 0;
packShort( sendBuf + len, len,(short)MON_MSG_AUTHREPLY);
packShort( sendBuf + len, len, mSequence);
packShort( sendBuf + len, len,(short)3);
packShort( sendBuf + len, len,(short)CURRENT_API_VERSION);
packByte( sendBuf + len, len, reply);
mConnection->Send(cUdpChannelReliable1, sendBuf, 9 );
return true;
}
void MonitorObject::DescriptionMark(int x,int mode)
{
if( mode == 0 ) set_bit(mMark,x); else unset_bit(mMark,x);
}
char * getErrorString(unsigned short errorCode)
{
if (errorCode == 0)
{
return "none";
}
else
{
switch (errorCode)
{
case INVALID_HEADER:
case INVALID_SEQUENCE:
case INVALID_MSG_LENGTH:
case INVALID_MSG_TYPE:
return "Invalid message";
case INVALID_AUTH_REQUEST:
return "Invalid authorization request";
case INVALID_ELEMENT_REQUEST:
case INVALID_HIERARCHY_REQUEST:
return "Invalid data request";
case INVALID_AUTH_REPLY:
return "Invalid reply to authentication request";
case INVALID_ELEMENT_REPLY:
case INVALID_HIERARCHY_REPLY:
return "Badly formatted data in dataReplyMessage";
case INVALID_ERROR_CODE:
return "Received invalid error message";
}
}
return "Undefined error code";
}
bool MonitorObject::processError(const unsigned char * data)
{
stringMessage strMsg(data);
unsigned short errCode = (unsigned short)atoi(strMsg.getData());
fprintf(stderr,"MONITOR API Error: %s\n", getErrorString(errCode));
return true;
}
///////////////////////////////////////
// MonitorManager implementation
////////////////////////////////////////
MonitorManager::MonitorManager(const char *configFile, CMonitorData *_gamedata, UdpManager *manager, bool _bprint)
{
mManager = manager;
mbprint = _bprint;
passString = NULL;
mMonitorData = _gamedata;
mObjectCount = 0;
for(int x=0;x<AUTHADDRESS_MAX;x++)
allowedAddressList[x] = 0;
loadAuthData(configFile);
}
MonitorManager::~MonitorManager()
{
int x;
x=0;
while( allowedAddressList[x])
free(allowedAddressList[x++]);
if( passString )
free( passString );
for (int i =0; i < mObjectCount; i++ )
delete mObject[i];
}
void MonitorManager::OnConnectRequest(UdpConnection *con)
{
if( mObjectCount == CONNECTION_MAX )
{
if( con )
{
con->SetHandler(NULL);
con->Disconnect();
con->Release();
}
if( mbprint )
fprintf(stderr,"MonitorAPI: Collector connection reached max (%d).\n",CONNECTION_MAX);
return;
}
AddObject(new MonitorObject(con,mMonitorData,passString,allowedAddressList,mbprint));
}
void MonitorManager::AddObject(MonitorObject *Object)
{
mObject[mObjectCount++] = Object;
}
void MonitorManager::GiveTime()
{
// check if the monitor object is no longer connected
for (int i = 0; i < mObjectCount; i++)
{
if( mObject[i]->mConnection == NULL ||
mObject[i]->mConnection->GetStatus() == UdpConnection::cStatusDisconnected )
{
MonitorObject *o = mObject[i];
mObjectCount--;
memmove(&mObject[i], &mObject[i + 1], (mObjectCount - i) * sizeof(MonitorObject *));
i--;
delete o;
}
}
}
void MonitorManager::HierarchyChanged()
{
for (int i = 0; i < mObjectCount; i++)
mObject[i]->HeirarchyChanged();
}
void MonitorManager::DescriptionMark(int x ,int mode)
{
for (int i = 0; i < mObjectCount; i++)
mObject[i]->DescriptionMark(x,mode);
}
bool MonitorManager::loadAuthData(const char * filename)
{
int nline;
int len;
int x;
char buffer[1024];
FILE *fp = fopen(filename,"r");
if (fp == NULL)
{
fprintf(stderr,"Monitor API: could not open %s file\nTHIS FILE IS REQUIRED.\n", filename);
return false;
}
if( passString )
free(passString);
for(x=0;x<AUTHADDRESS_MAX;x++)
{
if( allowedAddressList[x] )
{
free(allowedAddressList[x]);
allowedAddressList[x] = 0;
}
}
nline = 0;
x = 0;
while(!feof(fp))
{
fgets( buffer, 1023, fp);
// get rid of '\n' and '\r' for comparisons
strtok(buffer,"\r\n");
len = (int)strlen(buffer);
if( len > 0 )
{
if( nline == 0 )
{
passString = (char *)malloc( len + 1 );
strcpy(passString,buffer);
}
else
{
allowedAddressList[x] = (char *)malloc( len + 1 );
strcpy(allowedAddressList[x],buffer);
x++;
}
}
nline++;
}
// clean up
fclose(fp);
return true;
}
// ******************************************************************************************************
// ******************************************************************************************************
// ******************************************************************************************************
// ******************************************************************************************************
CMonitorAPI::CMonitorAPI( const char *configFile, unsigned short Port, bool _bprint , char *address, UdpManager * mang )
{
mbprint = _bprint;
mPort = Port;
mAddress = NULL;
if( address )
{
mAddress = (char *)malloc(strlen(address)+1);
strcpy(mAddress,address);
}
if( mang == NULL )
{
UdpManager::Params params;
params.handler = NULL;
params.maxConnections = CONNECTION_MAX;
params.outgoingBufferSize = 1000000;
params.noDataTimeout = 130000;
params.oldestUnacknowledgedTimeout = 120000;
params.processIcmpErrors = false;
params.port = mPort;
mManager = new UdpManager(&params);
mMonitorData = new CMonitorData();
}
mObjectManager = new MonitorManager(configFile,mMonitorData,mManager,mbprint);
mManager->SetHandler(mObjectManager);
if( mbprint )
fprintf(stderr,"MonitorAPI: started on port->%d\n",mPort);
}
CMonitorAPI::~CMonitorAPI()
{
if( mAddress )
free(mAddress);
if( mObjectManager )
delete mObjectManager;
mManager->Release();
if( mMonitorData )
delete mMonitorData;
}
void CMonitorAPI::Update()
{
if( mManager )
mManager->GiveTime();
if( mObjectManager )
mObjectManager->GiveTime();
}
int CMonitorAPI::add(const char *label, int id, int ping, const char *des )
{
int rnt;
rnt = mMonitorData->add(label,id,ping,des);
if( rnt )
mObjectManager->HierarchyChanged();
return rnt;
}
void CMonitorAPI::remove(int Id)
{
mMonitorData->remove(Id);
mObjectManager->HierarchyChanged();
}
void CMonitorAPI::setDescription( int Id, const char *Description )
{
int x;
int mode;
x = mMonitorData->setDescription(Id,Description,mode);
if( x == -1 )
return;
mObjectManager->DescriptionMark(x,mode);
}
void CMonitorAPI::dump(){ mMonitorData->dump(); }
//----------------------------------------------------------------
monMessage::monMessage():command(0),sequence(0),size(0){}
//----------------------------------------------------------------
monMessage::monMessage(short cmd,short seq,short s):command(cmd),sequence(seq),size(s){}
//----------------------------------------------------------------
monMessage::monMessage(const unsigned char * source):command(0),sequence(0),size(0)
{
int len;
len = 0;
unpackShort( (char *)source + len, len,command);
unpackShort( (char *)source + len, len,sequence);
unpackShort( (char *)source + len, len,size);
}
//----------------------------------------------------------------
// monMessage::monMessage(const monMessage &copy):command(copy.command),sequence(copy.sequence),size(copy.size){}
//----------------------------------------------------------------
stringMessage::stringMessage(const unsigned char * source):monMessage(source)
{
int size;
size = (int)strlen((char *)source+6) +1;
data = new char [ size ];
strcpy(data,(char *)source+6); // Add six for the size of the header
}
//----------------------------------------------------------------
stringMessage::stringMessage(const unsigned short command,const unsigned short sequence,const unsigned short size,char * newData):
monMessage(command, sequence, size)
{
data = new char [strlen(newData) + 1];
if (data)
strncpy(data, newData, strlen(newData + 1));
else
data = NULL;
}
//----------------------------------------------------------------
stringMessage::~stringMessage()
{
if(data)
delete [] data;
data = 0;
}
//----------------------------------------------------------------
authReplyMessage::authReplyMessage(const unsigned char * source) :
monMessage(source)
{
int len = 6;
unpackShort((char *)source+len,len,version);
unpackByte((char *)source+len,len,data);
}
//----------------------------------------------------------------
authReplyMessage::authReplyMessage(const unsigned short command,
const unsigned short sequence,
const unsigned short size,
unsigned char newData):
monMessage(command, sequence, size),data(newData){}
//----------------------------------------------------------------
dataReplyMessage::dataReplyMessage(const unsigned char * source) :
monMessage(source)
{
data = new unsigned char[getSize()+1];
if (data)
{
memcpy(data, source + 6, getSize());
data[getSize()] = 0;
}
else
data = NULL;
}
//----------------------------------------------------------------
dataReplyMessage::dataReplyMessage(const unsigned short command,
const unsigned short sequence,
const unsigned short size,
unsigned char * newData,
int newDataLen):
monMessage(command, sequence, size)
{
data = new unsigned char[newDataLen];
if (data)
memcpy(data, newData, newDataLen);
else
data = NULL;
}
//----------------------------------------------------------------
dataReplyMessage::~dataReplyMessage()
{
if (data)
{
delete [] data;
data = 0;
}
}
//----------------------------------------------------------------
simpleMessage::simpleMessage(const unsigned char * source):monMessage(source){}
//----------------------------------------------------------------
simpleMessage::simpleMessage(const unsigned short command,
const unsigned short sequence,
const unsigned short size):
monMessage(command, sequence, size){}
//----------------------------------------------------------------
simpleMessage::~simpleMessage(){}
//----------------------------------------------------------------
//----------------------------------------------------------------
dataBlockReplyMessage::dataBlockReplyMessage(const unsigned char * source) :
monMessage(source)
{
int err;
unsigned long S = 4000000;
unsigned char *p;
data = NULL;
p = (unsigned char *)malloc(4000000);
memset(p,0,4000000);
err = uncompress(p,&S,(source+6),(long)getSize());
if( Z_OK != err ) { free(p);return; }
data = new unsigned char[S+1];
memcpy(data,p,S);
setSize((unsigned short)S);
free(p);
}
//----------------------------------------------------------------
dataBlockReplyMessage::~dataBlockReplyMessage()
{
if (data)
{
delete [] data;
data = 0;
}
}
@@ -0,0 +1,184 @@
#ifndef __MONITOR_API__
#define __MONITOR_API__
/**********************************************************************************************
Please contact [email protected] for any comments or request for chagnes.
**********************************************************************************************
Required libs
UdpLibrary
zlib
********************************** DO NOT EDIT THIS FILE ***********************************
**********************************************************************************************
**********************************************************************************************/
#include "MonitorData.h"
class CMonitorAPI {
private:
CMonitorData *mMonitorData;
UdpManager *mManager;
MonitorManager *mObjectManager;
char *mAddress;
unsigned short mPort;
bool mbprint;
public:
/******************* CMonitorAPI *************************************
*
* configFile = Included in the zip file, is a file "mon.cfg". In this file is a password and
* ip address's that are allowed to connect to your server. You can rename the
* file or place it in another directory. Use this param to access this file.
*
*
* port = use port 2200 as a default. When using more than one server on a machine, use another port, range 2200-2220
*
* debug = turn on/off debugging.
*
* address = (NOT USED) Leave as NULL
*
* UdpManager * mang = (NOT USED) Leave as NULL
*
* // GenericNotifier *notifier = (NOT USED) Leave as NULL
*
*/
CMonitorAPI( const char *configFile, unsigned short port, bool debug = false , char * address = NULL, UdpManager * mang = NULL );
~CMonitorAPI();
/**************** Process communication from collectors ******************
*
* This needs to be called in the main loop every processing cycle.
* Update will read the socket for request and send updates to the
* collector.
*
* Note: Update is non-blocking
*/
void Update();
/**************** Add element to list **********************************
*
* label = name of the element.
* Elements labels must be unique. "." is use to group labels
* Example:
* Server.Zone 1.process
* Server.Zone 1.CPU
* Server.Zone 2.process
* Server.Zone 2.CPU
*
* Will show as
* Server -
* |
* - Zone 1 -
* - process
* - CPU
* |- Zone 2 -
* - process
* - CPU
*
* Note: do not use "/" char.
*
* Key = This id must be unigue and key use to identify the element when setting it.
* Any positvie intenger can be use.
*
* mode =
* #define MON_HISTORY will store values (avg 5min), you will be able to graph.
* #define MON_ONLY_SHOW will not store vlaue, only for showing.
*
*
*
* description = descritpion of the element. Tell us what the element means. Hostname, BPS, Kbytes, Seconds,.....
*
* Note: All values are sent to the collector every two minutes (forced). In between when values are
* forced, only values that are changed will be sent to the collector.
*
* ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
*
* Required:
* One element is requried. Name the elment "Population" and in the descritpion please add the follwing,
* <Current version of your server> <Hostname and the port >
*
* ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
*
* Max Limited
* #define ELEMENT_MAX_START 2000
*/
int add( const char *label, int Key, int mode = MON_HISTORY, const char *Description = NULL );
/**************** Set the description of an element **
*
* Sets the description to an element.
*
* Key = element key.
*
* Description = description of element.
*
* Note: Descriptions take longer to update, do not use description to
* display vital informaiton.
*
*/
void setDescription( int Key, const char *Description ) ;
/**************** Set the value of an element *********
*
* Sets the element to the current value.
*
* Key = element key.
*
* value = current value to set.
*
* Note: When a element is assoicated with a Server.
* Use the following values to signify the status.
* If you would like to add another status mode,
* please contact [email protected]
*
* #define STATUS_LOCKED -1 // Server is locking out players, mataince mode
* #define STATUS_DOWN -2 // Server is down.
* #define STATUS_NOCONNECT -3 // Server is not connected
* #define STATUS_LOADING -4 // Server is in a loading state
*
*/
void set(int Key, int value);
/**************** Remove element from list ***********
*
* Removes the element.
*
* Key = element key
*/
void remove(int Key);
/***************** Debug dump **********************
*
* Will printf a list of all the elelments.
* Format:
*
* Label, Key, Value, Mode
*/
void dump();
// ************** Do not use *************************
void setMax(int max){ mMonitorData->setMax(max);}
};
inline void CMonitorAPI::set(int Id, int value){ mMonitorData->set(Id,value); }
#endif
@@ -0,0 +1,758 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include "zlib.h"
#include "MonitorData.h"
//**********************************************************************************************
//**********************************************************************************************
//********************************** DO NOT EDIT THIS FILE ***********************************
//**********************************************************************************************
//**********************************************************************************************
#define BUFFER_SIZE_START 2048
#define BUFFER_RESIZE_VALUE 1024
extern void set_bit( unsigned char p[], int bit);
extern void unset_bit(unsigned char p[], int bit);
extern int get_bit( unsigned char p[], int bit);
// ------------------ Support Routine -----------------------------
//////////////////////////////////////////////////////////////////////
// qsort compare routine
//////////////////////////////////////////////////////////////////////
int compar_name( const void *e1, const void *e2 )
{
MON_ELEMENT *data1,*data2;
data1 = *(MON_ELEMENT **)e1;
data2 = *(MON_ELEMENT **)e2;
#ifdef _WIN32
return _stricmp(data1->label, data2->label);
#else
return strcasecmp(data1->label,data2->label);
#endif
}
int compar_index( const void *e1, const void *e2 )
{
MON_ELEMENT *data1,*data2;
data1 = (MON_ELEMENT *)e1;
data2 = (MON_ELEMENT *)e2;
return data1->id - data2->id;
}
// ------------------ Game Data Object ----------------------------
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//CMonitorData::CMonitorData(GenericNotifier *notifier)
//: m_notifier(notifier)
CMonitorData::CMonitorData()
{
m_sequence = 1;
m_buffer = NULL;
m_nbuffer = 0;
m_count = 0;
m_max = ELEMENT_MAX_START;
m_data = new MON_ELEMENT[m_max];
for(int x=0;x<m_max;x++)
{
memset(&m_data[x],0,sizeof(MON_ELEMENT));
}
resize_buffer(BUFFER_SIZE_START);
}
CMonitorData::~CMonitorData()
{
int x;
for(x=0;x<m_count;x++)
{
if( m_data[x].discription )
delete [] m_data[x].discription;
if( m_data[x].label )
delete [] m_data[x].label;
}
if(m_buffer)
delete m_buffer;
if( m_data )
delete [] m_data;
}
void CMonitorData::setMax(int _max)
{
if( m_data )
delete [] m_data;
m_max = _max;
m_data = new MON_ELEMENT[m_max];
for(int x=0;x<m_max;x++)
{
memset(&m_data[x],0,sizeof(MON_ELEMENT));
}
}
void CMonitorData::resize_buffer(int new_size)
{
char *temp;
if( m_buffer != NULL )
{
temp = m_buffer;
m_buffer = new char[ new_size];
memcpy(m_buffer,temp,m_nbuffer);
m_nbuffer = new_size;
delete [] temp;
}
else
{
m_buffer = new char[ new_size];
m_nbuffer = new_size;
}
}
void CMonitorData::send( UdpConnection *con,short & sequence,short msg,char *data )
{
int len;
unsigned short size;
char *p;
size = (unsigned short)strlen(data)+1;
p = (char *)malloc(size+6);
len = 0;
packShort(p+len, len, msg);
packShort(p+len, len, m_sequence);
packShort(p+len, len, size);
memcpy( p+len, data, size );
con->Send(cUdpChannelReliable1, p, size + 6);
free(p);
sequence++;
}
void CMonitorData::send( UdpConnection *con,short & sequence,short msg,char *data,int size )
{
unsigned long compress_len;
int len;
unsigned short usize;
char *p;
int rnt;
if( CURRENT_API_VERSION != CURRENT_API_3 )
return;
p = (char *)malloc(size+6+1000);
len = 0;
memset(p,0,size+6+1000);
packShort(p+len, len, msg);
packShort(p+len, len, m_sequence);
compress_len = size + 1000;
rnt = compress2((Bytef *)p+6,&compress_len,(Bytef *)data,(long)size,2);
if( rnt != Z_OK )
{
free(p);
printf("CMonitor::send-compress failed, error=%d size =%d\n",rnt,size);
return;
}
usize = (unsigned short)compress_len;
packShort(p+len, len, usize);
usize += 6;
con->Send(cUdpChannelReliable1, p, usize);
free(p);
sequence++;
}
bool CMonitorData::processHierarchyRequestBlock( UdpConnection *con, short & sequence )
{
int x,size,count,len;
char temp[512];
if( m_count == 0 )
{
send(con,sequence,MON_MSG_REPLY_HIERARCHY,"NOTREADY");
return 0;
}
memset(m_buffer,0,16);
send(con,sequence,MON_MSG_REPLY_HIERARCHY_BLOCK_BEGIN,m_buffer);
MON_ELEMENT **me;
me = new MON_ELEMENT *[m_count];
for(x=0;x<m_count;x++)
me[x] = &m_data[x];
qsort(me,m_count,sizeof(MON_ELEMENT *),compar_name);
count = x = size = 0;
while(x<m_count)
{
len = sprintf(temp,"%s,%X,%d|",me[x]->label,me[x]->id,me[x]->ping);
if( len+size >= m_nbuffer ) resize_buffer(size+BUFFER_RESIZE_VALUE);
strcpy(&m_buffer[size],temp);
size += len;
if( size > 64000 )
{
send(con,sequence,MON_MSG_REPLY_HIERARCHY_BLOCK,m_buffer,size+1);
memset(m_buffer,0,size);
count++;
size = 0;
}
x++;
}
delete [] me;
if( size > 0 )
{
send(con,sequence,MON_MSG_REPLY_HIERARCHY_BLOCK,m_buffer,size+1);
memset(m_buffer,0, 16);
count++;
size = 0;
}
memset(m_buffer,0, 16);
send(con,sequence,MON_MSG_REPLY_HIERARCHY_BLOCK_END,m_buffer);
return 1;
}
bool CMonitorData::processElementsRequest(
UdpConnection *con, short & sequence, char * data, int /* dataLen */ , long lastUpdateTime )
{
char tmp[200];
int x,id;
int size;
int count;
char **list;
memset(m_buffer,0,16);
if( !strcmp(data,"-1") )
{
size = 0;
for (x=0;x<m_count;x++)
{
sprintf(tmp,"%d %x|",m_data[x].id,m_data[x].value);
size += (int)strlen(tmp);
if( size >= m_nbuffer )
resize_buffer(size+BUFFER_RESIZE_VALUE);
strcat(m_buffer,tmp);
if( size > 65000 )
{
send(con,sequence,MON_MSG_REPLY_ELEMENTS,m_buffer);
memset(m_buffer,0,16);
}
}
if( size )
send(con,sequence,MON_MSG_REPLY_ELEMENTS,m_buffer);
return 1;
}
if( !strcmp(data,"-2") )
{
size = 0;
count = 0;
for (x=0;x<m_count;x++)
{
if( lastUpdateTime <= m_data[x].ChangedTime )
{
sprintf(tmp,"%d %x|",m_data[x].id,m_data[x].value);
size += (int)strlen(tmp);
if( size >= m_nbuffer )
resize_buffer(size+BUFFER_RESIZE_VALUE);
strcat(m_buffer,tmp);
count++;
}
if( size > 65000 )
{
send(con,sequence,MON_MSG_REPLY_ELEMENTS,m_buffer);
memset(m_buffer,0,16);
}
}
if ( count )
{
send(con,sequence,MON_MSG_REPLY_ELEMENTS,m_buffer);
return 1;
}
return 0;
}
list = new char * [m_max];
count = parseList( list, data,'|',m_max);
memset(m_buffer,0,16);
size = 0;
for(x=0;x<count;x++)
{
id = atoi(list[x]);
for(x=0;x<m_count;x++)
if( m_data[x].id == id )
{
sprintf(tmp,"%d %x|",m_data[x].id, m_data[x].value);
size += (int)strlen(tmp);
if( size >= m_nbuffer )
resize_buffer(size+BUFFER_RESIZE_VALUE);
strcat(m_buffer,tmp);
}
}
delete [] list;
if( count > 0 )
send(con,sequence,MON_MSG_REPLY_ELEMENTS,m_buffer);
return 0;
}
bool CMonitorData::processDescriptionRequest(UdpConnection *con, short & sequence, char * userData, int , unsigned char *mark)
{
char line[4096];
char tmp[400];
int x,id,size;
int flag;
char *p;
size = 0;
memset(m_buffer,0,16);
strcpy(line,userData);
p = strtok(line,"|");
flag = 0;
if( strstr(p,"next") )
{
for(x=0;x<m_count;x++)
{
if( get_bit(mark,x) == 0 )
{
set_bit( mark, x );
if( m_data[x].discription != NULL )
{
sprintf(tmp,"%d,%s|",m_data[x].id, m_data[x].discription);
size += (int)strlen(tmp);
if( size >= m_nbuffer )
resize_buffer(size+BUFFER_RESIZE_VALUE);
strcat(m_buffer,tmp);
send(con,sequence,MON_MSG_REPLY_DESCRIPTION,m_buffer);
return 1;
}
}
}
}
else
{
if( p )
{
size = 0;
flag = 0;
id = atoi(p);
for(x=0;x<m_count;x++)
{
if( flag == 0 && id == m_data[x].id )
flag = 1;
if( flag )
{
flag = 2;
set_bit(mark,x);
if( m_data[x].discription != NULL )
{
sprintf(tmp,"%d,%s|",m_data[x].id, m_data[x].discription);
size += (int)strlen(tmp);
if( size >= m_nbuffer )
resize_buffer(size+BUFFER_RESIZE_VALUE);
strcat(m_buffer,tmp);
if( size >= 2000 || m_data[x].discription )
{
send(con,sequence,MON_MSG_REPLY_DESCRIPTION,m_buffer);
return 1;
}
}
}
}
}
}
if( flag == 2 )
send(con,sequence,MON_MSG_REPLY_DESCRIPTION,m_buffer);
send(con,sequence,MON_MSG_REPLY_DESCRIPTION,"none");
return 0;
}
int CMonitorData::add(const char *label, int id, int ping, const char *des )
{
int x;
if( strlen(label) >= 127 )
{
printf("MonAPI Error: add() label exceeds length of 127. ->%s\n",label);
return 0;
}
for(x=0;x<m_count;x++)
{
if( id == m_data[x].id )
{
printf("MonAPI: assign new Id (%d) %s -> %s\n",id,m_data[x].label,label);
m_data[x].ping = pingValue( ping );
m_data[x].value = 0;
m_data[x].id = id;
//******* Label ***********
if( m_data[x].label )
delete [] m_data[x].label;
m_data[x].label = new char [strlen(label)+1];
strcpy(m_data[x].label,label);
//******* Discription ******
if( m_data[x].discription != NULL )
delete [] m_data[x].discription;
m_data[x].discription = NULL;
if( des )
{
m_data[x].discription = new char [strlen(des)+1];
strcpy(m_data[x].discription,des);
}
qsort(m_data,m_count,sizeof(MON_ELEMENT),compar_index);
return 1;
}
if( !strcmp(label,m_data[x].label) )
{
printf("MonAPI ERROR: Label already found %s Id: old(%d) new(%d).\n",label,m_data[x].id,id);
return 0;
}
}
if( m_max == m_count + 1 )
{
printf("MonitorObject: max element reached [%d].\n%s\nContact David Taylor (858) 577-3155.\n",m_max,label);
return 0;
}
m_data[m_count].ping = pingValue( ping );
m_data[m_count].value = 0;
m_data[m_count].id = id;
if(m_data[m_count].label)
delete [] m_data[m_count].label;
m_data[m_count].label = new char [strlen(label)+1];
strcpy(m_data[m_count].label,label);
if( des )
{
if( m_data[x].discription )
delete [] m_data[x].discription;
m_data[x].discription = new char [strlen(des)+1];
strcpy(m_data[x].discription,des);
}
m_count++;
qsort(m_data,m_count,sizeof(MON_ELEMENT),compar_index);
return 1;
}
int CMonitorData::setDescription( int Id, const char *Description , int & mode)
{
int x;
for(x=0;x<m_count;x++)
{
if( Id == m_data[x].id )
{
if( Description == NULL )
{
if( m_data[x].discription )
delete [] m_data[x].discription;
m_data[x].discription = NULL;
mode = 0;
return x;
}
if( m_data[x].discription && !strcmp( m_data[x].discription, Description ) )
return -1;
if( m_data[x].discription )
delete [] m_data[x].discription;
m_data[x].discription = new char [ strlen(Description) +1 ];
strcpy(m_data[x].discription,Description);
mode = 1;
return x;
}
}
return -1;
}
int CMonitorData::pingValue(int p)
{
switch(p)
{
case MON_HISTORY: return (60 * 5);
case MON_ONLY_SHOW: return 0;
default:
printf("MonAPI ERROR: add() function is not using defined constances.\n");
printf("Please use one of the following:\n");
printf("\tMON_PING_15\n\tMON_PING_30\n\tMON_PING_60\n\tMON_PING_5MIN\n");
break;
}
return 0;
}
void CMonitorData::set(int Id, int value)
{
int high, i, low;
for ( low=(-1), high=m_count; high-low > 1; )
{
i = (high+low) / 2;
if ( Id <= m_data[i].id )
high = i;
else
low = i;
}
if ( high < m_count && Id==m_data[high].id )
{
if( m_data[high].ChangedTime == 0 || m_data[high].value != value )
m_data[high].ChangedTime = (long)time(NULL);
m_data[high].value = value;
}
}
void CMonitorData::remove(int Id)
{
int x;
if( m_count == 1 )
{
if( m_data[0].label )
delete [] m_data[0].label;
if( m_data[0].discription )
delete [] m_data[0].discription;
m_data[0].label = 0;
m_data[0].id = 0;
m_data[0].value = 0;;
m_data[0].ping = 0;;
m_count--;
return;
}
for(x=0;x<m_count;x++)
{
if( Id == m_data[x].id )
{
if( m_data[x].label )
delete [] m_data[x].label;
if( m_data[x].discription )
delete [] m_data[x].discription;
m_data[x].label = 0;
if( x < m_count-1 )
{
memcpy(&m_data[x],&m_data[m_count-1],sizeof(MON_ELEMENT));
}
memset(&m_data[m_count-1],0,sizeof(MON_ELEMENT));
m_count--;
return;
}
}
}
int CMonitorData::parseList( char **list, char *data, char tok , int max )
{
int count;
int cnt;
if( data == NULL )
return 0;
list[0] = data;
count = 1;
cnt =0;
while( cnt < max && *data > 0 )
{
if( *data == tok )
{
*data = 0;
data++;
cnt++;
list[count] = data;
if( *data ) count++;
}
cnt++;
if( *data ) data++;
}
return count;
}
void CMonitorData::dump()
{
printf("********** Monitor API Dump *******************\n");
printf(" Version: %d\n",CURRENT_API_VERSION);
printf("\ncount: %d\n", m_count);
printf("\t%-40s %8s\t%s\t%s\n","Label","Id","Ping","Value");
for(int x=0;x<m_count;x++)
{
printf("\t%-40s % 8d\t%d\t%d\n",
m_data[x].label,
m_data[x].id,
m_data[x].value,
m_data[x].ping);
}
printf("***********************************************\n");
}
/*
int CMonitorData::compress(char *dest,unsigned long *destLen,const char *source,long sourceLen,int level)
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
stream.next_out = (Bytef *)dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
*/
//////////////////////////////////////////////////////////////////////////////
// ------------------ Pack and unpack Routine -----------------------------
///////////////////////////////////////////////////////////////////////////////
int packString(char *buffer, int & len, char * value)
{
int size;
size = (int)strlen(value)+1;
memcpy(buffer,value, size);
len += size;
return size;
}
int packByte(char *buffer, int & len, char value)
{
buffer[0] = value;
len++;
return 1;
}
int packShort(char *buffer, int & len, short value)
{
char *p;
p = (char *)&value;
#ifdef _sun
buffer[0] = p[1];
buffer[1] = p[0];
#else
buffer[0] = p[0];
buffer[1] = p[1];
#endif
len += 2;
return 2;
}
int packShort( char *buffer, int & len, unsigned short value )
{
char *p;
p = (char *)&value;
#ifdef _sun
buffer[0] = p[1];
buffer[1] = p[0];
#else
buffer[0] = p[0];
buffer[1] = p[1];
#endif
len += 2;
return 2;
}
int unpackShort(char *buffer, int & len, short & value)
{
char *p;
p = (char *)&value;
#ifdef _sun
p[1] = buffer[0];
p[0] = buffer[1];
#else
p[0] = buffer[0];
p[1] = buffer[1];
#endif
len += 2;
return 2;
}
int unpackShort(char *buffer, int & len, unsigned short & value)
{
char *p;
p = (char *)&value;
#ifdef _sun
p[1] = buffer[0];
p[0] = buffer[1];
#else
p[0] = buffer[0];
p[1] = buffer[1];
#endif
len += 2;
return 2;
}
int unpackByte( char *buffer, int & len, char &value)
{
value = buffer[0];
len++;
return 1;
}
@@ -0,0 +1,342 @@
#ifndef __MONITOR_DATA__
#define __MONITOR_DATA__
// **********************************************************************************************
// **********************************************************************************************
// ********************************** DO NOT EDIT THIS FILE ***********************************
// **********************************************************************************************
// **********************************************************************************************
//#include <UdpHandler.hpp>
#include <UdpLibrary.hpp>
#define CURRENT_API_VERSION 3
#define CURRENT_API_1 1
#define CURRENT_API_2 2
#define CURRENT_API_3 3
#define MON_HISTORY 4 // This will ping every 30 sec. and report max of 5 min.
#define MON_ONLY_SHOW 5 // This will not store data. WILL NOT GRAPH
#define STATUS_LOCKED -1 // Server is locking out players
#define STATUS_DOWN -2 // Server is down.
#define STATUS_NOCONNECT -3 // Server is not connected
#define STATUS_LOADING -4 // Server is in a loading state
#define ELEMENT_MAX_START 5000
/*
Provide binary data packing and unpacking functions
Usage
Format strings are as follows:
'c' - char (1)
'l' - long int (4)
'L' - long long int (8)
'i' - int (4)
's' - short int (2)
'S' - C-style, null-terminated string (n + null)
'Bn' - buffer, of size n. Used for non-terminated strings, or
other binary data.
*/
extern int packString(char *buffer, int & len, char * value);
extern int packByte(char *buffer, int & len, char value);
extern int packShort(char *buffer, int & len, short value);
extern int unpackShort(char *buffer, int & len, short & value);
extern int unpackShort(char *buffer, int & len, unsigned short & value);
extern int unpackByte( char *buffer, int & len, char & value);
//----------------------------------------------------------------
typedef unsigned char byte;
//----------------------------------------------------------------
// Define the message types that are understood via the Monitoring API
enum MON_MESSAGES
{
MON_MSG_AUTH = 1, // client sends auth info during connect request
MON_MSG_AUTHREPLY, // server responds to auth request
MON_MSG_QUERY_ELEMENTS, // client asking for element data
MON_MSG_QUERY_HIERARCHY, // client asking for hierarchy data
MON_MSG_REPLY_ELEMENTS, // server returns element data
MON_MSG_REPLY_HIERARCHY, // server returns element data
MON_MSG_QUERY_DESCRIPTION, // client asking for Description of element
MON_MSG_REPLY_DESCRIPTION, // server returns element Description of element
MON_MSG_QUERY_HIERARCHY_BLOCK, // client asking for hierarchy data
MON_MSG_REPLY_HIERARCHY_BLOCK_BEGIN,
MON_MSG_REPLY_HIERARCHY_BLOCK, // server returns element data
MON_MSG_REPLY_HIERARCHY_BLOCK_END,
MON_MSG_ERROR = 99 // one of many errors, defined elsewhere
};
// ----------------------------------------------------------------
// define error codes that can be sent and received via MON_MSG_ERROR types
enum MON_ERRORS
{
INVALID_HEADER = 10, // could not read the header data reliably
INVALID_SEQUENCE = 20, // out of range or unknown sequence number
INVALID_MSG_LENGTH = 30, // message length field is incorrect
INVALID_AUTH_REQUEST = 101, // could not read the entire request
INVALID_ELEMENT_REQUEST = 102, // could not read the entire request
INVALID_HIERARCHY_REQUEST = 103, // could not read the entire request
INVALID_AUTH_REPLY = 105, // the data reply was incorrectly formatted
INVALID_ELEMENT_REPLY = 106, // the data reply was incorrectly formatted
INVALID_HIERARCHY_REPLY = 107, // the data reply was incorrectly formatted
INVALID_ERROR_CODE = 108, // an error was sent, but it isn't recognized
INVALID_MSG_TYPE = 109, // an invalid message type was sent
INVALID_CONFIG_FILE = 110 // Error in reading config file
};
// ----------------------------------------------------------------
// monMessage
// The base message class for the Monitor API
// This message should not be used explicitly. Use simpleMessage for basic tasks.
// monMessage does not contain the etx field as required by the monitoring protocol.
class monMessage
{
public:
monMessage(short command, short sequence, short size);
monMessage(const unsigned char * source);
monMessage(const monMessage &copy);
monMessage();
inline const unsigned short getCommand() const {return command;}
inline const unsigned short getSequence() const {return sequence;}
inline const unsigned short getSize() const {return size;}
inline void setSize(unsigned short _size ) {size=_size;}
private:
short command;
short sequence;
unsigned short size;
};
//----------------------------------------------------------------
// stringMessage
// This message type is used for passing messages that can consist of a NULL terminated string
class stringMessage : public monMessage
{
public:
stringMessage(const unsigned short command, const unsigned short sequence, const unsigned short size, char * data);
stringMessage(const unsigned char * source);
virtual ~stringMessage();
inline const char * getData() const {return data;};
private:
char * data;
};
//----------------------------------------------------------------
// authReplyMessage
// This message is used exclusively to tell the client whether or not they were successfully
// authenticated. This message is sent in reply to a MON_MSG_AUTH request.
class authReplyMessage : public monMessage
{
public:
authReplyMessage(const unsigned short command, const unsigned short sequence, const unsigned short size, byte data);
authReplyMessage(const unsigned char * source);
inline const unsigned char getData() const {return data;};
inline const short getVersion() const { return version; };
inline void setData(const unsigned char newData) {data = newData;}
private:
char data;
short version;
};
//----------------------------------------------------------------
// dataReplyMessage
// This message type is sent for Element and Hierarchy data requests
// The data is stored and retrieved as a byte array, internally represented as a std::vector<byte>
class dataReplyMessage : public monMessage
{
public:
dataReplyMessage(const unsigned short command, const unsigned short sequence, const unsigned short size, unsigned char *data, int dataLen);
dataReplyMessage(const unsigned char * source);
virtual ~dataReplyMessage();
inline const unsigned char * getData() const {return data;};
private:
unsigned char * data;
};
//----------------------------------------------------------------
// dataReplyMessage
// This message type is sent for Element and Hierarchy data requests
// The data is stored and retrieved as a byte array, internally represented as a std::vector<byte>
class dataBlockReplyMessage : public monMessage
{
public:
dataBlockReplyMessage(const unsigned char * source);
virtual ~dataBlockReplyMessage();
inline const unsigned char * getData() const {return data;};
private:
unsigned char * data;
};
//----------------------------------------------------------------
// simpleMessage
// This is the most basic monitor API message. It can be created from an
// Archive::ByteStream in order to discover the message type for more complex messages,
// or it could be sent explicitly for query message types.
class simpleMessage : public monMessage
{
public:
simpleMessage(const unsigned short command, const unsigned short sequence, const unsigned short size);
simpleMessage(const unsigned char * source);
virtual ~simpleMessage();
private:
};
// *************** Internal Struct ***************************
typedef struct {
int value; // Value of the element
int id; // Id for users, user control, could be any value, must be unique
int ping; // Ping time, use one of the API defined values, MON_PING_15,...
char *label; // Label of element, use periods to make sub labels, last name sperated
// by periods is the name of the element.
//
// Example: "Universe.Planet.Zone1.count"
// Universe.Planet.Zone1 = Tree name
// count = element name
//
// NOTE: This label is the name of the data element, change the label name
// and a new history of data is started. You will not be able to change
// the name at run time.
//
char *discription; // Discription of element. This can be changed at will.
long ChangedTime;
} MON_ELEMENT;
/*
class GenericNotifier
{
public:
GenericNotifier(){}
virtual ~GenericNotifier(){}
virtual void dataReported(int id ){}
};
*/
class CMonitorData {
MON_ELEMENT *m_data; // Pointer to MON_DATA elements
int m_ndata;
int m_count;
int m_max;
char *m_buffer;
int m_nbuffer;
short m_sequence;
// GenericNotifier *m_notifier;
int parseList( char **list, char *data, char tok , int max );
void resize_buffer(int new_size);
void send( UdpConnection *mConnection, short & sequence, short msg, char *data );
void send( UdpConnection *mConnection, short & sequence, short msg, char *data , int size);
public:
// CMonitorData(GenericNotifier *notifier=NULL );
CMonitorData();
virtual ~CMonitorData();
int getCount(){ return m_ndata; }
int DataMax(){ return m_max; }
void setMax(int _max);
// bool processHierarchyRequest(UdpConnection *con, short & sequence);
bool processHierarchyRequestBlock(UdpConnection *con, short & sequence);
bool processElementsRequest( UdpConnection *con, short & sequence, char * userData, int dataLen , long lastUpdateTime);
bool processDescriptionRequest(UdpConnection *con, short & sequence, char * userData, int dataLen,unsigned char *mark);
int add(const char *label, int id, int ping, const char *des );
int setDescription( int Id, const char *Description , int & mode);
char *getDescription(int x){ if( m_ndata >= x ) return NULL; return m_data[x].discription;}
int pingValue(int p);
void set(int Id, int value);
void remove(int Id);
void dump();
// int compress(char *dest,unsigned long *destLen,const char *source,long sourceLen,int level);
};
#define AUTHADDRESS_MAX 30
#define CONNECTION_MAX 8
class MonitorObject : public UdpConnectionHandler
{
CMonitorData *mMonitorData;
short mSequence;
char *mPasswd;
char **mAddressList;
unsigned char *mMark;
int mbAuthenticated;
bool mHierarchySent;
bool mbprint;
long mlastUpdateTime;
bool checkAddress(const char * address);
bool checkPasswd( const char *passwd);
public:
UdpConnection *mConnection;
MonitorObject(UdpConnection *con, CMonitorData *, char *passwd, char **addressList ,bool _bprint );
virtual ~MonitorObject();
virtual void OnRoutePacket( UdpConnection *con, const unsigned char *data, int dataLen);
virtual void OnTerminated( UdpConnection *con);
bool processAuthRequest(const unsigned char * data, int dataLen);
bool processError(const unsigned char * data);
void HeirarchyChanged(){ mHierarchySent = false; }
void DescriptionMark(int x,int mode);
};
class MonitorManager : public UdpManagerHandler
{
bool mbprint;
CMonitorData *mMonitorData;
char *passString;
char *allowedAddressList[AUTHADDRESS_MAX];
bool loadAuthData(const char * filename);
public:
MonitorManager(const char *configFile, CMonitorData *gamedata, UdpManager *manager , bool _bprint = false);
virtual ~MonitorManager();
void AddObject(MonitorObject *player);
void GiveTime();
void HierarchyChanged();
void DescriptionMark(int x,int mode);
virtual void OnConnectRequest(UdpConnection *con);
protected:
MonitorObject *mObject[CONNECTION_MAX];
int mObjectCount;
UdpManager *mManager;
};
#endif
@@ -0,0 +1,3 @@
neverqst
10.10.3
10.10.4