mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Move more Packet code into separate class.
This commit is contained in:
parent
21f26742a6
commit
4ec09f27e2
@ -21,6 +21,22 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static partial class Packet {
|
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) {
|
public static byte[] MakeClickDistance(short distance) {
|
||||||
byte[] buffer = new byte[3];
|
byte[] buffer = new byte[3];
|
||||||
buffer[0] = Opcode.CpeSetClickDistance;
|
buffer[0] = Opcode.CpeSetClickDistance;
|
||||||
|
@ -50,5 +50,12 @@ namespace MCGalaxy {
|
|||||||
buffer[1] = Block.canPlace(p, Block.blackrock) ? (byte)100 : (byte)0;
|
buffer[1] = Block.canPlace(p, Block.blackrock) ? (byte)100 : (byte)0;
|
||||||
return buffer;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
SendRaw(Opcode.LevelInitialise);
|
SendRaw(Opcode.LevelInitialise);
|
||||||
using (LevelChunkStream s = new LevelChunkStream(this))
|
using (LevelChunkStream s = new LevelChunkStream(this))
|
||||||
LevelChunkStream.CompressMap(this, s);
|
LevelChunkStream.CompressMap(this, s);
|
||||||
|
|
||||||
byte[] buffer = new byte[7];
|
byte[] buffer = new byte[7];
|
||||||
buffer[0] = Opcode.LevelFinalise;
|
buffer[0] = Opcode.LevelFinalise;
|
||||||
@ -476,29 +476,6 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
Send(buffer);
|
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 = "") {
|
public void SendExtAddEntity(byte id, string name, string displayname = "") {
|
||||||
byte[] buffer = new byte[130];
|
byte[] buffer = new byte[130];
|
||||||
|
@ -211,7 +211,7 @@ namespace MCGalaxy {
|
|||||||
case Opcode.CpeCustomBlockSupportLevel: return 2;
|
case Opcode.CpeCustomBlockSupportLevel: return 2;
|
||||||
default:
|
default:
|
||||||
if (!dontmindme)
|
if (!dontmindme)
|
||||||
Leave("Unhandled message id \"" + buffer[0] + "\"!", true);
|
Leave("Unhandled message id \"" + buffer[0] + "\"!", true);
|
||||||
else
|
else
|
||||||
Server.s.Log(Encoding.UTF8.GetString(buffer, 0, buffer.Length));
|
Server.s.Log(Encoding.UTF8.GetString(buffer, 0, buffer.Length));
|
||||||
return -1;
|
return -1;
|
||||||
@ -219,7 +219,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandlePacket(byte[] buffer) {
|
void HandlePacket(byte[] buffer) {
|
||||||
switch (buffer[0]) {
|
switch (buffer[0]) {
|
||||||
case Opcode.Handshake:
|
case Opcode.Handshake:
|
||||||
HandleLogin(buffer); break;
|
HandleLogin(buffer); break;
|
||||||
case Opcode.SetBlockClient:
|
case Opcode.SetBlockClient:
|
||||||
@ -242,7 +242,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
void HandleBlockchange(byte[] packet) {
|
void HandleBlockchange(byte[] packet) {
|
||||||
try {
|
try {
|
||||||
if (!loggedIn || CheckBlockSpam()) return;
|
if (!loggedIn || CheckBlockSpam()) return;
|
||||||
ushort x = NetUtils.ReadU16(packet, 1);
|
ushort x = NetUtils.ReadU16(packet, 1);
|
||||||
ushort y = NetUtils.ReadU16(packet, 3);
|
ushort y = NetUtils.ReadU16(packet, 3);
|
||||||
ushort z = NetUtils.ReadU16(packet, 5);
|
ushort z = NetUtils.ReadU16(packet, 5);
|
||||||
|
@ -157,34 +157,34 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SendCpeExtensions() {
|
void SendCpeExtensions() {
|
||||||
SendExtInfo(21);
|
Send(Packet.MakeExtInfo(21), true);
|
||||||
SendExtEntry(CpeExt.ClickDistance, 1);
|
Send(Packet.MakeExtEntry(CpeExt.ClickDistance, 1), true);
|
||||||
SendExtEntry(CpeExt.CustomBlocks, 1);
|
Send(Packet.MakeExtEntry(CpeExt.CustomBlocks, 1), true);
|
||||||
SendExtEntry(CpeExt.HeldBlock, 1);
|
Send(Packet.MakeExtEntry(CpeExt.HeldBlock, 1), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.TextHotkey, 1);
|
Send(Packet.MakeExtEntry(CpeExt.TextHotkey, 1), true);
|
||||||
SendExtEntry(CpeExt.EnvColors, 1);
|
Send(Packet.MakeExtEntry(CpeExt.EnvColors, 1), true);
|
||||||
SendExtEntry(CpeExt.SelectionCuboid, 1);
|
Send(Packet.MakeExtEntry(CpeExt.SelectionCuboid, 1), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.BlockPermissions, 1);
|
Send(Packet.MakeExtEntry(CpeExt.BlockPermissions, 1), true);
|
||||||
SendExtEntry(CpeExt.ChangeModel, 1);
|
Send(Packet.MakeExtEntry(CpeExt.ChangeModel, 1), true);
|
||||||
SendExtEntry(CpeExt.EnvMapAppearance, 2);
|
Send(Packet.MakeExtEntry(CpeExt.EnvMapAppearance, 2), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.EnvWeatherType, 1);
|
Send(Packet.MakeExtEntry(CpeExt.EnvWeatherType, 1), true);
|
||||||
SendExtEntry(CpeExt.HackControl, 1);
|
Send(Packet.MakeExtEntry(CpeExt.HackControl, 1), true);
|
||||||
SendExtEntry(CpeExt.EmoteFix, 1);
|
Send(Packet.MakeExtEntry(CpeExt.EmoteFix, 1), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.FullCP437, 1);
|
Send(Packet.MakeExtEntry(CpeExt.FullCP437, 1), true);
|
||||||
SendExtEntry(CpeExt.LongerMessages, 1);
|
Send(Packet.MakeExtEntry(CpeExt.LongerMessages, 1), true);
|
||||||
SendExtEntry(CpeExt.BlockDefinitions, 1);
|
Send(Packet.MakeExtEntry(CpeExt.BlockDefinitions, 1), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.BlockDefinitionsExt, 2);
|
Send(Packet.MakeExtEntry(CpeExt.BlockDefinitionsExt, 2), true);
|
||||||
SendExtEntry(CpeExt.TextColors, 1);
|
Send(Packet.MakeExtEntry(CpeExt.TextColors, 1), true);
|
||||||
SendExtEntry(CpeExt.BulkBlockUpdate, 1);
|
Send(Packet.MakeExtEntry(CpeExt.BulkBlockUpdate, 1), true);
|
||||||
|
|
||||||
SendExtEntry(CpeExt.MessageTypes, 1);
|
Send(Packet.MakeExtEntry(CpeExt.MessageTypes, 1), true);
|
||||||
SendExtEntry(CpeExt.ExtPlayerList, 2);
|
Send(Packet.MakeExtEntry(CpeExt.ExtPlayerList, 2), true);
|
||||||
SendExtEntry(CpeExt.EnvMapAspect, 1);
|
Send(Packet.MakeExtEntry(CpeExt.EnvMapAspect, 1), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckWhitelist() {
|
bool CheckWhitelist() {
|
||||||
|
@ -279,7 +279,8 @@ namespace MCGalaxy {
|
|||||||
isFlying = false;
|
isFlying = false;
|
||||||
aiming = false;
|
aiming = false;
|
||||||
|
|
||||||
SendKick(kickMsg, sync);
|
bool cp437 = HasCpeExt(CpeExt.FullCP437);
|
||||||
|
Send(Packet.MakeKick(kickMsg, cp437), sync);
|
||||||
disconnected = true;
|
disconnected = true;
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
connections.Remove(this);
|
connections.Remove(this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user