mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Implement HackControl CPE extension. You can now also change jumpheight by using jumpheight=xyz in the map's motd.
This commit is contained in:
parent
4ec09f27e2
commit
c578d53996
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
}
|
||||
|
73
Levels/Hacks.cs
Normal file
73
Levels/Hacks.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary> Whether block changes made on this level should be
|
||||
|
@ -487,6 +487,7 @@
|
||||
<Compile Include="Generator\RealisticGenParams.cs" />
|
||||
<Compile Include="Generator\RealisticMapGen.cs" />
|
||||
<Compile Include="Generator\SimpleGen.cs" />
|
||||
<Compile Include="Levels\Hacks.cs" />
|
||||
<Compile Include="Levels\IO\CwFile.cs" />
|
||||
<Compile Include="Levels\IO\DatFile.cs" />
|
||||
<Compile Include="Levels\IO\FcmFile.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];
|
||||
|
@ -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;
|
||||
|
@ -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); }
|
||||
|
@ -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;
|
||||
|
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user