Cleanup /send.

This commit is contained in:
UnknownShadow200 2016-06-23 17:43:15 +10:00
parent a439ab3144
commit b40dd94d06
4 changed files with 70 additions and 93 deletions

View File

@ -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() { }

67
Commands/Chat/CmdSend.cs Normal file
View File

@ -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] <message>");
Player.Message(p, "%HSends <message> to [name].");
}
}
}

View File

@ -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] <message>");
Player.Message(p, "%HSends <message> to [name].");
}
}
}

View File

@ -170,6 +170,7 @@
<Compile Include="Commands\Chat\CmdHigh5.cs" />
<Compile Include="Commands\Chat\CmdHug.cs" />
<Compile Include="Commands\Chat\CmdIgnore.cs" />
<Compile Include="Commands\Chat\CmdInbox.cs" />
<Compile Include="Commands\Chat\CmdLoginMessage.cs" />
<Compile Include="Commands\Chat\CmdLogoutMessage.cs" />
<Compile Include="Commands\Chat\CmdMe.cs" />
@ -179,6 +180,7 @@
<Compile Include="Commands\Chat\CmdRankMsg.cs" />
<Compile Include="Commands\Chat\CmdRoll.cs" />
<Compile Include="Commands\Chat\CmdSay.cs" />
<Compile Include="Commands\Chat\CmdSend.cs" />
<Compile Include="Commands\Chat\CmdTColor.cs" />
<Compile Include="Commands\Chat\CmdTitle.cs" />
<Compile Include="Commands\Chat\CmdWhisper.cs" />
@ -244,7 +246,6 @@
<Compile Include="Commands\Information\CmdFaq.cs" />
<Compile Include="Commands\Information\CmdHasirc.cs" />
<Compile Include="Commands\Information\CmdHelp.cs" />
<Compile Include="Commands\Information\CmdInbox.cs" />
<Compile Include="Commands\Information\CmdRankInfo.cs" />
<Compile Include="Commands\Information\CmdServerInfo.cs" />
<Compile Include="Commands\Information\CmdLastCmd.cs" />
@ -344,7 +345,6 @@
<Compile Include="Commands\other\CmdReport.cs" />
<Compile Include="Commands\other\CmdResetPass.cs" />
<Compile Include="Commands\other\CmdRide.cs" />
<Compile Include="Commands\other\CmdSend.cs" />
<Compile Include="Commands\other\CmdSendCmd.cs" />
<Compile Include="Commands\other\CmdServer.cs" />
<Compile Include="Commands\other\CmdSetPass.cs" />