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; }
try {
foreach (string raw in LineWrapper.Wordwrap(message)) {
string line = raw;
if (!Supports(CpeExt.EmoteFix) && LineEndsInEmote(line))
line += '\'';
List<string> lines = LineWrapper.Wordwrap(message);
byte[] packet = new byte[lines.Count * 66];
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) {
Logger.LogError(e);
}