mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
Simplify CPE handling
This commit is contained in:
parent
594725b7fa
commit
7988ca65d3
@ -31,8 +31,8 @@ namespace MCGalaxy.Commands.Chatting {
|
|||||||
if (!message.CaselessEq("all")) {
|
if (!message.CaselessEq("all")) {
|
||||||
if (Player.IsSuper(p)) { Player.Message(p, "Super users cannot measure their own ping."); return; }
|
if (Player.IsSuper(p)) { Player.Message(p, "Super users cannot measure their own ping."); return; }
|
||||||
|
|
||||||
if (!p.HasCpeExt(CpeExt.TwoWayPing)) {
|
if (!p.hasTwoWayPing) {
|
||||||
Player.Message(p, "Your client does not support measuring ping.");
|
Player.Message(p, "Your client does not support measuring ping. You may need to update it.");
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, p.Ping.Format());
|
Player.Message(p, p.Ping.Format());
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,8 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public bool hasCpe, finishedCpeLogin = false;
|
public bool hasCpe, finishedCpeLogin = false;
|
||||||
public string appName;
|
public string appName;
|
||||||
public int extensionCount;
|
int extensionCount;
|
||||||
public List<string> extensions = new List<string>();
|
byte customBlockSupportLevel;
|
||||||
public int customBlockSupportLevel;
|
|
||||||
|
|
||||||
void HandleExtInfo(byte[] buffer, int offset) {
|
void HandleExtInfo(byte[] buffer, int offset) {
|
||||||
appName = NetUtils.ReadString(buffer, offset + 1);
|
appName = NetUtils.ReadString(buffer, offset + 1);
|
||||||
|
@ -89,7 +89,7 @@ namespace MCGalaxy.Network {
|
|||||||
byte[] MakePacket(Player p, ref byte[] bulk, ref byte[] normal,
|
byte[] MakePacket(Player p, ref byte[] bulk, ref byte[] normal,
|
||||||
ref byte[] noBlockDefs, ref byte[] original) {
|
ref byte[] noBlockDefs, ref byte[] original) {
|
||||||
// Different clients support varying types of blocks
|
// Different clients support varying types of blocks
|
||||||
if (p.HasCpeExt(CpeExt.BulkBlockUpdate) && p.hasCustomBlocks && p.hasBlockDefs && count >= 160) {
|
if (p.hasBulkBlockUpdate && p.hasCustomBlocks && p.hasBlockDefs && count >= 160) {
|
||||||
if (bulk == null) bulk = MakeBulk();
|
if (bulk == null) bulk = MakeBulk();
|
||||||
return bulk;
|
return bulk;
|
||||||
} else if (p.hasCustomBlocks && p.hasBlockDefs) {
|
} else if (p.hasCustomBlocks && p.hasBlockDefs) {
|
||||||
|
@ -16,129 +16,85 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using MCGalaxy.Blocks;
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.Network;
|
using MCGalaxy.Network;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public partial class Player {
|
public partial class Player {
|
||||||
|
|
||||||
class CPEExt {
|
class ExtEntry {
|
||||||
public string ExtName;
|
public string ExtName;
|
||||||
public int ExtVersion;
|
public byte ClientExtVersion, ServerExtVersion = 1;
|
||||||
public CPEExt(string extName) { ExtName = extName; }
|
|
||||||
|
public ExtEntry(string extName) { ExtName = extName; }
|
||||||
|
public ExtEntry(string extName, byte extVersion) {
|
||||||
|
ExtName = extName; ServerExtVersion = extVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ClickDistance, CustomBlocks, HeldBlock, TextHotKey;
|
ExtEntry[] extensions = new ExtEntry[] {
|
||||||
public int ExtPlayerList, EnvColors, SelectionCuboid, BlockPermissions;
|
new ExtEntry(CpeExt.ClickDistance), new ExtEntry(CpeExt.CustomBlocks),
|
||||||
public int ChangeModel, EnvMapAppearance, EnvWeatherType, HackControl;
|
new ExtEntry(CpeExt.HeldBlock), new ExtEntry(CpeExt.TextHotkey),
|
||||||
public int EmoteFix, MessageTypes, LongerMessages, FullCP437;
|
new ExtEntry(CpeExt.ExtPlayerList, 2), new ExtEntry(CpeExt.EnvColors),
|
||||||
public int BlockDefinitions, BlockDefinitionsExt, TextColors, BulkBlockUpdate;
|
new ExtEntry(CpeExt.SelectionCuboid), new ExtEntry(CpeExt.BlockPermissions),
|
||||||
public int EnvMapAspect, PlayerClick, EntityProperty, ExtEntityPositions, TwoWayPing;
|
new ExtEntry(CpeExt.ChangeModel), new ExtEntry(CpeExt.EnvMapAppearance, 2),
|
||||||
|
new ExtEntry(CpeExt.EnvWeatherType), new ExtEntry(CpeExt.HackControl),
|
||||||
|
new ExtEntry(CpeExt.EmoteFix), new ExtEntry(CpeExt.MessageTypes),
|
||||||
|
new ExtEntry(CpeExt.LongerMessages), new ExtEntry(CpeExt.FullCP437),
|
||||||
|
new ExtEntry(CpeExt.BlockDefinitions), new ExtEntry(CpeExt.BlockDefinitionsExt, 2),
|
||||||
|
new ExtEntry(CpeExt.TextColors), new ExtEntry(CpeExt.BulkBlockUpdate),
|
||||||
|
new ExtEntry(CpeExt.EnvMapAspect), new ExtEntry(CpeExt.PlayerClick),
|
||||||
|
new ExtEntry(CpeExt.EntityProperty), new ExtEntry(CpeExt.ExtEntityPositions),
|
||||||
|
new ExtEntry(CpeExt.TwoWayPing), new ExtEntry(CpeExt.InventoryOrder),
|
||||||
|
};
|
||||||
|
|
||||||
|
ExtEntry FindExtension(string extName) {
|
||||||
|
foreach (ExtEntry ext in extensions) {
|
||||||
|
if (ext.ExtName.CaselessEq(extName)) return ext;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// these are checked very frequently, so avoid overhead of HasCpeExt
|
// these are checked very frequently, so avoid overhead of HasCpeExt
|
||||||
public bool hasCustomBlocks, hasBlockDefs,
|
public bool hasCustomBlocks, hasBlockDefs, hasTextColors,
|
||||||
hasTextColors, hasChangeModel, hasExtList, hasCP437, hasTwoWayPing;
|
hasChangeModel, hasExtList, hasCP437, hasTwoWayPing, hasBulkBlockUpdate;
|
||||||
|
|
||||||
public void AddExtension(string ext, int version) {
|
void AddExtension(string extName, int version) {
|
||||||
switch (ext.Trim()) {
|
ExtEntry ext = FindExtension(extName.Trim());
|
||||||
case CpeExt.ClickDistance:
|
if (ext == null) return;
|
||||||
ClickDistance = version; break;
|
ext.ClientExtVersion = (byte)version;
|
||||||
case CpeExt.CustomBlocks:
|
|
||||||
CustomBlocks = version;
|
|
||||||
if (version == 1) Send(Packet.CustomBlockSupportLevel(1));
|
|
||||||
hasCustomBlocks = true; break;
|
|
||||||
case CpeExt.HeldBlock:
|
|
||||||
HeldBlock = version; break;
|
|
||||||
case CpeExt.TextHotkey:
|
|
||||||
TextHotKey = version; break;
|
|
||||||
case CpeExt.ExtPlayerList:
|
|
||||||
ExtPlayerList = version;
|
|
||||||
hasExtList = version == 2; break;
|
|
||||||
case CpeExt.EnvColors:
|
|
||||||
EnvColors = version; break;
|
|
||||||
case CpeExt.SelectionCuboid:
|
|
||||||
SelectionCuboid = version; break;
|
|
||||||
case CpeExt.BlockPermissions:
|
|
||||||
BlockPermissions = version; break;
|
|
||||||
case CpeExt.ChangeModel:
|
|
||||||
ChangeModel = version;
|
|
||||||
hasChangeModel = true; break;
|
|
||||||
case CpeExt.EnvMapAppearance:
|
|
||||||
EnvMapAppearance = version; break;
|
|
||||||
case CpeExt.EnvWeatherType:
|
|
||||||
EnvWeatherType = version; break;
|
|
||||||
case CpeExt.HackControl:
|
|
||||||
HackControl = version; break;
|
|
||||||
case CpeExt.EmoteFix:
|
|
||||||
EmoteFix = version; break;
|
|
||||||
case CpeExt.MessageTypes:
|
|
||||||
MessageTypes = version; break;
|
|
||||||
case CpeExt.LongerMessages:
|
|
||||||
LongerMessages = version; break;
|
|
||||||
case CpeExt.FullCP437:
|
|
||||||
FullCP437 = version;
|
|
||||||
hasCP437 = true; break;
|
|
||||||
case CpeExt.BlockDefinitions:
|
|
||||||
BlockDefinitions = version;
|
|
||||||
hasBlockDefs = true; break;
|
|
||||||
case CpeExt.BlockDefinitionsExt:
|
|
||||||
BlockDefinitionsExt = version; break;
|
|
||||||
case CpeExt.TextColors:
|
|
||||||
hasTextColors = true;
|
|
||||||
TextColors = version;
|
|
||||||
|
|
||||||
for (int i = 0; i < Colors.List.Length; i++) {
|
if (ext.ExtName == CpeExt.CustomBlocks) {
|
||||||
if (!Colors.List[i].IsModified()) continue;
|
if (version == 1) Send(Packet.CustomBlockSupportLevel(1));
|
||||||
Send(Packet.SetTextColor(Colors.List[i]));
|
hasCustomBlocks = true;
|
||||||
}
|
} else if (ext.ExtName == CpeExt.ChangeModel) {
|
||||||
break;
|
hasChangeModel = true;
|
||||||
case CpeExt.BulkBlockUpdate:
|
} else if (ext.ExtName == CpeExt.FullCP437) {
|
||||||
BulkBlockUpdate = version; break;
|
hasCP437 = true;
|
||||||
case CpeExt.EnvMapAspect:
|
} else if (ext.ExtName == CpeExt.ExtPlayerList) {
|
||||||
EnvMapAspect = version; break;
|
hasExtList = true;
|
||||||
case CpeExt.PlayerClick:
|
} else if (ext.ExtName == CpeExt.BlockDefinitions) {
|
||||||
PlayerClick = version; break;
|
hasBlockDefs = true;
|
||||||
case CpeExt.EntityProperty:
|
} else if (ext.ExtName == CpeExt.TextColors) {
|
||||||
EntityProperty = version; break;
|
hasTextColors = true;
|
||||||
case CpeExt.ExtEntityPositions:
|
for (int i = 0; i < Colors.List.Length; i++) {
|
||||||
ExtEntityPositions = version;
|
if (!Colors.List[i].IsModified()) continue;
|
||||||
hasExtPositions = true; break;
|
Send(Packet.SetTextColor(Colors.List[i]));
|
||||||
case CpeExt.TwoWayPing:
|
}
|
||||||
TwoWayPing = version;
|
} else if (ext.ExtName == CpeExt.ExtEntityPositions) {
|
||||||
hasTwoWayPing = true; break;
|
hasExtPositions = true;
|
||||||
|
} else if (ext.ExtName == CpeExt.TwoWayPing) {
|
||||||
|
hasTwoWayPing = true;
|
||||||
|
} else if (ext.ExtName == CpeExt.BulkBlockUpdate) {
|
||||||
|
hasBulkBlockUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasCpeExt(string Extension, int version = 1) {
|
public bool HasCpeExt(string extName, int version = 1) {
|
||||||
if (!hasCpe) return false;
|
if (!hasCpe) return false;
|
||||||
switch (Extension) {
|
ExtEntry ext = FindExtension(extName);
|
||||||
case CpeExt.ClickDistance: return ClickDistance == version;
|
return ext != null && ext.ClientExtVersion == version;
|
||||||
case CpeExt.CustomBlocks: return CustomBlocks == version;
|
|
||||||
case CpeExt.HeldBlock: return HeldBlock == version;
|
|
||||||
case CpeExt.TextHotkey: return TextHotKey == version;
|
|
||||||
case CpeExt.ExtPlayerList: return ExtPlayerList == version;
|
|
||||||
case CpeExt.EnvColors: return EnvColors == version;
|
|
||||||
case CpeExt.SelectionCuboid: return SelectionCuboid == version;
|
|
||||||
case CpeExt.BlockPermissions: return BlockPermissions == version;
|
|
||||||
case CpeExt.ChangeModel: return ChangeModel == version;
|
|
||||||
case CpeExt.EnvMapAppearance: return EnvMapAppearance == version;
|
|
||||||
case CpeExt.EnvWeatherType: return EnvWeatherType == version;
|
|
||||||
case CpeExt.HackControl: return HackControl == version;
|
|
||||||
case CpeExt.EmoteFix: return EmoteFix == version;
|
|
||||||
case CpeExt.MessageTypes: return MessageTypes == version;
|
|
||||||
case CpeExt.LongerMessages: return LongerMessages == version;
|
|
||||||
case CpeExt.FullCP437: return FullCP437 == version;
|
|
||||||
case CpeExt.BlockDefinitions: return BlockDefinitions == version;
|
|
||||||
case CpeExt.BlockDefinitionsExt: return BlockDefinitionsExt == version;
|
|
||||||
case CpeExt.TextColors: return TextColors == version;
|
|
||||||
case CpeExt.BulkBlockUpdate: return BulkBlockUpdate == version;
|
|
||||||
case CpeExt.EnvMapAspect: return EnvMapAspect == version;
|
|
||||||
case CpeExt.PlayerClick: return PlayerClick == version;
|
|
||||||
case CpeExt.EntityProperty: return EntityProperty == version;
|
|
||||||
case CpeExt.ExtEntityPositions: return ExtEntityPositions == version;
|
|
||||||
case CpeExt.TwoWayPing: return TwoWayPing == version;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string lastUrl = "";
|
string lastUrl = "";
|
||||||
|
@ -51,42 +51,13 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SendCpeExtensions() {
|
void SendCpeExtensions() {
|
||||||
Send(Packet.ExtInfo(26));
|
Send(Packet.ExtInfo((byte)(extensions.Length + 1)));
|
||||||
|
// fix for classicube client, doesn't reply if only send EnvMapAppearance with version 2
|
||||||
|
Send(Packet.ExtEntry(CpeExt.EnvMapAppearance, 1));
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EnvMapAppearance, 1)); // fix for classicube client, doesn't reply if only send EnvMapAppearance with version 2
|
foreach (ExtEntry ext in extensions) {
|
||||||
Send(Packet.ExtEntry(CpeExt.ClickDistance, 1));
|
Send(Packet.ExtEntry(ext.ExtName, ext.ServerExtVersion));
|
||||||
Send(Packet.ExtEntry(CpeExt.CustomBlocks, 1));
|
}
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.HeldBlock, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.TextHotkey, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EnvColors, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.SelectionCuboid, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.BlockPermissions, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.ChangeModel, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EnvMapAppearance, 2));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EnvWeatherType, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.HackControl, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EmoteFix, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.FullCP437, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.LongerMessages, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.BlockDefinitions, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.BlockDefinitionsExt, 2));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.TextColors, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.BulkBlockUpdate, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.MessageTypes, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.ExtPlayerList, 2));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EnvMapAspect, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.PlayerClick, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.EntityProperty, 1));
|
|
||||||
|
|
||||||
Send(Packet.ExtEntry(CpeExt.ExtEntityPositions, 1));
|
|
||||||
Send(Packet.ExtEntry(CpeExt.TwoWayPing, 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompleteLoginProcess() {
|
void CompleteLoginProcess() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user