moved webclient name generation over to the connect extension. fixed pending steam ID. name is tracked with cvar value. name also sets the steamID

This commit is contained in:
jenz 2026-07-23 14:58:45 +01:00
parent 4c7ec14d52
commit dfc25da57a
3 changed files with 64 additions and 4 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ Containerfile
.venv
safetyhook
.env
secret.h

View File

@ -25,6 +25,7 @@
#include <iclient.h>
#include <ISDKTools.h>
#include <iserver.h>
#include "secret.h"
#include <string>
Connect g_connect;
@ -38,6 +39,7 @@ ConVar g_SvForceSteam("sv_forcesteam", "0", FCVAR_NOTIFY, "Force steam authentic
ConVar g_SvGameDesc("sv_gamedesc_override", "default", FCVAR_NOTIFY, "Overwrite the default game description. Set to 'default' to keep default description.");
ConVar g_SvMapName("sv_mapname_override", "default", FCVAR_NOTIFY, "Overwrite the map name. Set to 'default' to keep default name.");
ConVar g_SvSetSteamIDIPS("sv_set_steam_id_ips", "default", FCVAR_NOTIFY, "IP's allowed for webclient nosteamers");
ConVar g_SvWebclientName("sv_webclient_name", "", FCVAR_NOTIFY, "Generated name for the currently connecting webclient player.");
IGameConfig *g_pGameConf = NULL;
@ -48,6 +50,9 @@ ISDKTools *g_pSDKTools = NULL;
class IClient;
class CBaseServer;
//just grabbing clients name.
extern IVEngineServer *engine;
typedef enum EAuthProtocol
{
k_EAuthProtocolWONCertificate = 1,
@ -272,6 +277,50 @@ uint64 GenerateSteamIDFromName(const char *pchName)
return steamID64;
}
//AI generated function
static uint32_t HashString(const char *str)
{
uint32_t hash = 5381;
while (*str)
{
hash = ((hash << 5) + hash) + (unsigned char)*str;
hash = hash & 0x7fffffff;
str++;
}
return hash;
}
//AI generated function
void GenerateNickNameFromPassword(const char *pchPassword, const char *salt, char *outName, size_t outSize)
{
static const char *adjectives[] = {
"Fast","Slow","Red","Blue","Green","Dark","Bright","Wild",
"Cool","Hot","Big","Small","Sharp","Brave","Swift","Bold"
};
static const char *nouns[] = {
"Wolf","Eagle","Tiger","Bear","Fox","Lion","Hawk","Shark",
"Snake","Raven","Storm","Rock","Fire","Ice","Wind","Steel"
};
char salted[256];
V_snprintf(salted, sizeof(salted), "%s%s", pchPassword, salt);
uint32_t h1 = HashString(salted);
char salted1[256];
V_snprintf(salted1, sizeof(salted1), "%s1", salted);
uint32_t h2 = HashString(salted1);
char salted2[256];
V_snprintf(salted2, sizeof(salted2), "%s2", salted);
uint32_t h3 = HashString(salted2);
V_snprintf(outName, outSize, "%s %s %u",
adjectives[h1 % 16],
nouns[h2 % 16],
h3 % 9999
);
}
DETOUR_DECL_MEMBER1(CBaseClient__SetSteamID, void, const CSteamID &, steamID)
{
char aSteamID[32];
@ -292,10 +341,12 @@ DETOUR_DECL_MEMBER1(CBaseClient__SetSteamID, void, const CSteamID &, steamID)
//connects from the IP's designated for the webclients.
if (strcmp(IpsAllowed, ipString) == 0)
{
//changes the storages pchName
GenerateNickNameFromPassword(storage.pchPassword, NAME_SALT, storage.pchName, sizeof(storage.pchName));
uint64 steamID64 = GenerateSteamIDFromName(storage.pchName);
CSteamID newSteamID = CSteamID(steamID64);
//smutils->LogMessage(myself, "Generated SteamID64: %llu for name: %s", steamID64, storage.pchName);
//smutils->LogMessage(myself, "SteamID render: %s", newSteamID.Render());
//smutils->LogMessage(myself, "SteamID render: %s. password. %s", newSteamID.Render(), storage.pchPassword);
storage.ullSteamID = steamID64;
storage.Webclient = true;
@ -586,10 +637,9 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient*, netadr_t&, address, in
Storage.SuppressBeginAuthSession = true;
g_ConnectClientStorage.replace(aSteamID, Storage);
auto client = DETOUR_MEMBER_CALL(CBaseServer__ConnectClient)(address, nProtocol, iChallenge, iClientChallenge, nAuthProtocol, pchName, pchPassword, pCookie, cbCookie);
Storage.SuppressBeginAuthSession = false;
g_ConnectClientStorage.replace(aSteamID, Storage);
//g_pSM->LogMessage(myself, "finished DETOUR_MEMBER_CALL. %s", aSteamID);
@ -598,12 +648,17 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient*, netadr_t&, address, in
g_ConnectClientStorage.retrieve(aSteamID, &storage_setSteamID);
if (storage_setSteamID.Webclient)
{
storage_setSteamID.SuppressBeginAuthSession = false;
CSteamID newSteamID = CSteamID(storage_setSteamID.ullSteamID);
//smutils->LogMessage(myself, "Generated name after webclient check: %s", storage_setSteamID.pchName);
g_SvWebclientName.SetValue(storage_setSteamID.pchName);
storage_setSteamID.pClient = client;
//smutils->LogMessage(myself, "SteamID render after webclient check: %s", newSteamID.Render());
g_ConnectClientStorage.replace(newSteamID.Render(), storage_setSteamID);
g_ConnectClientStorage.remove(aSteamID);
if (client && SteamAuthFailed)
if (client) //webclient is always nosteamer.
{
ValidateAuthTicketResponse_t Response;
Response.m_SteamID = newSteamID;
@ -615,6 +670,7 @@ DETOUR_DECL_MEMBER9(CBaseServer__ConnectClient, IClient*, netadr_t&, address, in
}
else
{
Storage.SuppressBeginAuthSession = false;
Storage.pClient = client;
g_ConnectClientStorage.replace(aSteamID, Storage);
@ -751,6 +807,7 @@ bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late)
bool Connect::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
ConVar_Register(0, this);

View File

@ -0,0 +1,2 @@
#pragma once
#define NAME_SALT "your-salt-here"