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:
parent
027efc7f11
commit
77d7e506e5
1 changed files with 34 additions and 0 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue