From fc327299b4011c4427e6075c519fa64e4d689875 Mon Sep 17 00:00:00 2001 From: p2r3 Date: Thu, 28 Aug 2025 02:27:04 +0300 Subject: [PATCH] don't send gameplay packets to clients who haven't loaded in --- src/main.c | 2 ++ src/packets.c | 1 + src/procedures.c | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 5ba55fe..83a6712 100644 --- a/src/main.c +++ b/src/main.c @@ -103,6 +103,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { // information about the joining player to all existing players. for (int i = 0; i < MAX_PLAYERS; i ++) { if (player_data[i].client_fd == -1) continue; + if (player_data[i].flags & 0x20) continue; sc_playerInfoUpdateAddPlayer(client_fd, player_data[i]); sc_systemChat(player_data[i].client_fd, join_message, 16 + player_name_len); if (player_data[i].client_fd == client_fd) continue; @@ -221,6 +222,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { // Send current position data to all connected players for (int i = 0; i < MAX_PLAYERS; i ++) { if (player_data[i].client_fd == -1) continue; + if (player_data[i].flags & 0x20) continue; if (player_data[i].client_fd == client_fd) continue; if (packet_id == 0x1F) { sc_updateEntityRotation(player_data[i].client_fd, client_fd, player->yaw, player->pitch); diff --git a/src/packets.c b/src/packets.c index 9b9392f..627d849 100644 --- a/src/packets.c +++ b/src/packets.c @@ -1010,6 +1010,7 @@ int cs_chat (int client_fd) { // Forward message to all connected players for (int i = 0; i < MAX_PLAYERS; i ++) { if (player_data[i].client_fd == -1) continue; + if (player_data[i].flags & 0x20) continue; sc_systemChat(player_data[i].client_fd, (char *)recv_buffer, message_len + name_len + 3); } diff --git a/src/procedures.c b/src/procedures.c index 9101bfd..985b07e 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -68,6 +68,7 @@ int reservePlayerData (int client_fd, uint8_t *uuid, char *name) { for (int i = 0; i < MAX_PLAYERS; i ++) { if (memcmp(player_data[i].uuid, uuid, 16) == 0) { player_data[i].client_fd = client_fd; + player_data[i].flags |= 0x20; memcpy(player_data[i].name, name, 16); return 0; } @@ -81,6 +82,7 @@ int reservePlayerData (int client_fd, uint8_t *uuid, char *name) { if (empty) { if (player_data_count >= MAX_PLAYERS) return 1; player_data[i].client_fd = client_fd; + player_data[i].flags |= 0x20; memcpy(player_data[i].uuid, uuid, 16); memcpy(player_data[i].name, name, 16); resetPlayerData(&player_data[i]); @@ -253,7 +255,7 @@ void spawnPlayer (PlayerData *player) { sc_updateTime(player->client_fd, world_time); // Give the player flight (for testing) - sc_playerAbilities(player->client_fd, 0x04); + // sc_playerAbilities(player->client_fd, 0x04); // Calculate player's chunk coordinates short _x = div_floor(player->x, 16), _z = div_floor(player->z, 16); @@ -276,6 +278,9 @@ void spawnPlayer (PlayerData *player) { // Re-teleport player after all chunks have been sent sc_synchronizePlayerPosition(player->client_fd, spawn_x, spawn_y, spawn_z, spawn_yaw, spawn_pitch); + // Flag player as fully loaded + player->flags &= ~0x20; + task_yield(); // Check task timer between packets } @@ -297,6 +302,7 @@ void makeBlockChange (short x, uint8_t y, short z, uint8_t block) { // Transmit block update to all in-game clients for (int i = 0; i < MAX_PLAYERS; i ++) { if (player_data[i].client_fd == -1) continue; + if (player_data[i].flags & 0x20) continue; if (getClientState(player_data[i].client_fd) != STATE_PLAY) continue; sc_blockUpdate(player_data[i].client_fd, x, y, z, block); }