- //infostream<<"Client got player inventory:"<<std::endl;
- //player->inventory.print(infostream);
- }
- }
- else if(command == TOCLIENT_TIME_OF_DAY)
- {
- if(datasize < 4)
- return;
-
- u16 time_of_day = readU16(&data[2]);
- time_of_day = time_of_day % 24000;
- //infostream<<"Client: time_of_day="<<time_of_day<<std::endl;
- float time_speed = 0;
- if(datasize >= 2 + 2 + 4){
- time_speed = readF1000(&data[4]);
- } else {
- // Old message; try to approximate speed of time by ourselves
- float time_of_day_f = (float)time_of_day / 24000.0;
- float tod_diff_f = 0;
- if(time_of_day_f < 0.2 && m_last_time_of_day_f > 0.8)
- tod_diff_f = time_of_day_f - m_last_time_of_day_f + 1.0;
- else
- tod_diff_f = time_of_day_f - m_last_time_of_day_f;
- m_last_time_of_day_f = time_of_day_f;
- float time_diff = m_time_of_day_update_timer;
- m_time_of_day_update_timer = 0;
- if(m_time_of_day_set){
- time_speed = 3600.0*24.0 * tod_diff_f / time_diff;
- infostream<<"Client: Measured time_of_day speed (old format): "
- <<time_speed<<" tod_diff_f="<<tod_diff_f
- <<" time_diff="<<time_diff<<std::endl;
- }
- }
-
- // Update environment
- m_env.setTimeOfDay(time_of_day);
- m_env.setTimeOfDaySpeed(time_speed);
- m_time_of_day_set = true;
-
- u32 dr = m_env.getDayNightRatio();
- verbosestream<<"Client: time_of_day="<<time_of_day
- <<" time_speed="<<time_speed
- <<" dr="<<dr<<std::endl;
- }
- else if(command == TOCLIENT_CHAT_MESSAGE)
- {
- /*
- u16 command
- u16 length
- wstring message
- */
- u8 buf[6];
- std::string datastring((char*)&data[2], datasize-2);
- std::istringstream is(datastring, std::ios_base::binary);
-
- // Read stuff
- is.read((char*)buf, 2);
- u16 len = readU16(buf);
-
- std::wstring message;
- for(u16 i=0; i<len; i++)
- {
- is.read((char*)buf, 2);
- message += (wchar_t)readU16(buf);
- }
-
- /*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);