Skip to content

Commit

Permalink
Build integrity + server print neo_version info
Browse files Browse the repository at this point in the history
* Server now just prints neo_version on startup
* Server and client long git hashes are now matched up on startup to
  check build integrity. If they don't, the client cannot connect unless
  they have matching git hashes.
* Server convar `neo_sv_build_integrity_check` to enable/disable this
  integrity check feature. Enabled by default.
* fixes NeotokyoRebuild#437
* fixes NeotokyoRebuild#485
  • Loading branch information
nullsystem committed Jul 7, 2024
1 parent 87c0230 commit e266b6d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions mp/src/game/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ target_sources_grouped(
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.cpp
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.h
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.cpp
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.h
)

target_sources_grouped(
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,7 @@ target_sources_grouped(
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.cpp
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_shot_manipulator.h
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.cpp
${CMAKE_SOURCE_DIR}/game/shared/neo/neo_version.h
neo/neo_client.cpp
neo/neo_detpack.cpp
neo/neo_detpack.h
Expand Down
2 changes: 2 additions & 0 deletions mp/src/game/server/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ extern ConVar tf_mm_servermode;

#ifdef NEO
#include "neo_mount_original.h"
#include "neo_version.h"
#endif

extern IToolFrameworkServer *g_pToolFrameworkServer;
Expand Down Expand Up @@ -643,6 +644,7 @@ bool CServerGameDLL::DLLInit( CreateInterfaceFn appSystemFactory,
{
return false;
}
neoVersionPrint();
#endif

// Yes, both the client and game .dlls will try to Connect, the soundemittersystem.dll will handle this gracefully
Expand Down
21 changes: 21 additions & 0 deletions mp/src/game/shared/neo/neo_gamerules.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "cbase.h"
#include "neo_gamerules.h"
#include "neo_version_info.h"
#include "in_buttons.h"
#include "ammodef.h"

Expand Down Expand Up @@ -36,6 +37,13 @@ ConVar neo_sv_player_restore("neo_sv_player_restore", "1", FCVAR_REPLICATED, "If
ConVar neo_name("neo_name", "", FCVAR_USERINFO | FCVAR_ARCHIVE, "The nickname to set instead of the steam profile name.");
ConVar cl_onlysteamnick("cl_onlysteamnick", "0", FCVAR_USERINFO | FCVAR_ARCHIVE, "Only show players Steam names, otherwise show player set names.", true, 0.0f, true, 1.0f);

#ifdef GAME_DLL
ConVar neo_sv_build_integrity_check("neo_sv_build_integrity_check", "1", FCVAR_GAMEDLL | FCVAR_REPLICATED,
"If enabled, the server checkes the build's Git hash between the client and"
" the server. If it doesn't match, the server rejects and disconnects the client.",
true, 0.0f, true, 1.0f);
#endif

REGISTER_GAMERULES_CLASS( CNEORules );

BEGIN_NETWORK_TABLE_NOBASE( CNEORules, DT_NEORules )
Expand Down Expand Up @@ -1291,6 +1299,19 @@ void CNEORules::RestartGame()
#ifdef GAME_DLL
bool CNEORules::ClientConnected(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
{
if (neo_sv_build_integrity_check.GetBool())
{
const char *clientGitHash = engine->GetClientConVarValue(engine->IndexOfEdict(pEntity), "__neo_cl_git_hash");
if (V_strcmp(clientGitHash, GIT_LONGHASH))
{
// Truncate the git hash so it's short hash and doesn't make message too long
static constexpr int MAX_GITHASH_SHOW = 7;
V_snprintf(reject, maxrejectlen, "Build integrity failed! Client vs server mis-match: Check your neo_version. "
"Client: %.*s | Server: %.*s",
MAX_GITHASH_SHOW, clientGitHash, MAX_GITHASH_SHOW, GIT_LONGHASH);
return false;
}
}
return BaseClass::ClientConnected(pEntity, pszName, pszAddress,
reject, maxrejectlen);
#if(0)
Expand Down
13 changes: 9 additions & 4 deletions mp/src/game/shared/neo/neo_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include "convar.h"
#include "dbg.h"

namespace {
void neoVersionCallback()
void neoVersionPrint()
{
#if defined(GAME_DLL)
static constexpr char HEADER[] = "neo_version (Server's build info):";
#else defined(CLIENT_DLL)
#elif defined(CLIENT_DLL)
static constexpr char HEADER[] = "neo_version (Client's build info):";
#endif
Msg("%s\n"
Expand All @@ -25,10 +24,16 @@ void neoVersionCallback()
COMPILER_ID, COMPILER_VERSION);
}

namespace {
#ifdef CLIENT_DLL
constexpr int NEO_VERSION_FLAGS = 0;
#else
constexpr int NEO_VERSION_FLAGS = FCVAR_HIDDEN;
#endif
ConCommand neo_version("neo_version", neoVersionCallback, "Print out client/server's build's information.", NEO_VERSION_FLAGS);
ConCommand neo_version("neo_version", neoVersionPrint, "Print out client/server's build's information.", NEO_VERSION_FLAGS);

#ifdef CLIENT_DLL
ConVar __neo_cl_git_hash("__neo_cl_git_hash", GIT_LONGHASH,
FCVAR_USERINFO | FCVAR_HIDDEN | FCVAR_DONTRECORD | FCVAR_NOT_CONNECTED | FCVAR_PRINTABLEONLY);
#endif
}
3 changes: 3 additions & 0 deletions mp/src/game/shared/neo/neo_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void neoVersionPrint();

0 comments on commit e266b6d

Please sign in to comment.