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.
This commit is contained in:
Lucas Nicodemus 2012-05-30 13:55:56 -06:00
parent 027efc7f11
commit 77d7e506e5

View file

@ -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;
}
/// <summary>
/// Handles exceptions that we didn't catch or that Red fucked up
/// </summary>