handle player loading flag more cautiously

This commit is contained in:
p2r3
2025-08-29 23:33:25 +03:00
parent b2d0908879
commit 849adf0568
3 changed files with 18 additions and 3 deletions

View File

@@ -137,7 +137,7 @@ typedef struct {
// 0x04 - sneaking // 0x04 - sneaking
// 0x08 - sprinting // 0x08 - sprinting
// 0x10 - eating, makes flagval_16 act as eating timer // 0x10 - eating, makes flagval_16 act as eating timer
// 0x20 - client not fully loaded // 0x20 - client loading, uses flagval_16 as fallback timer
uint8_t flags; uint8_t flags;
} PlayerData; } PlayerData;

View File

@@ -382,6 +382,14 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
if (state == STATE_PLAY) cs_playerInput(client_fd); if (state == STATE_PLAY) cs_playerInput(client_fd);
break; break;
case 0x2B: // Player Loaded
PlayerData *player;
if (getPlayerData(client_fd, &player)) break;
// Clear "client loading" flag and fallback timer
player->flags &= ~0x20;
player->flagval_16 = 0;
break;
case 0x34: case 0x34:
if (state == STATE_PLAY) cs_setHeldItem(client_fd); if (state == STATE_PLAY) cs_setHeldItem(client_fd);
break; break;

View File

@@ -1145,8 +1145,15 @@ void handleServerTick (int64_t time_since_last_tick) {
// Update player events // Update player events
for (int i = 0; i < MAX_PLAYERS; i ++) { for (int i = 0; i < MAX_PLAYERS; i ++) {
if (player_data[i].client_fd == -1) continue; if (player_data[i].client_fd == -1) continue; // Skip offline players
if (player_data[i].flags & 0x20) continue; if (player_data[i].flags & 0x20) { // Check "client loading" flag
// If 3 seconds (60 vanilla ticks) have passed, assume player has loaded
player_data[i].flagval_16 ++;
if (player_data[i].flagval_16 > (unsigned int)(3 * TICKS_PER_SECOND)) {
player_data[i].flags &= ~0x20;
player_data[i].flagval_16 = 0;
} else continue;
}
// Send Keep Alive and Update Time packets // Send Keep Alive and Update Time packets
sc_keepAlive(player_data[i].client_fd); sc_keepAlive(player_data[i].client_fd);
sc_updateTime(player_data[i].client_fd, world_time); sc_updateTime(player_data[i].client_fd, world_time);