📄 netudp.h
字号:
/*///////////////////////////////////////////////////////////////////////////
UDP连接封装管理
处理等待中的连接通知
李亦
2006.6.15
/*///////////////////////////////////////////////////////////////////////////
#ifndef _NETUDP_H_
#define _NETUDP_H_
#ifndef _NETWORKBASE_H_
#include "server/net/networkBase.h"
#endif
namespace RPGServer
{
class NetManager;
/// @see NetConnection, GameConnection, NetObject, NetEvent
class NetUDP : public INetworkBase
{
typedef INetworkBase Parent;
/// 在每一数据包的头一字节,记录着PacketType信息
/// 如果LSB为普通数据包时,头1字节设为奇数
/// 否则认为是OOB包,如掌握过程处理、连接初始化、服务器查询...
enum PacketTypes
{
MasterServerGameTypesRequest = 2,
MasterServerGameTypesResponse = 4,
MasterServerListRequest = 6,
MasterServerListResponse = 8,
GameMasterInfoRequest = 10,
GameMasterInfoResponse = 12,
GamePingRequest = 14,
GamePingResponse = 16,
GameInfoRequest = 18,
GameInfoResponse = 20,
GameHeartbeat = 22,
ConnectChallengeRequest = 26,
ConnectChallengeReject = 28,
ConnectChallengeResponse = 30,
ConnectRequest = 32,
ConnectReject = 34,
ConnectAccept = 36,
Disconnect = 38,
};
protected:
enum NetInterfaceConstants
{
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 sendConnectChallengeRequest(NetConnection *conn);
void handleConnectChallengeRequest(const NetAddress *addr, BitStream *stream);
void handleConnectChallengeResponse(const NetAddress *address, BitStream *stream);
void sendConnectRequest(NetConnection *conn);
void handleConnectRequest(const NetAddress *address, BitStream *stream);
void sendConnectAccept(NetConnection *conn);
void handleConnectAccept(const NetAddress *address, BitStream *stream);
void sendConnectReject(NetConnection *conn, const char *reason);
void handleConnectReject(const NetAddress *address, BitStream *stream);
void handleDisconnect(const NetAddress *address, BitStream *stream);
/// @}
public:
NetUDP(NetManager*);
/// Dispatch function for processing all network packets through this NetUDP.
virtual void processPacketReceiveEvent(PacketReceiveEvent *event);
/// Handles all packets that don't fall into the category of connection handshake or game data.
virtual void handleInfoPacket(const NetAddress *address, U8 packetType, BitStream *stream);
/// Begins the connection handshaking process for a connection.
virtual void startConnection(NetConnection *conn);
/// Checks for timeouts on all valid and pending connections.
virtual void checkTimeouts();
/// Send a disconnect packet on a connection, along with a reason.
void sendDisconnectPacket(NetConnection *conn, const char *reason);
};
};//namespace RPGServer
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -