diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vmpi/vmpi_service/service_conn_mgr.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/vmpi/vmpi_service/service_conn_mgr.h')
| -rw-r--r-- | utils/vmpi/vmpi_service/service_conn_mgr.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/utils/vmpi/vmpi_service/service_conn_mgr.h b/utils/vmpi/vmpi_service/service_conn_mgr.h new file mode 100644 index 0000000..c5f9558 --- /dev/null +++ b/utils/vmpi/vmpi_service/service_conn_mgr.h @@ -0,0 +1,92 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef SERVICE_CONN_MGR_H +#define SERVICE_CONN_MGR_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "utllinkedlist.h" +#include "utlvector.h" +#include "tcpsocket.h" +#include "ThreadedTCPSocketEmu.h" + + +class CServiceConn +{ +public: + CServiceConn(); + ~CServiceConn(); + + int m_ID; + ITCPSocket *m_pSocket; + DWORD m_LastRecvTime; +}; + + +// ------------------------------------------------------------------------------------------ // +// CServiceConnMgr. This class manages connections to all the UIs (there should only be one UI at +// any given time, but it's conceivable that multiple people can be logged into NT servers +// simultaneously). +// ------------------------------------------------------------------------------------------ // + +class CServiceConnMgr +{ +public: + + CServiceConnMgr(); + ~CServiceConnMgr(); + + bool InitServer(); // Registers as a systemwide server. + bool InitClient(); // Connects to the server. + void Term(); + + // Returns true if there are any connections. If you used InitClient() and there are + // no connections, it will continuously try to connect with a server. + bool IsConnected(); + + // This should be called as often as possible. It checks for dead connections and it + // handles incoming packets from UIs. + void Update(); + + // This sends out a message. If id is -1, then it sends to all connections. + void SendPacket( int id, const void *pData, int len ); + + +// Overridables. +public: + + virtual void OnNewConnection( int id ); + virtual void OnTerminateConnection( int id ); + virtual void HandlePacket( const char *pData, int len ); + + +private: + + void AttemptConnect(); + + +private: + + CUtlLinkedList<CServiceConn*, int> m_Connections; + + bool m_bShuttingDown; + + // This tells if we're running as a client or server. + bool m_bServer; + + // If we're a client, this is the last time we tried to connect. + DWORD m_LastConnectAttemptTime; + + // If we're the server, this is the socket we listen on. + ITCPListenSocket *m_pListenSocket; +}; + + +#endif // SERVICE_CONN_MGR_H |