cato-a / CoDaM_MiscMod

Official MiscMod for CoDaM in Call of Duty 1.1
BSD 3-Clause "New" or "Revised" License
15 stars 5 forks source link

developer "1" + no mm_user + send message = crash #19

Closed raphael12333 closed 11 months ago

raphael12333 commented 11 months ago

Hello Since I started using MiscMod a year ago, i always struggled to understand how to make a freshly installed server not to crash when sending a chat message

I just noticed it crashes when using developer "1" and not defining any account with permissions It crashes even when scr_mm_commands is not enabled

Here is the log part:

clientCommand: raph : 8 : say "t"
******* script runtime error *******
undefined is not a function pointer: (file 'callback.gsc', line 3)
 [[ level.command ]](str);
          *
called from:
(file 'callback.gsc', line 1)
CodeCallback_PlayerCommand(str) // add to callback.gsc
*
************************************
********************
ERROR: script runtime error
(see console for details)
********************
----- Server Shutdown -----
==== ShutdownGame ====

What do you think about it? It sounds really problematic to me, but maybe i didn't pay enough attention to the log and the reason for this crash is obvious for the people But in any case i think would be nice if MiscMod can run with developer "1" without the need to figure this out/modify the .cfg

I'm sorry not to propose a solution right now, I will maybe try later Regards

cato-a commented 11 months ago

Hi, about time to report it if you know known about it for a year.

I don't remember having a crash like this. You are probably sending a chat message before level.command is defined. You can test by letting the server run a while before sending a chat message.

To fix this you can check if the level.command call in callback.gsc is defined using the isDefined() function:

CodeCallback_PlayerCommand(str) // add to callback.gsc
{
    if(isDefined(level.command))
        [[ level.command ]](str);
}

I've had a look at the source code and it looks like level.commands is not defined when groups/user is not set or if the scr_mm_commands CVAR is not set. The above isDefined should fix this issue.

raphael12333 commented 11 months ago

Thank you for the fix proposal, I understand what is undefined now I'm not sure why I didn't talk about it before

If you use only the default group, so no created user, the commands would not work with this fix, if i understand correctly

I think it's due to this: https://github.com/cato-a/CoDaM_MiscMod/blob/0dcee77651f6218f8e942556b18d0ca7da72787b/___CoDaM_MiscMod/codam/_mm_commands.gsc#L20

I guess maybe level.command could be defined if scr_mm_groups != "" What do you think about it? Would that require heavy changes in the code?

cato-a commented 11 months ago

I intended to make it better at some point, just some basic checks to disable the commands if it's not configured, and I also think that the thought was you would never really use the command system without having at least 1 admin user.

But I guess you could remove the following 2 lines and see what happens. 🙂

https://github.com/cato-a/CoDaM_MiscMod/blob/0dcee77651f6218f8e942556b18d0ca7da72787b/___CoDaM_MiscMod/codam/_mm_commands.gsc#L20-L21

And you can also try to remove these 2 lines to use the built-in default group.

https://github.com/cato-a/CoDaM_MiscMod/blob/0dcee77651f6218f8e942556b18d0ca7da72787b/___CoDaM_MiscMod/codam/_mm_commands.gsc#L7-L8