]> git.lizzy.rs Git - minetest.git/blobdiff - src/network/serverpackethandler.cpp
Rename Scripting API files for consistency
[minetest.git] / src / network / serverpackethandler.cpp
index f99e104ec5b7259db1a8f40758d12024ec9b7d81..5b026bbdb03dffb3d27fcdaf60866efe8b07fe94 100644 (file)
@@ -23,10 +23,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_abm.h"
 #include "content_sao.h"
 #include "emerge.h"
+#include "mapblock.h"
 #include "nodedef.h"
 #include "player.h"
 #include "rollback_interface.h"
-#include "scripting_game.h"
+#include "scripting_server.h"
 #include "settings.h"
 #include "tool.h"
 #include "version.h"
@@ -613,20 +614,6 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
        u16 protocol_version = m_clients.getProtocolVersion(pkt->getPeerId());
 
 
-       ///// begin compatibility code
-       PlayerSAO* playersao = NULL;
-       if (protocol_version <= 22) {
-               playersao = StageTwoClientInit(pkt->getPeerId());
-
-               if (playersao == NULL) {
-                       actionstream
-                               << "TOSERVER_INIT2 stage 2 client init failed for peer "
-                               << pkt->getPeerId() << std::endl;
-                       return;
-               }
-       }
-       ///// end compatibility code
-
        /*
                Send some initialization data
        */
@@ -656,13 +643,6 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
        float time_speed = g_settings->getFloat("time_speed");
        SendTimeOfDay(pkt->getPeerId(), time, time_speed);
 
-       ///// begin compatibility code
-       if (protocol_version <= 22) {
-               m_clients.event(pkt->getPeerId(), CSE_SetClientReady);
-               m_script->on_joinplayer(playersao);
-       }
-       ///// end compatibility code
-
        // Warnings about protocol version can be issued here
        if (getClient(pkt->getPeerId())->net_proto_version < LATEST_PROTOCOL_VERSION) {
                SendChatMessage(pkt->getPeerId(), L"# Server: WARNING: YOUR CLIENT'S "
@@ -694,10 +674,6 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt)
        sendRequestedMedia(pkt->getPeerId(), tosend);
 }
 
-void Server::handleCommand_ReceivedMedia(NetworkPacket* pkt)
-{
-}
-
 void Server::handleCommand_ClientReady(NetworkPacket* pkt)
 {
        u16 peer_id = pkt->getPeerId();
@@ -742,6 +718,13 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt)
 
        m_clients.event(peer_id, CSE_SetClientReady);
        m_script->on_joinplayer(playersao);
+       // Send shutdown timer if shutdown has been scheduled
+       if (m_shutdown_timer > 0.0f) {
+               std::wstringstream ws;
+               ws << L"*** Server shutting down in "
+                               << duration_to_string(myround(m_shutdown_timer)).c_str() << ".";
+               SendChatMessage(pkt->getPeerId(), ws.str());
+       }
 }
 
 void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
@@ -810,7 +793,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
        v3f speed((f32)ss.X / 100.0, (f32)ss.Y / 100.0, (f32)ss.Z / 100.0);
 
        pitch = modulo360f(pitch);
-       yaw = modulo360f(yaw);
+       yaw = wrapDegrees_0_360(yaw);
 
        playersao->setBasePosition(position);
        player->setSpeed(speed);
@@ -1127,6 +1110,13 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
        }
 
        if (g_settings->getBool("enable_damage")) {
+               if (playersao->isDead()) {
+                       verbosestream << "Server::ProcessData(): Info: "
+                               "Ignoring damage as player " << player->getName()
+                               << " is already dead." << std::endl;
+                       return;
+               }
+
                actionstream << player->getName() << " damaged by "
                                << (int)damage << " hp at " << PP(playersao->getBasePosition() / BS)
                                << std::endl;
@@ -1136,46 +1126,6 @@ void Server::handleCommand_Damage(NetworkPacket* pkt)
        }
 }
 
-void Server::handleCommand_Breath(NetworkPacket* pkt)
-{
-       u16 breath;
-
-       *pkt >> breath;
-
-       RemotePlayer *player = m_env->getPlayer(pkt->getPeerId());
-
-       if (player == NULL) {
-               errorstream << "Server::ProcessData(): Canceling: "
-                               "No player for peer_id=" << pkt->getPeerId()
-                               << " disconnecting peer!" << std::endl;
-               m_con.DisconnectPeer(pkt->getPeerId());
-               return;
-       }
-
-
-       PlayerSAO *playersao = player->getPlayerSAO();
-       if (playersao == NULL) {
-               errorstream << "Server::ProcessData(): Canceling: "
-                               "No player object for peer_id=" << pkt->getPeerId()
-                               << " disconnecting peer!" << std::endl;
-               m_con.DisconnectPeer(pkt->getPeerId());
-               return;
-       }
-
-       /*
-        * If player is dead, we don't need to update the breath
-        * He is dead !
-        */
-       if (playersao->isDead()) {
-               verbosestream << "TOSERVER_BREATH: " << player->getName()
-                               << " is dead. Ignoring packet";
-               return;
-       }
-
-       playersao->setBreath(breath);
-       SendPlayerBreath(pkt->getPeerId());
-}
-
 void Server::handleCommand_Password(NetworkPacket* pkt)
 {
        if (pkt->getSize() != PASSWORD_SIZE * 2)
@@ -1435,12 +1385,16 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
                const ItemDefinition &playeritem_def =
                        playersao->getWieldedItem().getDefinition(m_itemdef);
                float max_d = BS * playeritem_def.range;
-               float max_d_hand = BS * m_itemdef->get("").range;
+               InventoryList *hlist = playersao->getInventory()->getList("hand");
+               const ItemDefinition &hand_def =
+                       hlist ? (hlist->getItem(0).getDefinition(m_itemdef)) : (m_itemdef->get(""));
+               float max_d_hand = BS * hand_def.range;
                if (max_d < 0 && max_d_hand >= 0)
                        max_d = max_d_hand;
                else if (max_d < 0)
                        max_d = BS * 4.0;
-               if (d > max_d * 1.5) {
+               // cube diagonal: sqrt(3) = 1.73
+               if (d > max_d * 1.73) {
                        actionstream << "Player " << player->getName()
                                        << " tried to access " << pointed.dump()
                                        << " from too far: "
@@ -1495,7 +1449,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
                                        <<pointed.object_id<<": "
                                        <<pointed_object->getDescription()<<std::endl;
 
-                       ItemStack punchitem = playersao->getWieldedItem();
+                       ItemStack punchitem = playersao->getWieldedItemOrHand();
                        ToolCapabilities toolcap =
                                        punchitem.getToolCapabilities(m_itemdef);
                        v3f dir = (pointed_object->getBasePosition() -
@@ -1562,7 +1516,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
                                        m_script->on_cheat(playersao, "finished_unknown_dig");
                                }
                                // Get player's wielded item
-                               ItemStack playeritem = playersao->getWieldedItem();
+                               ItemStack playeritem = playersao->getWieldedItemOrHand();
                                ToolCapabilities playeritem_toolcap =
                                                playeritem.getToolCapabilities(m_itemdef);
                                // Get diggability and expected digging time
@@ -1570,7 +1524,9 @@ void Server::handleCommand_Interact(NetworkPacket* pkt)
                                                &playeritem_toolcap);
                                // If can't dig, try hand
                                if (!params.diggable) {
-                                       const ItemDefinition &hand = m_itemdef->get("");
+                                       InventoryList *hlist = playersao->getInventory()->getList("hand");
+                                       const ItemDefinition &hand =
+                                               hlist ? hlist->getItem(0).getDefinition(m_itemdef) : m_itemdef->get("");
                                        const ToolCapabilities *tp = hand.tool_capabilities;
                                        if (tp)
                                                params = getDigParams(m_nodedef->get(n).groups, tp);