Closed valkyrienyanko closed 2 months ago
I found out the reason this is happening.
client.OnDisconnected += opcode =>
{
Game.SceneManager.ResetCurrentScene();
};
The entire scene is reset when client disconnects. So of course the server will reset but still remain active since its running on a separate thread.
I need to find a way to reset the entire scene without resetting the game server thread.
client.OnDisconnected += opcode =>
{
// The entire scene cannot be reset here because this will also reset the
// instance stored for both GameServer and GameClient. These run on separate
// threads, so resetting them here won't stop them on the other threads. Not
// to mention they shouldn't be reset in the first place! So this is why the
// entire scene is no longer reset when the client disconnects.
// See https://github.com/ValksGodotTools/Template/issues/20 for more info
// about this.
Player.QueueFree();
OtherPlayers.Values.ForEach(x => x.QueueFree());
};
This will be the solution for now. I will just have to remember to reset or QueueFree() anything in the future in this area.
https://github.com/user-attachments/assets/2c28e2d1-76e4-4664-ae0f-0b920ff71d91
Steps to Reproduce:
res://2D Top Down/level_2D_top_down.tscn
Observation
For some reason when the client disconnects and sets
_running = 0
for the client, it also sets_running = 0
for the server. This can be seen when running the following console command after the client disconnects.Relevant Code
https://github.com/ValksGodotTools/Template/blob/17f1637bf362016b6a3ac4e84fc5679fd8881773/Scripts/UI/UINetControlPanel.cs#L22
https://github.com/ValksGodotTools/Template/blob/17f1637bf362016b6a3ac4e84fc5679fd8881773/Scripts/UI/UINetControlPanel.cs#L19
https://github.com/ValksGodotTools/Template/blob/a67b9a0b848cb9aaad2f3d044183e254e2eedf6e/Template/Scripts/Netcode/ENetClient.cs#L44-L53
https://github.com/ValksGodotTools/Template/blob/a67b9a0b848cb9aaad2f3d044183e254e2eedf6e/Template/Scripts/Netcode/ENetServer.cs#L26-L47
https://github.com/ValksGodotTools/Template/blob/a67b9a0b848cb9aaad2f3d044183e254e2eedf6e/Template/Scripts/Netcode/ENetLow.cs#L90