]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/clientiface.cpp
New lighting curve (#5279)
[dragonfireclient.git] / src / clientiface.cpp
index b79d36ea2f1922e4e3a3e2ec3ee7ff3cac65101e..f07f02012fc38411d79087da8c3218e9821f793f 100644 (file)
@@ -18,18 +18,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include <sstream>
-
 #include "clientiface.h"
+#include "network/connection.h"
+#include "network/serveropcodes.h"
 #include "remoteplayer.h"
 #include "settings.h"
 #include "mapblock.h"
-#include "network/connection.h"
 #include "serverenvironment.h"
 #include "map.h"
 #include "emerge.h"
 #include "content_sao.h"              // TODO this is used for cleanup of only
 #include "log.h"
-#include "network/serveropcodes.h"
 #include "util/srp.h"
 #include "face_position_cache.h"
 
@@ -79,11 +78,11 @@ void RemoteClient::GetNextBlocks (
 
        RemotePlayer *player = env->getPlayer(peer_id);
        // This can happen sometimes; clients and players are not in perfect sync.
-       if (player == NULL)
+       if (!player)
                return;
 
        PlayerSAO *sao = player->getPlayerSAO();
-       if (sao == NULL)
+       if (!sao)
                return;
 
        // Won't send anything if already sending
@@ -95,7 +94,7 @@ void RemoteClient::GetNextBlocks (
        }
 
        v3f playerpos = sao->getBasePosition();
-       v3f playerspeed = player->getSpeed();
+       const v3f &playerspeed = player->getSpeed();
        v3f playerspeeddir(0,0,0);
        if(playerspeed.getLength() > 1.0*BS)
                playerspeeddir = playerspeed / playerspeed.getLength();
@@ -275,8 +274,7 @@ void RemoteClient::GetNextBlocks (
 
                        bool surely_not_found_on_disk = false;
                        bool block_is_invalid = false;
-                       if(block != NULL)
-                       {
+                       if (block) {
                                // Reset usage timer, this block will be of use in the future.
                                block->resetUsageTimer();
 
@@ -624,15 +622,24 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
        std::vector<u16> reply;
        MutexAutoLock clientslock(m_clients_mutex);
 
-       for (RemoteClientMap::iterator i = m_clients.begin();
-               i != m_clients.end(); ++i) {
-               if (i->second->getState() >= min_state)
-                       reply.push_back(i->second->peer_id);
+       for (const auto &m_client : m_clients) {
+               if (m_client.second->getState() >= min_state)
+                       reply.push_back(m_client.second->peer_id);
        }
 
        return reply;
 }
 
+/**
+ * Verify if user limit was reached.
+ * User limit count all clients from HelloSent state (MT protocol user) to Active state
+ * @return true if user limit was reached
+ */
+bool ClientInterface::isUserLimitReached()
+{
+       return getClientIDs(CS_HelloSent).size() >= g_settings->getU16("max_users");
+}
+
 void ClientInterface::step(float dtime)
 {
        m_print_info_timer += dtime;
@@ -645,7 +652,7 @@ void ClientInterface::step(float dtime)
 
 void ClientInterface::UpdatePlayerList()
 {
-       if (m_env != NULL) {
+       if (m_env) {
                std::vector<u16> clients = getClientIDs();
                m_clients_names.clear();
 
@@ -664,7 +671,7 @@ void ClientInterface::UpdatePlayerList()
                        {
                                MutexAutoLock clientslock(m_clients_mutex);
                                RemoteClient* client = lockedGetClientNoEx(*i);
-                               if(client != NULL)
+                               if (client)
                                        client->PrintInfo(infostream);
                        }
 
@@ -694,6 +701,32 @@ void ClientInterface::sendToAll(NetworkPacket *pkt)
        }
 }
 
+void ClientInterface::sendToAllCompat(NetworkPacket *pkt, NetworkPacket *legacypkt,
+               u16 min_proto_ver)
+{
+       MutexAutoLock clientslock(m_clients_mutex);
+       for (std::unordered_map<u16, RemoteClient*>::iterator i = m_clients.begin();
+                       i != m_clients.end(); ++i) {
+               RemoteClient *client = i->second;
+               NetworkPacket *pkt_to_send = nullptr;
+
+               if (client->net_proto_version >= min_proto_ver) {
+                       pkt_to_send = pkt;
+               } else if (client->net_proto_version != 0) {
+                       pkt_to_send = legacypkt;
+               } else {
+                       warningstream << "Client with unhandled version to handle: '"
+                               << client->net_proto_version << "'";
+                       continue;
+               }
+
+               m_con->Send(client->peer_id,
+                       clientCommandFactoryTable[pkt_to_send->getCommand()].channel,
+                       pkt_to_send,
+                       clientCommandFactoryTable[pkt_to_send->getCommand()].reliable);
+       }
+}
+
 RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
 {
        MutexAutoLock clientslock(m_clients_mutex);