DragonNest/Server/ServiceMonitorEx/Source/NetConnection.h
2024-12-20 16:56:44 +08:00

64 lines
3.2 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "NetSession.h"
#include "NetPacketParser.h"
#include "Singleton.hpp"
#include "CriticalSection.hpp"
#include "ServiceInfo.h"
class CNetConnection
{
public:
CNetConnection();
virtual ~CNetConnection();
DWORD Open();
VOID Close();
BOOL IsOpen() const { return(m_IsOpen);}
CNetSession* GetSession();
VOID ReleaseSession(CNetSession* pNetSession);
CServiceInfo* GetServiceInfo ();
private:
static VOID TcpClientErrorNotifyProc(LPVOID pModule, INT pErrorCode, LPCTSTR pErrorMessage, LPVOID pErrorNotifyProcParam);
static VOID TcpClientSessionBaseNotifyProc(EF_NETWORK_BASE_NOFITY pNotifyType, CSessionBase* pSession, LPVOID pResultParam, LPVOID pBaseNotifyProcParam);
static DWORD PacketNotify(LPVOID pSession, SHORT pMainCmd, SHORT pSubCmd, LPBYTE pBuffer, SHORT pPacketLen);
public:
static VOID SendRequestServiceStruct(CNetSession* pNetSession, INT pContainerVersion /* = -1 */);
private:
BOOL m_IsOpen;
CEventSelectTcpClient<CNetSession> m_TcpClient;
CNetPacketParser m_PacketParser;
CNetSession* m_pNetSession;
};
class CNetConnectionMgr
{
private:
DECLARE_SINGLETON_CLASS(CNetConnectionMgr);
public:
CNetConnectionMgr();
~CNetConnectionMgr();
CNetConnection* CreateConnection();
CNetConnection* GetConnection (UINT nConID);
void RemoveConnection (UINT nConID);
void RegistConnection (CNetConnection* pNetCon);
CNetSession* GetCurrentSession();
private:
std::map<UINT, CNetConnection*> m_MapNetConnections;
INT m_nConnectionID;
mutable CCriticalSection m_Lock;
CNetSession* m_CurrentSession;
};