From e34a973f647bc6b7814ad1f3e837689f8478b84a Mon Sep 17 00:00:00 2001 From: untodesu Date: Sat, 22 Mar 2025 15:08:17 +0500 Subject: A bunch of pre-release fixes - Updated localization for protocol messages - Added item registry check into server-side - Slightly improved how features are stored --- game/server/game.cc | 3 +++ game/server/overworld.cc | 67 ++++++++++++++++++++++++++---------------------- game/server/sessions.cc | 10 +++++++- game/server/worldgen.cc | 19 ++++++++++++++ game/server/worldgen.hh | 5 ++++ 5 files changed, 72 insertions(+), 32 deletions(-) (limited to 'game/server') diff --git a/game/server/game.cc b/game/server/game.cc index cc5baf8..c6fc67f 100644 --- a/game/server/game.cc +++ b/game/server/game.cc @@ -28,6 +28,7 @@ #include "server/universe.hh" #include "server/unloader.hh" #include "server/whitelist.hh" +#include "server/worldgen.hh" ConfigUnsigned server_game::view_distance(4U, 4U, 32U); @@ -55,6 +56,8 @@ void server_game::init(void) server_chat::init(); server_recieve::init(); + worldgen::init(); + unloader::init(); universe::init(); } diff --git a/game/server/overworld.cc b/game/server/overworld.cc index 78747fc..608fd01 100644 --- a/game/server/overworld.cc +++ b/game/server/overworld.cc @@ -1,6 +1,8 @@ #include "server/pch.hh" #include "server/overworld.hh" +#include "core/vectors.hh" + #include "shared/coord.hh" #include "shared/game_voxels.hh" #include "shared/voxel_storage.hh" @@ -11,9 +13,12 @@ static void compute_tree_feature(unsigned int height, Feature &feature, voxel_id // Ensure the tree height is too small height = cxpr::max(height, 4U); + // Put down a single piece of dirt + feature.push_back({ voxel_pos(0, -1, 0), game_voxels::dirt, true }); + // Generate tree stem for(unsigned int i = 0; i < height; ++i) { - feature.push_back({ voxel_pos(0, i, 0), log_voxel }); + feature.push_back({ voxel_pos(0, i, 0), log_voxel, true }); } auto leaves_start = height - 3U; @@ -23,43 +28,43 @@ static void compute_tree_feature(unsigned int height, Feature &feature, voxel_id // Generate the thin 3x3 layer of leaves that // starts from leaves_start and ends at leaves_thin_end for(unsigned int i = leaves_start; i <= leaves_thin_end; ++i) { - feature.push_back({ local_pos(-1, i, -1), leaves_voxel }); - feature.push_back({ local_pos(-1, i, +0), leaves_voxel }); - feature.push_back({ local_pos(-1, i, +1), leaves_voxel }); - feature.push_back({ local_pos(+0, i, -1), leaves_voxel }); - feature.push_back({ local_pos(+0, i, +1), leaves_voxel }); - feature.push_back({ local_pos(+1, i, -1), leaves_voxel }); - feature.push_back({ local_pos(+1, i, +0), leaves_voxel }); - feature.push_back({ local_pos(+1, i, +1), leaves_voxel }); + feature.push_back({ local_pos(-1, i, -1), leaves_voxel, false }); + feature.push_back({ local_pos(-1, i, +0), leaves_voxel, false }); + feature.push_back({ local_pos(-1, i, +1), leaves_voxel, false }); + feature.push_back({ local_pos(+0, i, -1), leaves_voxel, false }); + feature.push_back({ local_pos(+0, i, +1), leaves_voxel, false }); + feature.push_back({ local_pos(+1, i, -1), leaves_voxel, false }); + feature.push_back({ local_pos(+1, i, +0), leaves_voxel, false }); + feature.push_back({ local_pos(+1, i, +1), leaves_voxel, false }); } // Generate the tree cap; a 3x3 patch of leaves // that is slapped right on top of the thin 3x3 layer - feature.push_back({ local_pos(-1, height, +0), leaves_voxel }); - feature.push_back({ local_pos(+0, height, -1), leaves_voxel }); - feature.push_back({ local_pos(+0, height, +0), leaves_voxel }); - feature.push_back({ local_pos(+0, height, +1), leaves_voxel }); - feature.push_back({ local_pos(+1, height, +0), leaves_voxel }); + feature.push_back({ local_pos(-1, height, +0), leaves_voxel, false }); + feature.push_back({ local_pos(+0, height, -1), leaves_voxel, false }); + feature.push_back({ local_pos(+0, height, +0), leaves_voxel, false }); + feature.push_back({ local_pos(+0, height, +1), leaves_voxel, false }); + feature.push_back({ local_pos(+1, height, +0), leaves_voxel, false }); // Generate the thin 5x5 layer of leaves that // starts from leaves_start and ends at leaves_thin_end for(unsigned int i = leaves_start; i <= leaves_thick_end; ++i) { - feature.push_back({ local_pos(-1, i, -2), leaves_voxel }); - feature.push_back({ local_pos(-1, i, +2), leaves_voxel }); - feature.push_back({ local_pos(-2, i, -1), leaves_voxel }); - feature.push_back({ local_pos(-2, i, -2), leaves_voxel }); - feature.push_back({ local_pos(-2, i, +0), leaves_voxel }); - feature.push_back({ local_pos(-2, i, +1), leaves_voxel }); - feature.push_back({ local_pos(-2, i, +2), leaves_voxel }); - feature.push_back({ local_pos(+0, i, -2), leaves_voxel }); - feature.push_back({ local_pos(+0, i, +2), leaves_voxel }); - feature.push_back({ local_pos(+1, i, -2), leaves_voxel }); - feature.push_back({ local_pos(+1, i, +2), leaves_voxel }); - feature.push_back({ local_pos(+2, i, -1), leaves_voxel }); - feature.push_back({ local_pos(+2, i, -2), leaves_voxel }); - feature.push_back({ local_pos(+2, i, +0), leaves_voxel }); - feature.push_back({ local_pos(+2, i, +1), leaves_voxel }); - feature.push_back({ local_pos(+2, i, +2), leaves_voxel }); + feature.push_back({ local_pos(-1, i, -2), leaves_voxel, false }); + feature.push_back({ local_pos(-1, i, +2), leaves_voxel, false }); + feature.push_back({ local_pos(-2, i, -1), leaves_voxel, false }); + feature.push_back({ local_pos(-2, i, -2), leaves_voxel, false }); + feature.push_back({ local_pos(-2, i, +0), leaves_voxel, false }); + feature.push_back({ local_pos(-2, i, +1), leaves_voxel, false }); + feature.push_back({ local_pos(-2, i, +2), leaves_voxel, false }); + feature.push_back({ local_pos(+0, i, -2), leaves_voxel, false }); + feature.push_back({ local_pos(+0, i, +2), leaves_voxel, false }); + feature.push_back({ local_pos(+1, i, -2), leaves_voxel, false }); + feature.push_back({ local_pos(+1, i, +2), leaves_voxel, false }); + feature.push_back({ local_pos(+2, i, -1), leaves_voxel, false }); + feature.push_back({ local_pos(+2, i, -2), leaves_voxel, false }); + feature.push_back({ local_pos(+2, i, +0), leaves_voxel, false }); + feature.push_back({ local_pos(+2, i, +1), leaves_voxel, false }); + feature.push_back({ local_pos(+2, i, +2), leaves_voxel, false }); } } @@ -216,7 +221,7 @@ const Overworld_Metadata &Overworld::get_or_create_metadata(const chunk_pos_xz & auto is_unique = true; for(const auto &check_lpos : metadata.trees) { - if(check_lpos == lpos) { + if(cxvectors::distance2(check_lpos, lpos) <= 9) { is_unique = false; break; } diff --git a/game/server/sessions.cc b/game/server/sessions.cc index f2e643d..58f12d4 100644 --- a/game/server/sessions.cc +++ b/game/server/sessions.cc @@ -11,6 +11,7 @@ #include "shared/dimension.hh" #include "shared/factory.hh" #include "shared/head.hh" +#include "shared/item_registry.hh" #include "shared/player.hh" #include "shared/protocol.hh" #include "shared/transform.hh" @@ -56,13 +57,20 @@ static void on_login_request_packet(const protocol::LoginRequest &packet) // FIXME: calculate voxel registry checksum ahead of time // instead of figuring it out every time a new player connects - if(packet.voxel_def_checksum != voxel_registry::checksum()) { + if(packet.voxel_registry_checksum != voxel_registry::calcualte_checksum()) { protocol::Disconnect response; response.reason = "protocol.voxel_registry_checksum"; protocol::send(packet.peer, protocol::encode(response)); return; } + if(packet.item_registry_checksum != item_registry::calcualte_checksum()) { + protocol::Disconnect response; + response.reason = "protocol.item_registry_checksum"; + protocol::send(packet.peer, protocol::encode(response)); + return; + } + // Don't assign new usernames and just kick the player if // an another client using the same username is already connected // and playing; since we have a whitelist, adding "(1)" isn't feasible anymore diff --git a/game/server/worldgen.cc b/game/server/worldgen.cc index 83fddbb..4fc37c7 100644 --- a/game/server/worldgen.cc +++ b/game/server/worldgen.cc @@ -1,13 +1,19 @@ #include "server/pch.hh" #include "server/worldgen.hh" +#include "core/config.hh" + #include "shared/chunk.hh" #include "shared/dimension.hh" #include "shared/protocol.hh" #include "shared/threading.hh" +#include "server/globals.hh" +#include "server/inhabited.hh" #include "server/sessions.hh" +static ConfigBoolean aggressive_caching(false); + static emhash8::HashMap>> active_tasks; class WorldgenTask final : public Task { @@ -60,6 +66,14 @@ void WorldgenTask::finalize(void) auto chunk = m_dimension->create_chunk(m_cpos); chunk->set_voxels(m_voxels); + if(aggressive_caching.get_value()) { + // Marking the chunk with InhabitedComponent makes + // it so that it is saved regardles of whether it was + // modified by players or not. This isn't particularly + // good for server-side disk usage but it might improve performance + m_dimension->chunks.emplace(chunk->get_entity()); + } + protocol::ChunkVoxels response; response.voxels = m_voxels; response.chunk = m_cpos; @@ -84,6 +98,11 @@ void WorldgenTask::finalize(void) } } +void worldgen::init(void) +{ + globals::server_config.add_value("worldgen.aggressive_caching", aggressive_caching); +} + bool worldgen::is_generating(Dimension *dimension, const chunk_pos &cpos) { auto dim_tasks = active_tasks.find(dimension); diff --git a/game/server/worldgen.hh b/game/server/worldgen.hh index 3153071..7fb08b9 100644 --- a/game/server/worldgen.hh +++ b/game/server/worldgen.hh @@ -7,6 +7,11 @@ class Dimension; class Session; +namespace worldgen +{ +void init(void); +} // namespace worldgen + namespace worldgen { bool is_generating(Dimension *dimension, const chunk_pos &cpos); -- cgit