Displaying the names of the connected players in the server lobby
This commit is contained in:
@@ -546,16 +546,23 @@ namespace Barotrauma.Networking
|
|||||||
if (connectionStatus == NetConnectionStatus.Disconnected)
|
if (connectionStatus == NetConnectionStatus.Disconnected)
|
||||||
{
|
{
|
||||||
string disconnectMsg = inc.ReadString();
|
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");
|
case "The server has been shut down":
|
||||||
msgBox.Buttons[0].OnClicked += ReturnToServerList;
|
case "You have been banned from the server":
|
||||||
}
|
case "You have been kicked from the server":
|
||||||
else if (reconnectBox == null)
|
var msgBox = new GUIMessageBox("CONNECTION LOST", disconnectMsg);
|
||||||
{
|
msgBox.Buttons[0].OnClicked += ReturnToServerList;
|
||||||
reconnectBox = new GUIMessageBox("CONNECTION LOST", "You have been disconnected from the server. Reconnecting...", new string[0]);
|
break;
|
||||||
connected = false;
|
default:
|
||||||
ConnectToServer(serverIP);
|
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();
|
string levelSeed = inc.ReadString();
|
||||||
|
|
||||||
bool autoRestartEnabled = inc.ReadBoolean();
|
bool autoRestartEnabled = inc.ReadBoolean();
|
||||||
float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f;
|
float autoRestartTimer = autoRestartEnabled ? inc.ReadFloat() : 0.0f;
|
||||||
|
|
||||||
|
int clientCount = inc.ReadByte();
|
||||||
|
List<string> clientNames = new List<string>();
|
||||||
|
for (int i = 0; i < clientCount; i++)
|
||||||
|
{
|
||||||
|
clientNames.Add(inc.ReadString());
|
||||||
|
}
|
||||||
|
|
||||||
//ignore the message if we already a more up-to-date one
|
//ignore the message if we already a more up-to-date one
|
||||||
if (updateID > GameMain.NetLobbyScreen.LastUpdateID)
|
if (updateID > GameMain.NetLobbyScreen.LastUpdateID)
|
||||||
@@ -764,6 +778,12 @@ namespace Barotrauma.Networking
|
|||||||
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
|
GameMain.NetLobbyScreen.LevelSeed = levelSeed;
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
|
GameMain.NetLobbyScreen.SetAutoRestart(autoRestartEnabled, autoRestartTimer);
|
||||||
|
|
||||||
|
GameMain.NetLobbyScreen.ClearPlayers();
|
||||||
|
foreach (string clientName in clientNames)
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.AddPlayer(clientName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastSentChatMsgID = inc.ReadUInt32();
|
lastSentChatMsgID = inc.ReadUInt32();
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Barotrauma.Networking
|
|||||||
config.SimulatedDuplicatesChance = 0.05f;
|
config.SimulatedDuplicatesChance = 0.05f;
|
||||||
config.SimulatedMinimumLatency = 0.1f;
|
config.SimulatedMinimumLatency = 0.1f;
|
||||||
|
|
||||||
config.ConnectionTimeout = 60.0f;
|
config.ConnectionTimeout = 5.0f;
|
||||||
#endif
|
#endif
|
||||||
config.Port = port;
|
config.Port = port;
|
||||||
Port = port;
|
Port = port;
|
||||||
@@ -690,7 +690,6 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -811,6 +810,12 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
outmsg.Write(AutoRestartTimer);
|
outmsg.Write(AutoRestartTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outmsg.Write((byte)connectedClients.Count);
|
||||||
|
foreach (Client client in connectedClients)
|
||||||
|
{
|
||||||
|
outmsg.Write(client.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1270,7 +1275,6 @@ namespace Barotrauma.Networking
|
|||||||
client.Connection.Disconnect(targetmsg);
|
client.Connection.Disconnect(targetmsg);
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.RemovePlayer(client.name);
|
GameMain.NetLobbyScreen.RemovePlayer(client.name);
|
||||||
|
|
||||||
connectedClients.Remove(client);
|
connectedClients.Remove(client);
|
||||||
|
|
||||||
AddChatMessage(msg, ChatMessageType.Server);
|
AddChatMessage(msg, ChatMessageType.Server);
|
||||||
|
|||||||
@@ -202,6 +202,8 @@ namespace Barotrauma.Networking
|
|||||||
unauthClient = null;
|
unauthClient = null;
|
||||||
ConnectedClients.Add(newClient);
|
ConnectedClients.Add(newClient);
|
||||||
|
|
||||||
|
GameMain.NetLobbyScreen.AddPlayer(newClient.name);
|
||||||
|
|
||||||
AddChatMessage(clName+" has joined the server.", ChatMessageType.Server);
|
AddChatMessage(clName+" has joined the server.", ChatMessageType.Server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -780,6 +780,8 @@ namespace Barotrauma
|
|||||||
|
|
||||||
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
|
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)
|
public void RemovePlayer(string name)
|
||||||
@@ -787,6 +789,8 @@ namespace Barotrauma
|
|||||||
GUIComponent child = playerList.children.Find(c => c.UserData as string == name);
|
GUIComponent child = playerList.children.Find(c => c.UserData as string == name);
|
||||||
|
|
||||||
if (child != null) playerList.RemoveChild(child);
|
if (child != null) playerList.RemoveChild(child);
|
||||||
|
|
||||||
|
if (GameMain.Server != null) lastUpdateID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SelectPlayer(GUIComponent component, object obj)
|
private bool SelectPlayer(GUIComponent component, object obj)
|
||||||
@@ -946,6 +950,8 @@ namespace Barotrauma
|
|||||||
public void ClearPlayers()
|
public void ClearPlayers()
|
||||||
{
|
{
|
||||||
playerList.ClearChildren();
|
playerList.ClearChildren();
|
||||||
|
|
||||||
|
if (GameMain.Server != null) lastUpdateID++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void AddToGUIUpdateList()
|
public override void AddToGUIUpdateList()
|
||||||
|
|||||||
Reference in New Issue
Block a user