05.07.2017, 00:21
(
Последний раз редактировалось saffierr; 06.07.2017 в 13:10.
)
Hey there folks of Samp.
This is a simple and short tutorial on how to catch a player that's attempting to login to RCON.
I seriously hope, you won't just copy+paste everything, but rather read every explanation and write it yourself instead,
Only then, this tutorial has reached its clue for you.
Alright, let's start creating variables first.
Create this variable outside a callback somewhere ontop of your script
We will create a maximum amount of attempts for the player to attempt to login to RCON
I personally would go for 2 attempts, because let's say you're the real owner and you per acidentally mistyped the rcon's password.
Alright, these are basically the only variables we need.
Let's jump to the following callback in our script.
We will check if the player that tries to login has failed to login, because only then we will increase the 'RconAttempt' variable.
This is what the code should look like in the end:
Note: The formatted message won't be seen for the banned player, you will have to create a timer for that, but that's something aside of this tutorial.
I hope this tutorial is helpful for atleast 1 person.
Peace out.
This is a simple and short tutorial on how to catch a player that's attempting to login to RCON.
I seriously hope, you won't just copy+paste everything, but rather read every explanation and write it yourself instead,
Only then, this tutorial has reached its clue for you.
Alright, let's start creating variables first.
Create this variable outside a callback somewhere ontop of your script
PHP код:
new RconAttempt[MAX_PLAYERS]; // This variable will hold the amount of attempts the player has
I personally would go for 2 attempts, because let's say you're the real owner and you per acidentally mistyped the rcon's password.
PHP код:
#define MAX_RCONATTEMPTS 2
// This sets the maximum of attempts to 2
Let's jump to the following callback in our script.
PHP код:
public OnRconLoginAttempt(ip[], password[], success)
PHP код:
if(!success) // this checks if the player didn't succeed to login
{
new string[128], pIP[32], pname[MAX_PLAYER_NAME]; // This will hold the message we are going to send to all players
// We will now have to loop through all the online players because 'playerid' isn't usable in this callback.
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) // This is the loop, 'GetPlayerPoolSize' checks the highest ID IG, hence I'd rather use that loop instead of MAX_PLAYERS;
{
if(IsPlayerConnected(i)) // Check if the player is even connected
{
GetPlayerName(i, pname, MAX_PLAYER_NAME); // Get the player's name
GetPlayerIp(i, pIP, 32); // Check the player's IP
if(RconAttempt[i] < MAX_RCONATTEMPTS && !strcmp(ip, pIP)) //Check if the player hasn't reached the MAX_RCONATTEMPTS
{
RconAttempt[i]++; // if it's not reached, we will increase this variable
}
else if(RconAttempt[i] >= MAX_RCONATTEMPTS && !strcmp(ip, pIP)) // Check if the player reached the maximum attempts (2)
{
format(string, sizeof string, "%s has been automatically banned from the server. Reason: Attempting to hack the RCON password.", pname);
SendClientMessageToAll(COLOR_RED, string); // Send the formatted message to everyone in red.
Ban(i); // Ban the player who tried to login twice.
}
}
}
}
PHP код:
public OnRconLoginAttempt(ip[], password[], success)
{
if(!success)
{
new string[128], pIP[32], pname[MAX_PLAYER_NAME];
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerConnected(i))
{
GetPlayerName(i, pname, MAX_PLAYER_NAME);
GetPlayerIp(i, pIP, 32);
if(RconAttempt[i] < MAX_RCONATTEMPTS && !strcmp(ip, pIP))
{
RconAttempt[i]++;
}
else if(RconAttempt[i] >= MAX_RCONATTEMPTS && !strcmp(ip, pIP))
{
format(string, sizeof string, "%s has been automatically banned from the server. Reason: Attempting to hack the RCON password.", pname);
SendClientMessageToAll(COLOR_RED, string);
Ban(i);
}
}
}
}
}
I hope this tutorial is helpful for atleast 1 person.
Peace out.