[Tutorial] RCON Login protection
#1

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
PHP код:
new RconAttempt[MAX_PLAYERS]; // This variable will hold the amount of attempts the player has 
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.

PHP код:
#define MAX_RCONATTEMPTS 2
// This sets the maximum of attempts  to 2 
Alright, these are basically the only variables we need.

Let's jump to the following callback in our script.
PHP код:
public OnRconLoginAttempt(ip[], password[], success
We will check if the player that tries to login has failed to login, because only then we will increase the 'RconAttempt' variable.
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 0GetPlayerPoolSize(); <= ji++) // 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(ipnameMAX_PLAYER_NAME); // Get the player's name
            
GetPlayerIp(ipIP32); // Check the player's IP
            
if(RconAttempt[i] < MAX_RCONATTEMPTS && !strcmp(ippIP)) //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(ippIP)) // Check if the player reached the maximum attempts (2)
            
{
                
format(stringsizeof string"%s has been automatically banned from the server. Reason: Attempting to hack the RCON password."pname);
                
SendClientMessageToAll(COLOR_REDstring); // Send the formatted message to everyone in red.
                
Ban(i); // Ban the player who tried to login twice.
            
}
        }
    }

This is what the code should look like in the end:
PHP код:
public OnRconLoginAttempt(ip[], password[], success)
{
    if(!
success)
    {
        new 
string[128], pIP[32], pname[MAX_PLAYER_NAME];
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerConnected(i))
            {
                
GetPlayerName(ipnameMAX_PLAYER_NAME);
                
GetPlayerIp(ipIP32);
                if(
RconAttempt[i] < MAX_RCONATTEMPTS && !strcmp(ippIP))
                {
                    
RconAttempt[i]++;
                }
                else if(
RconAttempt[i] >= MAX_RCONATTEMPTS && !strcmp(ippIP))
                {
                    
format(stringsizeof string"%s has been automatically banned from the server. Reason: Attempting to hack the RCON password."pname);
                    
SendClientMessageToAll(COLOR_REDstring);
                    
Ban(i);
                }
            }
        }
    }

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.
Reply


Messages In This Thread
RCON Login protection - by saffierr - 05.07.2017, 00:21
Re: RCON Login protection - by SteSte - 05.07.2017, 00:38
Re: RCON Login protection - by Astralis - 05.07.2017, 00:42
Re: RCON Login protection - by SteSte - 05.07.2017, 00:53
Re: RCON Login protection - by Konstantinos - 05.07.2017, 08:24
Re: RCON Login protection - by iLearner - 05.07.2017, 11:37
Re: RCON Login protection - by saffierr - 05.07.2017, 11:55
Re: RCON Login protection - by saffierr - 05.07.2017, 11:57
Re: RCON Login protection - by RxErT - 05.07.2017, 12:19
Re: RCON Login protection - by saffierr - 05.07.2017, 16:27
Re: RCON Login protection - by Eoussama - 05.07.2017, 17:04
Re: RCON Login protection - by Vince - 05.07.2017, 17:15
Re: RCON Login protection - by HoussemGaming - 05.07.2017, 18:41
Re: RCON Login protection - by Meller - 05.07.2017, 21:10
Re: RCON Login protection - by saffierr - 06.07.2017, 02:12
Re: RCON Login protection - by coool - 06.07.2017, 12:22
Re: RCON Login protection - by iLearner - 06.07.2017, 12:38
Re: RCON Login protection - by TheRealMan - 06.07.2017, 12:40
Re: RCON Login protection - by saffierr - 06.07.2017, 13:10
Re: RCON Login protection - by coool - 07.07.2017, 06:09
Re: RCON Login protection - by Beryllium - 07.07.2017, 07:18
Re: RCON Login protection - by TeKno - 30.07.2017, 09:02
Re: RCON Login protection - by C4rtm4n - 01.08.2017, 09:42

Forum Jump:


Users browsing this thread: 2 Guest(s)