#pragma	once

//#include <WinSock2.h>

//#include "NetBridge_Struct.h"
#include "NetBridge.h"

#pragma warning( push )

	#pragma warning( disable : 4312 )
	#pragma warning( disable : 4711 )
	#pragma warning( disable : 4018 )

	
//	#include "ObjNet\ObjNet.h"
//	#include "ObjNet\lsockutil.h"
	//#include "MyDebug.h"
#pragma warning( pop )

//#include "NetBridge_EventObj.h"


#include <vector>
#include <map>
using namespace std;


struct Struct_PacketCollect
{
	DWORD	dwID;
	DWORD	dwCollectID;
	DWORD	dwTotalSize;
	DWORD	dwIndex;
	DWORD	dwTotal;
	DWORD	dwBufferSize;
	BYTE	Buffer[ 32000 ];
};

struct Struct_PacketAllCollect
{
	DWORD dwCount;
	DWORD dwSize;
	BYTE* pBuff;
};


//class CNetBridge_OLDENGINE;
class CObjEvent;

class CNetBridge_OLDENGINE : public CNetBridge
{
public:
	CNetBridge_OLDENGINE(void);
	virtual ~CNetBridge_OLDENGINE(void);

	virtual int			Init				();
	
	virtual	int			Host				( DWORD dwIP , WORD wPort, CEventObj* pEventObj, BOOL bCompress = false , BOOL bEncryption = false );
	virtual int			Connect				( DWORD dwIP , WORD wPort, CEventObj* pEventObj );

	virtual void		_Send				( DWORD dwNetID, DWORD dwSize, PVOID pBuffer, DWORD dwPriority =0, DWORD dwFlag =0 );
	virtual void		SendToAll			( DWORD dwSize, PVOID pPacket );
	virtual void		Flush				();
	virtual void		Close				( DWORD dwNetID );
	virtual DWORD		Wait				( DWORD dwTime );

	virtual void		GetConnectInfo		( DWORD dwNetID, DWORD* pdwIP, WORD* pwPort );

	virtual void		SetOutPutCB			( pfOutPutCB pFun ){ m_pFun = pFun; }
	virtual void		GetStatusInfo		( char* pszOut );

	virtual	bool		Shutdown			() { return true; };

	map< DWORD, Struct_PacketAllCollect >	m_mapCollect;


	DWORD					m_dwPacketCollectIndex;
	pfOutPutCB				m_pFun;
	IObjNet*				m_pObjnet;
	vector< CObjEvent* >	m_vecDelEvent;
};


class CObjEvent : public INewConnectionListener, public INetEventListener
{
	CNetBridge_OLDENGINE*	m_pEngine;
	CEventObj*				m_pEventObj;
public:
	CObjEvent( CNetBridge_OLDENGINE* pEngine, CEventObj* pEventobj ) { m_pEngine = pEngine; m_pEventObj = pEventobj; }
	INetEventListener* LSAPI	OnNewConnection	( LNETID NetID );
	void LSAPI					OnConnected     ( LNETID NetID );
	void LSAPI					OnDisconnected  ( LNETID NetID );
	void LSAPI					OnPeerShutdown  ( LNETID NetID ) {}
	bool LSAPI					OnPacket        ( LNETID NetID, HBUFFER hIncomingData );
	void LSAPI					OnConnectFailed ( int NetID );

};

