2022-02-06 16:48:52 +01:00
|
|
|
#pragma once
|
2023-04-08 18:52:33 +02:00
|
|
|
#include "tier1/NetAdr.h"
|
2022-02-08 16:32:00 +01:00
|
|
|
#include "common/igameserverdata.h"
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: container class to handle network streams
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
class CSocketCreator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSocketCreator(void);
|
|
|
|
~CSocketCreator(void);
|
|
|
|
|
|
|
|
void RunFrame(void);
|
|
|
|
void ProcessAccept(void);
|
|
|
|
|
2023-04-16 00:28:33 +02:00
|
|
|
bool CreateListenSocket(const netadr_t& netAdr, bool bDualStack = true);
|
2022-02-06 16:48:52 +01:00
|
|
|
void CloseListenSocket(void);
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
int ConnectSocket(const netadr_t& netAdr, bool bSingleSocket);
|
2023-04-22 16:02:54 +02:00
|
|
|
void DisconnectSocket(SocketHandle_t hSocket);
|
|
|
|
void DisconnectSockets(void);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-04-19 01:35:31 +02:00
|
|
|
bool ConfigureSocket(SocketHandle_t hSocket, bool bDualStack = true);
|
2023-01-29 15:24:24 +01:00
|
|
|
int OnSocketAccepted(SocketHandle_t hSocket, const netadr_t& netAdr);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
void CloseAcceptedSocket(int nIndex);
|
|
|
|
void CloseAllAcceptedSockets(void);
|
|
|
|
|
|
|
|
bool IsListening(void) const;
|
|
|
|
bool IsSocketBlocking(void) const;
|
|
|
|
|
2023-03-13 20:39:49 +01:00
|
|
|
int GetAuthorizedSocketCount(void) const;
|
2022-02-06 16:48:52 +01:00
|
|
|
int GetAcceptedSocketCount(void) const;
|
2023-03-13 20:39:49 +01:00
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
SocketHandle_t GetAcceptedSocketHandle(int nIndex) const;
|
2023-01-29 15:24:24 +01:00
|
|
|
const netadr_t& GetAcceptedSocketAddress(int nIndex) const;
|
2023-08-04 10:48:22 +02:00
|
|
|
CConnectedNetConsoleData& GetAcceptedSocketData(int nIndex);
|
|
|
|
const CConnectedNetConsoleData& GetAcceptedSocketData(int nIndex) const;
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct AcceptedSocket_t
|
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
AcceptedSocket_t(SocketHandle_t hSocket)
|
|
|
|
: m_hSocket(hSocket)
|
|
|
|
, m_Data(hSocket)
|
|
|
|
{}
|
2023-03-13 20:39:49 +01:00
|
|
|
|
|
|
|
SocketHandle_t m_hSocket;
|
|
|
|
netadr_t m_Address;
|
2023-08-04 10:48:22 +02:00
|
|
|
CConnectedNetConsoleData m_Data;
|
2022-02-06 16:48:52 +01:00
|
|
|
};
|
|
|
|
|
2023-08-04 12:44:46 +02:00
|
|
|
private:
|
2023-08-04 10:48:22 +02:00
|
|
|
CUtlVector<AcceptedSocket_t> m_AcceptedSockets;
|
2023-01-29 15:24:24 +01:00
|
|
|
SocketHandle_t m_hListenSocket; // Used to accept connections.
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SOCKET_TCP_MAX_ACCEPTS = 2
|
|
|
|
};
|
|
|
|
};
|