mirror of
https://github.com/JonnyBro/beatrun.git
synced 2024-12-29 21:33:02 +05:00
Fix course loading and uploading (rubat <3)
This commit is contained in:
parent
cf0a4e8931
commit
a1f535a731
1 changed files with 21 additions and 34 deletions
|
@ -1,41 +1,34 @@
|
||||||
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")
|
local domain = CreateClientConVar("Beatrun_Domain", "courses.beatrun.ru", true, false, "Online courses domain")
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
local url = domain:GetString() .. "/upload.php"
|
local url = domain:GetString() .. "/upload.php"
|
||||||
local data = file.Open("beatrun/courses/" .. game.GetMap() .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
local data = file.Open("beatrun/courses/" .. game.GetMap() .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
||||||
local filedata = util.Decompress(data:Read(data:Size()))
|
local filedata = util.Decompress(data:Read(data:Size()))
|
||||||
|
|
||||||
http.Post(url,
|
http.Post(url, {
|
||||||
{
|
|
||||||
key = apikey:GetString(),
|
key = apikey:GetString(),
|
||||||
map = game.GetMap(),
|
map = game.GetMap(),
|
||||||
course_data = util.Base64Encode(filedata, true)
|
course_data = util.Base64Encode(filedata, true)
|
||||||
},
|
},
|
||||||
|
function(body, length, headers, code) -- onSuccess function
|
||||||
-- onSuccess function
|
|
||||||
function(body, length, headers, code)
|
|
||||||
if code == 200 then
|
if code == 200 then
|
||||||
print(body)
|
print("Response: " .. body)
|
||||||
else
|
else
|
||||||
print("Error (" .. code .. "): ".. body)
|
print("Error (" .. code .. "): " .. body)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
function(message) -- onFailure function
|
||||||
-- onFailure function
|
|
||||||
function(message)
|
|
||||||
print("Unexpected error: " .. message)
|
print("Unexpected error: " .. message)
|
||||||
end
|
end)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
concommand.Add("Beatrun_UploadCourse", UploadCourse)
|
concommand.Add("Beatrun_UploadCourse", UploadCourse)
|
||||||
|
|
||||||
function GetCourse(sharecode)
|
function GetCourse(sharecode)
|
||||||
local url = domain:GetString() .. "/getcourse.php"
|
local url = domain:GetString() .. "/getcourse.php"
|
||||||
.."?sharecode=" .. sharecode
|
.. "?sharecode=" .. sharecode
|
||||||
.. "&map=" .. game.GetMap()
|
.. "&map=" .. game.GetMap()
|
||||||
.. "&key=" .. apikey:GetString()
|
.. "&key=" .. apikey:GetString()
|
||||||
|
|
||||||
|
@ -43,13 +36,9 @@ function GetCourse(sharecode)
|
||||||
if code == 200 then
|
if code == 200 then
|
||||||
print("Success! | Response: " .. code .. " | Length: " .. length)
|
print("Success! | Response: " .. code .. " | Length: " .. length)
|
||||||
print("Loading course...")
|
print("Loading course...")
|
||||||
|
|
||||||
PrintTable(headers)
|
PrintTable(headers)
|
||||||
|
|
||||||
local dir = "beatrun/courses/" .. game.GetMap() .. "/"
|
local dir = "beatrun/courses/" .. game.GetMap() .. "/"
|
||||||
|
|
||||||
file.CreateDir(dir)
|
file.CreateDir(dir)
|
||||||
|
|
||||||
local coursedata = util.Compress(body)
|
local coursedata = util.Compress(body)
|
||||||
|
|
||||||
if not file.Exists(dir .. sharecode .. ".txt", "DATA") then
|
if not file.Exists(dir .. sharecode .. ".txt", "DATA") then
|
||||||
|
@ -65,13 +54,11 @@ function GetCourse(sharecode)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end,
|
end, function(message)
|
||||||
function(message)
|
|
||||||
print("An error occurred: ", message)
|
print("An error occurred: ", message)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end,
|
end, {
|
||||||
{
|
|
||||||
["User-Agent"] = "Valve/Steam HTTP Client 1.0 (4000)",
|
["User-Agent"] = "Valve/Steam HTTP Client 1.0 (4000)",
|
||||||
["Accept-Encoding"] = "gzip"
|
["Accept-Encoding"] = "gzip"
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue