2022-03-26 00:24:13 +01:00
|
|
|
//===============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
// $NoKeywords: $
|
|
|
|
//
|
|
|
|
//===============================================================================//
|
2022-05-20 11:52:19 +02:00
|
|
|
// client.cpp: implementation of the CClient class.
|
2022-03-26 00:24:13 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
#include "core/stdafx.h"
|
2022-05-20 11:52:19 +02:00
|
|
|
#include "engine/client/client.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-03-26 00:24:13 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the client from buffer by index
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
CClient* CClient::GetClient(int nIndex) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-05-20 11:52:19 +02:00
|
|
|
return (CClient*)(std::uintptr_t)(g_pClientBuffer.GetPtr() + (nIndex * sizeof(CClient)));
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the userID of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 20:14:39 +02:00
|
|
|
int32_t CClient::GetUserID(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-03-27 19:35:33 +02:00
|
|
|
return m_nUserID;
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the userID of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 20:14:39 +02:00
|
|
|
int64_t CClient::GetOriginID(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-03-27 19:35:33 +02:00
|
|
|
return m_nOriginID;
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the signon state of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
SIGNONSTATE CClient::GetSignonState(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nSignonState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the persistence state of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
PERSISTENCE CClient::GetPersistenceState(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nPersistenceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: gets the net channel of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
CNetChan* CClient::GetNetChan(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_NetChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the userID of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
void CClient::SetUserID(std::int32_t nUserID)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-03-27 19:35:33 +02:00
|
|
|
m_nUserID = nUserID;
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the originID of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
void CClient::SetOriginID(std::int64_t nOriginID)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-03-27 19:35:33 +02:00
|
|
|
m_nOriginID = nOriginID;
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the signon state of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
void CClient::SetSignonState(SIGNONSTATE nSignonState)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
m_nSignonState = nSignonState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the persistence state of this client
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
void CClient::SetPersistenceState(PERSISTENCE nPersistenceState)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
m_nPersistenceState = nPersistenceState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: sets the net channel of this client
|
|
|
|
// !TODO : Remove this and rebuild INetChannel
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
void CClient::SetNetChan(CNetChan* pNetChan)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
m_NetChannel = pNetChan;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client is connected to server
|
|
|
|
// Output : true if connected, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsConnected(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nSignonState >= SIGNONSTATE::SIGNONSTATE_CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client is spawned to server
|
|
|
|
// Output : true if connected, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsSpawned(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nSignonState >= SIGNONSTATE::SIGNONSTATE_NEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client is active to server
|
|
|
|
// Output : true if connected, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsActive(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nSignonState == SIGNONSTATE::SIGNONSTATE_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client's persistence data is available
|
|
|
|
// Output : true if available, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsPersistenceAvailable(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nPersistenceState >= PERSISTENCE::PERSISTENCE_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client's persistence data is ready
|
|
|
|
// Output : true if ready, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsPersistenceReady(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_nPersistenceState == PERSISTENCE::PERSISTENCE_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if client is a fake client
|
|
|
|
// Output : true if connected, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsFakeClient(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
return m_bFakePlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: checks if this client is an actual human player
|
|
|
|
// Output : true if human, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
bool CClient::IsHumanPlayer(void) const
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
|
|
|
if (!IsConnected())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (IsFakeClient())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-21 18:56:56 +02:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: throw away any residual garbage in the channel
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
void CClient::Clear(void)
|
|
|
|
{
|
|
|
|
v_CClient_Clear(this);
|
|
|
|
}
|
|
|
|
|
2021-12-25 22:36:38 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: throw away any residual garbage in the channel
|
2022-03-26 00:24:13 +01:00
|
|
|
// Input : *pBaseClient -
|
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-21 18:56:56 +02:00
|
|
|
void CClient::VClear(CClient* pBaseClient)
|
|
|
|
{
|
|
|
|
v_CClient_Clear(pBaseClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: connect new client
|
|
|
|
// Input : *szName -
|
|
|
|
// *pNetChannel -
|
|
|
|
// bFakePlayer -
|
|
|
|
// *a5 -
|
|
|
|
// *szMessage -
|
|
|
|
// nMessageSize -
|
|
|
|
// Output : true if connection was succesfull, false otherwise
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
bool CClient::Connect(const char* szName, void* pNetChannel, bool bFakePlayer, void* a5, char* szMessage, int nMessageSize)
|
2022-03-26 00:24:13 +01:00
|
|
|
{
|
2022-05-21 18:56:56 +02:00
|
|
|
return v_CClient_Connect(this, szName, pNetChannel, bFakePlayer, a5, szMessage, nMessageSize);
|
2022-03-26 00:24:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------
|
|
|
|
// Purpose: connect new client
|
|
|
|
// Input : *pClient -
|
|
|
|
// *szName -
|
|
|
|
// *pNetChannel -
|
|
|
|
// bFakePlayer -
|
|
|
|
// *a5 -
|
|
|
|
// *szMessage -
|
|
|
|
// nMessageSize -
|
|
|
|
// Output : true if connection was succesfull, false otherwise
|
2021-12-25 22:36:38 +01:00
|
|
|
//---------------------------------------------------------------------------------
|
2022-05-21 18:56:56 +02:00
|
|
|
bool CClient::VConnect(CClient* pClient, const char* szName, void* pNetChannel, bool bFakePlayer, void* a5, char* szMessage, int nMessageSize)
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-05-21 18:56:56 +02:00
|
|
|
return v_CClient_Connect(pClient, szName, pNetChannel, bFakePlayer, a5, szMessage, nMessageSize);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-03-26 00:24:13 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
2021-12-25 22:36:38 +01:00
|
|
|
void CBaseClient_Attach()
|
|
|
|
{
|
2022-05-21 18:56:56 +02:00
|
|
|
DetourAttach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
|
|
|
|
DetourAttach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
|
|
|
void CBaseClient_Detach()
|
|
|
|
{
|
2022-05-21 18:56:56 +02:00
|
|
|
DetourDetach((LPVOID*)&v_CClient_Clear, &CClient::VClear);
|
|
|
|
DetourDetach((LPVOID*)&v_CClient_Connect, &CClient::VConnect);
|
2021-12-25 22:36:38 +01:00
|
|
|
}
|
2022-03-27 23:50:35 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-05-20 11:52:19 +02:00
|
|
|
CClient* g_pClient = nullptr;
|