summaryrefslogtreecommitdiffstats
path: root/Server/Plugins/Debuggers
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-08-23 14:17:30 +0200
committerGitHub <noreply@github.com>2016-08-23 14:17:30 +0200
commitc94628959db64698bf4bd11d43e6369721cfe85a (patch)
tree41f9d786c52985118f444d86721649e1186e6b2d /Server/Plugins/Debuggers
parentMerge pull request #3341 from cuberite/LuaStateImprovements (diff)
parentcUrlClient: Exported to Lua API. (diff)
downloadcuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar.gz
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar.bz2
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar.lz
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar.xz
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.tar.zst
cuberite-c94628959db64698bf4bd11d43e6369721cfe85a.zip
Diffstat (limited to 'Server/Plugins/Debuggers')
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua81
-rw-r--r--Server/Plugins/Debuggers/Info.lua12
2 files changed, 92 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();
diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua
index 8fd04d0ae..6c7eabbf2 100644
--- a/Server/Plugins/Debuggers/Info.lua
+++ b/Server/Plugins/Debuggers/Info.lua
@@ -224,6 +224,12 @@ g_PluginInfo =
HelpString = "Performs cBoundingBox API tests",
},
+ ["download"] =
+ {
+ Handler = HandleConsoleDownload,
+ HelpString = "Downloads a file from a specified URL",
+ },
+
["hash"] =
{
Handler = HandleConsoleHash,
@@ -278,6 +284,12 @@ g_PluginInfo =
HelpString = "Tests the cLineBlockTracer",
},
+ ["testurlclient"] =
+ {
+ Handler = HandleConsoleTestUrlClient,
+ HelpString = "Tests the cUrlClient",
+ },
+
["testurlparser"] =
{
Handler = HandleConsoleTestUrlParser,