2022-02-06 16:48:52 +01:00
|
|
|
#pragma once
|
2023-01-29 15:24:24 +01: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);
|
|
|
|
|
|
|
|
bool ConfigureListenSocket(int iSocket);
|
|
|
|
bool ConfigureConnectSocket(SocketHandle_t hSocket);
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
bool CreateListenSocket(const netadr_t& netAdr, bool bListenOnAllInterfaces = false);
|
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);
|
2022-02-06 16:48:52 +01:00
|
|
|
void DisconnectSocket(void);
|
|
|
|
|
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;
|
2022-02-06 16:48:52 +01:00
|
|
|
CConnectedNetConsoleData* GetAcceptedSocketData(int nIndex) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct AcceptedSocket_t
|
|
|
|
{
|
2023-03-13 20:39:49 +01:00
|
|
|
AcceptedSocket_t(void)
|
|
|
|
{
|
|
|
|
m_hSocket = NULL;
|
|
|
|
m_pData = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SocketHandle_t m_hSocket;
|
|
|
|
netadr_t m_Address;
|
|
|
|
CConnectedNetConsoleData* m_pData;
|
2022-02-06 16:48:52 +01:00
|
|
|
};
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
std::vector<AcceptedSocket_t> m_hAcceptedSockets;
|
|
|
|
SocketHandle_t m_hListenSocket; // Used to accept connections.
|
|
|
|
netadr_t m_ListenAddress; // Address used to listen on.
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SOCKET_TCP_MAX_ACCEPTS = 2
|
|
|
|
};
|
|
|
|
};
|