📄 networkbase.h
字号:
/*///////////////////////////////////////////////////////////////////////////
UDP连接封装管理
处理等待中的连接通知
李亦
2006.6.15
/*///////////////////////////////////////////////////////////////////////////
#ifndef _NETWORKBASE_H_
#define _NETWORKBASE_H_
struct PacketReceiveEvent;
class NetConnection;
namespace CS
{
class CAuthSocket;
/// @see NetConnection, GameConnection, NetObject, NetEvent
class INetworkBase
{
protected:
//NetManager* m_pNetManager;
Vector<NetConnection *> mPendingConnections; ///< List of connections that are in the startup phase.
U32 mLastTimeoutCheckTime; ///< Last time all the active connections were checked for timeouts.
U32 mRandomHashData[12]; ///< Data that gets hashed with connect challenge requests to prevent connection spoofing.
bool mRandomDataInitialized; ///< Have we initialized our random number generator?
bool mAllowConnections; ///< Is this INetworkBase allowing connections at this time?
enum NetInterfaceConstants
{
MaxPendingConnects = 20, ///< Maximum number of pending connections. If new connection requests come in before
TimeoutCheckInterval = 1500, ///< Interval in milliseconds between checking for connection timeouts.
};
/// Initialize random data.
void InitRandomData();
/// @name Connection management
/// Most of these are pretty self-explanatory.
/// @{
void addPendingConnection(NetConnection *conn);
NetConnection *findPendingConnection(const NetAddress *address, U32 packetSequence);
void removePendingConnection(NetConnection *conn);
/// @}
/// Calculate an MD5 sum representing a connection, and store it into addressDigest.
void computeNetMD5(const NetAddress *address, U32 connectSequence, U32 addressDigest[4]);
public:
INetworkBase();
/// Returns whether or not this INetworkBase allows connections from remote hosts.
bool doesAllowConnections() { return mAllowConnections; }
/// Sets whether or not this INetworkBase allows connections from remote hosts.
void setAllowsConnections(bool conn) { mAllowConnections = conn; }
/// Checks for timeouts on all valid and pending connections.
virtual void CheckTimeouts();
/// Dispatch function for processing all network packets through this INetworkBase.
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 packetType, BitStream *stream)=0;
/// Begins the connection handshaking process for a connection.
virtual void CltStartConnection()=0;
virtual void SvrAcceptConnection()=0;
virtual void SvrListenConnection(CAuthSocket *pSocketMain)=0;
/// Send a disconnect packet on a connection, along with a reason.
virtual void SvrSendDisconnectPacket(CSTR szReason)=0;
};
};//namespace RPGServer
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -