#ifndef		__CLINETWAKER_H__
#define		__CLINETWAKER_H__
#pragma warning (disable:4786)

#include "CliNetWakerClass.h"
#pragma unmanaged
//***********************************************************************************
// 定義回Call 函式
// 用來註冊函式的指標 ， 如果有事件發生就會呼叫登錄的函式

typedef void (*OnLoginFunctionBase)			    ( string info );
typedef void (*OnLogoutFunctionBase)		    ( );
typedef void (*OnLoginFailFunctionBase)		    ( SYSLogFailedENUM );	

typedef void (*OnSrvConnectFunctionBase)	    ( int id , string GSrvName );	
typedef void (*OnSrvDisconnectFunctionBase)	    ( int id );	
typedef void (*OnSrvPacketFunctionBase)		    ( int id , int size , void* data);	

typedef void (*OnCliConnectFunctionBase)	    ( int id , string accountname );	
typedef void (*OnCliDisconnectFunctionBase)	    ( int id );	
//typedef void (*OnCliPacketFunctionBase)		( int id , int size , void* data);	
typedef void (*OnSrvMsgFunctionBase)		    ( char* msg);	

typedef void (*OnCliReloginByOtherFunctionBase)	( int IPNum );	
//-----------------------------------------------------------------------------------
class	CliNetWaker;
//-----------------------------------------------------------------------------------
//CallBack class 設定
class NetListener: public NewWakerEventListener
{
    CliNetWaker* _Parent;
public:
    NetListener( CliNetWaker* value ){ _Parent = value; };

    void	OnLogin				( string info );
    void	OnLogout			( );
    void	OnLoginFailed		( SYSLogFailedENUM type );

    void    OnGSrvConnected     ( int id , string GSrvName);
    void    OnGSrvDisconnected  ( int id );
    bool    OnGSrvPacket        ( int id, int size , void* data );	

    void	OnServerMsg			( char* Msg);

    void    OnCliReloginByOther ( int IPNum );
};
//-----------------------------------------------------------------------------------
class	CliNetWaker 
{
    friend  NetListener;

    CliNetWakerClass*  	 _Net;
    NetListener*         _Listener;
   //-----------------------------------------------------------------------------------
    //執行狀態
    //-----------------------------------------------------------------------------------
    int	    _ExitFlag;

    int      _ProcTime;

    //------------------------------------------------------------------------------------------
    //紀錄登入事件函式的資料
    vector< OnLoginFunctionBase >			    _LoginFunctionList;
    vector< OnLogoutFunctionBase >			    _LogoutFunctionList;
    vector< OnLoginFailFunctionBase >		    _LoginFailFunctionList;

    vector< OnSrvConnectFunctionBase >		    _SrvConnectFunctionList;
    vector< OnSrvDisconnectFunctionBase >	    _SrvDisconnectFunctionList;
    vector< OnSrvPacketFunctionBase >		    _SrvPacketFunctionList;

    vector< OnSrvMsgFunctionBase >			    _SrvMsgFunctionList;
    vector< OnCliReloginByOtherFunctionBase >   _CliReloginByOtherFunctionList;


    void	_OnLogin				( string info );
    void	_OnLogout				( );
    void	_OnLoginFailed			( SYSLogFailedENUM type );

    void	_OnGSrvConnected		( int id , string GSrvName );
    void	_OnGSrvDisconnected	    ( int id );
    bool	_OnGSrvPacket			( int id , int size , PacketBase* data );

    void	_OnServerMsg			( char*	Msg );

    void    _OnCliReloginByOther    ( int IPNum );

public:

//    bool Init( );
    //bool Release( );
    CliNetWaker();
    ~CliNetWaker();

    //GateWay 資料交換處理
    bool	Process( );
    //設定多久處理一次( 1/1000 )
//    static void SetProcTime( );
    //連到 Switch Server
    void Connect( char* SwitchIP , int SwitchPort , char* Account , char* Password );
    //把自己Logout
    void	Logout( );
    //-------------------------------------------------------------------------------------------
//    static char*	GetCliIPAddr	( int	CliId );			//取得某一個 Client的IPAddr
    //-------------------------------------------------------------------------------------------
    //送封包給 Server 
    bool	SendToSrv( int SrvID , int Size , void*	Buf );	
    //-------------------------------------------------------------------------------------------
    
    //登錄事件的函式 (ret true 為成功 false 為失敗)
    bool RegOnLoginFunction			( OnLoginFunctionBase );
    bool RegOnLogoutFunction		( OnLogoutFunctionBase );
    bool RegOnLoginFailFunction		( OnLoginFailFunctionBase ); 

    bool RegOnSrvConnectFunction	( OnSrvConnectFunctionBase );
    bool RegOnSrvDisConnectFunction	( OnSrvDisconnectFunctionBase );
    //已登入過的封包id不可重覆登入
    bool RegOnSrvPacketFunction		( int PGid , OnSrvPacketFunctionBase );

    bool RegOnSrvMsgFunction		(  OnSrvMsgFunctionBase );
    
    bool    RegOnCliReloginByOther  ( OnCliReloginByOtherFunctionBase );
    //-------------------------------------------------------------------------------------------
};

#pragma managed
//-----------------------------------------------------------------------------------
#endif  //__CLINETWAKER_H__
