mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Remove more pointless Send funcs
This commit is contained in:
parent
ea09af941f
commit
8b69431c5a
@ -206,7 +206,7 @@ namespace MCGalaxy {
|
||||
if (global && pl.level.CustomBlockDefs[block] != null) continue;
|
||||
|
||||
if (pl.hasBlockDefs)
|
||||
pl.SendRaw(Opcode.CpeRemoveBlockDefinition, block);
|
||||
pl.Send(Packet.UndefineBlock(block));
|
||||
}
|
||||
Save(global, level);
|
||||
}
|
||||
|
@ -159,13 +159,13 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
internal static void Despawn(Player dst, byte id) {
|
||||
dst.SendRaw(Opcode.RemoveEntity, id);
|
||||
dst.Send(Packet.RemoveEntity(id));
|
||||
if (!Server.TablistGlobal)
|
||||
TabList.Remove(dst, id);
|
||||
}
|
||||
|
||||
internal static void Despawn(Player dst, PlayerBot b) {
|
||||
dst.SendRaw(Opcode.RemoveEntity, b.id);
|
||||
dst.Send(Packet.RemoveEntity(b.id));
|
||||
if (Server.TablistBots)
|
||||
TabList.Remove(dst, b.id);
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] UndefineBlock(byte block) {
|
||||
return new byte[] { Opcode.CpeRemoveBlockDefinition, block };
|
||||
}
|
||||
|
||||
public static byte[] DefineBlockExt(BlockDefinition def, bool uniqueSideTexs, bool hasCP437) {
|
||||
byte[] buffer = new byte[uniqueSideTexs ? 88 : 85];
|
||||
int i = 0;
|
||||
|
@ -44,6 +44,10 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static byte[] CustomBlockSupportLevel(byte level) {
|
||||
return new byte[] { Opcode.CpeCustomBlockSupportLevel, level };
|
||||
}
|
||||
|
||||
public static byte[] HoldThis(byte block, bool locked) {
|
||||
byte[] buffer = new byte[3];
|
||||
buffer[0] = Opcode.CpeHoldThis;
|
||||
|
@ -41,6 +41,16 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a ping packet. </remarks>
|
||||
public static byte[] Ping() {
|
||||
return new byte[] { Opcode.Ping };
|
||||
}
|
||||
|
||||
/// <summary> Constructs a packet that specified map data is about to be sent. </remarks>
|
||||
public static byte[] LevelInitalise() {
|
||||
return new byte[] { Opcode.LevelInitialise };
|
||||
}
|
||||
|
||||
/// <summary> Constructs a packet describing the dimensions of a level. </summary>
|
||||
public static byte[] LevelFinalise(ushort width, ushort height, ushort length) {
|
||||
byte[] buffer = new byte[7];
|
||||
@ -51,7 +61,7 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a packet that spawns / adds an entity. </summary>
|
||||
/// <summary> Constructs a packet that adds/spawns an entity. </summary>
|
||||
public static byte[] AddEntity(byte id, string name, Position pos,
|
||||
Orientation rot, bool hasCP437, bool extPos) {
|
||||
byte[] buffer = new byte[74 + (extPos ? 6 : 0)];
|
||||
@ -65,7 +75,7 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs an absolute position / teleport and rotation movement packet. </summary>
|
||||
/// <summary> Constructs an absolute position/teleport and rotation movement packet. </summary>
|
||||
public static byte[] Teleport(byte id, Position pos, Orientation rot, bool extPos) {
|
||||
byte[] buffer = new byte[10 + (extPos ? 6 : 0)];
|
||||
buffer[0] = Opcode.EntityTeleport;
|
||||
@ -77,6 +87,11 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a packet that removes/despawns an entity. </summary>
|
||||
public static byte[] RemoveEntity(byte id) {
|
||||
return new byte[] { Opcode.RemoveEntity, id };
|
||||
}
|
||||
|
||||
/// <summary> Constructs a chat message packet with an empty message. </summary>
|
||||
public static byte[] BlankMessage() { return Message("", 0, false); }
|
||||
|
||||
@ -89,6 +104,14 @@ namespace MCGalaxy.Network {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a kick / disconnect packet with the given reason / message. </summary>
|
||||
public static byte[] Kick(string message, bool cp437) {
|
||||
byte[] buffer = new byte[65];
|
||||
buffer[0] = Opcode.Kick;
|
||||
NetUtils.Write(message, buffer, 1, cp437);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a set user type/permission packet. </summary>
|
||||
/// <remarks> For certain clients, sets whether they are allowed to place bedrock, use ophax, place liquids. </remarks>
|
||||
public static byte[] UserType(Player p) {
|
||||
@ -97,13 +120,5 @@ namespace MCGalaxy.Network {
|
||||
buffer[1] = BlockPerms.CanModify(p, Block.blackrock) ? (byte)100 : (byte)0;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary> Constructs a kick / disconnect packet with the given reason / message. </summary>
|
||||
public static byte[] Kick(string message, bool cp437) {
|
||||
byte[] buffer = new byte[65];
|
||||
buffer[0] = Opcode.Kick;
|
||||
NetUtils.Write(message, buffer, 1, cp437);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,30 +102,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SendRaw(int id) {
|
||||
byte[] buffer = new byte[] { (byte)id };
|
||||
Send(buffer);
|
||||
}
|
||||
|
||||
public void SendRaw(int id, byte data) {
|
||||
byte[] buffer = new byte[] { (byte)id, data };
|
||||
Send(buffer);
|
||||
}
|
||||
|
||||
[Obsolete("Include the opcode in the array to avoid an extra temp allocation.")]
|
||||
public void SendRaw(int id, byte[] send, bool sync = false) {
|
||||
byte[] buffer = new byte[send.Length + 1];
|
||||
buffer[0] = (byte)id;
|
||||
for ( int i = 0; i < send.Length; i++ )
|
||||
buffer[i + 1] = send[i];
|
||||
SendRaw(buffer, sync);
|
||||
buffer = null;
|
||||
}
|
||||
|
||||
[Obsolete("Use Send() instead.")]
|
||||
public void SendRaw(byte[] buffer, bool sync = false) { Send(buffer, sync); }
|
||||
|
||||
public void Send(byte[] buffer, bool sync = false) {
|
||||
// Abort if socket has been closed
|
||||
if (disconnected || socket == null || !socket.Connected) return;
|
||||
@ -269,7 +245,7 @@ namespace MCGalaxy {
|
||||
AllowBuild = access == AccessResult.Whitelisted || access == AccessResult.Allowed;
|
||||
|
||||
try {
|
||||
SendRaw(Opcode.LevelInitialise);
|
||||
Send(Packet.LevelInitalise());
|
||||
|
||||
if (hasBlockDefs) {
|
||||
if (oldLevel != null && oldLevel != level)
|
||||
@ -307,7 +283,8 @@ namespace MCGalaxy {
|
||||
for (int i = 1; i < 256; i++) {
|
||||
BlockDefinition def = defs[i];
|
||||
if (def == null || def == BlockDefinition.GlobalDefs[i]) continue;
|
||||
SendRaw(Opcode.CpeRemoveBlockDefinition, (byte)i);
|
||||
|
||||
Send(Packet.UndefineBlock((byte)i));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +38,7 @@ namespace MCGalaxy {
|
||||
ClickDistance = version; break;
|
||||
case CpeExt.CustomBlocks:
|
||||
CustomBlocks = version;
|
||||
if (version == 1)
|
||||
SendRaw(Opcode.CpeCustomBlockSupportLevel, 1);
|
||||
if (version == 1) Send(Packet.CustomBlockSupportLevel(1));
|
||||
hasCustomBlocks = true; break;
|
||||
case CpeExt.HeldBlock:
|
||||
HeldBlock = version; break;
|
||||
|
@ -68,7 +68,7 @@ namespace MCGalaxy.Tasks {
|
||||
internal static void CheckState(SchedulerTask task) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
p.SendRaw(Opcode.Ping);
|
||||
p.Send(Packet.Ping());
|
||||
if (Server.afkminutes <= 0) return;
|
||||
if (DateTime.UtcNow < p.AFKCooldown) return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user