Skip to content

Commit

Permalink
Fixed ver server tag disappearing
Browse files Browse the repository at this point in the history
Improved server tags code
Bumped revision number
  • Loading branch information
danielga committed Apr 3, 2021
1 parent a7f8c94 commit 5074d8a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
4 changes: 2 additions & 2 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace global

LUA->CreateTable( );

LUA->PushString( "serversecure 1.5.34" );
LUA->PushString( "serversecure 1.5.35" );
LUA->SetField( -2, "Version" );

// version num follows LuaJIT style, xxyyzz
LUA->PushNumber( 10534 );
LUA->PushNumber( 10535 );
LUA->SetField( -2, "VersionNum" );

LUA->PushCFunction( GetClientCount );
Expand Down
72 changes: 54 additions & 18 deletions source/netfilter/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <cstring>
#include <queue>
#include <string>
#include <unordered_map>

#if defined SYSTEM_WINDOWS

Expand Down Expand Up @@ -102,14 +101,23 @@ namespace netfilter
std::vector<uint8_t> buffer;
};

struct server_tags_t
{
std::string gm;
std::string gmws;
std::string gmc;
std::string loc;
std::string ver;
};

struct reply_info_t
{
std::string game_dir;
std::string game_version;
std::string game_desc;
int32_t max_clients = 0;
int32_t udp_port = 0;
std::unordered_map<std::string, std::string> tags;
server_tags_t tags;
};

enum class PacketType
Expand Down Expand Up @@ -230,21 +238,26 @@ namespace netfilter
reply_info.udp_port = global::server->GetUDPPort( );

{
reply_info.tags.clear( );

const IGamemodeSystem::Information &gamemode =
static_cast<CFileSystem_Stdio *>( filesystem )->Gamemodes( )->Active( );

reply_info.tags["gm"] = gamemode.name;
if( !gamemode.name.empty( ) )
reply_info.tags.gm = gamemode.name;
else
reply_info.tags.gm.clear( );

if( gamemode.workshopid != 0 )
reply_info.tags["gmws"] = std::to_string( gamemode.workshopid );
reply_info.tags.gmws = std::to_string( gamemode.workshopid );
else
reply_info.tags.gmws.clear( );

if( !gamemode.category.empty( ) )
reply_info.tags["gmc"] = gamemode.category;
reply_info.tags.gmc = gamemode.category;
else
reply_info.tags.gmc.clear( );

if( game_version != nullptr )
reply_info.tags["ver"] = game_version;
reply_info.tags.ver = game_version;
}

{
Expand Down Expand Up @@ -274,17 +287,38 @@ namespace netfilter
}
}

static std::string ConcatenateTags( const std::unordered_map<std::string, std::string> &tags )
static std::string ConcatenateTags( const server_tags_t &tags )
{
std::string strtags;
for( const auto &tag : tags )

if( !tags.gm.empty( ) )
{
strtags += "gm:";
strtags += tags.gm;
}

if( !tags.gmws.empty( ) )
{
if( !strtags.empty( ) )
strtags += ' ';
strtags += strtags.empty( ) ? "gmws:" : " gmws:";
strtags += tags.gmws;
}

if( !tags.gmc.empty( ) )
{
strtags += strtags.empty( ) ? "gmc:" : " gmc:";
strtags += tags.gmc;
}

strtags += tag.first;
strtags += ':';
strtags += tag.second;
if( !tags.loc.empty( ) )
{
strtags += strtags.empty( ) ? "loc:" : " loc:";
strtags += tags.loc;
}

if( !tags.ver.empty( ) )
{
strtags += strtags.empty( ) ? "ver:" : " ver:";
strtags += tags.ver;
}

return strtags;
Expand Down Expand Up @@ -332,10 +366,12 @@ namespace netfilter
const uint64_t steamid = sid != nullptr ? sid->ConvertToUint64( ) : 0;

if( sv_location != nullptr )
reply_info.tags["loc"] = sv_location->GetString( );
reply_info.tags.loc = sv_location->GetString( );
else
reply_info.tags.loc.clear( );

const bool has_tags = !reply_info.tags.empty( );
const std::string tags = has_tags ? ConcatenateTags( reply_info.tags ) : std::string( );
const std::string tags = ConcatenateTags( reply_info.tags );
const bool has_tags = !tags.empty( );

info_cache_packet.Reset( );

Expand Down

0 comments on commit 5074d8a

Please sign in to comment.