⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netgateway.h

📁 五行MMORPG引擎系统V1.0
💻 H
字号:
/*///////////////////////////////////////////////////////////////////////////
UDP连接封装管理
	处理等待中的连接通知

李亦
2006.6.15
/*///////////////////////////////////////////////////////////////////////////



#ifndef _NETGATEWAY_H_
#define _NETGATEWAY_H_

#ifndef _NETWORKBASE_H_
#include "server/net/networkBase.h"
#endif


namespace CS
{
class NetManager;
class CAuthSocket;


enum EPacketTypes
{
	PT_PACKETNULL						= 0,
   //MasterServerGameTypesRequest  = 2,
   //MasterServerGameTypesResponse = 4,
   //MasterServerListRequest       = 6,
   //MasterServerListResponse      = 8,
   //GameMasterInfoRequest         = 10,
   //GameMasterInfoResponse        = 12,
   //GamePingRequest               = 14,
   //GamePingResponse              = 16,
   //GameInfoRequest               = 18,
   //GameInfoResponse              = 20,
   //_GameHeartbeat              = 22,

   PT_CHALLENGE_REQUEST       = 26,
   PT_CHALLENGE_REJECT        = 28,
   PT_CHALLENGE_RESPONSE      = 30,
   PT_CONNECT_REQUEST         = 32,
   PT_CONNECT_RESPONSE	      = 34,
   PT_DISCONNECT              = 36,
   //PT_CONNECT_ACCEPT          = 36,
   //PT_CONNECT_REJECT          = 38,


	PT_GAMECOMMAND			= 253,
	PT_GAMENORMAL			= 255,
};


/// @see NetConnection, GameConnection, NetObject, NetEvent
class NetGateway : public INetworkBase
{
	friend class CS::CAuthSocket;
	typedef INetworkBase Parent;
	/// 在每一数据包的头一字节,记录着PacketType信息
	/// 如果LSB为普通数据包时,头1字节设为奇数
	/// 否则认为是OOB包,如掌握过程处理、连接初始化、服务器查询...

protected:

   enum NetShakeHandConstants
   {
      ChallengeRetryCount = 4,      ///< Number of times to send connect challenge requests before giving up.
      ChallengeRetryTime  = 2500,   ///< Timeout interval in milliseconds before retrying connect challenge.

      ConnectRetryCount    = 4,     ///< Number of times to send connect requests before giving up.
      ConnectRetryTime     = 2500,  ///< Timeout interval in milliseconds before retrying connect request.
   };


   /// @name Connection management
   /// Most of these are pretty self-explanatory.
   /// @{


   void	CltSendChallengeRequest		(/*NetConnection *conn*/);
   void	SvrHandleChallengeRequest	(const NetAddress *addr, BitStream *stream);

   void	CltHandleChallengeResponse(const NetAddress *address, BitStream *stream);

   void	CltSendConnectRequest	(/*NetConnection *conn*/);
   void	SvrHandleConnectRequest	(const NetAddress *address, BitStream *stream);

   void	SvrSendConnectResponse	(BOOL bAccept,CSTR szReason=NULL);
   void	CltHandleConnectResponse(const NetAddress *address, BitStream *stream);

   //void	SvrSendConnectReject		(/*NetConnection *conn,*/ const char *reason);
   //void	CltHandleConnectReject	(const NetAddress *address, BitStream *stream);

   void	CltHandleDisconnect		(const NetAddress *address, BitStream *stream);

   /// @}

	//BOOL					m_bAllowConnects;
	CAuthSocket	*m_pSocketMain;
	//CAuthSocket	*m_pSocketNew;
public:
   NetGateway();


	BOOL ClientBlockSequene();
	BOOL ServerBlockSequene(/*CAuthSocket* pSocket*/);

   //bool IsAllowConnections()					{ return mAllowConnections; }
   //void SetAllowsConnections(BOOL bSet)	{ m_bAllowConnects = bSet; }


	virtual BOOL ProcessRecvPackets(BitStream *stream,U8 uPacketType);

   /// Dispatch function for processing all network packets through this NetGateway.
	virtual void processPacketReceiveEvent(PacketReceiveEvent *event){}

   /// Handles all packets that don't fall into the category of connection handshake or game data.
   virtual BOOL HandleInfoPacket(const NetAddress *address, U8 uPacketType, BitStream *stream);


   virtual void CltStartConnection();
   virtual void SvrAcceptConnection(/*CAuthSocket	*pSocketNew*/);
   virtual void SvrListenConnection(CAuthSocket	*pSocketMain);

   /// Checks for timeouts on all valid and pending connections.
   virtual void CheckTimeouts();

   /// Send a disconnect packet on a connection, along with a reason.
   void SvrSendDisconnectPacket(/*NetConnection *conn,*/ CSTR szReason);
};

};//namespace RPGServer

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -