]> git.lizzy.rs Git - minetest.git/blobdiff - src/network/serverpackethandler.cpp
Clean up ClientEvent hudadd/hudchange internals
[minetest.git] / src / network / serverpackethandler.cpp
index 0bd09e63766fed7bf57b4a7cb91e05227e8cf37b..ddc6f4e47c4ecb64d75a9c9f44d7476244a842bd 100644 (file)
@@ -56,12 +56,12 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
        session_t peer_id = pkt->getPeerId();
        RemoteClient *client = getClient(peer_id, CS_Created);
 
+       Address addr;
        std::string addr_s;
        try {
-               Address address = getPeerAddress(peer_id);
-               addr_s = address.serializeString();
-       }
-       catch (con::PeerNotFoundException &e) {
+               addr = m_con->GetPeerAddress(peer_id);
+               addr_s = addr.serializeString();
+       } catch (con::PeerNotFoundException &e) {
                /*
                 * no peer for this packet found
                 * most common reason is peer timeout, e.g. peer didn't
@@ -73,13 +73,14 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
                return;
        }
 
-       // If net_proto_version is set, this client has already been handled
        if (client->getState() > CS_Created) {
                verbosestream << "Server: Ignoring multiple TOSERVER_INITs from " <<
                        addr_s << " (peer_id=" << peer_id << ")" << std::endl;
                return;
        }
 
+       client->setCachedAddress(addr);
+
        verbosestream << "Server: Got TOSERVER_INIT from " << addr_s <<
                " (peer_id=" << peer_id << ")" << std::endl;
 
@@ -316,7 +317,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt)
        // Send active objects
        {
                PlayerSAO *sao = getPlayerSAO(peer_id);
-               if (client && sao)
+               if (sao)
                        SendActiveObjectRemoveAdd(client, sao);
        }
 
@@ -437,18 +438,20 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
        u8 count;
        *pkt >> count;
 
-       RemoteClient *client = getClient(pkt->getPeerId());
-
        if ((s16)pkt->getSize() < 1 + (int)count * 6) {
                throw con::InvalidIncomingDataException
                                ("GOTBLOCKS length is too short");
        }
 
+       m_clients.lock();
+       RemoteClient *client = m_clients.lockedGetClientNoEx(pkt->getPeerId());
+
        for (u16 i = 0; i < count; i++) {
                v3s16 p;
                *pkt >> p;
                client->GotBlock(p);
        }
+       m_clients.unlock();
 }
 
 void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
@@ -485,8 +488,12 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
        pitch = modulo360f(pitch);
        yaw = wrapDegrees_0_360(yaw);
 
-       playersao->setBasePosition(position);
-       player->setSpeed(speed);
+       if (!playersao->isAttached()) {
+               // Only update player positions when moving freely
+               // to not interfere with attachment handling
+               playersao->setBasePosition(position);
+               player->setSpeed(speed);
+       }
        playersao->setLookPitch(pitch);
        playersao->setPlayerYaw(yaw);
        playersao->setFov(fov);
@@ -749,21 +756,8 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
 
 void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
 {
-       /*
-               u16 command
-               u16 length
-               wstring message
-       */
-       u16 len;
-       *pkt >> len;
-
        std::wstring message;
-       for (u16 i = 0; i < len; i++) {
-               u16 tmp_wchar;
-               *pkt >> tmp_wchar;
-
-               message += (wchar_t)tmp_wchar;
-       }
+       *pkt >> message;
 
        session_t peer_id = pkt->getPeerId();
        RemotePlayer *player = m_env->getPlayer(peer_id);
@@ -775,15 +769,13 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt)
                return;
        }
 
-       // Get player name of this client
        std::string name = player->getName();
-       std::wstring wname = narrow_to_wide(name);
 
-       std::wstring answer_to_sender = handleChat(name, wname, message, true, player);
+       std::wstring answer_to_sender = handleChat(name, message, true, player);
        if (!answer_to_sender.empty()) {
                // Send the answer to sender
-               SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_NORMAL,
-                       answer_to_sender, wname));
+               SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
+                       answer_to_sender));
        }
 }
 
@@ -1050,12 +1042,13 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
                }
                float d = playersao->getEyePosition().getDistanceFrom(target_pos);
 
-               if (!checkInteractDistance(player, d, pointed.dump())
-                               && pointed.type == POINTEDTHING_NODE) {
-                       // Re-send block to revert change on client-side
-                       RemoteClient *client = getClient(peer_id);
-                       v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface);
-                       client->SetBlockNotSent(blockpos);
+               if (!checkInteractDistance(player, d, pointed.dump())) {
+                       if (pointed.type == POINTEDTHING_NODE) {
+                               // Re-send block to revert change on client-side
+                               RemoteClient *client = getClient(peer_id);
+                               v3s16 blockpos = getNodeBlockPos(pointed.node_undersurface);
+                               client->SetBlockNotSent(blockpos);
+                       }
                        return;
                }
        }
@@ -1656,19 +1649,18 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
 
        bool wantSudo = (cstate == CS_Active);
 
-       verbosestream << "Server: Received TOCLIENT_SRP_BYTES_M." << std::endl;
+       verbosestream << "Server: Received TOSERVER_SRP_BYTES_M." << std::endl;
 
        if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) {
-               actionstream << "Server: got SRP _M packet in wrong state "
-                       << cstate << " from " << addr_s
-                       << ". Ignoring." << std::endl;
+               warningstream << "Server: got SRP_M packet in wrong state "
+                       << cstate << " from " << addr_s << ". Ignoring." << std::endl;
                return;
        }
 
        if (client->chosen_mech != AUTH_MECHANISM_SRP &&
                        client->chosen_mech != AUTH_MECHANISM_LEGACY_PASSWORD) {
-               actionstream << "Server: got SRP _M packet, while auth"
-                       << "is going on with mech " << client->chosen_mech << " from "
+               warningstream << "Server: got SRP_M packet, while auth "
+                       "is going on with mech " << client->chosen_mech << " from "
                        << addr_s << " (wantSudo=" << wantSudo << "). Denying." << std::endl;
                if (wantSudo) {
                        DenySudoAccess(peer_id);
@@ -1716,7 +1708,7 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
 
                std::string checkpwd; // not used, but needed for passing something
                if (!m_script->getAuth(playername, &checkpwd, NULL)) {
-                       actionstream << "Server: " << playername <<
+                       errorstream << "Server: " << playername <<
                                " cannot be authenticated (auth handler does not work?)" <<
                                std::endl;
                        DenyAccess(peer_id, SERVER_ACCESSDENIED_SERVER_FAIL);