Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!mute doesn't work with the libcod branch #27

Closed
raphael12333 opened this issue Jun 1, 2024 · 3 comments
Closed

!mute doesn't work with the libcod branch #27

raphael12333 opened this issue Jun 1, 2024 · 3 comments

Comments

@raphael12333
Copy link
Contributor

Hello

There is no creturn() equivalent in libcod since the client commands are handled a bit differently

When a player gets muted he is still able to chat, I guess the anti-badword muting is affected too

I don't know how this should be fixed

Regards

@cato-a
Copy link
Owner

cato-a commented Jun 2, 2024

Hey

Perhaps you could redesign the code a bit and modify the CodeCallback_PlayerCommand in callback.gsc.

This is just a suggestion, I've not tested the code.

Modify command(str) function to the following:

command(str)
{
    str = codam\_mm_mmm::strip(str);
    if(str.size == 1) return; // just 1 letter, ignore

    isloggedin = (bool)isDefined(self.pers["mm_group"]);
    cmd = codam\_mm_mmm::strTok(str, " "); // is a command with level.prefix
    if(isDefined(level.commands[cmd[0]])) {
        perms = level.perms["default"];

        cmduser = "none";
        cmdgroup = cmduser;

        if(isloggedin) {
            cmduser = self.pers["mm_user"];
            cmdgroup = self.pers["mm_group"];
            perms = codam\_mm_mmm::array_join(perms, level.perms[cmdgroup]);
        }

        command = cmd[0]; // !something
        if(command != "!login") {
            commandargs = "";
            for(i = 1; i < cmd.size; i++) {
                if(i > 1)
                    commandargs += " ";
                commandargs += cmd[i];
            }

            if(commandargs == "")
                commandargs = "none";

            codam\_mm_mmm::mmlog("command;" + self getip() + ";" + codam\_mm_mmm::namefix(self.name) + ";" + cmduser + ";" + cmdgroup + ";" + command + ";" + commandargs);
        }

        commandid = level.commands[command]["id"]; // permission id
        if(commandid == 0 || permissions(perms, commandid))
            thread [[ level.commands[command]["func"] ]](cmd);
        else if(isloggedin)
            message_player("^1ERROR: ^7Access denied.");
        else
            message_player("^1ERROR: ^7No such command. Check your spelling.");
    } else {
        if(getCvarInt("scr_mm_rcm_compatibility") > 0) { // RCM compatibility
            logmessage = "";
            for(i = 0; i < cmd.size; i++) {
                if(i > 0)
                    logmessage += " ";

                logmessage += cmd[i];
            }

            codam\_mm_mmm::mmlog("say;" + codam\_mm_mmm::namefix(self.name) + ";" + logmessage);
        } else
            message_player("^1ERROR: ^7No such command. Check your spelling.");
    }
}

Create a function below command(str) function called command_mute(str):

command_mute(str)
{
    if((bool)isDefined(self.pers["mm_group"])) {
        return false;
    }

    if(level.maxmessages > 0) {
        penaltytime = level.penaltytime;
        if(self.pers["mm_chatmessages"] > level.maxmessages)
            penaltytime += self.pers["mm_chatmessages"] - level.maxmessages;
        penaltytime *= 1000;

        if(getTime() - self.pers["mm_chattimer"] >= penaltytime) {
            self.pers["mm_chattimer"] = getTime();
            self.pers["mm_chatmessages"] = 1;
        } else {
            self.pers["mm_chatmessages"]++;
            if(self.pers["mm_chatmessages"] > level.maxmessages) {
                if(self.pers["mm_chatmessages"] > 19) // 20 seconds max wait
                    self.pers["mm_chatmessages"] = 19; // 20 seconds max wait
                
                unit = "seconds";
                if(penaltytime == 1000) // 1 second
                    unit = "second";
                message_player("You are currently muted for " + (penaltytime / 1000.0) + " " + unit + ".");
            }
        }
    }

    if(isDefined(self.pers["mm_mute"]) || (level.maxmessages > 0 && self.pers["mm_chatmessages"] > level.maxmessages)) {
        return true;
    }

    if(badwords_mute(str)) {
        badmessage = "^5INFO: ^7You were silenced due to inappropriate language.";
        if(isDefined(self.badword))
            badmessage += " The offensive word in question was: " + self.badword + ".";
        message_player(badmessage);

        return true;
    }

    return false;
}

Modify callback.gsc to the following:

CodeCallback_PlayerCommand(args)
{
    if(isDefined(level.command)) {
        if(args[0] == "say" || args[0] == "say_team") {
            if(!isDefined(args[1])) {
                return;
            }

            command = "";
            for(i = 1; i < args.size; i++) {
                command += args[i];
                if(i < args.size - 1) {
                    command += " ";
                }
            }

            if(codam\_mm_commands::command_mute(command)) {
                return;
            }

            if(args[1][0] == level.prefix) {
                [[ level.command ]](command);

                return;
            }
        }
    }

    self processClientCommand();
}

Maybe it's a good idea to redesign the command codebase further to avoid all those array -> str -> array -> str and come up with something better.

@raphael12333
Copy link
Contributor Author

@cato-a i have just tried the code and now !mute works, but when muted the player can't use miscmod commands anymore

i don't think that is the case when using the main branch but i would check to be sure

i guess the way to allow the player to use miscmod commands while being muted would be to handle the client commands like codextended does, or maybe i'm missing the part in the gsc where it could be done

@cato-a
Copy link
Owner

cato-a commented Jun 2, 2024

In "main" MiscMod the player would also not be able to use any commands while muted.

For commands to work I guess you could move the following if below if(args[1][0] == level.prefix) statement:

if(codam\_mm_commands::command_mute(command)) {
    return;
}

@raphael12333 raphael12333 mentioned this issue Jun 2, 2024
@cato-a cato-a closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants