RCON - Unknown command or variable -
Amads - 09.08.2016
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...
Re: RCON - Unknown command or variable -
Amads - 13.08.2016
bump
Re: RCON - Unknown command or variable -
Shinja - 13.08.2016
Example command you use?
Re: RCON - Unknown command or variable -
Amads - 13.08.2016
any command
/rcon login
/rcon kick
/rcon say
etc.
Re: RCON - Unknown command or variable -
Dayrion - 14.08.2016
Any screens ?
If you use /rcon login [password] what happens?
Re: RCON - Unknown command or variable -
GangstaSunny - 14.08.2016
This message will only shown if there is a problem in "OnRconCommand".
Please show us this public.
Re: RCON - Unknown command or variable -
Amads - 14.08.2016
PHP код:
public OnRconCommand(cmd[])
{
if(strfind(cmd, "sms", true) != -1)
{
new cmd2[128], idx;
cmd2 = strtok(cmd, idx);
new Nick[MAX_PLAYER_NAME];
Nick = strtok(cmd, idx);
printf("[SMS]");
printf("[SMS] Aktywowano komendę");
if(isnull(Nick)) return printf("[SMS] Błąd! Niepoprawny nick: '%s'", Nick);
if(strlen(Nick) < 3 || 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 i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) == 0) continue;
GetPlayerName(i, Nick2, sizeof(Nick2));
if(!strcmp(Nick, Nick2))
{
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", Nick2, i);
CallRemoteFunction("DajKlucz", "i", i);
return 1;
}
}
printf("[SMS] Błąd! Nie znaleziono gracza o nicku '%s'", Nick);
return 1;
}
return 0;
}
Re: RCON - Unknown command or variable -
Konstantinos - 14.08.2016
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 ", true, 4))
{
printf("[SMS]");
printf("[SMS] Aktywowano komende");
if (!(3 <= 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 i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if (IsPlayerConnected(i) == 0) continue;
GetPlayerName(i, Nick2, sizeof(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", Nick2, i);
CallRemoteFunction("DajKlucz", "i", i);
return 1;
}
}
printf("[SMS] Blad! Nie znaleziono gracza o nicku '%s'", cmd[4]);
return 1;
}
return 0;
}
Re: RCON - Unknown command or variable -
Amads - 14.08.2016
Thanks!
Re: RCON - Unknown command or variable -
Stinged - 14.08.2016
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;
}