Skip to content

Commit

Permalink
Implemented optional CVar sv_tags for sets a string defining the "gam…
Browse files Browse the repository at this point in the history
…etags" for this server to allows users/scripts to filter in the matchmaking/server-browser interfaces based on the value
  • Loading branch information
s1lentq committed Jan 18, 2024
1 parent f29d6c5 commit a7dec21
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions rehlds/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ extern cvar_t sv_visiblemaxplayers;
extern cvar_t sv_downloadurl;
extern cvar_t sv_allow_dlfile;
extern cvar_t sv_version;
extern cvar_t sv_tags;
#ifdef REHLDS_FIXES
extern cvar_t sv_echo_unknown_cmd;
extern cvar_t sv_auto_precache_sounds_in_models;
Expand Down
3 changes: 3 additions & 0 deletions rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ cvar_t sv_version = { "sv_version", "", FCVAR_SERVER, 0.0f, NULL };
cvar_t sv_version = {"sv_version", "", 0, 0.0f, NULL};
#endif

cvar_t sv_tags = { "sv_tags", "", 0, 0.0f, NULL };

cvar_t sv_rcon_minfailures = { "sv_rcon_minfailures", "5", 0, 0.0f, NULL };
cvar_t sv_rcon_maxfailures = { "sv_rcon_maxfailures", "10", 0, 0.0f, NULL };
cvar_t sv_rcon_minfailuretime = { "sv_rcon_minfailuretime", "30", 0, 0.0f, NULL };
Expand Down Expand Up @@ -8258,6 +8260,7 @@ void SV_Init(void)
Cvar_RegisterVariable(&sv_version);
Cvar_RegisterVariable(&sv_allow_dlfile);
#ifdef REHLDS_FIXES
Cvar_RegisterVariable(&sv_tags);
Cvar_RegisterVariable(&sv_force_ent_intersection);
Cvar_RegisterVariable(&sv_echo_unknown_cmd);
Cvar_RegisterVariable(&sv_auto_precache_sounds_in_models);
Expand Down
23 changes: 23 additions & 0 deletions rehlds/engine/sv_steam3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ CSteam3Server::CSteam3Server() :
m_CallbackLogonFailure(this, &CSteam3Server::OnLogonFailure),
m_SteamIDGS(1, 0, k_EUniverseInvalid, k_EAccountTypeInvalid)
{
#ifdef REHLDS_FIXES
m_GameTagsData[0] = '\0';
#endif

m_bHasActivePlayers = false;
m_bWantToBeSecure = false;
m_bLanOnly = false;
Expand Down Expand Up @@ -499,6 +503,23 @@ void CSteam3Server::RunFrame()
}
}

void CSteam3Server::UpdateGameTags()
{
#ifdef REHLDS_FIXES
if (!sv_tags.string[0])
return;

if (m_GameTagsData[0] && !Q_stricmp(m_GameTagsData, sv_tags.string))
return;

const int nPacketSize = MAX_ROUTEABLE_PACKET - 128; // The packet has to fit into NET_SendPacket and there's some data sent before the tags too
ISteamGameServer;
Q_strlcpy(m_GameTagsData, sv_tags.string, min(nPacketSize, MAX_STEAM_TAGS_LENGTH));
Q_strlwr(m_GameTagsData);
CRehldsPlatformHolder::get()->SteamGameServer()->SetGameTags(m_GameTagsData);
#endif
}

void CSteam3Server::SendUpdatedServerDetails()
{
int botCount = 0;
Expand All @@ -521,6 +542,8 @@ void CSteam3Server::SendUpdatedServerDetails()
CRehldsPlatformHolder::get()->SteamGameServer()->SetBotPlayerCount(botCount);
CRehldsPlatformHolder::get()->SteamGameServer()->SetServerName(Cvar_VariableString("hostname"));
CRehldsPlatformHolder::get()->SteamGameServer()->SetMapName(g_psv.name);

UpdateGameTags();
}

void CSteam3Client::Shutdown()
Expand Down
7 changes: 7 additions & 0 deletions rehlds/engine/sv_steam3.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CSteam3
bool InitModule();
};

#define MAX_STEAM_TAGS_LENGTH 128 // Steam doesn't send tags string more than 128 bytes

class CSteam3Server: public CSteam3
{
public:
Expand All @@ -71,6 +73,10 @@ class CSteam3Server: public CSteam3
bool m_bLanOnly;
CSteamID m_SteamIDGS;

#ifdef REHLDS_FIXES
char m_GameTagsData[MAX_STEAM_TAGS_LENGTH];
#endif

public:

NOBODY void SetServerType();
Expand All @@ -96,6 +102,7 @@ class CSteam3Server: public CSteam3
void NotifyOfLevelChange(bool bForce);
void RunFrame();
void SendUpdatedServerDetails();
void UpdateGameTags();
};

class CSteam3Client: public CSteam3
Expand Down

0 comments on commit a7dec21

Please sign in to comment.