Skip to content

Commit

Permalink
Change MessageLines to be non-interruptable by other messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodlyay committed Aug 7, 2024
1 parent 0bb1e53 commit 9046849
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions MCGalaxy/Network/Player.Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ public partial class Player : IDisposable
public bool hasChangeModel, hasExtList, hasCP437;

public void Send(byte[] buffer) { Socket.Send(buffer, SendFlags.None); }

public void MessageLines(IEnumerable<string> lines) {
foreach (string line in lines) { Message(line); }
lock (messageLocker) {
foreach (string line in lines) { Message(line); }
}
}


// Put a lock on sending messages so that MessageLines is not interrupted by other messages
readonly object messageLocker = new object();
public void Message(string message, object a0) { Message(string.Format(message, a0)); }
public void Message(string message, object a0, object a1) { Message(string.Format(message, a0, a1)); }
public void Message(string message, object a0, object a1, object a2) { Message(string.Format(message, a0, a1, a2)); }
Expand All @@ -40,8 +44,9 @@ public virtual void Message(string message) {
// Message should start with server color if no initial color
if (message.Length > 0 && !(message[0] == '&' || message[0] == '%')) message = "&S" + message;
message = Chat.Format(message, this);

SendRawMessage(message);
lock (messageLocker) {
SendRawMessage(message);
}
}

void SendRawMessage(string message) {
Expand Down

0 comments on commit 9046849

Please sign in to comment.