Browse Source

Add command locks

pull/12/head
Anton Tarasenko 2 years ago
parent
commit
52f9aa5aa5
  1. 72
      sources/BaseAPI/API/Commands/CommandAPI.uc

72
sources/BaseAPI/API/Commands/CommandAPI.uc

@ -26,6 +26,13 @@ var private array< class<Command> > pendingClasses;
// Job that is supposed to register pending commands
var private CommandRegistrationJob registeringJob;
// Saves `HashTable` with command locks.
// Locks are simply boolean switches that mark for commands whether they can be executed.
//
// Lock is considered "unlocked" if this `HashTable` stores `true` at the key with its name
// and `false` otherwise.
var private HashTable commandLocks;
var private Commands_Feature commandsFeature;
// DO NOT CALL MANUALLY
@ -152,5 +159,70 @@ public final function Execute_S(string commandLine, EPlayer callerPlayer) {
}
}
/// Closes a command lock with a given case-insensitive name.
///
/// Command locks are basically just boolean values that commands can use to check for whether they
/// are allowed to perform certain actions (e.g. cheats).
public final function bool Lock(BaseText lockName) {
local Text lowerCaseName;
if (lockName == none) return false;
if (commandsFeature == none) return false;
if (commandLocks == none) {
commandLocks = _.collections.EmptyHashTable();
}
lowerCaseName = lockName.LowerCopy();
commandLocks.SetBool(lowerCaseName, true);
lowerCaseName.FreeSelf();
return true;
}
/// Opens a command lock with a given case-insensitive name.
///
/// Command locks are basically just boolean values that commands can use to check for whether they
/// are allowed to perform certain actions (e.g. cheats).
public final function bool Unlock(BaseText lockName) {
local Text lowerCaseName;
if (lockName == none) return false;
if (commandsFeature == none) return false;
if (commandLocks == none) {
commandLocks = _.collections.EmptyHashTable();
}
lowerCaseName = lockName.LowerCopy();
commandLocks.SetBool(lowerCaseName, false);
lowerCaseName.FreeSelf();
return true;
}
/// Checks if a command lock with a given case-insensitive name is closed.
///
/// Command locks are basically just boolean values that commands can use to check for whether they
/// are allowed to perform certain actions (e.g. cheats).
public final function bool IsLocked(BaseText lockName) {
local bool result;
local Text lowerCaseName;
if (lockName == none) return true;
if (commandsFeature == none) return true;
if (commandLocks == none) return true;
lowerCaseName = lockName.LowerCopy();
result = commandLocks.GetBool(lowerCaseName);
lowerCaseName.FreeSelf();
return result;
}
/// Closes all command locks.
///
/// Command locks are basically just boolean values that commands can use to check for whether they
/// are allowed to perform certain actions (e.g. cheats).
public final function CloseAllLocks() {
_.memory.Free(commandLocks);
commandLocks = none;
}
defaultproperties {
}
Loading…
Cancel
Save