+void Server::SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao)
+{
+ // Radius inside which objects are active
+ static thread_local const s16 radius =
+ g_settings->getS16("active_object_send_range_blocks") * MAP_BLOCKSIZE;
+
+ // Radius inside which players are active
+ static thread_local const bool is_transfer_limited =
+ g_settings->exists("unlimited_player_transfer_distance") &&
+ !g_settings->getBool("unlimited_player_transfer_distance");
+
+ static thread_local const s16 player_transfer_dist =
+ g_settings->getS16("player_transfer_distance") * MAP_BLOCKSIZE;
+
+ s16 player_radius = player_transfer_dist == 0 && is_transfer_limited ?
+ radius : player_transfer_dist;
+
+ s16 my_radius = MYMIN(radius, playersao->getWantedRange() * MAP_BLOCKSIZE);
+ if (my_radius <= 0)
+ my_radius = radius;
+
+ std::queue<u16> removed_objects, added_objects;
+ m_env->getRemovedActiveObjects(playersao, my_radius, player_radius,
+ client->m_known_objects, removed_objects);
+ m_env->getAddedActiveObjects(playersao, my_radius, player_radius,
+ client->m_known_objects, added_objects);
+
+ int removed_count = removed_objects.size();
+ int added_count = added_objects.size();
+
+ if (removed_objects.empty() && added_objects.empty())
+ return;
+
+ char buf[4];
+ std::string data;
+
+ // Handle removed objects
+ writeU16((u8*)buf, removed_objects.size());
+ data.append(buf, 2);
+ while (!removed_objects.empty()) {
+ // Get object
+ u16 id = removed_objects.front();
+ ServerActiveObject* obj = m_env->getActiveObject(id);
+
+ // Add to data buffer for sending
+ writeU16((u8*)buf, id);
+ data.append(buf, 2);
+
+ // Remove from known objects
+ client->m_known_objects.erase(id);
+
+ if (obj && obj->m_known_by_count > 0)
+ obj->m_known_by_count--;
+
+ removed_objects.pop();
+ }
+
+ // Handle added objects
+ writeU16((u8*)buf, added_objects.size());
+ data.append(buf, 2);
+ while (!added_objects.empty()) {
+ // Get object
+ u16 id = added_objects.front();
+ ServerActiveObject *obj = m_env->getActiveObject(id);
+ added_objects.pop();
+
+ if (!obj) {
+ warningstream << FUNCTION_NAME << ": NULL object id="
+ << (int)id << std::endl;
+ continue;
+ }
+
+ // Get object type
+ u8 type = obj->getSendType();
+
+ // Add to data buffer for sending
+ writeU16((u8*)buf, id);
+ data.append(buf, 2);
+ writeU8((u8*)buf, type);
+ data.append(buf, 1);
+
+ data.append(serializeLongString(
+ obj->getClientInitializationData(client->net_proto_version)));
+
+ // Add to known objects
+ client->m_known_objects.insert(id);
+
+ obj->m_known_by_count++;
+ }
+
+ NetworkPacket pkt(TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD, data.size(), client->peer_id);
+ pkt.putRawString(data.c_str(), data.size());
+ Send(&pkt);
+
+ verbosestream << "Server::SendActiveObjectRemoveAdd: "
+ << removed_count << " removed, " << added_count << " added, "
+ << "packet size is " << pkt.getSize() << std::endl;
+}
+
+void Server::SendActiveObjectMessages(session_t peer_id, const std::string &datas,
+ bool reliable)