CSharpRedotTools / Multiplayer-2023-Old

Client + server template
MIT License
8 stars 2 forks source link

Creating more than 1 client in an assembly causes frequent crashes and weirdness with packet data #1

Closed valkyrienyanko closed 1 year ago

valkyrienyanko commented 1 year ago

If I have 2 clients and 1 server all running in the same assembly. The server receives client A and client B peer Ids as the same value (like both 0 or both 1). This happens 80% of the time. This also crashed my game 50% of the time with no errors to the console.

If I have 1 client and 1 server in assembly A and then 1 client in assembly B. Then it works completely fine!

Why is this? I want to be able to create dummy test clients in the same assembly but I can't because of this weirdness.

valkyrienyanko commented 1 year ago

For example

for (int i = 0; i < 2; i++)
{
  var client = new GameClient();
  client.Connect("localhost", 25565);

  while(!client.IsConnected)
    await Task.Delay(1);

  client.Send(new CPacketPlayerJoin { Username = "Fred" });
}
valkyrienyanko commented 1 year ago

probably because they are using the same godot thread when they really need a separate godot thread for each client thread