/// Play from memory. bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop) { CIFile ifile; ifile.allowBNPCacheFileOnOpen(false); ifile.setCacheFileOnOpen(false); ifile.open(filepath); // try to load the music in memory uint32 fs = ifile.getFileSize(); if (!fs) { nlwarning("NLSOUND FMod Driver: Empty music file"); return false; } // read Buffer nlassert(!_MusicBuffer); _MusicBuffer = new uint8[fs]; try { ifile.serialBuffer(_MusicBuffer, fs); } catch (...) { nlwarning("NLSOUND FMod Driver: Error while reading music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } // open FMOD stream _MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer, FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs); if (!_MusicStream) { nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file"); delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } if (!playStream()) { nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file"); FSOUND_Stream_Close(_MusicStream); _MusicStream = NULL; delete[] _MusicBuffer; _MusicBuffer = NULL; return false; } return true; }
void CMailForumService::checkFile(const std::string& file) { uint fsz = CFile::getFileSize(file); if (fsz == 0) return; vector<uint8> buffer(fsz); CIFile fi; if (!fi.open(file)) return; fi.serialBuffer(&(buffer[0]), fsz); fi.close(); char* pb = (char*)(&(buffer[0])); char* pt = pb; while (*pt != '\0' && strncmp(pt, "$$$$", 4)) ++pt; // file contents "$$$$" -> end of file marker, file is complete, can be deleted if (pt != '\0') { CFile::deleteFile(file); int shard_id; char to_username[256]; char from_username[256]; int scanned = sscanf(pb, "shard=%d to=%s from=%s", &shard_id, to_username, from_username); CMessage msgout("MAIL_NOTIF"); uint32 shardId = (uint32)shard_id; string toUserName = to_username; string fromUserName = from_username; nldebug("MAIL: sent notification for user '%s' on shard '%d'", toUserName.c_str(), shardId); msgout.serial(shardId, toUserName, fromUserName); CUnifiedNetwork::getInstance()->send("EGS", msgout); } }
// *************************************************************************** bool CLuaState::executeFile(const std::string &pathName) { //H_AUTO(Lua_CLuaState_executeFile) CIFile inputFile; if(!inputFile.open(pathName)) return false; #ifdef LUA_NEVRAX_VERSION if (LuaDebuggerIDE) { std::string path = NLMISC::CPath::getCurrentPath() + "/" + pathName.c_str(); path = CPath::standardizeDosPath(path); LuaDebuggerIDE->addFile(path.c_str()); } #endif // load the script text string script; /* while(!inputFile.eof()) { char tmpBuff[5000]; inputFile.getline(tmpBuff, 5000); script+= tmpBuff; script+= "\n"; } */ script.resize(CFile::getFileSize(pathName)); inputFile.serialBuffer((uint8 *) &script[0], (uint)script.size()); // execute the script text, with dbgSrc==filename (use @ for lua internal purpose) executeScriptInternal(script, string("@") + CFile::getFilename(pathName)); return true; }