Fix course loading and uploading (rubat <3)

This commit is contained in:
Jonny_Bro (Nikita) 2023-08-10 17:15:57 +05:00
parent cf0a4e8931
commit a1f535a731

View file

@ -1,34 +1,27 @@
local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, "Your 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")
function UploadCourse()
if Course_Name == "" or Course_ID == "" then return print("Can't upload in Freeplay") end
local url = domain:GetString() .. "/upload.php"
local data = file.Open("beatrun/courses/" .. game.GetMap() .. "/" .. Course_ID .. ".txt", "rb", "DATA")
local filedata = util.Decompress(data:Read(data:Size()))
http.Post(url,
{
http.Post(url, {
key = apikey:GetString(),
map = game.GetMap(),
course_data = util.Base64Encode(filedata, true)
},
-- onSuccess function
function(body, length, headers, code)
function(body, length, headers, code) -- onSuccess function
if code == 200 then
print(body)
print("Response: " .. body)
else
print("Error (" .. code .. "): " .. body)
end
end,
-- onFailure function
function(message)
function(message) -- onFailure function
print("Unexpected error: " .. message)
end
)
end)
end
concommand.Add("Beatrun_UploadCourse", UploadCourse)
@ -43,13 +36,9 @@ function GetCourse(sharecode)
if code == 200 then
print("Success! | Response: " .. code .. " | Length: " .. length)
print("Loading course...")
PrintTable(headers)
local dir = "beatrun/courses/" .. game.GetMap() .. "/"
file.CreateDir(dir)
local coursedata = util.Compress(body)
if not file.Exists(dir .. sharecode .. ".txt", "DATA") then
@ -65,13 +54,11 @@ function GetCourse(sharecode)
return false
end
end,
function(message)
end, function(message)
print("An error occurred: ", message)
return false
end,
{
end, {
["User-Agent"] = "Valve/Steam HTTP Client 1.0 (4000)",
["Accept-Encoding"] = "gzip"
})