mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Move motd event into GetMotd
This allows plugins to change MOTD for /fly,/ascend etc checks
This commit is contained in:
parent
05a3de6fbe
commit
0efe8e9d4b
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
if (p.Game.Referee) {
|
if (p.Game.Referee) {
|
||||||
p.Send(Packet.HackControl(true, true, true, true, true, -1));
|
p.Send(Packet.HackControl(true, true, true, true, true, -1));
|
||||||
} else {
|
} else {
|
||||||
p.Send(Hacks.MakeHackControl(p, p.level.GetMotd(p)));
|
p.Send(Hacks.MakeHackControl(p, p.GetMotd()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
public override bool SuperUseable { get { return false; } }
|
public override bool SuperUseable { get { return false; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (!Hacks.CanUseRespawn(p, p.level)) {
|
if (!Hacks.CanUseRespawn(p)) {
|
||||||
p.Message("You cannot use %T/Spawn %Son this map.");
|
p.Message("You cannot use %T/Spawn %Son this map.");
|
||||||
p.isFlying = false; return;
|
p.isFlying = false; return;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
|||||||
public override bool SuperUseable { get { return false; } }
|
public override bool SuperUseable { get { return false; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (!Hacks.CanUseHacks(p, p.level)) {
|
if (!Hacks.CanUseHacks(p)) {
|
||||||
p.Message("You cannot use %T/Ascend %Son this map."); return;
|
p.Message("You cannot use %T/Ascend %Son this map."); return;
|
||||||
}
|
}
|
||||||
int x = p.Pos.BlockX, y = p.Pos.BlockY, z = p.Pos.BlockZ;
|
int x = p.Pos.BlockX, y = p.Pos.BlockY, z = p.Pos.BlockZ;
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
|||||||
public override bool SuperUseable { get { return false; } }
|
public override bool SuperUseable { get { return false; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (!Hacks.CanUseHacks(p, p.level)) {
|
if (!Hacks.CanUseHacks(p)) {
|
||||||
p.Message("You cannot use %T/Descend %Son this map."); return;
|
p.Message("You cannot use %T/Descend %Son this map."); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Misc {
|
|||||||
public override bool SuperUseable { get { return false; } }
|
public override bool SuperUseable { get { return false; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (!Hacks.CanUseFly(p, p.level)) {
|
if (!Hacks.CanUseFly(p)) {
|
||||||
p.Message("You cannot use %T/Fly %Son this map.");
|
p.Message("You cannot use %T/Fly %Son this map.");
|
||||||
p.isFlying = false; return;
|
p.isFlying = false; return;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace MCGalaxy.Core {
|
|||||||
if (p.Supports(CpeExt.InstantMOTD)) p.SendMapMotd();
|
if (p.Supports(CpeExt.InstantMOTD)) p.SendMapMotd();
|
||||||
p.SendCurrentEnv();
|
p.SendCurrentEnv();
|
||||||
|
|
||||||
if (p.isFlying && !Hacks.CanUseFly(p, p.level)) {
|
if (p.isFlying && !Hacks.CanUseFly(p)) {
|
||||||
p.Message("You cannot use %T/Fly %Son this map.");
|
p.Message("You cannot use %T/Fly %Son this map.");
|
||||||
p.isFlying = false;
|
p.isFlying = false;
|
||||||
}
|
}
|
||||||
|
@ -209,12 +209,13 @@ namespace MCGalaxy.Events.PlayerEvents {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public delegate void OnSendingMotd(Player p, ref string motd);
|
public delegate void OnGettingMotd(Player p, ref string motd);
|
||||||
/// <summary> Called when MOTD is being sent to a player. </summary>
|
/// <summary> Called when MOTD is being retrieved for a player. </summary>
|
||||||
public sealed class OnSendingMotdEvent : IEvent<OnSendingMotd> {
|
/// <remarks> e.g. You can use this event to make one player always have +hax motd. </remarks>
|
||||||
|
public sealed class OnGettingMotdEvent : IEvent<OnGettingMotd> {
|
||||||
|
|
||||||
public static void Call(Player p, ref string motd) {
|
public static void Call(Player p, ref string motd) {
|
||||||
IEvent<OnSendingMotd>[] items = handlers.Items;
|
IEvent<OnGettingMotd>[] items = handlers.Items;
|
||||||
// Can't use CallCommon because we need to pass arguments by ref
|
// Can't use CallCommon because we need to pass arguments by ref
|
||||||
for (int i = 0; i < items.Length; i++) {
|
for (int i = 0; i < items.Length; i++) {
|
||||||
try { items[i].method(p, ref motd); }
|
try { items[i].method(p, ref motd); }
|
||||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Games {
|
|||||||
static TimeSpan interval = TimeSpan.FromSeconds(5);
|
static TimeSpan interval = TimeSpan.FromSeconds(5);
|
||||||
|
|
||||||
public static bool DetectNoclip(Player p, Position newPos) {
|
public static bool DetectNoclip(Player p, Position newPos) {
|
||||||
if (p.Game.Referee || Hacks.CanUseNoclip(p, p.level)) return false;
|
if (p.Game.Referee || Hacks.CanUseNoclip(p)) return false;
|
||||||
if (!p.IsLikelyInsideBlock() || p.Game.NoclipLog.AddSpamEntry(5, interval)) return false;
|
if (!p.IsLikelyInsideBlock() || p.Game.NoclipLog.AddSpamEntry(5, interval)) return false;
|
||||||
|
|
||||||
Warn(ref p.Game.LastNoclipWarn, p, "noclip");
|
Warn(ref p.Game.LastNoclipWarn, p, "noclip");
|
||||||
@ -37,7 +37,7 @@ namespace MCGalaxy.Games {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool DetectSpeedhack(Player p, Position newPos, float moveDist) {
|
public static bool DetectSpeedhack(Player p, Position newPos, float moveDist) {
|
||||||
if (p.Game.Referee || Hacks.CanUseSpeed(p, p.level)) return false;
|
if (p.Game.Referee || Hacks.CanUseSpeed(p)) return false;
|
||||||
int dx = Math.Abs(p.Pos.X - newPos.X), dz = Math.Abs(p.Pos.Z - newPos.Z);
|
int dx = Math.Abs(p.Pos.X - newPos.X), dz = Math.Abs(p.Pos.Z - newPos.Z);
|
||||||
|
|
||||||
int maxMove = (int)(moveDist * 32);
|
int maxMove = (int)(moveDist * 32);
|
||||||
|
@ -24,29 +24,29 @@ namespace MCGalaxy {
|
|||||||
public static class Hacks {
|
public static class Hacks {
|
||||||
|
|
||||||
/// <summary> Returns whether the player is currently able to use any hacks at all. </summary>
|
/// <summary> Returns whether the player is currently able to use any hacks at all. </summary>
|
||||||
public static bool CanUseHacks(Player p, Level lvl) {
|
public static bool CanUseHacks(Player p) {
|
||||||
byte[] packet = MakeHackControl(p, lvl.GetMotd(p));
|
byte[] packet = MakeHackControl(p, p.GetMotd());
|
||||||
return packet[1] != 0 && packet[2] != 0 && packet[3] != 0 && packet[4] != 0 && packet[5] != 0;
|
return packet[1] != 0 && packet[2] != 0 && packet[3] != 0 && packet[4] != 0 && packet[5] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns whether the player is currently able to fly. </summary>
|
/// <summary> Returns whether the player is currently able to fly. </summary>
|
||||||
public static bool CanUseFly(Player p, Level lvl) {
|
public static bool CanUseFly(Player p) {
|
||||||
return MakeHackControl(p, lvl.GetMotd(p))[1] != 0;
|
return MakeHackControl(p, p.GetMotd())[1] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns whether the player is currently able to use noclip. </summary>
|
/// <summary> Returns whether the player is currently able to use noclip. </summary>
|
||||||
public static bool CanUseNoclip(Player p, Level lvl) {
|
public static bool CanUseNoclip(Player p) {
|
||||||
return MakeHackControl(p, lvl.GetMotd(p))[2] != 0;
|
return MakeHackControl(p, p.GetMotd())[2] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns whether the player is currently able to move at faster speeds. </summary>
|
/// <summary> Returns whether the player is currently able to move at faster speeds. </summary>
|
||||||
public static bool CanUseSpeed(Player p, Level lvl) {
|
public static bool CanUseSpeed(Player p) {
|
||||||
return MakeHackControl(p, lvl.GetMotd(p))[3] != 0;
|
return MakeHackControl(p, p.GetMotd())[3] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns whether the player is currently able to respawn. </summary>
|
/// <summary> Returns whether the player is currently able to respawn. </summary>
|
||||||
public static bool CanUseRespawn(Player p, Level lvl) {
|
public static bool CanUseRespawn(Player p) {
|
||||||
return MakeHackControl(p, lvl.GetMotd(p))[4] != 0;
|
return MakeHackControl(p, p.GetMotd())[4] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Parses the MOTD flags and returns resulting HackControl packet. </summary>
|
/// <summary> Parses the MOTD flags and returns resulting HackControl packet. </summary>
|
||||||
|
@ -24,6 +24,7 @@ using MCGalaxy.Bots;
|
|||||||
using MCGalaxy.Commands;
|
using MCGalaxy.Commands;
|
||||||
using MCGalaxy.DB;
|
using MCGalaxy.DB;
|
||||||
using MCGalaxy.Events.LevelEvents;
|
using MCGalaxy.Events.LevelEvents;
|
||||||
|
using MCGalaxy.Events.PlayerEvents;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
using MCGalaxy.Generator;
|
using MCGalaxy.Generator;
|
||||||
using MCGalaxy.Levels.IO;
|
using MCGalaxy.Levels.IO;
|
||||||
@ -96,15 +97,6 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetMotd(Player p) {
|
|
||||||
Zone zone = p.ZoneIn;
|
|
||||||
string zoneMOTD = zone == null ? null : zone.Config.MOTD;
|
|
||||||
if (zoneMOTD != null && zoneMOTD != "ignore") return zoneMOTD;
|
|
||||||
|
|
||||||
if (Config.MOTD != "ignore") return Config.MOTD;
|
|
||||||
return String.IsNullOrEmpty(p.group.MOTD) ? Server.Config.MOTD : p.group.MOTD;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Zone FindZoneExact(string name) {
|
public Zone FindZoneExact(string name) {
|
||||||
Zone[] zones = Zones.Items;
|
Zone[] zones = Zones.Items;
|
||||||
foreach (Zone zone in zones) {
|
foreach (Zone zone in zones) {
|
||||||
@ -152,7 +144,7 @@ namespace MCGalaxy {
|
|||||||
BotsFile.Save(this);
|
BotsFile.Save(this);
|
||||||
PlayerBot.RemoveLoadedBots(this, false);
|
PlayerBot.RemoveLoadedBots(this, false);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.LogError("Error saving bots", ex);
|
Logger.LogError("Error saving bots", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +226,7 @@ namespace MCGalaxy {
|
|||||||
File.Copy(path + ".backup", path);
|
File.Copy(path + ".backup", path);
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
|
|
||||||
Logger.Log(LogType.SystemActivity, "SAVED: Level \"{0}\". ({1}/{2}/{3})",
|
Logger.Log(LogType.SystemActivity, "SAVED: Level \"{0}\". ({1}/{2}/{3})",
|
||||||
name, players.Count, PlayerInfo.Online.Count, Server.Config.MaxPlayers);
|
name, players.Count, PlayerInfo.Online.Count, Server.Config.MaxPlayers);
|
||||||
Changed = false;
|
Changed = false;
|
||||||
}
|
}
|
||||||
@ -246,7 +238,7 @@ namespace MCGalaxy {
|
|||||||
public string Backup(bool force = false, string backup = "") {
|
public string Backup(bool force = false, string backup = "") {
|
||||||
if (!backedup || force) {
|
if (!backedup || force) {
|
||||||
string backupPath = LevelInfo.BackupBasePath(name);
|
string backupPath = LevelInfo.BackupBasePath(name);
|
||||||
if (!Directory.Exists(backupPath)) Directory.CreateDirectory(backupPath);
|
if (!Directory.Exists(backupPath)) Directory.CreateDirectory(backupPath);
|
||||||
int next = LevelInfo.LatestBackup(name) + 1;
|
int next = LevelInfo.LatestBackup(name) + 1;
|
||||||
if (backup.Length == 0) backup = next.ToString();
|
if (backup.Length == 0) backup = next.ToString();
|
||||||
|
|
||||||
@ -299,7 +291,7 @@ namespace MCGalaxy {
|
|||||||
lvl.Config.JailZ = (ushort)(lvl.spawnz * 32);
|
lvl.Config.JailZ = (ushort)(lvl.spawnz * 32);
|
||||||
lvl.Config.jailrotx = lvl.rotx;
|
lvl.Config.jailrotx = lvl.rotx;
|
||||||
lvl.Config.jailroty = lvl.roty;
|
lvl.Config.jailroty = lvl.roty;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
string propsPath = LevelInfo.PropsPath(lvl.MapName);
|
string propsPath = LevelInfo.PropsPath(lvl.MapName);
|
||||||
bool propsExisted = lvl.Config.Load(propsPath);
|
bool propsExisted = lvl.Config.Load(propsPath);
|
||||||
@ -364,18 +356,18 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct UndoPos {
|
public struct UndoPos {
|
||||||
public int Index;
|
public int Index;
|
||||||
int flags;
|
int flags;
|
||||||
BlockRaw oldRaw, newRaw;
|
BlockRaw oldRaw, newRaw;
|
||||||
|
|
||||||
public BlockID OldBlock {
|
public BlockID OldBlock {
|
||||||
get { return (BlockID)(oldRaw | ((flags & 0x03) << Block.ExtendedShift)); }
|
get { return (BlockID)(oldRaw | ((flags & 0x03) << Block.ExtendedShift)); }
|
||||||
}
|
}
|
||||||
public BlockID NewBlock {
|
public BlockID NewBlock {
|
||||||
get { return (BlockID)(newRaw | (((flags & 0xC >> 2)) << Block.ExtendedShift)); }
|
get { return (BlockID)(newRaw | (((flags & 0xC >> 2)) << Block.ExtendedShift)); }
|
||||||
}
|
}
|
||||||
public DateTime Time {
|
public DateTime Time {
|
||||||
get { return Server.StartTime.AddTicks((flags >> 4) * TimeSpan.TicksPerSecond); }
|
get { return Server.StartTime.AddTicks((flags >> 4) * TimeSpan.TicksPerSecond); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetData(BlockID oldBlock, BlockID newBlock) {
|
public void SetData(BlockID oldBlock, BlockID newBlock) {
|
||||||
@ -396,13 +388,13 @@ namespace MCGalaxy {
|
|||||||
public void UpdateBlockProps() {
|
public void UpdateBlockProps() {
|
||||||
LoadDefaultProps();
|
LoadDefaultProps();
|
||||||
string propsPath = BlockProps.PropsPath("_" + MapName);
|
string propsPath = BlockProps.PropsPath("_" + MapName);
|
||||||
|
|
||||||
// backwards compatibility with older versions
|
// backwards compatibility with older versions
|
||||||
if (!File.Exists(propsPath)) {
|
if (!File.Exists(propsPath)) {
|
||||||
BlockProps.Load("lvl_" + MapName, Props, 2, true);
|
BlockProps.Load("lvl_" + MapName, Props, 2, true);
|
||||||
} else {
|
} else {
|
||||||
BlockProps.Load("_" + MapName, Props, 2, false);
|
BlockProps.Load("_" + MapName, Props, 2, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateBlockHandlers() {
|
public void UpdateBlockHandlers() {
|
||||||
@ -412,7 +404,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateBlockHandler(BlockID block) {
|
public void UpdateBlockHandler(BlockID block) {
|
||||||
bool nonSolid = !MCGalaxy.Blocks.CollideType.IsSolid(CollideType(block));
|
bool nonSolid = !MCGalaxy.Blocks.CollideType.IsSolid(CollideType(block));
|
||||||
deleteHandlers[block] = BlockBehaviour.GetDeleteHandler(block, Props);
|
deleteHandlers[block] = BlockBehaviour.GetDeleteHandler(block, Props);
|
||||||
placeHandlers[block] = BlockBehaviour.GetPlaceHandler(block, Props);
|
placeHandlers[block] = BlockBehaviour.GetPlaceHandler(block, Props);
|
||||||
walkthroughHandlers[block] = BlockBehaviour.GetWalkthroughHandler(block, Props, nonSolid);
|
walkthroughHandlers[block] = BlockBehaviour.GetWalkthroughHandler(block, Props, nonSolid);
|
||||||
|
@ -150,10 +150,9 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SendMapMotd() {
|
public void SendMapMotd() {
|
||||||
string motd = level.GetMotd(this);
|
string motd = GetMotd();
|
||||||
motd = Chat.Format(motd, this);
|
motd = Chat.Format(motd, this);
|
||||||
|
|
||||||
OnSendingMotdEvent.Call(this, ref motd);
|
|
||||||
byte[] packet = Packet.Motd(this, motd);
|
byte[] packet = Packet.Motd(this, motd);
|
||||||
Send(packet);
|
Send(packet);
|
||||||
|
|
||||||
|
@ -106,6 +106,18 @@ namespace MCGalaxy {
|
|||||||
return BlockBindings[RawHeldBlock];
|
return BlockBindings[RawHeldBlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetMotd() {
|
||||||
|
Zone zone = ZoneIn;
|
||||||
|
string motd = zone == null ? "ignore" : zone.Config.MOTD;
|
||||||
|
|
||||||
|
// fallback to level MOTD, then rank MOTD, then server MOTD
|
||||||
|
if (motd == "ignore") motd = level.Config.MOTD;
|
||||||
|
if (motd == "ignore") motd = String.IsNullOrEmpty(group.MOTD) ? Server.Config.MOTD : group.MOTD;
|
||||||
|
|
||||||
|
OnGettingMotdEvent.Call(this, ref motd);
|
||||||
|
return motd;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetPrefix() {
|
public void SetPrefix() {
|
||||||
prefix = Game.Referee ? "&2[Ref] " : "";
|
prefix = Game.Referee ? "&2[Ref] " : "";
|
||||||
if (GroupPrefix.Length > 0) { prefix += GroupPrefix + color; }
|
if (GroupPrefix.Length > 0) { prefix += GroupPrefix + color; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user