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

Commit

Permalink
1.3.6 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rnen authored Sep 23, 2018
1 parent a6b9042 commit 5283887
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 245 deletions.
100 changes: 57 additions & 43 deletions AdminToolbox/AdminToolbox/AdminToolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace AdminToolbox
name = "Admin Toolbox",
description = "Plugin for advanced admin tools",
id = "rnen.admin.toolbox",
version = "1.3.5",
version = "1.3.6",
SmodMajor = 3,
SmodMinor = 1,
SmodRevision = 13
SmodRevision = 18
)]
class AdminToolbox : Plugin
{
internal static bool isRoundFinished = false, lockRound = false, isColored = false, isColoredCommand = false, intercomLock = false, intercomLockChanged = false;
internal static bool isRoundFinished = false, lockRound = false, isColored = false, isColoredCommand = false, intercomLock = false, intercomLockChanged = false, isStarting = true;
public static Dictionary<string, AdminToolboxPlayerSettings> playerdict = new Dictionary<string, AdminToolboxPlayerSettings>();
public static Dictionary<string, Vector> warpVectors = new Dictionary<string, Vector>();
public static Dictionary<string, Vector> presetWarps { get; private set; } = new Dictionary<string, Vector>()
Expand Down Expand Up @@ -59,6 +59,7 @@ public class AdminToolboxPlayerSettings
TeamKills = 0,
Deaths = 0,
RoundsPlayed = 0,
banCount = 0,
previousHealth = 100,
prevAmmo5 = 0,
prevAmmo7 = 0,
Expand Down Expand Up @@ -130,6 +131,7 @@ public override void Register()
this.AddCommands(new string[] { "e", "empty" }, new Command.EmptyCommand());
this.AddCommands(new string[] { "atban","offlineban","oban" }, new Command.ATBanCommand(this));
this.AddCommands(new string[] { "kill", "slay" }, new Command.KillCommand(this));
this.AddCommands(new string[] { "speak" }, new Command.SpeakCommand());

#endregion
#region Config Registering Config Entries
Expand Down Expand Up @@ -176,18 +178,14 @@ public override void Register()
public static void AddMissingPlayerVariables(List<Player> players = null)
{
if (PluginManager.Manager.Server.GetPlayers().Count == 0) return;
else if (players != null && players.Count > 0)
foreach (Player player in players)
AdminToolbox.AddToPlayerDict(player);
else
foreach (Player player in PluginManager.Manager.Server.GetPlayers())
AdminToolbox.AddToPlayerDict(player);
else if ( players == null || players.Count < 1) players = PluginManager.Manager.Server.GetPlayers();
if (players.Count > 0)
players.ForEach(p => { if(p != null) AddToPlayerDict(p); });
}
private static void AddToPlayerDict(Player player)
{
if (player.SteamId != null && player.SteamId != string.Empty)
if (!playerdict.ContainsKey(player.SteamId))
playerdict.Add(player.SteamId, new AdminToolboxPlayerSettings());
if (player != null && player is Player && !string.IsNullOrEmpty(player.SteamId) && !playerdict.ContainsKey(player.SteamId))
playerdict.Add(player.SteamId, new AdminToolboxPlayerSettings());
}

public static List<Player> GetJailedPlayers(string filter = "")
Expand All @@ -206,29 +204,24 @@ public static List<Player> GetJailedPlayers(string filter = "")
myPlayers.Add(pl);
return myPlayers;
}
public static void CheckJailedPlayers(Player myPlayer = null)
public static void CheckJailedPlayers()
{
bool isInsideJail(Player pl)
{
float x = System.Math.Abs(pl.GetPosition().x - presetWarps["jail"].x), y = System.Math.Abs(pl.GetPosition().y - presetWarps["jail"].y), z = System.Math.Abs(pl.GetPosition().z - presetWarps["jail"].z);
if (x > 7 || y > 5 || z > 7) return false;
else return true;
}
if (myPlayer != null)
{
if (!AdminToolbox.playerdict.ContainsKey(myPlayer.SteamId)) { AddMissingPlayerVariables(new List<Player> { myPlayer }); return; }
AdminToolbox.playerdict[myPlayer.SteamId].isInJail = isInsideJail(myPlayer);
if (!AdminToolbox.playerdict[myPlayer.SteamId].isInJail) SendToJail(myPlayer);
else if (AdminToolbox.playerdict[myPlayer.SteamId].JailedToTime <= DateTime.Now) ReturnFromJail(myPlayer);
}
else
foreach (Player pl in GetJailedPlayers())
if (GetJailedPlayers().Count > 0)
GetJailedPlayers().ForEach(pl =>
{
if(!AdminToolbox.playerdict.ContainsKey(pl.SteamId)) { AddMissingPlayerVariables(new List<Player> { pl }); continue; }
AdminToolbox.playerdict[pl.SteamId].isInJail = isInsideJail(pl);
if (!AdminToolbox.playerdict[pl.SteamId].isInJail) SendToJail(pl);
else if (AdminToolbox.playerdict[pl.SteamId].JailedToTime <= DateTime.Now) ReturnFromJail(pl);
}
if (AdminToolbox.playerdict.ContainsKey(pl.SteamId))
{
AdminToolbox.playerdict[pl.SteamId].isInJail = isInsideJail(pl);
if (!AdminToolbox.playerdict[pl.SteamId].isInJail) SendToJail(pl);
else if (AdminToolbox.playerdict[pl.SteamId].JailedToTime <= DateTime.Now) ReturnFromJail(pl);
}
});
}

public static void SendToJail(Player ply)
Expand All @@ -248,7 +241,7 @@ public static void SendToJail(Player ply)
}
//Changes role to Tutorial, teleports to jail, removes inv.
ply.ChangeRole(Role.TUTORIAL, true, false);
ply.Teleport(AdminToolbox.warpVectors["jail"]);
ply.Teleport(AdminToolbox.warpVectors["jail"],true);
foreach (Smod2.API.Item item in ply.GetInventory())
item.Remove();
AdminToolbox.playerdict[ply.SteamId].isJailed = true;
Expand All @@ -262,7 +255,7 @@ public static void ReturnFromJail(Player ply)
{
AdminToolbox.playerdict[ply.SteamId].isJailed = false;
ply.ChangeRole(AdminToolbox.playerdict[ply.SteamId].previousRole, true, false);
ply.Teleport(AdminToolbox.playerdict[ply.SteamId].originalPos);
ply.Teleport(AdminToolbox.playerdict[ply.SteamId].originalPos,true);
AdminToolbox.playerdict[ply.SteamId].isInJail = false;
ply.SetHealth(AdminToolbox.playerdict[ply.SteamId].previousHealth);
foreach (Smod2.API.Item item in ply.GetInventory())
Expand Down Expand Up @@ -402,17 +395,24 @@ public static Player GetPlayer(string args)
if (int.TryParse(args, out int pID))
{
foreach (Player pl in PluginManager.Manager.Server.GetPlayers())
if (pl.PlayerId == pID || pl.SteamId == pID.ToString())
if (pl.PlayerId == pID)
return pl;
}
else if (long.TryParse(args, out long sID))
{
foreach (Player pl in PluginManager.Manager.Server.GetPlayers())
if (pl.SteamId == sID.ToString())
return pl;
}
else
{
//Takes a string and finds the closest player from the playerlist
int maxNameLength = 31, LastnameDifference = 31/*, lastNameLength = 31*/;
int maxNameLength = 31, LastnameDifference = 31;
string str1 = args.ToLower();
foreach (Player pl in PluginManager.Manager.Server.GetPlayers(str1))
{
if (!pl.Name.ToLower().Contains(args.ToLower())) { goto NoPlayer; }
if (!pl.Name.ToLower().Contains(args.ToLower()))
continue;
if (str1.Length < maxNameLength)
{
int x = maxNameLength - str1.Length;
Expand All @@ -433,7 +433,6 @@ public static Player GetPlayer(string args)
playerOut = pl;
}
}
NoPlayer:;
}
}
return playerOut;
Expand All @@ -460,7 +459,8 @@ public class LogHandler
private bool unifiedStats = ConfigManager.Manager.Config.GetBoolValue("admintoolbox_stats_unified", true);

private static string AdminToolboxFolder = (ConfigManager.Manager.Config.GetStringValue("admintoolbox_folder_path", string.Empty) != string.Empty) ? ConfigManager.Manager.Config.GetStringValue("admintoolbox_folder_path", FileManager.AppFolder + "AdminToolbox") : FileManager.AppFolder + "AdminToolbox";
private static string AdminToolboxPlayerStats = (ConfigManager.Manager.Config.GetBoolValue("admintoolbox_stats_unified", true)) ? AdminToolboxFolder + Path.DirectorySeparatorChar + "PlayerStats" + Path.DirectorySeparatorChar + "Global" : AdminToolboxFolder + Path.DirectorySeparatorChar + "PlayerStats" + Path.DirectorySeparatorChar + PluginManager.Manager.Server.Port, AdminToolboxLogs = AdminToolboxFolder + Path.DirectorySeparatorChar + "ServerLogs";
private static string AdminToolboxPlayerStats = (ConfigManager.Manager.Config.GetBoolValue("admintoolbox_stats_unified", true)) ? AdminToolboxFolder + Path.DirectorySeparatorChar + "PlayerStats" + Path.DirectorySeparatorChar + "Global" : AdminToolboxFolder + Path.DirectorySeparatorChar + "PlayerStats" + Path.DirectorySeparatorChar + PluginManager.Manager.Server.Port,
AdminToolboxLogs = AdminToolboxFolder + Path.DirectorySeparatorChar + "ServerLogs";


public enum ServerLogType
Expand Down Expand Up @@ -530,6 +530,17 @@ public void AddLog(string msg, ServerLogType type)
streamWriter.Close();
}
}

public void ManageDatedLogs()
{
int configInt = ConfigManager.Manager.Config.GetIntValue("admintoolbox_logremover_hours_old", 0);

if(configInt > 0)
{
Directory.GetFiles(AdminToolboxLogs).ToList().ForEach(path => { if ((DateTime.Now - File.GetCreationTime(path)).TotalHours > configInt) File.Delete(path); } );
}
}

private void MoveOldFiles()
{
string infoString = (Directory.GetDirectories(FileManager.AppFolder + "ATServerLogs").Length > 0) ? "\n\n Relocated folders: " : string.Empty;
Expand Down Expand Up @@ -601,9 +612,10 @@ void WriteToFile(Player pl)
int TeamKills = (AdminToolbox.playerdict.ContainsKey(pl.SteamId) && AdminToolbox.playerdict[pl.SteamId].TeamKills > 0) ? AdminToolbox.playerdict[pl.SteamId].TeamKills : 0;
int Deaths = (AdminToolbox.playerdict.ContainsKey(pl.SteamId) && AdminToolbox.playerdict[pl.SteamId].Deaths > 0) ? AdminToolbox.playerdict[pl.SteamId].Deaths : 0;
double minutesPlayed = (AdminToolbox.playerdict.ContainsKey(pl.SteamId) && AdminToolbox.playerdict[pl.SteamId].minutesPlayed > 0) ? DateTime.Now.Subtract(AdminToolbox.playerdict[pl.SteamId].joinTime).TotalMinutes + AdminToolbox.playerdict[pl.SteamId].minutesPlayed : 0;
if(AdminToolbox.playerdict.ContainsKey(pl.SteamId)) AdminToolbox.playerdict[pl.SteamId].joinTime = DateTime.Now;
int BanCount = (AdminToolbox.playerdict.ContainsKey(pl.SteamId) && AdminToolbox.playerdict[pl.SteamId].banCount > 0) ? AdminToolbox.playerdict[pl.SteamId].banCount : 0;
if (AdminToolbox.playerdict.ContainsKey(pl.SteamId)) AdminToolbox.playerdict[pl.SteamId].joinTime = DateTime.Now;
StreamWriter streamWriter = new StreamWriter(playerFilePath, false);
string str = string.Empty + Kills + splitChar + TeamKills + splitChar + Deaths + splitChar + minutesPlayed;
string str = string.Empty + Kills + splitChar + TeamKills + splitChar + Deaths + splitChar + minutesPlayed + splitChar + BanCount;
streamWriter.Write(str);
streamWriter.Close();
ReadFromFile(pl);
Expand All @@ -613,15 +625,16 @@ void ReadFromFile(Player pl)
string playerFilePath = (AdminToolbox.playerdict.ContainsKey(pl.SteamId)) ? AdminToolboxPlayerStats + Path.DirectorySeparatorChar + pl.SteamId + ".txt" : AdminToolboxPlayerStats + Path.DirectorySeparatorChar + "server" + ".txt";
if (!File.Exists(playerFilePath))
PlayerStatsFileManager(new List<Player> { pl }, LogHandlers.PlayerFile.Write);
string[] fileStrings = (File.ReadAllLines(playerFilePath).Length > 0) ? File.ReadAllLines(playerFilePath) : new string[] { "0;0;0;0" };
string[] playerStats = fileStrings[0].Split(splitChar);
string[] fileStrings = (File.ReadAllLines(playerFilePath).Length > 0) ? File.ReadAllLines(playerFilePath) : new string[] { "0;0;0;0;0" };
string[] playerStats = fileStrings.First().Split(splitChar);
if (AdminToolbox.playerdict.ContainsKey(pl.SteamId))
{
//AdminToolbox.AdminToolboxPlayerSettings myPlayer = AdminToolbox.playerdict[pl.SteamId];
AdminToolbox.playerdict[pl.SteamId].Kills = (playerStats.Length > 0 && int.TryParse(playerStats[0], out int x1) && x1 > AdminToolbox.playerdict[pl.SteamId].Kills) ? x1 : AdminToolbox.playerdict[pl.SteamId].Kills;
AdminToolbox.playerdict[pl.SteamId].TeamKills = (playerStats.Length > 1 && int.TryParse(playerStats[1], out int x2) && x2 > AdminToolbox.playerdict[pl.SteamId].TeamKills) ? x2 : AdminToolbox.playerdict[pl.SteamId].TeamKills;
AdminToolbox.playerdict[pl.SteamId].Deaths = (playerStats.Length > 2 && int.TryParse(playerStats[2], out int x3) && x3 > AdminToolbox.playerdict[pl.SteamId].Deaths) ? x3 : AdminToolbox.playerdict[pl.SteamId].Deaths;
AdminToolbox.playerdict[pl.SteamId].minutesPlayed = (playerStats.Length > 3 && double.TryParse(playerStats[3], out double x4) && x4 > AdminToolbox.playerdict[pl.SteamId].minutesPlayed) ? x4 : AdminToolbox.playerdict[pl.SteamId].minutesPlayed;
AdminToolbox.playerdict[pl.SteamId].Kills = (playerStats.Length > 0 && int.TryParse(playerStats[0], out int x0) && x0 > AdminToolbox.playerdict[pl.SteamId].Kills) ? x0 : AdminToolbox.playerdict[pl.SteamId].Kills;
AdminToolbox.playerdict[pl.SteamId].TeamKills = (playerStats.Length > 1 && int.TryParse(playerStats[1], out int x1) && x1 > AdminToolbox.playerdict[pl.SteamId].TeamKills) ? x1 : AdminToolbox.playerdict[pl.SteamId].TeamKills;
AdminToolbox.playerdict[pl.SteamId].Deaths = (playerStats.Length > 2 && int.TryParse(playerStats[2], out int x2) && x2 > AdminToolbox.playerdict[pl.SteamId].Deaths) ? x2 : AdminToolbox.playerdict[pl.SteamId].Deaths;
AdminToolbox.playerdict[pl.SteamId].minutesPlayed = (playerStats.Length > 3 && double.TryParse(playerStats[3], out double x3) && x3 > AdminToolbox.playerdict[pl.SteamId].minutesPlayed) ? x3 : AdminToolbox.playerdict[pl.SteamId].minutesPlayed;
AdminToolbox.playerdict[pl.SteamId].banCount = (playerStats.Length > 4 && int.TryParse(playerStats[4], out int x4) && x4 > AdminToolbox.playerdict[pl.SteamId].banCount) ? x4 : AdminToolbox.playerdict[pl.SteamId].banCount;
//AdminToolbox.playerdict[pl.SteamId] = myPlayer;
}
}
Expand All @@ -641,13 +654,14 @@ public static void SetPlayerBools(string steamID, bool? spectatorOnly = null, bo
AdminToolbox.playerdict[steamID].instantKill = (instantKill.HasValue) ? (bool)instantKill : AdminToolbox.playerdict[steamID].instantKill;
AdminToolbox.playerdict[steamID].isJailed = (isJailed.HasValue) ? (bool)isJailed : AdminToolbox.playerdict[steamID].isJailed;
}
public static void SetPlayerStats(string steamID, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null)
public static void SetPlayerStats(string steamID, int? Kills = null, int? TeamKills = null, int? Deaths = null, int? RoundsPlayed = null, int? BanCount = null)
{
if (!AdminToolbox.playerdict.ContainsKey(steamID)) return;
AdminToolbox.playerdict[steamID].Kills = (Kills.HasValue) ? (int)Kills : AdminToolbox.playerdict[steamID].Kills;
AdminToolbox.playerdict[steamID].TeamKills = (TeamKills.HasValue) ? (int)TeamKills : AdminToolbox.playerdict[steamID].TeamKills; ;
AdminToolbox.playerdict[steamID].Deaths = (Deaths.HasValue) ? (int)Deaths : AdminToolbox.playerdict[steamID].Deaths;
AdminToolbox.playerdict[steamID].RoundsPlayed = (RoundsPlayed.HasValue) ? (int)RoundsPlayed : AdminToolbox.playerdict[steamID].RoundsPlayed;
AdminToolbox.playerdict[steamID].banCount = (BanCount.HasValue) ? (int)BanCount : AdminToolbox.playerdict[steamID].banCount;
}
}
}
13 changes: 7 additions & 6 deletions AdminToolbox/AdminToolbox/AdminToolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\SCPSL\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
<Reference Include="Assembly-CSharp, Version=11.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Smod2">
<HintPath>..\..\..\SCPSL\Smod2.dll</HintPath>
<Private>False</Private>
<Reference Include="Smod2, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\SCP_SL_SERVER\SCPSL_Data\Managed\Smod2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -61,6 +61,7 @@
<Compile Include="Commands\ATColorCommand.cs" />
<Compile Include="Commands\JailCommand.cs" />
<Compile Include="Commands\EmptyCommand.cs" />
<Compile Include="Commands\SpeakCommand.cs" />
<Compile Include="Commands\ServerCommand.cs" />
<Compile Include="Commands\RoundLockCommand.cs" />
<Compile Include="Commands\WarpsCommand.cs" />
Expand Down
49 changes: 25 additions & 24 deletions AdminToolbox/AdminToolbox/Commands/ATBanCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using Smod2;
using Smod2.API;
using Smod2.Commands;
Expand All @@ -8,7 +7,6 @@ namespace AdminToolbox.Command
{
public class ATBanCommand : ICommandHandler
{

private Plugin plugin;

public ATBanCommand(Plugin plugin)
Expand All @@ -18,7 +16,7 @@ public ATBanCommand(Plugin plugin)

public string GetUsage()
{
return "ATBAN [NAME] [IP/SteamID] [MINUTES]";
return "ATBAN [NAME] [IP/SteamID] [MINUTES] (OPTIONAL REASON)";
}

public string GetCommandDescription()
Expand All @@ -30,37 +28,40 @@ public string[] OnCall(ICommandSender sender, string[] args)
{
try
{
if (args.Length != 3) return new string[] { GetUsage() };
string ipBanPath = FileManager.AppFolder + "IpBans.txt";
string sidBanPath = FileManager.AppFolder + "SteamIdBans.txt";
string outs = "";
if (args.Length < 3) return new string[] { GetUsage() };

string IssuingPlayer = (sender is Player pl && !string.IsNullOrEmpty(pl.SteamId)) ? pl.Name : "Server";
DateTime bannedTime; ;
if (double.TryParse(args[2], out var minutes))
bannedTime = DateTime.Now.AddMinutes(minutes);
else
return new string[] { "Wrong time format: " + args[2] };
string bannedPlayer = args[0];
string input = args[1];
int minutes = (int.TryParse(args[2], out int x)) ? x : 0;
string reason = (args.Length > 3) ? args[3] : "";

if (minutes < 1)
return new string[] { "Wrong time format: \"" + minutes + "\"" };

if (args[1].Contains("."))

if (input.Contains("."))
{
if (args[1].Split('.').Length != 4) return new string[] { "Invalid IP: " + args[1] };
string ip = (args[1].Contains("::ffff:")) ? args[1] : "::ffff:" + args[1];
outs += args[0] + ";" + ip + ";" + bannedTime.Ticks + ";;" + IssuingPlayer + ";" + DateTime.Now.Ticks;
File.AppendAllText(ipBanPath, "\n" + outs);
if (IssuingPlayer != "Server") plugin.Info("Player with name: " + args[0] + " and with IP: " + args[1] + " was banned for " + args[2] + " minutes by " + IssuingPlayer);
return new string[] { "Player with name: " + args[0] + " and with IP: " + args[1] + " was banned for " + args[2] + " minutes by " + IssuingPlayer };
if (input.Split('.').Length != 4) return new string[] { "Invalid IP: " + input };
string ip = (input.Contains("::ffff:")) ? input : "::ffff:" + input;

PluginManager.Manager.Server.BanIpAddress(bannedPlayer, ip, minutes, reason, IssuingPlayer);

if (IssuingPlayer != "Server") plugin.Info("Player with name: " + bannedPlayer + " and with IP: " + ip + " was banned for " + minutes + " minutes by " + IssuingPlayer);
return new string[] { "Player with name: " + bannedPlayer + " and with IP: " + ip + " was banned for " + minutes + " minutes by " + IssuingPlayer };
}
else
{
outs += args[0] + ";" + args[1] + ";" + bannedTime.Ticks + ";;" + IssuingPlayer + ";" + DateTime.Now.Ticks;
File.AppendAllText(sidBanPath, "\n" + outs);
if (IssuingPlayer != "Server") plugin.Info("Player with name: " + args[0] + " and with SteamID: " + args[1] + " was banned for " + args[2] + " minutes by " + IssuingPlayer);
return new string[] { "Player with name: " + args[0] + " and with SteamID: " + args[1] + " was banned for " + args[2] + " minutes by " + IssuingPlayer };
PluginManager.Manager.Server.BanSteamId(args[0], input, minutes, reason, IssuingPlayer);

if (IssuingPlayer != "Server") plugin.Info("Player with name: " + bannedPlayer + " and with SteamID: " + input + " was banned for " + minutes + " minutes by " + IssuingPlayer);
return new string[] { "Player with name: " + IssuingPlayer + " and with SteamID: " + input + " was banned for " + minutes + " minutes by " + IssuingPlayer };
}
}
catch (Exception e)
{
return new string[] { e.StackTrace };
plugin.Error(e.StackTrace);
return new string[] { "Encountered an error! Check server window." };
}
}
}
Expand Down
Loading

0 comments on commit 5283887

Please sign in to comment.