2024-07-29 21:09:55 +02:00
|
|
|
|
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ======//
|
2022-05-20 20:14:39 +02:00
|
|
|
|
//
|
|
|
|
|
// 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
|
2024-02-06 14:42:36 +01:00
|
|
|
|
if (sv_stats->GetBool())
|
2023-12-30 01:17:39 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
2024-02-06 14:42:36 +01:00
|
|
|
|
|
|
|
|
|
// -1 means we update statistics only; see 'CClientState::VProcessServerTick()'.
|
|
|
|
|
serverTick.m_NetTick.m_nCommandTick = -1;
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // !CLIENT_DLL
|
2024-02-06 14:42:36 +01:00
|
|
|
|
|
|
|
|
|
Assert(!pMsg->IsOverflowed(), "Snapshot buffer overflowed before string table update!");
|
2024-01-02 15:21:36 +01:00
|
|
|
|
CNetworkStringTableContainer__WriteUpdateMessage(thisp, pClient, nTickAck, pMsg);
|
2023-02-18 00:24:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-26 13:21:20 +01:00
|
|
|
|
void VNetworkStringTableContainer::Detour(const bool bAttach) const
|
2023-02-18 00:24:02 +01:00
|
|
|
|
{
|
2024-01-02 15:21:36 +01:00
|
|
|
|
DetourSetup(&CNetworkStringTableContainer__WriteUpdateMessage, &CNetworkStringTableContainer::WriteUpdateMessage, bAttach);
|
2023-02-18 00:24:02 +01:00
|
|
|
|
}
|