diff --git a/.gitignore b/.gitignore
index 5ac4b6a..eb79c13 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,11 +5,10 @@ releases/
###################
*.com
*.class
-*.dll
-*.exe
*.o
*.so
*/bin/*
+*/DLL/*
*/obj/*
bin/*
obj/*
diff --git a/NameValidator/Config.cs b/NameValidator/Config.cs
index c04c349..7494074 100644
--- a/NameValidator/Config.cs
+++ b/NameValidator/Config.cs
@@ -14,6 +14,11 @@ public class Config
///
public string Action = "kick";
+ ///
+ /// The minimum number of characters in a nickname.
+ ///
+ public int MinimumCharacters = 3;
+
///
/// The reason to use when the action is set to kick/ban.
///
@@ -34,11 +39,6 @@ public class Config
///
public List InvalidNameRegexes = new List();
- ///
- /// Whether to kick any player using characters that the Terraria font doesn't natively support.
- ///
- public bool TerrariaFontOnly = false;
-
public static Config Read(string path)
{
try
diff --git a/NameValidator/NameValidator.cs b/NameValidator/NameValidator.cs
index 0a5ad93..d3fabb4 100644
--- a/NameValidator/NameValidator.cs
+++ b/NameValidator/NameValidator.cs
@@ -1,10 +1,8 @@
using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
-using System.Windows.Media;
using Terraria;
using TerrariaApi.Server;
using TShockAPI;
@@ -14,8 +12,6 @@ namespace NameValidator
[ApiVersion(2, 1)]
public class NameValidator : TerrariaPlugin
{
- private FontFamily font;
-
public override string Author => "Enerdy";
public override string Description => "Validate character names on join based on a configuration file.";
@@ -31,25 +27,13 @@ public NameValidator(Main game)
{
Order = 10;
}
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- ServerApi.Hooks.NetGreetPlayer.Register(this, OnJoin);
- }
- }
-
+
public override void Initialize()
{
- string fontname = "Andy";
- if ((font = Fonts.SystemFontFamilies.FirstOrDefault(f => f.Source.Equals(fontname, StringComparison.OrdinalIgnoreCase))) == null)
- TShock.Log.ConsoleError($"The font '{fontname}' was not found.");
-
string path = Path.Combine(TShock.SavePath, "NameValidator.json");
Config = Config.Read(path);
- ServerApi.Hooks.NetGreetPlayer.Register(this, OnJoin);
+ ServerApi.Hooks.ServerJoin.Register(this, OnJoin);
Commands.ChatCommands.Add(new Command("namevalidator.reload", (args) =>
{
@@ -58,7 +42,16 @@ public override void Initialize()
}, "nvreload"));
}
- private void OnJoin(GreetPlayerEventArgs e)
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ ServerApi.Hooks.ServerJoin.Deregister(this, OnJoin);
+ }
+ }
+
+ //private void OnJoin(GreetPlayerEventArgs e)
+ private void OnJoin(JoinEventArgs e)
{
if (e.Handled || e.Who < 0 || e.Who > Main.player.Length - 1)
return;
@@ -67,18 +60,23 @@ private void OnJoin(GreetPlayerEventArgs e)
// If the player's name is null then it most likely isn't a real player
if (!String.IsNullOrEmpty(player?.name))
{
- string name = player.name;
+ string name = player.name.ToLower();
+ var playerX = new TSPlayer(e.Who);
+
+ if (name.Length < Config.MinimumCharacters)
+ playerX.Kick($"Minimum name length of {Config.MinimumCharacters} characters required!", true, true);
+
if (!ValidateString(name))
{
switch (Config.Action.ToLowerInvariant())
{
case "ban":
- TShock.Utils.Ban(TShock.Players[e.Who], Config.Reason);
+ TShock.Players[e.Who].Ban(Config.Reason);
TShock.Log.ConsoleInfo($"Player '{name}' was banned for \"{Config.Reason}\".");
e.Handled = true;
return;
case "kick":
- TShock.Utils.Kick(TShock.Players[e.Who], Config.Reason, silent: true);
+ TShock.Players[e.Who].Kick(Config.Reason, silent: true);
TShock.Log.ConsoleInfo($"Player '{name}' was kicked for \"{Config.Reason}\".");
e.Handled = true;
return;
@@ -88,6 +86,10 @@ private void OnJoin(GreetPlayerEventArgs e)
}
}
}
+ else
+ {
+ TShock.Log.ConsoleInfo($"An attempted connection without a null just occured.");
+ }
}
///
@@ -97,24 +99,6 @@ private void OnJoin(GreetPlayerEventArgs e)
/// Whether the string is valid.
private bool ValidateString(string s)
{
- // Font contains check
- if (Config.TerrariaFontOnly)
- {
- foreach (char c in s)
- {
- ICollection typefaces = font.GetTypefaces();
- foreach (Typeface t in typefaces)
- {
- t.TryGetGlyphTypeface(out GlyphTypeface glyph);
- if (glyph != null && !glyph.CharacterToGlyphMap.ContainsKey(Convert.ToInt16(c)))
- {
- // Spot detected
- return false;
- }
- }
- }
- }
-
// Regex check
if (Config.InvalidNameRegexes != null)
{
diff --git a/NameValidator/NameValidator.csproj b/NameValidator/NameValidator.csproj
index f05b43c..eac677d 100644
--- a/NameValidator/NameValidator.csproj
+++ b/NameValidator/NameValidator.csproj
@@ -50,25 +50,22 @@
- ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll
+ False
+ refs\Newtonsoft.Json.dll
-
+
False
- DLL\OTAPI.dll
+ refs\OTAPI.dll
-
-
-
-
-
-
-
- DLL\TerrariaServer.exe
+
+ False
+ refs\TerrariaServer.exe
-
- DLL\TShockAPI.dll
+
+ False
+ refs\TShockAPI.dll
@@ -79,6 +76,13 @@
+
+
+
+
+
+
+