mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Write code page 437 characters in every string
This commit is contained in:
parent
77f3ac689f
commit
f95b31eb03
@ -172,11 +172,11 @@ namespace MCGalaxy {
|
||||
if (global && pl.level.CustomBlockDefs[id] != GlobalDefs[id]) continue;
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, true));
|
||||
pl.Send(Packet.DefineBlockExt(def, true, pl.hasCP437));
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, false));
|
||||
pl.Send(Packet.DefineBlockExt(def, false, pl.hasCP437));
|
||||
} else {
|
||||
pl.Send(Packet.DefineBlock(def));
|
||||
pl.Send(Packet.DefineBlock(def, pl.hasCP437));
|
||||
}
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.BlockPermissions))
|
||||
@ -247,11 +247,11 @@ namespace MCGalaxy {
|
||||
if (def == null) continue;
|
||||
|
||||
if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, true));
|
||||
pl.Send(Packet.DefineBlockExt(def, true, pl.hasCP437));
|
||||
} else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0) {
|
||||
pl.Send(Packet.DefineBlockExt(def, false));
|
||||
pl.Send(Packet.DefineBlockExt(def, false, pl.hasCP437));
|
||||
} else {
|
||||
pl.Send(Packet.DefineBlock(def));
|
||||
pl.Send(Packet.DefineBlock(def, pl.hasCP437));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
public static void WriteHeader(Stream s, Vec3U16 dims) {
|
||||
byte[] header = new byte[EntrySize * HeaderEntries * 4];
|
||||
NetUtils.WriteAscii("CBDB_MCG", header, 0);
|
||||
NetUtils.Write("CBDB_MCG", header, 0, false);
|
||||
WriteU16(Version, header, 8);
|
||||
WriteU16(dims.X, header, 10);
|
||||
WriteU16(dims.Y, header, 12);
|
||||
|
@ -71,7 +71,7 @@ namespace MCGalaxy {
|
||||
else WriteAscii(str, array, offset);
|
||||
}
|
||||
|
||||
public static void WriteAscii(string str, byte[] array, int offset) {
|
||||
static void WriteAscii(string str, byte[] array, int offset) {
|
||||
int count = Math.Min(str.Length, StringSize);
|
||||
for (int i = 0; i < count; i++) {
|
||||
char raw = str[i].UnicodeToCp437();
|
||||
@ -81,7 +81,7 @@ namespace MCGalaxy {
|
||||
array[offset + i] = (byte)' ';
|
||||
}
|
||||
|
||||
public static void WriteCP437(string str, byte[] array, int offset) {
|
||||
static void WriteCP437(string str, byte[] array, int offset) {
|
||||
int count = Math.Min(str.Length, StringSize);
|
||||
for (int i = 0; i < count; i++)
|
||||
array[offset + i] = (byte)str[i].UnicodeToCp437();
|
||||
|
@ -21,33 +21,34 @@ namespace MCGalaxy {
|
||||
|
||||
public static partial class Packet {
|
||||
|
||||
public static byte[] DefineBlock(BlockDefinition def) {
|
||||
public static byte[] DefineBlock(BlockDefinition def, bool hasCP437) {
|
||||
byte[] buffer = new byte[80];
|
||||
int i = 0;
|
||||
buffer[i++] = Opcode.CpeDefineBlock;
|
||||
MakeDefineBlockStart(def, buffer, ref i, false);
|
||||
MakeDefineBlockStart(def, buffer, ref i, false, hasCP437);
|
||||
buffer[i++] = def.Shape;
|
||||
MakeDefineBlockEnd(def, ref i, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] DefineBlockExt(BlockDefinition def, bool uniqueSideTexs) {
|
||||
public static byte[] DefineBlockExt(BlockDefinition def, bool uniqueSideTexs, bool hasCP437) {
|
||||
byte[] buffer = new byte[uniqueSideTexs ? 88 : 85];
|
||||
int i = 0;
|
||||
buffer[i++] = Opcode.CpeDefineBlockExt;
|
||||
MakeDefineBlockStart(def, buffer, ref i, uniqueSideTexs);
|
||||
MakeDefineBlockStart(def, buffer, ref i, uniqueSideTexs, hasCP437);
|
||||
buffer[i++] = def.MinX; buffer[i++] = def.MinZ; buffer[i++] = def.MinY;
|
||||
buffer[i++] = def.MaxX; buffer[i++] = def.MaxZ; buffer[i++] = def.MaxY;
|
||||
MakeDefineBlockEnd(def, ref i, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int i, bool uniqueSideTexs) {
|
||||
static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int i,
|
||||
bool uniqueSideTexs, bool hasCP437) {
|
||||
// speed = 2^((raw - 128) / 64);
|
||||
// therefore raw = 64log2(speed) + 128
|
||||
byte rawSpeed = (byte)(64 * Math.Log(def.Speed, 2) + 128);
|
||||
buffer[i++] = def.BlockID;
|
||||
NetUtils.WriteAscii(def.Name, buffer, i);
|
||||
NetUtils.Write(def.Name, buffer, i, hasCP437);
|
||||
i += NetUtils.StringSize;
|
||||
buffer[i++] = def.CollideType;
|
||||
buffer[i++] = rawSpeed;
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy {
|
||||
public static byte[] ExtInfo(byte count) {
|
||||
byte[] buffer = new byte[67];
|
||||
buffer[0] = Opcode.CpeExtInfo;
|
||||
NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1);
|
||||
NetUtils.Write("MCGalaxy " + Server.Version, buffer, 1, false);
|
||||
NetUtils.WriteI16((short)count, buffer, 65);
|
||||
return buffer;
|
||||
}
|
||||
@ -32,7 +32,7 @@ namespace MCGalaxy {
|
||||
public static byte[] ExtEntry(string name, int version) {
|
||||
byte[] buffer = new byte[69];
|
||||
buffer[0] = Opcode.CpeExtEntry;
|
||||
NetUtils.WriteAscii(name, buffer, 1);
|
||||
NetUtils.Write(name, buffer, 1, false);
|
||||
NetUtils.WriteI32(version, buffer, 65);
|
||||
return buffer;
|
||||
}
|
||||
@ -52,15 +52,44 @@ namespace MCGalaxy {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] TextHotKey(string label, string input, int keycode, byte mods) {
|
||||
public static byte[] TextHotKey(string label, string input, int keycode,
|
||||
byte mods, bool hasCP437) {
|
||||
byte[] buffer = new byte[134];
|
||||
buffer[0] = Opcode.CpeSetTextHotkey;
|
||||
NetUtils.WriteAscii(label, buffer, 1);
|
||||
NetUtils.WriteAscii(input, buffer, 65);
|
||||
NetUtils.Write(label, buffer, 1, hasCP437);
|
||||
NetUtils.Write(input, buffer, 65, hasCP437);
|
||||
NetUtils.WriteI32(keycode, buffer, 129);
|
||||
buffer[133] = mods;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] ExtAddEntity(byte id, string name, string displayname, bool hasCP437) {
|
||||
byte[] buffer = new byte[130];
|
||||
buffer[0] = Opcode.CpeExtAddEntity;
|
||||
buffer[1] = id;
|
||||
NetUtils.Write(name, buffer, 2, hasCP437);
|
||||
NetUtils.Write(displayname, buffer, 66, hasCP437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] ExtAddPlayerName(byte id, string listName, string displayName,
|
||||
string grp, byte grpRank, bool hasCP437) {
|
||||
byte[] buffer = new byte[196];
|
||||
buffer[0] = Opcode.CpeExtAddPlayerName;
|
||||
NetUtils.WriteI16(id, buffer, 1);
|
||||
NetUtils.Write(listName, buffer, 3, hasCP437);
|
||||
NetUtils.Write(displayName, buffer, 67, hasCP437);
|
||||
NetUtils.Write(grp, buffer, 131, hasCP437);
|
||||
buffer[195] = grpRank;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] ExtRemovePlayerName(byte id) {
|
||||
byte[] buffer = new byte[3];
|
||||
buffer[0] = Opcode.CpeExtRemovePlayerName;
|
||||
NetUtils.WriteI16(id, buffer, 1);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] EnvColor(byte type, short r, short g, short b) {
|
||||
byte[] buffer = new byte[8];
|
||||
@ -73,11 +102,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public static byte[] MakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2,
|
||||
short r, short g, short b, short opacity ) {
|
||||
short r, short g, short b, short opacity, bool hasCP437) {
|
||||
byte[] buffer = new byte[86];
|
||||
buffer[0] = Opcode.CpeMakeSelection;
|
||||
buffer[1] = id;
|
||||
NetUtils.WriteAscii(label, buffer, 2);
|
||||
NetUtils.Write(label, buffer, 2, hasCP437);
|
||||
|
||||
NetUtils.WriteU16(p1.X, buffer, 66);
|
||||
NetUtils.WriteU16(p1.Y, buffer, 68);
|
||||
@ -113,24 +142,34 @@ namespace MCGalaxy {
|
||||
buffer[index + 3] = delete ? (byte)1 : (byte)0;
|
||||
}
|
||||
|
||||
public static byte[] MapAppearance(string url, byte side, byte edge, int sideLevel) {
|
||||
public static byte[] ChangeModel(byte id, string model, bool hasCP437) {
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.CpeChangeModel;
|
||||
buffer[1] = id;
|
||||
NetUtils.Write(model, buffer, 2, hasCP437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] MapAppearance(string url, byte side, byte edge, int sideLevel,
|
||||
bool hasCP437) {
|
||||
byte[] buffer = new byte[69];
|
||||
WriteMapAppearance(buffer, url, side, edge, sideLevel);
|
||||
WriteMapAppearance(buffer, url, side, edge, sideLevel, hasCP437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] MapAppearanceV2(string url, byte side, byte edge, int sideLevel,
|
||||
int cloudHeight, int maxFog) {
|
||||
int cloudHeight, int maxFog, bool hasCP437) {
|
||||
byte[] buffer = new byte[73];
|
||||
WriteMapAppearance(buffer, url, side, edge, sideLevel);
|
||||
WriteMapAppearance(buffer, url, side, edge, sideLevel, hasCP437);
|
||||
NetUtils.WriteI16((short)cloudHeight, buffer, 69);
|
||||
NetUtils.WriteI16((short)maxFog, buffer, 71);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge, int sideLevel) {
|
||||
static void WriteMapAppearance(byte[] buffer, string url, byte side, byte edge,
|
||||
int sideLevel, bool hasCP437) {
|
||||
buffer[0] = Opcode.CpeEnvSetMapApperance;
|
||||
NetUtils.WriteAscii(url, buffer, 1);
|
||||
NetUtils.Write(url, buffer, 1, hasCP437);
|
||||
buffer[65] = side;
|
||||
buffer[66] = edge;
|
||||
NetUtils.WriteI16((short)sideLevel, buffer, 67);
|
||||
@ -158,12 +197,12 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public static byte[] ExtAddEntity2(byte id, string skinName, string displayName,
|
||||
ushort x, ushort y, ushort z, byte rotx, byte roty) {
|
||||
ushort x, ushort y, ushort z, byte rotx, byte roty, bool hasCP437) {
|
||||
byte[] buffer = new byte[138];
|
||||
buffer[0] = Opcode.CpeExtAddEntity2;
|
||||
buffer[1] = id;
|
||||
NetUtils.WriteAscii(displayName.TrimEnd('+'), buffer, 2);
|
||||
NetUtils.WriteAscii(skinName.TrimEnd('+'), buffer, 66);
|
||||
NetUtils.Write(displayName.TrimEnd('+'), buffer, 2, hasCP437);
|
||||
NetUtils.Write(skinName.TrimEnd('+'), buffer, 66, hasCP437);
|
||||
NetUtils.WriteU16(x, buffer, 130);
|
||||
NetUtils.WriteU16(y, buffer, 132);
|
||||
NetUtils.WriteU16(z, buffer, 134);
|
||||
@ -173,10 +212,10 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
public static byte[] EnvMapUrl(string url) {
|
||||
public static byte[] EnvMapUrl(string url, bool hasCP437) {
|
||||
byte[] buffer = new byte[65];
|
||||
buffer[0] = Opcode.CpeSetMapEnvUrl;
|
||||
NetUtils.WriteAscii(url, buffer, 1);
|
||||
NetUtils.Write(url, buffer, 1, hasCP437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -27,25 +27,24 @@ namespace MCGalaxy {
|
||||
buffer[1] = Server.version;
|
||||
|
||||
motd = ChatTokens.Apply(motd, p);
|
||||
bool cp437 = p.HasCpeExt(CpeExt.FullCP437);
|
||||
if (motd.Length > 64) {
|
||||
NetUtils.Write(motd, buffer, 2, cp437);
|
||||
NetUtils.Write(motd.Substring(64), buffer, 66, cp437);
|
||||
NetUtils.Write(motd, buffer, 2, p.hasCP437);
|
||||
NetUtils.Write(motd.Substring(64), buffer, 66, p.hasCP437);
|
||||
} else {
|
||||
NetUtils.Write(Server.name, buffer, 2, cp437);
|
||||
NetUtils.Write(motd, buffer, 66, cp437);
|
||||
NetUtils.Write(Server.name, buffer, 2, p.hasCP437);
|
||||
NetUtils.Write(motd, buffer, 66, p.hasCP437);
|
||||
}
|
||||
|
||||
buffer[130] = Block.canPlace(p, Block.blackrock) ? (byte)100 : (byte)0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] AddEntity(byte id, string name, ushort x, ushort y,
|
||||
ushort z, byte rotx, byte roty) {
|
||||
public static byte[] AddEntity(byte id, string name, ushort x, ushort y,
|
||||
ushort z, byte rotx, byte roty, bool hasCP437) {
|
||||
byte[] buffer = new byte[74];
|
||||
buffer[0] = Opcode.AddEntity;
|
||||
buffer[1] = id;
|
||||
NetUtils.WriteAscii(name.TrimEnd('+'), buffer, 2);
|
||||
NetUtils.Write(name.TrimEnd('+'), buffer, 2, hasCP437);
|
||||
NetUtils.WriteU16(x, buffer, 66);
|
||||
NetUtils.WriteU16(y, buffer, 68);
|
||||
NetUtils.WriteU16(z, buffer, 70);
|
||||
@ -54,7 +53,7 @@ namespace MCGalaxy {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] Teleport(byte id, ushort x, ushort y, ushort z,
|
||||
public static byte[] Teleport(byte id, ushort x, ushort y, ushort z,
|
||||
byte rotx, byte roty) {
|
||||
byte[] buffer = new byte[10];
|
||||
buffer[0] = Opcode.EntityTeleport;
|
||||
@ -67,12 +66,13 @@ namespace MCGalaxy {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] BlankMessage() {
|
||||
public static byte[] BlankMessage() { return Message("", 0, false); }
|
||||
|
||||
public static byte[] Message(string message, byte id, bool hasCp437) {
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.Message;
|
||||
|
||||
for (int i = 2; i < buffer.Length; i++)
|
||||
buffer[i] = (byte)' ';
|
||||
buffer[1] = id;
|
||||
NetUtils.Write(message, buffer, 2, hasCp437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -160,14 +160,7 @@ namespace MCGalaxy {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SendBlankMessage() {
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.Message;
|
||||
|
||||
for (int i = 2; i < buffer.Length; i++)
|
||||
buffer[i] = (byte)' ';
|
||||
Send(buffer);
|
||||
}
|
||||
public void SendBlankMessage() { Send(Packet.BlankMessage()); }
|
||||
|
||||
public static void MessageLines(Player p, IEnumerable<string> lines) {
|
||||
foreach (string line in lines)
|
||||
@ -240,12 +233,8 @@ namespace MCGalaxy {
|
||||
string line = raw;
|
||||
if (!HasCpeExt(CpeExt.EmoteFix) && line.TrimEnd(' ')[line.TrimEnd(' ').Length - 1] < '!')
|
||||
line += '\'';
|
||||
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.Message;
|
||||
buffer[1] = (byte)id;
|
||||
NetUtils.Write(line, buffer, 2, HasCpeExt(CpeExt.FullCP437));
|
||||
Send(buffer);
|
||||
|
||||
Send(Packet.Message(line, id, hasCP437));
|
||||
}
|
||||
} catch ( Exception e ) {
|
||||
message = "&f" + message;
|
||||
@ -266,11 +255,7 @@ namespace MCGalaxy {
|
||||
|
||||
/// <summary> Sends a raw message without performing any token resolving, emoticon parsing, or color parsing. </summary>
|
||||
public void SendRawMessage(CpeMessageType id, string message) {
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.Message;
|
||||
buffer[1] = (byte)id;
|
||||
NetUtils.Write(message, buffer, 2, HasCpeExt(CpeExt.FullCP437));
|
||||
Send(buffer);
|
||||
Send(Packet.Message(message, (byte)id, HasCpeExt(CpeExt.FullCP437)));
|
||||
}
|
||||
|
||||
public void SendMotd() { SendMapMotd(); }
|
||||
@ -356,7 +341,7 @@ namespace MCGalaxy {
|
||||
// NOTE: Fix for standard clients
|
||||
if (id == Entities.SelfID) y -= 22;
|
||||
|
||||
Send(Packet.AddEntity(id, name, x, y, z, rotx, roty));
|
||||
Send(Packet.AddEntity(id, name, x, y, z, rotx, roty, hasCP437));
|
||||
if (hasChangeModel) UpdateModels();
|
||||
}
|
||||
|
||||
@ -392,13 +377,14 @@ namespace MCGalaxy {
|
||||
NetUtils.WriteU16(z, buffer, 5);
|
||||
|
||||
if (block == Block.custom_block) {
|
||||
buffer[7] = hasBlockDefs ? level.GetExtTile(x, y, z) : level.GetFallbackExtTile(x, y, z);
|
||||
if (!hasCustomBlocks) buffer[7] = Block.ConvertCPE(buffer[7]);
|
||||
} else if (hasCustomBlocks) {
|
||||
buffer[7] = Block.Convert(block);
|
||||
block = hasBlockDefs ? level.GetExtTile(x, y, z) : level.GetFallbackExtTile(x, y, z);
|
||||
} else {
|
||||
buffer[7] = Block.ConvertCPE(Block.Convert(block));
|
||||
block = Block.Convert(block);
|
||||
}
|
||||
|
||||
// TODO: custom blocks replacing core blocks
|
||||
if (!hasCustomBlocks) block = Block.ConvertCPE(block);
|
||||
buffer[7] = block;
|
||||
Send(buffer);
|
||||
}
|
||||
|
||||
@ -414,65 +400,45 @@ namespace MCGalaxy {
|
||||
NetUtils.WriteU16(z, buffer, 5);
|
||||
|
||||
if (block == Block.custom_block) {
|
||||
buffer[7] = hasBlockDefs ? extBlock : level.GetFallback(extBlock);
|
||||
if (!hasCustomBlocks) buffer[7] = Block.ConvertCPE(buffer[7]);
|
||||
} else if (hasCustomBlocks) {
|
||||
buffer[7] = Block.Convert(block);
|
||||
block = hasBlockDefs ? extBlock : level.GetFallback(extBlock);
|
||||
} else {
|
||||
buffer[7] = Block.Convert(Block.ConvertCPE(block));
|
||||
block = Block.Convert(block);
|
||||
}
|
||||
|
||||
if (!hasCustomBlocks) block = Block.ConvertCPE(block);
|
||||
buffer[7] = block;
|
||||
Send(buffer);
|
||||
}
|
||||
|
||||
public void SendExtAddEntity(byte id, string name, string displayname = "") {
|
||||
byte[] buffer = new byte[130];
|
||||
buffer[0] = Opcode.CpeExtAddEntity;
|
||||
buffer[1] = id;
|
||||
NetUtils.WriteAscii(name, buffer, 2);
|
||||
if (displayname == "") displayname = name;
|
||||
NetUtils.WriteAscii(displayname, buffer, 66);
|
||||
Send(buffer);
|
||||
public void SendExtAddEntity(byte id, string name, string displayName = "") {
|
||||
Send(Packet.ExtAddEntity(id, name, displayName, hasCP437));
|
||||
}
|
||||
|
||||
public void SendExtAddEntity2(byte id, string skinName, string displayName, ushort x, ushort y, ushort z, byte rotx, byte roty) {
|
||||
// NOTE: Fix for standard clients
|
||||
if (id == Entities.SelfID) y -= 22;
|
||||
|
||||
Send(Packet.ExtAddEntity2(id, skinName, displayName, x, y, z, rotx, roty));
|
||||
Send(Packet.ExtAddEntity2(id, skinName, displayName, x, y, z, rotx, roty, hasCP437));
|
||||
if (hasChangeModel) UpdateModels();
|
||||
}
|
||||
|
||||
public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank) {
|
||||
byte[] buffer = new byte[196];
|
||||
buffer[0] = Opcode.CpeExtAddPlayerName;
|
||||
NetUtils.WriteI16(id, buffer, 1);
|
||||
NetUtils.WriteAscii(listName, buffer, 3);
|
||||
NetUtils.WriteAscii(displayName, buffer, 67);
|
||||
NetUtils.WriteAscii(grp, buffer, 131);
|
||||
buffer[195] = grpRank;
|
||||
Send(buffer);
|
||||
Send(Packet.ExtAddPlayerName(id, listName, displayName, grp, grpRank, hasCP437));
|
||||
}
|
||||
|
||||
public void SendExtRemovePlayerName(byte id) {
|
||||
byte[] buffer = new byte[3];
|
||||
buffer[0] = Opcode.CpeExtRemovePlayerName;
|
||||
NetUtils.WriteI16(id, buffer, 1);
|
||||
Send(buffer);
|
||||
Send(Packet.ExtRemovePlayerName(id));
|
||||
}
|
||||
|
||||
public void SendChangeModel( byte id, string model ) {
|
||||
public void SendChangeModel(byte id, string model) {
|
||||
// Fallback block models for clients that don't support block definitions
|
||||
byte block;
|
||||
bool fallback = byte.TryParse(model, out block) && block >= Block.CpeCount;
|
||||
block = level == null ? block : level.GetFallback(block);
|
||||
if (fallback && !hasBlockDefs && block != Block.air)
|
||||
model = block.ToString();
|
||||
|
||||
byte[] buffer = new byte[66];
|
||||
buffer[0] = Opcode.CpeChangeModel;
|
||||
buffer[1] = id;
|
||||
NetUtils.WriteAscii(model, buffer, 2);
|
||||
Send(buffer);
|
||||
|
||||
Send(Packet.ChangeModel(id, model, hasCP437));
|
||||
}
|
||||
|
||||
internal void CloseSocket() {
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy {
|
||||
|
||||
// these are checked frequently, so avoid overhead of HasCpeExt
|
||||
public bool hasCustomBlocks, hasBlockDefs,
|
||||
hasTextColors, hasChangeModel, hasExtList;
|
||||
hasTextColors, hasChangeModel, hasExtList, hasCP437;
|
||||
|
||||
public void AddExtension(string ext, int version) {
|
||||
switch (ext.Trim()) {
|
||||
@ -69,7 +69,8 @@ namespace MCGalaxy {
|
||||
case CpeExt.LongerMessages:
|
||||
LongerMessages = version; break;
|
||||
case CpeExt.FullCP437:
|
||||
FullCP437 = version; break;
|
||||
FullCP437 = version;
|
||||
hasCP437 = true; break;
|
||||
case CpeExt.BlockDefinitions:
|
||||
BlockDefinitions = version;
|
||||
hasBlockDefs = true; break;
|
||||
@ -156,8 +157,8 @@ namespace MCGalaxy {
|
||||
if (HasCpeExt(CpeExt.EnvMapAspect)) {
|
||||
string url = GetTextureUrl();
|
||||
// reset all other textures back to client default.
|
||||
if (url != lastUrl) Send(Packet.EnvMapUrl(""));
|
||||
Send(Packet.EnvMapUrl(url));
|
||||
if (url != lastUrl) Send(Packet.EnvMapUrl("", hasCP437));
|
||||
Send(Packet.EnvMapUrl(url, hasCP437));
|
||||
|
||||
Send(Packet.EnvMapProperty(EnvProp.SidesBlock, side));
|
||||
Send(Packet.EnvMapProperty(EnvProp.EdgeBlock, edge));
|
||||
@ -171,13 +172,13 @@ namespace MCGalaxy {
|
||||
string url = GetTextureUrl();
|
||||
// reset all other textures back to client default.
|
||||
if (url != lastUrl) {
|
||||
Send(Packet.MapAppearanceV2("", side, edge, level.EdgeLevel, level.CloudsHeight, level.MaxFogDistance));
|
||||
Send(Packet.MapAppearanceV2("", side, edge, level.EdgeLevel, level.CloudsHeight, level.MaxFogDistance, hasCP437));
|
||||
}
|
||||
Send(Packet.MapAppearanceV2(url, side, edge, level.EdgeLevel, level.CloudsHeight, level.MaxFogDistance));
|
||||
Send(Packet.MapAppearanceV2(url, side, edge, level.EdgeLevel, level.CloudsHeight, level.MaxFogDistance, hasCP437));
|
||||
lastUrl = url;
|
||||
} else if (HasCpeExt(CpeExt.EnvMapAppearance)) {
|
||||
string url = level.terrainUrl == "" ? Server.defaultTerrainUrl : level.terrainUrl;
|
||||
Send(Packet.MapAppearance(url, side, edge, level.EdgeLevel));
|
||||
Send(Packet.MapAppearance(url, side, edge, level.EdgeLevel, hasCP437));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,9 +296,8 @@ namespace MCGalaxy {
|
||||
isFlying = false;
|
||||
aiming = false;
|
||||
|
||||
bool cp437 = HasCpeExt(CpeExt.FullCP437);
|
||||
string kickPacketMsg = ChatTokens.Apply(discMsg, this);
|
||||
Send(Packet.Kick(discMsg, cp437), sync);
|
||||
Send(Packet.Kick(discMsg, hasCP437), sync);
|
||||
disconnected = true;
|
||||
if (isKick) totalKicked++;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user