Skip to content

Commit

Permalink
Fix multiple cirtical banning bugs.
Browse files Browse the repository at this point in the history
Added convar `vMenuBanCheaters` that can be used to enable/disable auto-banning of possible cheaters. Default is "false".
  • Loading branch information
TomGrobbe committed Sep 16, 2018
1 parent 4a2ea58 commit c1fdd50
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
45 changes: 27 additions & 18 deletions vMenuServer/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private async void RemoveBanRecord([FromSource]Player source, string banRecordJs
{
if (source != null && !string.IsNullOrEmpty(source.Name) && source.Name.ToLower() != "**invalid**" && source.Name.ToLower() != "** invalid **")
{
if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Unban"))
if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Unban") || IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything"))
{
dynamic obj = JsonConvert.DeserializeObject(banRecordJsonString);
BanRecord ban = JsonToBanRecord(obj);
Expand Down Expand Up @@ -458,23 +458,27 @@ private async void RemoveBanRecord([FromSource]Player source, string banRecordJs
/// <param name="source"></param>
public static async void BanCheater(Player source)
{
var ban = new BanRecord()
bool enabled = (GetConvar("vMenuBanCheaters", "false") ?? "false") == "true";
if (enabled)
{
bannedBy = "vMenu Auto Ban",
bannedUntil = new DateTime(3000, 1, 1),
banReason = "You have been automatically banned. If you believe this was done by error, please contact the server owner for support.",
identifiers = source.Identifiers.ToList(),
playerName = GetSafePlayerName(source.Name)
};
var ban = new BanRecord()
{
bannedBy = "vMenu Auto Ban",
bannedUntil = new DateTime(3000, 1, 1),
banReason = "You have been automatically banned. If you believe this was done by error, please contact the server owner for support.",
identifiers = source.Identifiers.ToList(),
playerName = GetSafePlayerName(source.Name)
};

if (await AddBan(ban))
{
TriggerEvent("vMenu:BanCheaterSuccessful", JsonConvert.SerializeObject(ban).ToString());
BanLog($"A cheater has been banned. {JsonConvert.SerializeObject(ban).ToString()}");
}
if (await AddBan(ban))
{
TriggerEvent("vMenu:BanCheaterSuccessful", JsonConvert.SerializeObject(ban).ToString());
BanLog($"A cheater has been banned. {JsonConvert.SerializeObject(ban).ToString()}");
}

source.TriggerEvent("vMenu:GoodBye"); // this is much more fun than just kicking them.
Log("A cheater has been banned because they attempted to trigger a fake event.");
source.TriggerEvent("vMenu:GoodBye"); // this is much more fun than just kicking them.
Log("A cheater has been banned because they attempted to trigger a fake event.");
}
}


Expand All @@ -485,9 +489,14 @@ public static async void BanCheater(Player source)
/// <returns></returns>
public static string GetSafePlayerName(string playerName)
{
string safeName = playerName.Replace("^", "").Replace("<", "").Replace(">", "").Replace("~", "");
safeName = Regex.Replace(safeName, @"[^\u0000-\u007F]+", string.Empty);
return safeName.Trim(new char[] { '.', ',', ' ', '!', '?' });
if (!string.IsNullOrEmpty(playerName))
{
string safeName = playerName.Replace("^", "").Replace("<", "").Replace(">", "").Replace("~", "");
safeName = Regex.Replace(safeName, @"[^\u0000-\u007F]+", string.Empty);
return safeName.Trim(new char[] { '.', ',', ' ', '!', '?' });
}
return "InvalidPlayerName";

}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions vMenuServer/MainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ private void KickPlayer([FromSource] Player source, int target, string kickReaso
}
else
{
BanManager.BanCheater(new PlayerList()[target]);
BanManager.BanCheater(source);
}
}

Expand All @@ -675,7 +675,7 @@ private void KillPlayer([FromSource] Player source, int target)
}
else
{
BanManager.BanCheater(new PlayerList()[target]);
BanManager.BanCheater(source);
}
}

Expand All @@ -700,7 +700,7 @@ private void SummonPlayer([FromSource] Player source, int target)
}
else
{
BanManager.BanCheater(new PlayerList()[target]);
BanManager.BanCheater(source);
}
}
#endregion
Expand Down

0 comments on commit c1fdd50

Please sign in to comment.