//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS2_SCE_RT_Server.h
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
// Description:
//
//     server-specific code
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PS2_SCE_RT_SERVER_H___
#define ___ASURA_PS2_SCE_RT_SERVER_H___ 1


#include "Network/Asura_PS2_SCE_RT.h"
#include "scert/include/dme_server.h"


//static const int ASURA_PS2_SERVER_TCP_PORT = 2000;
//static const int ASURA_PS2_SERVER_UDP_PORT = 2001;


class Asura_PS2_SCE_RT_Server : public Asura_PS2_SCE_RT
{

	struct PlayerInfo
	{
		PlayerInfo() { m_sClientID = -1; }
		
		short m_sClientID;
	};

private:
	
	// constructor / destruction private to enforce singleton pattern
	Asura_PS2_SCE_RT_Server();
	~Asura_PS2_SCE_RT_Server();

public:

	// static functions to manage creation and destruction
	static Asura_PS2_SCE_RT_Server* Create();
	static void Destroy(Asura_PS2_SCE_RT_Server* pxServer);

	// member functions
	bool Initialise();
	void Shutdown();
	bool Update();
	void ProcessClientConnected(u_short uClientIndex);
	void ProcessClientDisconnected(u_short uClientIndex);
	short GetClientIndex(u_int uMachineHandle) { return m_pxPlayerInfo[uMachineHandle].m_sClientID; }
	int FindMachineIndex(u_short usClientIndex);	// return -1 if not found

	// static functions for callbacks
#if DME_CLIENT_VERSION_BUILD < 0017
	static void ConnectionCallback(int iConnectionIndex, int iClientIndex, const char* szClientIpString);
	static void DisconnectCallback(int iConnectionIndex, int iClientIndex, const char* szClientIpString);
#else
	static void ConnectionCallback(NetTypeClientConnectCallbackData* pxData);
	static void DisconnectCallback(NetTypeClientConnectCallbackData* pxData);
#endif

private:
	
	// static data - singleton enforcer
	static Asura_PS2_SCE_RT_Server* s_pxTheServer;

	// member data
	PlayerInfo* m_pxPlayerInfo;
};



// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PS2_SCE_RT_SERVER_H___
