From 77d7e506e5248ce1c5280d0d1e4157cedd5a15cf Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Wed, 30 May 2012 13:55:56 -0600 Subject: [PATCH] Implemented the new NameCollision hook. In other words, people that cancel connection at the password screen that meet certain conditions will be disconnected if another attempt happens from that same IP. --- TShockAPI/TShock.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 4324c0a7..ac854852 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -223,6 +223,7 @@ namespace TShockAPI ProjectileHooks.SetDefaults += OnProjectileSetDefaults; WorldHooks.StartHardMode += OnStartHardMode; WorldHooks.SaveWorld += SaveManager.Instance.OnSaveWorld; + NetHooks.NameCollision += NetHooks_NameCollision; GetDataHandlers.InitGetDataHandler(); Commands.InitCommands(); @@ -322,6 +323,7 @@ namespace TShockAPI ProjectileHooks.SetDefaults -= OnProjectileSetDefaults; WorldHooks.StartHardMode -= OnStartHardMode; WorldHooks.SaveWorld -= SaveManager.Instance.OnSaveWorld; + NetHooks.NameCollision -= NetHooks_NameCollision; if (File.Exists(Path.Combine(SavePath, "tshock.pid"))) { @@ -334,6 +336,38 @@ namespace TShockAPI base.Dispose(disposing); } + void NetHooks_NameCollision(int who, string name, HandledEventArgs e) + { + string ip = TShock.Utils.GetRealIP(Netplay.serverSock[who].tcpClient.Client.RemoteEndPoint.ToString()); + foreach (TSPlayer ply in TShock.Players) + { + if (ply == null) + { + continue; + } + if (ply.Name == name && ply.Index != who) + { + if (ply.IP == ip) + { + if (ply.State < 2) + { + Console.WriteLine("A name collision has occurred and a client was kicked with less stateful data."); + Utils.ForceKick(ply, "Name collision and this client has no world data.", true, false); + e.Handled = true; + return; + } + else + { + e.Handled = false; + return; + } + } + } + } + e.Handled = false; + return; + } + /// /// Handles exceptions that we didn't catch or that Red fucked up ///