Browse Source

Change Commands feature to use configured steamIDs

Previously we've used hardcoded steam ids to test commands on our
servers. Proper priviledge system still wasn't introduced, but
hardcoding ourselves before public release is a shitty idea, so I've
added an alternative crutch instead: server admin can now specify steam
ids of players allowed to use commands in the config.

This is a temporary workaround and to be replaced later.
pull/8/head
Anton Tarasenko 2 years ago
parent
commit
a689e84b8f
  1. 35
      sources/Commands/Commands.uc
  2. 18
      sources/Commands/Commands_Feature.uc

35
sources/Commands/Commands.uc

@ -21,35 +21,58 @@ class Commands extends FeatureConfig
perobjectconfig perobjectconfig
config(AcediaSystem); config(AcediaSystem);
var public config bool useChatInput; var public config bool useChatInput;
var public config bool useMutateInput; var public config bool useMutateInput;
var public config string chatCommandPrefix; var public config string chatCommandPrefix;
var public config array<string> allowedPlayers;
protected function HashTable ToData() protected function HashTable ToData()
{ {
local int i;
local HashTable data; local HashTable data;
local ArrayList playerList;
data = __().collections.EmptyHashTable(); data = __().collections.EmptyHashTable();
data.SetBool(P("useChatInput"), useChatInput, true); data.SetBool(P("useChatInput"), useChatInput, true);
data.SetBool(P("useMutateInput"), useMutateInput, true); data.SetBool(P("useMutateInput"), useMutateInput, true);
data.SetString(P("chatCommandPrefix"), chatCommandPrefix); data.SetString(P("chatCommandPrefix"), chatCommandPrefix);
playerList = _.collections.EmptyArrayList();
for (i = 0; i < allowedPlayers.length; i += 1) {
playerList.AddString(allowedPlayers[i]);
}
data.SetItem(P("allowedPlayers"), playerList);
playerList.FreeSelf();
return data; return data;
} }
protected function FromData(HashTable source) protected function FromData(HashTable source)
{ {
local int i;
local ArrayList playerList;
if (source == none) { if (source == none) {
return; return;
} }
useChatInput = source.GetBool(P("useChatInput")); useChatInput = source.GetBool(P("useChatInput"));
useMutateInput = source.GetBool(P("useMutateInput")); useMutateInput = source.GetBool(P("useMutateInput"));
chatCommandPrefix = source.GetString(P("chatCommandPrefix"), "!"); chatCommandPrefix = source.GetString(P("chatCommandPrefix"), "!");
playerList = source.GetArrayList(P("allowedPlayers"));
allowedPlayers.length = 0;
if (playerList == none) {
return;
}
for (i = 0; i < playerList.GetLength(); i += 1) {
allowedPlayers[allowedPlayers.length] = playerList.GetString(i);
}
playerList.FreeSelf();
} }
protected function DefaultIt() protected function DefaultIt()
{ {
useChatInput = true; useChatInput = true;
useMutateInput = true; useMutateInput = true;
chatCommandPrefix = "!"; chatCommandPrefix = "!";
allowedPlayers.length = 0;
} }
defaultproperties defaultproperties

18
sources/Commands/Commands_Feature.uc

@ -46,6 +46,9 @@ var private /*config*/ bool useMutateInput;
// Chat messages, prepended by this prefix will be treated as commands. // Chat messages, prepended by this prefix will be treated as commands.
// Default is "!". Empty values are also treated as "!". // Default is "!". Empty values are also treated as "!".
var private /*config*/ Text chatCommandPrefix; var private /*config*/ Text chatCommandPrefix;
// List of steam IDs of players allowed to use commands.
// Temporary measure until a better solution is finished.
var private /*config*/ array<string> allowedPlayers;
var LoggerAPI.Definition errCommandDuplicate; var LoggerAPI.Definition errCommandDuplicate;
@ -94,6 +97,7 @@ protected function SwapConfig(FeatureConfig config)
} }
_.memory.Free(chatCommandPrefix); _.memory.Free(chatCommandPrefix);
chatCommandPrefix = _.text.FromString(newConfig.chatCommandPrefix); chatCommandPrefix = _.text.FromString(newConfig.chatCommandPrefix);
allowedPlayers = newConfig.allowedPlayers;
if (useChatInput != newConfig.useChatInput) if (useChatInput != newConfig.useChatInput)
{ {
useChatInput = newConfig.useChatInput; useChatInput = newConfig.useChatInput;
@ -423,6 +427,8 @@ public final function array<Text> GetGroupsNames()
*/ */
public final function HandleInput(Parser parser, EPlayer callerPlayer) public final function HandleInput(Parser parser, EPlayer callerPlayer)
{ {
local int i;
local bool foundID;
local string steamID; local string steamID;
local PlayerController controller; local PlayerController controller;
local Command commandInstance; local Command commandInstance;
@ -435,11 +441,15 @@ public final function HandleInput(Parser parser, EPlayer callerPlayer)
if (controller == none) return; if (controller == none) return;
steamID = controller.GetPlayerIDHash(); steamID = controller.GetPlayerIDHash();
if ( steamID != "76561198025127722" for (i = 0; i < allowedPlayers.length; i += 1)
&& steamID != "76561198044316328"
&& steamID != "76561198003353515"
&& steamID != "76561198281136503")
{ {
if (allowedPlayers[i] == steamID)
{
foundID = true;
break;
}
}
if (!foundID) {
return; return;
} }
parser.MUntilMany(commandName, commandDelimiters, true, true); parser.MUntilMany(commandName, commandDelimiters, true, true);

Loading…
Cancel
Save