mirror of
https://github.com/JonnyBro/beatrun.git
synced 2025-03-04 02:49:37 +05:00
refactor: support new courses database update
refactor: debug command
This commit is contained in:
parent
5a39333f8b
commit
166adc32d7
2 changed files with 55 additions and 63 deletions
|
@ -1,13 +1,13 @@
|
||||||
local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, language.GetPhrase("beatrun.convars.apikey"))
|
local apikey = CreateClientConVar("Beatrun_Apikey", "0", true, false, language.GetPhrase("beatrun.convars.apikey"))
|
||||||
local domain = CreateClientConVar("Beatrun_Domain", "courses.jonnybro.ru", true, false, language.GetPhrase("beatrun.convars.domain"))
|
local domain = CreateClientConVar("Beatrun_Domain", "courses.jonnybro.ru", true, false, language.GetPhrase("beatrun.convars.domain"))
|
||||||
|
|
||||||
local QueuedArgs = NULL
|
local QueuedArgs
|
||||||
local QueuedFunction = NULL
|
local QueuedFunction
|
||||||
local currentMap = game.GetMap()
|
local currentMap = game.GetMap()
|
||||||
|
|
||||||
concommand.Add("Beatrun_Cancel", function()
|
concommand.Add("Beatrun_Cancel", function()
|
||||||
QueuedArgs = NULL
|
QueuedArgs = nil
|
||||||
QueuedFunction = NULL
|
QueuedFunction = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
concommand.Add("Beatrun_Confirm", function()
|
concommand.Add("Beatrun_Confirm", function()
|
||||||
|
@ -23,8 +23,8 @@ concommand.Add("Beatrun_Confirm", function()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
QueuedArgs = NULL
|
QueuedArgs = nil
|
||||||
QueuedFunction = NULL
|
QueuedFunction = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function GetCurrentMapWorkshopID()
|
local function GetCurrentMapWorkshopID()
|
||||||
|
@ -39,72 +39,81 @@ local function GetCurrentMapWorkshopID()
|
||||||
return "no_map_id"
|
return "no_map_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetCourse(sharecode)
|
local function FetchCourse(url, headers)
|
||||||
local url = domain:GetString() .. "/api/download"
|
http.Fetch(url, function(body, length, _, code)
|
||||||
|
|
||||||
http.Fetch(url, function(body, length, headers, code)
|
|
||||||
local response = util.JSONToTable(body)
|
local response = util.JSONToTable(body)
|
||||||
|
|
||||||
|
if BEATRUN_DEBUG then print(body) end
|
||||||
|
|
||||||
if response and response.res == 200 then
|
if response and response.res == 200 then
|
||||||
print("Success! | Length: " .. length .. "\nLoading course...")
|
print("Success! | Length: " .. length .. "\nLoading course...")
|
||||||
|
|
||||||
local dir = "beatrun/courses/" .. currentMap .. "/"
|
local dir = "beatrun/courses/" .. currentMap .. "/"
|
||||||
|
|
||||||
file.CreateDir(dir)
|
file.CreateDir(dir)
|
||||||
|
|
||||||
local coursedata = util.Compress(response.file)
|
local coursedata = util.Compress(response.file)
|
||||||
|
|
||||||
file.Write(dir .. sharecode .. ".txt", coursedata)
|
file.Write(dir .. headers.code .. ".txt", coursedata)
|
||||||
|
|
||||||
LoadCourseRaw(coursedata)
|
LoadCourseRaw(coursedata)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
elseif not response then
|
elseif not response then
|
||||||
print("Can't access the database! Please make sure that domain is correct")
|
print("Can't access the database! Please make sure that domain is correct.")
|
||||||
|
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
|
print(body)
|
||||||
print("Error! | Response: " .. response.message)
|
print("Error! | Response: " .. response.message)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end, function(e)
|
end, function(e) print("An error occurred: " .. e) end, headers)
|
||||||
print("An error occurred: " .. e)
|
|
||||||
|
|
||||||
return false
|
|
||||||
end, {
|
|
||||||
authorization = apikey:GetString(),
|
|
||||||
code = sharecode,
|
|
||||||
map = string.Replace(currentMap, " ", "-")
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
concommand.Add("Beatrun_LoadCode", function(ply, cmd, args, argstr)
|
concommand.Add("Beatrun_LoadCode", function(ply, cmd, args, argstr)
|
||||||
GetCourse(args[1])
|
FetchCourse(domain:GetString() .. "/api/download", {
|
||||||
|
authorization = apikey:GetString(),
|
||||||
|
code = args[1],
|
||||||
|
map = string.Replace(currentMap, " ", "-")
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function UploadCourse()
|
local function PostCourse(url, course, headers)
|
||||||
if Course_Name == "" or Course_ID == "" then return print(language.GetPhrase("beatrun.coursesdatabase.cantuploadfreeplay")) end
|
http.Post(url, {
|
||||||
|
data = course
|
||||||
local url = domain:GetString() .. "/api/upload"
|
}, function(body, _, _, code)
|
||||||
local data = file.Open("beatrun/courses/" .. currentMap .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
|
||||||
local filedata = data:Read()
|
|
||||||
|
|
||||||
http.Post(url, NULL, function(body, length, headers, code)
|
|
||||||
local response = util.JSONToTable(body)
|
local response = util.JSONToTable(body)
|
||||||
|
|
||||||
if response.res == 200 then
|
if BEATRUN_DEBUG then print(body) end
|
||||||
|
|
||||||
|
if response and response.res == 200 then
|
||||||
print("Success! | Code: " .. response.code)
|
print("Success! | Code: " .. response.code)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
elseif not response then
|
||||||
|
print("Can't access the database! Please make sure that domain is correct.")
|
||||||
|
|
||||||
|
return false
|
||||||
else
|
else
|
||||||
|
print(body)
|
||||||
print("An error occurred: " .. response.message)
|
print("An error occurred: " .. response.message)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end, function(e)
|
end, function(e) print("Unexpected error: " .. e) end, headers)
|
||||||
print("Unexpected error: " .. e)
|
end
|
||||||
end, {
|
|
||||||
|
function UploadCourse()
|
||||||
|
if Course_Name == "" or Course_ID == "" then return print(language.GetPhrase("beatrun.coursesdatabase.cantuploadfreeplay")) end
|
||||||
|
|
||||||
|
local fl = file.Open("beatrun/courses/" .. currentMap .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
||||||
|
local data = fl:Read()
|
||||||
|
|
||||||
|
PostCourse(domain:GetString() .. "/api/upload", util.Base64Encode(data, true), {
|
||||||
authorization = apikey:GetString(),
|
authorization = apikey:GetString(),
|
||||||
course = util.Base64Encode(filedata, true),
|
course = util.Base64Encode(data, true),
|
||||||
map = string.Replace(currentMap, " ", "-"),
|
map = string.Replace(currentMap, " ", "-"),
|
||||||
mapid = GetCurrentMapWorkshopID()
|
mapid = GetCurrentMapWorkshopID()
|
||||||
})
|
})
|
||||||
|
@ -120,28 +129,13 @@ end)
|
||||||
function UpdateCourse(course_code)
|
function UpdateCourse(course_code)
|
||||||
if Course_Name == "" or Course_ID == "" then return print(language.GetPhrase("beatrun.coursesdatabase.cantuploadfreeplay")) end
|
if Course_Name == "" or Course_ID == "" then return print(language.GetPhrase("beatrun.coursesdatabase.cantuploadfreeplay")) end
|
||||||
|
|
||||||
local url = domain:GetString() .. "/api/update"
|
local fl = file.Open("beatrun/courses/" .. currentMap .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
||||||
local data = file.Open("beatrun/courses/" .. currentMap .. "/" .. Course_ID .. ".txt", "rb", "DATA")
|
local data = fl:Read()
|
||||||
local filedata = data:Read()
|
|
||||||
|
|
||||||
http.Post(url, NULL, function(body, length, headers, code)
|
PostCourse(domain:GetString() .. "/api/update", data, {
|
||||||
local response = util.JSONToTable(body)
|
|
||||||
|
|
||||||
if response.res == 200 then
|
|
||||||
print("Success! | Code: " .. response.code)
|
|
||||||
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
print("An error occurred: " .. response.message)
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end, function(e)
|
|
||||||
print("Unexpected error: " .. e)
|
|
||||||
end, {
|
|
||||||
authorization = apikey:GetString(),
|
authorization = apikey:GetString(),
|
||||||
code = course_code,
|
code = course_code,
|
||||||
course = util.Base64Encode(filedata, true),
|
course = util.Base64Encode(data, true),
|
||||||
map = string.Replace(currentMap, " ", "-")
|
map = string.Replace(currentMap, " ", "-")
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,11 +21,9 @@ local startx = 0.2
|
||||||
local starty = 0.75
|
local starty = 0.75
|
||||||
|
|
||||||
local debugdata = {"BodyAnim", "BodyAnimCycle", "BodyAnimString", "campos", "camang"}
|
local debugdata = {"BodyAnim", "BodyAnimCycle", "BodyAnimString", "campos", "camang"}
|
||||||
|
|
||||||
local debugdata2 = {"BodyAnimArmCopy", "TraceCount"}
|
local debugdata2 = {"BodyAnimArmCopy", "TraceCount"}
|
||||||
|
|
||||||
local debugoffset = {0, 0, 0}
|
local debugoffset = {0, 0, 0}
|
||||||
|
|
||||||
local debuglist = {debugdata, debugdata2}
|
local debuglist = {debugdata, debugdata2}
|
||||||
|
|
||||||
TraceLine_o = TraceLine_o or util.TraceLine
|
TraceLine_o = TraceLine_o or util.TraceLine
|
||||||
|
@ -68,13 +66,11 @@ local function DrawDebugInfo()
|
||||||
surface.DrawText(text)
|
surface.DrawText(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local counter = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function RenderTraces()
|
local function RenderTraces()
|
||||||
cam.Start3D()
|
cam.Start3D()
|
||||||
for k, v in ipairs(traces) do
|
for _, v in ipairs(traces) do
|
||||||
render.DrawLine(v[1], v[2], v[3], true)
|
render.DrawLine(v[1], v[2], v[3], true)
|
||||||
end
|
end
|
||||||
cam.End3D()
|
cam.End3D()
|
||||||
|
@ -84,12 +80,14 @@ local function RenderTraces()
|
||||||
table.Empty(traces)
|
table.Empty(traces)
|
||||||
end
|
end
|
||||||
|
|
||||||
local debugging = false
|
BEATRUN_DEBUG = false
|
||||||
|
|
||||||
concommand.Add("Beatrun_DebugToggle", function()
|
concommand.Add("Beatrun_Debug", function(ply, cmd, args)
|
||||||
debugging = not debugging
|
BEATRUN_DEBUG = tobool(args[1])
|
||||||
|
|
||||||
if debugging then
|
print("Beatrun Debug: " .. tostring(BEATRUN_DEBUG))
|
||||||
|
|
||||||
|
if BEATRUN_DEBUG then
|
||||||
hook.Add("HUDPaint", "DrawDebugInfo", DrawDebugInfo)
|
hook.Add("HUDPaint", "DrawDebugInfo", DrawDebugInfo)
|
||||||
hook.Add("PostRender", "RenderTraces", RenderTraces)
|
hook.Add("PostRender", "RenderTraces", RenderTraces)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue