2022-02-06 16:48:52 +01:00
|
|
|
//===========================================================================//
|
|
|
|
//
|
|
|
|
// Purpose: Server/Client dual-stack socket utility class
|
|
|
|
//
|
|
|
|
//===========================================================================//
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
#include <tier1/NetAdr.h>
|
2022-02-06 16:48:52 +01:00
|
|
|
#include <tier2/socketcreator.h>
|
|
|
|
#ifndef NETCONSOLE
|
|
|
|
#include <engine/sys_utils.h>
|
|
|
|
#endif // !NETCONSOLE
|
|
|
|
#include <engine/net.h>
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Constructor
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CSocketCreator::CSocketCreator(void)
|
|
|
|
{
|
2023-04-19 01:35:31 +02:00
|
|
|
m_hListenSocket = SOCKET_ERROR;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Destructor
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CSocketCreator::~CSocketCreator(void)
|
|
|
|
{
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSockets();
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: accept new connections and walk open sockets and handle any incoming data
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::RunFrame(void)
|
|
|
|
{
|
|
|
|
if (IsListening())
|
|
|
|
{
|
2023-04-16 00:28:33 +02:00
|
|
|
ProcessAccept(); // handle any new connection requests.
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: handle a new connection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::ProcessAccept(void)
|
|
|
|
{
|
|
|
|
sockaddr_storage inClient{};
|
|
|
|
int nLengthAddr = sizeof(inClient);
|
2023-04-02 17:23:53 +02:00
|
|
|
SocketHandle_t newSocket = SocketHandle_t(::accept(SOCKET(m_hListenSocket), reinterpret_cast<sockaddr*>(&inClient), &nLengthAddr));
|
2023-04-16 00:28:33 +02:00
|
|
|
if (newSocket == SOCKET_ERROR)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
|
|
|
if (!IsSocketBlocking())
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Error(eDLL_T::COMMON, NO_ERROR, "%s - Error: %s\n", __FUNCTION__, NET_ErrorString(WSAGetLastError()));
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-16 00:28:33 +02:00
|
|
|
if (!ConfigureSocket(newSocket, false))
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(newSocket);
|
2022-02-06 16:48:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
netadr_t netAdr;
|
|
|
|
netAdr.SetFromSockadr(&inClient);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
OnSocketAccepted(newSocket, netAdr);
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: bind to a TCP port and accept incoming connections
|
2023-01-29 15:24:24 +01:00
|
|
|
// Input : *netAdr -
|
2023-04-16 00:28:33 +02:00
|
|
|
// bDualStack -
|
2022-02-06 16:48:52 +01:00
|
|
|
// Output : true on success, failed otherwise
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-04-16 00:28:33 +02:00
|
|
|
bool CSocketCreator::CreateListenSocket(const netadr_t& netAdr, bool bDualStack)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
|
|
|
CloseListenSocket();
|
2023-04-02 17:23:53 +02:00
|
|
|
m_hListenSocket = SocketHandle_t(::socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP));
|
2022-02-06 16:48:52 +01:00
|
|
|
|
|
|
|
if (m_hListenSocket != INVALID_SOCKET)
|
|
|
|
{
|
2023-04-16 00:28:33 +02:00
|
|
|
if (!ConfigureSocket(m_hListenSocket, bDualStack))
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
|
|
|
CloseListenSocket();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sockaddr_storage sadr{};
|
2023-04-16 00:28:33 +02:00
|
|
|
netAdr.ToSockadr(&sadr);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
int results = ::bind(m_hListenSocket, reinterpret_cast<sockaddr*>(&sadr), sizeof(sockaddr_in6));
|
2023-04-16 00:28:33 +02:00
|
|
|
if (results == SOCKET_ERROR)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket bind failed (%s)\n", NET_ErrorString(WSAGetLastError()));
|
2022-02-06 16:48:52 +01:00
|
|
|
CloseListenSocket();
|
2023-01-29 15:24:24 +01:00
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-08 16:32:00 +01:00
|
|
|
results = ::listen(m_hListenSocket, SOCKET_TCP_MAX_ACCEPTS);
|
2023-04-16 00:28:33 +02:00
|
|
|
if (results == SOCKET_ERROR)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket listen failed (%s)\n", NET_ErrorString(WSAGetLastError()));
|
2022-02-06 16:48:52 +01:00
|
|
|
CloseListenSocket();
|
2023-01-29 15:24:24 +01:00
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: close an open rcon connection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::CloseListenSocket(void)
|
|
|
|
{
|
2023-04-16 00:28:33 +02:00
|
|
|
if (m_hListenSocket != SOCKET_ERROR)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(m_hListenSocket);
|
2023-04-16 00:28:33 +02:00
|
|
|
m_hListenSocket = SOCKET_ERROR;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: connect to the remote server
|
2023-01-29 15:24:24 +01:00
|
|
|
// Input : *netAdr -
|
2023-04-16 00:28:33 +02:00
|
|
|
// bSingleSocket -
|
2022-02-06 16:48:52 +01:00
|
|
|
// Output : accepted socket index, SOCKET_ERROR (-1) if failed
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-01-29 15:24:24 +01:00
|
|
|
int CSocketCreator::ConnectSocket(const netadr_t& netAdr, bool bSingleSocket)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
|
|
|
if (bSingleSocket)
|
2023-04-16 00:28:33 +02:00
|
|
|
{ // NOTE: Closing an accepted socket will re-index all the sockets with higher indices.
|
2022-02-06 16:48:52 +01:00
|
|
|
CloseAllAcceptedSockets();
|
|
|
|
}
|
|
|
|
|
2023-04-02 17:23:53 +02:00
|
|
|
SocketHandle_t hSocket = SocketHandle_t(::socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP));
|
2022-02-06 16:48:52 +01:00
|
|
|
if (hSocket == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Unable to create socket (%s)\n", NET_ErrorString(WSAGetLastError()));
|
2022-02-06 16:48:52 +01:00
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
2023-04-16 00:28:33 +02:00
|
|
|
if (!ConfigureSocket(hSocket))
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(hSocket);
|
2022-02-06 16:48:52 +01:00
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sockaddr_storage s{};
|
2023-01-29 15:24:24 +01:00
|
|
|
netAdr.ToSockadr(&s);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
int results = ::connect(hSocket, reinterpret_cast<sockaddr*>(&s), sizeof(sockaddr_in6));
|
2022-02-06 16:48:52 +01:00
|
|
|
if (results == SOCKET_ERROR)
|
|
|
|
{
|
|
|
|
if (!IsSocketBlocking())
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket connection failed (%s)\n", NET_ErrorString(WSAGetLastError()));
|
2023-01-29 15:24:24 +01:00
|
|
|
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(hSocket);
|
2022-02-06 16:48:52 +01:00
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd_set writefds{};
|
|
|
|
timeval tv{};
|
|
|
|
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
tv.tv_sec = 1;
|
|
|
|
|
|
|
|
FD_ZERO(&writefds);
|
|
|
|
FD_SET(static_cast<u_int>(hSocket), &writefds);
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
if (::select(hSocket + 1, NULL, &writefds, NULL, &tv) < 1) // block for at most 1 second.
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket connection timed out\n");
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(hSocket); // took too long to connect to, give up.
|
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
return SOCKET_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: CRConClient check if connected.
|
|
|
|
|
2023-01-29 15:24:24 +01:00
|
|
|
int nIndex = OnSocketAccepted(hSocket, netAdr);
|
2022-02-06 16:48:52 +01:00
|
|
|
return nIndex;
|
|
|
|
}
|
|
|
|
|
2023-04-22 16:02:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: closes specific open sockets (listen + accepted)
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::DisconnectSocket(SocketHandle_t hSocket)
|
|
|
|
{
|
|
|
|
Assert(hSocket != SOCKET_ERROR);
|
|
|
|
if (::closesocket(hSocket) == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Error(eDLL_T::COMMON, NO_ERROR, "Unable to close socket (%s)\n",
|
2023-04-22 16:02:54 +02:00
|
|
|
NET_ErrorString(WSAGetLastError()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: closes all open sockets (listen + accepted)
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-04-22 16:02:54 +02:00
|
|
|
void CSocketCreator::DisconnectSockets(void)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
|
|
|
CloseListenSocket();
|
|
|
|
CloseAllAcceptedSockets();
|
|
|
|
}
|
|
|
|
|
2023-04-19 01:35:31 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: Configures a socket for use
|
|
|
|
// Input : iSocket -
|
|
|
|
// bDualStack -
|
|
|
|
// Output : true on success, false otherwise
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CSocketCreator::ConfigureSocket(SocketHandle_t hSocket, bool bDualStack /*= true*/)
|
|
|
|
{
|
|
|
|
// Disable NAGLE as RCON cmds are small in size.
|
|
|
|
int opt = 1;
|
|
|
|
int ret = ::setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&opt), sizeof(opt));
|
|
|
|
if (ret == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket 'sockopt(%s)' failed (%s)\n", "TCP_NODELAY", NET_ErrorString(WSAGetLastError()));
|
2023-04-19 01:35:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark socket as reusable.
|
|
|
|
opt = 1;
|
|
|
|
ret = ::setsockopt(hSocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&opt), sizeof(opt));
|
|
|
|
if (ret == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket 'sockopt(%s)' failed (%s)\n", "SO_REUSEADDR", NET_ErrorString(WSAGetLastError()));
|
2023-04-19 01:35:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bDualStack)
|
|
|
|
{
|
|
|
|
// Disable IPv6 only mode to enable dual stack.
|
|
|
|
opt = 0;
|
|
|
|
ret = ::setsockopt(hSocket, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<char*>(&opt), sizeof(opt));
|
|
|
|
if (ret == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket 'sockopt(%s)' failed (%s)\n", "IPV6_V6ONLY", NET_ErrorString(WSAGetLastError()));
|
2023-04-19 01:35:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark socket as non-blocking.
|
|
|
|
opt = 1;
|
|
|
|
ret = ::ioctlsocket(hSocket, FIONBIO, reinterpret_cast<u_long*>(&opt));
|
|
|
|
if (ret == SOCKET_ERROR)
|
|
|
|
{
|
2023-07-22 21:14:04 +02:00
|
|
|
Warning(eDLL_T::COMMON, "Socket 'ioctl(%s)' failed (%s)\n", "FIONBIO", NET_ErrorString(WSAGetLastError()));
|
2023-04-19 01:35:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: handles new TCP requests and puts them in accepted queue
|
|
|
|
// Input : hSocket -
|
2023-01-29 15:24:24 +01:00
|
|
|
// *netAdr -
|
2022-02-06 16:48:52 +01:00
|
|
|
// Output : accepted socket index, -1 if failed
|
|
|
|
//-----------------------------------------------------------------------------
|
2023-01-29 15:24:24 +01:00
|
|
|
int CSocketCreator::OnSocketAccepted(SocketHandle_t hSocket, const netadr_t& netAdr)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
AcceptedSocket_t newEntry(hSocket);
|
2023-01-29 15:24:24 +01:00
|
|
|
newEntry.m_Address = netAdr;
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-08-04 10:48:22 +02:00
|
|
|
m_AcceptedSockets.AddToTail(newEntry);
|
2022-02-06 16:48:52 +01:00
|
|
|
|
2023-08-04 10:48:22 +02:00
|
|
|
int nIndex = m_AcceptedSockets.Count() - 1;
|
2022-02-06 16:48:52 +01:00
|
|
|
return nIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: close an accepted socket
|
|
|
|
// Input : nIndex -
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::CloseAcceptedSocket(int nIndex)
|
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
if (nIndex >= m_AcceptedSockets.Count())
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-04-16 15:51:16 +02:00
|
|
|
Assert(0);
|
2022-02-06 16:48:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-04 10:48:22 +02:00
|
|
|
AcceptedSocket_t& connected = m_AcceptedSockets[nIndex];
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(connected.m_hSocket);
|
2022-08-02 23:58:43 +02:00
|
|
|
|
2023-08-04 10:48:22 +02:00
|
|
|
m_AcceptedSockets.Remove(nIndex);
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: close all accepted sockets
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void CSocketCreator::CloseAllAcceptedSockets(void)
|
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
for (int i = 0; i < m_AcceptedSockets.Count(); ++i)
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
AcceptedSocket_t& connected = m_AcceptedSockets[i];
|
2023-04-22 16:02:54 +02:00
|
|
|
DisconnectSocket(connected.m_hSocket);
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
2023-08-04 10:48:22 +02:00
|
|
|
m_AcceptedSockets.Purge();
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns true if the listening socket is created and listening
|
2022-06-30 20:21:15 +02:00
|
|
|
// Output : bool
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CSocketCreator::IsListening(void) const
|
|
|
|
{
|
2023-04-19 01:35:31 +02:00
|
|
|
return m_hListenSocket != SOCKET_ERROR;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns true if the socket would block because of the last socket command
|
2022-06-30 20:21:15 +02:00
|
|
|
// Output : bool
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool CSocketCreator::IsSocketBlocking(void) const
|
|
|
|
{
|
|
|
|
return (WSAGetLastError() == WSAEWOULDBLOCK);
|
|
|
|
}
|
|
|
|
|
2023-03-13 20:39:49 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns authorized socket count
|
|
|
|
// Output : int
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int CSocketCreator::GetAuthorizedSocketCount(void) const
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2023-08-04 10:48:22 +02:00
|
|
|
for (int i = 0; i < m_AcceptedSockets.Count(); ++i)
|
2023-03-13 20:39:49 +01:00
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
if (m_AcceptedSockets[i].m_Data.m_bAuthorized)
|
2023-03-13 20:39:49 +01:00
|
|
|
{
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns accepted socket count
|
2022-06-30 20:21:15 +02:00
|
|
|
// Output : int
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
int CSocketCreator::GetAcceptedSocketCount(void) const
|
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
return m_AcceptedSockets.Count();
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns accepted socket handle
|
2022-06-30 20:21:15 +02:00
|
|
|
// Input : nIndex -
|
|
|
|
// Output : SocketHandle_t
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
SocketHandle_t CSocketCreator::GetAcceptedSocketHandle(int nIndex) const
|
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
|
|
|
return m_AcceptedSockets[nIndex].m_hSocket;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns accepted socket address
|
2022-06-30 20:21:15 +02:00
|
|
|
// Input : nIndex -
|
2023-01-29 15:24:24 +01:00
|
|
|
// Output : const netadr_t&
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-01-29 15:24:24 +01:00
|
|
|
const netadr_t& CSocketCreator::GetAcceptedSocketAddress(int nIndex) const
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
|
|
|
return m_AcceptedSockets[nIndex].m_Address;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns accepted socket data
|
|
|
|
// Input : nIndex -
|
|
|
|
// Output : CConnectedNetConsoleData*
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
CConnectedNetConsoleData& CSocketCreator::GetAcceptedSocketData(int nIndex)
|
|
|
|
{
|
|
|
|
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
|
|
|
return m_AcceptedSockets[nIndex].m_Data;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: returns accepted socket data
|
2022-06-30 20:21:15 +02:00
|
|
|
// Input : nIndex -
|
|
|
|
// Output : CConnectedNetConsoleData*
|
2022-02-06 16:48:52 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2023-08-04 10:48:22 +02:00
|
|
|
const CConnectedNetConsoleData& CSocketCreator::GetAcceptedSocketData(int nIndex) const
|
2022-02-06 16:48:52 +01:00
|
|
|
{
|
2023-08-04 10:48:22 +02:00
|
|
|
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
|
|
|
return m_AcceptedSockets[nIndex].m_Data;
|
2022-02-06 16:48:52 +01:00
|
|
|
}
|