#ifndef __MONITOR_API__
#define __MONITOR_API__

//**********************************************************************************************
//**********************************************************************************************
//**********************************  DO NOT EDIT THIS FILE  ***********************************
//**********************************************************************************************
//**********************************************************************************************

#include "UdpLibrary/UdpHandler.hpp"
#include "UdpLibrary/UdpLibrary.hpp"
#include "monitorData.h"

#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 uchar *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(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;
};

class CMonitorAPI {

	bool mbprint;

public:

	CMonitorAPI( char *configFile, unsigned short Port, bool _bprint = false , char * address = nullptr, UdpManager * mang = nullptr );
	
	~CMonitorAPI();

	void Update();

	void add( const char *label, int id, int ping = MON_PING_5MIN, char *des = nullptr );

	void setDescription( int Id, const char *Description ) ;
	
	int  PingValue(int p){ return mMonitorData->pingValue(p); }
	
	void set(int Id, int value){ mMonitorData->set(Id,value); }
	
	void remove(int Id);
	
	void dump();

private:

	CMonitorData		*mMonitorData;
	UdpManager			*mManager;
	MonitorManager		*mObjectManager;
	char				*mAddress;
	unsigned short		mPort;

};

#endif


