#pragma once

//#include "../NetWaker/GSrvNetWaker.h"
#include "../mainproc/NetGlobal.h"
#include "PG_Login.h"

class CNetCli_Login : public CNetGlobal
{

protected:
	//-------------------------------------------------------------------
	static CNetCli_Login*	m_pThis;
	static DWORD			m_dwStep;
	static bool				_Init();
	static bool				_Release();
	static void				_ClearRoleData();

	//-------------------------------------------------------------------
	// from Master
	static void		OnPacket_IdentifyMaster			( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_SampleRoleData			( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_SampleRoleDataEnd		( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_CreateRoleResult		( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_DeleteRoleResult		( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_SelectRoleResult		( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_EnterWorld				( int iServerID , int iSize , PVOID pData );
	static void		OnPacket_LeaveWorld				( int iServerID , int iSize , PVOID pData );
	//-------------------------------------------------------------------	
	static void		OnEvent_Login					( string sInfo );						// loging to switch server
	static void		OnEvent_Logout					();										// logout
	static void		OnEvent_LogFailed				( SYSLogFailedENUM emLogFailed );


	static void		OnEvent_ServerConnect			( int iServerID , string sServerName );
	static void		OnEvent_ServerDisConnect		( int iServerID );

	map< int, SampleRoleData* >						m_mapSampleRole;
	vector< int >									m_vecDBID;


public:
    CNetCli_Login( ){ m_dwStep = 0; m_pThis = this; };
	//-------------------------------------------------------------------
	//  Login
	//-------------------------------------------------------------------

	// 連線後, 從 Master 收到所有目前角色資料( Sample )

	static bool Login								( const char* szIP, int iPort, char* szAccount, char* szPassword );
	
	virtual void On_Login							( const char* pszInfo ) =0;
	virtual void On_Logout							() =0;
	virtual void On_LoginFailed						( SYSLogFailedENUM emLogFailed ) =0;

	static bool	Logout								();

		virtual void On_ServerConnect					( int iServerID , const char* cpszServerName ){};
		virtual void On_ServerDisConnect				( int iServerID ){};

	virtual void On_SamepleRoleData					( int iFieldIndex, SampleRoleData* pSampleRole ) =0; // iFieldIndex = 流水號
	virtual void On_SamepleRoleDataEnd				() =0;
		
		//static void CreateRole						( int iFieldIndex, CreateRoleData* pCreateRoleData );
		static void CreateRole						( CreateRoleData* pCreateRoleData );
		static void SelectRole						( int iFieldIndex );
		static void DeleteRole						( int iFieldIndex );

	// 向 Master 要求某動作後的回傳結果

	virtual void On_DeleteRoleResult				( EM_DeleteRoleResult emResult ) =0;
	virtual void On_CreateRoleResult				( EM_CreateRoleResult emResult ) =0;
	virtual void On_SelectRoleResult				( EM_SelectRoleResult emResult, int iDBID ) =0;

	// 向 Master 要求重發所有角色資料
	static void RquestRoleData						();

	// Login Event
	virtual void On_EnterWorld						( int iDBID, SampleRoleData* pSampleRole ) = 0;
	virtual	void On_LeaveWorld						( int iDBID ) = 0;

#ifdef _AUTOLOGIN
	static bool		m_bAutoLogin;
	static char		m_szAutoLogingID[32];
	static char		m_szAutoLogingPW[32];
	static int		m_iAutoLoginRoleID;
#endif
};
