Store handShakeComplete only after the player has been added to the player list.

This prevents a race condition between reconnecting and being added to the list.

Should fix #999
This commit is contained in:
IntegratedQuantum 2025-02-02 21:13:57 +01:00
parent a0365dabd9
commit 9be4ff1047
2 changed files with 2 additions and 2 deletions

View File

@ -637,7 +637,7 @@ pub const Protocols = struct {
const stepUserData: u8 = 1;
const stepAssets: u8 = 2;
const stepServerData: u8 = 3;
const stepComplete: u8 = 255;
pub const stepComplete: u8 = 255;
fn receive(conn: *Connection, data: []const u8) !void {
if(conn.handShakeState.load(.monotonic) < data[0]) {
@ -678,7 +678,6 @@ pub const Protocols = struct {
conn.flush();
conn.mutex.unlock();
conn.handShakeState.store(stepServerData, .monotonic);
conn.handShakeState.store(stepComplete, .monotonic);
main.server.connect(conn.user.?);
},
stepAssets => {

View File

@ -471,6 +471,7 @@ pub fn connectInternal(user: *User) void {
userMutex.lock();
users.append(user);
userMutex.unlock();
user.conn.handShakeState.store(main.network.Protocols.handShake.stepComplete, .monotonic);
}
pub fn messageFrom(msg: []const u8, source: *User) void { // MARK: message