diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 6be3eff6..327d1ce4 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -7,6 +7,7 @@ using Terraria; using TerrariaAPI; using TerrariaAPI.Hooks; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace TShockAPI { @@ -60,8 +61,10 @@ namespace TShockAPI GameHooks.OnUpdate += new Action(OnUpdate); GameHooks.OnLoadContent += new Action(OnLoadContent); ServerHooks.OnChat += new Action(OnChat); + ServerHooks.OnJoin += new Action(OnJoin); } + /* * Hooks: * */ @@ -94,6 +97,16 @@ namespace TShockAPI } } + + void OnJoin(int ply, AllowEventArgs handler) + { + string ip = GetRealIP((Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint))); + if (CheckBanned(ip) || CheckCheat(ip) || CheckGreif(ip)) + { + Kick(ply, "Your account has been disabled."); + } + } + void OnLoadContent(Microsoft.Xna.Framework.Content.ContentManager obj) { @@ -106,7 +119,7 @@ namespace TShockAPI void OnPostInit() { - + } void OnUpdate(GameTime time) @@ -118,6 +131,43 @@ namespace TShockAPI * Useful stuff: * */ + public static bool CheckGreif(String ip) + { + ip = GetRealIP(ip); + if (!banTnt) { return false; } + TextReader tr = new StreamReader(saveDir + "grief.txt"); + string list = tr.ReadToEnd(); + tr.Close(); + + return list.Contains(ip); + } + + public static bool CheckCheat(String ip) + { + ip = GetRealIP(ip); + if (!banCheater) { return false; } + TextReader tr = new StreamReader(saveDir + "cheaters.txt"); + string trr = tr.ReadToEnd(); + tr.Close(); + if (trr.Contains(ip)) + { + return true; + } + return false; + } + + public static bool CheckBanned(String p) + { + String ip = p.Split(':')[0]; + TextReader tr = new StreamReader(saveDir + "bans.txt"); + string banlist = tr.ReadToEnd(); + tr.Close(); + banlist = banlist.Trim(); + if (banlist.Contains(ip)) + return true; + return false; + } + private static void KeepTilesUpToDate() { TextReader tr = new StreamReader(saveDir + "tiles.txt"); diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 5482ca86..5b24c5bf 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -33,6 +33,7 @@ +