Add set_breath and get_breath to lua API.
[oweals/minetest.git] / src / server.cpp
index 1618a091522f885f29df63c49009135026a78558..3bba193da5365c903a4d297d9ee9afba6a669369 100644 (file)
@@ -1139,6 +1139,13 @@ void Server::AsyncRunStep()
                                        SendPlayerHP(client->peer_id);
                        }
 
+                       /*
+                               Send player breath if changed
+                       */
+                       if(playersao->m_breath_not_sent){
+                               SendPlayerBreath(client->peer_id);
+                       }
+
                        /*
                                Send player inventories if necessary
                        */
@@ -1237,7 +1244,7 @@ void Server::AsyncRunStep()
                float &counter = m_masterserver_timer;
                if((!counter || counter >= 300.0) && g_settings->getBool("server_announce") == true)
                {
-                       ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_number, m_uptime.get(), m_gamespec.id);
+                       ServerList::sendAnnounce(!counter ? "start" : "update", m_clients_number, m_uptime.get(), m_gamespec.id, m_mods);
                        counter = 0.01;
                }
                counter += dtime;
@@ -1922,6 +1929,15 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        return;
                }
 
+               if(!isSingleplayer() && strcasecmp(playername, "singleplayer") == 0)
+               {
+                       actionstream<<"Server: Player with an invalid name "
+                                       <<"tried to connect from "<<addr_s<<std::endl;
+                       SendAccessDenied(m_con, peer_id,
+                                       L"Name is not allowed");
+                       return;
+               }
+
                infostream<<"Server: New connection: \""<<playername<<"\" from "
                                <<m_con.GetPeerAddress(peer_id).serializeString()<<std::endl;
 
@@ -2096,6 +2112,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                if(g_settings->getBool("enable_damage"))
                        SendPlayerHP(peer_id);
 
+               // Send Breath
+               SendPlayerBreath(peer_id);
+
                // Send detached inventories
                sendDetachedInventories(peer_id);
 
@@ -2574,6 +2593,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                SendPlayerHP(peer_id);
                }
        }
+       else if(command == TOSERVER_BREATH)
+       {
+               std::string datastring((char*)&data[2], datasize-2);
+               std::istringstream is(datastring, std::ios_base::binary);
+               u16 breath = readU16(is);
+               playersao->setBreath(breath);
+       }
        else if(command == TOSERVER_PASSWORD)
        {
                /*
@@ -3317,6 +3343,21 @@ void Server::SendHP(con::Connection &con, u16 peer_id, u8 hp)
        con.Send(peer_id, 0, data, true);
 }
 
+void Server::SendBreath(con::Connection &con, u16 peer_id, u16 breath)
+{
+       DSTACK(__FUNCTION_NAME);
+       std::ostringstream os(std::ios_base::binary);
+
+       writeU16(os, TOCLIENT_BREATH);
+       writeU16(os, breath);
+
+       // Make data buffer
+       std::string s = os.str();
+       SharedBuffer<u8> data((u8*)s.c_str(), s.size());
+       // Send as reliable
+       con.Send(peer_id, 0, data, true);
+}
+
 void Server::SendAccessDenied(con::Connection &con, u16 peer_id,
                const std::wstring &reason)
 {
@@ -3746,6 +3787,15 @@ void Server::SendPlayerHP(u16 peer_id)
        SendHP(m_con, peer_id, playersao->getHP());
 }
 
+void Server::SendPlayerBreath(u16 peer_id)
+{
+       DSTACK(__FUNCTION_NAME);
+       PlayerSAO *playersao = getPlayerSAO(peer_id);
+       assert(playersao);
+       playersao->m_breath_not_sent = false;
+       SendBreath(m_con, peer_id, playersao->getBreath());
+}
+
 void Server::SendMovePlayer(u16 peer_id)
 {
        DSTACK(__FUNCTION_NAME);