[Mod] SSCSM implementation [sscsm]

Post Reply
User avatar
luk3yx
Member
Posts: 83
Joined: Sun Oct 21, 2012 18:14
GitHub: luk3yx
IRC: luk3yx
In-game: luk3yx
Location: Earth
Contact:

[Mod] SSCSM implementation [sscsm]

by luk3yx » Post

Minetest server-sent CSM proof-of-concept

Source (alternate links: GitHub, GitLab).

A lua-based implementation of SSCSMs. This mod (probably) requires Minetest 5.0.0 or later.

How it works

Any client with the CSM installed will automatically attempt to request SSCSMs from the server via a mod channel. If the server has this mod installed, it will reply with a few messages containing the mod name and partially minified mod code. The CSM will then create a separate environment so SSCSMs cannot mess with existing CSMs (and so CSMs do not accidentally interfere with SSCSMs), and execute the SSCSMs inside this environment. Note that it is trivial for users to modify this environment. The server-side mod sends two "built-in" SSCSMs before and after all other SSCSMs to add extra helper functions (in the sscsm namespace), to execute register_on_mods_loaded callbacks and attempt to leave the mod channel.

Installation (client-side mod)

To install the CSM, you can follow GreenDimond's CSM installation guide. If you would like to allow/deny/inspect code before running SSCSMs, use the "csm_strict" directory (and make sure to rename it to "sscsm_strict" or "sscsm") instead.

Direct download

Installation (server-side mod)

The server-side mod can be installed normally, however mod channels must be enabled to communiate with clients (add enable_mod_channels = true to minetest.conf). SSCSMs will most likely require a less strict csm_restriction_flags setting, adding csm_restriction_flags = 60 to minetest.conf should fix most chat-oriented SSCSMs (but will also allow other CSMs to send chat messages).

API

The API is available on the git repository.

Dependencies

This mod is a library for other mods to use and has no dependencies.

License

This SSCSM implementation is licensed under the LGPL v3.0+ license.
Last edited by luk3yx on Fri Dec 25, 2020 03:18, edited 2 times in total.
git_undo() { [ -e .git ] || return 1; local r=$(git remote get-url origin); cd ..; rm -rf "$OLDPWD"; git clone "$r" "$OLDPWD"; cd "$OLDPWD"; }

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: [Mod] SSCSM implementation [sscsm]

by sirrobzeroone » Post

Hey luk3yx,

Do you have a small example mod(s) which demonstrates server/client communication using SSCSM? or know of a mod that makes use of sscsm? I tend to learn better if I can see something working and slowly pull it apart.

Thanks

Edit: Not sure if Im doing something else wrong but I'm also getting these errors in debug:

Code: Select all

2020-07-26 19:14:24: WARNING[Main]: [SSCSM] SSCSMs enabled, however CSMs cannot send chat messages! This will prevent SSCSMs from sending messages to the server.
2020-07-26 19:14:24: WARNING[Server]: [SSCSM] Testing mode enabled.
2020-07-26 19:14:24: ERROR[Server]: SSCSM "sscsm:badtest" has unsatisfied dependencies: "bad_mod", "bad3"
I've added these too minetest.conf as well:

enable_mod_channels = true
csm_restriction_flags = 50 << did have this at 60 but dropped it to 50 to try and resolve the error but no luck.

User avatar
luk3yx
Member
Posts: 83
Joined: Sun Oct 21, 2012 18:14
GitHub: luk3yx
IRC: luk3yx
In-game: luk3yx
Location: Earth
Contact:

Re: [Mod] SSCSM implementation [sscsm]

by luk3yx » Post

sirrobzeroone wrote:
Sun Jul 26, 2020 07:45
Hey luk3yx,

Do you have a small example mod(s) which demonstrates server/client communication using SSCSM? or know of a mod that makes use of sscsm? I tend to learn better if I can see something working and slowly pull it apart.

Thanks
There are the weather_lite and advmarkers mods.
sirrobzeroone wrote:
Sun Jul 26, 2020 07:45
Edit: Not sure if Im doing something else wrong but I'm also getting these errors in debug:

Code: Select all

2020-07-26 19:14:24: WARNING[Main]: [SSCSM] SSCSMs enabled, however CSMs cannot send chat messages! This will prevent SSCSMs from sending messages to the server.
2020-07-26 19:14:24: WARNING[Server]: [SSCSM] Testing mode enabled.
2020-07-26 19:14:24: ERROR[Server]: SSCSM "sscsm:badtest" has unsatisfied dependencies: "bad_mod", "bad3"
I've added these too minetest.conf as well:

enable_mod_channels = true
csm_restriction_flags = 50 << did have this at 60 but dropped it to 50 to try and resolve the error but no luck.
The first warning is caused by csm_restriction_flags being set to 50 instead of 60 (the setting uses byte flags as described here, I strongly recommend changing it back to 60). The other two messages are from the SSCSM library registering testing SSCSMs, they will go away (and the testing SSCSMs won't be registered) if you install a mod that uses SSCSM.
git_undo() { [ -e .git ] || return 1; local r=$(git remote get-url origin); cd ..; rm -rf "$OLDPWD"; git clone "$r" "$OLDPWD"; cd "$OLDPWD"; }

User avatar
LRV
Helper
Posts: 378
Joined: Mon Dec 19, 2016 17:29
GitHub: Mooncarguy
In-game: Mooncarman Mooncarguy

Re: [Mod] SSCSM implementation [sscsm]

by LRV » Post

Topic follows guidelines and was moved.
This is a cool signature. :)

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] SSCSM implementation [sscsm]

by Miniontoby » Post

Can we please get an example for server side using command to send message to client saying a number and and then client side using a command to send a letter to the server?

EDIT: I found out that you need to use the sscsm.register function on the server side to be able to have commands for the client... It could have been better documentated
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: [Mod] SSCSM implementation [sscsm]

by Miniontoby » Post

Idk how and why, but I think this mod has to do with the fact I have lost all my csm's!

EDIT: I found them using a program.

Now, I would love to require different stuff, but the require function not existing
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

User avatar
luk3yx
Member
Posts: 83
Joined: Sun Oct 21, 2012 18:14
GitHub: luk3yx
IRC: luk3yx
In-game: luk3yx
Location: Earth
Contact:

Re: [Mod] SSCSM implementation [sscsm]

by luk3yx » Post

Miniontoby wrote:
Mon May 16, 2022 15:01
Can we please get an example for server side using command to send message to client saying a number and and then client side using a command to send a letter to the server?

EDIT: I found out that you need to use the sscsm.register function on the server side to be able to have commands for the client... It could have been better documentated
Sending messages from the server to the client is done in MultiCraft's weather_lite mod to co-ordinate weather changes across all clients. My advmarkers mod sends messages in both directions.

There's documentation here, though I don't really have any examples. MultiCraft has some SSCSM API documentation at https://github.com/MultiCraft/MultiCraf ... 3213-L3315, however I don't know if this is any more useful than README.md.
Miniontoby wrote:
Wed May 18, 2022 16:56
Idk how and why, but I think this mod has to do with the fact I have lost all my csm's!

EDIT: I found them using a program.
It shouldn't be able to touch existing CSMs.
Miniontoby wrote:
Wed May 18, 2022 16:56
Now, I would love to require different stuff, but the require function not existing
To use multiple code files in SSCSMs, you have to register multiple SSCSMs and make them depend on each other with something like this:

Code: Select all

sscsm.register({
    name = 'mymod:sscsm1',
    file = minetest.get_modpath('mymod') .. '/sscsm1.lua',
})

sscsm.register({
    name = 'mymod:sscsm2',
    file = minetest.get_modpath('mymod') .. '/sscsm2.lua',
    depends = {'mymod:sscsm1'},
})
In the above code, `sscsm1.lua` is loaded before `sscsm2.lua`.

If you were wanting to require() something like luasocket, that isn't possible in CSMs (at least without engine modifications).
git_undo() { [ -e .git ] || return 1; local r=$(git remote get-url origin); cd ..; rm -rf "$OLDPWD"; git clone "$r" "$OLDPWD"; cd "$OLDPWD"; }

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests