1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

fix for issue #70

update start script for windows
This commit is contained in:
RaidMax
2019-03-18 10:36:31 -05:00
parent 70c65f6485
commit 52b15e5061
4 changed files with 41 additions and 30 deletions

View File

@ -1,6 +1,5 @@
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Exceptions;
using SharedLibraryCore.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
@ -23,7 +22,9 @@ namespace SharedLibraryCore.Commands
foreach (Command cmd in Manager.GetCommands())
{
if (cmd.Name == CommandString.ToLower() || cmd.Alias == CommandString.ToLower())
{
C = cmd;
}
}
if (C == null)
@ -34,6 +35,7 @@ namespace SharedLibraryCore.Commands
E.Data = E.Data.RemoveWords(1);
String[] Args = E.Data.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
// todo: the code below can be cleaned up
if (E.Origin.Level < C.Permission)
{
@ -48,31 +50,36 @@ namespace SharedLibraryCore.Commands
throw new CommandException($"{E.Origin} did not supply enough arguments for \"{C.Name}\"");
}
if (C.RequiresTarget || Args.Length > 0)
if (C.RequiresTarget)
{
if (!Int32.TryParse(Args[0], out int cNum))
cNum = -1;
if (Args[0][0] == '@') // user specifying target by database ID
if (Args.Length > 0)
{
int dbID = -1;
int.TryParse(Args[0].Substring(1, Args[0].Length - 1), out dbID);
var found = await Manager.GetClientService().Get(dbID);
if (found != null)
if (!Int32.TryParse(Args[0], out int cNum))
{
E.Target = found;
E.Target.CurrentServer = E.Owner;
E.Data = String.Join(" ", Args.Skip(1));
cNum = -1;
}
}
else if (Args[0].Length < 3 && cNum > -1 && cNum < E.Owner.MaxClients) // user specifying target by client num
{
if (E.Owner.Clients[cNum] != null)
if (Args[0][0] == '@') // user specifying target by database ID
{
E.Target = E.Owner.Clients[cNum];
E.Data = String.Join(" ", Args.Skip(1));
int dbID = -1;
int.TryParse(Args[0].Substring(1, Args[0].Length - 1), out dbID);
var found = await Manager.GetClientService().Get(dbID);
if (found != null)
{
E.Target = found;
E.Target.CurrentServer = E.Owner;
E.Data = String.Join(" ", Args.Skip(1));
}
}
else if (Args[0].Length < 3 && cNum > -1 && cNum < E.Owner.MaxClients) // user specifying target by client num
{
if (E.Owner.Clients[cNum] != null)
{
E.Target = E.Owner.Clients[cNum];
E.Data = String.Join(" ", Args.Skip(1));
}
}
}
@ -103,7 +110,7 @@ namespace SharedLibraryCore.Commands
}
}
if (E.Target == null && C.RequiresTarget) // Find active player as single word
if (E.Target == null && C.RequiresTarget && Args.Length > 0) // Find active player as single word
{
matchingPlayers = E.Owner.GetClientByName(Args[0]);
if (matchingPlayers.Count > 1)
@ -115,6 +122,7 @@ namespace SharedLibraryCore.Commands
}
throw new CommandException($"{E.Origin} had multiple players found for {C.Name}");
}
else if (matchingPlayers.Count == 1)
{
E.Target = matchingPlayers.First();
@ -141,6 +149,7 @@ namespace SharedLibraryCore.Commands
throw new CommandException($"{E.Origin} specified invalid player for \"{C.Name}\"");
}
}
E.Data = E.Data.Trim();
return C;
}