]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server.cpp
Fix doc and forceloading crash.
[dragonfireclient.git] / src / server.cpp
index 09c2ca6634c5e92d3558e21a11f904f7bfc44f78..b257448a1c4e2de8b1b7091ffd74e103352e4c2a 100644 (file)
@@ -90,14 +90,15 @@ class ServerThread : public JThread
 
 void * ServerThread::Thread()
 {
-       ThreadStarted();
-
        log_register_thread("ServerThread");
 
        DSTACK(__FUNCTION_NAME);
-
        BEGIN_DEBUG_EXCEPTION_HANDLER
 
+       m_server->AsyncRunStep(true);
+
+       ThreadStarted();
+
        while(!StopRequested())
        {
                try{
@@ -675,6 +676,7 @@ Server::Server(
        m_savemap_timer = 0.0;
 
        m_step_dtime = 0.0;
+       m_lag = g_settings->getFloat("dedicated_server_step");
 
        if(path_world == "")
                throw ServerError("Supplied empty world path");
@@ -1017,7 +1019,7 @@ void Server::step(float dtime)
        }
 }
 
-void Server::AsyncRunStep()
+void Server::AsyncRunStep(bool initial_step)
 {
        DSTACK(__FUNCTION_NAME);
 
@@ -1034,7 +1036,7 @@ void Server::AsyncRunStep()
                SendBlocks(dtime);
        }
 
-       if(dtime < 0.001)
+       if((dtime < 0.001) && (initial_step == false))
                return;
 
        g_profiler->add("Server::AsyncRunStep with dtime (num)", 1);
@@ -1260,13 +1262,14 @@ void Server::AsyncRunStep()
        }
 
 
+       m_lag += (m_lag > dtime ? -1 : 1) * dtime/100;
 #if USE_CURL
        // send masterserver announce
        {
                float &counter = m_masterserver_timer;
                if(!isSingleplayer() && (!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true)
                {
-                       ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_names, m_uptime.get(), m_env->getGameTime(), m_gamespec.id, m_mods);
+                       ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_names, m_uptime.get(), m_env->getGameTime(), m_lag, m_gamespec.id, m_mods);
                        counter = 0.01;
                }
                counter += dtime;
@@ -1526,7 +1529,7 @@ void Server::AsyncRunStep()
                                memcpy((char*)&reply[2], unreliable_data.c_str(),
                                                unreliable_data.size());
                                // Send as unreliable
-                               m_con.Send(client->peer_id, 0, reply, false);
+                               m_con.Send(client->peer_id, 1, reply, false);
                        }
 
                        /*if(reliable_data.size() > 0 || unreliable_data.size() > 0)
@@ -2298,9 +2301,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                }
 
                /*infostream<<"Server::ProcessData(): Moved player "<<peer_id<<" to "
-                                                                                                                       <<"("<<position.X<<","<<position.Y<<","<<position.Z<<")"
-                                                                                                                       <<" pitch="<<pitch<<" yaw="<<yaw<<std::endl;*/
-
+                               <<"("<<position.X<<","<<position.Y<<","<<position.Z<<")"
+                               <<" pitch="<<pitch<<" yaw="<<yaw<<std::endl;*/
        }
        else if(command == TOSERVER_GOTBLOCKS)
        {
@@ -3720,7 +3722,7 @@ void Server::SendHUDAdd(u16 peer_id, u32 id, HudElement *form)
        std::string s = os.str();
        SharedBuffer<u8> data((u8*)s.c_str(), s.size());
        // Send as reliable
-       m_con.Send(peer_id, 0, data, true);
+       m_con.Send(peer_id, 1, data, true);
 }
 
 void Server::SendHUDRemove(u16 peer_id, u32 id)
@@ -3735,7 +3737,8 @@ void Server::SendHUDRemove(u16 peer_id, u32 id)
        std::string s = os.str();
        SharedBuffer<u8> data((u8*)s.c_str(), s.size());
        // Send as reliable
-       m_con.Send(peer_id, 0, data, true);
+
+       m_con.Send(peer_id, 1, data, true);
 }
 
 void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value)
@@ -4203,7 +4206,7 @@ void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver, u16 net_proto
        /*
                Send packet
        */
-       m_con.Send(peer_id, 1, reply, true);
+       m_con.Send(peer_id, 2, reply, true);
 }
 
 void Server::SendBlocks(float dtime)
@@ -4565,7 +4568,7 @@ void Server::sendRequestedMedia(u16 peer_id,
                                <<" size=" <<s.size()<<std::endl;
                SharedBuffer<u8> data((u8*)s.c_str(), s.size());
                // Send as reliable
-               m_con.Send(peer_id, 0, data, true);
+               m_con.Send(peer_id, 2, data, true);
        }
 }
 
@@ -5334,10 +5337,10 @@ v3f findSpawnPos(ServerMap &map)
                                -range + (myrand() % (range * 2)));
 
                // Get ground height at point
-               s16 groundheight = map.findGroundLevel(nodepos2d, g_settings->getBool("cache_block_before_spawn"));
+               s16 groundheight = map.findGroundLevel(nodepos2d);
                if (groundheight <= water_level) // Don't go underwater
                        continue;
-               if (groundheight > water_level + g_settings->getS16("max_spawn_height")) // Don't go to high places
+               if (groundheight > water_level + 6) // Don't go to high places
                        continue;
 
                nodepos = v3s16(nodepos2d.X, groundheight, nodepos2d.Y);