#ifndef H_GLOBALS #define H_GLOBALS #include #include #ifdef ESP_PLATFORM #define WIFI_SSID "your-ssid" #define WIFI_PASS "your-password" void task_yield (); #else #define task_yield(); #endif #define true 1 #define false 0 // TCP port, Minecraft's default is 25565 #define PORT 25565 // How many players to keep in memory, NOT the amount of concurrent players // Even when offline, players who have logged on before take up a slot #define MAX_PLAYERS 16 // How many mobs to allocate memory for #define MAX_MOBS (MAX_PLAYERS) // Manhattan distance at which mobs despawn #define MOB_DESPAWN_DISTANCE 256 // Server game mode: 0 - survival; 1 - creative; 2 - adventure; 3 - spectator #define GAMEMODE 0 // Max render distance, determines how many chunks to send #define VIEW_DISTANCE 2 // Time between server ticks in microseconds (default = 1s) #define TIME_BETWEEN_TICKS 1000000 // Calculated from TIME_BETWEEN_TICKS #define TICKS_PER_SECOND ((float)1000000 / TIME_BETWEEN_TICKS) // How many visited chunk coordinates to "remember" // The server will not re-send chunks that the player has recently been in #define VISITED_HISTORY 4 // How many player-made block changes to allow // Determines the fixed amount of memory allocated to blocks #define MAX_BLOCK_CHANGES 20000 // If defined, writes and reads world data to/from disk (or flash). // This is a synchronous operation, and can cause performance issues if // frequent random disk access is slow. Data is still stored in and // accessed from memory - reading from disk is only done on startup. // When targeting ESP-IDF, LittleFS is used to manage flash reads and // writes. Consider increasing DISK_SYNC_INTERVAL if wear is a concern. #define SYNC_WORLD_TO_DISK // The minimum interval (in microseconds) at which certain data is written // to disk/flash. Bounded on the low end by TIME_BETWEEN_TICKS. Currently // only applies to player data. Block changes are written as soon as they // are made, but in much smaller portions. #define DISK_SYNC_INTERVAL 15000000 // Time in microseconds to spend waiting for data transmission before // timing out. (default = 5s) #define NETWORK_TIMEOUT_TIME 5000000 // If defined, scales the frequency at which player movement updates are // broadcast based on the amount of players, reducing overhead for higher // player counts. For very many players, makes movement look jittery. #define SCALE_MOVEMENT_UPDATES_TO_PLAYER_COUNT // If defined, calculates fluid flow when blocks are updated near fluids #define DO_FLUID_FLOW // If defined, allows players to craft and use chests. // Chests take up 15 block change slots each, require additional checks, // and use some terrible memory hacks to function. On some platforms, this // could cause bad performance or even crashes during gameplay. #define ALLOW_CHESTS // If defined, enables flight for all players. As a side-effect, allows // players to sprint when starving. // #define ENABLE_PLAYER_FLIGHT // If defined, logs unrecognized packet IDs // #define DEV_LOG_UNKNOWN_PACKETS // If defined, logs cases when packet length doesn't match parsed byte count #define DEV_LOG_LENGTH_DISCREPANCY // If defined, log chunk generation events #define DEV_LOG_CHUNK_GENERATION #define STATE_NONE 0 #define STATE_STATUS 1 #define STATE_LOGIN 2 #define STATE_TRANSFER 3 #define STATE_CONFIGURATION 4 #define STATE_PLAY 5 extern ssize_t recv_count; extern uint8_t recv_buffer[256]; extern uint32_t world_seed; extern uint32_t rng_seed; extern uint16_t world_time; extern char motd[]; extern uint8_t motd_len; extern uint16_t client_count; #pragma pack(push, 1) typedef struct { short x; uint8_t y; short z; uint8_t block; } BlockChange; typedef struct { uint8_t uuid[16]; char name[16]; int client_fd; short x; uint8_t y; short z; short visited_x[VISITED_HISTORY]; short visited_z[VISITED_HISTORY]; #ifdef SCALE_MOVEMENT_UPDATES_TO_PLAYER_COUNT uint16_t packets_since_update; #endif int8_t yaw; int8_t pitch; uint8_t grounded_y; uint8_t health; uint8_t hunger; uint16_t saturation; uint8_t hotbar; uint16_t inventory_items[41]; uint16_t craft_items[9]; uint8_t inventory_count[41]; uint8_t craft_count[9]; // Usage depends on player's flags, see below // When no flags are set, acts as cursor item ID uint16_t flagval_16; // Usage depends on player's flags, see below // When no flags are set, acts as cursor item count uint8_t flagval_8; // 0x01 - attack cooldown, uses flagval_8 as the timer // 0x02 - has not spawned yet // 0x04 - sneaking // 0x08 - sprinting // 0x10 - eating, makes flagval_16 act as eating timer // 0x20 - client loading, uses flagval_16 as fallback timer uint8_t flags; } PlayerData; typedef struct { uint8_t type; short x; // When the mob is dead (health is 0), the Y coordinate acts // as a timer for deleting and deallocating the mob uint8_t y; short z; // Lower 5 bits: health // Upper 3 bits: reserved (?) uint8_t data; } MobData; #pragma pack(pop) extern BlockChange block_changes[MAX_BLOCK_CHANGES]; extern int block_changes_count; extern PlayerData player_data[MAX_PLAYERS]; extern int player_data_count; extern MobData mob_data[MAX_MOBS]; #endif