Avoid messages from multiple threads rarely interleaving with each other

This commit is contained in:
UnknownShadow200 2020-05-27 18:26:43 +10:00
parent d034a047b7
commit bcfbd1624d

View File

@ -163,13 +163,16 @@ namespace MCGalaxy {
if (cancelmessage) { cancelmessage = false; return; } if (cancelmessage) { cancelmessage = false; return; }
try { try {
foreach (string raw in LineWrapper.Wordwrap(message)) { List<string> lines = LineWrapper.Wordwrap(message);
string line = raw; byte[] packet = new byte[lines.Count * 66];
if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line))
line += '\''; for (int i = 0; i < lines.Count; i++) {
string line = lines[i];
Send(Packet.Message(line, (CpeMessageType)id, hasCP437)); if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line)) line += '\'';
Packet.WriteMessage(line, id, hasCP437, packet, i * 66);
} }
// So multi-line messages from multiple threads don't interleave
Send(packet);
} catch (Exception e) { } catch (Exception e) {
Logger.LogError(e); Logger.LogError(e);
} }
@ -245,9 +248,9 @@ namespace MCGalaxy {
using (LevelChunkStream dst = new LevelChunkStream(this)) using (LevelChunkStream dst = new LevelChunkStream(this))
using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst)) using (Stream stream = LevelChunkStream.CompressMapHeader(this, volume, dst))
{ {
if (level.MightHaveCustomBlocks()) { if (level.MightHaveCustomBlocks()) {
LevelChunkStream.CompressMap(this, stream, dst); LevelChunkStream.CompressMap(this, stream, dst);
} else { } else {
LevelChunkStream.CompressMapSimple(this, stream, dst); LevelChunkStream.CompressMapSimple(this, stream, dst);
} }
} }