From 08ee9794fbc0960a8aab1af21d34f40685809e75 Mon Sep 17 00:00:00 2001 From: JDiaz Date: Mon, 11 Jan 2021 18:03:31 +0100 Subject: Implement on_rightclickplayer callback (#10775) Co-authored-by: rubenwardy --- src/server/player_sao.cpp | 5 +++++ src/server/player_sao.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 232c6a01d..c1b1401e6 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -456,6 +456,11 @@ u16 PlayerSAO::punch(v3f dir, return hitparams.wear; } +void PlayerSAO::rightClick(ServerActiveObject *clicker) +{ + m_env->getScriptIface()->on_rightclickplayer(this, clicker); +} + void PlayerSAO::setHP(s32 hp, const PlayerHPChangeReason &reason) { if (hp == (s32)m_hp) diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 3e178d4fc..6aee8d5aa 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -111,7 +111,7 @@ public: u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, float time_from_last_punch); - void rightClick(ServerActiveObject *clicker) {} + void rightClick(ServerActiveObject *clicker); void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHPRaw(u16 hp) { m_hp = hp; } s16 readDamage(); -- cgit v1.2.3 From 45ccfe26fb6e0a130e4925ec362cccb1f045a829 Mon Sep 17 00:00:00 2001 From: Zughy <63455151+Zughy@users.noreply.github.com> Date: Thu, 21 Jan 2021 18:17:09 +0000 Subject: Removed some obsolete code (#10562) Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com> --- builtin/game/deprecated.lua | 25 +------------------------ builtin/game/item.lua | 4 ---- builtin/game/register.lua | 7 ------- doc/world_format.txt | 11 ----------- src/activeobject.h | 10 +++++----- src/mapgen/mapgen.h | 2 -- src/script/common/c_content.cpp | 17 ----------------- src/script/lua_api/l_mapgen.cpp | 3 --- src/server/player_sao.cpp | 2 +- 9 files changed, 7 insertions(+), 74 deletions(-) (limited to 'src/server') diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 20f0482eb..c5c7848f5 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -1,28 +1,5 @@ -- Minetest: builtin/deprecated.lua --- --- Default material types --- -local function digprop_err() - core.log("deprecated", "The core.digprop_* functions are obsolete and need to be replaced by item groups.") -end - -core.digprop_constanttime = digprop_err -core.digprop_stonelike = digprop_err -core.digprop_dirtlike = digprop_err -core.digprop_gravellike = digprop_err -core.digprop_woodlike = digprop_err -core.digprop_leaveslike = digprop_err -core.digprop_glasslike = digprop_err - -function core.node_metadata_inventory_move_allow_all() - core.log("deprecated", "core.node_metadata_inventory_move_allow_all is obsolete and does nothing.") -end - -function core.add_to_creative_inventory(itemstring) - core.log("deprecated", "core.add_to_creative_inventory is obsolete and does nothing.") -end - -- -- EnvRef -- @@ -77,7 +54,7 @@ core.setting_save = setting_proxy("write") function core.register_on_auth_fail(func) core.log("deprecated", "core.register_on_auth_fail " .. - "is obsolete and should be replaced by " .. + "is deprecated and should be replaced by " .. "core.register_on_authplayer instead.") core.register_on_authplayer(function (player_name, ip, is_success) diff --git a/builtin/game/item.lua b/builtin/game/item.lua index 109712b42..0df25b455 100644 --- a/builtin/game/item.lua +++ b/builtin/game/item.lua @@ -705,10 +705,6 @@ core.nodedef_default = { on_receive_fields = nil, - on_metadata_inventory_move = core.node_metadata_inventory_move_allow_all, - on_metadata_inventory_offer = core.node_metadata_inventory_offer_allow_all, - on_metadata_inventory_take = core.node_metadata_inventory_take_allow_all, - -- Node properties drawtype = "normal", visual_scale = 1.0, diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 93e1dad12..b006957e9 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -324,13 +324,6 @@ for name in pairs(forbidden_item_names) do register_alias_raw(name, "") end - --- Obsolete: --- Aliases for core.register_alias (how ironic...) --- core.alias_node = core.register_alias --- core.alias_tool = core.register_alias --- core.alias_craftitem = core.register_alias - -- -- Built-in node definitions. Also defined in C. -- diff --git a/doc/world_format.txt b/doc/world_format.txt index 73a03e5ee..a8a9e463e 100644 --- a/doc/world_format.txt +++ b/doc/world_format.txt @@ -493,19 +493,8 @@ Static objects are persistent freely moving objects in the world. Object types: 1: Test object -2: Item -3: Rat (obsolete) -4: Oerkki (obsolete) -5: Firefly (obsolete) -6: MobV2 (obsolete) 7: LuaEntity -1: Item: - u8 version - version 0: - u16 len - u8[len] itemstring - 7: LuaEntity: u8 compatibility_byte (always 1) u16 len diff --git a/src/activeobject.h b/src/activeobject.h index 0829858ad..1d8a3712b 100644 --- a/src/activeobject.h +++ b/src/activeobject.h @@ -28,11 +28,11 @@ enum ActiveObjectType { ACTIVEOBJECT_TYPE_INVALID = 0, ACTIVEOBJECT_TYPE_TEST = 1, // Obsolete stuff - ACTIVEOBJECT_TYPE_ITEM = 2, -// ACTIVEOBJECT_TYPE_RAT = 3, -// ACTIVEOBJECT_TYPE_OERKKI1 = 4, -// ACTIVEOBJECT_TYPE_FIREFLY = 5, - ACTIVEOBJECT_TYPE_MOBV2 = 6, +// ACTIVEOBJECT_TYPE_ITEM = 2, +// ACTIVEOBJECT_TYPE_RAT = 3, +// ACTIVEOBJECT_TYPE_OERKKI1 = 4, +// ACTIVEOBJECT_TYPE_FIREFLY = 5, +// ACTIVEOBJECT_TYPE_MOBV2 = 6, // End obsolete stuff ACTIVEOBJECT_TYPE_LUAENTITY = 7, // Special type, not stored as a static object diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h index 1487731e2..61db4f3b9 100644 --- a/src/mapgen/mapgen.h +++ b/src/mapgen/mapgen.h @@ -30,10 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #define MAPGEN_DEFAULT_NAME "v7" /////////////////// Mapgen flags -#define MG_TREES 0x01 // Obsolete. Moved into mgv6 flags #define MG_CAVES 0x02 #define MG_DUNGEONS 0x04 -#define MG_FLAT 0x08 // Obsolete. Moved into mgv6 flags #define MG_LIGHT 0x10 #define MG_DECORATIONS 0x20 #define MG_BIOMES 0x40 diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index e3cb9042e..4316f412d 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -83,9 +83,6 @@ void read_item_definition(lua_State* L, int index, getboolfield(L, index, "liquids_pointable", def.liquids_pointable); - warn_if_field_exists(L, index, "tool_digging_properties", - "Obsolete; use tool_capabilities"); - lua_getfield(L, index, "tool_capabilities"); if(lua_istable(L, -1)){ def.tool_capabilities = new ToolCapabilities( @@ -653,20 +650,6 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) warningstream << "Node " << f.name.c_str() << " has a palette, but not a suitable paramtype2." << std::endl; - // Warn about some obsolete fields - warn_if_field_exists(L, index, "wall_mounted", - "Obsolete; use paramtype2 = 'wallmounted'"); - warn_if_field_exists(L, index, "light_propagates", - "Obsolete; determined from paramtype"); - warn_if_field_exists(L, index, "dug_item", - "Obsolete; use 'drop' field"); - warn_if_field_exists(L, index, "extra_dug_item", - "Obsolete; use 'drop' field"); - warn_if_field_exists(L, index, "extra_dug_item_rarity", - "Obsolete; use 'drop' field"); - warn_if_field_exists(L, index, "metadata_name", - "Obsolete; use on_add and metadata callbacks"); - // True for all ground-like things like stone and mud, false for eg. trees getboolfield(L, index, "is_ground_content", f.is_ground_content); f.light_propagates = (f.param_type == CPT_LIGHT); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 834938e56..498859f14 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -873,9 +873,6 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L) if (lua_isnumber(L, -1)) settingsmgr->setMapSetting("chunksize", readParam(L, -1), true); - warn_if_field_exists(L, 1, "flagmask", - "Obsolete: flags field now includes unset flags."); - lua_getfield(L, 1, "flags"); if (lua_isstring(L, -1)) settingsmgr->setMapSetting("mg_flags", readParam(L, -1), true); diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index c1b1401e6..110d2010d 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -148,7 +148,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) void PlayerSAO::getStaticData(std::string * result) const { - FATAL_ERROR("Obsolete function"); + FATAL_ERROR("This function shall not be called for PlayerSAO"); } void PlayerSAO::step(float dtime, bool send_recommended) -- cgit v1.2.3 From 4c76239818f5159314f30883f98b977d30aaa26c Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 22 Jan 2021 15:09:26 +0000 Subject: Remove dead code (#10845) --- src/client/client.cpp | 20 ----- src/client/client.h | 7 -- src/client/clientenvironment.cpp | 7 -- src/client/hud.cpp | 2 - src/client/mapblock_mesh.cpp | 7 -- src/client/mapblock_mesh.h | 2 - src/client/mesh_generator_thread.h | 1 - src/client/minimap.h | 1 - src/client/tile.cpp | 2 - src/emerge.cpp | 9 +-- src/exceptions.h | 5 -- src/filesys.cpp | 15 ---- src/filesys.h | 3 - src/gui/guiButtonItemImage.cpp | 1 - src/gui/guiButtonItemImage.h | 1 - src/gui/guiChatConsole.h | 2 - src/gui/guiEngine.cpp | 2 - src/gui/guiFormSpecMenu.cpp | 4 +- src/gui/guiFormSpecMenu.h | 2 +- src/map.cpp | 160 ------------------------------------- src/map.h | 8 +- src/mapblock.h | 9 --- src/mapgen/mapgen_v6.cpp | 3 +- src/network/networkexceptions.h | 8 +- src/pathfinder.cpp | 6 +- src/script/cpp_api/s_async.cpp | 29 ------- src/script/cpp_api/s_async.h | 6 -- src/server.h | 3 - src/server/player_sao.h | 1 - src/server/serveractiveobject.h | 3 - src/serverenvironment.h | 10 +-- 31 files changed, 8 insertions(+), 331 deletions(-) (limited to 'src/server') diff --git a/src/client/client.cpp b/src/client/client.cpp index af69d0ec9..6577c287d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -159,20 +159,6 @@ void Client::loadMods() scanModIntoMemory(BUILTIN_MOD_NAME, getBuiltinLuaPath()); m_script->loadModFromMemory(BUILTIN_MOD_NAME); - // TODO Uncomment when server-sent CSM and verifying of builtin are complete - /* - // Don't load client-provided mods if disabled by server - if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOAD_CLIENT_MODS)) { - warningstream << "Client-provided mod loading is disabled by server." << - std::endl; - // If builtin integrity is wrong, disconnect user - if (!checkBuiltinIntegrity()) { - // TODO disconnect user - } - return; - } - */ - ClientModConfiguration modconf(getClientModsLuaPath()); m_mods = modconf.getMods(); // complain about mods with unsatisfied dependencies @@ -216,12 +202,6 @@ void Client::loadMods() m_script->on_minimap_ready(m_minimap); } -bool Client::checkBuiltinIntegrity() -{ - // TODO - return true; -} - void Client::scanModSubfolder(const std::string &mod_name, const std::string &mod_path, std::string mod_subpath) { diff --git a/src/client/client.h b/src/client/client.h index bffdc7ec6..25a1b97ba 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -415,11 +415,6 @@ public: return m_csm_restriction_flags & flag; } - u32 getCSMNodeRangeLimit() const - { - return m_csm_restriction_noderange; - } - inline std::unordered_map &getHUDTranslationMap() { return m_hud_server_to_client; @@ -437,7 +432,6 @@ public: } private: void loadMods(); - bool checkBuiltinIntegrity(); // Virtual methods from con::PeerHandler void peerAdded(con::Peer *peer) override; @@ -587,7 +581,6 @@ private: // Client modding ClientScripting *m_script = nullptr; - bool m_modding_enabled; std::unordered_map m_mod_storages; float m_mod_storage_save_timer = 10.0f; std::vector m_mods; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index da1e6e9c7..fc7cbe254 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -334,13 +334,6 @@ GenericCAO* ClientEnvironment::getGenericCAO(u16 id) return NULL; } -bool isFreeClientActiveObjectId(const u16 id, - ClientActiveObjectMap &objects) -{ - return id != 0 && objects.find(id) == objects.end(); - -} - u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) { // Register object. If failed return zero id diff --git a/src/client/hud.cpp b/src/client/hud.cpp index e956c2738..46736b325 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -571,8 +571,6 @@ void Hud::drawCompassTranslate(HudElement *e, video::ITexture *texture, void Hud::drawCompassRotate(HudElement *e, video::ITexture *texture, const core::rect &rect, int angle) { - core::dimension2di imgsize(texture->getOriginalSize()); - core::rect oldViewPort = driver->getViewPort(); core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION); core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW); diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 4c43fcb61..d78a86b2d 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1176,13 +1176,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): } if (m_mesh[layer]) { -#if 0 - // Usually 1-700 faces and 1-7 materials - std::cout << "Updated MapBlock has " << fastfaces_new.size() - << " faces and uses " << m_mesh[layer]->getMeshBufferCount() - << " materials (meshbuffers)" << std::endl; -#endif - // Use VBO for mesh (this just would set this for ever buffer) if (m_enable_vbo) m_mesh[layer]->setHardwareMappingHint(scene::EHM_STATIC); diff --git a/src/client/mapblock_mesh.h b/src/client/mapblock_mesh.h index 0308b8161..3b17c4af9 100644 --- a/src/client/mapblock_mesh.h +++ b/src/client/mapblock_mesh.h @@ -125,8 +125,6 @@ public: m_animation_force_timer--; } - void updateCameraOffset(v3s16 camera_offset); - private: scene::IMesh *m_mesh[MAX_TILE_LAYERS]; MinimapMapblock *m_minimap_mapblock; diff --git a/src/client/mesh_generator_thread.h b/src/client/mesh_generator_thread.h index f3c5e7da8..4371b8390 100644 --- a/src/client/mesh_generator_thread.h +++ b/src/client/mesh_generator_thread.h @@ -40,7 +40,6 @@ struct QueuedMeshUpdate { v3s16 p = v3s16(-1337, -1337, -1337); bool ack_block_to_server = false; - bool urgent = false; int crack_level = -1; v3s16 crack_pos; MeshMakeData *data = nullptr; // This is generated in MeshUpdateQueue::pop() diff --git a/src/client/minimap.h b/src/client/minimap.h index 4a2c462f8..87c9668ee 100644 --- a/src/client/minimap.h +++ b/src/client/minimap.h @@ -138,7 +138,6 @@ public: size_t getMaxModeIndex() const { return m_modes.size() - 1; }; void nextMode(); - void setModesFromString(std::string modes_string); MinimapModeDef getModeDef() const { return data->mode; } video::ITexture *getMinimapTexture(); diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 37836d0df..aad956ada 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -429,7 +429,6 @@ private: // Cached settings needed for making textures from meshes bool m_setting_trilinear_filter; bool m_setting_bilinear_filter; - bool m_setting_anisotropic_filter; }; IWritableTextureSource *createTextureSource() @@ -450,7 +449,6 @@ TextureSource::TextureSource() // for these settings to take effect m_setting_trilinear_filter = g_settings->getBool("trilinear_filter"); m_setting_bilinear_filter = g_settings->getBool("bilinear_filter"); - m_setting_anisotropic_filter = g_settings->getBool("anisotropic_filter"); } TextureSource::~TextureSource() diff --git a/src/emerge.cpp b/src/emerge.cpp index 12e407797..e0dc5628e 100644 --- a/src/emerge.cpp +++ b/src/emerge.cpp @@ -396,14 +396,7 @@ int EmergeManager::getGroundLevelAtPoint(v2s16 p) // TODO(hmmmm): Move this to ServerMap bool EmergeManager::isBlockUnderground(v3s16 blockpos) { -#if 0 - v2s16 p = v2s16((blockpos.X * MAP_BLOCKSIZE) + MAP_BLOCKSIZE / 2, - (blockpos.Y * MAP_BLOCKSIZE) + MAP_BLOCKSIZE / 2); - int ground_level = getGroundLevelAtPoint(p); - return blockpos.Y * (MAP_BLOCKSIZE + 1) <= min(water_level, ground_level); -#endif - - // Use a simple heuristic; the above method is wildly inaccurate anyway. + // Use a simple heuristic return blockpos.Y * (MAP_BLOCKSIZE + 1) <= mgparams->water_level; } diff --git a/src/exceptions.h b/src/exceptions.h index c54307653..a558adc5d 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -72,11 +72,6 @@ public: SettingNotFoundException(const std::string &s): BaseException(s) {} }; -class InvalidFilenameException : public BaseException { -public: - InvalidFilenameException(const std::string &s): BaseException(s) {} -}; - class ItemNotFoundException : public BaseException { public: ItemNotFoundException(const std::string &s): BaseException(s) {} diff --git a/src/filesys.cpp b/src/filesys.cpp index 28a33f4d0..eeba0c564 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -401,21 +401,6 @@ void GetRecursiveSubPaths(const std::string &path, } } -bool DeletePaths(const std::vector &paths) -{ - bool success = true; - // Go backwards to succesfully delete the output of GetRecursiveSubPaths - for(int i=paths.size()-1; i>=0; i--){ - const std::string &path = paths[i]; - bool did = DeleteSingleFileOrEmptyDirectory(path); - if(!did){ - errorstream<<"Failed to delete "< &ignore = {}); -// Tries to delete all, returns false if any failed -bool DeletePaths(const std::vector &paths); - // Only pass full paths to this one. True on success. bool RecursiveDeleteContent(const std::string &path); diff --git a/src/gui/guiButtonItemImage.cpp b/src/gui/guiButtonItemImage.cpp index d8b9042ac..39272fe37 100644 --- a/src/gui/guiButtonItemImage.cpp +++ b/src/gui/guiButtonItemImage.cpp @@ -39,7 +39,6 @@ GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment, item, getActiveFont(), client); sendToBack(m_image); - m_item_name = item; m_client = client; } diff --git a/src/gui/guiButtonItemImage.h b/src/gui/guiButtonItemImage.h index aad923bda..b90ac757e 100644 --- a/src/gui/guiButtonItemImage.h +++ b/src/gui/guiButtonItemImage.h @@ -42,7 +42,6 @@ public: Client *client); private: - std::string m_item_name; Client *m_client; GUIItemImage *m_image; }; diff --git a/src/gui/guiChatConsole.h b/src/gui/guiChatConsole.h index 204f9f9cc..896342ab0 100644 --- a/src/gui/guiChatConsole.h +++ b/src/gui/guiChatConsole.h @@ -68,8 +68,6 @@ public: // Irrlicht draw method virtual void draw(); - bool canTakeFocus(gui::IGUIElement* element) { return false; } - virtual bool OnEvent(const SEvent& event); virtual void setVisible(bool visible); diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index c5ad5c323..6e2c2b053 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -486,8 +486,6 @@ void GUIEngine::drawHeader(video::IVideoDriver *driver) splashrect += v2s32((screensize.Width/2)-(splashsize.X/2), ((free_space/2)-splashsize.Y/2)+10); - video::SColor bgcolor(255,50,50,50); - draw2DImageFilterScaled(driver, texture, splashrect, core::rect(core::position2d(0,0), core::dimension2di(texture->getOriginalSize())), diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 973fc60a8..4415bdd3a 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -3505,8 +3505,6 @@ bool GUIFormSpecMenu::getAndroidUIInput() GUIInventoryList::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const { - core::rect imgrect(0, 0, imgsize.X, imgsize.Y); - for (const GUIInventoryList *e : m_inventorylists) { s32 item_index = e->getItemIndexAtPos(p); if (item_index != -1) @@ -3837,7 +3835,7 @@ ItemStack GUIFormSpecMenu::verifySelectedItem() return ItemStack(); } -void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no) +void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode) { if(m_text_dst) { diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 37106cb65..d658aba7b 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -253,7 +253,7 @@ public: void updateSelectedItem(); ItemStack verifySelectedItem(); - void acceptInput(FormspecQuitMode quitmode); + void acceptInput(FormspecQuitMode quitmode=quit_mode_no); bool preprocessEvent(const SEvent& event); bool OnEvent(const SEvent& event); bool doPause; diff --git a/src/map.cpp b/src/map.cpp index 6a7cadca5..aff545921 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -530,23 +530,6 @@ void Map::transformLiquids(std::map &modified_blocks, u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 loop_max = liquid_loop_max; -#if 0 - - /* If liquid_loop_max is not keeping up with the queue size increase - * loop_max up to a maximum of liquid_loop_max * dedicated_server_step. - */ - if (m_transforming_liquid.size() > loop_max * 2) { - // "Burst" mode - float server_step = g_settings->getFloat("dedicated_server_step"); - if (m_transforming_liquid_loop_count_multiplier - 1.0 < server_step) - m_transforming_liquid_loop_count_multiplier *= 1.0 + server_step / 10; - } else { - m_transforming_liquid_loop_count_multiplier = 1.0; - } - - loop_max *= m_transforming_liquid_loop_count_multiplier; -#endif - while (m_transforming_liquid.size() != 0) { // This should be done here so that it is done when continue is used @@ -1302,18 +1285,6 @@ ServerMap::~ServerMap() */ delete dbase; delete dbase_ro; - -#if 0 - /* - Free all MapChunks - */ - core::map::Iterator i = m_chunks.getIterator(); - for(; i.atEnd() == false; i++) - { - MapChunk *chunk = i.getNode()->getValue(); - delete chunk; - } -#endif } MapgenParams *ServerMap::getMapgenParams() @@ -1402,25 +1373,6 @@ bool ServerMap::initBlockMake(v3s16 blockpos, BlockMakeData *data) data->vmanip = new MMVManip(this); data->vmanip->initialEmerge(full_bpmin, full_bpmax); - // Note: we may need this again at some point. -#if 0 - // Ensure none of the blocks to be generated were marked as - // containing CONTENT_IGNORE - for (s16 z = blockpos_min.Z; z <= blockpos_max.Z; z++) { - for (s16 y = blockpos_min.Y; y <= blockpos_max.Y; y++) { - for (s16 x = blockpos_min.X; x <= blockpos_max.X; x++) { - core::map::Node *n; - n = data->vmanip->m_loaded_blocks.find(v3s16(x, y, z)); - if (n == NULL) - continue; - u8 flags = n->getValue(); - flags &= ~VMANIP_BLOCK_CONTAINS_CIGNORE; - n->setValue(flags); - } - } - } -#endif - // Data is ready now. return true; } @@ -1431,8 +1383,6 @@ void ServerMap::finishBlockMake(BlockMakeData *data, v3s16 bpmin = data->blockpos_min; v3s16 bpmax = data->blockpos_max; - v3s16 extra_borders(1, 1, 1); - bool enable_mapgen_debug_info = m_emerge->enable_mapgen_debug_info; EMERGE_DBG_OUT("finishBlockMake(): " PP(bpmin) " - " PP(bpmax)); @@ -1525,116 +1475,6 @@ MapSector *ServerMap::createSector(v2s16 p2d) return sector; } -#if 0 -/* - This is a quick-hand function for calling makeBlock(). -*/ -MapBlock * ServerMap::generateBlock( - v3s16 p, - std::map &modified_blocks -) -{ - bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info"); - - TimeTaker timer("generateBlock"); - - //MapBlock *block = original_dummy; - - v2s16 p2d(p.X, p.Z); - v2s16 p2d_nodes = p2d * MAP_BLOCKSIZE; - - /* - Do not generate over-limit - */ - if(blockpos_over_limit(p)) - { - infostream<makeChunk(&data); - //mapgen::make_block(&data); - - if(enable_mapgen_debug_info == false) - t.stop(true); // Hide output - } - - /* - Blit data back on map, update lighting, add mobs and whatever this does - */ - finishBlockMake(&data, modified_blocks); - - /* - Get central block - */ - MapBlock *block = getBlockNoCreateNoEx(p); - -#if 0 - /* - Check result - */ - if(block) - { - bool erroneus_content = false; - for(s16 z0=0; z0getNode(p); - if(n.getContent() == CONTENT_IGNORE) - { - infostream<<"CONTENT_IGNORE at " - <<"("<setNode(v3s16(x0,y0,z0), n); - } - } - } -#endif - - if(enable_mapgen_debug_info == false) - timer.stop(true); // Hide output - - return block; -} -#endif - MapBlock * ServerMap::createBlock(v3s16 p) { /* diff --git a/src/map.h b/src/map.h index c8bae9451..e68795c4a 100644 --- a/src/map.h +++ b/src/map.h @@ -417,13 +417,7 @@ private: bool m_map_saving_enabled; int m_map_compression_level; -#if 0 - // Chunk size in MapSectors - // If 0, chunks are disabled. - s16 m_chunksize; - // Chunks - core::map m_chunks; -#endif + std::set m_chunks_in_progress; /* diff --git a/src/mapblock.h b/src/mapblock.h index 641a1b69b..7b82301e9 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -340,15 +340,6 @@ public: // is not valid on this MapBlock. bool isValidPositionParent(v3s16 p); MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL); - void setNodeParent(v3s16 p, MapNode & n); - - inline void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node) - { - for (u16 z = 0; z < d; z++) - for (u16 y = 0; y < h; y++) - for (u16 x = 0; x < w; x++) - setNode(x0 + x, y0 + y, z0 + z, node); - } // Copies data to VoxelManipulator to getPosRelative() void copyTo(VoxelManipulator &dst); diff --git a/src/mapgen/mapgen_v6.cpp b/src/mapgen/mapgen_v6.cpp index e04180f96..bce9cee81 100644 --- a/src/mapgen/mapgen_v6.cpp +++ b/src/mapgen/mapgen_v6.cpp @@ -792,7 +792,7 @@ void MapgenV6::flowMud(s16 &mudflow_minpos, s16 &mudflow_maxpos) v3s16(0, 0, -1), // Front v3s16(-1, 0, 0), // Left }; - + // Iterate twice for (s16 k = 0; k < 2; k++) { for (s16 z = mudflow_minpos; z <= mudflow_maxpos; z++) @@ -1055,7 +1055,6 @@ void MapgenV6::growGrass() // Add surface nodes MapNode n_dirt_with_grass(c_dirt_with_grass); MapNode n_dirt_with_snow(c_dirt_with_snow); MapNode n_snowblock(c_snowblock); - MapNode n_snow(c_snow); const v3s16 &em = vm->m_area.getExtent(); u32 index = 0; diff --git a/src/network/networkexceptions.h b/src/network/networkexceptions.h index f4913928c..58a3bb490 100644 --- a/src/network/networkexceptions.h +++ b/src/network/networkexceptions.h @@ -56,12 +56,6 @@ public: InvalidIncomingDataException(const char *s) : BaseException(s) {} }; -class InvalidOutgoingDataException : public BaseException -{ -public: - InvalidOutgoingDataException(const char *s) : BaseException(s) {} -}; - class NoIncomingDataException : public BaseException { public: @@ -103,4 +97,4 @@ class SendFailedException : public BaseException { public: SendFailedException(const std::string &s) : BaseException(s) {} -}; \ No newline at end of file +}; diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index 3f0b98c10..1cb84997a 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -157,9 +157,8 @@ public: ArrayGridNodeContainer(Pathfinder *pathf, v3s16 dimensions); virtual PathGridnode &access(v3s16 p); -private: - v3s16 m_dimensions; +private: int m_x_stride; int m_y_stride; std::vector m_nodes_array; @@ -306,8 +305,6 @@ private: int m_max_index_y = 0; /**< max index of search area in y direction */ int m_max_index_z = 0; /**< max index of search area in z direction */ - - int m_searchdistance = 0; /**< max distance to search in each direction */ int m_maxdrop = 0; /**< maximum number of blocks a path may drop */ int m_maxjump = 0; /**< maximum number of blocks a path may jump */ int m_min_target_distance = 0; /**< current smalest path to target */ @@ -619,7 +616,6 @@ std::vector Pathfinder::getPath(v3s16 source, std::vector retval; //initialization - m_searchdistance = searchdistance; m_maxjump = max_jump; m_maxdrop = max_drop; m_start = source; diff --git a/src/script/cpp_api/s_async.cpp b/src/script/cpp_api/s_async.cpp index 5f1f9297e..0619b32c0 100644 --- a/src/script/cpp_api/s_async.cpp +++ b/src/script/cpp_api/s_async.cpp @@ -157,35 +157,6 @@ void AsyncEngine::step(lua_State *L) lua_pop(L, 2); // Pop core and error handler } -/******************************************************************************/ -void AsyncEngine::pushFinishedJobs(lua_State* L) { - // Result Table - MutexAutoLock l(resultQueueMutex); - - unsigned int index = 1; - lua_createtable(L, resultQueue.size(), 0); - int top = lua_gettop(L); - - while (!resultQueue.empty()) { - LuaJobInfo jobDone = resultQueue.front(); - resultQueue.pop_front(); - - lua_createtable(L, 0, 2); // Pre-allocate space for two map fields - int top_lvl2 = lua_gettop(L); - - lua_pushstring(L, "jobid"); - lua_pushnumber(L, jobDone.id); - lua_settable(L, top_lvl2); - - lua_pushstring(L, "retval"); - lua_pushlstring(L, jobDone.serializedResult.data(), - jobDone.serializedResult.size()); - lua_settable(L, top_lvl2); - - lua_rawseti(L, top, index++); - } -} - /******************************************************************************/ void AsyncEngine::prepareEnvironment(lua_State* L, int top) { diff --git a/src/script/cpp_api/s_async.h b/src/script/cpp_api/s_async.h index b1f4bf45f..99a4f891c 100644 --- a/src/script/cpp_api/s_async.h +++ b/src/script/cpp_api/s_async.h @@ -98,12 +98,6 @@ public: */ void step(lua_State *L); - /** - * Push a list of finished jobs onto the stack - * @param L The Lua stack - */ - void pushFinishedJobs(lua_State *L); - protected: /** * Get a Job from queue to be processed diff --git a/src/server.h b/src/server.h index 4b3ac5cf7..a7e85d0e1 100644 --- a/src/server.h +++ b/src/server.h @@ -564,9 +564,6 @@ private: // Craft definition manager IWritableCraftDefManager *m_craftdef; - // Event manager - EventManager *m_event; - // Mods std::unique_ptr m_modmgr; diff --git a/src/server/player_sao.h b/src/server/player_sao.h index 6aee8d5aa..8e2d8803f 100644 --- a/src/server/player_sao.h +++ b/src/server/player_sao.h @@ -114,7 +114,6 @@ public: void rightClick(ServerActiveObject *clicker); void setHP(s32 hp, const PlayerHPChangeReason &reason); void setHPRaw(u16 hp) { m_hp = hp; } - s16 readDamage(); u16 getBreath() const { return m_breath; } void setBreath(const u16 breath, bool send = true); diff --git a/src/server/serveractiveobject.h b/src/server/serveractiveobject.h index 25653a1ad..51f445914 100644 --- a/src/server/serveractiveobject.h +++ b/src/server/serveractiveobject.h @@ -162,8 +162,6 @@ public: {} virtual const ItemGroupList &getArmorGroups() const { static ItemGroupList rv; return rv; } - virtual void setPhysicsOverride(float physics_override_speed, float physics_override_jump, float physics_override_gravity) - {} virtual void setAnimation(v2f frames, float frame_speed, float frame_blend, bool frame_loop) {} virtual void getAnimation(v2f *frames, float *frame_speed, float *frame_blend, bool *frame_loop) @@ -206,7 +204,6 @@ public: } std::string generateUpdateInfantCommand(u16 infant_id, u16 protocol_version); - std::string generateUpdateNametagAttributesCommand(const video::SColor &color) const; void dumpAOMessagesToQueue(std::queue &queue); diff --git a/src/serverenvironment.h b/src/serverenvironment.h index c76d34a37..a11c814ed 100644 --- a/src/serverenvironment.h +++ b/src/serverenvironment.h @@ -190,14 +190,6 @@ enum ClearObjectsMode { CLEAR_OBJECTS_MODE_QUICK, }; -/* - The server-side environment. - - This is not thread-safe. Server uses an environment mutex. -*/ - -typedef std::unordered_map ServerActiveObjectMap; - class ServerEnvironment : public Environment { public: @@ -331,7 +323,7 @@ public: { return m_ao_manager.getObjectsInsideRadius(pos, radius, objects, include_obj_cb); } - + // Find all active objects inside a box void getObjectsInArea(std::vector &objects, const aabb3f &box, std::function include_obj_cb) -- cgit v1.2.3 From 375bcd65c1903957e3a640cefffcc8df164b78bd Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 12 Feb 2021 20:54:06 +0100 Subject: Send attachments instantly before set_pos (#10235) --- src/server.cpp | 3 +++ src/server/luaentity_sao.cpp | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/server') diff --git a/src/server.cpp b/src/server.cpp index af4eb17e2..81cdd1f8d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1821,6 +1821,9 @@ void Server::SendMovePlayer(session_t peer_id) PlayerSAO *sao = player->getPlayerSAO(); assert(sao); + // Send attachment updates instantly to the client prior updating position + sao->sendOutdatedData(); + NetworkPacket pkt(TOCLIENT_MOVE_PLAYER, sizeof(v3f) + sizeof(f32) * 2, peer_id); pkt << sao->getBasePosition() << sao->getLookPitch() << sao->getRotation().Y; diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index c7277491a..5f35aaed8 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -492,6 +492,9 @@ void LuaEntitySAO::sendPosition(bool do_interpolate, bool is_movement_end) if(isAttached()) return; + // Send attachment updates instantly to the client prior updating position + sendOutdatedData(); + m_last_sent_move_precision = m_base_position.getDistanceFrom( m_last_sent_position); m_last_sent_position_timer = 0; -- cgit v1.2.3 From 7832b6843e73410e15677d1324d582b4b7c7e824 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 15 Feb 2021 20:41:19 +0100 Subject: Server-side authority for attached players (#10952) The server must have authority about attachments. This commit ignores any player movement packets as long they're attached. --- src/network/serverpackethandler.cpp | 8 ++++++-- src/server/luaentity_sao.cpp | 10 +++------- src/server/player_sao.cpp | 32 ++++++-------------------------- 3 files changed, 15 insertions(+), 35 deletions(-) (limited to 'src/server') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 270b8e01f..ddc6f4e47 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -488,8 +488,12 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, pitch = modulo360f(pitch); yaw = wrapDegrees_0_360(yaw); - playersao->setBasePosition(position); - player->setSpeed(speed); + if (!playersao->isAttached()) { + // Only update player positions when moving freely + // to not interfere with attachment handling + playersao->setBasePosition(position); + player->setSpeed(speed); + } playersao->setLookPitch(pitch); playersao->setPlayerYaw(yaw); playersao->setFov(fov); diff --git a/src/server/luaentity_sao.cpp b/src/server/luaentity_sao.cpp index 5f35aaed8..3bcbe107b 100644 --- a/src/server/luaentity_sao.cpp +++ b/src/server/luaentity_sao.cpp @@ -146,15 +146,11 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) // Each frame, parent position is copied if the object is attached, otherwise it's calculated normally // If the object gets detached this comes into effect automatically from the last known origin - if(isAttached()) - { - v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); - m_base_position = pos; + if (auto *parent = getParent()) { + m_base_position = parent->getBasePosition(); m_velocity = v3f(0,0,0); m_acceleration = v3f(0,0,0); - } - else - { + } else { if(m_prop.physical){ aabb3f box = m_prop.collisionbox; box.MinEdge *= BS; diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 110d2010d..0d31f2e0b 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -260,10 +260,13 @@ void PlayerSAO::step(float dtime, bool send_recommended) // otherwise it's calculated normally. // If the object gets detached this comes into effect automatically from // the last known origin. - if (isAttached()) { - v3f pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition(); + if (auto *parent = getParent()) { + v3f pos = parent->getBasePosition(); m_last_good_position = pos; setBasePosition(pos); + + if (m_player) + m_player->setSpeed(v3f()); } if (!send_recommended) @@ -570,34 +573,11 @@ void PlayerSAO::setMaxSpeedOverride(const v3f &vel) bool PlayerSAO::checkMovementCheat() { if (m_is_singleplayer || + isAttached() || g_settings->getBool("disable_anticheat")) { m_last_good_position = m_base_position; return false; } - if (UnitSAO *parent = dynamic_cast(getParent())) { - v3f attachment_pos; - { - int parent_id; - std::string bone; - v3f attachment_rot; - bool force_visible; - getAttachment(&parent_id, &bone, &attachment_pos, &attachment_rot, &force_visible); - } - - v3f parent_pos = parent->getBasePosition(); - f32 diff = m_base_position.getDistanceFromSQ(parent_pos) - attachment_pos.getLengthSQ(); - const f32 maxdiff = 4.0f * BS; // fair trade-off value for various latencies - - if (diff > maxdiff * maxdiff) { - setBasePosition(parent_pos); - actionstream << "Server: " << m_player->getName() - << " moved away from parent; diff=" << sqrtf(diff) / BS - << " resetting position." << std::endl; - return true; - } - // Player movement is locked to the entity. Skip further checks - return false; - } bool cheated = false; /* -- cgit v1.2.3 From 4abe4b87b5902bff229505b83b9bddb9a8f759cd Mon Sep 17 00:00:00 2001 From: DS Date: Tue, 23 Feb 2021 19:39:15 +0100 Subject: Allow overwriting media files of dependencies (#10752) --- doc/lua_api.txt | 3 +++ games/devtest/mods/basenodes/textures/default_dirt.png | Bin 790 -> 7303 bytes .../mods/basenodes/textures/dirt_with_grass/info.txt | 3 --- games/devtest/mods/basenodes/textures/info.txt | 7 +++++++ games/devtest/mods/unittests/mod.conf | 1 + games/devtest/mods/unittests/textures/default_dirt.png | Bin 0 -> 790 bytes src/server/mods.cpp | 3 ++- src/server/mods.h | 8 ++++++++ 8 files changed, 21 insertions(+), 4 deletions(-) delete mode 100644 games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt create mode 100644 games/devtest/mods/basenodes/textures/info.txt create mode 100644 games/devtest/mods/unittests/textures/default_dirt.png (limited to 'src/server') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a9c3bcdd9..d3165b9fd 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -256,6 +256,9 @@ Subfolders with names starting with `_` or `.` are ignored. If a subfolder contains a media file with the same name as a media file in one of its parents, the parent's file is used. +Although it is discouraged, a mod can overwrite a media file of any mod that it +depends on by supplying a file with an equal name. + Naming conventions ------------------ diff --git a/games/devtest/mods/basenodes/textures/default_dirt.png b/games/devtest/mods/basenodes/textures/default_dirt.png index 58670305d..aa75bffb6 100644 Binary files a/games/devtest/mods/basenodes/textures/default_dirt.png and b/games/devtest/mods/basenodes/textures/default_dirt.png differ diff --git a/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt b/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt deleted file mode 100644 index 8db21ed9c..000000000 --- a/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt +++ /dev/null @@ -1,3 +0,0 @@ -This is for testing loading textures from subfolders. -If it works correctly, the default_grass_side.png file in this folder is used but -default_grass.png is not overwritten by the file in this folder. diff --git a/games/devtest/mods/basenodes/textures/info.txt b/games/devtest/mods/basenodes/textures/info.txt new file mode 100644 index 000000000..2d4ef7efa --- /dev/null +++ b/games/devtest/mods/basenodes/textures/info.txt @@ -0,0 +1,7 @@ + +The dirt_with_grass folder is for testing loading textures from subfolders. +If it works correctly, the default_grass_side.png file in the folder is used but +default_grass.png is not overwritten by the file in the folder. + +default_dirt.png should be overwritten by the default_dirt.png in the unittests +mod which depends on basenodes. diff --git a/games/devtest/mods/unittests/mod.conf b/games/devtest/mods/unittests/mod.conf index 0d5e3c959..fa94e01a6 100644 --- a/games/devtest/mods/unittests/mod.conf +++ b/games/devtest/mods/unittests/mod.conf @@ -1,2 +1,3 @@ name = unittests description = Adds automated unit tests for the engine +depends = basenodes diff --git a/games/devtest/mods/unittests/textures/default_dirt.png b/games/devtest/mods/unittests/textures/default_dirt.png new file mode 100644 index 000000000..58670305d Binary files /dev/null and b/games/devtest/mods/unittests/textures/default_dirt.png differ diff --git a/src/server/mods.cpp b/src/server/mods.cpp index cf1467648..83fa12da9 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -98,7 +98,8 @@ void ServerModManager::getModNames(std::vector &modlist) const void ServerModManager::getModsMediaPaths(std::vector &paths) const { - for (const ModSpec &spec : m_sorted_mods) { + for (auto it = m_sorted_mods.crbegin(); it != m_sorted_mods.crend(); it++) { + const ModSpec &spec = *it; fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "textures"); fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "sounds"); fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media"); diff --git a/src/server/mods.h b/src/server/mods.h index 54774bd86..8954bbf72 100644 --- a/src/server/mods.h +++ b/src/server/mods.h @@ -42,5 +42,13 @@ public: void loadMods(ServerScripting *script); const ModSpec *getModSpec(const std::string &modname) const; void getModNames(std::vector &modlist) const; + /** + * Recursively gets all paths of mod folders that can contain media files. + * + * Result is ordered in descending priority, ie. files from an earlier path + * should not be replaced by files from a latter one. + * + * @param paths result vector + */ void getModsMediaPaths(std::vector &paths) const; }; -- cgit v1.2.3 From fc864029b9635106a5390aa09d227d7dac31d1a5 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 7 Mar 2021 10:04:07 +0100 Subject: Protect per-player detached inventory actions --- src/network/serverpackethandler.cpp | 6 +++++- src/server/serverinventorymgr.cpp | 12 ++++++++++++ src/server/serverinventorymgr.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index ddc6f4e47..f1ed42302 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -626,7 +626,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) const bool player_has_interact = checkPriv(player->getName(), "interact"); - auto check_inv_access = [player, player_has_interact] ( + auto check_inv_access = [player, player_has_interact, this] ( const InventoryLocation &loc) -> bool { if (loc.type == InventoryLocation::CURRENT_PLAYER) return false; // Only used internally on the client, never sent @@ -634,6 +634,10 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) // Allow access to own inventory in all cases return loc.name == player->getName(); } + if (loc.type == InventoryLocation::DETACHED) { + if (!getInventoryMgr()->checkDetachedInventoryAccess(loc, player->getName())) + return false; + } if (!player_has_interact) { infostream << "Cannot modify foreign inventory: " diff --git a/src/server/serverinventorymgr.cpp b/src/server/serverinventorymgr.cpp index 555e01ec6..2a80c9bbe 100644 --- a/src/server/serverinventorymgr.cpp +++ b/src/server/serverinventorymgr.cpp @@ -168,6 +168,18 @@ bool ServerInventoryManager::removeDetachedInventory(const std::string &name) return true; } +bool ServerInventoryManager::checkDetachedInventoryAccess( + const InventoryLocation &loc, const std::string &player) const +{ + SANITY_CHECK(loc.type == InventoryLocation::DETACHED); + + const auto &inv_it = m_detached_inventories.find(loc.name); + if (inv_it == m_detached_inventories.end()) + return false; + + return inv_it->second.owner.empty() || inv_it->second.owner == player; +} + void ServerInventoryManager::sendDetachedInventories(const std::string &peer_name, bool incremental, std::function apply_cb) diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h index ccf6d3b2e..0e4b72415 100644 --- a/src/server/serverinventorymgr.h +++ b/src/server/serverinventorymgr.h @@ -43,6 +43,7 @@ public: Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef, const std::string &player = ""); bool removeDetachedInventory(const std::string &name); + bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const; void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function apply_cb); -- cgit v1.2.3 From bbe120308f2944eade833b4f16cfc3b42b01fa34 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 13 Apr 2021 20:02:18 +0200 Subject: Attachments: Avoid data loss caused by set_attach() in callbacks (#11181) --- src/server/unit_sao.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/server') diff --git a/src/server/unit_sao.cpp b/src/server/unit_sao.cpp index 2371640ca..fa6c8f0f4 100644 --- a/src/server/unit_sao.cpp +++ b/src/server/unit_sao.cpp @@ -134,16 +134,21 @@ void UnitSAO::setAttachment(int parent_id, const std::string &bone, v3f position int old_parent = m_attachment_parent_id; m_attachment_parent_id = parent_id; + + // The detach callbacks might call to setAttachment() again. + // Ensure the attachment params are applied after this callback is run. + if (parent_id != old_parent) + onDetach(old_parent); + + m_attachment_parent_id = parent_id; m_attachment_bone = bone; m_attachment_position = position; m_attachment_rotation = rotation; m_force_visible = force_visible; m_attachment_sent = false; - if (parent_id != old_parent) { - onDetach(old_parent); + if (parent_id != old_parent) onAttach(parent_id); - } } void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position, -- cgit v1.2.3 From d08242316688ce8ac10dcf94a2cfede21e65be7f Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Thu, 13 May 2021 08:24:07 +0200 Subject: Fix format --- src/content/mods.cpp | 15 ++++++---- src/script/lua_api/l_clientobject.cpp | 56 ++++++++++++++++++----------------- src/server/serverinventorymgr.h | 3 +- 3 files changed, 41 insertions(+), 33 deletions(-) (limited to 'src/server') diff --git a/src/content/mods.cpp b/src/content/mods.cpp index 434004b29..f791fa797 100644 --- a/src/content/mods.cpp +++ b/src/content/mods.cpp @@ -50,7 +50,8 @@ static void log_mod_deprecation(const ModSpec &spec, const std::string &warning) auto handling_mode = get_deprecated_handling_mode(); if (handling_mode != DeprecatedHandlingMode::Ignore) { std::ostringstream os; - os << warning << " (" << spec.name << " at " << spec.path << ")" << std::endl; + os << warning << " (" << spec.name << " at " << spec.path << ")" + << std::endl; if (handling_mode == DeprecatedHandlingMode::Error) { throw ModError(os.str()); @@ -89,7 +90,8 @@ void parseModContents(ModSpec &spec) if (info.exists("name")) spec.name = info.get("name"); else - log_mod_deprecation(spec, "Mods not having a mod.conf file with the name is deprecated."); + log_mod_deprecation(spec, "Mods not having a mod.conf file with " + "the name is deprecated."); if (info.exists("author")) spec.author = info.get("author"); @@ -130,7 +132,8 @@ void parseModContents(ModSpec &spec) std::ifstream is((spec.path + DIR_DELIM + "depends.txt").c_str()); if (is.good()) - log_mod_deprecation(spec, "depends.txt is deprecated, please use mod.conf instead."); + log_mod_deprecation(spec, "depends.txt is deprecated, " + "please use mod.conf instead."); while (is.good()) { std::string dep; @@ -152,8 +155,10 @@ void parseModContents(ModSpec &spec) if (info.exists("description")) spec.desc = info.get("description"); - else if (fs::ReadFile(spec.path + DIR_DELIM + "description.txt", spec.desc)) - log_mod_deprecation(spec, "description.txt is deprecated, please use mod.conf instead."); + else if (fs::ReadFile(spec.path + DIR_DELIM + "description.txt", + spec.desc)) + log_mod_deprecation(spec, "description.txt is deprecated, please " + "use mod.conf instead."); } } diff --git a/src/script/lua_api/l_clientobject.cpp b/src/script/lua_api/l_clientobject.cpp index 5a1123169..c093e754e 100644 --- a/src/script/lua_api/l_clientobject.cpp +++ b/src/script/lua_api/l_clientobject.cpp @@ -48,7 +48,7 @@ ClientActiveObject *ClientObjectRef::get_cao(ClientObjectRef *ref) GenericCAO *ClientObjectRef::get_generic_cao(ClientObjectRef *ref, lua_State *L) { ClientActiveObject *obj = get_cao(ref); - if (! obj) + if (!obj) return nullptr; ClientEnvironment &env = getClient(L)->getEnv(); GenericCAO *gcao = env.getGenericCAO(obj->getId()); @@ -59,7 +59,7 @@ int ClientObjectRef::l_get_pos(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); ClientActiveObject *cao = get_cao(ref); - if (! cao) + if (!cao) return 0; push_v3f(L, cao->getPosition() / BS); return 1; @@ -69,7 +69,7 @@ int ClientObjectRef::l_get_velocity(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; push_v3f(L, gcao->getVelocity() / BS); return 1; @@ -79,7 +79,7 @@ int ClientObjectRef::l_get_acceleration(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; push_v3f(L, gcao->getAcceleration() / BS); return 1; @@ -89,7 +89,7 @@ int ClientObjectRef::l_get_rotation(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; push_v3f(L, gcao->getRotation()); return 1; @@ -99,7 +99,7 @@ int ClientObjectRef::l_is_player(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; lua_pushboolean(L, gcao->isPlayer()); return 1; @@ -109,7 +109,7 @@ int ClientObjectRef::l_is_local_player(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; lua_pushboolean(L, gcao->isLocalPlayer()); return 1; @@ -119,7 +119,7 @@ int ClientObjectRef::l_get_name(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; lua_pushstring(L, gcao->getName().c_str()); return 1; @@ -129,10 +129,10 @@ int ClientObjectRef::l_get_attach(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ClientActiveObject *parent = gcao->getParent(); - if (! parent) + if (!parent) return 0; push_objectRef(L, parent->getId()); return 1; @@ -140,10 +140,11 @@ int ClientObjectRef::l_get_attach(lua_State *L) int ClientObjectRef::l_get_nametag(lua_State *L) { - log_deprecated(L,"Deprecated call to get_nametag, use get_properties().nametag instead"); + log_deprecated(L, "Deprecated call to get_nametag, use get_properties().nametag " + "instead"); ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ObjectProperties *props = gcao->getProperties(); lua_pushstring(L, props->nametag.c_str()); @@ -152,10 +153,11 @@ int ClientObjectRef::l_get_nametag(lua_State *L) int ClientObjectRef::l_get_item_textures(lua_State *L) { - log_deprecated(L,"Deprecated call to get_item_textures, use get_properties().textures instead"); + log_deprecated(L, "Deprecated call to get_item_textures, use " + "get_properties().textures instead"); ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ObjectProperties *props = gcao->getProperties(); lua_newtable(L); @@ -168,10 +170,11 @@ int ClientObjectRef::l_get_item_textures(lua_State *L) int ClientObjectRef::l_get_max_hp(lua_State *L) { - log_deprecated(L,"Deprecated call to get_max_hp, use get_properties().hp_max instead"); + log_deprecated(L, "Deprecated call to get_max_hp, use get_properties().hp_max " + "instead"); ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ObjectProperties *props = gcao->getProperties(); lua_pushnumber(L, props->hp_max); @@ -182,7 +185,7 @@ int ClientObjectRef::l_get_properties(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ObjectProperties *prop = gcao->getProperties(); push_object_properties(L, prop); @@ -193,7 +196,7 @@ int ClientObjectRef::l_set_properties(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; ObjectProperties prop = *gcao->getProperties(); read_object_properties(L, 2, nullptr, &prop, getClient(L)->idef()); @@ -205,7 +208,7 @@ int ClientObjectRef::l_get_hp(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; lua_pushnumber(L, gcao->getHp()); return 1; @@ -215,7 +218,7 @@ int ClientObjectRef::l_punch(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; PointedThing pointed(gcao->getId(), v3f(0, 0, 0), v3s16(0, 0, 0), 0); getClient(L)->interact(INTERACT_START_DIGGING, pointed); @@ -226,7 +229,7 @@ int ClientObjectRef::l_rightclick(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; PointedThing pointed(gcao->getId(), v3f(0, 0, 0), v3s16(0, 0, 0), 0); getClient(L)->interact(INTERACT_PLACE, pointed); @@ -237,7 +240,7 @@ int ClientObjectRef::l_remove(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); ClientActiveObject *cao = get_cao(ref); - if (! cao) + if (!cao) return 0; getClient(L)->getEnv().removeActiveObject(cao->getId()); @@ -248,12 +251,12 @@ int ClientObjectRef::l_set_nametag_images(lua_State *L) { ClientObjectRef *ref = checkobject(L, 1); GenericCAO *gcao = get_generic_cao(ref, L); - if (! gcao) + if (!gcao) return 0; gcao->nametag_images.clear(); - if(lua_istable(L, 2)){ + if (lua_istable(L, 2)) { lua_pushnil(L); - while(lua_next(L, 2) != 0){ + while (lua_next(L, 2) != 0) { gcao->nametag_images.push_back(lua_tostring(L, -1)); lua_pop(L, 1); } @@ -333,7 +336,6 @@ luaL_Reg ClientObjectRef::methods[] = {luamethod(ClientObjectRef, get_pos), luamethod(ClientObjectRef, get_properties), luamethod(ClientObjectRef, set_properties), luamethod(ClientObjectRef, get_hp), - luamethod(ClientObjectRef, get_max_hp), - luamethod(ClientObjectRef, punch), + luamethod(ClientObjectRef, get_max_hp), luamethod(ClientObjectRef, punch), luamethod(ClientObjectRef, rightclick), luamethod(ClientObjectRef, set_nametag_images), {0, 0}}; diff --git a/src/server/serverinventorymgr.h b/src/server/serverinventorymgr.h index 0e4b72415..b6541bd3c 100644 --- a/src/server/serverinventorymgr.h +++ b/src/server/serverinventorymgr.h @@ -43,7 +43,8 @@ public: Inventory *createDetachedInventory(const std::string &name, IItemDefManager *idef, const std::string &player = ""); bool removeDetachedInventory(const std::string &name); - bool checkDetachedInventoryAccess(const InventoryLocation &loc, const std::string &player) const; + bool checkDetachedInventoryAccess( + const InventoryLocation &loc, const std::string &player) const; void sendDetachedInventories(const std::string &peer_name, bool incremental, std::function apply_cb); -- cgit v1.2.3