mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-01 23:25:09 +02:00
handle player loading flag more cautiously
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user