+ // Get view range and camera fov (radians) from the client
+ s16 wanted_range = sao->getWantedRange() + 1;
+ float camera_fov = sao->getFov();
+
+ /*
+ Get the starting value of the block finder radius.
+ */
+ if (m_last_center != center) {
+ m_nearest_unsent_d = 0;
+ m_last_center = center;
+ }
+ // reset the unsent distance if the view angle has changed more that 10% of the fov
+ // (this matches isBlockInSight which allows for an extra 10%)
+ if (camera_dir.dotProduct(m_last_camera_dir) < std::cos(camera_fov * 0.1f)) {
+ m_nearest_unsent_d = 0;
+ m_last_camera_dir = camera_dir;
+ }
+ if (m_nearest_unsent_d > 0) {
+ // make sure any blocks modified since the last time we sent blocks are resent
+ for (const v3s16 &p : m_blocks_modified) {
+ m_nearest_unsent_d = std::min(m_nearest_unsent_d, center.getDistanceFrom(p));
+ }
+ }
+ m_blocks_modified.clear();
+
+ s16 d_start = m_nearest_unsent_d;
+
+ // Distrust client-sent FOV and get server-set player object property
+ // zoom FOV (degrees) as a check to avoid hacked clients using FOV to load
+ // distant world.
+ // (zoom is disabled by value 0)
+ float prop_zoom_fov = sao->getZoomFOV() < 0.001f ?
+ 0.0f :
+ std::max(camera_fov, sao->getZoomFOV() * core::DEGTORAD);
+
+ const s16 full_d_max = std::min(adjustDist(m_max_send_distance, prop_zoom_fov),
+ wanted_range);
+ const s16 d_opt = std::min(adjustDist(m_block_optimize_distance, prop_zoom_fov),
+ wanted_range);
+ const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
+
+ s16 d_max_gen = std::min(adjustDist(m_max_gen_distance, prop_zoom_fov),
+ wanted_range);