/* Minetest-c55 Copyright (C) 2010-2011 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "server.h" #include "utility.h" #include #include #include "clientserver.h" #include "map.h" #include "jmutexautolock.h" #include "main.h" #include "constants.h" #include "voxel.h" #include "config.h" #include "servercommand.h" #include "filesys.h" #include "mapblock.h" #include "serverobject.h" #include "settings.h" #include "profiler.h" #include "log.h" #include "script.h" #include "scriptapi.h" #include "nodedef.h" #include "itemdef.h" #include "craftdef.h" #include "mapgen.h" #include "content_mapnode.h" #include "content_nodemeta.h" #include "content_abm.h" #include "content_sao.h" #include "mods.h" #include "sha1.h" #include "base64.h" #include "tool.h" #include "utility_string.h" #include "sound.h" // dummySoundManager #include "event_manager.h" #include "hex.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define BLOCK_EMERGE_FLAG_FROMDISK (1<<0) class MapEditEventIgnorer { public: MapEditEventIgnorer(bool *flag): m_flag(flag) { if(*m_flag == false) *m_flag = true; else m_flag = NULL; } ~MapEditEventIgnorer() { if(m_flag) { assert(*m_flag); *m_flag = false; } } private: bool *m_flag; }; class MapEditEventAreaIgnorer { public: MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a): m_ignorevariable(ignorevariable) { if(m_ignorevariable->getVolume() == 0) *m_ignorevariable = a; else m_ignorevariable = NULL; } ~MapEditEventAreaIgnorer() { if(m_ignorevariable) { assert(m_ignorevariable->getVolume() != 0); *m_ignorevariable = VoxelArea(); } } private: VoxelArea *m_ignorevariable; }; void * ServerThread::Thread() { ThreadStarted(); log_register_thread("ServerThread"); DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER while(getRun()) { try{ //TimeTaker timer("AsyncRunStep() + Receive()"); { //TimeTaker timer("AsyncRunStep()"); m_server->AsyncRunStep(); } //infostream<<"Running m_server->Receive()"<Receive(); } catch(con::NoIncomingDataException &e) { } catch(con::PeerNotFoundException &e) { infostream<<"Server: PeerNotFoundException"<setAsyncFatalError(e.what()); } catch(LuaError &e) { m_server->setAsyncFatalError(e.what()); } } END_DEBUG_EXCEPTION_HANDLER(errorstream) return NULL; } void * EmergeThread::Thread() { ThreadStarted(); log_register_thread("EmergeThread"); DSTACK(__FUNCTION_NAME); BEGIN_DEBUG_EXCEPTION_HANDLER bool enable_mapgen_debug_info = g_settings->getBool("enable_mapgen_debug_info"); /* Get block info from queue, emerge them and send them to clients. After queue is empty, exit. */ while(getRun()) try{ QueuedBlockEmerge *qptr = m_server->m_emerge_queue.pop(); if(qptr == NULL) break; SharedPtr q(qptr); v3s16 &p = q->pos; v2s16 p2d(p.X,p.Z); /* Do not generate over-limit */ if(blockpos_over_limit(p)) continue; //infostream<<"EmergeThread::Thread(): running"<::Iterator i; for(i=q->peer_ids.getIterator(); i.atEnd()==false; i++) { //u16 peer_id = i.getNode()->getKey(); // Check flags u8 flags = i.getNode()->getValue(); if((flags & BLOCK_EMERGE_FLAG_FROMDISK) == false) only_from_disk = false; } } if(enable_mapgen_debug_info) infostream<<"EmergeThread: p=" <<"("<isGenerated() == false)){ if(enable_mapgen_debug_info) infostream<<"EmergeThread: generating"<m_env_mutex); ScopeProfiler sp(g_profiler, "EmergeThread: after " "mapgen::make_block (envlock)", SPT_AVG); // Blit data back on map, update lighting, add mobs and // whatever this does map.finishBlockMake(&data, modified_blocks); // Get central block block = map.getBlockNoCreateNoEx(p); // If block doesn't exist, don't try doing anything with it // This happens if the block is not in generation boundaries if(!block) break; /* Do some post-generate stuff */ v3s16 minp = data.blockpos_min*MAP_BLOCKSIZE; v3s16 maxp = data.blockpos_max*MAP_BLOCKSIZE + v3s16(1,1,1)*(MAP_BLOCKSIZE-1); /* Ignore map edit events, they will not need to be sent to anybody because the block hasn't been sent to anybody */ //MapEditEventIgnorer ign(&m_server->m_ignore_map_edit_events); MapEditEventAreaIgnorer ign( &m_server->m_ignore_map_edit_events_area, VoxelArea(minp, maxp)); { TimeTaker timer("on_generated"); scriptapi_environment_on_generated(m_server->m_lua, minp, maxp, mapgen::get_blockseed(data.seed, minp)); /*int t = timer.stop(true); dstream<<"on_generated took "<m_env->activateBlock(block, 0); }while(false); } if(block == NULL) got_block = false; /* Set sent status of modified blocks on clients */ // NOTE: Server's clients are also behind the connection mutex JMutexAutoLock lock(m_server->m_con_mutex); /* Add the originally fetched block to the modified list */ if(got_block) { modified_blocks.insert(p, block); } /* Set the modified blocks unsent for all the clients */ for(core::map::Iterator i = m_server->m_clients.getIterator(); i.atEnd() == false; i++) { RemoteClient *client = i.getNode()->getValue(); if(modified_blocks.size() > 0) { // Remove block from sent history client->SetBlocksNotSent(modified_blocks); } } } catch(VersionMismatchException &e) { m_server->setAsyncFatalError(std::string( "World data version mismatch (server-side) (world probably saved by a newer version of Minetest): ")+e.what()); } END_DEBUG_EXCEPTION_HANDLER(errorstream) log_deregister_thread(); return NULL; } v3f ServerSoundParams::getPos(ServerEnvironment *env, bool *pos_exists) const { if(pos_exists) *pos_exists = false; switch(type){ case SSP_LOCAL: return v3f(0,0,0); case SSP_POSITIONAL: if(pos_exists) *pos_exists = true; return pos; case SSP_OBJECT: { if(object == 0) return v3f(0,0,0); ServerActiveObject *sao = env->getActiveObject(object); if(!sao) return v3f(0,0,0); if(pos_exists) *pos_exists = true; return sao->getBasePosition(); } } return v3f(0,0,0); } void RemoteClient::GetNextBlocks(Server *server, float dtime, core::array &dest) { DSTACK(__FUNCTION_NAME); /*u32 timer_result; TimeTaker timer("RemoteClient::GetNextBlocks", &timer_result);*/ // Increment timers m_nothing_to_send_pause_timer -= dtime; m_nearest_unsent_reset_timer += dtime; if(m_nothing_to_send_pause_timer >= 0) { return; } // Won't send anything if already sending if(m_blocks_sending.size() >= g_settings->getU16 ("max_simultaneous_block_sends_per_client")) { //infostream<<"Not sending any blocks, Queue full."<m_env->getPlayer(peer_id); assert(player != NULL); v3f playerpos = player->getPosition(); v3f playerspeed = player->getSpeed(); v3f playerspeeddir(0,0,0); if(playerspeed.getLength() > 1.0*BS) playerspeeddir = playerspeed / playerspeed.getLength(); // Predict to next block v3f playerpos_predicted = playerpos + playerspeeddir*MAP_BLOCKSIZE*BS; v3s16 center_nodepos = floatToInt(playerpos_predicted, BS); v3s16 center = getNodeBlockPos(center_nodepos); // Camera position and direction v3f camera_pos = player->getEyePosition(); v3f camera_dir = v3f(0,0,1); camera_dir.rotateYZBy(player->getPitch()); camera_dir.rotateXZBy(player->getYaw()); /*infostream<<"camera_dir=("<getPlayerName(peer_id)<getFloat( "full_block_send_enable_min_time_from_building")) { max_simul_sends_usually = LIMITED_MAX_SIMULTANEOUS_BLOCK_SENDS; } /* Number of blocks sending + number of blocks selected for sending */ u32 num_blocks_selected = m_blocks_sending.size(); /* next time d will be continued from the d from which the nearest unsent block was found this time. This is because not necessarily any of the blocks found this time are actually sent. */ s32 new_nearest_unsent_d = -1; s16 d_max = g_settings->getS16("max_block_send_distance"); s16 d_max_gen = g_settings->getS16("max_block_generate_distance"); // Don't loop very much at a time s16 max_d_increment_at_time = 2; if(d_max > d_start + max_d_increment_at_time) d_max = d_start + max_d_increment_at_time; /*if(d_max_gen > d_start+2) d_max_gen = d_start+2;*/ //infostream<<"Starting from "<getPlayerName(peer_id)< list; getFacePositions(list, d); core::list::Iterator li; for(li=list.begin(); li!=list.end(); li++) { v3s16 p = *li + center; /* Send throttling - Don't allow too many simultaneous transfers - EXCEPT when the blocks are very close Also, don't send blocks that are already flying. */ // Start with the usual maximum u16 max_simul_dynamic = max_simul_sends_usually; // If block is very close, allow full maximum if(d <= BLOCK_SEND_DISABLE_LIMITS_MAX_D) max_simul_dynamic = max_simul_sends_setting; // Don't select too many blocks for sending if(num_blocks_selected >= max_simul_dynamic) { queue_is_full = true; goto queue_full_break; } // Don't send blocks that are currently being transferred if(m_blocks_sending.find(p) != NULL) continue; /* Do not go over-limit */ if(p.X < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.X > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Y < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Y > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Z < -MAP_GENERATION_LIMIT / MAP_BLOCKSIZE || p.Z > MAP_GENERATION_LIMIT / MAP_BLOCKSIZE) continue; // If this is true, inexistent block will be made from scratch bool generate = d <= d_max_gen; { /*// Limit the generating area vertically to 2/3 if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3) generate = false;*/ // Limit the send area vertically to 1/2 if(abs(p.Y - center.Y) > d_max / 2) continue; } #if 0 /* If block is far away, don't generate it unless it is near ground level. */ if(d >= 4) { #if 1 // Block center y in nodes f32 y = (f32)(p.Y * MAP_BLOCKSIZE + MAP_BLOCKSIZE/2); // Don't generate if it's very high or very low if(y < -64 || y > 64) generate = false; #endif #if 0 v2s16 p2d_nodes_center( MAP_BLOCKSIZE*p.X, MAP_BLOCKSIZE*p.Z); // Get ground height in nodes s16 gh = server->m_env->getServerMap().findGroundLevel( p2d_nodes_center); // If differs a lot, don't generate if(fabs(gh - y) > MAP_BLOCKSIZE*2) generate = false; // Actually, don't even send it //continue; #endif } #endif //infostream<<"d="<m_env->getMap().getBlockNoCreateNoEx(p); bool surely_not_found_on_disk = false; bool block_is_invalid = false; if(block != NULL) { // Reset usage timer, this block will be of use in the future. block->resetUsageTimer(); // Block is dummy if data doesn't exist. // It means it has been not found from disk and not generated if(block->isDummy()) { surely_not_found_on_disk = true; } // Block is valid if lighting is up-to-date and data exists if(block->isValid() == false) { block_is_invalid = true; } /*if(block->isFullyGenerated() == false) { block_is_invalid = true; }*/ #if 0 v2s16 p2d(p.X, p.Z); ServerMap *map = (ServerMap*)(&server->m_env->getMap()); v2s16 chunkpos = map->sector_to_chunk(p2d); if(map->chunkNonVolatile(chunkpos) == false) block_is_invalid = true; #endif if(block->isGenerated() == false) block_is_invalid = true; #if 1 /* If block is not close, don't send it unless it is near ground level. Block is near ground level if night-time mesh differs from day-time mesh. */ if(d >= 4) { if(block->getDayNightDiff() == false) continue; } #endif } /* If block has been marked to not exist on disk (dummy) and generating new ones is not wanted, skip block. */ if(generate == false && surely_not_found_on_disk == true) { // get next one. continue; } /* Add inexistent block to emerge queue. */ if(block == NULL || surely_not_found_on_disk || block_is_invalid) { //TODO: Get value from somewhere // Allow only one block in emerge queue //if(server->m_emerge_queue.peerItemCount(peer_id) < 1) // Allow two blocks in queue per client //if(server->m_emerge_queue.peerItemCount(peer_id) < 2) u32 max_emerge = 5; // Make it more responsive when needing to generate stuff if(surely_not_found_on_disk) max_emerge = 1; if(server->m_emerge_queue.peerItemCount(peer_id) < max_emerge) { //infostream<<"Adding block to emerge queue"<m_emerge_queue.addBlock(peer_id, p, flags); server->m_emergethread.trigger(); if(nearest_emerged_d == -1) nearest_emerged_d = d; } else { if(nearest_emergefull_d == -1) nearest_emergefull_d = d; } // get next one. continue; } if(nearest_sent_d == -1) nearest_sent_d = d; /* Add block to send queue */ /*errorstream<<"sending from d="<getPlayerName(peer_id)< g_settings->getS16("max_block_send_distance")){ new_nearest_unsent_d = 0; m_nothing_to_send_pause_timer = 2.0; /*infostream<<"GetNextBlocks(): d wrapped around for " <getPlayerName(peer_id) <<"; setting to 0 and pausing"< &blocks) { m_nearest_unsent_d = 0; for(core::map::Iterator i = blocks.getIterator(); i.atEnd()==false; i++) { v3s16 p = i.getNode()->getKey(); if(m_blocks_sending.find(p) != NULL) m_blocks_sending.remove(p); if(m_blocks_sent.find(p) != NULL) m_blocks_sent.remove(p); } } /* PlayerInfo */ PlayerInfo::PlayerInfo() { name[0] = 0; avg_rtt = 0; } void PlayerInfo::PrintLine(std::ostream *s) { (*s)< #include <al.h> #include <alc.h> //#include <alext.h> #elif defined(__APPLE__) #include <OpenAL/al.h> #include <OpenAL/alc.h> //#include <OpenAL/alext.h> #else #include <AL/al.h> #include <AL/alc.h> #include <AL/alext.h> #endif #include <vorbis/vorbisfile.h> #include "log.h" #include "filesys.h" #include "util/numeric.h" // myrand() #include "debug.h" // assert() #include "porting.h" #include <map> #include <vector> #include <fstream> #define BUFFER_SIZE 30000 static const char *alcErrorString(ALCenum err) { switch (err) { case ALC_NO_ERROR: return "no error"; case ALC_INVALID_DEVICE: return "invalid device"; case ALC_INVALID_CONTEXT: return "invalid context"; case ALC_INVALID_ENUM: return "invalid enum"; case ALC_INVALID_VALUE: return "invalid value"; case ALC_OUT_OF_MEMORY: return "out of memory"; default: return "<unknown OpenAL error>"; } } static const char *alErrorString(ALenum err) { switch (err) { case AL_NO_ERROR: return "no error"; case AL_INVALID_NAME: return "invalid name"; case AL_INVALID_ENUM: return "invalid enum"; case AL_INVALID_VALUE: return "invalid value"; case AL_INVALID_OPERATION: return "invalid operation"; case AL_OUT_OF_MEMORY: return "out of memory"; default: return "<unknown OpenAL error>"; } } static ALenum warn_if_error(ALenum err, const char *desc) { if(err == AL_NO_ERROR) return err; errorstream<<"WARNING: "<<desc<<": "<<alErrorString(err)<<std::endl; return err; } void f3_set(ALfloat *f3, v3f v) { f3[0] = v.X; f3[1] = v.Y; f3[2] = v.Z; } struct SoundBuffer { ALenum format; ALsizei freq; ALuint buffer_id; std::vector<char> buffer; }; SoundBuffer* loadOggFile(const std::string &filepath) { int endian = 0; // 0 for Little-Endian, 1 for Big-Endian int bitStream; long bytes; char array[BUFFER_SIZE]; // Local fixed size array vorbis_info *pInfo; OggVorbis_File oggFile; // Do a dumb-ass static string copy for old versions of ov_fopen // because they expect a non-const char* char nonconst[10000]; snprintf(nonconst, 10000, "%s", filepath.c_str()); // Try opening the given file //if(ov_fopen(filepath.c_str(), &oggFile) != 0) if(ov_fopen(nonconst, &oggFile) != 0) { infostream<<"Audio: Error opening "<<filepath<<" for decoding"<<std::endl; return NULL; } SoundBuffer *snd = new SoundBuffer; // Get some information about the OGG file pInfo = ov_info(&oggFile, -1); // Check the number of channels... always use 16-bit samples if(pInfo->channels == 1) snd->format = AL_FORMAT_MONO16; else snd->format = AL_FORMAT_STEREO16; // The frequency of the sampling rate snd->freq = pInfo->rate; // Keep reading until all is read do { // Read up to a buffer's worth of decoded sound data bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream); if(bytes < 0) { ov_clear(&oggFile); infostream<<"Audio: Error decoding "<<filepath<<std::endl; return NULL; } // Append to end of buffer snd->buffer.insert(snd->buffer.end(), array, array + bytes); } while (bytes > 0); alGenBuffers(1, &snd->buffer_id); alBufferData(snd->buffer_id, snd->format, &(snd->buffer[0]), snd->buffer.size(), snd->freq); ALenum error = alGetError(); if(error != AL_NO_ERROR){ infostream<<"Audio: OpenAL error: "<<alErrorString(error) <<"preparing sound buffer"<<std::endl; } infostream<<"Audio file "<<filepath<<" loaded"<<std::endl; // Clean up! ov_clear(&oggFile); return snd; } struct PlayingSound { ALuint source_id; bool loop; }; class OpenALSoundManager: public ISoundManager { private: OnDemandSoundFetcher *m_fetcher; ALCdevice *m_device; ALCcontext *m_context; bool m_can_vorbis; int m_next_id; std::map<std::string, std::vector<SoundBuffer*> > m_buffers; std::map<int, PlayingSound*> m_sounds_playing; v3f m_listener_pos; public: bool m_is_initialized; OpenALSoundManager(OnDemandSoundFetcher *fetcher): m_fetcher(fetcher), m_device(NULL), m_context(NULL), m_can_vorbis(false), m_next_id(1), m_is_initialized(false) { ALCenum error = ALC_NO_ERROR; infostream<<"Audio: Initializing..."<<std::endl; m_device = alcOpenDevice(NULL); if(!m_device){ infostream<<"Audio: No audio device available, audio system " <<"not initialized"<<std::endl; return; } if(alcIsExtensionPresent(m_device, "EXT_vorbis")){ infostream<<"Audio: Vorbis extension present"<<std::endl; m_can_vorbis = true; } else{ infostream<<"Audio: Vorbis extension NOT present"<<std::endl; m_can_vorbis = false; } m_context = alcCreateContext(m_device, NULL); if(!m_context){ error = alcGetError(m_device); infostream<<"Audio: Unable to initialize audio context, " <<"aborting audio initialization ("<<alcErrorString(error) <<")"<<std::endl; alcCloseDevice(m_device); m_device = NULL; return; } if(!alcMakeContextCurrent(m_context) || (error = alcGetError(m_device) != ALC_NO_ERROR)) { infostream<<"Audio: Error setting audio context, aborting audio " <<"initialization ("<<alcErrorString(error)<<")"<<std::endl; alcDestroyContext(m_context); m_context = NULL; alcCloseDevice(m_device); m_device = NULL; return; } alDistanceModel(AL_EXPONENT_DISTANCE); infostream<<"Audio: Initialized: OpenAL "<<alGetString(AL_VERSION) <<", using "<<alcGetString(m_device, ALC_DEVICE_SPECIFIER) <<std::endl; m_is_initialized = true; } ~OpenALSoundManager() { infostream<<"Audio: Deinitializing..."<<std::endl; // KABOOM! // TODO: Clear SoundBuffers alcMakeContextCurrent(NULL); alcDestroyContext(m_context); m_context = NULL; alcCloseDevice(m_device); m_device = NULL; for (std::map<std::string, std::vector<SoundBuffer*> >::iterator i = m_buffers.begin(); i != m_buffers.end(); i++) { for (std::vector<SoundBuffer*>::iterator iter = (*i).second.begin(); iter != (*i).second.end(); iter++) { delete *iter; } (*i).second.clear(); } m_buffers.clear(); infostream<<"Audio: Deinitialized."<<std::endl; } void addBuffer(const std::string &name, SoundBuffer *buf) { std::map<std::string, std::vector<SoundBuffer*> >::iterator i = m_buffers.find(name); if(i != m_buffers.end()){ i->second.push_back(buf); return; } std::vector<SoundBuffer*> bufs; bufs.push_back(buf); m_buffers[name] = bufs; return; } SoundBuffer* getBuffer(const std::string &name) { std::map<std::string, std::vector<SoundBuffer*> >::iterator i = m_buffers.find(name); if(i == m_buffers.end()) return NULL; std::vector<SoundBuffer*> &bufs = i->second; int j = myrand() % bufs.size(); return bufs[j]; } PlayingSound* createPlayingSound(SoundBuffer *buf, bool loop, float volume) { infostream<<"OpenALSoundManager: Creating playing sound"<<std::endl; assert(buf); PlayingSound *sound = new PlayingSound; assert(sound); warn_if_error(alGetError(), "before createPlayingSound"); alGenSources(1, &sound->source_id); alSourcei(sound->source_id, AL_BUFFER, buf->buffer_id); alSourcei(sound->source_id, AL_SOURCE_RELATIVE, true); alSource3f(sound->source_id, AL_POSITION, 0, 0, 0); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); volume = MYMAX(0.0, volume); alSourcef(sound->source_id, AL_GAIN, volume); alSourcePlay(sound->source_id); warn_if_error(alGetError(), "createPlayingSound"); return sound; } PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop, float volume, v3f pos) { infostream<<"OpenALSoundManager: Creating positional playing sound" <<std::endl; assert(buf); PlayingSound *sound = new PlayingSound; assert(sound); warn_if_error(alGetError(), "before createPlayingSoundAt"); alGenSources(1, &sound->source_id); alSourcei(sound->source_id, AL_BUFFER, buf->buffer_id); alSourcei(sound->source_id, AL_SOURCE_RELATIVE, false); alSource3f(sound->source_id, AL_POSITION, pos.X, pos.Y, pos.Z); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); //alSourcef(sound->source_id, AL_ROLLOFF_FACTOR, 0.7); alSourcef(sound->source_id, AL_REFERENCE_DISTANCE, 30.0); alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); volume = MYMAX(0.0, volume); alSourcef(sound->source_id, AL_GAIN, volume); alSourcePlay(sound->source_id); warn_if_error(alGetError(), "createPlayingSoundAt"); return sound; } int playSoundRaw(SoundBuffer *buf, bool loop, float volume) { assert(buf); PlayingSound *sound = createPlayingSound(buf, loop, volume); if(!sound) return -1; int id = m_next_id++; m_sounds_playing[id] = sound; return id; } int playSoundRawAt(SoundBuffer *buf, bool loop, float volume, v3f pos) { assert(buf); PlayingSound *sound = createPlayingSoundAt(buf, loop, volume, pos); if(!sound) return -1; int id = m_next_id++; m_sounds_playing[id] = sound; return id; } void deleteSound(int id) { std::map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id); if(i == m_sounds_playing.end()) return; PlayingSound *sound = i->second; alDeleteSources(1, &sound->source_id); delete sound; m_sounds_playing.erase(id); } /* If buffer does not exist, consult the fetcher */ SoundBuffer* getFetchBuffer(const std::string &name) { SoundBuffer *buf = getBuffer(name); if(buf) return buf; if(!m_fetcher) return NULL; std::set<std::string> paths; std::set<std::string> datas; m_fetcher->fetchSounds(name, paths, datas); for(std::set<std::string>::iterator i = paths.begin(); i != paths.end(); i++){ loadSoundFile(name, *i); } for(std::set<std::string>::iterator i = datas.begin(); i != datas.end(); i++){ loadSoundData(name, *i); } return getBuffer(name); } // Remove stopped sounds void maintain() { verbosestream<<"OpenALSoundManager::maintain(): " <<m_sounds_playing.size()<<" playing sounds, " <<m_buffers.size()<<" sound names loaded"<<std::endl; std::set<int> del_list; for(std::map<int, PlayingSound*>::iterator i = m_sounds_playing.begin(); i != m_sounds_playing.end(); i++) { int id = i->first; PlayingSound *sound = i->second; // If not playing, remove it { ALint state; alGetSourcei(sound->source_id, AL_SOURCE_STATE, &state); if(state != AL_PLAYING){ del_list.insert(id); } } } if(!del_list.empty()) verbosestream<<"OpenALSoundManager::maintain(): deleting " <<del_list.size()<<" playing sounds"<<std::endl; for(std::set<int>::iterator i = del_list.begin(); i != del_list.end(); i++) { deleteSound(*i); } } /* Interface */ bool loadSoundFile(const std::string &name, const std::string &filepath) { SoundBuffer *buf = loadOggFile(filepath); if(buf) addBuffer(name, buf); return false; } bool loadSoundData(const std::string &name, const std::string &filedata) { // The vorbis API sucks; just write it to a file and use vorbisfile // TODO: Actually load it directly from memory std::string basepath = porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "tmp"; std::string path = basepath + DIR_DELIM + "tmp.ogg"; verbosestream<<"OpenALSoundManager::loadSoundData(): Writing " <<"temporary file to ["<<path<<"]"<<std::endl; fs::CreateAllDirs(basepath); std::ofstream of(path.c_str(), std::ios::binary); of.write(filedata.c_str(), filedata.size()); of.close(); return loadSoundFile(name, path); } void updateListener(v3f pos, v3f vel, v3f at, v3f up) { m_listener_pos = pos; alListener3f(AL_POSITION, pos.X, pos.Y, pos.Z); alListener3f(AL_VELOCITY, vel.X, vel.Y, vel.Z); ALfloat f[6]; f3_set(f, at); f3_set(f+3, -up); alListenerfv(AL_ORIENTATION, f); warn_if_error(alGetError(), "updateListener"); } void setListenerGain(float gain) { alListenerf(AL_GAIN, gain); } int playSound(const std::string &name, bool loop, float volume) { maintain(); if(name == "") return 0; SoundBuffer *buf = getFetchBuffer(name); if(!buf){ infostream<<"OpenALSoundManager: \""<<name<<"\" not found." <<std::endl; return -1; } return playSoundRaw(buf, loop, volume); } int playSoundAt(const std::string &name, bool loop, float volume, v3f pos) { maintain(); if(name == "") return 0; SoundBuffer *buf = getFetchBuffer(name); if(!buf){ infostream<<"OpenALSoundManager: \""<<name<<"\" not found." <<std::endl; return -1; } return playSoundRawAt(buf, loop, volume, pos); } void stopSound(int sound) { maintain(); deleteSound(sound); } bool soundExists(int sound) { maintain(); return (m_sounds_playing.count(sound) != 0); } void updateSoundPosition(int id, v3f pos) { std::map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id); if(i == m_sounds_playing.end()) return; PlayingSound *sound = i->second; alSourcei(sound->source_id, AL_SOURCE_RELATIVE, false); alSource3f(sound->source_id, AL_POSITION, pos.X, pos.Y, pos.Z); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); alSourcef(sound->source_id, AL_REFERENCE_DISTANCE, 30.0); } }; ISoundManager *createOpenALSoundManager(OnDemandSoundFetcher *fetcher) { OpenALSoundManager *m = new OpenALSoundManager(fetcher); if(m->m_is_initialized) return m; delete m; return NULL; }; / Get client and check that it is valid RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); if(client->serialization_version == SER_FMT_VER_INVALID) continue; SendChatMessage(client->peer_id, message); } } void Server::SendPlayerHP(u16 peer_id) { DSTACK(__FUNCTION_NAME); PlayerSAO *playersao = getPlayerSAO(peer_id); assert(playersao); playersao->m_hp_not_sent = false; SendHP(m_con, peer_id, playersao->getHP()); } void Server::SendMovePlayer(u16 peer_id) { DSTACK(__FUNCTION_NAME); Player *player = m_env->getPlayer(peer_id); assert(player); std::ostringstream os(std::ios_base::binary); writeU16(os, TOCLIENT_MOVE_PLAYER); writeV3F1000(os, player->getPosition()); writeF1000(os, player->getPitch()); writeF1000(os, player->getYaw()); { v3f pos = player->getPosition(); f32 pitch = player->getPitch(); f32 yaw = player->getYaw(); verbosestream<<"Server: Sending TOCLIENT_MOVE_PLAYER" <<" pos=("<getPlayer(params.to_player.c_str()); if(!player){ infostream<<"Server::playSound: Player \""<peer_id == PEER_ID_INEXISTENT){ infostream<<"Server::playSound: Player \""<peer_id); dst_clients.insert(client); } else { for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { RemoteClient *client = i.getNode()->getValue(); Player *player = m_env->getPlayer(client->peer_id); if(!player) continue; if(pos_exists){ if(player->getPosition().getDistanceFrom(pos) > params.max_hear_distance) continue; } dst_clients.insert(client); } } if(dst_clients.size() == 0) return -1; // Create the sound s32 id = m_next_sound_id++; // The sound will exist as a reference in m_playing_sounds m_playing_sounds[id] = ServerPlayingSound(); ServerPlayingSound &psound = m_playing_sounds[id]; psound.params = params; for(std::set::iterator i = dst_clients.begin(); i != dst_clients.end(); i++) psound.clients.insert((*i)->peer_id); // Create packet std::ostringstream os(std::ios_base::binary); writeU16(os, TOCLIENT_PLAY_SOUND); writeS32(os, id); os< data((u8*)s.c_str(), s.size()); // Send for(std::set::iterator i = dst_clients.begin(); i != dst_clients.end(); i++){ // Send as reliable m_con.Send((*i)->peer_id, 0, data, true); } return id; } void Server::stopSound(s32 handle) { // Get sound reference std::map::iterator i = m_playing_sounds.find(handle); if(i == m_playing_sounds.end()) return; ServerPlayingSound &psound = i->second; // Create packet std::ostringstream os(std::ios_base::binary); writeU16(os, TOCLIENT_STOP_SOUND); writeS32(os, handle); // Make data buffer std::string s = os.str(); SharedBuffer data((u8*)s.c_str(), s.size()); // Send for(std::set::iterator i = psound.clients.begin(); i != psound.clients.end(); i++){ // Send as reliable m_con.Send(*i, 0, data, true); } // Remove sound reference m_playing_sounds.erase(i); } void Server::sendRemoveNode(v3s16 p, u16 ignore_id, core::list *far_players, float far_d_nodes) { float maxd = far_d_nodes*BS; v3f p_f = intToFloat(p, BS); // Create packet u32 replysize = 8; SharedBuffer reply(replysize); writeU16(&reply[0], TOCLIENT_REMOVENODE); writeS16(&reply[2], p.X); writeS16(&reply[4], p.Y); writeS16(&reply[6], p.Z); for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { // Get client and check that it is valid RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); if(client->serialization_version == SER_FMT_VER_INVALID) continue; // Don't send if it's the same one if(client->peer_id == ignore_id) continue; if(far_players) { // Get player Player *player = m_env->getPlayer(client->peer_id); if(player) { // If player is far away, only set modified blocks not sent v3f player_pos = player->getPosition(); if(player_pos.getDistanceFrom(p_f) > maxd) { far_players->push_back(client->peer_id); continue; } } } // Send as reliable m_con.Send(client->peer_id, 0, reply, true); } } void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id, core::list *far_players, float far_d_nodes) { float maxd = far_d_nodes*BS; v3f p_f = intToFloat(p, BS); for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { // Get client and check that it is valid RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); if(client->serialization_version == SER_FMT_VER_INVALID) continue; // Don't send if it's the same one if(client->peer_id == ignore_id) continue; if(far_players) { // Get player Player *player = m_env->getPlayer(client->peer_id); if(player) { // If player is far away, only set modified blocks not sent v3f player_pos = player->getPosition(); if(player_pos.getDistanceFrom(p_f) > maxd) { far_players->push_back(client->peer_id); continue; } } } // Create packet u32 replysize = 8 + MapNode::serializedLength(client->serialization_version); SharedBuffer reply(replysize); writeU16(&reply[0], TOCLIENT_ADDNODE); writeS16(&reply[2], p.X); writeS16(&reply[4], p.Y); writeS16(&reply[6], p.Z); n.serialize(&reply[8], client->serialization_version); // Send as reliable m_con.Send(client->peer_id, 0, reply, true); } } void Server::setBlockNotSent(v3s16 p) { for(core::map::Iterator i = m_clients.getIterator(); i.atEnd()==false; i++) { RemoteClient *client = i.getNode()->getValue(); client->SetBlockNotSent(p); } } void Server::SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver) { DSTACK(__FUNCTION_NAME); v3s16 p = block->getPos(); #if 0 // Analyze it a bit bool completely_air = true; for(s16 z0=0; z0getNodeNoEx(v3s16(x0,y0,z0)).d != CONTENT_AIR) { completely_air = false; x0 = y0 = z0 = MAP_BLOCKSIZE; // Break out } } // Print result infostream<<"Server: Sending block ("<serialize(os, ver, false); std::string s = os.str(); SharedBuffer blockdata((u8*)s.c_str(), s.size()); u32 replysize = 8 + blockdata.getSize(); SharedBuffer reply(replysize); writeU16(&reply[0], TOCLIENT_BLOCKDATA); writeS16(&reply[2], p.X); writeS16(&reply[4], p.Y); writeS16(&reply[6], p.Z); memcpy(&reply[8], *blockdata, blockdata.getSize()); /*infostream<<"Server: Sending block ("< queue; s32 total_sending = 0; { ScopeProfiler sp(g_profiler, "Server: selecting blocks for sending"); for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); // If definitions and textures have not been sent, don't // send MapBlocks either if(!client->definitions_sent) continue; total_sending += client->SendingCount(); if(client->serialization_version == SER_FMT_VER_INVALID) continue; client->GetNextBlocks(this, dtime, queue); } } // Sort. // Lowest priority number comes first. // Lowest is most important. queue.sort(); for(u32 i=0; i= g_settings->getS32 ("max_simultaneous_block_sends_server_total")) break; PrioritySortedBlockTransfer q = queue[i]; MapBlock *block = NULL; try { block = m_env->getMap().getBlockNoCreate(q.pos); } catch(InvalidPositionException &e) { continue; } RemoteClient *client = getClient(q.peer_id); SendBlockNoLock(q.peer_id, block, client->serialization_version); client->SentBlock(q.pos); total_sending++; } } void Server::fillMediaCache() { DSTACK(__FUNCTION_NAME); infostream<<"Server: Calculating media file checksums"< paths; for(core::list::Iterator i = m_mods.begin(); i != m_mods.end(); i++){ const ModSpec &mod = *i; paths.push_back(mod.path + DIR_DELIM + "textures"); paths.push_back(mod.path + DIR_DELIM + "sounds"); paths.push_back(mod.path + DIR_DELIM + "media"); } // Collect media file information from paths into cache for(std::list::iterator i = paths.begin(); i != paths.end(); i++) { std::string mediapath = *i; std::vector dirlist = fs::GetDirListing(mediapath); for(u32 j=0; jm_media[filename] = MediaInfo(filepath, sha1_base64); verbosestream<<"Server: "< file_announcements; for(std::map::iterator i = m_media.begin(); i != m_media.end(); i++){ // Put in list file_announcements.push_back( SendableMediaAnnouncement(i->first, i->second.sha1_digest)); } // Make packet std::ostringstream os(std::ios_base::binary); /* u16 command u32 number of files for each texture { u16 length of name string name u16 length of sha1_digest string sha1_digest } */ writeU16(os, TOCLIENT_ANNOUNCE_MEDIA); writeU16(os, file_announcements.size()); for(core::list::Iterator j = file_announcements.begin(); j != file_announcements.end(); j++){ os<name); os<sha1_digest); } // Make data buffer std::string s = os.str(); SharedBuffer data((u8*)s.c_str(), s.size()); // Send as reliable m_con.Send(peer_id, 0, data, true); } struct SendableMedia { std::string name; std::string path; std::string data; SendableMedia(const std::string &name_="", const std::string path_="", const std::string &data_=""): name(name_), path(path_), data(data_) {} }; void Server::sendRequestedMedia(u16 peer_id, const core::list &tosend) { DSTACK(__FUNCTION_NAME); verbosestream<<"Server::sendRequestedMedia(): " <<"Sending files to client"< > file_bunches; file_bunches.push_back(core::list()); u32 file_size_bunch_total = 0; for(core::list::ConstIterator i = tosend.begin(); i != tosend.end(); i++) { if(m_media.find(i->name) == m_media.end()){ errorstream<<"Server::sendRequestedMedia(): Client asked for " <<"unknown file \""<<(i->name)<<"\""<= bytes_per_bunch){ file_bunches.push_back(core::list()); file_size_bunch_total = 0; } } /* Create and send packets */ u32 num_bunches = file_bunches.size(); for(u32 i=0; i::Iterator j = file_bunches[i].begin(); j != file_bunches[i].end(); j++){ os<name); os<data); } // Make data buffer std::string s = os.str(); verbosestream<<"Server::sendRequestedMedia(): bunch " <getPlayer()->getName() <<" dies"<setHP(0); // Trigger scripted stuff scriptapi_on_dieplayer(m_lua, playersao); SendPlayerHP(peer_id); SendDeathscreen(m_con, peer_id, false, v3f(0,0,0)); } void Server::RespawnPlayer(u16 peer_id) { DSTACK(__FUNCTION_NAME); PlayerSAO *playersao = getPlayerSAO(peer_id); assert(playersao); infostream<<"Server::RespawnPlayer(): Player " <getPlayer()->getName() <<" respawns"<setHP(PLAYER_MAX_HP); bool repositioned = scriptapi_on_respawnplayer(m_lua, playersao); if(!repositioned){ v3f pos = findSpawnPos(m_env->getServerMap()); playersao->setPos(pos); } } void Server::UpdateCrafting(u16 peer_id) { DSTACK(__FUNCTION_NAME); Player* player = m_env->getPlayer(peer_id); assert(player); // Get a preview for crafting ItemStack preview; // No crafting in creative mode if(g_settings->getBool("creative_mode") == false) getCraftingResult(&player->inventory, preview, false, this); // Put the new preview in InventoryList *plist = player->inventory.getList("craftpreview"); assert(plist); assert(plist->getSize() >= 1); plist->changeItem(0, preview); } RemoteClient* Server::getClient(u16 peer_id) { DSTACK(__FUNCTION_NAME); //JMutexAutoLock lock(m_con_mutex); core::map::Node *n; n = m_clients.find(peer_id); // A client should exist for all peers assert(n != NULL); return n->getValue(); } std::wstring Server::getStatusString() { std::wostringstream os(std::ios_base::binary); os<::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { // Get client and check that it is valid RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); if(client->serialization_version == SER_FMT_VER_INVALID) continue; // Get player Player *player = m_env->getPlayer(client->peer_id); // Get name of player std::wstring name = L"unknown"; if(player != NULL) name = narrow_to_wide(player->getName()); // Add name to information string os<getMap()))->isSavingEnabled() == false) os<get("motd") != "") os<get("motd")); return os.str(); } std::set Server::getPlayerEffectivePrivs(const std::string &name) { std::set privs; scriptapi_get_auth(m_lua, name, NULL, &privs); return privs; } bool Server::checkPriv(const std::string &name, const std::string &priv) { std::set privs = getPlayerEffectivePrivs(name); return (privs.count(priv) != 0); } void Server::reportPrivsModified(const std::string &name) { if(name == ""){ for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++){ RemoteClient *client = i.getNode()->getValue(); Player *player = m_env->getPlayer(client->peer_id); reportPrivsModified(player->getName()); } } else { Player *player = m_env->getPlayer(name.c_str()); if(!player) return; SendPlayerPrivileges(player->peer_id); PlayerSAO *sao = player->getPlayerSAO(); if(!sao) return; sao->updatePrivileges( getPlayerEffectivePrivs(name), isSingleplayer()); } } // Saves g_settings to configpath given at initialization void Server::saveConfig() { if(m_path_config != "") g_settings->updateConfigFile(m_path_config.c_str()); } void Server::notifyPlayer(const char *name, const std::wstring msg) { Player *player = m_env->getPlayer(name); if(!player) return; SendChatMessage(player->peer_id, std::wstring(L"Server: -!- ")+msg); } void Server::notifyPlayers(const std::wstring msg) { BroadcastChatMessage(msg); } void Server::queueBlockEmerge(v3s16 blockpos, bool allow_generate) { u8 flags = 0; if(!allow_generate) flags |= BLOCK_EMERGE_FLAG_FROMDISK; m_emerge_queue.addBlock(PEER_ID_INEXISTENT, blockpos, flags); } // IGameDef interface // Under envlock IItemDefManager* Server::getItemDefManager() { return m_itemdef; } INodeDefManager* Server::getNodeDefManager() { return m_nodedef; } ICraftDefManager* Server::getCraftDefManager() { return m_craftdef; } ITextureSource* Server::getTextureSource() { return NULL; } u16 Server::allocateUnknownNodeId(const std::string &name) { return m_nodedef->allocateDummy(name); } ISoundManager* Server::getSoundManager() { return &dummySoundManager; } MtEventManager* Server::getEventManager() { return m_event; } IWritableItemDefManager* Server::getWritableItemDefManager() { return m_itemdef; } IWritableNodeDefManager* Server::getWritableNodeDefManager() { return m_nodedef; } IWritableCraftDefManager* Server::getWritableCraftDefManager() { return m_craftdef; } const ModSpec* Server::getModSpec(const std::string &modname) { for(core::list::Iterator i = m_mods.begin(); i != m_mods.end(); i++){ const ModSpec &mod = *i; if(mod.name == modname) return &mod; } return NULL; } std::string Server::getBuiltinLuaPath() { return porting::path_share + DIR_DELIM + "builtin"; } v3f findSpawnPos(ServerMap &map) { //return v3f(50,50,50)*BS; v3s16 nodepos; #if 0 nodepos = v2s16(0,0); groundheight = 20; #endif #if 1 // Try to find a good place a few times for(s32 i=0; i<1000; i++) { s32 range = 1 + i; // We're going to try to throw the player to this position v2s16 nodepos2d = v2s16(-range + (myrand()%(range*2)), -range + (myrand()%(range*2))); //v2s16 sectorpos = getNodeSectorPos(nodepos2d); // Get ground height at point (fallbacks to heightmap function) s16 groundheight = map.findGroundLevel(nodepos2d); // Don't go underwater if(groundheight < WATER_LEVEL) { //infostream<<"-> Underwater"< WATER_LEVEL + 4) { //infostream<<"-> Underwater"<= 2){ is_good = true; nodepos.Y -= 1; break; } } nodepos.Y++; } if(is_good){ // Found a good place //infostream<<"Searched through "<(m_env->getPlayer(name)); // If player is already connected, cancel if(player != NULL && player->peer_id != 0) { infostream<<"emergePlayer(): Player already connected"<getPlayer(peer_id) != NULL) { infostream<<"emergePlayer(): Player with wrong name but same" " peer_id already exists"<updateName(name); /* Set player position */ infostream<<"Server: Finding spawn place for player \"" <getServerMap()); player->setPosition(pos); /* Add player to environment */ m_env->addPlayer(player); } /* Create a new player active object */ PlayerSAO *playersao = new PlayerSAO(m_env, player, peer_id, getPlayerEffectivePrivs(player->getName()), isSingleplayer()); /* Add object to environment */ m_env->addActiveObject(playersao); /* Run scripts */ if(newplayer) scriptapi_on_newplayer(m_lua, playersao); scriptapi_on_joinplayer(m_lua, playersao); /* Creative mode */ if(g_settings->getBool("creative_mode")) playersao->createCreativeInventory(); return playersao; } void Server::handlePeerChange(PeerChange &c) { JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock conlock(m_con_mutex); if(c.type == PEER_ADDED) { /* Add */ // Error check core::map::Node *n; n = m_clients.find(c.peer_id); // The client shouldn't already exist assert(n == NULL); // Create client RemoteClient *client = new RemoteClient(); client->peer_id = c.peer_id; m_clients.insert(client->peer_id, client); } // PEER_ADDED else if(c.type == PEER_REMOVED) { /* Delete */ // Error check core::map::Node *n; n = m_clients.find(c.peer_id); // The client should exist assert(n != NULL); /* Mark objects to be not known by the client */ RemoteClient *client = n->getValue(); // Handle objects for(core::map::Iterator i = client->m_known_objects.getIterator(); i.atEnd()==false; i++) { // Get object u16 id = i.getNode()->getKey(); ServerActiveObject* obj = m_env->getActiveObject(id); if(obj && obj->m_known_by_count > 0) obj->m_known_by_count--; } /* Clear references to playing sounds */ for(std::map::iterator i = m_playing_sounds.begin(); i != m_playing_sounds.end();) { ServerPlayingSound &psound = i->second; psound.clients.erase(c.peer_id); if(psound.clients.size() == 0) m_playing_sounds.erase(i++); else i++; } Player *player = m_env->getPlayer(c.peer_id); // Collect information about leaving in chat std::wstring message; { if(player != NULL) { std::wstring name = narrow_to_wide(player->getName()); message += L"*** "; message += name; message += L" left game"; if(c.timeout) message += L" (timed out)"; } } /* Run scripts and remove from environment */ { if(player != NULL) { PlayerSAO *playersao = player->getPlayerSAO(); assert(playersao); scriptapi_on_leaveplayer(m_lua, playersao); playersao->disconnected(); } } /* Print out action */ { if(player != NULL) { std::ostringstream os(std::ios_base::binary); for(core::map::Iterator i = m_clients.getIterator(); i.atEnd() == false; i++) { RemoteClient *client = i.getNode()->getValue(); assert(client->peer_id == i.getNode()->getKey()); if(client->serialization_version == SER_FMT_VER_INVALID) continue; // Get player Player *player = m_env->getPlayer(client->peer_id); if(!player) continue; // Get name of player os<getName()<<" "; } actionstream<getName()<<" " <<(c.timeout?"times out.":"leaves game.") <<" List of players: " < 0) { PeerChange c = m_peer_change_queue.pop_front(); verbosestream<<"Server: Handling peer change: " <<"id="<getFloat("dedicated_server_step"); // This is kind of a hack but can be done like this // because server.step() is very light { ScopeProfiler sp(g_profiler, "dedicated server sleep"); sleep_ms((int)(steplen*1000.0)); } server.step(steplen); if(server.getShutdownRequested() || kill) { infostream<<"Dedicated server quitting"<getFloat("profiler_print_interval"); if(profiler_print_interval != 0) { if(m_profiler_interval.step(steplen, profiler_print_interval)) { infostream<<"Profiler:"<print(infostream); g_profiler->clear(); } } } }