Skip to content

Commit 017abb8

Browse files
committed
enable command reloading and better register function
1 parent 118709e commit 017abb8

File tree

8 files changed

+208
-258
lines changed

8 files changed

+208
-258
lines changed

game/quiver/info_changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Added the following Source SDK Pull Requests:
4949
- #1480: Fixed Widowmaker not giving metal on friendly disguises
5050
- #1481: Workaround for CTFStatPanel not hiding on freezecam screenshot
5151
- #1483: (Temporary) Fix issues with dynamic models on listen servers
52+
- #948: Add proper server admin tools (heavily modified)
5253

5354
Details:
5455
- Fixed a bug where the mini-crit damage effect doesn't show up when your shield breaks.

src/game/server/admin/base_serveradmin.cpp

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include "fmtstr.h"
99

1010
//MODULES
11-
#include "serveradmin_command_base.h"
11+
#include "serveradmin_register.h"
1212

1313
// always comes last
1414
#include "tier0/memdbgon.h"
1515

16+
#ifdef BDSBASE
17+
1618
CBase_Admin *g_pBaseAdmin = NULL;
1719
bool g_bAdminSystem = false;
1820

@@ -91,7 +93,7 @@ CBase_Admin::CBase_Admin()
9193
m_steamID = NULL;
9294
m_permissions = NULL;
9395

94-
InitAdminCommands();
96+
RegisterCommands();
9597
}
9698

9799
CBase_Admin::~CBase_Admin()
@@ -283,6 +285,8 @@ bool IsSteamIDAdmin( const char *steamID )
283285
return false;
284286
}
285287

288+
//ConVar sa_listenserverhostimmune("sa_listenserverhostimmune", "1", FCVAR_DEVELOPMENTONLY);
289+
286290
//-----------------------------------------------------------------------------
287291
// Purpose: Check if a player has admin permissions
288292
//-----------------------------------------------------------------------------
@@ -291,7 +295,7 @@ bool CBase_Admin::IsPlayerAdmin( CBasePlayer *pPlayer, const char *requiredFlags
291295
if ( !pPlayer )
292296
return false;
293297

294-
if ( !engine->IsDedicatedServer() && pPlayer == UTIL_GetListenServerHost() )
298+
if (!engine->IsDedicatedServer() && pPlayer == UTIL_GetListenServerHost())
295299
{
296300
// We only need to see this once
297301
if ( !bIsListenServerMsg )
@@ -470,6 +474,8 @@ int CBase_Admin::GetRedNumber()
470474
return TEAM_REBELS;
471475
#elif TF_DLL
472476
return TF_TEAM_RED;
477+
#else
478+
return TEAM_UNASSIGNED;
473479
#endif
474480
}
475481

@@ -479,6 +485,8 @@ int CBase_Admin::GetBlueNumber()
479485
return TEAM_COMBINE;
480486
#elif TF_DLL
481487
return TF_TEAM_BLUE;
488+
#else
489+
return TEAM_UNASSIGNED;
482490
#endif
483491
}
484492

@@ -755,13 +763,13 @@ bool CBase_Admin::FindSpecialTargetGroup( const char *targetSpecifier )
755763
//-----------------------------------------------------------------------------
756764
AdminCommandFunction FindAdminCommand(const char* cmd)
757765
{
758-
FOR_EACH_VEC(BaseAdmin()->g_AdminCommands, i)
766+
FOR_EACH_VEC(BaseAdmin()->GetCommands(), i)
759767
{
760-
const CommandEntry& entry = BaseAdmin()->g_AdminCommands[i];
768+
const CommandEntry *entry = BaseAdmin()->GetCommands()[i];
761769

762-
if (Q_stricmp(entry.chatCommand, cmd) == 0)
770+
if (Q_stricmp(entry->chatCommand, cmd) == 0)
763771
{
764-
return entry.function;
772+
return entry->function;
765773
}
766774
}
767775

@@ -770,11 +778,11 @@ AdminCommandFunction FindAdminCommand(const char* cmd)
770778

771779
bool IsCommandAllowed(const char* cmd, bool isServerConsole, CBasePlayer* pAdmin)
772780
{
773-
FOR_EACH_VEC(BaseAdmin()->g_AdminCommands, i)
781+
FOR_EACH_VEC(BaseAdmin()->GetCommands(), i)
774782
{
775-
const CommandEntry& entry = BaseAdmin()->g_AdminCommands[i];
783+
const CommandEntry *entry = BaseAdmin()->GetCommands()[i];
776784

777-
if (Q_stricmp(entry.chatCommand, cmd) == 0)
785+
if (Q_stricmp(entry->chatCommand, cmd) == 0)
778786
{
779787
if (!isServerConsole)
780788
{
@@ -787,9 +795,22 @@ bool IsCommandAllowed(const char* cmd, bool isServerConsole, CBasePlayer* pAdmin
787795

788796
if (!bImmunity)
789797
{
790-
if (!CBase_Admin::IsPlayerAdmin(pAdmin, entry.requiredFlags))
798+
if (strchr(entry->requiredFlags, ADMIN_UNDEFINED) != NULL)
791799
{
792-
return false;
800+
return true;
801+
}
802+
803+
if (!CBase_Admin::IsPlayerAdmin(pAdmin, entry->requiredFlags))
804+
{
805+
//do we at least have the b flag?
806+
if (CBase_Admin::IsPlayerAdmin(pAdmin, "b"))
807+
{
808+
return true;
809+
}
810+
else
811+
{
812+
return false;
813+
}
793814
}
794815
}
795816
}
@@ -803,39 +824,6 @@ bool IsCommandAllowed(const char* cmd, bool isServerConsole, CBasePlayer* pAdmin
803824
return false;
804825
}
805826

806-
void PrintCommandHelpStrings(bool isServerConsole, CBasePlayer *pAdmin)
807-
{
808-
const char* szTitle = "[Server Admin] Usage: sa <command> [arguments]\n==============================================\n\n";
809-
810-
if (isServerConsole)
811-
{
812-
Msg(szTitle);
813-
}
814-
else
815-
{
816-
ClientPrint(pAdmin, HUD_PRINTCONSOLE, szTitle);
817-
}
818-
819-
FOR_EACH_VEC(BaseAdmin()->g_AdminCommands, i)
820-
{
821-
const CommandEntry& entry = BaseAdmin()->g_AdminCommands[i];
822-
823-
if (IsCommandAllowed(entry.chatCommand, isServerConsole, pAdmin))
824-
{
825-
const char* szMsg = UTIL_VarArgs("[%s] %s %s\n", entry.moduleName, entry.chatCommand, entry.helpMessage);
826-
827-
if (isServerConsole)
828-
{
829-
Msg(szMsg);
830-
}
831-
else
832-
{
833-
ClientPrint(pAdmin, HUD_PRINTCONSOLE, szMsg);
834-
}
835-
}
836-
}
837-
}
838-
839827
//-----------------------------------------------------------------------------
840828
// Purpose: Initialize the admin system (parse the file, add admins, register commands)
841829
//-----------------------------------------------------------------------------
@@ -901,11 +889,6 @@ void CBase_Admin::InitAdminSystem()
901889
}
902890
}
903891

904-
void CBase_Admin::InitAdminCommands()
905-
{
906-
LoadBaseCommandModule();
907-
}
908-
909892
//-----------------------------------------------------------------------------
910893
// Purpose: Checks chat for certain strings (chat commands)
911894
//-----------------------------------------------------------------------------
@@ -925,30 +908,30 @@ void CBase_Admin::CheckChatText( char *p, int bufsize )
925908

926909
FOR_EACH_VEC(g_pBaseAdmin->g_AdminCommands, i)
927910
{
928-
const CommandEntry& entry = g_pBaseAdmin->g_AdminCommands[i];
911+
const CommandEntry *entry = g_pBaseAdmin->g_AdminCommands[i];
929912

930-
size_t cmdLen = strlen(entry.chatCommand);
931-
if (Q_strncmp(p, entry.chatCommand, cmdLen) == 0)
913+
size_t cmdLen = strlen(entry->chatCommand);
914+
if (Q_strncmp(p, entry->chatCommand, cmdLen) == 0)
932915
{
933916
char consoleCmd[256];
934917

935-
if (entry.requiresArguments)
918+
if (entry->requiresArguments)
936919
{
937920
const char* args = p + cmdLen;
938-
Q_snprintf(consoleCmd, sizeof(consoleCmd), "%s%s", entry.consoleCommand, args);
921+
Q_snprintf(consoleCmd, sizeof(consoleCmd), "%s%s", entry->consoleCommand, args);
939922
}
940923
else
941924
{
942-
Q_snprintf(consoleCmd, sizeof(consoleCmd), "%s", entry.consoleCommand);
925+
Q_snprintf(consoleCmd, sizeof(consoleCmd), "%s", entry->consoleCommand);
943926
}
944927

945928
if (pPlayer)
946929
{
947930
pPlayer->SetLastCommandWasFromChat(true);
948931
engine->ClientCommand(pPlayer->edict(), consoleCmd);
949-
if (entry.consoleMessage)
932+
if (entry->consoleMessage)
950933
{
951-
ClientPrint(pPlayer, HUD_PRINTTALK, entry.consoleMessage);
934+
ClientPrint(pPlayer, HUD_PRINTTALK, entry->consoleMessage);
952935
}
953936
}
954937
return;
@@ -1044,4 +1027,18 @@ void CBase_Admin::LogAction( CBasePlayer *pAdmin, CBasePlayer *pTarget, const ch
10441027

10451028
filesystem->FPrintf( g_AdminLogFile, "%s", logEntry.Get() );
10461029
filesystem->Flush( g_AdminLogFile );
1047-
}
1030+
}
1031+
1032+
void CBase_Admin::ReloadCommands(void)
1033+
{
1034+
g_AdminCommands.PurgeAndDeleteElements();
1035+
RegisterCommands();
1036+
DevMsg("Reloaded commands.\n");
1037+
}
1038+
1039+
void ToggleModule_ChangeCallback(IConVar* pConVar, char const* pOldString, float flOldValue)
1040+
{
1041+
BaseAdmin()->ReloadCommands();
1042+
}
1043+
1044+
#endif

src/game/server/admin/base_serveradmin.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef BASE_SERVERADMIN_H
22
#define BASE_SERVERADMIN_H
33

4-
#include "admin\serveradmin_command_core.h"
4+
#ifdef BDSBASE
5+
6+
#include "admin\serveradmin_core.h"
57

68
#define VERSION "1.0"
79

@@ -73,8 +75,7 @@ class CBase_Admin
7375
const char *GetSteamID() const { return m_steamID; }
7476

7577
static void InitAdminSystem();
76-
void AddCommand(CommandEntry entry) {g_AdminCommands.AddToTail(entry);}
77-
static CUtlMap<CUtlString, AdminData_t> &GetAdminMap();
78+
static CUtlMap<CUtlString, AdminData_t>& GetAdminMap();
7879
static bool ParseAdminFile( const char *filename, CUtlMap<CUtlString, AdminData_t> &outAdminMap );
7980
static void SaveAdminCache(); // For persisting updated list if needed
8081
static bool IsPlayerAdmin( CBasePlayer *pPlayer, const char *requiredFlags );
@@ -86,6 +87,10 @@ class CBase_Admin
8687
static void CheckChatText( char *p, int bufsize );
8788
static void LogAction( CBasePlayer *pAdmin, CBasePlayer *pTarget, const char *action, const char *details = "", const char *groupTarget = nullptr );
8889

90+
CUtlVector<CommandEntry *>& GetCommands() { return g_AdminCommands; }
91+
void AddCommand(CommandEntry *entry) { g_AdminCommands.AddToTail(entry); }
92+
void ReloadCommands();
93+
8994
int GetRedNumber();
9095
int GetBlueNumber();
9196

@@ -109,12 +114,6 @@ class CBase_Admin
109114
void TargetAllBots( bool enabled ) { bBots = enabled; }
110115
void TargetAllHumans( bool enabled ) { bHumans = enabled; }
111116

112-
private:
113-
void InitAdminCommands();
114-
115-
public:
116-
CUtlVector<CommandEntry> g_AdminCommands;
117-
118117
private:
119118
const char *m_steamID;
120119
const char *m_permissions;
@@ -131,6 +130,8 @@ class CBase_Admin
131130
bool bHumans;
132131

133132
static bool bIsListenServerMsg;
133+
134+
CUtlVector<CommandEntry *> g_AdminCommands;
134135
};
135136

136137
extern CUtlVector<CBase_Admin *> g_AdminList;
@@ -174,4 +175,17 @@ extern AdminCommandFunction FindAdminCommand(const char* cmd);
174175
extern bool IsCommandAllowed(const char* cmd, bool isServerConsole, CBasePlayer* pAdmin);
175176
extern void PrintCommandHelpStrings(bool isServerConsole, CBasePlayer* pAdmin);
176177

178+
extern void ToggleModule_ChangeCallback(IConVar* pConVar, char const* pOldString, float flOldValue);
179+
180+
#define CONVAR_MODULE_TOGGLE(name, defaultVal, flags, helpString) \
181+
ConVar moduleToggle(name, defaultVal, flags, helpString, ToggleModule_ChangeCallback);
182+
183+
#define REGISTER_ADMIN_COMMAND(toggleCvarName, moduleName, chatName, commandName, usesArguments, consoleText, helpString, flags, func) \
184+
{ConVarRef toggleCvar( toggleCvarName ); \
185+
if (toggleCvar.GetBool()) \
186+
{ \
187+
BaseAdmin()->AddCommand(new CommandEntry{ moduleName, chatName, commandName, usesArguments, consoleText, helpString, flags, func }); \
188+
}}
189+
#endif
190+
177191
#endif // BASE_SERVERADMIN_H

0 commit comments

Comments
 (0)