mirror of
https://github.com/JonnyBro/beatrun.git
synced 2024-12-29 05:13:02 +05:00
getting ready for new courses database update
This commit is contained in:
parent
0e362a4b41
commit
233204feae
1 changed files with 20 additions and 6 deletions
|
@ -1,6 +1,21 @@
|
||||||
local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, "API key")
|
local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, "API key")
|
||||||
local domain = CreateClientConVar("Beatrun_Domain", "courses.beatrun.ru", true, false, "Online courses domain")
|
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()
|
function UploadCourse()
|
||||||
if Course_Name == "" or Course_ID == "" then return print("Can't upload in Freeplay") end
|
if Course_Name == "" or Course_ID == "" then return print("Can't upload in Freeplay") end
|
||||||
|
|
||||||
|
@ -11,16 +26,15 @@ function UploadCourse()
|
||||||
http.Post(url, {
|
http.Post(url, {
|
||||||
key = apikey:GetString(),
|
key = apikey:GetString(),
|
||||||
map = string.Replace(game.GetMap(), " ", "-"),
|
map = string.Replace(game.GetMap(), " ", "-"),
|
||||||
course_data = util.Base64Encode(filedata, true)
|
course_data = util.Base64Encode(filedata, true),
|
||||||
},
|
mapid = GetCurrentMapWorkshopID()
|
||||||
function(body, length, headers, code) -- onSuccess function
|
}, function(body, length, headers, code) -- onSuccess function
|
||||||
if code == 200 then
|
if code == 200 then
|
||||||
print("Response: " .. body)
|
print("Response: " .. body)
|
||||||
else
|
else
|
||||||
print("Error (" .. code .. "): " .. body)
|
print("Error (" .. code .. "): " .. body)
|
||||||
end
|
end
|
||||||
end,
|
end, function(message) -- onFailure function
|
||||||
function(message) -- onFailure function
|
|
||||||
print("Unexpected error: " .. message)
|
print("Unexpected error: " .. message)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -94,6 +108,6 @@ function UpdateCourse(course_code)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
concommand.Add("Beatrun_UpdateCourse", function(ply, cmd, args, argstr)
|
concommand.Add("Beatrun_UpdateCode", function(ply, cmd, args, argstr)
|
||||||
UpdateCourse(args[1])
|
UpdateCourse(args[1])
|
||||||
end)
|
end)
|
Loading…
Reference in a new issue