Closed y5nw closed 9 months ago
This PR allows sending mail to non-player recipients.
There are some potential usecases for this PR:
* Interaction with automated systems (e.g. remote control) * Mailing lists; in particular, it could allow (for example) sending messages to all members of a beerchat channel, which can be useful for (for public channels) announcements or (for private channels) internal communication without having to keep track of the members.
Advtrains
Hi,
First, thanks for this PR and giving interest to mail. However, I have some problems with that PR. The concept itself is good, but some are already active, and some are planning for the upcoming version (release blockers PR have to be merged first) :
Waiting for my "colleagues", but it has at my first impression to be reworked a bit.
Waiting for my "colleagues", but it has at my first impression to be reworked a bit.
base concept sounds good to me (haven't tested the code though)
i like the idea of the recipient handler, this might be useful for some other automated mods/things :smirk:
release blockers PR have to be merged first
feel free to ping me up if you need help (might take a few days but i'll try) the other PR's have all approvals on it btw :wink:
I'll wait for #128 merged, to have more likely merging conflicts, if you agree. Anyway will be rebased soon for the next release.
All merges are now done, I'm gonna test a last time tonight.
Would you like I squash or I rebase (or I squash only some commits) ?
This PR allows sending mail to non-player recipients.
There are some potential usecases for this PR:
Checklist:
(I hope I did not miss anything important.)
Advtrains
For people into Advtrains, I put together a simple patch for Advtrains as a proof-of-concept for what can be done with this PR. The patch below allows * sending ATC commands to a train (note the protection code - the mail is rejected if the sender does not have permission to control the train) * sending mail to subscribers of a LuaATC environment, which can be useful for communicating certain changes to the code. ```diff diff --git a/advtrains/init.lua b/advtrains/init.lua index a7e5764..d1a605c 100644 --- a/advtrains/init.lua +++ b/advtrains/init.lua @@ -222,6 +222,7 @@ dofile(advtrains.modpath.."/craft_items.lua") dofile(advtrains.modpath.."/log.lua") dofile(advtrains.modpath.."/passive.lua") +dofile(advtrains.modpath.."/mail.lua") if mesecon then dofile(advtrains.modpath.."/p_mesecon_iface.lua") end diff --git a/advtrains/mail.lua b/advtrains/mail.lua new file mode 100644 index 0000000..6c0c48b --- /dev/null +++ b/advtrains/mail.lua @@ -0,0 +1,19 @@ +if mail and mail.register_recipient_handler then + mail.register_recipient_handler(function(sender, recipient) + local tid = string.match(recipient, "^advtrains/train/(.+)$") + if tid and advtrains.trains[tid] then + local train = advtrains.trains[tid] + for _, wid in ipairs(train.trainparts) do + local wagon = advtrains.wagons[wid] + if not advtrains.check_driving_couple_protection(sender, wagon.owner, wagon.whitelist) then + return false, attrans("You do not have permission to operate the train @1", tid) + end + end + return true, function(msg) + if msg.subject == "ATC" then + advtrains.atc.train_set_command(train, msg.body) + end + end + end + end) +end diff --git a/advtrains/mod.conf b/advtrains/mod.conf index 5808d1a..34c5fad 100644 --- a/advtrains/mod.conf +++ b/advtrains/mod.conf @@ -4,4 +4,4 @@ description=Core system for realistic trains in Minetest author=orwell96 depends=serialize_lib -optional_depends=mesecons,mesecons_switch,digtron +optional_depends=mesecons,mesecons_switch,digtron,mail diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index d85bedc..c1685df 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -376,6 +376,12 @@ function atlatc.run_initcode() end end - - - +--- mail interface +if mail and mail.register_recipient_handler then + mail.register_recipient_handler(function(_, pname) + local envname = string.match(pname, "atlatc/subscribers/(.+)") + if envname and atlatc.envs[envname] then + return true, atlatc.envs[envname].subscribers + end + end) +end diff --git a/advtrains_luaautomation/mod.conf b/advtrains_luaautomation/mod.conf index a737603..2fc210d 100644 --- a/advtrains_luaautomation/mod.conf +++ b/advtrains_luaautomation/mod.conf @@ -4,4 +4,4 @@ description=Lua control interface to Advanced Trains author=orwell96 depends=advtrains -optional_depends=advtrains_interlocking,advtrains_line_automation,mesecons_switch +optional_depends=advtrains_interlocking,advtrains_line_automation,mesecons_switch,mail ```