Skip to content

Commit

Permalink
fix sound scripts pure bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Aug 28, 2020
1 parent d0b7fc7 commit 34675a9
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 84 deletions.
56 changes: 56 additions & 0 deletions common/netmessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,62 @@ bool CLC_FileMD5Check::WriteToBuffer( bf_write &buffer )
return !buffer.IsOverflowed();
}

void CLC_FileCRCCheck::SetPath(const char* path)
{
int iCode = FindCommonPathID(path);
if (iCode == -1)
{
m_iCodePath = -1;
V_strncpy(m_szPathID, path, sizeof(m_szPathID));
}
else
{
m_iCodePath = iCode;
}
}

const char* CLC_FileCRCCheck::GetPath()
{
int iCode = m_iCodePath;
if ((iCode >= 0) && (iCode < ARRAYSIZE(g_MostCommonPathIDs)))
{
return g_MostCommonPathIDs[iCode];
}

Assert(iCode == -1);
return m_szPathID;
}

void CLC_FileCRCCheck::SetFileName(const char* fileName)
{
int iCode = FindCommonPrefix(fileName);
if (iCode == -1)
{
m_iCodeFilename = -1;
V_strncpy(m_szFilename, fileName, sizeof(m_szFilename));
}
else
{
m_iCodeFilename = iCode;
V_strncpy(m_szFilename, &fileName[V_strlen(g_MostCommonPrefixes[iCode]) + 1], sizeof(m_szFilename));
}
}

const char* CLC_FileCRCCheck::GetFileName()
{
// FIXME(mastercoms): unresolved external va symbol
#if 0
int iCode = m_iCodeFilename;
if ((iCode >= 0) && (iCode < ARRAYSIZE(g_MostCommonPrefixes)))
{
return va("%s%c%s", g_MostCommonPrefixes[iCode], CORRECT_PATH_SEPARATOR, m_szFilename);
}

Assert(iCode == -1);
#endif
return m_szFilename;
}

bool CLC_FileMD5Check::ReadFromBuffer( bf_read &buffer )
{
VPROF( "CLC_FileMD5Check::ReadFromBuffer" );
Expand Down
8 changes: 8 additions & 0 deletions common/netmessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ class CLC_FileCRCCheck : public CNetMessage
{
public:
DECLARE_CLC_MESSAGE( FileCRCCheck );
int m_iCodePath;
int m_iCodeFilename;
char m_szPathID[MAX_PATH];
char m_szFilename[MAX_PATH];
MD5Value_t m_MD5;
Expand All @@ -320,8 +322,14 @@ class CLC_FileCRCCheck : public CNetMessage
int m_nPackFileNumber;
int m_PackFileID;
int m_nFileFraction;

void SetPath(const char* path);
const char* GetPath();
void SetFileName(const char* fileName);
const char* GetFileName();
};


class CLC_FileMD5Check : public CNetMessage
{
public:
Expand Down
95 changes: 42 additions & 53 deletions engine/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,65 +1561,54 @@ void CClientState::CheckUpdatingSteamResources()
}
}


//-----------------------------------------------------------------------------
// Purpose: At a certain rate, this function will verify any unverified
// file CRCs with the server.
//-----------------------------------------------------------------------------
void CClientState::CheckFileCRCsWithServer()
{
//! !FIXME! Stubbed this. Several reasons:
//!
//! 1.) Removed the CRC functionality (because it was broken when we switched to use MD5's for hashes of
//! loose files, but the server only has CRC's of some files in the VPK headers.). Currently the only
//! supported pure server mode is "trusted source."
//! 2.) Sending MD5's of VPK's is a bit too restrictive for most use cases. For example, if a client
//! has an extra VPK for custom content, the server doesn't know what to do with it. Or if we
//! release an optional update, the VPK's might legitimately differ.
//!
//! Rich has pointed out that we really need pure server client work to be something that the client
//! cannot easily bypass. Currently that is the case. But I need to ship the SteamPipe conversion now.
//! We can revisit pure server security after that has shipped.
//
// VPROF_( "CheckFileCRCsWithServer", 1, VPROF_BUDGETGROUP_OTHER_NETWORKING, false, BUDGETFLAG_CLIENT );
// const float flBatchInterval = 1.0f / 5.0f;
// const int nBatchSize = 5;
//
// // Don't do this yet..
// if ( !m_bCheckCRCsWithServer )
// return;
//
// if ( m_nSignonState != SIGNONSTATE_FULL )
// return;
//
// // Only send a batch every so often.
// float flCurTime = Plat_FloatTime();
// if ( (flCurTime - m_flLastCRCBatchTime) < flBatchInterval )
// return;
//
// m_flLastCRCBatchTime = flCurTime;
//
// CUnverifiedFileHash rgUnverifiedFiles[nBatchSize];
// int count = g_pFileSystem->GetUnverifiedFileHashes( rgUnverifiedFiles, ARRAYSIZE( rgUnverifiedFiles ) );
// if ( count == 0 )
// return;
//
// // Send the messages to the server.
// for ( int i=0; i < count; i++ )
// {
// CLC_FileCRCCheck crcCheck;
// V_strncpy( crcCheck.m_szPathID, rgUnverifiedFiles[i].m_PathID, sizeof( crcCheck.m_szPathID ) );
// V_strncpy( crcCheck.m_szFilename, rgUnverifiedFiles[i].m_Filename, sizeof( crcCheck.m_szFilename ) );
// crcCheck.m_nFileFraction = rgUnverifiedFiles[i].m_nFileFraction;
// crcCheck.m_MD5 = rgUnverifiedFiles[i].m_FileHash.m_md5contents;
// crcCheck.m_CRCIOs = rgUnverifiedFiles[i].m_FileHash.m_crcIOSequence;
// crcCheck.m_eFileHashType = rgUnverifiedFiles[i].m_FileHash.m_eFileHashType;
// crcCheck.m_cbFileLen = rgUnverifiedFiles[i].m_FileHash.m_cbFileLen;
// crcCheck.m_nPackFileNumber = rgUnverifiedFiles[i].m_FileHash.m_nPackFileNumber;
// crcCheck.m_PackFileID = rgUnverifiedFiles[i].m_FileHash.m_PackFileID;
//
// m_NetChannel->SendNetMsg( crcCheck );
// }
// See comment in filetracker.cpp to see why we can't send hashes for TF.
#if 0
VPROF_("CheckFileCRCsWithServer", 1, VPROF_BUDGETGROUP_OTHER_NETWORKING, false, BUDGETFLAG_CLIENT);
const float flBatchInterval = 1.0f / 5.0f;
const int nBatchSize = 5;

// Don't do this yet..
if (!m_bCheckCRCsWithServer)
return;

if (m_nSignonState != SIGNONSTATE_FULL)
return;

// Only send a batch every so often.
float flCurTime = Plat_FloatTime();
if ((flCurTime - m_flLastCRCBatchTime) < flBatchInterval)
return;

m_flLastCRCBatchTime = flCurTime;

CUnverifiedFileHash rgUnverifiedFiles[nBatchSize];
int count = g_pFileSystem->GetUnverifiedFileHashes(rgUnverifiedFiles, ARRAYSIZE(rgUnverifiedFiles));
if (count == 0)
return;

// Send the messages to the server.
for (int i = 0; i < count; i++)
{
CLC_FileCRCCheck crcCheck;
V_strncpy( crcCheck.m_szPathID, rgUnverifiedFiles[i].m_PathID, sizeof( crcCheck.m_szPathID ) );
V_strncpy( crcCheck.m_szFilename, rgUnverifiedFiles[i].m_Filename, sizeof( crcCheck.m_szFilename ) );
crcCheck.m_nFileFraction = rgUnverifiedFiles[i].m_nFileFraction;
crcCheck.m_MD5 = rgUnverifiedFiles[i].m_FileHash.m_md5contents;
crcCheck.m_CRCIOs = rgUnverifiedFiles[i].m_FileHash.m_crcIOSequence;
crcCheck.m_eFileHashType = rgUnverifiedFiles[i].m_FileHash.m_eFileHashType;
crcCheck.m_cbFileLen = rgUnverifiedFiles[i].m_FileHash.m_cbFileLen;
crcCheck.m_nPackFileNumber = rgUnverifiedFiles[i].m_FileHash.m_nPackFileNumber;
crcCheck.m_PackFileID = rgUnverifiedFiles[i].m_FileHash.m_PackFileID;

m_NetChannel->SendNetMsg(crcCheck);
}
#endif
}


Expand Down
28 changes: 19 additions & 9 deletions engine/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,17 @@ varargs versions of all text functions.
*/
char *va( const char *format, ... )
{
char* outbuf = tmpstr512();
va_list argptr;
va_start (argptr, format);
Q_vsnprintf( outbuf, 512, format, argptr );
va_end (argptr);
return outbuf;
va_list argptr;
static char string[8][512];
static int curstring = 0;

curstring = (curstring + 1) % 8;

va_start(argptr, format);
Q_vsnprintf(string[curstring], sizeof(string[curstring]), format, argptr);
va_end(argptr);

return string[curstring];
}

/*
Expand All @@ -390,9 +395,14 @@ bufffer.
*/
const char *vstr(Vector& v)
{
char* outbuf = tmpstr512();
Q_snprintf(outbuf, 512, "%.2f %.2f %.2f", v[0], v[1], v[2]);
return outbuf;
static int idx = 0;
static char string[16][1024];

idx++;
idx &= 15;

Q_snprintf(string[idx], sizeof(string[idx]), "%.2f %.2f %.2f", v[0], v[1], v[2]);
return string[idx];
}

char com_basedir[MAX_OSPATH];
Expand Down
2 changes: 1 addition & 1 deletion engine/net_ws.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void NET_CloseSocket( int hSocket, int sock = -1)
}
}

bool NET_SetBufferSize(unsigned int nBufferSize, int newsocket, bool bReceive, bool bUDP)
bool NET_SetBufferSize(int nBufferSize, int newsocket, bool bReceive, bool bUDP)
{
int optval = bReceive ? SO_RCVBUF : SO_SNDBUF;
int opt = 0;
Expand Down
8 changes: 2 additions & 6 deletions engine/sv_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ bool CGameClient::ProcessFileCRCCheck( CLC_FileCRCCheck *msg )

char warningStr[1024] = {0};

// The client may send us files we don't care about, so filter them here
// if ( !sv.GetPureServerWhitelist()->GetForceMatchList()->IsFileInList( msg->m_szFilename ) )
// return true;

// first check against all the other files users have sent
FileHash_t filehash;
filehash.m_md5contents = msg->m_MD5;
Expand All @@ -274,8 +270,8 @@ bool CGameClient::ProcessFileCRCCheck( CLC_FileCRCCheck *msg )
filehash.m_nPackFileNumber = msg->m_nPackFileNumber;
filehash.m_PackFileID = msg->m_PackFileID;

const char *path = msg->m_szPathID;
const char *fileName = msg->m_szFilename;
const char *path = msg->GetPath();
const char *fileName = msg->GetFileName();
if ( g_PureFileTracker.DoesFileMatch( path, fileName, msg->m_nFileFraction, &filehash, GetNetworkID() ) )
{
// track successful file
Expand Down
7 changes: 3 additions & 4 deletions filesystem/basefilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2941,15 +2941,14 @@ bool CBaseFileSystem::LoadKeyValues( KeyValues& head, KeyValuesPreloadType_t typ
ParsePathID( filename, pPathID, tempPathID );

// FIXME: THIS STUFF DOESN'T TRACK pPathID AT ALL RIGHT NOW!!!!!
if ( !m_PreloadData[ type ].m_pReader || !m_PreloadData[ type ].m_pReader->InstanceInPlace( head, filename ) )
if (!m_PreloadData[type].m_pReader || !m_PreloadData[type].m_pReader->InstanceInPlace(head, filename))
{
bret = head.LoadFromFile( this, filename, pPathID );
bret = head.LoadFromFile(this, filename, pPathID);
}
return bret;
#else
bret = head.LoadFromFile( this, filename, pPathID );
return bret;
#endif
return bret;
}


Expand Down
2 changes: 1 addition & 1 deletion game_clean/start_server.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@echo off
srcds.bat +sv_pure 0 +maxplayers 32 +sv_lan 1 %* < nul
srcds.bat +sv_pure 1 +maxplayers 32 +sv_lan 1 %* < nul
16 changes: 6 additions & 10 deletions soundemittersystem/soundemittersystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ soundlevel_t CSoundEmitterSystemBase::LookupSoundLevel( const char *soundname )
void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPreload, bool bIsOverride /*=false*/, bool bRefresh /*=false*/ )
{
CSoundScriptFile sf;
sf.hFilename = filesystem->FindOrAddFileName( filename );
sf.hFilename = filesystem->FindOrAddFileName(filename);
sf.dirty = false;

int scriptindex = m_SoundKeyValues.AddToTail( sf );
Expand All @@ -873,7 +873,7 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre

// Open the soundscape data file, and abort if we can't
KeyValues *kv = new KeyValues( "" );
if ( filesystem->LoadKeyValues( *kv, IFileSystem::TYPE_SOUNDEMITTER, filename, "GAME" ) )
if (filesystem->LoadKeyValues( *kv, IFileSystem::TYPE_SOUNDEMITTER, filename, "GAME" ) )
{
// parse out all of the top level sections and save their names
KeyValues *pKeys = kv;
Expand Down Expand Up @@ -907,7 +907,7 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre
UtlHashHandle_t lookup = m_Sounds.Insert( pEntry ); // insert returns existing item if found
if ( m_Sounds[ lookup ] != pEntry )
{
if ( bIsOverride )
if ( bIsOverride || bRefresh )
{
MEM_ALLOC_CREDIT();

Expand All @@ -929,10 +929,6 @@ void CSoundEmitterSystemBase::AddSoundsFromFile( const char *filename, bool bPre

++replaceCount;
}
else if ( bRefresh )
{
InitSoundInternalParameters( pKeys->GetName(), pKeys, m_Sounds[ lookup ]->m_SoundParams );
}
#if 0
else
{
Expand Down Expand Up @@ -1054,7 +1050,7 @@ int CSoundEmitterSystemBase::CheckForMissingWavFiles( bool verbose )
if ( name[0] == CHAR_SENTENCE )
continue;
Q_snprintf( testfile, sizeof( testfile ), "sound/%s", PSkipSoundChars( name ) );
if ( filesystem->FileExists( testfile ) )
if (filesystem->FileExists( testfile ) )
continue;

internal->SetHadMissingWaveFiles( true );
Expand Down Expand Up @@ -1146,7 +1142,7 @@ const char *CSoundEmitterSystemBase::GetSourceFileForSound( int index ) const
return "";
}
static char fn[ 512 ];
if ( filesystem->String( m_SoundKeyValues[ scriptindex ].hFilename, fn, sizeof( fn ) ))
if (filesystem->String( m_SoundKeyValues[ scriptindex ].hFilename, fn, sizeof( fn ) ))
{
return fn;
}
Expand Down Expand Up @@ -1293,7 +1289,7 @@ const char *CSoundEmitterSystemBase::GetSoundScriptName( int index ) const
return NULL;

static char fn[ 512 ];
if ( filesystem->String( m_SoundKeyValues[ index ].hFilename, fn, sizeof( fn ) ) )
if (filesystem->String( m_SoundKeyValues[ index ].hFilename, fn, sizeof( fn ) ) )
{
return fn;
}
Expand Down

0 comments on commit 34675a9

Please sign in to comment.