From 3151f0b6f261ceff3802a7b6da6b3b2d10c3a4fa Mon Sep 17 00:00:00 2001 From: p2r3 Date: Sun, 31 Aug 2025 01:56:47 +0300 Subject: [PATCH] add a way to restore world data over the network --- src/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.c b/src/main.c index d3f9bba..bc8c659 100644 --- a/src/main.c +++ b/src/main.c @@ -572,6 +572,24 @@ int main () { continue; } + // Received FEED packet, load world data from socket and disconnect + if (recv_buffer[0] == 0xFE && recv_buffer[1] == 0xED && getClientState(client_fd) == STATE_NONE) { + // Consume 0xFEED bytes (previous read was just a peek) + recv_all(client_fd, recv_buffer, 2, false); + // Write full buffers straight into memory + recv_all(client_fd, block_changes, sizeof(block_changes), false); + recv_all(client_fd, player_data, sizeof(player_data), false); + // Recover block_changes_count + for (int i = 0; i < MAX_BLOCK_CHANGES; i ++) { + if (block_changes[i].block == 0xFF) continue; + if (block_changes[i].block == B_chest) i += 14; + if (i >= block_changes_count) block_changes_count = i + 1; + } + // Kick the client + disconnectClient(&clients[client_index], 7); + continue; + } + // Read packet length int length = readVarInt(client_fd); if (length == VARNUM_ERROR) {