From e577fa0fd0f27db8f46c8e6c01bed5b6ec871507 Mon Sep 17 00:00:00 2001 From: Shank Date: Mon, 30 May 2011 02:33:28 -0600 Subject: [PATCH] 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