diff --git a/lua/starfall/libs_sh/entities.lua b/lua/starfall/libs_sh/entities.lua index 426fff2ce..c26055add 100644 --- a/lua/starfall/libs_sh/entities.lua +++ b/lua/starfall/libs_sh/entities.lua @@ -319,7 +319,7 @@ end -- @param number channel Default CHAN_AUTO or CHAN_WEAPON for weapons function ents_methods:emitSound(snd, lvl, pitch, volume, channel) checkluatype(snd, TYPE_STRING) - snd = SF.CheckSound(snd) + snd = SF.CheckSound(instance.player, snd) local ent = getent(self) checkpermission(instance, ent, "entities.emitSound") diff --git a/lua/starfall/libs_sh/sound.lua b/lua/starfall/libs_sh/sound.lua index ee248dd97..0fd4fbc2d 100644 --- a/lua/starfall/libs_sh/sound.lua +++ b/lua/starfall/libs_sh/sound.lua @@ -75,7 +75,7 @@ end) function sound_library.create(ent, path, nofilter) checkluatype(path, TYPE_STRING) if nofilter~=nil then checkluatype(nofilter, TYPE_BOOL) end - path = SF.CheckSound(path) + path = SF.CheckSound(instance.player, path) checkpermission(instance, { ent, path }, "sound.create") @@ -116,6 +116,14 @@ function sound_library.duration(path) return SoundDuration(path) end +--- Returns true if the sound or sound property exists. +-- @param string path String path to the sound file +-- @return boolean True if exists, false if not +function sound_library.exists(path) + checkluatype(path, TYPE_STRING) + return istable(sound.GetProperties(path)) or file.Exists("sound/" .. path, "GAME") +end + -------------------------------------------------- --- Starts to play the sound. diff --git a/lua/starfall/sflib.lua b/lua/starfall/sflib.lua index d3f8517b8..39aa14091 100644 --- a/lua/starfall/sflib.lua +++ b/lua/starfall/sflib.lua @@ -1450,7 +1450,12 @@ function SF.CheckModel(model, player, prop) return model end -function SF.CheckSound(path) +SF.UniqueSounds = {} +setmetatable(SF.UniqueSounds, {["__index"]=function(t,k) local newTab = {} t[k] = {} return {} end}) + +local maxUniqueSounds = CreateConVar("sf_sounds_unique_max"..(CLIENT and "_cl" or ""), tostring(200), FCVAR_ARCHIVE, "The maximum number of unique sounds paths allowed") + +function SF.CheckSound(ply, path) -- Limit length and remove invalid chars if #path>260 then SF.Throw("Sound path too long!", 3) end path = SF.NormalizePath(string.gsub(path, "[\"?']", "")) @@ -1461,8 +1466,13 @@ function SF.CheckSound(path) SF.Throw("Invalid sound flags! "..flags, 3) end - if not (istable(sound.GetProperties(checkpath)) or file.Exists("sound/" .. checkpath, "GAME")) then - SF.Throw("Invalid sound path! "..checkpath, 3) + local UserUniqueSounds = SF.UniqueSounds[ply:SteamID()] + if not UserUniqueSounds[checkpath] then + if table.Count(UserUniqueSounds) >= maxUniqueSounds:GetInt() then + SF.Throw("The unique sounds limit has been reached.", 3) + else + UserUniqueSounds[checkpath] = true + end end return path