mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Pass by reference
CConnectedNetConsoleData was allocated and deallocated manually, but std::vector is able to do it on its own. The vector type has been swapped out with CUtlVector as this removed the need of having to cast size types to a 32bit int to make it more compatible with the other sdk/engine types without throwing compiler warnings.
This commit is contained in:
parent
6eb3388aee
commit
ddfe027677
@ -59,7 +59,7 @@ void CRConClient::RunFrame(void)
|
||||
|
||||
if (pData)
|
||||
{
|
||||
Recv(pData);
|
||||
Recv(*pData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,8 @@ void CRConServer::Think(void)
|
||||
const netadr_t& netAdr = m_Socket.GetAcceptedSocketAddress(m_nConnIndex);
|
||||
if (!m_WhiteListAddress.CompareAdr(netAdr))
|
||||
{
|
||||
const CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
if (!pData->m_bAuthorized)
|
||||
const CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
if (!pData.m_bAuthorized)
|
||||
{
|
||||
Disconnect("redundant");
|
||||
}
|
||||
@ -169,11 +169,11 @@ void CRConServer::RunFrame(void)
|
||||
const int nCount = m_Socket.GetAcceptedSocketCount();
|
||||
for (m_nConnIndex = nCount - 1; m_nConnIndex >= 0; m_nConnIndex--)
|
||||
{
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
|
||||
if (CheckForBan(pData))
|
||||
{
|
||||
SendEncode(pData->m_hSocket, s_BannedMessage, "",
|
||||
SendEncode(pData.m_hSocket, s_BannedMessage, "",
|
||||
sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH, int(eDLL_T::NETCON));
|
||||
|
||||
Disconnect("banned");
|
||||
@ -204,11 +204,11 @@ bool CRConServer::SendToAll(const char* pMsgBuf, const int nMsgLen) const
|
||||
const int nCount = m_Socket.GetAcceptedSocketCount();
|
||||
for (int i = nCount - 1; i >= 0; i--)
|
||||
{
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(i);
|
||||
const CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(i);
|
||||
|
||||
if (pData->m_bAuthorized)
|
||||
if (pData.m_bAuthorized)
|
||||
{
|
||||
int ret = ::send(pData->m_hSocket, sendbuf.str().data(),
|
||||
int ret = ::send(pData.m_hSocket, sendbuf.str().data(),
|
||||
int(sendbuf.str().size()), MSG_NOSIGNAL);
|
||||
|
||||
if (ret == SOCKET_ERROR)
|
||||
@ -317,9 +317,9 @@ bool CRConServer::Serialize(vector<char>& vecBuf, const char* pResponseMsg, cons
|
||||
// Input : &request -
|
||||
// *pData -
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRConServer::Authenticate(const cl_rcon::request& request, CConnectedNetConsoleData* pData)
|
||||
void CRConServer::Authenticate(const cl_rcon::request& request, CConnectedNetConsoleData& pData)
|
||||
{
|
||||
if (pData->m_bAuthorized)
|
||||
if (pData.m_bAuthorized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -327,14 +327,14 @@ void CRConServer::Authenticate(const cl_rcon::request& request, CConnectedNetCon
|
||||
{
|
||||
if (Comparator(request.requestmsg()))
|
||||
{
|
||||
pData->m_bAuthorized = true;
|
||||
pData.m_bAuthorized = true;
|
||||
if (++m_nAuthConnections >= sv_rcon_maxconnections->GetInt())
|
||||
{
|
||||
m_Socket.CloseListenSocket();
|
||||
CloseNonAuthConnection();
|
||||
}
|
||||
|
||||
SendEncode(pData->m_hSocket, s_AuthMessage, sv_rcon_sendlogs->GetString(),
|
||||
SendEncode(pData.m_hSocket, s_AuthMessage, sv_rcon_sendlogs->GetString(),
|
||||
sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH, static_cast<int>(eDLL_T::NETCON));
|
||||
}
|
||||
else // Bad password.
|
||||
@ -345,12 +345,12 @@ void CRConServer::Authenticate(const cl_rcon::request& request, CConnectedNetCon
|
||||
DevMsg(eDLL_T::SERVER, "Bad RCON password attempt from '%s'\n", netAdr.ToString());
|
||||
}
|
||||
|
||||
SendEncode(pData->m_hSocket, s_WrongPwMessage, "",
|
||||
SendEncode(pData.m_hSocket, s_WrongPwMessage, "",
|
||||
sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH, static_cast<int>(eDLL_T::NETCON));
|
||||
|
||||
pData->m_bAuthorized = false;
|
||||
pData->m_bValidated = false;
|
||||
pData->m_nFailedAttempts++;
|
||||
pData.m_bAuthorized = false;
|
||||
pData.m_bValidated = false;
|
||||
pData.m_nFailedAttempts++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -385,7 +385,7 @@ bool CRConServer::Comparator(const string& svPassword) const
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
|
||||
{
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(m_nConnIndex);
|
||||
|
||||
cl_rcon::request request;
|
||||
if (!Decode(&request, pMsgBuf, nMsgLen))
|
||||
@ -394,15 +394,15 @@ bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pData->m_bAuthorized &&
|
||||
if (!pData.m_bAuthorized &&
|
||||
request.requesttype() != cl_rcon::request_t::SERVERDATA_REQUEST_AUTH)
|
||||
{
|
||||
// Notify netconsole that authentication is required.
|
||||
SendEncode(pData->m_hSocket, s_NoAuthMessage, "",
|
||||
SendEncode(pData.m_hSocket, s_NoAuthMessage, "",
|
||||
sv_rcon::response_t::SERVERDATA_RESPONSE_AUTH, static_cast<int>(eDLL_T::NETCON));
|
||||
|
||||
pData->m_bValidated = false;
|
||||
pData->m_nIgnoredMessage++;
|
||||
pData.m_bValidated = false;
|
||||
pData.m_nIgnoredMessage++;
|
||||
return true;
|
||||
}
|
||||
switch (request.requesttype())
|
||||
@ -414,7 +414,7 @@ bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
|
||||
}
|
||||
case cl_rcon::request_t::SERVERDATA_REQUEST_EXECCOMMAND:
|
||||
{
|
||||
if (pData->m_bAuthorized) // Only execute if auth was successful.
|
||||
if (pData.m_bAuthorized) // Only execute if auth was successful.
|
||||
{
|
||||
Execute(request, false);
|
||||
}
|
||||
@ -422,7 +422,7 @@ bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
|
||||
}
|
||||
case cl_rcon::request_t::SERVERDATA_REQUEST_SETVALUE:
|
||||
{
|
||||
if (pData->m_bAuthorized)
|
||||
if (pData.m_bAuthorized)
|
||||
{
|
||||
Execute(request, true);
|
||||
}
|
||||
@ -430,7 +430,7 @@ bool CRConServer::ProcessMessage(const char* pMsgBuf, const int nMsgLen)
|
||||
}
|
||||
case cl_rcon::request_t::SERVERDATA_REQUEST_SEND_CONSOLE_LOG:
|
||||
{
|
||||
if (pData->m_bAuthorized)
|
||||
if (pData.m_bAuthorized)
|
||||
{
|
||||
sv_rcon_sendlogs->SetValue(request.requestval().c_str());
|
||||
}
|
||||
@ -470,9 +470,9 @@ void CRConServer::Execute(const cl_rcon::request& request, const bool bConVar) c
|
||||
// Purpose: checks for amount of failed attempts and bans netconsole accordingly
|
||||
// Input : *pData -
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CRConServer::CheckForBan(CConnectedNetConsoleData* pData)
|
||||
bool CRConServer::CheckForBan(CConnectedNetConsoleData& pData)
|
||||
{
|
||||
if (pData->m_bValidated)
|
||||
if (pData.m_bValidated)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -503,7 +503,7 @@ bool CRConServer::CheckForBan(CConnectedNetConsoleData* pData)
|
||||
}
|
||||
}
|
||||
|
||||
pData->m_bValidated = true;
|
||||
pData.m_bValidated = true;
|
||||
|
||||
// Check if IP is in the banned list.
|
||||
if (m_BannedList.find(szNetAdr) != m_BannedList.end())
|
||||
@ -512,14 +512,14 @@ bool CRConServer::CheckForBan(CConnectedNetConsoleData* pData)
|
||||
}
|
||||
|
||||
// Check if netconsole has reached maximum number of attempts > add to banned list.
|
||||
if (pData->m_nFailedAttempts >= sv_rcon_maxfailures->GetInt()
|
||||
|| pData->m_nIgnoredMessage >= sv_rcon_maxignores->GetInt())
|
||||
if (pData.m_nFailedAttempts >= sv_rcon_maxfailures->GetInt()
|
||||
|| pData.m_nIgnoredMessage >= sv_rcon_maxignores->GetInt())
|
||||
{
|
||||
// Don't add white listed address to banned list.
|
||||
if (m_WhiteListAddress.CompareAdr(netAdr))
|
||||
{
|
||||
pData->m_nFailedAttempts = 0;
|
||||
pData->m_nIgnoredMessage = 0;
|
||||
pData.m_nFailedAttempts = 0;
|
||||
pData.m_nIgnoredMessage = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -545,8 +545,8 @@ void CRConServer::Disconnect(const char* szReason) // NETMGR
|
||||
//-----------------------------------------------------------------------------
|
||||
void CRConServer::Disconnect(const int nIndex, const char* szReason) // NETMGR
|
||||
{
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(nIndex);
|
||||
if (pData->m_bAuthorized || sv_rcon_debug->GetBool())
|
||||
CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(nIndex);
|
||||
if (pData.m_bAuthorized || sv_rcon_debug->GetBool())
|
||||
{
|
||||
// Inform server owner when authenticated connection has been closed.
|
||||
netadr_t netAdr = m_Socket.GetAcceptedSocketAddress(nIndex);
|
||||
@ -570,9 +570,9 @@ void CRConServer::CloseNonAuthConnection(void)
|
||||
int nCount = m_Socket.GetAcceptedSocketCount();
|
||||
for (int i = nCount - 1; i >= 0; i--)
|
||||
{
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(i);
|
||||
CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(i);
|
||||
|
||||
if (!pData->m_bAuthorized)
|
||||
if (!pData.m_bAuthorized)
|
||||
{
|
||||
m_Socket.CloseAcceptedSocket(i);
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ public:
|
||||
bool Serialize(vector<char>& vecBuf, const char* pResponseMsg, const char* pResponseVal, const sv_rcon::response_t responseType,
|
||||
const int nMessageId = static_cast<int>(eDLL_T::NETCON), const int nMessageType = static_cast<int>(LogType_t::LOG_NET)) const;
|
||||
|
||||
void Authenticate(const cl_rcon::request& request, CConnectedNetConsoleData* pData);
|
||||
void Authenticate(const cl_rcon::request& request, CConnectedNetConsoleData& pData);
|
||||
bool Comparator(const string& svPassword) const;
|
||||
|
||||
virtual bool ProcessMessage(const char* pMsgBuf, const int nMsgLen) override;
|
||||
|
||||
void Execute(const cl_rcon::request& request, const bool bConVar) const;
|
||||
bool CheckForBan(CConnectedNetConsoleData* pData);
|
||||
bool CheckForBan(CConnectedNetConsoleData& pData);
|
||||
|
||||
virtual void Disconnect(const char* szReason = nullptr) override;
|
||||
void Disconnect(const int nIndex, const char* szReason = nullptr);
|
||||
|
@ -69,23 +69,16 @@ bool CNetConBase::Send(const SocketHandle_t hSocket, const char* pMsgBuf,
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: receive message
|
||||
// Input : *pData -
|
||||
// Input : &pData -
|
||||
// nMaxLen -
|
||||
// Output: true on success, false otherwise
|
||||
//-----------------------------------------------------------------------------
|
||||
void CNetConBase::Recv(CConnectedNetConsoleData* pData, const int nMaxLen)
|
||||
void CNetConBase::Recv(CConnectedNetConsoleData& pData, const int nMaxLen)
|
||||
{
|
||||
if (!pData)
|
||||
{
|
||||
Error(eDLL_T::ENGINE, NO_ERROR, "RCON Cmd: invalid input data\n");
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
static char szRecvBuf[1024];
|
||||
|
||||
{//////////////////////////////////////////////
|
||||
const int nPendingLen = ::recv(pData->m_hSocket, szRecvBuf, sizeof(char), MSG_PEEK);
|
||||
const int nPendingLen = ::recv(pData.m_hSocket, szRecvBuf, sizeof(char), MSG_PEEK);
|
||||
if (nPendingLen == SOCKET_ERROR && m_Socket.IsSocketBlocking())
|
||||
{
|
||||
return;
|
||||
@ -98,7 +91,7 @@ void CNetConBase::Recv(CConnectedNetConsoleData* pData, const int nMaxLen)
|
||||
}//////////////////////////////////////////////
|
||||
|
||||
int nReadLen = 0; // Find out how much we have to read.
|
||||
int iResult = ::ioctlsocket(pData->m_hSocket, FIONREAD, reinterpret_cast<u_long*>(&nReadLen));
|
||||
int iResult = ::ioctlsocket(pData.m_hSocket, FIONREAD, reinterpret_cast<u_long*>(&nReadLen));
|
||||
|
||||
if (iResult == SOCKET_ERROR)
|
||||
{
|
||||
@ -108,7 +101,7 @@ void CNetConBase::Recv(CConnectedNetConsoleData* pData, const int nMaxLen)
|
||||
|
||||
while (nReadLen > 0)
|
||||
{
|
||||
const int nRecvLen = ::recv(pData->m_hSocket, szRecvBuf, MIN(sizeof(szRecvBuf), nReadLen), MSG_NOSIGNAL);
|
||||
const int nRecvLen = ::recv(pData.m_hSocket, szRecvBuf, MIN(sizeof(szRecvBuf), nReadLen), MSG_NOSIGNAL);
|
||||
if (nRecvLen == 0) // Socket was closed.
|
||||
{
|
||||
Disconnect("socket closed unexpectedly");
|
||||
@ -134,67 +127,67 @@ void CNetConBase::Recv(CConnectedNetConsoleData* pData, const int nMaxLen)
|
||||
// *pData -
|
||||
// Output: true on success, false otherwise
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CNetConBase::ProcessBuffer(CConnectedNetConsoleData* pData,
|
||||
bool CNetConBase::ProcessBuffer(CConnectedNetConsoleData& pData,
|
||||
const char* pRecvBuf, int nRecvLen, const int nMaxLen)
|
||||
{
|
||||
bool bSuccess = true;
|
||||
|
||||
while (nRecvLen > 0)
|
||||
{
|
||||
if (pData->m_nPayloadLen)
|
||||
if (pData.m_nPayloadLen)
|
||||
{
|
||||
if (pData->m_nPayloadRead < pData->m_nPayloadLen)
|
||||
if (pData.m_nPayloadRead < pData.m_nPayloadLen)
|
||||
{
|
||||
pData->m_RecvBuffer[pData->m_nPayloadRead++] = *pRecvBuf;
|
||||
pData.m_RecvBuffer[pData.m_nPayloadRead++] = *pRecvBuf;
|
||||
|
||||
pRecvBuf++;
|
||||
nRecvLen--;
|
||||
}
|
||||
if (pData->m_nPayloadRead == pData->m_nPayloadLen)
|
||||
if (pData.m_nPayloadRead == pData.m_nPayloadLen)
|
||||
{
|
||||
if (!ProcessMessage(
|
||||
reinterpret_cast<const char*>(pData->m_RecvBuffer.data()), pData->m_nPayloadLen)
|
||||
reinterpret_cast<const char*>(pData.m_RecvBuffer.data()), pData.m_nPayloadLen)
|
||||
&& bSuccess)
|
||||
{
|
||||
bSuccess = false;
|
||||
}
|
||||
|
||||
pData->m_nPayloadLen = 0;
|
||||
pData->m_nPayloadRead = 0;
|
||||
pData.m_nPayloadLen = 0;
|
||||
pData.m_nPayloadRead = 0;
|
||||
}
|
||||
}
|
||||
else if (pData->m_nPayloadRead+1 <= sizeof(int)) // Read size field.
|
||||
else if (pData.m_nPayloadRead+1 <= sizeof(int)) // Read size field.
|
||||
{
|
||||
pData->m_RecvBuffer[pData->m_nPayloadRead++] = *pRecvBuf;
|
||||
pData.m_RecvBuffer[pData.m_nPayloadRead++] = *pRecvBuf;
|
||||
|
||||
pRecvBuf++;
|
||||
nRecvLen--;
|
||||
}
|
||||
else // Build prefix.
|
||||
{
|
||||
pData->m_nPayloadLen = int(ntohl(*reinterpret_cast<u_long*>(&pData->m_RecvBuffer[0])));
|
||||
pData->m_nPayloadRead = 0;
|
||||
pData.m_nPayloadLen = int(ntohl(*reinterpret_cast<u_long*>(&pData.m_RecvBuffer[0])));
|
||||
pData.m_nPayloadRead = 0;
|
||||
|
||||
if (!pData->m_bAuthorized && nMaxLen > -1)
|
||||
if (!pData.m_bAuthorized && nMaxLen > -1)
|
||||
{
|
||||
if (pData->m_nPayloadLen > nMaxLen)
|
||||
if (pData.m_nPayloadLen > nMaxLen)
|
||||
{
|
||||
Disconnect("overflow"); // Sending large messages while not authenticated.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (pData->m_nPayloadLen < 0 ||
|
||||
pData->m_nPayloadLen > pData->m_RecvBuffer.max_size())
|
||||
if (pData.m_nPayloadLen < 0 ||
|
||||
pData.m_nPayloadLen > pData.m_RecvBuffer.max_size())
|
||||
{
|
||||
Error(eDLL_T::ENGINE, NO_ERROR, "RCON Cmd: sync error (%d)\n", pData->m_nPayloadLen);
|
||||
Error(eDLL_T::ENGINE, NO_ERROR, "RCON Cmd: sync error (%d)\n", pData.m_nPayloadLen);
|
||||
Disconnect("desync"); // Out of sync (irrecoverable).
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pData->m_RecvBuffer.resize(pData->m_nPayloadLen);
|
||||
pData.m_RecvBuffer.resize(pData.m_nPayloadLen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,9 @@ public:
|
||||
virtual void Disconnect(const char* szReason = nullptr) { NOTE_UNUSED(szReason); };
|
||||
|
||||
virtual bool Send(const SocketHandle_t hSocket, const char* pMsgBuf, const int nMsgLen) const;
|
||||
virtual void Recv(CConnectedNetConsoleData* pData, const int nMaxLen = SOCKET_ERROR);
|
||||
virtual void Recv(CConnectedNetConsoleData& pData, const int nMaxLen = SOCKET_ERROR);
|
||||
|
||||
virtual bool ProcessBuffer(CConnectedNetConsoleData* pData, const char* pRecvBuf, int nRecvLen, const int nMaxLen = SOCKET_ERROR);
|
||||
virtual bool ProcessBuffer(CConnectedNetConsoleData& pData, const char* pRecvBuf, int nRecvLen, const int nMaxLen = SOCKET_ERROR);
|
||||
virtual bool ProcessMessage(const char* /*pMsgBuf*/, int /*nMsgLen*/) { return true; };
|
||||
|
||||
CSocketCreator* GetSocketCreator(void) { return &m_Socket; }
|
||||
|
@ -91,7 +91,7 @@ bool CL_NetConConnect(CNetConBase* pBase, const char* pHostAdr, const int nHostP
|
||||
//-----------------------------------------------------------------------------
|
||||
CConnectedNetConsoleData* SH_GetNetConData(CNetConBase* pBase, const int iSocket)
|
||||
{
|
||||
const CSocketCreator* pCreator = pBase->GetSocketCreator();
|
||||
CSocketCreator* pCreator = pBase->GetSocketCreator();
|
||||
Assert(iSocket >= 0 && (pCreator->GetAcceptedSocketCount() == 0
|
||||
|| iSocket < pCreator->GetAcceptedSocketCount()));
|
||||
|
||||
@ -100,7 +100,7 @@ CConnectedNetConsoleData* SH_GetNetConData(CNetConBase* pBase, const int iSocket
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pCreator->GetAcceptedSocketData(iSocket);
|
||||
return &pCreator->GetAcceptedSocketData(iSocket);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -226,7 +226,7 @@ void CNetCon::RunFrame(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_Mutex);
|
||||
|
||||
CConnectedNetConsoleData* pData = m_Socket.GetAcceptedSocketData(0);
|
||||
CConnectedNetConsoleData& pData = m_Socket.GetAcceptedSocketData(0);
|
||||
Recv(pData);
|
||||
}
|
||||
else if (m_bPromptConnect)
|
||||
|
@ -35,23 +35,23 @@ public:
|
||||
|
||||
SocketHandle_t GetAcceptedSocketHandle(int nIndex) const;
|
||||
const netadr_t& GetAcceptedSocketAddress(int nIndex) const;
|
||||
CConnectedNetConsoleData* GetAcceptedSocketData(int nIndex) const;
|
||||
CConnectedNetConsoleData& GetAcceptedSocketData(int nIndex);
|
||||
const CConnectedNetConsoleData& GetAcceptedSocketData(int nIndex) const;
|
||||
|
||||
public:
|
||||
struct AcceptedSocket_t
|
||||
{
|
||||
AcceptedSocket_t(void)
|
||||
{
|
||||
m_hSocket = NULL;
|
||||
m_pData = nullptr;
|
||||
}
|
||||
AcceptedSocket_t(SocketHandle_t hSocket)
|
||||
: m_hSocket(hSocket)
|
||||
, m_Data(hSocket)
|
||||
{}
|
||||
|
||||
SocketHandle_t m_hSocket;
|
||||
netadr_t m_Address;
|
||||
CConnectedNetConsoleData* m_pData;
|
||||
CConnectedNetConsoleData m_Data;
|
||||
};
|
||||
|
||||
std::vector<AcceptedSocket_t> m_hAcceptedSockets;
|
||||
CUtlVector<AcceptedSocket_t> m_AcceptedSockets;
|
||||
SocketHandle_t m_hListenSocket; // Used to accept connections.
|
||||
|
||||
private:
|
||||
|
@ -266,15 +266,12 @@ bool CSocketCreator::ConfigureSocket(SocketHandle_t hSocket, bool bDualStack /*=
|
||||
//-----------------------------------------------------------------------------
|
||||
int CSocketCreator::OnSocketAccepted(SocketHandle_t hSocket, const netadr_t& netAdr)
|
||||
{
|
||||
AcceptedSocket_t newEntry;
|
||||
|
||||
newEntry.m_hSocket = hSocket;
|
||||
AcceptedSocket_t newEntry(hSocket);
|
||||
newEntry.m_Address = netAdr;
|
||||
newEntry.m_pData = new CConnectedNetConsoleData(hSocket);
|
||||
|
||||
m_hAcceptedSockets.push_back(newEntry);
|
||||
m_AcceptedSockets.AddToTail(newEntry);
|
||||
|
||||
int nIndex = static_cast<int>(m_hAcceptedSockets.size()) - 1;
|
||||
int nIndex = m_AcceptedSockets.Count() - 1;
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
@ -284,17 +281,16 @@ int CSocketCreator::OnSocketAccepted(SocketHandle_t hSocket, const netadr_t& net
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSocketCreator::CloseAcceptedSocket(int nIndex)
|
||||
{
|
||||
if (nIndex >= int(m_hAcceptedSockets.size()))
|
||||
if (nIndex >= m_AcceptedSockets.Count())
|
||||
{
|
||||
Assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
AcceptedSocket_t& connected = m_hAcceptedSockets[nIndex];
|
||||
AcceptedSocket_t& connected = m_AcceptedSockets[nIndex];
|
||||
DisconnectSocket(connected.m_hSocket);
|
||||
delete connected.m_pData;
|
||||
|
||||
m_hAcceptedSockets.erase(m_hAcceptedSockets.begin() + nIndex);
|
||||
m_AcceptedSockets.Remove(nIndex);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -302,14 +298,12 @@ void CSocketCreator::CloseAcceptedSocket(int nIndex)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CSocketCreator::CloseAllAcceptedSockets(void)
|
||||
{
|
||||
for (size_t i = 0; i < m_hAcceptedSockets.size(); ++i)
|
||||
for (int i = 0; i < m_AcceptedSockets.Count(); ++i)
|
||||
{
|
||||
AcceptedSocket_t& connected = m_hAcceptedSockets[i];
|
||||
AcceptedSocket_t& connected = m_AcceptedSockets[i];
|
||||
DisconnectSocket(connected.m_hSocket);
|
||||
|
||||
delete connected.m_pData;
|
||||
}
|
||||
m_hAcceptedSockets.clear();
|
||||
m_AcceptedSockets.Purge();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -338,9 +332,9 @@ int CSocketCreator::GetAuthorizedSocketCount(void) const
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
for (size_t i = 0; i < m_hAcceptedSockets.size(); ++i)
|
||||
for (int i = 0; i < m_AcceptedSockets.Count(); ++i)
|
||||
{
|
||||
if (m_hAcceptedSockets[i].m_pData->m_bAuthorized)
|
||||
if (m_AcceptedSockets[i].m_Data.m_bAuthorized)
|
||||
{
|
||||
ret++;
|
||||
}
|
||||
@ -355,7 +349,7 @@ int CSocketCreator::GetAuthorizedSocketCount(void) const
|
||||
//-----------------------------------------------------------------------------
|
||||
int CSocketCreator::GetAcceptedSocketCount(void) const
|
||||
{
|
||||
return static_cast<int>(m_hAcceptedSockets.size());
|
||||
return m_AcceptedSockets.Count();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -365,8 +359,8 @@ int CSocketCreator::GetAcceptedSocketCount(void) const
|
||||
//-----------------------------------------------------------------------------
|
||||
SocketHandle_t CSocketCreator::GetAcceptedSocketHandle(int nIndex) const
|
||||
{
|
||||
Assert(nIndex >= 0 && nIndex < int(m_hAcceptedSockets.size()));
|
||||
return m_hAcceptedSockets[nIndex].m_hSocket;
|
||||
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
||||
return m_AcceptedSockets[nIndex].m_hSocket;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -376,8 +370,8 @@ SocketHandle_t CSocketCreator::GetAcceptedSocketHandle(int nIndex) const
|
||||
//-----------------------------------------------------------------------------
|
||||
const netadr_t& CSocketCreator::GetAcceptedSocketAddress(int nIndex) const
|
||||
{
|
||||
Assert(nIndex >= 0 && nIndex < int(m_hAcceptedSockets.size()));
|
||||
return m_hAcceptedSockets[nIndex].m_Address;
|
||||
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
||||
return m_AcceptedSockets[nIndex].m_Address;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -385,8 +379,19 @@ const netadr_t& CSocketCreator::GetAcceptedSocketAddress(int nIndex) const
|
||||
// Input : nIndex -
|
||||
// Output : CConnectedNetConsoleData*
|
||||
//-----------------------------------------------------------------------------
|
||||
CConnectedNetConsoleData* CSocketCreator::GetAcceptedSocketData(int nIndex) const
|
||||
CConnectedNetConsoleData& CSocketCreator::GetAcceptedSocketData(int nIndex)
|
||||
{
|
||||
Assert(nIndex >= 0 && nIndex < int(m_hAcceptedSockets.size()));
|
||||
return m_hAcceptedSockets[nIndex].m_pData;
|
||||
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
||||
return m_AcceptedSockets[nIndex].m_Data;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: returns accepted socket data
|
||||
// Input : nIndex -
|
||||
// Output : CConnectedNetConsoleData*
|
||||
//-----------------------------------------------------------------------------
|
||||
const CConnectedNetConsoleData& CSocketCreator::GetAcceptedSocketData(int nIndex) const
|
||||
{
|
||||
Assert(nIndex >= 0 && nIndex < m_AcceptedSockets.Count());
|
||||
return m_AcceptedSockets[nIndex].m_Data;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user