mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-29 16:43:30 -04:00
Show join/leave joker messages on IRC, use case-insensitive comparisons to avoid allocating unnecessary memory.
This commit is contained in:
parent
e9b879d825
commit
082017c313
@ -1,69 +1,65 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2011 MCGalaxy
|
Copyright 2011 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 CmdJoker : Command
|
public sealed class CmdJoker : Command {
|
||||||
{
|
|
||||||
public override string name { get { return "joker"; } }
|
public override string name { get { return "joker"; } }
|
||||||
public override string shortcut { get { return ""; } }
|
public override string shortcut { get { return ""; } }
|
||||||
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 static string keywords { get { return ""; } }
|
public static string keywords { get { return ""; } }
|
||||||
public CmdJoker() { }
|
|
||||||
|
|
||||||
public override void Use(Player p, string message)
|
public override void Use(Player p, string message) {
|
||||||
{
|
|
||||||
if (message == "") { Help(p); return; }
|
if (message == "") { Help(p); return; }
|
||||||
bool stealth = false;
|
bool stealth = false;
|
||||||
if (message[0] == '#')
|
if (message[0] == '#') {
|
||||||
{
|
|
||||||
message = message.Remove(0, 1).Trim();
|
message = message.Remove(0, 1).Trim();
|
||||||
stealth = true;
|
stealth = true;
|
||||||
Server.s.Log("Stealth joker attempted");
|
Server.s.Log("Stealth joker attempted");
|
||||||
}
|
}
|
||||||
|
|
||||||
Player who = PlayerInfo.Find(message);
|
Player who = PlayerInfo.Find(message);
|
||||||
if (who == null)
|
if (who == null) { Player.SendMessage(p, "Could not find player."); return; }
|
||||||
{
|
|
||||||
Player.SendMessage(p, "Could not find player.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot joker someone of equal or greater rank."); return; }
|
if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot joker someone of equal or greater rank."); return; }
|
||||||
|
|
||||||
if (!who.joker)
|
if (!who.joker) {
|
||||||
{
|
if (stealth) {
|
||||||
who.joker = true;
|
Chat.GlobalMessageOps(who.color + who.DisplayName + " %Sis now STEALTH jokered.");
|
||||||
if (stealth) { Chat.GlobalMessageOps(who.color + who.DisplayName + Server.DefaultColor + " is now STEALTH joker'd. "); return; }
|
} else {
|
||||||
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " is now a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
|
Player.SendChatFrom(who, who.color + who.DisplayName + " %Sis now a &aJ&bo&ck&5e&9r%S.", false);
|
||||||
}
|
}
|
||||||
else
|
Server.IRC.Say(who.color + who.DisplayName + " %Sis now a &aJ&bo&ck&5e&9r%S.", stealth);
|
||||||
{
|
} else {
|
||||||
who.joker = false;
|
if (stealth) {
|
||||||
if (stealth) { Chat.GlobalMessageOps(who.color + who.DisplayName + Server.DefaultColor + " is now STEALTH Unjoker'd. "); return; }
|
Chat.GlobalMessageOps(who.color + who.DisplayName + " %Sis now STEALTH unjokered.");
|
||||||
Player.SendChatFrom(who, who.color + who.DisplayName + Server.DefaultColor + " is no longer a &aJ&bo&ck&5e&9r" + Server.DefaultColor + ".", false);
|
} else {
|
||||||
|
Player.SendChatFrom(who, who.color + who.DisplayName + " %Sis no longer a &aJ&bo&ck&5e&9r%S.", false);
|
||||||
|
}
|
||||||
|
Server.IRC.Say(who.color + who.DisplayName + " %Sis no longer a &aJ&bo&ck&5e&9r%S.", stealth);
|
||||||
}
|
}
|
||||||
|
who.joker = !who.joker;
|
||||||
}
|
}
|
||||||
public override void Help(Player p)
|
|
||||||
{
|
public override void Help(Player p) {
|
||||||
Player.SendMessage(p, "/joker <name> - Causes a player to become a joker!");
|
Player.SendMessage(p, "/joker <name> - Causes a player to become a joker!");
|
||||||
Player.SendMessage(p, "/joker # <name> - Makes the player a joker silently");
|
Player.SendMessage(p, "/joker # <name> - Makes the player a joker silently");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,24 +23,22 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static class LevelInfo {
|
public static class LevelInfo {
|
||||||
|
|
||||||
|
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||||
public static Level Find(string name) {
|
public static Level Find(string name) {
|
||||||
name = name.ToLower();
|
|
||||||
Level match = null; int matches = 0;
|
Level match = null; int matches = 0;
|
||||||
|
|
||||||
foreach (Level level in Server.levels) {
|
foreach (Level lvl in Server.levels) {
|
||||||
if (level.name.ToLower() == name) return level;
|
if (lvl.name.Equals(name, comp)) return lvl;
|
||||||
if (level.name.ToLower().Contains(name)) {
|
if (lvl.name.IndexOf(name, comp) >= 0) {
|
||||||
match = level; matches++;
|
match = lvl; matches++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matches == 1 ? match : null;
|
return matches == 1 ? match : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Level FindExact(string name) {
|
public static Level FindExact(string name) {
|
||||||
name = name.ToLower();
|
foreach (Level lvl in Server.levels) {
|
||||||
|
if (lvl.name.Equals(name, comp)) return lvl;
|
||||||
foreach (Level level in Server.levels) {
|
|
||||||
if (level.name.ToLower() == name) return level;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ namespace MCGalaxy {
|
|||||||
return GetGroup(name).color;
|
return GetGroup(name).color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||||
public static Player Find(string name) {
|
public static Player Find(string name) {
|
||||||
List<Player> tempList = new List<Player>();
|
List<Player> tempList = new List<Player>();
|
||||||
tempList.AddRange(players);
|
tempList.AddRange(players);
|
||||||
@ -41,8 +42,8 @@ namespace MCGalaxy {
|
|||||||
name = name.ToLower();
|
name = name.ToLower();
|
||||||
|
|
||||||
foreach (Player p in tempList) {
|
foreach (Player p in tempList) {
|
||||||
if (p.name.ToLower() == name) return p;
|
if (p.name.Equals(name, comp)) return p;
|
||||||
if (p.name.ToLower().Contains(name)) {
|
if (p.name.IndexOf(name, comp) >= 0) {
|
||||||
match = p; matches++;
|
match = p; matches++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,10 +53,9 @@ namespace MCGalaxy {
|
|||||||
public static Player FindExact(string name) {
|
public static Player FindExact(string name) {
|
||||||
List<Player> tempList = new List<Player>();
|
List<Player> tempList = new List<Player>();
|
||||||
tempList.AddRange(players);
|
tempList.AddRange(players);
|
||||||
name = name.ToLower();
|
|
||||||
|
|
||||||
foreach (Player p in tempList) {
|
foreach (Player p in tempList) {
|
||||||
if (p.name.ToLower() == name) return p;
|
if (p.name.Equals(name, comp)) return p;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,11 +64,10 @@ namespace MCGalaxy {
|
|||||||
List<Player> tempList = new List<Player>();
|
List<Player> tempList = new List<Player>();
|
||||||
tempList.AddRange(players);
|
tempList.AddRange(players);
|
||||||
Player match = null; int matches = 0;
|
Player match = null; int matches = 0;
|
||||||
nick = nick.ToLower();
|
|
||||||
|
|
||||||
foreach (Player p in tempList) {
|
foreach (Player p in tempList) {
|
||||||
if (p.DisplayName.ToLower() == nick) return p;
|
if (p.DisplayName.Equals(nick, comp)) return p;
|
||||||
if (p.DisplayName.ToLower().Contains(nick)) {
|
if (p.DisplayName.IndexOf(nick, comp) >= 0) {
|
||||||
match = p; matches++;
|
match = p; matches++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user