Browse Source

Fix some commands accepting empty player list

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
c99603a114
  1. 24
      sources/Commands/PlayersParser.uc

24
sources/Commands/PlayersParser.uc

@ -112,6 +112,7 @@ public final function SetSelf(EPlayer newSelfPlayer)
private final function InsertPlayer(EPlayer toInsert) private final function InsertPlayer(EPlayer toInsert)
{ {
local int i; local int i;
if (toInsert == none) { if (toInsert == none) {
return; return;
} }
@ -128,6 +129,7 @@ private final function InsertPlayer(EPlayer toInsert)
private final function AddByKey(int key) private final function AddByKey(int key)
{ {
local int i; local int i;
for (i = 0; i < playersSnapshot.length; i += 1) for (i = 0; i < playersSnapshot.length; i += 1)
{ {
if (playersSnapshot[i].GetIdentity().GetKey() == key) { if (playersSnapshot[i].GetIdentity().GetKey() == key) {
@ -141,6 +143,7 @@ private final function AddByKey(int key)
private final function RemoveByKey(int key) private final function RemoveByKey(int key)
{ {
local int i; local int i;
while (i < currentSelection.length) while (i < currentSelection.length)
{ {
if (currentSelection[i].GetIdentity().GetKey() == key) { if (currentSelection[i].GetIdentity().GetKey() == key) {
@ -157,7 +160,10 @@ private final function AddByName(BaseText name)
{ {
local int i; local int i;
local Text nextPlayerName; local Text nextPlayerName;
if (name == none) return;
if (name == none) {
return;
}
for (i = 0; i < playersSnapshot.length; i += 1) for (i = 0; i < playersSnapshot.length; i += 1)
{ {
nextPlayerName = playersSnapshot[i].GetName(); nextPlayerName = playersSnapshot[i].GetName();
@ -174,6 +180,7 @@ private final function RemoveByName(BaseText name)
{ {
local int i; local int i;
local Text nextPlayerName; local Text nextPlayerName;
while (i < currentSelection.length) while (i < currentSelection.length)
{ {
nextPlayerName = currentSelection[i].GetName(); nextPlayerName = currentSelection[i].GetName();
@ -191,6 +198,7 @@ private final function RemoveByName(BaseText name)
private final function AddAdmins() private final function AddAdmins()
{ {
local int i; local int i;
for (i = 0; i < playersSnapshot.length; i += 1) for (i = 0; i < playersSnapshot.length; i += 1)
{ {
if (playersSnapshot[i].IsAdmin()) { if (playersSnapshot[i].IsAdmin()) {
@ -203,6 +211,7 @@ private final function AddAdmins()
private final function RemoveAdmins() private final function RemoveAdmins()
{ {
local int i; local int i;
while (i < currentSelection.length) while (i < currentSelection.length)
{ {
if (currentSelection[i].IsAdmin()) { if (currentSelection[i].IsAdmin()) {
@ -242,6 +251,7 @@ private final function AddByMacro(BaseText macroText)
private final function RemoveByMacro(BaseText macroText) private final function RemoveByMacro(BaseText macroText)
{ {
local int i; local int i;
if (macroText.Compare(T(TADMIN), SCASE_INSENSITIVE)) if (macroText.Compare(T(TADMIN), SCASE_INSENSITIVE))
{ {
RemoveAdmins(); RemoveAdmins();
@ -272,6 +282,7 @@ private final function ParseSelector(Parser parser)
{ {
local bool additiveSelector; local bool additiveSelector;
local Parser.ParserState confirmedState; local Parser.ParserState confirmedState;
if (parser == none) return; if (parser == none) return;
if (!parser.Ok()) return; if (!parser.Ok()) return;
@ -314,9 +325,11 @@ private final function ParseSelector(Parser parser)
private final function ParseKeySelector(Parser parser, bool additiveSelector) private final function ParseKeySelector(Parser parser, bool additiveSelector)
{ {
local int key; local int key;
if (parser == none) return; if (parser == none) return;
if (!parser.Ok()) return; if (!parser.Ok()) return;
if (!parser.MInteger(key).Ok()) return; if (!parser.MInteger(key).Ok()) return;
if (additiveSelector) { if (additiveSelector) {
AddByKey(key); AddByKey(key);
} }
@ -331,6 +344,7 @@ private final function ParseMacroSelector(Parser parser, bool additiveSelector)
{ {
local MutableText macroName; local MutableText macroName;
local Parser.ParserState confirmedState; local Parser.ParserState confirmedState;
if (parser == none) return; if (parser == none) return;
if (!parser.Ok()) return; if (!parser.Ok()) return;
@ -356,12 +370,13 @@ private final function ParseNameSelector(Parser parser, bool additiveSelector)
{ {
local MutableText playerName; local MutableText playerName;
local Parser.ParserState confirmedState; local Parser.ParserState confirmedState;
if (parser == none) return; if (parser == none) return;
if (!parser.Ok()) return; if (!parser.Ok()) return;
confirmedState = parser.GetCurrentState(); confirmedState = parser.GetCurrentState();
playerName = ParseLiteral(parser); playerName = ParseLiteral(parser);
if (!parser.Ok()) if (!parser.Ok() || playerName.IsEmpty())
{ {
_.memory.Free(playerName); _.memory.Free(playerName);
return; return;
@ -383,6 +398,7 @@ private final function MutableText ParseLiteral(Parser parser)
{ {
local MutableText literal; local MutableText literal;
local Parser.ParserState confirmedState; local Parser.ParserState confirmedState;
if (parser == none) return none; if (parser == none) return none;
if (!parser.Ok()) return none; if (!parser.Ok()) return none;
@ -405,6 +421,7 @@ public final function array<EPlayer> GetPlayers()
{ {
local int i; local int i;
local array<EPlayer> result; local array<EPlayer> result;
for (i = 0; i < currentSelection.length; i += 1) for (i = 0; i < currentSelection.length; i += 1)
{ {
if (currentSelection[i].IsExistent()) { if (currentSelection[i].IsExistent()) {
@ -426,8 +443,10 @@ public final function array<EPlayer> GetPlayers()
public final function bool ParseWith(Parser parser) public final function bool ParseWith(Parser parser)
{ {
local Parser.ParserState confirmedState; local Parser.ParserState confirmedState;
if (parser == none) return false; if (parser == none) return false;
if (!parser.Ok()) return false; if (!parser.Ok()) return false;
if (parser.HasFinished()) return false;
Reset(); Reset();
confirmedState = parser.Skip().GetCurrentState(); confirmedState = parser.Skip().GetCurrentState();
@ -482,6 +501,7 @@ public final function bool Parse(BaseText toParse)
{ {
local bool wasSuccessful; local bool wasSuccessful;
local Parser parser; local Parser parser;
if (toParse == none) { if (toParse == none) {
return false; return false;
} }

Loading…
Cancel
Save