]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server.cpp
Mgv7 mountains: Remove divide by zero code that creates vast walls
[dragonfireclient.git] / src / server.cpp
index 857114d0f0fc12461fd5a9c4840aa1c141d813d6..399c41b70afe5ac10321e9237ff2c8b6cf462e0a 100644 (file)
@@ -194,7 +194,8 @@ Server::Server(
        m_clients(&m_con),
        m_shutdown_requested(false),
        m_ignore_map_edit_events(false),
-       m_ignore_map_edit_events_peer_id(0)
+       m_ignore_map_edit_events_peer_id(0),
+       m_next_sound_id(0)
 
 {
        m_liquid_transform_timer = 0.0;
@@ -295,6 +296,12 @@ Server::Server(
        // Lock environment
        JMutexAutoLock envlock(m_env_mutex);
 
+       // Load mapgen params from Settings
+       m_emerge->loadMapgenParams();
+
+       // Create the Map (loads map_meta.txt, overriding configured mapgen params)
+       ServerMap *servermap = new ServerMap(path_world, this, m_emerge);
+
        // Initialize scripting
        infostream<<"Server: Initializing Lua"<<std::endl;
 
@@ -302,10 +309,8 @@ Server::Server(
 
        std::string scriptpath = getBuiltinLuaPath() + DIR_DELIM "init.lua";
 
-       if (!m_script->loadScript(scriptpath)) {
+       if (!m_script->loadScript(scriptpath))
                throw ModError("Failed to load and run " + scriptpath);
-       }
-
 
        // Print 'em
        infostream<<"Server: Loading mods: ";
@@ -336,22 +341,16 @@ Server::Server(
        // Apply item aliases in the node definition manager
        m_nodedef->updateAliases(m_itemdef);
 
-       // Perform pending node name resolutions
-       m_nodedef->getResolver()->resolveNodes();
+       m_nodedef->setNodeRegistrationStatus(true);
 
-       // Load the mapgen params from global settings now after any
-       // initial overrides have been set by the mods
-       m_emerge->loadMapgenParams();
+       // Perform pending node name resolutions
+       m_nodedef->runNodeResolverCallbacks();
 
        // Initialize Environment
-       ServerMap *servermap = new ServerMap(path_world, this, m_emerge);
        m_env = new ServerEnvironment(servermap, m_script, this, m_path_world);
 
        m_clients.setEnv(m_env);
 
-       // Run some callbacks after the MG params have been set up but before activation
-       m_script->environment_OnMapgenInit(&m_emerge->params);
-
        // Initialize mapgens
        m_emerge->initMapgens();
 
@@ -430,6 +429,9 @@ Server::~Server()
 void Server::start(Address bind_addr)
 {
        DSTACK(__FUNCTION_NAME);
+
+       m_bind_addr = bind_addr;
+
        infostream<<"Starting server on "
                        << bind_addr.serializeString() <<"..."<<std::endl;
 
@@ -568,7 +570,7 @@ void Server::AsyncRunStep(bool initial_step)
                m_env->step(dtime);
        }
 
-       const float map_timer_and_unload_dtime = 2.92;
+       static const float map_timer_and_unload_dtime = 2.92;
        if(m_map_timer_and_unload_interval.step(dtime, map_timer_and_unload_dtime))
        {
                JMutexAutoLock lock(m_env_mutex);
@@ -664,7 +666,7 @@ void Server::AsyncRunStep(bool initial_step)
                /*
                        Set the modified blocks unsent for all the clients
                */
-               if(modified_blocks.size() > 0)
+               if(!modified_blocks.empty())
                {
                        SetBlocksNotSent(modified_blocks);
                }
@@ -680,6 +682,7 @@ void Server::AsyncRunStep(bool initial_step)
                                g_settings->getBool("server_announce"))
                {
                        ServerList::sendAnnounce(counter ? "update" : "start",
+                                       m_bind_addr.getPort(),
                                        m_clients.getPlayerNames(),
                                        m_uptime.get(),
                                        m_env->getGameTime(),
@@ -745,7 +748,7 @@ void Server::AsyncRunStep(bool initial_step)
                                        client->m_known_objects, added_objects);
 
                        // Ignore if nothing happened
-                       if(removed_objects.size() == 0 && added_objects.size() == 0)
+                       if(removed_objects.empty() && added_objects.empty())
                        {
                                //infostream<<"active objects: none changed"<<std::endl;
                                continue;
@@ -1051,7 +1054,7 @@ void Server::AsyncRunStep(bool initial_step)
                        /*
                                Set blocks not sent to far players
                        */
-                       if(far_players.size() > 0)
+                       if(!far_players.empty())
                        {
                                // Convert list format to that wanted by SetBlocksNotSent
                                std::map<v3s16, MapBlock*> modified_blocks2;
@@ -1361,9 +1364,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                u8 client_max = data[2];
                u8 our_max = SER_FMT_VER_HIGHEST_READ;
                // Use the highest version supported by both
-               u8 deployed = std::min(client_max, our_max);
+               int deployed = std::min(client_max, our_max);
                // If it's lower than the lowest supported, give up.
-               if(deployed < SER_FMT_VER_LOWEST)
+               if(deployed < SER_FMT_CLIENT_VER_LOWEST)
                        deployed = SER_FMT_VER_INVALID;
 
                if(deployed == SER_FMT_VER_INVALID)
@@ -1510,7 +1513,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                                <<"tried to connect from "<<addr_s<<" "
                                                <<"but it was disallowed for the following reason: "
                                                <<reason<<std::endl;
-                               DenyAccess(peer_id, narrow_to_wide(reason.c_str()));
+                               DenyAccess(peer_id, narrow_to_wide(reason));
                                return;
                        }
                }
@@ -2650,7 +2653,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        }
 
                } // action == 4
-               
+
 
                /*
                        Catch invalid actions
@@ -2675,7 +2678,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                continue;
                        ServerPlayingSound &psound = i->second;
                        psound.clients.erase(peer_id);
-                       if(psound.clients.size() == 0)
+                       if(psound.clients.empty())
                                m_playing_sounds.erase(i++);
                }
        }
@@ -3628,7 +3631,7 @@ s32 Server::playSound(const SimpleSoundSpec &spec,
                        dst_clients.push_back(*i);
                }
        }
-       if(dst_clients.size() == 0)
+       if(dst_clients.empty())
                return -1;
 
        // Create the sound
@@ -4291,6 +4294,7 @@ void Server::RespawnPlayer(u16 peer_id)
                        <<" respawns"<<std::endl;
 
        playersao->setHP(PLAYER_MAX_HP);
+       playersao->setBreath(PLAYER_MAX_BREATH);
 
        bool repositioned = m_script->on_respawnplayer(playersao);
        if(!repositioned){
@@ -4322,7 +4326,7 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason)
                {
                        ServerPlayingSound &psound = i->second;
                        psound.clients.erase(peer_id);
-                       if(psound.clients.size() == 0)
+                       if(psound.clients.empty())
                                m_playing_sounds.erase(i++);
                        else
                                i++;
@@ -4468,7 +4472,7 @@ std::wstring Server::getStatusString()
                        name = narrow_to_wide(player->getName());
                // Add name to information string
                if(!first)
-                       os<<L",";
+                       os<<L", ";
                else
                        first = false;
                os<<name;
@@ -4570,7 +4574,7 @@ bool Server::showFormspec(const char *playername, const std::string &formspec, c
 u32 Server::hudAdd(Player *player, HudElement *form) {
        if (!player)
                return -1;
-       
+
        u32 id = player->addHud(form);
 
        SendHUDAdd(player->peer_id, id, form);
@@ -4586,7 +4590,7 @@ bool Server::hudRemove(Player *player, u32 id) {
 
        if (!todel)
                return false;
-       
+
        delete todel;
 
        SendHUDRemove(player->peer_id, id);
@@ -4607,9 +4611,9 @@ bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) {
 
        SendHUDSetFlags(player->peer_id, flags, mask);
        player->hud_flags = flags;
-       
+
        PlayerSAO* playersao = player->getPlayerSAO();
-       
+
        if (playersao == NULL)
                return false;
 
@@ -5095,8 +5099,8 @@ void dedicated_server_loop(Server &server, bool &kill)
                {
                        infostream<<"Dedicated server quitting"<<std::endl;
 #if USE_CURL
-                       if(g_settings->getBool("server_announce") == true)
-                               ServerList::sendAnnounce("delete");
+                       if(g_settings->getBool("server_announce"))
+                               ServerList::sendAnnounce("delete", server.m_bind_addr.getPort());
 #endif
                        break;
                }