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

Commit 7ea0a75

Browse files
Remove all statics from WebClient
1 parent edd1f8b commit 7ea0a75

7 files changed

Lines changed: 36 additions & 36 deletions

File tree

Scripts/Msc/UIPopupCreateLobby.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private async void _on_Create_pressed()
104104
NetworkManager.StartServer(port, ValidatedMaxPlayerCount);
105105

106106
var dummyClient = new ENetClient();
107-
dummyClient.Start(WebClient.ExternalIp, port);
107+
dummyClient.Start(NetworkManager.WebClient.ExternalIp, port);
108108
int attempts = 100;
109109
while (!dummyClient.IsConnected)
110110
{
@@ -124,7 +124,7 @@ private async void _on_Create_pressed()
124124
NetworkManager.StartClient(localIp, port);
125125

126126
SceneGameServersScript.AddServer(info);
127-
if (WebClient.ConnectionAlive)
127+
if (NetworkManager.WebClient.ConnectionAlive)
128128
SceneGameServersScript.PostServer(info);
129129

130130
await SceneGameServersScript.ClientConnect(async () => {

Scripts/Msc/UIPopupReportBug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private async void _on_Send_pressed()
2222
if (string.IsNullOrWhiteSpace(Description.Text))
2323
return;
2424

25-
await WebClient.PostError(Error.Text, Description.Text);
25+
await NetworkManager.WebClient.PostError(Error.Text, Description.Text);
2626
}
2727
}
2828
}

Scripts/Netcode/Common/Utils/WebClient.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace GodotModules.Netcode
88
{
99
public class WebClient : IDisposable
1010
{
11-
public static HttpClient Client { get; set; }
12-
public static bool ConnectionAlive { get; set; }
13-
public static Task<WebServerResponse<LobbyListing[]>> TaskGetServers => WebClient.Get<LobbyListing[]>("servers/get");
14-
public static string ExternalIp { get; set; }
15-
private static int FailedPingAttempts { get; set; }
16-
public static string WEB_SERVER_IP = "localhost:4000";
11+
public HttpClient Client { get; set; }
12+
public bool ConnectionAlive { get; set; }
13+
public Task<WebServerResponse<LobbyListing[]>> TaskGetServers => Get<LobbyListing[]>("servers/get");
14+
public string ExternalIp { get; set; }
15+
private int FailedPingAttempts { get; set; }
16+
public string WEB_SERVER_IP = "localhost:4000";
1717
private const int WEB_PING_INTERVAL = 10000;
18-
private static bool LogExceptions = false;
19-
public static Timer TimerPingMasterServer { get; set; }
18+
private bool LogExceptions = false;
19+
public Timer TimerPingMasterServer { get; set; }
2020

2121
public WebClient()
2222
{
@@ -46,21 +46,21 @@ public WebClient()
4646
}
4747
}
4848

49-
public async static Task<WebServerResponse<string>> PostError(string errorText, string errorDescription)
49+
public async Task<WebServerResponse<string>> PostError(string errorText, string errorDescription)
5050
=> await PostAsync("errors/post", new Dictionary<string, string> {
5151
{ "error", errorText },
5252
{ "description", errorDescription }
5353
});
5454

55-
public async static Task<WebServerResponse<string>> RemoveLobbyAsync() => await PostAsync("server/remove", DataExternalIp);
55+
public async Task<WebServerResponse<string>> RemoveLobbyAsync() => await PostAsync("server/remove", DataExternalIp);
5656

57-
public async static Task<WebServerResponse<string>> RemoveLobbyPlayerAsync() => await PostAsync("servers/players/remove", DataExternalIp);
57+
public async Task<WebServerResponse<string>> RemoveLobbyPlayerAsync() => await PostAsync("servers/players/remove", DataExternalIp);
5858

59-
public async static Task<WebServerResponse<string>> AddLobbyPlayerAsync() => await PostAsync("servers/players/add", DataExternalIp);
59+
public async Task<WebServerResponse<string>> AddLobbyPlayerAsync() => await PostAsync("servers/players/add", DataExternalIp);
6060

61-
private static Dictionary<string, string> DataExternalIp => new() { { "Ip", ExternalIp } };
61+
private Dictionary<string, string> DataExternalIp => new() { { "Ip", ExternalIp } };
6262

63-
public async static Task<WebServerResponse<string>> AddLobbyAsync(LobbyListing info)
63+
public async Task<WebServerResponse<string>> AddLobbyAsync(LobbyListing info)
6464
{
6565
var values = new Dictionary<string, string>
6666
{
@@ -75,7 +75,7 @@ public async static Task<WebServerResponse<string>> AddLobbyAsync(LobbyListing i
7575
return await PostAsync("servers/add", values);
7676
}
7777

78-
private async static Task<WebServerResponse<string>> PostAsync(string path, Dictionary<string, string> values = null)
78+
private async Task<WebServerResponse<string>> PostAsync(string path, Dictionary<string, string> values = null)
7979
{
8080
if (!ConnectionAlive)
8181
return new() { Status = WebServerStatus.OFFLINE };
@@ -106,7 +106,7 @@ private async static Task<WebServerResponse<string>> PostAsync(string path, Dict
106106
}
107107
}
108108

109-
public static async Task UpdateIsAlive()
109+
public async Task UpdateIsAlive()
110110
{
111111
try
112112
{
@@ -120,7 +120,7 @@ public static async Task UpdateIsAlive()
120120
}
121121
}
122122

123-
public static async Task<WebServerResponse<T>> Get<T>(string path)
123+
public async Task<WebServerResponse<T>> Get<T>(string path)
124124
{
125125
if (!ConnectionAlive)
126126
return new() { Status = WebServerStatus.OFFLINE };
@@ -153,7 +153,7 @@ public static async Task<WebServerResponse<T>> Get<T>(string path)
153153

154154
public async void OnTimerPingMasterServerEvent(System.Object source, ElapsedEventArgs args)
155155
{
156-
var res = await WebClient.PostAsync("servers/ping", new Dictionary<string, string> { { "Name", NetworkManager.CurrentLobby.Name } });
156+
var res = await PostAsync("servers/ping", new Dictionary<string, string> { { "Name", NetworkManager.CurrentLobby.Name } });
157157
if (res.Status == WebServerStatus.ERROR)
158158
{
159159
FailedPingAttempts++;

Scripts/Scenes/Game Servers/SceneGameServers.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ public override async void _Ready()
6262
GameManager.SpawnPopupMessage(message);
6363
}
6464

65-
await WebClient.UpdateIsAlive();
65+
await NetworkManager.WebClient.UpdateIsAlive();
6666

67-
if (WebClient.ConnectionAlive)
67+
if (NetworkManager.WebClient.ConnectionAlive)
6868
await ListServers();
6969
}
7070

7171
public override void _Input(InputEvent @event)
7272
{
7373
SceneManager.EscapePressed(async () =>
7474
{
75-
WebClient.Client.CancelPendingRequests();
75+
NetworkManager.WebClient.Client.CancelPendingRequests();
7676

7777
if (NetworkManager.GameClient != null)
7878
NetworkManager.GameClient.Stop();
@@ -122,7 +122,7 @@ public async Task ListServers()
122122
GettingServers = true;
123123
UIGameServersNavBtns.BtnRefresh.Disabled = true;
124124

125-
var res = await WebClient.TaskGetServers;
125+
var res = await NetworkManager.WebClient.TaskGetServers;
126126

127127
if (!SceneManager.InGameServers())
128128
return;
@@ -197,7 +197,7 @@ public async Task ListServers()
197197

198198
public async void PostServer(LobbyListing info)
199199
{
200-
await WebClient.AddLobbyAsync(info);
200+
await NetworkManager.WebClient.AddLobbyAsync(info);
201201
}
202202

203203
private void _on_Control_resized()

Scripts/Scenes/Game Servers/UIGameServersNavBtns.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private async void _on_Refresh_pressed()
4343

4444
SceneGameServersScript.ClearServers();
4545

46-
if (WebClient.ConnectionAlive)
46+
if (NetworkManager.WebClient.ConnectionAlive)
4747
await SceneGameServersScript.ListServers();
4848
}
4949

Scripts/Scenes/Lobby/SceneLobby.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public override async void _Input(InputEvent @event)
6060

6161
if (NetworkManager.IsHost)
6262
{
63-
WebClient.Client.CancelPendingRequests();
64-
WebClient.TimerPingMasterServer.Stop();
63+
NetworkManager.WebClient.Client.CancelPendingRequests();
64+
NetworkManager.WebClient.TimerPingMasterServer.Stop();
6565

6666
if (NetworkManager.GameServer != null)
6767
NetworkManager.GameServer.Stop();
6868

6969
NetworkManager.IsHost = false;
7070

71-
await WebClient.RemoveLobbyAsync();
71+
await NetworkManager.WebClient.RemoveLobbyAsync();
7272
}
7373
}
7474
}
@@ -82,12 +82,12 @@ private async void TimerCountdownCallback()
8282

8383
if (NetworkManager.IsHost)
8484
{
85-
WebClient.TimerPingMasterServer.Stop();
85+
NetworkManager.WebClient.TimerPingMasterServer.Stop();
8686

8787
// tell everyone game has started
8888
await NetworkManager.GameClient.Send(ClientPacketOpcode.Lobby, new CPacketLobby(LobbyOpcode.LobbyGameStart));
8989

90-
await WebClient.RemoveLobbyAsync();
90+
await NetworkManager.WebClient.RemoveLobbyAsync();
9191
}
9292
}
9393
}
@@ -107,7 +107,7 @@ public async void AddPlayer(uint id, string name)
107107
player.SetId(id);
108108

109109
if (NetworkManager.IsHost)
110-
await WebClient.AddLobbyPlayerAsync();
110+
await NetworkManager.WebClient.AddLobbyPlayerAsync();
111111
}
112112

113113
public async void RemovePlayer(uint id)
@@ -120,7 +120,7 @@ public async void RemovePlayer(uint id)
120120
UIPlayers.Remove(id);
121121

122122
if (NetworkManager.IsHost)
123-
await WebClient.RemoveLobbyPlayerAsync();
123+
await NetworkManager.WebClient.RemoveLobbyPlayerAsync();
124124
}
125125

126126
public void SetReady(uint id, bool ready)

Scripts/Scenes/Menu/UIOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void SetupUI()
4949
SliderSFX.Value = Options.VolumeSFX;
5050
VSync.Pressed = Options.VSync;
5151
InputUsername.Text = Options.OnlineUsername;
52-
InputWebServer.Text = WebClient.WEB_SERVER_IP;
52+
InputWebServer.Text = NetworkManager.WebClient.WEB_SERVER_IP;
5353
}
5454

5555
private void SetupFullscreenOptions()
@@ -107,7 +107,7 @@ private void _on_OnlineUsername_text_changed(string text)
107107

108108
private void _on_WebServerIp_text_changed(string text)
109109
{
110-
WebClient.WEB_SERVER_IP = text;
110+
NetworkManager.WebClient.WEB_SERVER_IP = text;
111111
}
112112
}
113113
}

0 commit comments

Comments
 (0)