Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from Rnen/patient-zero
Browse files Browse the repository at this point in the history
Patient Zero mode
  • Loading branch information
Rnen committed Aug 29, 2022
2 parents 57d9923 + 06b619f commit fe8bbb5
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 190 deletions.
55 changes: 43 additions & 12 deletions SCP008/Commands/EnableDisableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ namespace SCP008PLUGIN.Command
/// <summary>
/// Command for enabling/disabling <see cref="SCP008"/>
/// </summary>
class EnableDisableCommand : ICommandHandler
public class EnableDisableCommand : ICommandHandler
{
private readonly SCP008 plugin;

public EnableDisableCommand(SCP008 plugin) => this.plugin = plugin;
public string GetCommandDescription() => "Enables or disables " + plugin.Details.name;
public string GetUsage() => "SCP008";
public string GetUsage() => "SCP008 (SUBCOMMAND)";

bool IsAllowed(ICommandSender sender)
public string[] SubCommands = new string[] { "(bool / enable / disable)", "zero / patientzero", "help / git" };

private bool IsAllowed(ICommandSender sender)
{
//Checking if the ICommandSender is a player and setting the player variable if it is
Player player = (sender is Player) ? sender as Player : null;
Expand All @@ -33,12 +35,12 @@ bool IsAllowed(ICommandSender sender)

//Checks if there is any entries, if empty, let anyone use it
if (roleList != null && roleList.Count > 0
&& (roleList.Contains(player.GetUserGroup().Name.ToUpper()) || roleList.Contains(player.GetRankName().ToUpper()) ) )
&& (roleList.Contains(player.GetUserGroup().Name.ToUpper()) || roleList.Contains(player.GetRankName().ToUpper())))
{
//Config contained rank
return true;
}
else if (roleList == null || roleList.Count == 0 || (roleList.Count == 1 && string.IsNullOrEmpty(roleList.First()) ) )
else if (roleList == null || roleList.Count == 0 || (roleList.Count == 1 && string.IsNullOrEmpty(roleList.First())))
return true; // config was empty
else
return false; // config was not empty and didnt contain player role
Expand All @@ -49,17 +51,46 @@ bool IsAllowed(ICommandSender sender)

public string[] OnCall(ICommandSender sender, string[] args)
{
if(args.Length > 0 && args[0] == "help")
return plugin.PluginManager.CommandManager.CallCommand(sender, "008help", args);
if (IsAllowed(sender))
{
if (args.Length > 0 && bool.TryParse(args[0], out bool value)) // If the command contains a arguement and it can be parsed as a bool
plugin.SetIsEnabled(value);
else
plugin.SetIsEnabled(!plugin.GetIsEnabled()); //If not just toggle
if (args.Length > 0)
{
if (Utility.TryParseCommandBool(args[0], out bool b))
{
plugin.IsEnabled = b;
return new string[] { "SCP008 plugin set to " + plugin.IsEnabled };
}

switch (args[0].ToUpper())
{
case "GIT":
case "GITHUB":
return plugin.PluginManager.CommandManager.CallCommand(sender, "008help", args);
case "HELP":
return new string[] { GetUsage(), "Subcommands: " + string.Join(" ,", SubCommands) };
case "V":
case "VERSION":
return new string[] { "Plugin Version: " + plugin.Details.version, "SMod Version: " + Smod2.PluginManager.GetSmodVersion() };
case "ZERO":
case "PATIENTZERO":
if(args.Length > 1 && Utility.TryParseCommandBool(args[1], out bool b2))
{
plugin.IsEnabledZeroOnStart = b2;
return new string[] { "SCP008 PatientZero mode set to " + plugin.IsEnabledZeroOnStart};
}
else
{
plugin.IsEnabledZeroOnStart = !plugin.IsEnabledZeroOnStart;
return new string[] { "SCP008 PatientZero mode set to " + plugin.IsEnabledZeroOnStart };
}
}
return new string[] { GetUsage(), "Subcommands: " + string.Join(" ,", SubCommands) };
}
else
plugin.IsEnabled = !plugin.IsEnabled; //If not just toggle

//Returning the current state of the static bool
return new string[] { "SCP008 plugin set to " + plugin.GetIsEnabled() };
return new string[] { "SCP008 plugin set to " + plugin.IsEnabled };
}
else
return new string[] { "You dont have the required permission to run " + GetUsage() };
Expand Down
9 changes: 5 additions & 4 deletions SCP008/Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ class HelpCommand : ICommandHandler
public string[] OnCall(ICommandSender sender, string[] args)
{
if (sender is Player p && p != null)
return new string[] { "This command is only for use in server window!" };
return new string[] { "Visit https://github.com/Rnen/SCP008 for more information" };
else
{
try
{
System.Diagnostics.Process.Start("https://github.com/Rnen/SCP008");
return new string[] { "Opening browser..." };
}
catch { return new string[] { "Could not open browser!" }; }
}
catch
{
return new string[] { "Could not open browser!" };
}
}
}
}
115 changes: 73 additions & 42 deletions SCP008/Commands/InfectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class InfectCommand : ICommandHandler

public InfectCommand(SCP008 plugin) => this.plugin = plugin;
public string GetCommandDescription() => "Infects / removes infection";
public string GetUsage() => "INFECT (PLAYER)";
public string GetUsage() => "INFECT (PLAYER) [SUBCOMMAND]";

public string[] SubCommands = new string[] { "+ / add", "infect+ / ++ / zero / patientzero", "cure / remove / -" };

bool IsAllowed(ICommandSender sender)
{
Expand Down Expand Up @@ -52,63 +54,92 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
if (IsAllowed(sender))
{
if (args.Length == 0 && sender is Player p)
if (SCP008.playersToDamage.Contains(p.UserId))
if (args.Length == 0 && sender is Player p && p != null)
try
{
SCP008.playersToDamage.Remove(p.UserId);
return new string[] { "Cured infected " + p.Name };
if (SCP008.infected.Contains(p.UserID))
{
Utility.CureInfection(p, true);
return new string[] { "Cured infected " + p.Name };
}
else
{
Utility.Infect(p);
return new string[] { "Infected " + p.Name };
}
}
else
catch (Exception e)
{
SCP008.playersToDamage.Add(p.UserId);
return new string[] { "Infected " + p.Name };
return new string[] { "Infect command exception " + e };
}
else if (args.Length > 0)
{
if (args[0].ToLower() == "all" || args[0] == "*")
string arg1 = (args.Length > 1 && !string.IsNullOrEmpty(args[1])) ? args[1].ToLower() : "";
List<Player> players = new List<Player>();
switch (args[0].ToLower())
{
int x = 0;
foreach(Player pl in Server.GetPlayers()
.Where(ply =>
ply.TeamRole.Role != Smod2.API.RoleType.SPECTATOR &&
ply.TeamRole.Role != Smod2.API.RoleType.UNASSIGNED &&
ply.TeamRole.Role != Smod2.API.RoleType.ZOMBIE))
{
string arg = (args.Length > 1 && !string.IsNullOrEmpty(args[1])) ? args[1].ToLower() : "";
if (SCP008.playersToDamage.Contains(pl.UserId) && arg != "infect")
SCP008.playersToDamage.Remove(pl.UserId);
else if(!SCP008.playersToDamage.Contains(pl.UserId) && arg != "infect")
SCP008.playersToDamage.Add(pl.UserId);
x++;
}
return new string[] { "Toggled infection on " + x + " players!" };
case "all":
case "*":
players = Server.GetPlayers(i => i.PlayerRole.Team != TeamType.SPECTATOR || i.PlayerRole.Team != TeamType.NONE);
break;
case "list":
case "infected":
return new string[] { "Infected Players:", string.Join("\n", SCP008.InfectedPlayers.OrderBy(s => s.Name).Select(i => i.Name).ToList()) };
case "help":
case "subcommand":
case "subcommands":
return new string[] { GetUsage(), "Availabile subcommands:" + string.Join(" ,", SubCommands) };
default:
players = Server.GetPlayers(args[0]);
break;
}
else
{
List<Player> players = Server.GetPlayers(args[0]);
Player player;
if (players == null || players.Count == 0) return new string[] { "No players on the server called " + args[0] };
player = players.OrderBy(pl => pl.Name.Length).First();

if (!SCP008.playersToDamage.Contains(player.UserId))
{
SCP008.playersToDamage.Add(player.UserId);
return new string[] { "Infected " + player.Name };
}
else if (SCP008.playersToDamage.Contains(player.UserId))
if (players == null || players.Count == 0)
return new string[] { "No players on the server called " + args[0] };

string ret = this.plugin.Details.id + " INFECT COMMAND ERROR";

foreach (Player player in players)
switch (arg1.ToLower())
{
SCP008.playersToDamage.Remove(player.UserId);
return new string[] { "Cured infected " + player.Name };
case "+":
case "add":
Utility.Infect(player);
break;
case "++":
case "add+":
case "zero":
case "patientzero":
Utility.Infect(player, true);
return new string[] { $"Made \"{player.Name}\" into Patient Zero!" };
case "cure":
case "remove":
case "-":
SCP008.patientZero = "";
Utility.CureInfection(player);
if (players.Count == 1)
return new string[] { $"Cured \"{player.Name}\" from SCP008 infection!" };
ret = $"Cured {players.Count} players from SCP008 infection!";
break;
case "":
default:
if (SCP008.infected.Contains(player.UserID))
Utility.CureInfection(player);
else
Utility.Infect(player);
break;
}
else
return new string[] { this.plugin.Details.id + " INFECT ERROR" };
}
if (!string.IsNullOrEmpty(arg1))
return new string[] { $"Used {arg1} on {players.Count} players!" };
else
return new string[] { $"Toggled infection on {players.Count} players!" };
}
else
return new string[] { GetUsage() };
return new[] { GetUsage() };
}
else
return new string[] { "You dont have the required permission to run " + GetUsage() };
}
}
}

0 comments on commit fe8bbb5

Please sign in to comment.