From 0afb85f24216dbffc5c379015a414e79a03dfa21 Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 01:20:58 -0600 Subject: [PATCH 1/9] Ugh --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eacd5b25..0281722e 100644 --- a/.gitignore +++ b/.gitignore @@ -42,4 +42,5 @@ Thumbs.db *.sdf *.opensdf *.cache -*.txt \ No newline at end of file +*.txt +*.pdb \ No newline at end of file From f87a14577ebfd4b874a62be071727c9027f8122f Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 01:23:45 -0600 Subject: [PATCH 2/9] Added shitty config system --- TShockAPI/TShock.cs | 99 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index e92b8120..e33f8534 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -13,6 +13,25 @@ namespace TShockAPI public class TShock : TerrariaPlugin { public static string saveDir = "./tshock/"; + private static double version = 3; + private static bool shownVersion = false; + + public static bool killGuide = true; + public static int invasionMultiplier = 1; + public static int defaultMaxSpawns = 4; + public static int defaultSpawnRate = 700; + public static bool kickCheater = true; + public static bool banCheater = true; + public static int serverPort = 7777; + public static bool enableWhitelist = false; + public static bool infinateInvasion = false; + public static bool permaPvp = false; + public static int killCount = 0; + public static bool shownOneTimeInvasionMinder = false; + + public static string tileWhitelist = ""; + private static bool banTnt = false; + private static bool kickTnt = false; public override Version Version { @@ -99,6 +118,86 @@ namespace TShockAPI * Useful stuff: * */ + private static void KeepTilesUpToDate() + { + TextReader tr = new StreamReader(saveDir + "tiles.txt"); + string file = tr.ReadToEnd(); + tr.Close(); + if (!file.Contains("0x3d")) + { + System.IO.File.Delete(saveDir + "tiles.txt"); + CreateFile(saveDir + "tiles.txt"); + TextWriter tw = new StreamWriter(saveDir + "tiles.txt"); + tw.Write("0x03, 0x05, 0x14, 0x25, 0x18, 0x18, 0x20, 0x1b, 0x34, 0x48, 0x33, 0x3d, 0x47, 0x49, 0x4a, 0x35, 0x3d, 0x3e, 0x45, 0x47, 0x49, 0x4a,"); + tw.Close(); + } + } + + public static void SetupConfig() + { + if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); } + if (!System.IO.File.Exists(saveDir + "tiles.txt")) + { + CreateFile(saveDir + "tiles.txt"); + TextWriter tw = new StreamWriter(saveDir + "tiles.txt"); + tw.Write("0x03, 0x05, 0x14, 0x25, 0x18, 0x18, 0x20, 0x1b, 0x34, 0x48, 0x33, 0x3d, 0x47, 0x49, 0x4a, 0x35, 0x3d, 0x3e, 0x45, 0x47, 0x49, 0x4a,"); + tw.Close(); + } + if (!System.IO.File.Exists(saveDir + "motd.txt")) + { + CreateFile(saveDir + "motd.txt"); + TextWriter tw = new StreamWriter(saveDir + "motd.txt"); + tw.WriteLine("This server is running TShock. Type /help for a list of commands."); + tw.WriteLine("%255,000,000%Current map: %map%"); + tw.WriteLine("Current players: %players%"); + tw.Close(); + } + if (!System.IO.File.Exists(saveDir + "bans.txt")) { CreateFile(saveDir + "bans.txt"); } + if (!System.IO.File.Exists(saveDir + "cheaters.txt")) { CreateFile(saveDir + "cheaters.txt"); } + if (!System.IO.File.Exists(saveDir + "admins.txt")) { CreateFile(saveDir + "admins.txt"); } + if (!System.IO.File.Exists(saveDir + "grief.txt")) { CreateFile(saveDir + "grief.txt"); } + if (!System.IO.File.Exists(saveDir + "config.txt")) + { + CreateFile(saveDir + "config.txt"); + TextWriter tw = new StreamWriter(saveDir + "config.txt"); + tw.WriteLine("true,50,4,700,true,true,7777,false,false,false,false,false"); + tw.Close(); + } + KeepTilesUpToDate(); + TextReader tr = new StreamReader(saveDir + "config.txt"); + string config = tr.ReadToEnd(); + config = config.Replace("\n", ""); + config = config.Replace("\r", ""); + config = config.Replace(" ", ""); + tr.Close(); + string[] configuration = config.Split(','); + try + { + killGuide = Convert.ToBoolean(configuration[0]); + invasionMultiplier = Convert.ToInt32(configuration[1]); + defaultMaxSpawns = Convert.ToInt32(configuration[2]); + defaultSpawnRate = Convert.ToInt32(configuration[3]); + kickCheater = Convert.ToBoolean(configuration[4]); + banCheater = Convert.ToBoolean(configuration[5]); + serverPort = Convert.ToInt32(configuration[6]); + enableWhitelist = Convert.ToBoolean(configuration[7]); + infinateInvasion = Convert.ToBoolean(configuration[8]); + permaPvp = Convert.ToBoolean(configuration[9]); + kickTnt = Convert.ToBoolean(configuration[10]); + banTnt = Convert.ToBoolean(configuration[11]); + if (infinateInvasion) + { + //Main.startInv(); + } + } + catch (Exception e) + { + WriteError(e.Message); + } + + Netplay.serverPort = serverPort; + } + public static void Kick(int ply, string reason) { NetMessage.SendData(0x2, ply, -1, reason, 0x0, 0f, 0f, 0f); From dfa89f28f1e6a4212f83855126db7f671f5f238a Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 01:30:47 -0600 Subject: [PATCH 3/9] Fixed kick. --- TShockAPI/TShock.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index e33f8534..6be3eff6 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -73,7 +73,7 @@ namespace TShockAPI if (msg.Length > 5 && msg.Substring(0, 5) == "/kick") { string plStr = msg.Remove(0, 5).Trim(); - if (FindPlayer(plStr) == -1 || plStr == "") + if (!(FindPlayer(plStr) == -1 || plStr == "")) { Kick(FindPlayer(plStr), "You were kicked."); Broadcast(plStr + " was kicked by " + FindPlayer(ply)); @@ -101,7 +101,7 @@ namespace TShockAPI void OnPreInit() { - + SetupConfig(); } void OnPostInit() From 45c7e6e830544626379647740ded6333d670ccbe Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 01:49:44 -0600 Subject: [PATCH 4/9] General stuff. --- TShockAPI/TShock.cs | 52 +++++++++++++++++++++++++++++++++++++- TShockAPI/TShockAPI.csproj | 1 + 2 files changed, 52 insertions(+), 1 deletion(-) 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 @@ + From c61a4b6aca06e273abc93a0d7cd0c12ff366cd5d Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 01:58:22 -0600 Subject: [PATCH 5/9] Added a hook for TNT. --- TShockAPI/TShock.cs | 6 ++++++ ...gnTimeResolveAssemblyReferencesInput.cache | Bin 6155 -> 6278 bytes 2 files changed, 6 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 327d1ce4..608000fc 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -62,6 +62,12 @@ namespace TShockAPI GameHooks.OnLoadContent += new Action(OnLoadContent); ServerHooks.OnChat += new Action(OnChat); ServerHooks.OnJoin += new Action(OnJoin); + NetHooks.OnPreGetData += new NetHooks.GetDataD(OnPreGetData); + } + + void OnPreGetData(byte id, messageBuffer msg, int idx, int length, HandledEventArgs e) + { + throw new NotImplementedException(); } diff --git a/TShockAPI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/TShockAPI/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 303b254c1e9d2b9739a4b79cf23c65fa3ffd984b..2a9ad2b0dae8b46a41e12533b16402309b13a659 100644 GIT binary patch delta 304 zcmeA+Xfxb!kdup-fq{Wd97v>3R^$%eEXT#f$XE(wicj|E3gUAwN-W68OfJ?-$;n}p zo-E6q!YTt)n*>rj`7JN|0drpoJ6=Bo^+LpkmviY2-EfWBT Cd`b5J delta 313 zcmZoO>^9hNkduptfq{Wd97v>3X5_}s^CEI{^gtpClLh&*85Jkj@;RdGa<9 zIdgR&Q=-~AF)t-EC9x#cvA8%jHz}vmEi)&zxRy-=C@WO$k(pN#kXVx8R+OLXS(2Jt z%ceP*TU4G=YqGYeyM#7S4R3W&VmU~UUt(@*Et?KdC>ZEW&&iiXMObx#Jg|Ev+lg^8 LDsT1_vt Date: Mon, 30 May 2011 02:08:32 -0600 Subject: [PATCH 6/9] Added whitelist --- TShockAPI/TShock.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 608000fc..f5d08318 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -111,6 +111,10 @@ namespace TShockAPI { Kick(ply, "Your account has been disabled."); } + if (!OnWhitelist(ip)) + { + Kick(ply, "Not on whitelist."); + } } void OnLoadContent(Microsoft.Xna.Framework.Content.ContentManager obj) @@ -137,6 +141,16 @@ namespace TShockAPI * Useful stuff: * */ + public static bool OnWhitelist(string ip) + { + if (!enableWhitelist) { return true; } + if (!System.IO.File.Exists(saveDir + "whitelist.txt")) { CreateFile(saveDir + "whitelist.txt"); TextWriter tw = new StreamWriter(saveDir + "whitelist.txt"); tw.WriteLine("127.0.0.1"); tw.Close(); } + TextReader tr = new StreamReader(saveDir + "whitelist.txt"); + string whitelist = tr.ReadToEnd(); + ip = GetRealIP(ip); + if (whitelist.Contains(ip)) { return true; } else { return false; } + } + public static bool CheckGreif(String ip) { ip = GetRealIP(ip); From b852c1bd54a08d6d2ab28e7f4245418cc1991e96 Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 02:24:13 -0600 Subject: [PATCH 7/9] Added whitelist --- TShockAPI/TShock.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index f5d08318..189ff8c9 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -62,15 +62,8 @@ namespace TShockAPI GameHooks.OnLoadContent += new Action(OnLoadContent); ServerHooks.OnChat += new Action(OnChat); ServerHooks.OnJoin += new Action(OnJoin); - NetHooks.OnPreGetData += new NetHooks.GetDataD(OnPreGetData); } - void OnPreGetData(byte id, messageBuffer msg, int idx, int length, HandledEventArgs e) - { - throw new NotImplementedException(); - } - - /* * Hooks: * */ @@ -226,6 +219,7 @@ namespace TShockAPI if (!System.IO.File.Exists(saveDir + "cheaters.txt")) { CreateFile(saveDir + "cheaters.txt"); } if (!System.IO.File.Exists(saveDir + "admins.txt")) { CreateFile(saveDir + "admins.txt"); } if (!System.IO.File.Exists(saveDir + "grief.txt")) { CreateFile(saveDir + "grief.txt"); } + if (!System.IO.File.Exists(saveDir + "whitelist.txt")) { CreateFile(saveDir + "whitelist.txt"); } if (!System.IO.File.Exists(saveDir + "config.txt")) { CreateFile(saveDir + "config.txt"); From e577fa0fd0f27db8f46c8e6c01bed5b6ec871507 Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 02:33:28 -0600 Subject: [PATCH 8/9] Added MOTD --- TShockAPI/TShock.cs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 189ff8c9..64dc01db 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -62,12 +62,19 @@ namespace TShockAPI GameHooks.OnLoadContent += new Action(OnLoadContent); ServerHooks.OnChat += new Action(OnChat); ServerHooks.OnJoin += new Action(OnJoin); + NetHooks.OnGreetPlayer += new NetHooks.GreetPlayerD(OnGreetPlayer); } /* * Hooks: * */ + void OnGreetPlayer(int who, HandledEventArgs e) + { + e.Handled = true; + ShowMOTD(who); + } + void OnChat(int ply, string msg, HandledEventArgs handler) { if (IsAdmin(ply)) @@ -382,5 +389,41 @@ namespace TShockAPI { using (FileStream fs = File.Create(file)) { } } + + public static void ShowMOTD(int ply) + { + string foo = ""; + TextReader tr = new StreamReader(saveDir + "motd.txt"); + while ((foo = tr.ReadLine()) != null) + { + foo = foo.Replace("%map%", Main.worldName); + foo = foo.Replace("%players%", GetPlayers()); + if (foo.Substring(0, 1) == "%" && foo.Substring(12, 1) == "%") //Look for a beginning color code. + { + string possibleColor = foo.Substring(0, 13); + foo = foo.Remove(0, 13); + float[] pC = { 0, 0, 0 }; + possibleColor = possibleColor.Replace("%", ""); + string[] pCc = possibleColor.Split(','); + if (pCc.Length == 3) + { + try + { + pC[0] = Clamp(Convert.ToInt32(pCc[0]), 255, 0); + pC[1] = Clamp(Convert.ToInt32(pCc[1]), 255, 0); + pC[2] = Clamp(Convert.ToInt32(pCc[2]), 255, 0); + SendMessage(ply, foo, pC); + continue; + } + catch (Exception e) + { + _writeError(e.Message); + } + } + } + SendMessage(ply, foo); + } + tr.Close(); + } } } \ No newline at end of file From ef60c83b40be0a7948d3cb0381cc6e4526a9b2d6 Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 02:40:41 -0600 Subject: [PATCH 9/9] Updated more stuff with motd --- TShockAPI/TShock.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 64dc01db..768d6e7c 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -71,8 +71,18 @@ namespace TShockAPI void OnGreetPlayer(int who, HandledEventArgs e) { + int plr = who; //legacy support e.Handled = true; ShowMOTD(who); + if (Main.player[plr].statLifeMax > 400 || Main.player[plr].statManaMax > 200 || Main.player[plr].statLife > 400 || Main.player[plr].statMana > 200) + { + HandleCheater(plr); + } + if (permaPvp) + { + Main.player[who].hostile = true; + NetMessage.SendData(30, -1, -1, "", who); + } } void OnChat(int ply, string msg, HandledEventArgs handler) @@ -318,6 +328,20 @@ namespace TShockAPI return pl; } + public static void HandleCheater(int ply) + { + string cheater = ShankShock.FindPlayer(ply); + string ip = ShankShock.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)); + + _writecheater(ply); + if (!kickCheater) { return; } + Netplay.serverSock[ply].kill = true; + Netplay.serverSock[ply].Reset(); + NetMessage.syncPlayers(); + ShankShock.Broadcast(cheater + " was " + (banCheater ? "banned " : "kicked ") + "for cheating."); + + } + public static string FindPlayer(int ply) { for (int i = 0; i < Main.player.Length; i++)