]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server.h
sitä sun tätä tekeillä, toimii kivasti
[dragonfireclient.git] / src / server.h
index 5c856333a103064649c5c1635a769c0da7d0ba2d..79cdf052d6fd04052242e8cce58794c3f6249d1a 100644 (file)
@@ -102,6 +102,23 @@ class BlockEmergeQueue
                JMutexAutoLock lock(m_mutex);
                return m_queue.size();
        }
+       
+       u32 peerItemCount(u16 peer_id)
+       {
+               JMutexAutoLock lock(m_mutex);
+
+               u32 count = 0;
+
+               core::list<QueuedBlockEmerge*>::Iterator i;
+               for(i=m_queue.begin(); i!=m_queue.end(); i++)
+               {
+                       QueuedBlockEmerge *q = *i;
+                       if(q->peer_ids.find(peer_id) != NULL)
+                               count++;
+               }
+
+               return count;
+       }
 
 private:
        core::list<QueuedBlockEmerge*> m_queue;
@@ -201,6 +218,28 @@ struct PlayerInfo
 
 u32 PIChecksum(core::list<PlayerInfo> &l);
 
+/*
+       Used for queueing and sorting block transfers in containers
+       
+       Lower priority number means higher priority.
+*/
+struct PrioritySortedBlockTransfer
+{
+       PrioritySortedBlockTransfer(float a_priority, v3s16 a_pos, u16 a_peer_id)
+       {
+               priority = a_priority;
+               pos = a_pos;
+               peer_id = a_peer_id;
+       }
+       bool operator < (PrioritySortedBlockTransfer &other)
+       {
+               return priority < other.priority;
+       }
+       float priority;
+       v3s16 pos;
+       u16 peer_id;
+};
+
 class RemoteClient
 {
 public:
@@ -215,8 +254,8 @@ class RemoteClient
        u8 pending_serialization_version;
 
        RemoteClient():
-               m_time_from_building(0.0),
-               m_num_blocks_in_emerge_queue(0)
+               m_time_from_building(0.0)
+               //m_num_blocks_in_emerge_queue(0)
        {
                peer_id = 0;
                serialization_version = SER_FMT_VER_INVALID;
@@ -230,8 +269,13 @@ class RemoteClient
        {
        }
        
-       // Connection and environment should be locked when this is called
-       void SendBlocks(Server *server, float dtime);
+       /*
+               Finds block that should be sent next to the client.
+               Environment should be locked when this is called.
+               dtime is used for resetting send radius at slow interval
+       */
+       void GetNextBlocks(Server *server, float dtime,
+                       core::array<PrioritySortedBlockTransfer> &dest);
 
        // Connection and environment should be locked when this is called
        // steps() objects of blocks not found in active_blocks, then
@@ -249,9 +293,23 @@ class RemoteClient
        void SetBlockNotSent(v3s16 p);
        void SetBlocksNotSent(core::map<v3s16, MapBlock*> &blocks);
 
-       void BlockEmerged();
+       //void BlockEmerged();
+
+       /*bool IsSendingBlock(v3s16 p)
+       {
+               JMutexAutoLock lock(m_blocks_sending_mutex);
+               return (m_blocks_sending.find(p) != NULL);
+       }*/
+
+       s32 SendingCount()
+       {
+               JMutexAutoLock lock(m_blocks_sending_mutex);
+               return m_blocks_sending.size();
+       }
        
        // Increments timeouts and removes timed-out blocks from list
+       // NOTE: This doesn't fix the server-not-sending-block bug
+       //       because it is related to emerging, not sending.
        //void RunSendingTimeouts(float dtime, float timeout);
 
        void PrintInfo(std::ostream &o)
@@ -259,8 +317,8 @@ class RemoteClient
                JMutexAutoLock l2(m_blocks_sent_mutex);
                JMutexAutoLock l3(m_blocks_sending_mutex);
                o<<"RemoteClient "<<peer_id<<": "
-                               <<"m_num_blocks_in_emerge_queue="
-                               <<m_num_blocks_in_emerge_queue.get()
+                               /*<<"m_num_blocks_in_emerge_queue="
+                               <<m_num_blocks_in_emerge_queue.get()*/
                                <<", m_blocks_sent.size()="<<m_blocks_sent.size()
                                <<", m_blocks_sending.size()="<<m_blocks_sending.size()
                                <<", m_nearest_unsent_d="<<m_nearest_unsent_d
@@ -280,10 +338,11 @@ class RemoteClient
        */
        
        //TODO: core::map<v3s16, MapBlock*> m_active_blocks
+       //NOTE: Not here, it should be server-wide!
 
        // Number of blocks in the emerge queue that have this client as
        // a receiver. Used for throttling network usage.
-       MutexedVariable<s16> m_num_blocks_in_emerge_queue;
+       //MutexedVariable<s16> m_num_blocks_in_emerge_queue;
 
        /*
                Blocks that have been sent to client.
@@ -310,6 +369,15 @@ class RemoteClient
        JMutex m_blocks_sending_mutex;
 };
 
+/*struct ServerSettings
+{
+       ServerSettings()
+       {
+               creative_mode = false;
+       }
+       bool creative_mode;
+};*/
+
 class Server : public con::PeerHandler
 {
 public:
@@ -317,14 +385,17 @@ class Server : public con::PeerHandler
                NOTE: Every public method should be thread-safe
        */
        Server(
-                       std::string mapsavedir,
-                       bool creative_mode,
-                       MapgenParams mapgen_params
-               );
+               std::string mapsavedir,
+               HMParams hm_params,
+               MapParams map_params
+       );
        ~Server();
        void start(unsigned short port);
        void stop();
+       // This is mainly a way to pass the time to the server.
+       // Actual processing is done in an another thread.
        void step(float dtime);
+       // This is run by ServerThread and does the actual processing
        void AsyncRunStep();
        void Receive();
        void ProcessData(u8 *data, u32 datasize, u16 peer_id);
@@ -334,7 +405,6 @@ class Server : public con::PeerHandler
 
        // Environment and Connection must be locked when called
        void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver);
-       //void SendBlock(u16 peer_id, MapBlock *block, u8 ver);
        //TODO: Sending of many blocks in a single packet
        
        // Environment and Connection must be locked when called
@@ -377,9 +447,7 @@ class Server : public con::PeerHandler
        EmergeThread m_emergethread;
 
        BlockEmergeQueue m_emerge_queue;
-
-       bool m_creative_mode;
-
+       
        friend class EmergeThread;
        friend class RemoteClient;
 };