- /*infostream<<"Client received chat message: "
- <<wide_to_narrow(message)<<std::endl;*/
-
- m_chat_queue.push_back(message);
- }
- else if(command == TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD)
- {
- //if(g_settings->getBool("enable_experimental"))
- {
- /*
- u16 command
- u16 count of removed objects
- for all removed objects {
- u16 id
- }
- u16 count of added objects
- for all added objects {
- u16 id
- u8 type
- u32 initialization data length
- string initialization data
- }
- */
-
- char buf[6];
- // Get all data except the command number
- std::string datastring((char*)&data[2], datasize-2);
- // Throw them in an istringstream
- std::istringstream is(datastring, std::ios_base::binary);
-
- // Read stuff
-
- // Read removed objects
- is.read(buf, 2);
- u16 removed_count = readU16((u8*)buf);
- for(u16 i=0; i<removed_count; i++)
- {
- is.read(buf, 2);
- u16 id = readU16((u8*)buf);
- // Remove it
- {
- //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
- m_env.removeActiveObject(id);
- }
- }
-
- // Read added objects
- is.read(buf, 2);
- u16 added_count = readU16((u8*)buf);
- for(u16 i=0; i<added_count; i++)
- {
- is.read(buf, 2);
- u16 id = readU16((u8*)buf);
- is.read(buf, 1);
- u8 type = readU8((u8*)buf);
- std::string data = deSerializeLongString(is);
- // Add it
- {
- //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
- m_env.addActiveObject(id, type, data);
- }
- }
- }
- }
- else if(command == TOCLIENT_ACTIVE_OBJECT_MESSAGES)
- {
- //if(g_settings->getBool("enable_experimental"))
- {
- /*
- u16 command
- for all objects
- {
- u16 id
- u16 message length
- string message
- }
- */
- char buf[6];
- // Get all data except the command number
- std::string datastring((char*)&data[2], datasize-2);
- // Throw them in an istringstream
- std::istringstream is(datastring, std::ios_base::binary);
-
- while(is.eof() == false)
- {
- // Read stuff
- is.read(buf, 2);
- u16 id = readU16((u8*)buf);
- if(is.eof())
- break;
- is.read(buf, 2);
- u16 message_size = readU16((u8*)buf);
- std::string message;
- message.reserve(message_size);
- for(u16 i=0; i<message_size; i++)
- {
- is.read(buf, 1);
- message.append(buf, 1);
- }
- // Pass on to the environment
- {
- //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
- m_env.processActiveObjectMessage(id, message);
- }
- }
- }
- }
- else if(command == TOCLIENT_MOVEMENT)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
- Player *player = m_env.getLocalPlayer();
- assert(player != NULL);
-
- player->movement_acceleration_default = readF1000(is) * BS;
- player->movement_acceleration_air = readF1000(is) * BS;
- player->movement_acceleration_fast = readF1000(is) * BS;
- player->movement_speed_walk = readF1000(is) * BS;
- player->movement_speed_crouch = readF1000(is) * BS;
- player->movement_speed_fast = readF1000(is) * BS;
- player->movement_speed_climb = readF1000(is) * BS;
- player->movement_speed_jump = readF1000(is) * BS;
- player->movement_liquid_fluidity = readF1000(is) * BS;
- player->movement_liquid_fluidity_smooth = readF1000(is) * BS;
- player->movement_liquid_sink = readF1000(is) * BS;
- player->movement_gravity = readF1000(is) * BS;
- }
- else if(command == TOCLIENT_HP)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
- Player *player = m_env.getLocalPlayer();
- assert(player != NULL);
- u8 oldhp = player->hp;
- u8 hp = readU8(is);
- player->hp = hp;
-
- if(hp < oldhp)
- {
- // Add to ClientEvent queue
- ClientEvent event;
- event.type = CE_PLAYER_DAMAGE;
- event.player_damage.amount = oldhp - hp;
- m_client_event_queue.push_back(event);
- }
- }
- else if(command == TOCLIENT_BREATH)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
- Player *player = m_env.getLocalPlayer();
- assert(player != NULL);
- u16 breath = readU16(is);
- player->setBreath(breath) ;
- }
- else if(command == TOCLIENT_MOVE_PLAYER)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
- Player *player = m_env.getLocalPlayer();
- assert(player != NULL);
- v3f pos = readV3F1000(is);
- f32 pitch = readF1000(is);
- f32 yaw = readF1000(is);
- player->setPosition(pos);
- /*player->setPitch(pitch);
- player->setYaw(yaw);*/
-
- infostream<<"Client got TOCLIENT_MOVE_PLAYER"
- <<" pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")"
- <<" pitch="<<pitch
- <<" yaw="<<yaw
- <<std::endl;
-
- /*
- Add to ClientEvent queue.
- This has to be sent to the main program because otherwise
- it would just force the pitch and yaw values to whatever
- the camera points to.
- */
- ClientEvent event;
- event.type = CE_PLAYER_FORCE_MOVE;
- event.player_force_move.pitch = pitch;
- event.player_force_move.yaw = yaw;
- m_client_event_queue.push_back(event);
-
- // Ignore damage for a few seconds, so that the player doesn't
- // get damage from falling on ground
- m_ignore_damage_timer = 3.0;
- }
- else if(command == TOCLIENT_PLAYERITEM)
- {
- infostream<<"Client: WARNING: Ignoring TOCLIENT_PLAYERITEM"<<std::endl;
- }
- else if(command == TOCLIENT_DEATHSCREEN)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
-
- bool set_camera_point_target = readU8(is);
- v3f camera_point_target = readV3F1000(is);
-
- ClientEvent event;
- event.type = CE_DEATHSCREEN;
- event.deathscreen.set_camera_point_target = set_camera_point_target;
- event.deathscreen.camera_point_target_x = camera_point_target.X;
- event.deathscreen.camera_point_target_y = camera_point_target.Y;
- event.deathscreen.camera_point_target_z = camera_point_target.Z;
- m_client_event_queue.push_back(event);
- }
- else if(command == TOCLIENT_ANNOUNCE_MEDIA)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
-
- int num_files = readU16(is);
-
- infostream<<"Client: Received media announcement: packet size: "
- <<datasize<<std::endl;
-
- if (m_media_downloader == NULL ||
- m_media_downloader->isStarted()) {
- const char *problem = m_media_downloader ?
- "we already saw another announcement" :
- "all media has been received already";
- errorstream<<"Client: Received media announcement but "
- <<problem<<"! "
- <<" files="<<num_files
- <<" size="<<datasize<<std::endl;
- return;
- }
-
- // Mesh update thread must be stopped while
- // updating content definitions
- assert(!m_mesh_update_thread.IsRunning());
-
- for(int i=0; i<num_files; i++)
- {
- std::string name = deSerializeString(is);
- std::string sha1_base64 = deSerializeString(is);
- std::string sha1_raw = base64_decode(sha1_base64);
- m_media_downloader->addFile(name, sha1_raw);
- }
-
- std::vector<std::string> remote_media;
- try {
- Strfnd sf(deSerializeString(is));
- while(!sf.atend()) {
- std::string baseurl = trim(sf.next(","));
- if(baseurl != "")
- m_media_downloader->addRemoteServer(baseurl);
- }
- }
- catch(SerializationError) {
- // not supported by server or turned off
- }
-
- m_media_downloader->step(this);
- }
- else if(command == TOCLIENT_MEDIA)
- {
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
-
- /*
- u16 command
- u16 total number of file bunches
- u16 index of this bunch
- u32 number of files in this bunch
- for each file {
- u16 length of name
- string name
- u32 length of data
- data
- }
- */
- int num_bunches = readU16(is);
- int bunch_i = readU16(is);
- u32 num_files = readU32(is);
- infostream<<"Client: Received files: bunch "<<bunch_i<<"/"
- <<num_bunches<<" files="<<num_files
- <<" size="<<datasize<<std::endl;
-
- if (num_files == 0)
- return;
-
- if (m_media_downloader == NULL ||
- !m_media_downloader->isStarted()) {
- const char *problem = m_media_downloader ?
- "media has not been requested" :
- "all media has been received already";
- errorstream<<"Client: Received media but "
- <<problem<<"! "
- <<" bunch "<<bunch_i<<"/"<<num_bunches
- <<" files="<<num_files
- <<" size="<<datasize<<std::endl;
- return;
- }