mt-mods / beerchat

beerchat mod for minetest
GNU Lesser General Public License v3.0
9 stars 7 forks source link

/tell not handling self recipient #112

Closed S-S-X closed 1 year ago

S-S-X commented 1 year ago

SoloSniper: using /tell <your-username> crashes server

And stack trace follows:

2023-07-08 19:13:01: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'mesecons_commandblock' in callback on_chat_message(): /data/world//worldmods/beerchat/plugin/mute.lua:3: bad argument #1 to 'get_player_by_name' (string expected, got nil)
2023-07-08 19:13:01: ERROR[Main]: stack traceback:
2023-07-08 19:13:01: ERROR[Main]:   [C]: in function 'get_player_by_name'
2023-07-08 19:13:01: ERROR[Main]:   /data/world//worldmods/beerchat/plugin/mute.lua:3: in function 'is_muted'
2023-07-08 19:13:01: ERROR[Main]:   /data/world//worldmods/beerchat/plugin/mute.lua:14: in function 'fn'
2023-07-08 19:13:01: ERROR[Main]:   /data/world//worldmods/beerchat/hooks.lua:65: in function 'execute_callbacks'
2023-07-08 19:13:01: ERROR[Main]:   /data/world//worldmods/beerchat/plugin/override.lua:12: in function 'func'
2023-07-08 19:13:01: ERROR[Main]:   /usr/local/share/minetest/builtin/game/chat.lua:79: in function </usr/local/share/minetest/builtin/game/chat.lua:52>
2023-07-08 19:13:01: ERROR[Main]:   /usr/local/share/minetest/builtin/game/register.lua:446: in function </usr/local/share/minetest/builtin/game/register.lua:432>

Might be is_muted or something around it should be changed a bit so that it is able to tolerate weird input.

S-S-X commented 1 year ago

Checked a bit and I think root of the problem is in override: https://github.com/mt-mods/beerchat/blob/845ef5ea4fc4f841fbb574a8aa69d8fa07acff00/plugin/override.lua#L11-L14

Might be that using /tell <any recipient> without adding message after recipient name will make it crash because pattern requires %s+ which causes target to be nil if there's no space after target even if target itself is specified.

S-S-X commented 1 year ago

While fixing root cause would be very good idea I think it might anyway also be good to add nil checks to is_muted here: https://github.com/mt-mods/beerchat/blob/845ef5ea4fc4f841fbb574a8aa69d8fa07acff00/plugin/mute.lua#L2-L10

For is_muted it is kind of "just in case" fix/check but I think it is appropriate in this case (in any case where input comes through common and public event handlers).

Monniasza commented 1 year ago

Typing just /tell crashes the server

Monniasza commented 1 year ago

The following error occurs when typing just /tell:

AsyncErr: Lua: Runtime error from mod 'mesecons_commandblock' in callback on_chat_message(): D:\minetest\bin\..\mods\beerchat/plugin/mute.lua:3: bad argument #1 to 'get_player_by_name' (string expected, got nil)
stack traceback:
    [C]: in function 'get_player_by_name'
    D:\minetest\bin\..\mods\beerchat/plugin/mute.lua:3: in function 'is_muted'
    D:\minetest\bin\..\mods\beerchat/plugin/mute.lua:14: in function 'fn'
    D:\minetest\bin\..\mods\beerchat/hooks.lua:65: in function 'execute_callbacks'
    D:\minetest\bin\..\mods\beerchat/plugin/override.lua:12: in function 'func'
    D:\minetest\bin\..\builtin\game\chat.lua:79: in function <D:\minetest\bin\..\builtin\game\chat.lua:52>
    D:\minetest\bin\..\builtin\game\register.lua:446: in function <D:\minetest\bin\..\builtin\game\register.lua:432>
Monniasza commented 1 year ago

/tell is located in mesecons_commandblock, not Beerchat

S-S-X commented 1 year ago

/tell is located in mesecons_commandblock, not Beerchat

See linked PR #113 Its entry point is actually located on beerchat when beerchat is installed. Specifically in "plugin/override.lua" (code snippet on second comment here ^^).