Skip to content
Snippets Groups Projects
Commit c3c6731d authored by joenas's avatar joenas
Browse files

Breaking changes:

Removed port setting (fixes #9)
Throw errors when weird/faulty matrix url (work on #10)
Added neturl for url parsing
parent b601d5cc
Branches
No related tags found
No related merge requests found
[submodule "lua-matrix"] [submodule "lua-matrix"]
path = lua-matrix path = lua-matrix
url = https://github.com/diggers-mt/lua-matrix url = https://github.com/diggers-mt/lua-matrix
[submodule "neturl"]
path = neturl
url = https://github.com/golgote/neturl.git
...@@ -62,12 +62,13 @@ secure.trusted_mods = matrix ...@@ -62,12 +62,13 @@ secure.trusted_mods = matrix
* `matrix.password`: Password for Matrix user * `matrix.password`: Password for Matrix user
* `matrix.server`: Server to connect to, include http(s), `https://matrix.org` * `matrix.server`: Server to connect to, include http(s) and port, `https://matrix.org`
* `matrix.port`: Server port, default `8448`
* `matrix.room_id`: Room to join, `room_id` in matrix. Always starts with `!` * `matrix.room_id`: Room to join, `room_id` in matrix. Always starts with `!`
### Removed, don't use
* `matrix.port`: Server port, default `8448`
## License ## License
......
...@@ -28,6 +28,5 @@ end ...@@ -28,6 +28,5 @@ end
setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org
setting("string", "server", nil, true) -- Server address to connect to setting("string", "server", nil, true) -- Server address to connect to
setting("number", "port", 8448) -- Server port to connect to
setting("string", "room_id", nil, true) -- Channel to join (not needed?) setting("string", "room_id", nil, true) -- Channel to join (not needed?)
setting("string", "password", nil, true) -- Server password setting("string", "password", nil, true) -- Server password
function eprintf(fmt, ...)
minetest.log("info", fmt:format(...))
end
function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
local sb = {}
for key, value in pairs (tt) do
table.insert(sb, string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
table.insert(sb, "{\n");
table.insert(sb, table_print (value, indent + 2, done))
table.insert(sb, string.rep (" ", indent)) -- indent it
table.insert(sb, "}\n");
elseif "number" == type(key) then
table.insert(sb, string.format("\"%s\"\n", tostring(value)))
else
table.insert(sb, string.format(
"%s = \"%s\"\n", tostring (key), tostring(value)))
end
end
return table.concat(sb)
else
return tt .. "\n"
end
end
function to_string( tbl )
if "nil" == type( tbl ) then
return tostring(nil)
elseif "table" == type( tbl ) then
return table_print(tbl)
elseif "string" == type( tbl ) then
return tbl
else
return tostring(tbl)
end
end
...@@ -13,6 +13,7 @@ end ...@@ -13,6 +13,7 @@ end
ie.package.path = ie.package.path =
modpath.."/lua-matrix/?.lua;" modpath.."/lua-matrix/?.lua;"
..modpath.."/neturl/lib/?.lua;"
..ie.package.path ..ie.package.path
matrix = { matrix = {
...@@ -24,16 +25,16 @@ matrix = { ...@@ -24,16 +25,16 @@ matrix = {
} }
dofile(modpath.."/config.lua") dofile(modpath.."/config.lua")
--dofile(modpath.."/debug.lua")
local function eprintf(fmt, ...)
minetest.log("info", fmt:format(...))
end
-- Temporarily set require so that LuaIRC can access it -- Temporarily set require so that LuaIRC can access it
local old_require = require local old_require = require
require = ie.require require = ie.require
local client = require("matrix").client(matrix.config.server..":"..matrix.config.port) dofile(modpath.."/validate_server.lua")
local hs_url = validate_server(matrix.config.server)
local client = require("matrix").client(hs_url)
local start_ts = os.time() * 1000 local start_ts = os.time() * 1000
......
Subproject commit e69ad0d005d7d70ff445d823ff69f1b41b6157ea
...@@ -7,10 +7,6 @@ matrix.user (Username) string ...@@ -7,10 +7,6 @@ matrix.user (Username) string
# Server to connect to, include http(s) # Server to connect to, include http(s)
matrix.server (Matrix server) string https://matrix.org matrix.server (Matrix server) string https://matrix.org
# Server port.
# The standard matrix port is 8448
matrix.port (Server port) int 8448
# Channel the bot joins after connecting. # Channel the bot joins after connecting.
matrix.room_id (Channel to join) string matrix.room_id (Channel to join) string
......
local url = require "net.url"
function validate_server(hs_url)
u = url.parse(hs_url):normalize()
if not (u.host and u.scheme) then
return error("'"..hs_url.."' doesn't look like a valid url. Please specify scheme (http/s) and hostname")
end
if u.port and u.port == 8448 and u.scheme == 'http' then
return error("Port 8448 is for https, make sure your homeserver URL is correct")
end
if u.port and u.port == 8008 and u.scheme == 'https' then
minetest.log("warn", "Port 8008 is not https, make sure your homeserver URL is correct")
end
return hs_url
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment