Move more Packet code into separate class.

This commit is contained in:
UnknownShadow200 2016-08-20 19:03:21 +10:00
parent 21f26742a6
commit 4ec09f27e2
6 changed files with 51 additions and 50 deletions

View File

@ -21,6 +21,22 @@ namespace MCGalaxy {
public static partial class Packet {
public static byte[] MakeExtInfo(byte count) {
byte[] buffer = new byte[67];
buffer[0] = Opcode.CpeExtInfo;
NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1);
NetUtils.WriteI16((short)count, buffer, 65);
return buffer;
}
public static byte[] MakeExtEntry(string name, int version) {
byte[] buffer = new byte[69];
buffer[0] = Opcode.CpeExtEntry;
NetUtils.WriteAscii(name, buffer, 1);
NetUtils.WriteI32(version, buffer, 65);
return buffer;
}
public static byte[] MakeClickDistance(short distance) {
byte[] buffer = new byte[3];
buffer[0] = Opcode.CpeSetClickDistance;

View File

@ -50,5 +50,12 @@ namespace MCGalaxy {
buffer[1] = Block.canPlace(p, Block.blackrock) ? (byte)100 : (byte)0;
return buffer;
}
public static byte[] MakeKick(string message, bool cp437) {
byte[] buffer = new byte[65];
buffer[0] = Opcode.Kick;
NetUtils.Write(message, buffer, 1, cp437);
return buffer;
}
}
}

View File

@ -477,29 +477,6 @@ namespace MCGalaxy {
Send(buffer);
}
void SendKick(string message, bool sync) {
byte[] buffer = new byte[65];
buffer[0] = Opcode.Kick;
NetUtils.Write(message, buffer, 1, HasCpeExt(CpeExt.FullCP437));
Send(buffer, sync);
}
void SendExtInfo( byte count ) {
byte[] buffer = new byte[67];
buffer[0] = Opcode.CpeExtInfo;
NetUtils.WriteAscii("MCGalaxy " + Server.Version, buffer, 1);
NetUtils.WriteI16((short)count, buffer, 65);
Send(buffer, true);
}
void SendExtEntry( string name, int version ) {
byte[] buffer = new byte[69];
buffer[0] = Opcode.CpeExtEntry;
NetUtils.WriteAscii(name, buffer, 1);
NetUtils.WriteI32(version, buffer, 65);
Send(buffer, true);
}
public void SendExtAddEntity(byte id, string name, string displayname = "") {
byte[] buffer = new byte[130];
buffer[0] = Opcode.CpeExtAddEntity;

View File

@ -157,34 +157,34 @@ namespace MCGalaxy {
}
void SendCpeExtensions() {
SendExtInfo(21);
SendExtEntry(CpeExt.ClickDistance, 1);
SendExtEntry(CpeExt.CustomBlocks, 1);
SendExtEntry(CpeExt.HeldBlock, 1);
Send(Packet.MakeExtInfo(21), true);
Send(Packet.MakeExtEntry(CpeExt.ClickDistance, 1), true);
Send(Packet.MakeExtEntry(CpeExt.CustomBlocks, 1), true);
Send(Packet.MakeExtEntry(CpeExt.HeldBlock, 1), true);
SendExtEntry(CpeExt.TextHotkey, 1);
SendExtEntry(CpeExt.EnvColors, 1);
SendExtEntry(CpeExt.SelectionCuboid, 1);
Send(Packet.MakeExtEntry(CpeExt.TextHotkey, 1), true);
Send(Packet.MakeExtEntry(CpeExt.EnvColors, 1), true);
Send(Packet.MakeExtEntry(CpeExt.SelectionCuboid, 1), true);
SendExtEntry(CpeExt.BlockPermissions, 1);
SendExtEntry(CpeExt.ChangeModel, 1);
SendExtEntry(CpeExt.EnvMapAppearance, 2);
Send(Packet.MakeExtEntry(CpeExt.BlockPermissions, 1), true);
Send(Packet.MakeExtEntry(CpeExt.ChangeModel, 1), true);
Send(Packet.MakeExtEntry(CpeExt.EnvMapAppearance, 2), true);
SendExtEntry(CpeExt.EnvWeatherType, 1);
SendExtEntry(CpeExt.HackControl, 1);
SendExtEntry(CpeExt.EmoteFix, 1);
Send(Packet.MakeExtEntry(CpeExt.EnvWeatherType, 1), true);
Send(Packet.MakeExtEntry(CpeExt.HackControl, 1), true);
Send(Packet.MakeExtEntry(CpeExt.EmoteFix, 1), true);
SendExtEntry(CpeExt.FullCP437, 1);
SendExtEntry(CpeExt.LongerMessages, 1);
SendExtEntry(CpeExt.BlockDefinitions, 1);
Send(Packet.MakeExtEntry(CpeExt.FullCP437, 1), true);
Send(Packet.MakeExtEntry(CpeExt.LongerMessages, 1), true);
Send(Packet.MakeExtEntry(CpeExt.BlockDefinitions, 1), true);
SendExtEntry(CpeExt.BlockDefinitionsExt, 2);
SendExtEntry(CpeExt.TextColors, 1);
SendExtEntry(CpeExt.BulkBlockUpdate, 1);
Send(Packet.MakeExtEntry(CpeExt.BlockDefinitionsExt, 2), true);
Send(Packet.MakeExtEntry(CpeExt.TextColors, 1), true);
Send(Packet.MakeExtEntry(CpeExt.BulkBlockUpdate, 1), true);
SendExtEntry(CpeExt.MessageTypes, 1);
SendExtEntry(CpeExt.ExtPlayerList, 2);
SendExtEntry(CpeExt.EnvMapAspect, 1);
Send(Packet.MakeExtEntry(CpeExt.MessageTypes, 1), true);
Send(Packet.MakeExtEntry(CpeExt.ExtPlayerList, 2), true);
Send(Packet.MakeExtEntry(CpeExt.EnvMapAspect, 1), true);
}
bool CheckWhitelist() {

View File

@ -279,7 +279,8 @@ namespace MCGalaxy {
isFlying = false;
aiming = false;
SendKick(kickMsg, sync);
bool cp437 = HasCpeExt(CpeExt.FullCP437);
Send(Packet.MakeKick(kickMsg, cp437), sync);
disconnected = true;
if (!loggedIn) {
connections.Remove(this);