Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit 2d5e07b

Browse files
minor changes
1 parent 06bb6a5 commit 2d5e07b

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

Scripts/Netcode/Web/WebClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public WebClient()
4444
}
4545
}
4646

47-
public async static Task<WebServerResponse<string>> Post(string path, Dictionary<string, string> values)
47+
public async static Task<WebServerResponse<string>> Post(string path, Dictionary<string, string> values = null)
4848
{
4949
try
5050
{

Scripts/Scenes/Game Servers/UILobbyListing.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void SetInfo(LobbyListing info)
3737
Info = info;
3838
LabelTitle.Text = info.Name;
3939
LabelDescription.Text = info.Description;
40-
LabelPlayerCount.Text = "" + info.MaxPlayerCount;
40+
LabelPlayerCount.Text = $"{info.Players} / {info.MaxPlayerCount}";
4141
LabelPing.Text = $"{info.Ping}ms";
4242
}
4343

@@ -68,6 +68,7 @@ public class LobbyListing
6868
public string LobbyHost { get; set; }
6969
public byte LobbyHostId { get; set; }
7070
public int MaxPlayerCount { get; set; }
71+
public int Players { get; set; }
7172
public bool Public { get; set; }
7273
}
7374
}

Scripts/Scenes/Lobby/SceneLobby.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using GodotModules.Netcode;
33
using GodotModules.Netcode.Client;
44
using GodotModules.Netcode.Server;
5+
using System.Threading.Tasks;
56

67
namespace GodotModules
78
{
@@ -54,14 +55,17 @@ public override void _Ready()
5455
LobbyMaxPlayers.Text = "" + CurrentLobby.MaxPlayerCount;
5556
}
5657

57-
public override async void _Input(InputEvent @event)
58+
public override void _Input(InputEvent @event)
5859
{
5960
if (Input.IsActionJustPressed("ui_cancel"))
6061
{
6162
if (NetworkManager.IsHost)
6263
{
63-
await WebClient.Post("servers/remove", new Dictionary<string, string> {
64-
{ "Ip", WebClient.ExternalIp }
64+
Task.Run(async () =>
65+
{
66+
await WebClient.Post("servers/remove", new Dictionary<string, string> {
67+
{ "Ip", WebClient.ExternalIp }
68+
});
6569
});
6670

6771
WebClient.Client.CancelPendingRequests();
@@ -107,6 +111,15 @@ public void AddPlayer(uint id, string name)
107111
if (UIPlayers.Duplicate(id))
108112
return;
109113

114+
if (NetworkManager.IsHost)
115+
{
116+
Task.Run(async () => {
117+
await WebClient.Post("servers/players/add", new Dictionary<string, string> {
118+
{ "Ip", WebClient.ExternalIp }
119+
});
120+
});
121+
}
122+
110123
var player = Prefabs.LobbyPlayerListing.Instance<UILobbyPlayerListing>();
111124
UIPlayers[id] = player;
112125

@@ -121,6 +134,15 @@ public void RemovePlayer(uint id)
121134
if (UIPlayers.DoesNotHave(id))
122135
return;
123136

137+
if (NetworkManager.IsHost)
138+
{
139+
Task.Run(async () => {
140+
await WebClient.Post("servers/players/remove", new Dictionary<string, string> {
141+
{ "Ip", WebClient.ExternalIp }
142+
});
143+
});
144+
}
145+
124146
var uiPlayer = UIPlayers[id];
125147
uiPlayer.QueueFree();
126148
UIPlayers.Remove(id);

Scripts/Scenes/Main/GameManager.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ private static async Task ExitCleanup()
5151
NetworkManager.GameServer.Dispose();
5252
NetworkManager.GameServer.Stop();
5353

54-
while (NetworkManager.GameServer.IsRunning)
54+
while (NetworkManager.GameServer.IsRunning)
55+
{
56+
Logger.LogDebug("Game server still running");
5557
await Task.Delay(100);
58+
}
5659
}
5760

5861
if (NetworkManager.GameClient != null)
@@ -61,8 +64,11 @@ private static async Task ExitCleanup()
6164
NetworkManager.GameClient.Dispose();
6265
NetworkManager.GameClient.Stop();
6366

64-
while (NetworkManager.GameClient.IsRunning)
67+
while (NetworkManager.GameClient.IsRunning)
68+
{
69+
Logger.LogDebug("Game client still running");
6570
await Task.Delay(100);
71+
}
6672
}
6773

6874
UtilOptions.SaveOptions();

0 commit comments

Comments
 (0)