X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fserver.cpp;h=a20e82856e889c44a408f5b3efd3f8b7a52cdf67;hb=7701e70dc92262c41d68cf1c9f7fbd0c333e5c52;hp=93767da9d1ff1b04340f94b79d88e9567ffd3c05;hpb=4648d8f4997963ac050f356b664a07caadd66587;p=minetest.git diff --git a/src/server.cpp b/src/server.cpp index 93767da9d..a20e82856 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -67,6 +67,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "server/serverinventorymgr.h" #include "translation.h" #include "database/database-sqlite3.h" +#if USE_POSTGRESQL +#include "database/database-postgresql.h" +#endif #include "database/database-files.h" #include "database/database-dummy.h" #include "gameparams.h" @@ -424,15 +427,11 @@ void Server::init() m_mod_storage_database->beginSave(); m_modmgr = std::make_unique(m_path_world); - std::vector unsatisfied_mods = m_modmgr->getUnsatisfiedMods(); // complain about mods with unsatisfied dependencies if (!m_modmgr->isConsistent()) { - m_modmgr->printUnsatisfiedModsError(); - - warningstream - << "You have unsatisfied dependencies, loading your world anyway. " - << "This will become a fatal error in the future." << std::endl; + std::string error = m_modmgr->getUnsatisfiedModsError(); + throw ServerError(error); } //lock environment @@ -451,6 +450,7 @@ void Server::init() m_inventory_mgr = std::make_unique(); m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME); + m_script->checkSetByBuiltin(); m_gamespec.checkAndLog(); m_modmgr->loadMods(m_script); @@ -486,6 +486,7 @@ void Server::init() m_startup_server_map = nullptr; // Ownership moved to ServerEnvironment m_env = new ServerEnvironment(servermap, m_script, this, m_path_world, m_metrics_backend.get()); + m_env->init(); m_inventory_mgr->setEnv(m_env); m_clients.setEnv(m_env); @@ -695,11 +696,13 @@ void Server::AsyncRunStep(bool initial_step) std::map modified_blocks; m_env->getServerMap().transformLiquids(modified_blocks, m_env); - /* - Set the modified blocks unsent for all the clients - */ if (!modified_blocks.empty()) { - SetBlocksNotSent(modified_blocks); + MapEditEvent event; + event.type = MEET_OTHER; + for (const auto &pair : modified_blocks) { + event.modified_blocks.insert(pair.first); + } + m_env->getMap().dispatchEvent(event); } } m_clients.step(dtime); @@ -1094,7 +1097,7 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id) if (!playersao || !player) { if (player && player->getPeerId() != PEER_ID_INEXISTENT) { actionstream << "Server: Failed to emerge player \"" << playername - << "\" (player allocated to an another client)" << std::endl; + << "\" (player allocated to another client)" << std::endl; DenyAccess(peer_id, SERVER_ACCESSDENIED_ALREADY_CONNECTED); } else { errorstream << "Server: " << playername << ": Failed to emerge player" @@ -1252,17 +1255,6 @@ void Server::onMapEditEvent(const MapEditEvent &event) m_unsent_map_edit_queue.push(new MapEditEvent(event)); } -void Server::SetBlocksNotSent(std::map& block) -{ - std::vector clients = m_clients.getClientIDs(); - ClientInterface::AutoLock clientlock(m_clients); - // Set the modified blocks unsent for all the clients - for (const session_t client_id : clients) { - if (RemoteClient *client = m_clients.lockedGetClientNoEx(client_id)) - client->SetBlocksNotSent(block); - } -} - void Server::peerAdded(con::Peer *peer) { verbosestream<<"Server::peerAdded(): peer->id=" @@ -1363,8 +1355,6 @@ void Server::Send(session_t peer_id, NetworkPacket *pkt) void Server::SendMovement(session_t peer_id) { - std::ostringstream os(std::ios_base::binary); - NetworkPacket pkt(TOCLIENT_MOVEMENT, 12 * sizeof(float), peer_id); pkt << g_settings->getFloat("movement_acceleration_default"); @@ -1874,7 +1864,7 @@ void Server::SendSetLighting(session_t peer_id, const Lighting &lighting) { NetworkPacket pkt(TOCLIENT_SET_LIGHTING, 4, peer_id); - + pkt << lighting.shadow_intensity; Send(&pkt); @@ -2255,50 +2245,31 @@ void Server::fadeSound(s32 handle, float step, float gain) void Server::sendRemoveNode(v3s16 p, std::unordered_set *far_players, float far_d_nodes) { - float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); v3s16 block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_REMOVENODE, 6); pkt << p; - std::vector clients = m_clients.getClientIDs(); - ClientInterface::AutoLock clientlock(m_clients); - - for (session_t client_id : clients) { - RemoteClient *client = m_clients.lockedGetClientNoEx(client_id); - if (!client) - continue; - - RemotePlayer *player = m_env->getPlayer(client_id); - PlayerSAO *sao = player ? player->getPlayerSAO() : nullptr; - - // If player is far away, only set modified blocks not sent - if (!client->isBlockSent(block_pos) || (sao && - sao->getBasePosition().getDistanceFrom(p_f) > maxd)) { - if (far_players) - far_players->emplace(client_id); - else - client->SetBlockNotSent(block_pos); - continue; - } - - // Send as reliable - m_clients.send(client_id, 0, &pkt, true); - } + sendNodeChangePkt(pkt, block_pos, p_f, far_d_nodes, far_players); } void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set *far_players, float far_d_nodes, bool remove_metadata) { - float maxd = far_d_nodes * BS; v3f p_f = intToFloat(p, BS); v3s16 block_pos = getNodeBlockPos(p); NetworkPacket pkt(TOCLIENT_ADDNODE, 6 + 2 + 1 + 1 + 1); pkt << p << n.param0 << n.param1 << n.param2 << (u8) (remove_metadata ? 0 : 1); + sendNodeChangePkt(pkt, block_pos, p_f, far_d_nodes, far_players); +} +void Server::sendNodeChangePkt(NetworkPacket &pkt, v3s16 block_pos, + v3f p, float far_d_nodes, std::unordered_set *far_players) +{ + float maxd = far_d_nodes * BS; std::vector clients = m_clients.getClientIDs(); ClientInterface::AutoLock clientlock(m_clients); @@ -2312,7 +2283,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, std::unordered_set *far_player // If player is far away, only set modified blocks not sent if (!client->isBlockSent(block_pos) || (sao && - sao->getBasePosition().getDistanceFrom(p_f) > maxd)) { + sao->getBasePosition().getDistanceFrom(p) > maxd)) { if (far_players) far_players->emplace(client_id); else @@ -3888,25 +3859,6 @@ PlayerSAO* Server::emergePlayer(const char *name, session_t peer_id, u16 proto_v return playersao; } -bool Server::registerModStorage(ModMetadata *storage) -{ - if (m_mod_storages.find(storage->getModName()) != m_mod_storages.end()) { - errorstream << "Unable to register same mod storage twice. Storage name: " - << storage->getModName() << std::endl; - return false; - } - - m_mod_storages[storage->getModName()] = storage; - return true; -} - -void Server::unregisterModStorage(const std::string &name) -{ - std::unordered_map::const_iterator it = m_mod_storages.find(name); - if (it != m_mod_storages.end()) - m_mod_storages.erase(name); -} - void dedicated_server_loop(Server &server, bool &kill) { verbosestream<<"dedicated_server_loop()"<