|
21 | 21 | using Microsoft.AspNetCore.Authorization; |
22 | 22 | using Microsoft.AspNetCore.Mvc; |
23 | 23 | using System; |
| 24 | +using System.Buffers; |
24 | 25 | using System.Net.WebSockets; |
25 | 26 | using System.Security.Claims; |
26 | 27 | using System.Text; |
@@ -394,7 +395,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
394 | 395 |
|
395 | 396 | outboundMsg.action = chatMessage.action; |
396 | 397 |
|
397 | | - // send to everyone (minus those who have the chatter blocked) |
| 398 | + // Serialize once before broadcasting |
398 | 399 | byte[] bytesJSON = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(outboundMsg)); |
399 | 400 |
|
400 | 401 | // send it to everyone in the same room |
@@ -430,7 +431,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
430 | 431 | if (data != null && data.ContainsKey("room")) |
431 | 432 | { |
432 | 433 | Int16 roomID = data["room"].GetInt16(); |
433 | | - sourceUserSession.UpdateSessionNetworkRoom(roomID); |
| 434 | + await sourceUserSession.UpdateSessionNetworkRoom(roomID); |
434 | 435 | } |
435 | 436 | } |
436 | 437 | else if (msgID == EWebSocketMessageID.NETWORK_ROOM_MARK_READY) |
@@ -557,7 +558,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
557 | 558 | outboundMsg.announcement = chatMessage.announcement; |
558 | 559 | outboundMsg.show_announcement_to_host = chatMessage.show_announcement_to_host; |
559 | 560 |
|
560 | | - // send to everyone in lobby |
| 561 | + // Serialize once before broadcasting |
561 | 562 | byte[] bytesJSON = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(outboundMsg)); |
562 | 563 |
|
563 | 564 | foreach (LobbyMember lobbyMember in playerLobby.Members) |
@@ -630,15 +631,15 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
630 | 631 | } |
631 | 632 |
|
632 | 633 | // start match + create placeholder match |
633 | | - lobbyInfo.UpdateState(ELobbyState.INGAME); |
| 634 | + await lobbyInfo.UpdateState(ELobbyState.INGAME); |
634 | 635 |
|
635 | 636 | // simple websocket msg, has no data, so dont even read anything |
636 | 637 |
|
637 | 638 | // response |
638 | 639 | WebSocketMessage_Simple startCommand = new WebSocketMessage_Simple(); |
639 | 640 | startCommand.msg_id = (int)EWebSocketMessageID.START_GAME; |
640 | 641 |
|
641 | | - // send to everyone in lobby |
| 642 | + // Serialize once before broadcasting |
642 | 643 | byte[] bytesJSON = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(startCommand)); |
643 | 644 |
|
644 | 645 | foreach (KeyValuePair<Int64, UserSession> sessionData in WebSocketManager.GetUserDataCache()) |
@@ -682,7 +683,7 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
682 | 683 | WebSocketMessage_Simple startCommand = new WebSocketMessage_Simple(); |
683 | 684 | startCommand.msg_id = (int)EWebSocketMessageID.FULL_MESH_CONNECTIVITY_CHECK_RESPONSE; |
684 | 685 |
|
685 | | - // send to everyone in lobby |
| 686 | + // Serialize once before broadcasting |
686 | 687 | byte[] bytesJSON = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(startCommand)); |
687 | 688 |
|
688 | 689 | foreach (KeyValuePair<Int64, UserSession> sessionData in WebSocketManager.GetUserDataCache()) |
@@ -757,12 +758,6 @@ private async Task ProcessWSMessage(UserWebSocketInstance sourceWS, UserSession |
757 | 758 | } |
758 | 759 | else if (msgID == EWebSocketMessageID.NETWORK_SIGNAL) |
759 | 760 | { |
760 | | - var options = new JsonSerializerOptions |
761 | | - { |
762 | | - PropertyNameCaseInsensitive = true, |
763 | | - AllowOutOfOrderMetadataProperties = true |
764 | | - }; |
765 | | - |
766 | 761 | WebSocketMessage_SignalBidirectional? signal = |
767 | 762 | JsonSerializer.Deserialize<WebSocketMessage_SignalBidirectional>(payload, JsonOpts); |
768 | 763 | //Console.WriteLine("Signal received: " + signal.signal); |
|
0 commit comments