SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 05/07/2017, 12:21 AM   #1
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,153
Reputation: 36
Default RCON Login protection

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 Code:
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 Code:
#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 Code:
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 Code:
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 Code:
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.

Last edited by saffierr; 06/07/2017 at 01:10 PM.
saffierr is offline   Reply With Quote
Old 05/07/2017, 12:38 AM   #2
SteSte
Huge Clucker
 
SteSte's Avatar
 
Join Date: Aug 2015
Location: United States
Posts: 200
Reputation: 19
Default Re: RCON Login protection

Oh Snap! Well made, I'll come back to this for my gamemode.
+Rep
__________________
Working On:
Superhuman - Roleplay
PM me if your interested in helping.
SteSte is offline   Reply With Quote
Old 05/07/2017, 12:42 AM   #3
Astralis
High-roller
 
Join Date: Sep 2009
Location: France
Posts: 2,793
Reputation: 351
Default Re: RCON Login protection

Always a good thing to have more than one password.
__________________
Astralis is offline   Reply With Quote
Old 05/07/2017, 12:53 AM   #4
SteSte
Huge Clucker
 
SteSte's Avatar
 
Join Date: Aug 2015
Location: United States
Posts: 200
Reputation: 19
Default Re: RCON Login protection

Quote:
Originally Posted by Astralis View Post
Always a good thing to have more than one password.
You can do that?
__________________
Working On:
Superhuman - Roleplay
PM me if your interested in helping.
SteSte is offline   Reply With Quote
Old 05/07/2017, 08:24 AM   #5
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 12,005
Reputation: 1354
Default Re: RCON Login protection

So 3 unsuccessful attempts will ban everyone because you forgot to compare IPs.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System



www.SF-SE.net
play.sf-se.net:7777
Play now!
Konstantinos is offline   Reply With Quote
Old 05/07/2017, 11:37 AM   #6
iLearner
Huge Clucker
 
iLearner's Avatar
 
Join Date: Apr 2017
Posts: 289
Reputation: 64
Default Re: RCON Login protection

PHP Code:
 format(stringsizeof string"%s has been automatically banned from the server. Reason: Attempting to hack the RCON password."pname); 
Do you even know what is hacking.
iLearner is offline   Reply With Quote
Old 05/07/2017, 11:55 AM   #7
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,153
Reputation: 36
Default Re: RCON Login protection

Quote:
Originally Posted by Konstantinos View Post
So 3 unsuccessful attempts will ban everyone because you forgot to compare IPs.
Ooh yes, excuse me, I indeed did.
I will edit it once I'm back home, probably tonight.
Thank you anyways!
saffierr is offline   Reply With Quote
Old 05/07/2017, 11:57 AM   #8
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,153
Reputation: 36
Default Re: RCON Login protection

Quote:
Originally Posted by iLearner View Post
PHP Code:
 format(stringsizeof string"%s has been automatically banned from the server. Reason: Attempting to hack the RCON password."pname); 
Do you even know what is hacking.
You can call it whatever you want, that was a word I used, it's totally optional for your prefferences.
saffierr is offline   Reply With Quote
Old 05/07/2017, 12:19 PM   #9
RxErT
Big Clucker
 
RxErT's Avatar
 
Join Date: May 2016
Location: SA:MP Lemon
Posts: 78
Reputation: 5
Default Re: RCON Login protection

Quote:
Originally Posted by Heroleo911003 View Post
You can do that?
Yes, it does, try to use CrossAdmin, it has 2 Rcon passwords.
__________________
[████████] FilterScripts [████████]
Looking for a SA:MP Server With DDOS Protection and some great available stuff?
Change your mood today!
RxErT is offline   Reply With Quote
Old 05/07/2017, 04:27 PM   #10
saffierr
High-roller
 
saffierr's Avatar
 
Join Date: Jul 2013
Location: GetPlayerGirlHouse(targetplayer);
Posts: 1,153
Reputation: 36
Default Re: RCON Login protection

Added the IP Check.
saffierr is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rcon protection NexySamp Scripting Help 11 04/07/2015 02:11 PM
need help with rcon protection HeLiOn_PrImE Scripting Help 22 08/02/2014 12:36 PM
[FilterScript] [R.P.S] Rcon Protection System (/rSenha) [/rcon login = kick] Diogo_Bras Lanšamentos/Releases 14 30/04/2011 03:57 PM
HELP:i cant login as rcon using remote console or /rcon login rconpass ingame greekboy Help Archive 3 21/10/2010 12:43 PM


All times are GMT. The time now is 02:54 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.