mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Fix crashing of ClassicalSharp 0.4
This commit is contained in:
parent
f30759285d
commit
7fde09b296
@ -185,7 +185,7 @@ namespace MCGalaxy {
|
||||
if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue;
|
||||
|
||||
pl.Send(def.MakeDefinePacket(pl));
|
||||
if (pl.HasCpeExt(CpeExt.BlockPermissions))
|
||||
if (pl.Supports(CpeExt.BlockPermissions))
|
||||
pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete));
|
||||
}
|
||||
Save(global, level);
|
||||
@ -220,7 +220,7 @@ namespace MCGalaxy {
|
||||
if (!global && pl.level != level) continue;
|
||||
if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw]) continue;
|
||||
|
||||
if (!pl.HasCpeExt(CpeExt.InventoryOrder)) continue;
|
||||
if (!pl.Supports(CpeExt.InventoryOrder)) continue;
|
||||
pl.Send(Packet.SetInventoryOrder(raw, order));
|
||||
}
|
||||
}
|
||||
@ -282,9 +282,9 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public byte[] MakeDefinePacket(Player pl) {
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) {
|
||||
if (pl.Supports(CpeExt.BlockDefinitionsExt, 2) && Shape != 0) {
|
||||
return Packet.DefineBlockExt(this, true, pl.hasCP437);
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && Shape != 0) {
|
||||
} else if (pl.Supports(CpeExt.BlockDefinitionsExt) && Shape != 0) {
|
||||
return Packet.DefineBlockExt(this, false, pl.hasCP437);
|
||||
} else {
|
||||
return Packet.DefineBlock(this, pl.hasCP437);
|
||||
|
@ -69,7 +69,7 @@ namespace MCGalaxy.Blocks {
|
||||
public static void ResendBlockPermissions(byte block) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (!pl.HasCpeExt(CpeExt.BlockPermissions)) continue;
|
||||
if (!pl.Supports(CpeExt.BlockPermissions)) continue;
|
||||
|
||||
int count = pl.hasCustomBlocks ? Block.CpeCount : Block.OriginalCount;
|
||||
if (block < count) {
|
||||
|
@ -92,7 +92,7 @@ namespace MCGalaxy {
|
||||
List[col.Code] = col;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (!p.HasCpeExt(CpeExt.TextColors)) continue;
|
||||
if (!p.Supports(CpeExt.TextColors)) continue;
|
||||
p.Send(Packet.SetTextColor(col));
|
||||
}
|
||||
SaveList();
|
||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.CPE {
|
||||
|
||||
if (packedDist > short.MaxValue) {
|
||||
Player.Message(p, "\"{0}\", is too long a reach distance. Max is 1023 blocks.", message);
|
||||
} else if (!p.HasCpeExt(CpeExt.ClickDistance)) {
|
||||
} else if (!p.Supports(CpeExt.ClickDistance)) {
|
||||
Player.Message(p, "Your client doesn't support changing your reach distance.");
|
||||
} else {
|
||||
p.Send(Packet.ClickDistance((short)packedDist));
|
||||
|
@ -55,7 +55,7 @@ namespace MCGalaxy.Core {
|
||||
if (!short.TryParse(reach, out reachDist)) return;
|
||||
p.ReachDistance = reachDist / 32f;
|
||||
|
||||
if (p.HasCpeExt(CpeExt.ClickDistance))
|
||||
if (p.Supports(CpeExt.ClickDistance))
|
||||
p.Send(Packet.ClickDistance(reachDist));
|
||||
}
|
||||
|
||||
|
@ -50,9 +50,9 @@ namespace MCGalaxy.Core {
|
||||
p.isFlying = false;
|
||||
}
|
||||
|
||||
if (p.HasCpeExt(CpeExt.EnvWeatherType))
|
||||
if (p.Supports(CpeExt.EnvWeatherType))
|
||||
p.Send(Packet.EnvWeatherType((byte)level.Config.Weather));
|
||||
if (p.HasCpeExt(CpeExt.EnvColors))
|
||||
if (p.Supports(CpeExt.EnvColors))
|
||||
p.SendCurrentEnvColors();
|
||||
p.SendCurrentMapAppearance();
|
||||
p.SendCurrentBlockPermissions();
|
||||
|
@ -139,8 +139,11 @@ namespace MCGalaxy {
|
||||
if (id == Entities.SelfID) pos.Y -= 22;
|
||||
name = Colors.Cleanup(name, dst.hasTextColors);
|
||||
|
||||
if (dst.hasExtList) {
|
||||
if (dst.Supports(CpeExt.ExtPlayerList, 2)) {
|
||||
dst.Send(Packet.ExtAddEntity2(id, skin, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
|
||||
} else if (dst.hasExtList) {
|
||||
dst.Send(Packet.ExtAddEntity(id, skin, name, dst.hasCP437));
|
||||
dst.Send(Packet.Teleport(id, pos, rot, dst.hasExtPositions));
|
||||
} else {
|
||||
dst.Send(Packet.AddEntity(id, name, pos, rot, dst.hasCP437, dst.hasExtPositions));
|
||||
}
|
||||
@ -149,7 +152,7 @@ namespace MCGalaxy {
|
||||
dst.Send(Packet.ChangeModel(id, model, dst.hasCP437));
|
||||
}
|
||||
|
||||
if (dst.HasCpeExt(CpeExt.EntityProperty)) {
|
||||
if (dst.Supports(CpeExt.EntityProperty)) {
|
||||
dst.Send(Packet.EntityProperty(id, EntityProp.RotX, Orientation.PackedToDegrees(rot.RotX)));
|
||||
dst.Send(Packet.EntityProperty(id, EntityProp.RotZ, Orientation.PackedToDegrees(rot.RotZ)));
|
||||
}
|
||||
@ -186,7 +189,7 @@ namespace MCGalaxy {
|
||||
entity.ModelBB = AABB.ModelAABB(model, lvl);
|
||||
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != lvl || !pl.HasCpeExt(CpeExt.ChangeModel)) continue;
|
||||
if (pl.level != lvl || !pl.Supports(CpeExt.ChangeModel)) continue;
|
||||
if (!pl.CanSeeEntity(entity)) continue;
|
||||
|
||||
byte id = (pl == entity) ? Entities.SelfID : entity.EntityID;
|
||||
@ -217,7 +220,7 @@ namespace MCGalaxy {
|
||||
if (prop == EntityProp.RotY) entity.SetYawPitch(rot.RotY, rot.HeadX);
|
||||
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != lvl || !pl.HasCpeExt(CpeExt.EntityProperty)) continue;
|
||||
if (pl.level != lvl || !pl.Supports(CpeExt.EntityProperty)) continue;
|
||||
if (!pl.CanSeeEntity(entity)) continue;
|
||||
|
||||
byte id = (pl == entity) ? Entities.SelfID : entity.EntityID;
|
||||
|
@ -99,14 +99,14 @@ namespace MCGalaxy.Games {
|
||||
// Show message for non-CPE clients
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != game.Map || pl.HasCpeExt(CpeExt.MessageTypes)) continue;
|
||||
if (pl.level != game.Map || pl.Supports(CpeExt.MessageTypes)) continue;
|
||||
pl.SendMessage("You have 20 seconds to vote for the next map");
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != game.Map || !pl.HasCpeExt(CpeExt.MessageTypes)) continue;
|
||||
if (pl.level != game.Map || !pl.Supports(CpeExt.MessageTypes)) continue;
|
||||
pl.SendCpeMessage(CpeMessageType.BottomRight1, "&e" + (20 - i) + "s %Sleft to vote");
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
@ -150,7 +150,7 @@ namespace MCGalaxy.Games {
|
||||
const string line1 = "&eLevel vote - type &a1&e, &b2&e or &c3";
|
||||
string line2 = "&a" + Candidate1 + "&e, &b" + Candidate2 + "&e, &c" + Candidate3;
|
||||
|
||||
if (p.HasCpeExt(CpeExt.MessageTypes)) {
|
||||
if (p.Supports(CpeExt.MessageTypes)) {
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight3, line1);
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, line2);
|
||||
} else {
|
||||
|
@ -114,14 +114,14 @@ namespace MCGalaxy.Games.ZS {
|
||||
Command.all.FindByName("Spawn").Use(p, "");
|
||||
p.Game.Referee = false;
|
||||
|
||||
if (p.HasCpeExt(CpeExt.HackControl))
|
||||
if (p.Supports(CpeExt.HackControl))
|
||||
p.Send(Hacks.MakeHackControl(p));
|
||||
} else {
|
||||
HandlePlayerDisconnect(p, null);
|
||||
Entities.GlobalDespawn(p, false, true);
|
||||
p.Game.Referee = true;
|
||||
|
||||
if (p.HasCpeExt(CpeExt.HackControl))
|
||||
if (p.Supports(CpeExt.HackControl))
|
||||
p.Send(Packet.HackControl(true, true, true, true, true, -1));
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ namespace MCGalaxy.Games {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level != Map) continue;
|
||||
CpeMessageType type = announce && p.HasCpeExt(CpeExt.MessageTypes)
|
||||
CpeMessageType type = announce && p.Supports(CpeExt.MessageTypes)
|
||||
? CpeMessageType.Announcement : CpeMessageType.Normal;
|
||||
|
||||
p.Send(Packet.Message(message, type, p.hasCP437));
|
||||
@ -258,7 +258,7 @@ namespace MCGalaxy.Games {
|
||||
p.Game.InvisibilityTime = left;
|
||||
|
||||
string msg = "&bInvisibility for &a" + left;
|
||||
if (p.HasCpeExt(CpeExt.MessageTypes)) {
|
||||
if (p.Supports(CpeExt.MessageTypes)) {
|
||||
p.SendCpeMessage(CpeMessageType.BottomRight2, msg);
|
||||
} else {
|
||||
Player.Message(p, msg);
|
||||
|
@ -46,7 +46,7 @@ namespace MCGalaxy {
|
||||
lvl.Config.Weather = weather;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level == lvl && pl.HasCpeExt(CpeExt.EnvWeatherType))
|
||||
if (pl.level == lvl && pl.Supports(CpeExt.EnvWeatherType))
|
||||
pl.Send(Packet.EnvWeatherType(weather));
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ namespace MCGalaxy {
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != lvl) continue;
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.EnvMapAspect)) {
|
||||
if (pl.Supports(CpeExt.EnvMapAspect)) {
|
||||
pl.Send(Packet.EnvMapProperty(prop, value));
|
||||
} else {
|
||||
pl.SendCurrentMapAppearance();
|
||||
@ -177,7 +177,7 @@ namespace MCGalaxy {
|
||||
internal static void UpdateEnvColor(Player p, byte type, string hex) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != p.level || !pl.HasCpeExt(CpeExt.EnvColors)) continue;
|
||||
if (pl.level != p.level || !pl.Supports(CpeExt.EnvColors)) continue;
|
||||
pl.SendEnvColor(type, hex);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ namespace MCGalaxy {
|
||||
retryTag: try {
|
||||
foreach (string raw in LineWrapper.Wordwrap(message)) {
|
||||
string line = raw;
|
||||
if (!HasCpeExt(CpeExt.EmoteFix) && LineEndsInEmote(line))
|
||||
if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line))
|
||||
line += '\'';
|
||||
|
||||
Send(Packet.Message(line, (CpeMessageType)id, hasCP437));
|
||||
@ -150,7 +150,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public void SendCpeMessage(CpeMessageType type, string message, bool colorParse = true) {
|
||||
if (type != CpeMessageType.Normal && !HasCpeExt(CpeExt.MessageTypes)) {
|
||||
if (type != CpeMessageType.Normal && !Supports(CpeExt.MessageTypes)) {
|
||||
if (type == CpeMessageType.Announcement) type = CpeMessageType.Normal;
|
||||
else return;
|
||||
}
|
||||
@ -166,7 +166,7 @@ namespace MCGalaxy {
|
||||
OnSendingMotdEvent.Call(this, packet);
|
||||
Send(packet);
|
||||
|
||||
if (!HasCpeExt(CpeExt.HackControl)) return;
|
||||
if (!Supports(CpeExt.HackControl)) return;
|
||||
Send(Hacks.MakeHackControl(this));
|
||||
if (Game.Referee)
|
||||
Send(Packet.HackControl(true, true, true, true, true, -1));
|
||||
@ -200,7 +200,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
BlockDefinition.SendLevelCustomBlocks(this);
|
||||
|
||||
if (HasCpeExt(CpeExt.InventoryOrder)) {
|
||||
if (Supports(CpeExt.InventoryOrder)) {
|
||||
BlockDefinition.SendLevelInventoryOrder(this);
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
/// <summary> Returns whether this player's client supports the given CPE extension. </summary>
|
||||
public bool HasCpeExt(string extName, int version = 1) {
|
||||
public bool Supports(string extName, int version = 1) {
|
||||
if (!hasCpe) return false;
|
||||
ExtEntry ext = FindExtension(extName);
|
||||
return ext != null && ext.ClientExtVersion == version;
|
||||
@ -104,7 +104,7 @@ namespace MCGalaxy {
|
||||
if (!hasBlockDefs) side = level.RawFallback(side);
|
||||
if (!hasBlockDefs) edge = level.RawFallback(edge);
|
||||
|
||||
if (HasCpeExt(CpeExt.EnvMapAspect)) {
|
||||
if (Supports(CpeExt.EnvMapAspect)) {
|
||||
string url = GetTextureUrl();
|
||||
// reset all other textures back to client default.
|
||||
if (url != lastUrl) Send(Packet.EnvMapUrl("", hasCP437));
|
||||
@ -121,7 +121,7 @@ namespace MCGalaxy {
|
||||
Send(Packet.EnvMapProperty(EnvProp.CloudsSpeed, level.Config.CloudsSpeed));
|
||||
Send(Packet.EnvMapProperty(EnvProp.WeatherSpeed, level.Config.WeatherSpeed));
|
||||
Send(Packet.EnvMapProperty(EnvProp.ExpFog, level.Config.ExpFog ? 1 : 0));
|
||||
} else if (HasCpeExt(CpeExt.EnvMapAppearance, 2)) {
|
||||
} else if (Supports(CpeExt.EnvMapAppearance, 2)) {
|
||||
string url = GetTextureUrl();
|
||||
// reset all other textures back to client default.
|
||||
if (url != lastUrl) {
|
||||
@ -131,7 +131,7 @@ namespace MCGalaxy {
|
||||
Send(Packet.MapAppearanceV2(url, side, edge, level.Config.EdgeLevel,
|
||||
level.Config.CloudsHeight, level.Config.MaxFogDistance, hasCP437));
|
||||
lastUrl = url;
|
||||
} else if (HasCpeExt(CpeExt.EnvMapAppearance)) {
|
||||
} else if (Supports(CpeExt.EnvMapAppearance)) {
|
||||
string url = level.Config.Terrain.Length == 0 ? ServerConfig.DefaultTerrain : level.Config.Terrain;
|
||||
Send(Packet.MapAppearance(url, side, edge, level.Config.EdgeLevel, hasCP437));
|
||||
}
|
||||
@ -166,7 +166,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public void SendCurrentBlockPermissions() {
|
||||
if (!HasCpeExt(CpeExt.BlockPermissions)) return;
|
||||
if (!Supports(CpeExt.BlockPermissions)) return;
|
||||
|
||||
// Write the block permissions as one bulk TCP packet
|
||||
int count = NumBlockPermissions();
|
||||
|
@ -303,7 +303,7 @@ namespace MCGalaxy {
|
||||
|
||||
void HandleMovement(byte[] buffer, int offset) {
|
||||
if (!loggedIn || trainGrab || following.Length > 0) { CheckBlocks(Pos); return; }
|
||||
if (HasCpeExt(CpeExt.HeldBlock)) {
|
||||
if (Supports(CpeExt.HeldBlock)) {
|
||||
RawHeldBlock = ExtBlock.FromRaw(buffer[offset + 1]);
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ namespace MCGalaxy {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasCpeExt(CpeExt.LongerMessages) && continued != 0) {
|
||||
if (Supports(CpeExt.LongerMessages) && continued != 0) {
|
||||
partialMessage += text;
|
||||
if (text.Length < NetUtils.StringSize) partialMessage += " ";
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user