Skip to content

Commit

Permalink
Add loadout access convar (#21)
Browse files Browse the repository at this point in the history
Adds the ability for the server operator to (temporarily) disable access to loadouts.

Co-authored-by: nosoop <[email protected]>
  • Loading branch information
jack5github and nosoop authored May 11, 2021
1 parent ca131fb commit 1335cea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions scripting/cwx.sp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Cookie g_ItemPersistCookies[NUM_PLAYER_CLASSES][NUM_ITEMS];

bool g_bForceReequipItems[MAXPLAYERS + 1];

ConVar sm_cwx_enable_loadout;

#include "cwx/item_config.sp"
#include "cwx/item_entity.sp"
#include "cwx/item_export.sp"
Expand All @@ -82,6 +84,9 @@ public void OnPluginStart() {

CreateVersionConVar("cwx_version", "Custom Weapons X version.");

sm_cwx_enable_loadout = CreateConVar("sm_cwx_enable_loadout", "1",
"Allows players to receive custom items they have selected.");

RegAdminCmd("sm_cwx_equip", EquipItemCmd, ADMFLAG_ROOT);
RegAdminCmd("sm_cwx_equip_target", EquipItemCmdTarget, ADMFLAG_ROOT);

Expand Down Expand Up @@ -239,6 +244,10 @@ Action OnPlayerLoadoutUpdated(UserMsg msg_id, BfRead msg, const int[] players,
}

void OnPlayerLoadoutUpdatedPost(UserMsg msg_id, bool sent) {
if (!sm_cwx_enable_loadout.BoolValue) {
return;
}

int client = GetClientFromSerial(s_LastUpdatedClient);
int playerClass = view_as<int>(TF2_GetPlayerClass(client));

Expand Down Expand Up @@ -281,6 +290,10 @@ void OnPlayerSpawnPost(Event event, const char[] name, bool dontBroadcast) {
* avoid returning a nullptr.
*/
MRESReturn OnGetLoadoutItemPost(int client, Handle hReturn, Handle hParams) {
if (!sm_cwx_enable_loadout.BoolValue) {
return MRES_Ignored;
}

// TODO: work around invalid class items being invalidated
int playerClass = DHookGetParam(hParams, 1);
int loadoutSlot = DHookGetParam(hParams, 2);
Expand Down Expand Up @@ -395,6 +408,11 @@ void OnClientCustomLoadoutItemModified(int client, int modifiedClass) {
return;
}

if (!sm_cwx_enable_loadout.BoolValue) {
// do nothing if user selections are disabled
return;
}

if (IsPlayerInRespawnRoom(client) && IsPlayerAlive(client)) {
// see if the player is into being respawned on loadout changes
QueryClientConVar(client, "tf_respawn_on_loadoutchanges", OnLoadoutRespawnPreference);
Expand Down
6 changes: 5 additions & 1 deletion scripting/cwx/loadout_radio_menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ static int OnLoadoutSlotMenuEvent(Menu menu, MenuAction action, int param1, int

SetGlobalTransTarget(client);

char buffer[64];
char buffer[192];
FormatEx(buffer, sizeof(buffer), "Custom Weapons X");

if (!sm_cwx_enable_loadout.BoolValue) {
Format(buffer, sizeof(buffer), "%s\n%t", buffer, "CustomItemsUnavailable");
}

panel.SetTitle(buffer);

SetGlobalTransTarget(LANG_SERVER);
Expand Down
4 changes: 4 additions & 0 deletions translations/cwx.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,8 @@
{
"en" "[No custom item]"
}
"CustomItemsUnavailable"
{
"en" "(Custom items are currently disabled by the server operator.)"
}
}

0 comments on commit 1335cea

Please sign in to comment.