Avoid messages from multiple threads rarely interleaving with each other

This commit is contained in:
UnknownShadow200 2020-05-27 18:20:43 +10:00
parent 2115a8eccb
commit d034a047b7

View File

@ -95,12 +95,16 @@ namespace MCGalaxy.Network {
public static byte[] Message(string message, CpeMessageType type, bool hasCp437) { public static byte[] Message(string message, CpeMessageType type, bool hasCp437) {
byte[] buffer = new byte[66]; byte[] buffer = new byte[66];
buffer[0] = Opcode.Message; WriteMessage(message, (byte)type, hasCp437, buffer, 0);
buffer[1] = (byte)type;
NetUtils.Write(message, buffer, 2, hasCp437);
return buffer; return buffer;
} }
public static void WriteMessage(string message, byte type, bool hasCp437, byte[] buffer, int index) {
buffer[index++] = Opcode.Message;
buffer[index++] = type;
NetUtils.Write(message, buffer, index, hasCp437);
}
public static byte[] Kick(string message, bool cp437) { public static byte[] Kick(string message, bool cp437) {
byte[] buffer = new byte[65]; byte[] buffer = new byte[65];
buffer[0] = Opcode.Kick; buffer[0] = Opcode.Kick;