RCON - Unknown command or variable
#1

Hello.
I have no idea what's going on, but sometimes I can't use ANY RCON commands ony my server, if I try anything it just spits out 'Unknown command or variable: <command>'. This is weird...
Reply
#2

bump
Reply
#3

Example command you use?
Reply
#4

any command
/rcon login
/rcon kick
/rcon say
etc.
Reply
#5

Any screens ?
If you use /rcon login [password] what happens?
Reply
#6

This message will only shown if there is a problem in "OnRconCommand".
Please show us this public.
Reply
#7

PHP код:
public OnRconCommand(cmd[])
{
    if(
strfind(cmd"sms"true) != -1)
    {
        new 
cmd2[128], idx;
        
cmd2 strtok(cmdidx);
    
        new 
Nick[MAX_PLAYER_NAME];
        
Nick strtok(cmdidx);
        
        
printf("[SMS]");
        
printf("[SMS] Aktywowano komendę");
        if(
isnull(Nick))                             return printf("[SMS] Błąd! Niepoprawny nick: '%s'"Nick);
        if(
strlen(Nick) < || strlen(Nick) > 20)     return printf("[SMS] Błąd! Za krуtki/długi nick: '%s'"Nick);
        
        
printf("[SMS] Podany nick: '%s', szukam gracza..."Nick);
        new 
Nick2[MAX_PLAYER_NAME];
        for(new 
iMAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i) == 0) continue;
             
GetPlayerName(iNick2sizeof(Nick2));
             if(!
strcmp(NickNick2))
             {
                     
printf("[SMS] Gracz znaleziony."Nick);
                    if(
IsPlayerNPC(i))     return printf("[SMS] Błąd! Wybrany gracz to NPC.");
                    
printf("[SMS] Wręczam klucz graczowi: '%s' ID: %d"Nick2i);
                    
CallRemoteFunction("DajKlucz""i"i);
                    
                    return 
1;
             }
        }
        
printf("[SMS] Błąd! Nie znaleziono gracza o nicku '%s'"Nick);
        return 
1;
    }
    return 
0;

Reply
#8

First of all, the callback must exist in a loaded filterscript for it to work in gamemode. Looking at CallRemoteFunction, I presume that's what you do.

About the problem: returning 0 means that the command did not exist and it searches in other script. What you do here is:
pawn Код:
if (...) return printf(...);
but printf does not return any specific value; thus makes it return 0. In order to fix it, all you have to do is:
pawn Код:
if (...)
{
    printf(...);
    return 1; // command was found
}
The methods you are using are not up-to-date and especially strtok which is used since 2006. sscanf is so much faster and it's the best string splitter you can find out there - consider using it!

Player pool was added in 0.3.7 and reduces the iterators a player-loop will have (especially if you have not re-defined MAX_PLAYERS and you just loop 1000 times for nothing). Foreach/y_iterate is also great include.

PHP код:
public OnRconCommand(cmd[])
{
    if (!
strcmp(cmd"sms"true))
    {
        print(
"Usage: /rcon sms <nick>");
        return 
1;
    }
    if (!
strcmp(cmd"sms "true4))
    {
        
printf("[SMS]");
        
printf("[SMS] Aktywowano komende");
        if (!(
<= strlen(cmd[4]) <= 20))
        {
            print(
"[SMS] Blad! Za krуtki/dlugi nick.");
            return 
1;
        }
        
printf("[SMS] Podany nick: '%s', szukam gracza..."cmd[4]);
        new 
Nick2[MAX_PLAYER_NAME];
        for (new 
0GetPlayerPoolSize(); <= ji++)
        {
            if (
IsPlayerConnected(i) == 0) continue;
            
GetPlayerName(iNick2sizeof(Nick2));
            if (!
strcmp(cmd[4], Nick2))
            {
                
printf("[SMS] Gracz znaleziony."cmd[4]);
                if (
IsPlayerNPC(i))
                {
                    
printf("[SMS] Blad! Wybrany gracz to NPC.");
                    return 
1;
                }
                
printf("[SMS] Wreczam klucz graczowi: '%s' ID: %d"Nick2i);
                
CallRemoteFunction("DajKlucz""i"i);
                return 
1;
            }
        }
        
printf("[SMS] Blad! Nie znaleziono gracza o nicku '%s'"cmd[4]);
        return 
1;
    }
    return 
0;

Reply
#9

Thanks!
Reply
#10

I think processing RCON Commands the same way ZCMD does is the best choice.

Код:
#define RCON:%0(%1)        forward rcon_%0(%1); public rcon_%0(%1)

public OnRconCommand(cmd[])
{
	new command[32], pos;
	while (cmd[pos] > ' ')
	{
		command[pos] = cmd[pos];
		pos++;
	}
	format(command, sizeof (command), "rcon_%s", command);
	while (cmd[pos] == ' ')
		pos++;

	if (!cmd[pos]) return CallLocalFunction(command, "s", "\1");
	return CallLocalFunction(command, "s", cmd[pos]);
}

RCON:sms(params[])
{
    if (isnull(params))
        return print("Usage: /rcon sms <nick>"), 1;

    // Just like zcmd 
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)