From 233204feaef8a3152e94b188bf407d2781fa6657 Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Sat, 2 Sep 2023 10:57:09 +0500 Subject: [PATCH] getting ready for new courses database update --- .../beatrun/gamemode/cl/OnlineCourse.lua | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua b/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua index c0d3880..588ef3b 100644 --- a/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua +++ b/beatrun/gamemodes/beatrun/gamemode/cl/OnlineCourse.lua @@ -1,6 +1,21 @@ local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, "API key") local domain = CreateClientConVar("Beatrun_Domain", "courses.beatrun.ru", true, false, "Online courses domain") +local function GetCurrentMapWorkshopID() + for _, addon in pairs(engine.GetAddons()) do + if not addon or not addon.title or not addon.wsid or not addon.mounted or not addon.downloaded then continue end + + _, addon_folders = file.Find("*", addon.title) + + for _, dir in ipairs(addon_folders) do + if dir ~= "maps" then continue end + if file.Exists("maps/" .. game.GetMap() .. ".bsp", addon.title) then return addon.wsid end + end + end + + return 0 +end + function UploadCourse() if Course_Name == "" or Course_ID == "" then return print("Can't upload in Freeplay") end @@ -11,16 +26,15 @@ function UploadCourse() http.Post(url, { key = apikey:GetString(), map = string.Replace(game.GetMap(), " ", "-"), - course_data = util.Base64Encode(filedata, true) - }, - function(body, length, headers, code) -- onSuccess function + course_data = util.Base64Encode(filedata, true), + mapid = GetCurrentMapWorkshopID() + }, function(body, length, headers, code) -- onSuccess function if code == 200 then print("Response: " .. body) else print("Error (" .. code .. "): " .. body) end - end, - function(message) -- onFailure function + end, function(message) -- onFailure function print("Unexpected error: " .. message) end) end @@ -94,6 +108,6 @@ function UpdateCourse(course_code) end) end -concommand.Add("Beatrun_UpdateCourse", function(ply, cmd, args, argstr) +concommand.Add("Beatrun_UpdateCode", function(ply, cmd, args, argstr) UpdateCourse(args[1]) end) \ No newline at end of file