diff --git a/NebulaNetwork/Client.cs b/NebulaNetwork/Client.cs index 73904e30d..1cce3f040 100644 --- a/NebulaNetwork/Client.cs +++ b/NebulaNetwork/Client.cs @@ -172,7 +172,9 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) { // If the client is Quitting by himself, we don't have to inform him of his disconnection. if (e.Code == (ushort)DisconnectionReason.ClientRequestedDisconnect) + { return; + } // Opens the pause menu on disconnection to prevent NRE when leaving the game if (Multiplayer.Session?.IsGameLoaded ?? false) @@ -180,13 +182,33 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) GameMain.instance._paused = true; } + if (e.Code == (ushort)DisconnectionReason.ModIsMissing) + { + InGamePopup.ShowWarning( + "Mod Mismatch", + $"You are missing mod {e.Reason}", + "OK".Translate(), + Multiplayer.LeaveGame); + return; + } + + if (e.Code == (ushort)DisconnectionReason.ModIsMissingOnServer) + { + InGamePopup.ShowWarning( + "Mod Mismatch", + $"Server is missing mod {e.Reason}", + "OK".Translate(), + Multiplayer.LeaveGame); + return; + } + if (e.Code == (ushort)DisconnectionReason.ModVersionMismatch) { string[] versions = e.Reason.Split(';'); InGamePopup.ShowWarning( "Mod Version Mismatch", - $"Your Nebula Multiplayer Mod is not the same as the Host version.\nYou:{versions[0]} - Remote:{versions[1]}", - "OK", + $"Your mod {versions[0]} version is not the same as the Host version.\nYou:{versions[1]} - Remote:{versions[2]}", + "OK".Translate(), Multiplayer.LeaveGame); return; } @@ -197,7 +219,7 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) InGamePopup.ShowWarning( "Game Version Mismatch", $"Your version of the game is not the same as the one used by the Host.\nYou:{versions[0]} - Remote:{versions[1]}", - "OK", + "OK".Translate(), Multiplayer.LeaveGame); return; } @@ -215,17 +237,15 @@ private void ClientSocket_OnClose(object sender, CloseEventArgs e) InGamePopup.ShowWarning( "Server Unavailable", $"Could not reach the server, please try again later.", - "OK", + "OK".Translate(), Multiplayer.LeaveGame); } }); } - - - static void DisableNagleAlgorithm(WebSocket socket) + private static void DisableNagleAlgorithm(WebSocket socket) { - var tcpClient = AccessTools.FieldRefAccess("_tcpClient")(socket); + TcpClient tcpClient = AccessTools.FieldRefAccess("_tcpClient")(socket); tcpClient.NoDelay = true; } } diff --git a/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs b/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs index 9b2a75801..5fd2d2ee5 100644 --- a/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Session/HandshakeRequestProcessor.cs @@ -14,7 +14,7 @@ namespace NebulaNetwork.PacketProcessors.Session [RegisterPacketProcessor] public class HandshakeRequestProcessor : PacketProcessor { - private IPlayerManager playerManager; + private readonly IPlayerManager playerManager; public HandshakeRequestProcessor() { @@ -23,10 +23,13 @@ public HandshakeRequestProcessor() public override void ProcessPacket(HandshakeRequest packet, NebulaConnection conn) { - if (IsClient) return; + if (IsClient) + { + return; + } INebulaPlayer player; - using (playerManager.GetPendingPlayers(out var pendingPlayers)) + using (playerManager.GetPendingPlayers(out Dictionary pendingPlayers)) { if (!pendingPlayers.TryGetValue(conn, out player)) { @@ -50,13 +53,14 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con if (!BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(guid)) { conn.Disconnect(DisconnectionReason.ModIsMissingOnServer, guid); + return; } clientMods.Add(guid, version); } } - foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) + foreach (KeyValuePair pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { if (pluginInfo.Value.Instance is IMultiplayerMod mod) { @@ -68,7 +72,10 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con string version = clientMods[pluginInfo.Key]; - if (mod.CheckVersion(mod.Version, version)) continue; + if (mod.CheckVersion(mod.Version, version)) + { + continue; + } conn.Disconnect(DisconnectionReason.ModVersionMismatch, $"{pluginInfo.Key};{version};{mod.Version}"); return; @@ -88,9 +95,9 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con //TODO: some validation of client cert / generating auth challenge for the client // Load old data of the client string clientCertHash = CryptoUtils.Hash(packet.ClientCert); - using (playerManager.GetSavedPlayerData(out var savedPlayerData)) + using (playerManager.GetSavedPlayerData(out Dictionary savedPlayerData)) { - if (savedPlayerData.TryGetValue(clientCertHash, out var value)) + if (savedPlayerData.TryGetValue(clientCertHash, out IPlayerData value)) { player.LoadUserData(value); } @@ -109,16 +116,16 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con // Make sure that each player that is currently in the game receives that a new player as join so they can create its RemotePlayerCharacter PlayerJoining pdata = new PlayerJoining((PlayerData)player.Data.CreateCopyWithoutMechaData()); // Remove inventory from mecha data - using (playerManager.GetConnectedPlayers(out var connectedPlayers)) + using (playerManager.GetConnectedPlayers(out Dictionary connectedPlayers)) { - foreach (var kvp in connectedPlayers) + foreach (KeyValuePair kvp in connectedPlayers) { kvp.Value.SendPacket(pdata); } } // Add the new player to the list - using (playerManager.GetSyncingPlayers(out var syncingPlayers)) + using (playerManager.GetSyncingPlayers(out Dictionary syncingPlayers)) { syncingPlayers.Add(conn, player); } @@ -129,7 +136,7 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con using (BinaryUtils.Writer p = new BinaryUtils.Writer()) { int count = 0; - foreach (var pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) + foreach (KeyValuePair pluginInfo in BepInEx.Bootstrap.Chainloader.PluginInfos) { if (pluginInfo.Value.Instance is IMultiplayerModWithSettings mod) { @@ -139,7 +146,7 @@ public override void ProcessPacket(HandshakeRequest packet, NebulaConnection con } } - var gameDesc = GameMain.data.gameDesc; + GameDesc gameDesc = GameMain.data.gameDesc; player.SendPacket(new HandshakeResponse(gameDesc.galaxyAlgo, gameDesc.galaxySeed, gameDesc.starCount, gameDesc.resourceMultiplier, isNewUser, (PlayerData)player.Data, p.CloseAndGetBytes(), count)); } }