Cleanup /whitelist.

This commit is contained in:
UnknownShadow200 2016-06-08 17:47:28 +10:00
parent 62276be0e5
commit 608bf5c7e5
2 changed files with 58 additions and 101 deletions

View File

@ -1,100 +1,70 @@
/* /*
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy) Copyright 2010 MCLawl Team - Written by Valek (Modified for use with MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands {
{ public sealed class CmdWhitelist : Command {
public sealed class CmdWhitelist : Command
{
public override string name { get { return "whitelist"; } } public override string name { get { return "whitelist"; } }
public override string shortcut { get { return "w"; } } public override string shortcut { get { return "w"; } }
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdWhitelist() { } public CmdWhitelist() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{
if (!Server.useWhitelist) { Player.Message(p, "Whitelist is not enabled."); return; } if (!Server.useWhitelist) { Player.Message(p, "Whitelist is not enabled."); return; }
if (message == "") { Help(p); return; } if (message == "") { Help(p); return; }
int pos = message.IndexOf(' '); int sep = message.IndexOf(' ');
if (pos != -1) string action = sep >= 0 ? message.Substring(0, sep) : message;
{ string player = sep >= 0 ? message.Substring(sep + 1) : "";
string action = message.Substring(0, pos);
string player = message.Substring(pos + 1);
switch (action) if (action.CaselessEq("list")) {
{ string output = "Whitelist: &f";
case "add": foreach (string name in Server.whiteList.All())
if (Server.whiteList.Contains(player)) output += name + ", ";
{ output = output.Substring(0, output.Length - 2);
Player.Message(p, "&f" + player + " %Sis already on the whitelist!"); Player.Message(p, output);
break; return;
}
Server.whiteList.Add(player);
Chat.GlobalMessageOps(p.ColoredName + " %Sadded &f" + player + " %Sto the whitelist.");
Server.whiteList.Save();
Server.s.Log("WHITELIST: Added " + player);
break;
case "del":
if (!Server.whiteList.Contains(player))
{
Player.Message(p, "&f" + player + " %Sis not on the whitelist!");
break;
}
Server.whiteList.Remove(player);
Chat.GlobalMessageOps(p.ColoredName + " %Sremoved &f" + player + " %Sfrom the whitelist.");
Server.whiteList.Save();
Server.s.Log("WHITELIST: Removed " + player);
break;
case "list":
string output = "Whitelist:&f";
foreach (string wlName in Server.whiteList.All())
{
output += " " + wlName + ",";
}
output = output.Substring(0, output.Length - 1);
Player.Message(p, output);
break;
default:
Help(p);
return;
}
} }
else if (player == "") { Help(p); return; }
{
if (message == "list") if (action.CaselessEq("add")) {
{ if (Server.whiteList.Contains(player)) {
string output = "Whitelist:&f"; Player.Message(p, "&f" + player + " %Sis already on the whitelist!"); return;
foreach (string wlName in Server.whiteList.All())
{
output += " " + wlName + ",";
}
output = output.Substring(0, output.Length - 1);
Player.Message(p, output);
} }
else
{ Server.whiteList.Add(player);
Help(p); Chat.GlobalMessageOps(p.ColoredName + " %Sadded &f" + player + " %Sto the whitelist.");
Server.whiteList.Save();
Server.s.Log("WHITELIST: Added " + player);
} else if (action.CaselessEq("del")) {
if (!Server.whiteList.Contains(player)) {
Player.Message(p, "&f" + player + " %Sis not on the whitelist!"); return;
} }
Server.whiteList.Remove(player);
Chat.GlobalMessageOps(p.ColoredName + " %Sremoved &f" + player + " %Sfrom the whitelist.");
Server.whiteList.Save();
Server.s.Log("WHITELIST: Removed " + player);
} else {
Help(p);
} }
} }
public override void Help(Player p) public override void Help(Player p) {
{
Player.Message(p, "/whitelist <add/del/list> [player] - Handles whitelist entry for [player], or lists all entries."); Player.Message(p, "/whitelist <add/del/list> [player] - Handles whitelist entry for [player], or lists all entries.");
} }
} }

View File

@ -43,34 +43,20 @@ namespace Sharkbite.Irc
internal const int MAX_COMMAND_SIZE = 512; internal const int MAX_COMMAND_SIZE = 512;
internal const char CtcpQuote = '\u0001'; internal const char CtcpQuote = '\u0001';
internal CommandBuilder(Connection connection ) internal CommandBuilder(Connection connection) {
{
this.connection = connection; this.connection = connection;
commandBuffer = new StringBuilder(MAX_COMMAND_SIZE); commandBuffer = new StringBuilder(MAX_COMMAND_SIZE);
} }
internal Connection Connection internal Connection Connection { get { return connection; } }
{ internal StringBuilder Buffer { get { return commandBuffer; } }
get
{
return connection;
}
}
internal StringBuilder Buffer
{
get
{
return commandBuffer;
}
}
/// <summary> /// <summary>
/// This methods actually sends the notice and privmsg commands. /// This methods actually sends the notice and privmsg commands.
/// It assumes that the message has already been broken up /// It assumes that the message has already been broken up
/// and has a valid target. /// and has a valid target.
/// </summary> /// </summary>
internal void SendMessage(string type, string target, string message) internal void SendMessage(string type, string target, string message) {
{
commandBuffer.Append(type); commandBuffer.Append(type);
commandBuffer.Append(SPACE); commandBuffer.Append(SPACE);
commandBuffer.Append(target); commandBuffer.Append(target);
@ -78,13 +64,14 @@ namespace Sharkbite.Irc
commandBuffer.Append(message); commandBuffer.Append(message);
connection.SendCommand( commandBuffer ); connection.SendCommand( commandBuffer );
} }
/// <summary> /// <summary>
/// Clear the contents of the string buffer. /// Clear the contents of the string buffer.
/// </summary> /// </summary>
internal void ClearBuffer() internal void ClearBuffer() {
{
commandBuffer.Remove(0, commandBuffer.Length ); commandBuffer.Remove(0, commandBuffer.Length );
} }
/// <summary> /// <summary>
/// Break up a large message into smaller peices that will fit within the IRC /// Break up a large message into smaller peices that will fit within the IRC
/// max message size. /// max message size.