Skip to content

Commit

Permalink
Add commands to refresh config cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch committed Mar 6, 2022
1 parent 0f2e4dc commit 31fddd8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 30 deletions.
74 changes: 44 additions & 30 deletions addons/sourcemod/scripting/prophunt.sp
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,7 @@ public void OnPluginStart()
g_PropConfigs = new ArrayList(sizeof(PropConfig));

// Read global prop config
char file[PLATFORM_MAX_PATH];
BuildPath(Path_SM, file, sizeof(file), "configs/prophunt/props.cfg");

KeyValues kv = new KeyValues("Props");
if (kv.ImportFromFile(file))
{
if (kv.GotoFirstSubKey(false))
{
do
{
PropConfig config;
config.ReadFromKv(kv);
g_PropConfigs.PushArray(config);
}
while (kv.GotoNextKey(false));
kv.GoBack();
}
kv.GoBack();
}
delete kv;
ReadPropConfig();

// Set up everything that needs gamedata
GameData gamedata = new GameData("prophunt");
Expand Down Expand Up @@ -250,16 +231,7 @@ public void OnMapStart()
PrecacheSound(UNLOCK_SOUND);

// Read map config
char file[PLATFORM_MAX_PATH];
if (GetMapConfigFilepath(file, sizeof(file)))
{
KeyValues kv = new KeyValues("PropHunt");
if (kv.ImportFromFile(file))
{
g_CurrentMapConfig.ReadFromKv(kv);
}
delete kv;
}
ReadMapConfig();
}

public void OnMapEnd()
Expand Down Expand Up @@ -516,6 +488,48 @@ void TogglePlugin(bool enable)
SetWinningTeam(TFTeam_Unassigned);
}

void ReadPropConfig()
{
g_PropConfigs.Clear();

char file[PLATFORM_MAX_PATH];
BuildPath(Path_SM, file, sizeof(file), PROP_CONFIG_FILEPATH);

KeyValues kv = new KeyValues("Props");
if (kv.ImportFromFile(file))
{
if (kv.GotoFirstSubKey(false))
{
do
{
PropConfig config;
config.ReadFromKv(kv);
g_PropConfigs.PushArray(config);
}
while (kv.GotoNextKey(false));
kv.GoBack();
}
kv.GoBack();
}
delete kv;
}

void ReadMapConfig()
{
g_CurrentMapConfig.Clear();

char file[PLATFORM_MAX_PATH];
if (GetMapConfigFilepath(file, sizeof(file)))
{
KeyValues kv = new KeyValues("PropHunt");
if (kv.ImportFromFile(file))
{
g_CurrentMapConfig.ReadFromKv(kv);
}
delete kv;
}
}

bool SearchForProps(int client, char[] message, int maxlength)
{
return SearchForEntityProps(client, message, maxlength) || SearchForStaticProps(client, message, maxlength);
Expand Down
14 changes: 14 additions & 0 deletions addons/sourcemod/scripting/prophunt/console.sp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void Console_Initialize()
{
RegAdminCmd("sm_getmodel", ConCmd_GetModel, ADMFLAG_CHEATS);
RegAdminCmd("sm_setmodel", ConCmd_SetModel, ADMFLAG_CHEATS);
RegAdminCmd("sm_reloadconfigs", ConCmd_ReloadConfigs, ADMFLAG_CONFIG);
}

void Console_Toggle(bool enable)
Expand Down Expand Up @@ -157,6 +158,19 @@ public Action ConCmd_SetModel(int client, int args)
return Plugin_Handled;
}

public Action ConCmd_ReloadConfigs(int client, int args)
{
if (!g_IsEnabled)
return Plugin_Continue;

ReadPropConfig();
ReadMapConfig();

CReplyToCommand(client, "%s %t", PLUGIN_TAG, "PH_Command_ReloadConfig_Success");

return Plugin_Handled;
}

public Action CommandListener_Build(int client, const char[] command, int argc)
{
if (argc < 1)
Expand Down
5 changes: 5 additions & 0 deletions addons/sourcemod/translations/prophunt.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@
"#format" "{1:s},{2:t}"
"en" "Forced model {lightgreen}{1} {default}on {2}."
}

"PH_Command_ReloadConfig_Success"
{
"en" "Configuration cache has been refreshed."
}
}

0 comments on commit 31fddd8

Please sign in to comment.