diff --git a/include/globals.h b/include/globals.h index fd6df27..7bf944b 100644 --- a/include/globals.h +++ b/include/globals.h @@ -137,7 +137,7 @@ typedef struct { // 0x04 - sneaking // 0x08 - sprinting // 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; } PlayerData; diff --git a/src/main.c b/src/main.c index 6d7188b..0ab1b8d 100644 --- a/src/main.c +++ b/src/main.c @@ -382,6 +382,14 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { if (state == STATE_PLAY) cs_playerInput(client_fd); 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: if (state == STATE_PLAY) cs_setHeldItem(client_fd); break; diff --git a/src/procedures.c b/src/procedures.c index cc56540..5397d8e 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -1145,8 +1145,15 @@ void handleServerTick (int64_t time_since_last_tick) { // Update player events 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 == -1) continue; // Skip offline players + 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 sc_keepAlive(player_data[i].client_fd); sc_updateTime(player_data[i].client_fd, world_time);