SamTheBlow / grand-strategy-game

A grand strategy game made in Godot.
MIT License
7 stars 4 forks source link

Networking: in lobby, second user doesn't know about third user #192

Closed SamTheBlow closed 3 months ago

SamTheBlow commented 3 months ago

Happens in both 4.0.1 and latest commit. Run three instances of the game. While in the lobby, start a server on one of them, then have the other ones join. The second user is seemingly unaware of the third user joining (doesn't appear in lobby, and when the game starts, doesn't appear in the turn order). Note that if the server starts the game before the other users join, then this problem does not occur.

This is a major problem!

SamTheBlow commented 3 months ago

Also happens in 4.0.0 Wouldn't be surprised if this bug's been around from the beginning and I just never noticed

SamTheBlow commented 3 months ago

More generally, when a 4th user joins, the 2nd and 3rd users aren't aware of the 4th user In other words, any user who isn't the host is not informed of new users joining (only in the lobby)

SamTheBlow commented 3 months ago

This commented out function ("_send_new_player_to_clients") doesn't exist... I guess I'll have to make it exist xd But, this still doesn't explain why it works after the game's started

https://github.com/SamTheBlow/grand-strategy-game/blob/fb901eeb4860648bc3d0eec0e1d2ca32f9d5c6ba/project/scripts/players/players.gd#L33-L42

SamTheBlow commented 3 months ago

Okay, here's the cause of the bug: https://github.com/SamTheBlow/grand-strategy-game/blob/fb901eeb4860648bc3d0eec0e1d2ca32f9d5c6ba/project/scripts/main.gd#L233-L244 When a player is added on the server, this function is called in main.gd. The code quite literally says "if not game: return". That explains why it only works in-game. This code is an ugly workaround that I wrote to pass some data to the game when a player joins. But, I did not consider the case of when we're not in a game. This should be easy to fix now.