From 05c588026975c3d1357e21544edf406f7c077478 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 1 Feb 2017 18:10:48 +0200 Subject: [PATCH] Displaying the names of the connected players in the server lobby --- Subsurface/Source/Networking/GameClient.cs | 42 ++++++++++++++----- Subsurface/Source/Networking/GameServer.cs | 14 ++++--- .../Source/Networking/GameServerLogin.cs | 2 + Subsurface/Source/Screens/NetLobbyScreen.cs | 8 +++- 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 11bdc3ca8..fb3106632 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -546,16 +546,23 @@ namespace Barotrauma.Networking if (connectionStatus == NetConnectionStatus.Disconnected) { string disconnectMsg = inc.ReadString(); - if (disconnectMsg == "The server has been shut down") + + switch (disconnectMsg) { - var msgBox = new GUIMessageBox("CONNECTION LOST", "The server has been shut down"); - msgBox.Buttons[0].OnClicked += ReturnToServerList; - } - else if (reconnectBox == null) - { - reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]); - connected = false; - ConnectToServer(serverIP); + case "The server has been shut down": + case "You have been banned from the server": + case "You have been kicked from the server": + var msgBox = new GUIMessageBox("CONNECTION LOST", disconnectMsg); + msgBox.Buttons[0].OnClicked += ReturnToServerList; + break; + default: + reconnectBox = new GUIMessageBox( + "CONNECTION LOST", + "You have been disconnected from the server. Reconnecting...", new string[0]); + + connected = false; + ConnectToServer(serverIP); + break; } } @@ -743,8 +750,15 @@ namespace Barotrauma.Networking string levelSeed = inc.ReadString(); - bool autoRestartEnabled = inc.ReadBoolean(); - float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f; + bool autoRestartEnabled = inc.ReadBoolean(); + float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f; + + int clientCount = inc.ReadByte(); + List clientNames = new List(); + for (int i = 0; i < clientCount; i++) + { + clientNames.Add(inc.ReadString()); + } //ignore the message if we already a more up-to-date one if (updateID > GameMain.NetLobbyScreen.LastUpdateID) @@ -764,6 +778,12 @@ namespace Barotrauma.Networking GameMain.NetLobbyScreen.LevelSeed = levelSeed; GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer); + + GameMain.NetLobbyScreen.ClearPlayers(); + foreach (string clientName in clientNames) + { + GameMain.NetLobbyScreen.AddPlayer(clientName); + } } } lastSentChatMsgID = inc.ReadUInt32(); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 3aa5d7c8d..8e573199b 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -77,7 +77,7 @@ namespace Barotrauma.Networking config.SimulatedDuplicatesChance = 0.05f; config.SimulatedMinimumLatency = 0.1f; - config.ConnectionTimeout = 60.0f; + config.ConnectionTimeout = 5.0f; #endif config.Port = port; Port = port; @@ -504,7 +504,7 @@ namespace Barotrauma.Networking } } } - + updateTimer = DateTime.Now + updateInterval; } @@ -690,7 +690,6 @@ namespace Barotrauma.Networking break; default: return; - //break; } } } @@ -811,6 +810,12 @@ namespace Barotrauma.Networking { outmsg.Write(AutoRestartTimer); } + + outmsg.Write((byte)connectedClients.Count); + foreach (Client client in connectedClients) + { + outmsg.Write(client.name); + } } else { @@ -1269,8 +1274,7 @@ namespace Barotrauma.Networking client.Connection.Disconnect(targetmsg); - GameMain.NetLobbyScreen.RemovePlayer(client.name); - + GameMain.NetLobbyScreen.RemovePlayer(client.name); connectedClients.Remove(client); AddChatMessage(msg, ChatMessageType.Server); diff --git a/Subsurface/Source/Networking/GameServerLogin.cs b/Subsurface/Source/Networking/GameServerLogin.cs index ae4ccdae3..ef460f968 100644 --- a/Subsurface/Source/Networking/GameServerLogin.cs +++ b/Subsurface/Source/Networking/GameServerLogin.cs @@ -202,6 +202,8 @@ namespace Barotrauma.Networking unauthClient = null; ConnectedClients.Add(newClient); + GameMain.NetLobbyScreen.AddPlayer(newClient.name); + AddChatMessage(clName+" has joined the server.", ChatMessageType.Server); } } diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index aaa241141..6b45badf9 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -779,7 +779,9 @@ namespace Barotrauma playerList); textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f); - textBlock.UserData = name; + textBlock.UserData = name; + + if (GameMain.Server != null) lastUpdateID++; } public void RemovePlayer(string name) @@ -787,6 +789,8 @@ namespace Barotrauma GUIComponent child = playerList.children.Find(c => c.UserData as string == name); if (child != null) playerList.RemoveChild(child); + + if (GameMain.Server != null) lastUpdateID++; } private bool SelectPlayer(GUIComponent component, object obj) @@ -946,6 +950,8 @@ namespace Barotrauma public void ClearPlayers() { playerList.ClearChildren(); + + if (GameMain.Server != null) lastUpdateID++; } public override void AddToGUIUpdateList()