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

Commit bc16a9c

Browse files
Fix #71
1 parent 94fa2da commit bc16a9c

8 files changed

Lines changed: 13 additions & 40 deletions

File tree

Scripts/Netcode/Client/ENetClient.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace GodotModules.Netcode.Client
1010
{
11-
public class ENetClient : IDisposable
11+
public class ENetClient
1212
{
1313
public static readonly Dictionary<ServerPacketOpcode, APacketServer> HandlePacket = ReflectionUtils.LoadInstances<ServerPacketOpcode, APacketServer>("SPacket");
1414

@@ -73,8 +73,6 @@ public async void Start(string ip, ushort port)
7373
/// </summary>
7474
public void Stop() => ENetCmds.Enqueue(new ENetCmd(ENetOpcode.ClientWantsToDisconnect));
7575

76-
public void CancelTask() => ENetCmds.Enqueue(new ENetCmd(ENetOpcode.CancelTask));
77-
7876
public void Log(object obj) => Logger.Log($"[Client]: {obj}", ConsoleColor.Yellow);
7977

8078
/// <summary>
@@ -135,9 +133,6 @@ private async Task ENetThreadWorker(string ip, ushort port)
135133
case ENetOpcode.ClientWantsToDisconnect:
136134
peer.Disconnect(0);
137135
break;
138-
case ENetOpcode.CancelTask:
139-
CancelTokenSource.Cancel();
140-
break;
141136
}
142137
}
143138

@@ -211,11 +206,6 @@ private async Task ENetThreadWorker(string ip, ushort port)
211206
}
212207

213208
private bool ConcurrentQueuesWorking() => ENetCmds.Count != 0 || Outgoing.Count != 0;
214-
215-
public void Dispose()
216-
{
217-
CancelTokenSource.Dispose();
218-
}
219209
}
220210

221211
public struct PacketHandleData

Scripts/Netcode/Client/GameClient.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class GameClient : ENetClient
66
{
77
public static bool ConnectingToLobby { get; set; }
88
public static bool Disconnected { get; set; }
9-
9+
1010
public Dictionary<uint, string> Players { get; set; }
1111

1212
public GameClient()
@@ -38,7 +38,10 @@ private void HandlePeerLeave(DisconnectOpcode opcode)
3838
Connected = 0;
3939
NetworkManager.GodotCmds.Enqueue(new GodotCmd(GodotOpcode.Disconnect, opcode));
4040
if (CancelTokenSource != null)
41+
{
4142
CancelTokenSource.Cancel();
43+
CancelTokenSource.Dispose();
44+
}
4245
}
4346
}
4447
}

Scripts/Netcode/Common/_Opcodes.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ public enum ENetOpcode
115115
StopServer,
116116
RestartServer,
117117
ClientWantsToExitApp,
118-
ClientWantsToDisconnect,
119-
CancelTask,
120-
Dispose
118+
ClientWantsToDisconnect
121119
}
122120
}

Scripts/Netcode/Server/ENetServer.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace GodotModules.Netcode.Server
99
{
10-
public abstract class ENetServer : IDisposable
10+
public abstract class ENetServer
1111
{
1212
public bool HasSomeoneConnected { get => Interlocked.Read(ref SomeoneConnected) == 1; }
1313
public bool IsRunning { get => Interlocked.Read(ref Running) == 1; }
@@ -261,8 +261,5 @@ private void Send(ServerPacket gamePacket, Peer peer)
261261
}
262262

263263
private bool ConcurrentQueuesWorking() => ENetCmds.Count != 0 || Outgoing.Count != 0;
264-
265-
public virtual void Dispose()
266-
{ }
267264
}
268265
}

Scripts/Netcode/Server/GameServer.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ protected override void ServerCmds()
100100
CTS.Cancel();
101101
KickAll(DisconnectOpcode.Stopping);
102102
break;
103-
104-
case ENetOpcode.Dispose:
105-
CTS.Dispose();
106-
EmitClientTransforms.Stop();
107-
EmitClientTransforms.Dispose();
108-
ServerSimulation.Stop();
109-
ServerSimulation.Dispose();
110-
break;
111103
}
112104
}
113105
}
@@ -128,6 +120,11 @@ protected override void Timeout(Event netEvent)
128120

129121
protected override void Stopped()
130122
{
123+
CTS.Dispose();
124+
EmitClientTransforms.Stop();
125+
EmitClientTransforms.Dispose();
126+
ServerSimulation.Stop();
127+
ServerSimulation.Dispose();
131128
}
132129

133130
private void HandlePlayerLeave(uint id)
@@ -189,11 +186,5 @@ public void SendToOtherPlayers(uint id, ServerPacketOpcode opcode, APacket data
189186
else
190187
Send(opcode, data, flags, otherPlayers);
191188
}
192-
193-
public override void Dispose()
194-
{
195-
base.Dispose();
196-
ENetCmds.Enqueue(new ENetCmd(ENetOpcode.Dispose));
197-
}
198189
}
199190
}

Scripts/Scenes/Game Servers/SceneGameServers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override void _Input(InputEvent @event)
7575
WebClient.Client.CancelPendingRequests();
7676

7777
if (NetworkManager.GameClient != null)
78-
NetworkManager.GameClient.CancelTask();
78+
NetworkManager.GameClient.Stop();
7979

8080
await SceneManager.ChangeScene("Menu");
8181
});

Scripts/Scenes/Main/GameManager.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private static async Task ExitCleanup()
4848
if (NetworkManager.GameServer.IsRunning)
4949
{
5050
NetworkManager.GameServer.ENetCmds.Enqueue(new ENetCmd(ENetOpcode.ClientWantsToExitApp));
51-
NetworkManager.GameServer.Dispose();
5251
NetworkManager.GameServer.Stop();
5352

5453
while (NetworkManager.GameServer.IsRunning)
@@ -61,7 +60,6 @@ private static async Task ExitCleanup()
6160
if (NetworkManager.GameClient != null)
6261
if (NetworkManager.GameClient.IsRunning)
6362
{
64-
NetworkManager.GameClient.Dispose();
6563
NetworkManager.GameClient.Stop();
6664

6765
while (NetworkManager.GameClient.IsRunning)

Scripts/Scenes/Main/NetworkManager.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,12 @@ public override async void _Process(float delta)
108108

109109
public static void StartClient(string ip, ushort port)
110110
{
111-
if (GameClient != null)
112-
GameClient.Dispose();
113111
GameClient = new GameClient();
114112
GameClient.Start(ip, port);
115113
}
116114

117115
public static async void StartServer(ushort port, int maxClients)
118116
{
119-
if (GameServer != null)
120-
GameServer.Dispose();
121117
GameServer = new GameServer();
122118
await GameServer.Start(port, maxClients);
123119
}

0 commit comments

Comments
 (0)