diff --git a/Commands/Information/CmdInbox.cs b/Commands/Chat/CmdInbox.cs similarity index 97% rename from Commands/Information/CmdInbox.cs rename to Commands/Chat/CmdInbox.cs index 9435bd084..63606e7bf 100644 --- a/Commands/Information/CmdInbox.cs +++ b/Commands/Chat/CmdInbox.cs @@ -24,7 +24,7 @@ namespace MCGalaxy.Commands { public override string name { get { return "inbox"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Information; } } + public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public CmdInbox() { } diff --git a/Commands/Chat/CmdSend.cs b/Commands/Chat/CmdSend.cs new file mode 100644 index 000000000..dfa9da87b --- /dev/null +++ b/Commands/Chat/CmdSend.cs @@ -0,0 +1,67 @@ +/* + Copyright 2011 MCForge + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. +*/ +using System; +using System.Text.RegularExpressions; +using MCGalaxy.SQL; + +namespace MCGalaxy.Commands { + public sealed class CmdSend : Command { + public override string name { get { return "send"; } } + public override string shortcut { get { return ""; } } + public override string type { get { return CommandTypes.Chat; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } + public CmdSend() { } + + public override void Use(Player p, string message) { + string[] parts = message.SplitSpaces(2); + if (message == "" || parts.Length == 1) { Help(p); return; } + + Player who = PlayerInfo.Find(parts[0]); + string whoTo = who == null ? parts[0] : who.name; + string fromname = p == null ? "(console)" : p.name; + if (!Player.ValidName(whoTo)) { + Player.Message(p, "%cIllegal name!"); return; + } + + message = parts[1]; + //DB + if (message.Length >= 256 && Server.useMySQL) { + Player.Message(p, "Message was too long. It has been trimmed to:"); + Player.Message(p, message.Substring(0, 255)); + message = message.Remove(0, 255); + } + //safe against SQL injections because whoTo is checked for illegal characters + Database.executeQuery("CREATE TABLE if not exists `Inbox" + whoTo + "` (PlayerFrom CHAR(20), TimeSent DATETIME, Contents VARCHAR(255));"); + ParameterisedQuery query = ParameterisedQuery.Create(); + query.AddParam("@From", fromname); + query.AddParam("@Time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + query.AddParam("@Content", message); + Database.executeQuery(query, "INSERT INTO `Inbox" + whoTo + "` (PlayerFrom, TimeSent, Contents) VALUES (@From, @Time, @Content)"); + //DB + + Player.Message(p, "Message sent to &5" + whoTo + "."); + if (who != null) who.SendMessage("Message recieved from &5" + fromname + "%S."); + } + + public override void Help(Player p) { + Player.Message(p, "%T/send [name] "); + Player.Message(p, "%HSends to [name]."); + } + } +} diff --git a/Commands/other/CmdSend.cs b/Commands/other/CmdSend.cs deleted file mode 100644 index 75eeecc1f..000000000 --- a/Commands/other/CmdSend.cs +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ -using System; -using System.Text.RegularExpressions; -using MCGalaxy.SQL; -namespace MCGalaxy.Commands -{ - public sealed class CmdSend : Command - { - public override string name { get { return "send"; } } - public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Other; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } - public CmdSend() { } - - public override void Use(Player p, string message) - { - if (message == "" || message.IndexOf(' ') == -1) { Help(p); return; } - - Player who = PlayerInfo.Find(message.Split(' ')[0]); - - string whoTo, fromname; - if (who != null) whoTo = who.name; - else whoTo = message.Split(' ')[0]; - if (p != null) fromname = p.name; - else fromname = "Console"; - - if (!Player.ValidName(whoTo)) - { - Player.Message(p, "%cIllegal name!"); - return; - } - - message = message.Substring(message.IndexOf(' ') + 1); - - if (!Regex.IsMatch(message.ToLower(), @".*%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])%([0-9]|[a-f]|[k-r])")) - { - if (Regex.IsMatch(message.ToLower(), @".*%([0-9]|[a-f]|[k-r])(.+?).*")) - { - Regex rg = new Regex(@"%([0-9]|[a-f]|[k-r])(.+?)"); - MatchCollection mc = rg.Matches(message.ToLower()); - if (mc.Count > 0) - { - Match ma = mc[0]; - GroupCollection gc = ma.Groups; - message.Replace("%" + gc[1].ToString().Substring(1), "&" + gc[1].ToString().Substring(1)); - } - } - } - - //DB - if (message.Length > 255 && Server.useMySQL) { Player.Message(p, "Message was too long. The text below has been trimmed."); Player.Message(p, message.Substring(256)); message = message.Remove(256); } - //safe against SQL injections because whoTo is checked for illegal characters - Database.executeQuery("CREATE TABLE if not exists `Inbox" + whoTo + "` (PlayerFrom CHAR(20), TimeSent DATETIME, Contents VARCHAR(255));"); - if (!Server.useMySQL) - Server.s.Log(message.Replace("'", "\\'")); - - ParameterisedQuery query = ParameterisedQuery.Create(); - query.AddParam("@From", fromname); - query.AddParam("@Time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); - query.AddParam("@Content", message); - Database.executeQuery(query, "INSERT INTO `Inbox" + whoTo + "` (PlayerFrom, TimeSent, Contents) VALUES (@From, @Time, @Content)"); - //DB - - Player.Message(p, "Message sent to &5" + whoTo + "."); - if (who != null) who.SendMessage("Message recieved from &5" + fromname + "%S."); - } - - public override void Help(Player p) { - Player.Message(p, "%T/send [name] "); - Player.Message(p, "%HSends to [name]."); - } - } -} diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index a85e386fb..b30d90125 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -170,6 +170,7 @@ + @@ -179,6 +180,7 @@ + @@ -244,7 +246,6 @@ - @@ -344,7 +345,6 @@ -