2022-05-20 20:14:39 +02:00
|
|
|
|
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
|
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
// $NoKeywords: $
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
#include "core/stdafx.h"
|
2023-02-18 00:24:02 +01:00
|
|
|
|
#include "tier1/cvar.h"
|
|
|
|
|
#ifndef CLIENT_DLL
|
|
|
|
|
#include "server/server.h"
|
|
|
|
|
#include "host.h"
|
|
|
|
|
#endif // !CLIENT_DLL
|
2023-04-10 15:04:46 +02:00
|
|
|
|
#include "net.h"
|
2023-02-18 00:24:02 +01:00
|
|
|
|
#include "networkstringtable.h"
|
2022-05-20 20:14:39 +02:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose:
|
|
|
|
|
// Input : i -
|
|
|
|
|
// Output : CNetworkStringTableItem
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//CNetworkStringTableItem* CNetworkStringTable::GetItem(int i)
|
|
|
|
|
//{
|
|
|
|
|
// if (i >= 0)
|
|
|
|
|
// {
|
|
|
|
|
// return &m_pItems->Element(i);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// Assert(m_pItemsClientSide);
|
|
|
|
|
// return &m_pItemsClientSide->Element(-i);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Returns the table identifier
|
|
|
|
|
// Output : TABLEID
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
TABLEID CNetworkStringTable::GetTableId(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Returns the max size of the table
|
|
|
|
|
// Output : int
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
int CNetworkStringTable::GetMaxStrings(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_nMaxEntries;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Returns a table, by name
|
|
|
|
|
// Output : const char
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
const char* CNetworkStringTable::GetTableName(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_pszTableName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Returns the number of bits needed to encode an entry index
|
|
|
|
|
// Output : int
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
int CNetworkStringTable::GetEntryBits(void) const
|
|
|
|
|
{
|
|
|
|
|
return m_nEntryBits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Sets the tick count
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void CNetworkStringTable::SetTick(int tick_count)
|
|
|
|
|
{
|
2023-01-25 19:21:06 +01:00
|
|
|
|
Assert(tick_count >= m_nTickCount);
|
2022-05-20 20:14:39 +02:00
|
|
|
|
m_nTickCount = tick_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Locks the string table
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
bool CNetworkStringTable::Lock(bool bLock)
|
|
|
|
|
{
|
|
|
|
|
bool bState = m_bLocked;
|
|
|
|
|
m_bLocked = bLock;
|
|
|
|
|
return bState;
|
|
|
|
|
}
|
2023-02-18 00:24:02 +01:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// Purpose: Writes network string table delta's to snapshot buffer
|
|
|
|
|
// Input : *pClient -
|
|
|
|
|
// nTickAck -
|
|
|
|
|
// *pMsg -
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void CNetworkStringTableContainer::WriteUpdateMessage(CNetworkStringTableContainer* thisp, CClient* pClient, unsigned int nTickAck, bf_write* pMsg)
|
|
|
|
|
{
|
|
|
|
|
#ifndef CLIENT_DLL
|
2023-12-30 01:17:39 +01:00
|
|
|
|
const double currentTime = Plat_FloatTime();
|
|
|
|
|
|
|
|
|
|
ServerPlayer_t& clientExtended = g_ServerPlayer[pClient->GetUserID()];
|
|
|
|
|
int commandTick = -1; // -1 means we update statistics only; see 'CClientState::VProcessServerTick()'.
|
|
|
|
|
|
|
|
|
|
// NOTE: if we send this message each tick, the client will start to
|
|
|
|
|
// falter. Unlike other source games, we have to have some delay in
|
|
|
|
|
// between each server tick message for this to work correctly.
|
|
|
|
|
if (clientExtended.m_bRetryClockSync ||
|
|
|
|
|
(currentTime - clientExtended.m_flLastClockSyncTime) > sv_clockSyncInterval->GetFloat())
|
2023-02-18 00:24:02 +01:00
|
|
|
|
{
|
2023-12-30 01:17:39 +01:00
|
|
|
|
// Sync the clocks on the client with that of the server's.
|
|
|
|
|
commandTick = pClient->GetCommandTick();
|
|
|
|
|
clientExtended.m_flLastClockSyncTime = currentTime;
|
|
|
|
|
clientExtended.m_bRetryClockSync = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If commandTick == statistics only while server opted out, do not
|
|
|
|
|
// send the message.
|
|
|
|
|
const bool shouldSend = (commandTick == -1 && !sv_stats->GetBool()) ? false : true;
|
|
|
|
|
|
|
|
|
|
if (shouldSend)
|
|
|
|
|
{
|
|
|
|
|
const uint8_t nCPUPercentage = static_cast<uint8_t>(g_pServer->GetCPUUsage() * 100.0f);
|
2023-04-10 15:04:46 +02:00
|
|
|
|
SVC_ServerTick serverTick(g_pServer->GetTick(), *host_frametime_unbounded, *host_frametime_stddeviation, nCPUPercentage);
|
2023-02-18 00:24:02 +01:00
|
|
|
|
|
2023-04-10 15:04:46 +02:00
|
|
|
|
serverTick.m_nGroup = 0;
|
|
|
|
|
serverTick.m_bReliable = true;
|
2023-12-30 01:17:39 +01:00
|
|
|
|
serverTick.m_NetTick.m_nCommandTick = commandTick;
|
2023-04-09 11:06:55 +02:00
|
|
|
|
|
2023-04-10 15:04:46 +02:00
|
|
|
|
pMsg->WriteUBitLong(serverTick.GetType(), NETMSG_TYPE_BITS);
|
2023-12-30 01:17:39 +01:00
|
|
|
|
|
2023-04-10 15:04:46 +02:00
|
|
|
|
if (!pMsg->IsOverflowed())
|
2023-04-09 11:06:55 +02:00
|
|
|
|
{
|
2023-04-10 15:04:46 +02:00
|
|
|
|
serverTick.WriteToBuffer(pMsg);
|
2023-02-18 00:24:02 +01:00
|
|
|
|
}
|
2023-12-30 01:17:39 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert(0, "Snapshot buffer overflowed before string table update!");
|
|
|
|
|
clientExtended.m_bRetryClockSync = true; // Retry on next snapshot for this client.
|
|
|
|
|
}
|
2023-02-18 00:24:02 +01:00
|
|
|
|
}
|
|
|
|
|
#endif // !CLIENT_DLL
|
|
|
|
|
v_CNetworkStringTableContainer__WriteUpdateMessage(thisp, pClient, nTickAck, pMsg);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
|
void VNetworkStringTableContainer::Detour(const bool bAttach) const
|
2023-02-18 00:24:02 +01:00
|
|
|
|
{
|
2023-04-23 17:05:00 +02:00
|
|
|
|
#if !defined (CLIENT_DLL) && !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) // TODO: doesn't work properly for S0/S1 yet.
|
2023-11-26 13:21:20 +01:00
|
|
|
|
DetourSetup(&v_CNetworkStringTableContainer__WriteUpdateMessage, &CNetworkStringTableContainer::WriteUpdateMessage, bAttach);
|
2023-04-23 17:05:00 +02:00
|
|
|
|
#endif // !CLIENT_DLL && !GAMEDLL_S0 && !GAMEDLL_S1
|
2023-02-18 00:24:02 +01:00
|
|
|
|
}
|