aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/tcb_ts_ui.lua
Commit message (Expand)AuthorAge
* Can disable automatic working without cancelling routeorwell962019-01-15
* Add Automatic Routesetting UIorwell962019-01-09
* Permit basic signal aspect settingorwell962018-11-19
* Do not allow static signals for routesettingorwell962018-10-30
* Fix typo in signal assignment, causing crashorwell962018-10-29
* Miscellaneous routesetting fixesorwell962018-10-29
* Add Interlocking Tool to inspect route locksorwell962018-10-26
* Add "Reset track section" functionorwell962018-10-26
* Make signal influence point (~halt point) specifiableorwell962018-10-09
* Fix various bugs found while testingorwell962018-08-13
* Add 'interlocking' privilege and add security checksorwell962018-08-12
* Automatic working (re-set certain route on train pass)orwell962018-08-12
* fix digging unconfigured tcbsorwell962018-08-12
* Signal aspect handling, make default signals compatible, fix signal diggingorwell962018-08-12
* Add routesetting callbacks.orwell962018-08-12
* Uncommitted route handling (update_route function)orwell962018-08-03
* Implement routesettingorwell962018-07-21
* Basic route management from signalling formspecorwell962018-07-04
* Signal assignment and route programming procedureorwell962018-07-04
* Implement trains blocking sectionsorwell962018-06-29
* Complete Track Section handling, incl. removing tcb's and marker entitiesorwell962018-06-26
* Add track section concept and rework TCB design, implement new linking behaviororwell962018-06-21
class="hl opt">.privileges) do privileges[priv] = true end -- If singleplayer, give all privileges except those marked as give_to_singleplayer = false if core.is_singleplayer() then for priv, def in pairs(core.registered_privileges) do if def.give_to_singleplayer then privileges[priv] = true end end -- For the admin, give everything elseif name == core.settings:get("name") then for priv, def in pairs(core.registered_privileges) do if def.give_to_admin then privileges[priv] = true end end end -- All done return { password = auth_entry.password, privileges = privileges, -- Is set to nil if unknown last_login = auth_entry.last_login, } end, create_auth = function(name, password) assert(type(name) == "string") assert(type(password) == "string") core.log('info', "Built-in authentication handler adding player '"..name.."'") return core_auth.create({ name = name, password = password, privileges = core.string_to_privs(core.settings:get("default_privs")), last_login = os.time(), }) end, delete_auth = function(name) assert(type(name) == "string") local auth_entry = core_auth.read(name) if not auth_entry then return false end core.log('info', "Built-in authentication handler deleting player '"..name.."'") return core_auth.delete(name) end, set_password = function(name, password) assert(type(name) == "string") assert(type(password) == "string") local auth_entry = core_auth.read(name) if not auth_entry then core.builtin_auth_handler.create_auth(name, password) else core.log('info', "Built-in authentication handler setting password of player '"..name.."'") auth_entry.password = password core_auth.save(auth_entry) end return true end, set_privileges = function(name, privileges) assert(type(name) == "string") assert(type(privileges) == "table") local auth_entry = core_auth.read(name) if not auth_entry then auth_entry = core.builtin_auth_handler.create_auth(name, core.get_password_hash(name, core.settings:get("default_password"))) end -- Run grant callbacks for priv, _ in pairs(privileges) do if not auth_entry.privileges[priv] then core.run_priv_callbacks(name, priv, nil, "grant") end end -- Run revoke callbacks for priv, _ in pairs(auth_entry.privileges) do if not privileges[priv] then core.run_priv_callbacks(name, priv, nil, "revoke") end end auth_entry.privileges = privileges core_auth.save(auth_entry) core.notify_authentication_modified(name) end, reload = function() core_auth.reload() return true end, record_login = function(name) assert(type(name) == "string") local auth_entry = core_auth.read(name) assert(auth_entry) auth_entry.last_login = os.time() core_auth.save(auth_entry) end, iterate = function() local names = {} local nameslist = core_auth.list_names() for k,v in pairs(nameslist) do names[v] = true end return pairs(names) end, } core.register_on_prejoinplayer(function(name, ip) if core.registered_auth_handler ~= nil then return -- Don't do anything if custom auth handler registered end local auth_entry = core_auth.read(name) if auth_entry ~= nil then return end local name_lower = name:lower() for k in core.builtin_auth_handler.iterate() do if k:lower() == name_lower then return string.format("\nCannot create new player called '%s'. ".. "Another account called '%s' is already registered. ".. "Please check the spelling if it's your account ".. "or use a different nickname.", name, k) end end end) -- -- Authentication API -- function core.register_authentication_handler(handler) if core.registered_auth_handler then error("Add-on authentication handler already registered by "..core.registered_auth_handler_modname) end core.registered_auth_handler = handler core.registered_auth_handler_modname = core.get_current_modname() handler.mod_origin = core.registered_auth_handler_modname end function core.get_auth_handler() return core.registered_auth_handler or core.builtin_auth_handler end local function auth_pass(name) return function(...) local auth_handler = core.get_auth_handler() if auth_handler[name] then return auth_handler[name](...) end return false end end core.set_player_password = auth_pass("set_password") core.set_player_privs = auth_pass("set_privileges") core.remove_player_auth = auth_pass("delete_auth") core.auth_reload = auth_pass("reload") local record_login = auth_pass("record_login") core.register_on_joinplayer(function(player) record_login(player:get_player_name()) end)