diff --git a/Commands/CPE/CmdEnvironment.cs b/Commands/CPE/CmdEnvironment.cs index 13b9b3a34..0c5a776c6 100644 --- a/Commands/CPE/CmdEnvironment.cs +++ b/Commands/CPE/CmdEnvironment.cs @@ -188,14 +188,13 @@ namespace MCGalaxy.Commands { static void SendPresetsMessage(Player p) { Player.Message(p, "/env preset [type] -- Uses an env preset on your current map"); - Player.Message(p, "Valid types: Cartoon/Midnight/Midnight2/Noir/Normal/Trippy/Watery/Sunset/Gloomy/Cloudy"); - + Player.Message(p, "Valid types: Cartoon/Midnight/Midnight2/Noir/Normal/Trippy/Watery/Sunset/Gloomy/Cloudy"); if (!Directory.Exists("presets")) return; - string custom = ""; - foreach (string s in Directory.GetFiles("presets/", "*.env")) - custom += ", " + Path.GetFileNameWithoutExtension(s); - if (custom != "") - Player.Message(p, "Custom preset types: " + custom.Remove(0, 2)); + + string[] files = Directory.GetFiles("preset", "*.env"); + string all = files.Join(f => Path.GetFileNameWithoutExtension(f)); + if (all != "") + Player.Message(p, "Custom preset types: " + all); } public override void Help(Player p) { diff --git a/Commands/Chat/CmdChatRoom.cs b/Commands/Chat/CmdChatRoom.cs index 9662f9e5c..4e4bed3e2 100644 --- a/Commands/Chat/CmdChatRoom.cs +++ b/Commands/Chat/CmdChatRoom.cs @@ -159,8 +159,8 @@ namespace MCGalaxy.Commands { if (pl.spyChatRooms.Contains(room)) { pl.spyChatRooms.Remove(room); - pl.SendMessage("Stopped spying on chatroom '" + room + - "' because it was deleted by: " + p.color + p.name); + Player.Message(pl, "Stopped spying on chatroom '{0}' because it was deleted by: {1}", + room, p.ColoredName); } } Chat.MessageAll("The chatroom '{0}' has been deleted", room); diff --git a/Commands/Fun/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs index d49f59880..d6e42ce19 100644 --- a/Commands/Fun/CmdTntWars.cs +++ b/Commands/Fun/CmdTntWars.cs @@ -1054,13 +1054,10 @@ namespace MCGalaxy.Commands { Player.Message(pl.p, "TNT Wars: Changed gamemode to Team Deathmatch"); AssignAutoTeam(pl, it, it.RedTeam(), it.BlueTeam()); - string msg = pl.p.color + pl.p.name + Server.DefaultColor + " is now"; - if (pl.Red) - msg += " on the " + Colors.red + "red team"; - if (pl.Blue) - msg += " on the " + Colors.blue + "blue team"; - if (pl.spec) - msg += Server.DefaultColor + " (as a spectator)"; + string msg = pl.p.ColoredName + " %Sis now"; + if (pl.Red) msg += " on the " + Colors.red + "red team"; + if (pl.Blue) msg += " on the " + Colors.blue + "blue team"; + if (pl.spec) msg += " (as a spectator)"; Chat.MessageAll(msg); } diff --git a/Commands/Information/CmdView.cs b/Commands/Information/CmdView.cs index b03e4400f..c02b19466 100644 --- a/Commands/Information/CmdView.cs +++ b/Commands/Information/CmdView.cs @@ -32,15 +32,13 @@ namespace MCGalaxy.Commands { Directory.CreateDirectory("extra/text"); if (message == "") { string[] files = Directory.GetFiles("extra/text", "*.txt"); - string allFiles = ""; - foreach (string file in files) - allFiles += ", " + Path.GetFileNameWithoutExtension(file); + string all = files.Join(f => Path.GetFileNameWithoutExtension(f)); - if (allFiles == "") { + if (all == "") { Player.Message(p, "No files are viewable by you"); } else { Player.Message(p, "Available files:"); - Player.Message(p, allFiles.Remove(0, 2)); + Player.Message(p, all); } } else { Player who = p; diff --git a/Commands/other/CmdAscend.cs b/Commands/other/CmdAscend.cs index 9eff82326..b911a369f 100644 --- a/Commands/other/CmdAscend.cs +++ b/Commands/other/CmdAscend.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } - if (!p.level.CanUseHacks(p)) { + if (!Hacks.CanUseHacks(p, p.level)) { Player.Message(p, "You cannot use /ascend on this map."); return; } ushort x = (ushort)(p.pos[0] / 32), y = (ushort)(p.pos[1] / 32), z = (ushort)(p.pos[2] / 32); diff --git a/Commands/other/CmdDescend.cs b/Commands/other/CmdDescend.cs index 0ba64366f..408bb6882 100644 --- a/Commands/other/CmdDescend.cs +++ b/Commands/other/CmdDescend.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } - if (!p.level.CanUseHacks(p)) { + if (!Hacks.CanUseHacks(p, p.level)) { Player.Message(p, "You cannot use /descend on this map."); return; } if (p.pos[1] < 51 + 4) { Player.Message(p, "No free spaces found below you."); return; } diff --git a/Commands/other/CmdFly.cs b/Commands/other/CmdFly.cs index f6498239a..31e6f8fea 100644 --- a/Commands/other/CmdFly.cs +++ b/Commands/other/CmdFly.cs @@ -29,7 +29,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } - if (!p.level.CanUseHacks(p)) { + if (!Hacks.CanUseHacks(p, p.level)) { Player.Message(p, "You cannot use /fly on this map."); p.isFlying = false; return; } diff --git a/Levels/Hacks.cs b/Levels/Hacks.cs new file mode 100644 index 000000000..84ce434bb --- /dev/null +++ b/Levels/Hacks.cs @@ -0,0 +1,73 @@ +/* + Copyright 2015 MCGalaxy + + 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; + +namespace MCGalaxy { + + public static class Hacks { + + public static bool CanUseHacks(Player p, Level lvl) { + string motd = lvl.GetMotd(p); + bool noHacks = motd.Contains("-hax") || lvl.ctfmode || lvl.CurrentGame() != null; + if (noHacks && p.Rank >= LevelPermission.Operator && motd.Contains("+ophax")) + return true; + return !noHacks; + } + + public static byte[] MakeHackControl(Player p, Level lvl) { + string motd = lvl.GetMotd(p); + bool isOp = p.Rank >= LevelPermission.Operator; + + bool fly = true, noclip = true, speed = true, respawn = true, _3rdPerson = true; + short maxJump = -1; + string[] parts = motd.Split(' '); + for (int i = 0; i < parts.Length; i++) { + string part = parts[i]; + // +/- + if (part.CaselessEq("-hax")) { + fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; + } if (part.CaselessEq("-hax")) { + fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; + } else if (part.CaselessEq("-ophax") && isOp) { + fly = false; noclip = false; speed = false; respawn = false; _3rdPerson = false; + } else if (part.CaselessEq("+ophax") && isOp) { + fly = true; noclip = true; speed = true; respawn = true; _3rdPerson = true; + } + + // +specific hack flags + if (part.CaselessEq("+noclip")) { noclip = true; } + else if (part.CaselessEq("+fly")) { fly = false; } + else if (part.CaselessEq("+speed")) { speed = true; } + else if (part.CaselessEq("+respawn")) { respawn = true; } + + // -specific hack flags + if (part.CaselessEq("-noclip")) { noclip = false; } + else if (part.CaselessEq("-fly")) { fly = false; } + else if (part.CaselessEq("-speed")) { speed = false; } + else if (part.CaselessEq("-respawn")) { respawn = false; } + + if (!part.CaselessStarts("jumpheight=")) continue; + string heightPart = part.Substring(part.IndexOf('=') + 1); + float value; + if (float.TryParse(heightPart, out value)) + maxJump = (short)(value * 32); + } + return Packet.MakeHackControl(fly, noclip, speed, respawn, _3rdPerson, maxJump); + } + } +} \ No newline at end of file diff --git a/Levels/Level.cs b/Levels/Level.cs index d7c968c55..6a82c19b4 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -108,13 +108,9 @@ namespace MCGalaxy { } } - public bool CanUseHacks(Player p) { - bool serverMotd = p.level == Server.mainLevel || motd == "ignore"; - string realMotd = serverMotd ? Server.motd : motd; - bool noHacks = realMotd.Contains("-hax") || ctfmode || CurrentGame() != null; - if (noHacks && p.Rank >= LevelPermission.Operator && realMotd.Contains("+ophax")) - return true; - return !noHacks; + public string GetMotd(Player p) { + if (motd != "ignore") return motd; + return String.IsNullOrEmpty(p.group.MOTD) ? Server.motd : p.group.MOTD; } /// Whether block changes made on this level should be diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index d6e9a2f07..2ee79ff9f 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -487,6 +487,7 @@ + diff --git a/Network/Packet.CPE.cs b/Network/Packet.CPE.cs index 428c7e61d..042e8500f 100644 --- a/Network/Packet.CPE.cs +++ b/Network/Packet.CPE.cs @@ -83,7 +83,7 @@ namespace MCGalaxy { return buffer; } - public static byte[] SendHackControl(bool canFly, bool canNoclip, + public static byte[] MakeHackControl(bool canFly, bool canNoclip, bool canSpeed, bool canRespawn, bool can3rdPerson, short maxJumpHeight) { byte[] buffer = new byte[8]; diff --git a/Network/Packet.cs b/Network/Packet.cs index 43fe431da..f9e0e9afe 100644 --- a/Network/Packet.cs +++ b/Network/Packet.cs @@ -21,23 +21,19 @@ namespace MCGalaxy { public static partial class Packet { - public static byte[] MakeMotd(Player p, bool ignoreLevelMotd) { + public static byte[] MakeMotd(Player p) { byte[] buffer = new byte[131]; buffer[0] = Opcode.Handshake; buffer[1] = Server.version; - bool cp437 = p.HasCpeExt(CpeExt.FullCP437); - Level lvl = p.level; - if (ignoreLevelMotd || lvl.motd == "ignore") { - NetUtils.Write(Server.name, buffer, 2, cp437); - string line2 = String.IsNullOrEmpty(p.group.MOTD) ? Server.motd : p.group.MOTD; - NetUtils.Write(line2, buffer, 66, cp437); - } else if (lvl.motd.Length > 64) { - NetUtils.Write(lvl.motd, buffer, 2, cp437); - NetUtils.Write(lvl.motd.Substring(64), buffer, 66, cp437); + bool cp437 = p.HasCpeExt(CpeExt.FullCP437); + string motd = p.level.GetMotd(p); + if (motd.Length > 64) { + NetUtils.Write(motd, buffer, 2, cp437); + NetUtils.Write(motd.Substring(64), buffer, 66, cp437); } else { NetUtils.Write(Server.name, buffer, 2, cp437); - NetUtils.Write(lvl.motd, buffer, 66, cp437); + NetUtils.Write(motd, buffer, 66, cp437); } buffer[130] = Block.canPlace(p, Block.blackrock) ? (byte)100 : (byte)0; diff --git a/Network/Player.Networking.cs b/Network/Player.Networking.cs index 2259b5209..7659ee9c8 100644 --- a/Network/Player.Networking.cs +++ b/Network/Player.Networking.cs @@ -296,14 +296,16 @@ namespace MCGalaxy { } } - public void SendMotd() { SendMapMotd(true); } + public void SendMotd() { SendMapMotd(); } + public void SendUserMOTD() { SendMapMotd(); } - public void SendUserMOTD() { SendMapMotd(false); } - - void SendMapMotd(bool ignoreLevelMotd) { - byte[] packet = Packet.MakeMotd(this, ignoreLevelMotd); + void SendMapMotd() { + byte[] packet = Packet.MakeMotd(this); if (OnSendMOTD != null) OnSendMOTD(this, packet); Send(packet); + + if (HasCpeExt(CpeExt.HackControl)) + Send(Hacks.MakeHackControl(this, level)); } public void SendMap(Level oldLevel) { SendRawMap(oldLevel, level); } diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 3a44bbd2e..dc5fbdea1 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -482,7 +482,7 @@ try { SendBlockchange(pos1.x, pos1.y, pos1.z, Block.waterstill); } catch { } // handles the /womid client message, which displays the WoM vrersion if ( text.Truncate(6) == "/womid" ) { string version = (text.Length <= 21 ? text.Substring(text.IndexOf(' ') + 1) : text.Substring(7, 15)); - Server.s.Log(Colors.red + "[INFO] " + color + DisplayName + "%f is using wom client"); + Server.s.Log(Colors.red + "[INFO] " + ColoredName + "%f is using wom client"); Server.s.Log(Colors.red + "[INFO] %fVersion: " + version); UsingWom = true; return; diff --git a/sharkbite.thresher/Identd.cs b/sharkbite.thresher/Identd.cs index 83d2d9d46..907e32079 100644 --- a/sharkbite.thresher/Identd.cs +++ b/sharkbite.thresher/Identd.cs @@ -112,7 +112,7 @@ namespace Sharkbite.Irc listener = new TcpListener( IdentdPort ); listener.Start(); - loop: + while (true) { try { @@ -134,7 +134,6 @@ namespace Sharkbite.Irc { Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceWarning,"[" + Thread.CurrentThread.Name +"] Identd::Run() exception=" + ioe); } - goto loop; } } catch( Exception )