summaryrefslogtreecommitdiffstats
path: root/Server/Plugins/Debuggers/Debuggers.lua
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-23 13:20:43 +0200
committerMattes D <github@xoft.cz>2016-08-23 13:20:43 +0200
commit5ca371bb9a65cc322eb8327d81709985daefe173 (patch)
tree41f9d786c52985118f444d86721649e1186e6b2d /Server/Plugins/Debuggers/Debuggers.lua
parentcUrlClient: Refactored callbacks to use UniquePtr. (diff)
downloadcuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.gz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.bz2
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.lz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.xz
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.tar.zst
cuberite-5ca371bb9a65cc322eb8327d81709985daefe173.zip
Diffstat (limited to '')
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua81
1 files changed, 80 insertions, 1 deletions
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index da375cdff..f405d95ae 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -61,7 +61,7 @@ function Initialize(a_Plugin)
-- TestUUIDFromName()
-- TestRankMgr()
TestFileExt()
- TestFileLastMod()
+ -- TestFileLastMod()
TestPluginInterface()
local LastSelfMod = cFile:GetLastModificationTime(a_Plugin:GetLocalFolder() .. "/Debuggers.lua")
@@ -2135,6 +2135,35 @@ end
+function HandleConsoleTestUrlClient(a_Split, a_EntireCmd)
+ local url = a_Split[2] or "https://github.com"
+ local isSuccess, msg = cUrlClient:Get(url,
+ function (a_Body, a_SecondParam)
+ if not(a_Body) then
+ -- An error has occurred, a_SecondParam is the error message
+ LOG("Error while retrieving URL \"" .. url .. "\": " .. (a_SecondParam or "<no message>"))
+ return
+ end
+ -- Body received, a_SecondParam is the HTTP headers dictionary-table
+ assert(type(a_Body) == "string")
+ assert(type(a_SecondParam) == "table")
+ LOG("URL body received, length is " .. string.len(a_Body) .. " bytes and there are these headers:")
+ for k, v in pairs(a_SecondParam) do
+ LOG(" \"" .. k .. "\": \"" .. v .. "\"")
+ end
+ LOG("(headers list finished)")
+ end
+ )
+ if not(isSuccess) then
+ LOG("cUrlClient request failed: " .. (msg or "<no message>"))
+ end
+ return true
+end
+
+
+
+
+
function HandleConsoleTestUrlParser(a_Split, a_EntireCmd)
LOG("Testing cUrlParser...")
local UrlsToTest =
@@ -2262,6 +2291,56 @@ end
+function HandleConsoleDownload(a_Split)
+ -- Check params:
+ local url = a_Split[2]
+ local fnam = a_Split[3]
+ if (not(url) or not(fnam)) then
+ return true, "Missing parameters. Usage: download <url> <filename>"
+ end
+
+ local callbacks =
+ {
+ OnStatusLine = function (self, a_HttpVersion, a_Status, a_Rest)
+ if (a_Status ~= 200) then
+ LOG("Cannot download " .. url .. ", HTTP error code " .. a_Status)
+ return
+ end
+
+ local f, err = io.open(fnam, "wb")
+ if not(f) then
+ LOG("Cannot download " .. url .. ", error opening the file " .. fnam .. ": " .. (err or "<no message>"))
+ return
+ end
+ self.m_File = f
+ end,
+
+ OnBodyData = function (self, a_Data)
+ if (self.m_File) then
+ self.m_File:write(a_Data)
+ end
+ end,
+
+ OnBodyFinished = function (self)
+ if (self.m_File) then
+ self.m_File:close()
+ LOG("File " .. fnam .. " has been downloaded.")
+ end
+ end,
+ }
+
+ local isSuccess, msg = cUrlClient:Get(url, callbacks)
+ if not(isSuccess) then
+ LOG("Cannot start an URL download: " .. (msg or "<no message>"))
+ return true
+ end
+ return true
+end
+
+
+
+
+
function HandleBlkCmd(a_Split, a_Player)
-- Gets info about the block the player is looking at.
local World = a_Player:GetWorld();