#Server.Command not working as expected

1 messages ยท Page 1 of 1 (latest)

thick agate
#

Issue

When using Server.Command() it gives an error of Command '' not found

Platform

It seems to be Carbon specific. Lot of plugins use this, for example SkillTree (which is where we found the issue). Below is a quick test plugin I made to reproduce the issue

using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Test", "mjmfighter", "1.0.0")]
    [Description("Test plugin")]
    public class Test : RustPlugin
    {
        private void OnServerInitialized()
        {
            permission.RegisterPermission("test.perm", this);
        }

        [ConsoleCommand("testaddperm")]
        private void AddPerm(ConsoleSystem.Arg arg)
        {
            if (!arg.IsAdmin)
            {
                arg.ReplyWith("You do not have permission to use this command.");
                return;
            }
            var player = arg.GetPlayerOrSleeper(0);
            Puts($"Adding permission to {player.displayName}");
            Server.Command($"c.grant user {player.UserIDString} test.perm");
        }

        [ConsoleCommand("testremoveperm")]
        private void RemovePerm(ConsoleSystem.Arg arg)
        {
            if (!arg.IsAdmin)
            {
                arg.ReplyWith("You do not have permission to use this command.");
                return;
            }
            var player = arg.GetPlayerOrSleeper(0);
            Puts($"Revoking permission to {player.displayName}");
            Server.Command($"c.revoke user {player.UserIDString} test.perm");
        }
    }
}

This is the error you get (along with me copy and pasting the command to show it works as expected when run manually):

testaddperm mjmfighter
[Test] Adding permission to mjmfighter -OML-
Command 'c.grant user 76561197999436353 test.perm' not found
c.grant user 76561197999436353 test.perm
Granted user 'mjmfighter -OML-' permission 'test.perm'
worldly parcel
#

I feel like this must be a regression - when I first started using Carbon several months ago, a custom map I bought came with a plugin that used Server.Command("o.unload SomeMapName"); which I swear worked after I changed o.unload to c.unload.

#

Also, what if you change it to something like this: Server.Command("c.grant", "user", $"{player.UserIDString}", "test.perm");?

thick agate
west zenith
#

at no point it should say that, but ill test it locally shortly

thick agate
west zenith
#

๐Ÿ˜„

#

tf tho, weird ass issue

#

Server.Command("c.grant", "user", $"{player.UserIDString}", "test.perm"); should absolutely work

#

doing Server.Command($"c.grant user {player.UserIDString} {test.perm}"); shouldn't, because you've included all arguments in the command name

thick agate
#

But a lot of plugins do it that way, and it has worked in the past. So maybe facepunch changed something?

#

and neither work ๐Ÿ˜‚

west zenith
#

forgot that oxide's special

#

will fix that ready for the next Carbon update

thick agate
#

awesome, thanks!

worldly parcel
west zenith
#

exactly

#

i deliberately coded it like that in Carbon since it makes sense, there'd be a params string[] args after the command name in which one'd include the arguments in

#

makes 0 sense

worldly parcel
#

this is what happens when API authors don't write documentation on how to use their stuff, and let lazy/hurried developers figure it out on their own ๐Ÿ˜‰

thick agate
#

"ConsoleSystem.Run combines it all into one string anyways, so who cares" - probably some dev somewhere

worldly parcel
west zenith
#

fixed it locally, doing further testing then committing the fix

#

it will support both versions

west zenith
#

alright, now these two variants work as expected:

        Server.Command("c.grant user 76561199282176194 test.use"); 
        Server.Command("c.revoke", "user", 76561199282176194, "test.use");
#

can also do:

        Server.Command("c.grant user", 76561199282176194, "test.use");```
thick agate
#

Awesome, good to hear! Thanks Raul!

west zenith