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 += '\'';
Send(Packet.Message(line, (CpeMessageType)id, hasCP437)); for (int i = 0; i < lines.Count; i++) {
string line = lines[i];
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);
} }