[Include] OPRL.inc - OnPlayerRconLogin : Calls out when a player logs in as RCON, not an IP.
#4

Quote:
Originally Posted by [WH]Marcos
Посмотреть сообщение
Good work, but I've a question: Can this include be used to create an kinda of "seccond" rcon login?
Yes, you can. I've added a second RCON example too.
pawn Код:
/*______________________________________________________________________________

                        Lordz's Second RCON System!
                        Copyright© - 2014 "SecondRCON"
                        Author : Lordz™ AKA Lordzy

NOTE:
This script is created as a filterscript, mainly as an example for the include
"OPRL" AKA "OnPlayerRconLogin". This script ensures that the second RCON request
is only sent to the player who RCON logins, not to the players who got the same
IP address.

______________________________________________________________________________*/


#define FILTERSCRIPT

#include <a_samp>
#include <OPRL>

new
    bool:RCON2LoggedIn[MAX_PLAYERS],
    RCON2WrongLogins[MAX_PLAYERS];
   
#define SECOND_RCON_DIALOG  1126 //Dialog ID of the second RCON.
#define SECOND_RCON_PASS    "testing" //Second RCON password, you can change it but keep it in quotes.
#define MAX_FALSE_2RCON_ATTEMPTS    3 //Maximum number of second RCON fails.
#define MAX_HOLD_SECONDS    120 //Maximum seconds in which a player could stay as RCON without confirming second RCON.

public OnPlayerConnect(playerid)
{
    if(IsPlayerAdmin(playerid)) RCON2LoggedIn[playerid] = true;
    else RCON2LoggedIn[playerid] = false;
    RCON2WrongLogins[playerid] = 0;
    return 1;
}

public OnFilterScriptInit()
{
    for(new i; i< GetMaxPlayers(); i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(IsPlayerAdmin(i)) RCON2LoggedIn[i] = true;
        else RCON2LoggedIn[i] = false;
        RCON2WrongLogins[i] = 0;
    }
    printf("-------------------------------------------------");
    printf("    OnPlayerRconLogin - Second RCON system");
    printf("                    Loaded!");
    printf("-------------------------------------------------");
    return 1;
}

public OnPlayerRconLogin(playerid)
{
    if(RCON2LoggedIn[playerid] == false)
    {
        SendClientMessage(playerid, -1, "{FF0000}Server : {880088}Before playing as RCON Administrator, please login to the second RCON option too.");
        ShowPlayerDialog(playerid, SECOND_RCON_DIALOG, DIALOG_STYLE_INPUT, "Second RCON Login", "Hello,\nBefore accessing RCON, please login to the second RCON.", "Login", "");
        SetTimerEx("DetectSecondRconLogin", 1000*MAX_HOLD_SECONDS, false, "d", playerid);
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == SECOND_RCON_DIALOG)
    {
        if(response)
        {
            if(!strlen(inputtext))
            {
                RCON2WrongLogins[playerid]++;
                new
                    string[128];
                if(RCON2WrongLogins[playerid] >= MAX_FALSE_2RCON_ATTEMPTS)
                {
                    new
                        Lname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, Lname, sizeof(Lname));
                    format(string, sizeof(string), "%s (ID:%d) has been automatically kicked from the server! (Reason : %d/%d)", Lname, playerid, RCON2WrongLogins[playerid], MAX_FALSE_2RCON_ATTEMPTS);
                    SendClientMessageToAll(0xFF0000FF, string);
                    return SetTimerEx("KickPlayer", 150, false, "d", playerid);
                }
                format(string, sizeof(string), "ERROR! The previous second RCON given was incorrect! (Warnings : %d/%d)", RCON2WrongLogins[playerid], MAX_FALSE_2RCON_ATTEMPTS);
                SendClientMessage(playerid, 0xFF0000FF, string);
                return ShowPlayerDialog(playerid, SECOND_RCON_DIALOG, DIALOG_STYLE_INPUT, "Second RCON Login", "Hello,\nBefore accessing RCON, please login to the second RCON.", "Login", "");
            }
            if(!strcmp(inputtext, SECOND_RCON_PASS, false))
            {
                GameTextForPlayer(playerid, "~G~ACCESS GRANTED!", 2000, 3);
                PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
                RCON2LoggedIn[playerid] = true;
                return 1;
            }
            else if(strcmp(inputtext, SECOND_RCON_PASS, false))
            {
                RCON2WrongLogins[playerid]++;
                new
                    string[128];
                if(RCON2WrongLogins[playerid] >= MAX_FALSE_2RCON_ATTEMPTS)
                {
                    new
                        Lname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, Lname, sizeof(Lname));
                    format(string, sizeof(string), "%s (ID:%d) has been automatically kicked from the server! (Reason : Wrong RCON logins | %d/%d)", Lname, playerid, RCON2WrongLogins[playerid], MAX_FALSE_2RCON_ATTEMPTS);
                    SendClientMessageToAll(0xFF0000FF, string);
                    return SetTimerEx("KickPlayer", 150, false, "d", playerid);
                }
                format(string, sizeof(string), "ERROR! The previous second RCON given was incorrect! (Warnings : %d/%d)", RCON2WrongLogins[playerid], MAX_FALSE_2RCON_ATTEMPTS);
                SendClientMessage(playerid, 0xFF0000FF, string);
                return ShowPlayerDialog(playerid, SECOND_RCON_DIALOG, DIALOG_STYLE_INPUT, "Second RCON Login", "Hello,\nBefore accessing RCON, please login to the second RCON.", "Login", "");
            }
        }
        if(!response)
        {
            new
                string[128],
                Lname[MAX_PLAYER_NAME];
            format(string, sizeof(string), "%s (ID:%d) has been automatically kicked from the server! (Reason : Wrong RCON login)", Lname, playerid);
            SendClientMessageToAll(0xFF000FF, string);
            return SetTimerEx("KickPlayer", 150, false, "d", playerid);
        }
    }
    return 1;
}


forward KickPlayer(playerid);
forward DetectSecondRconLogin(playerid);


public DetectSecondRconLogin(playerid)
{
    if(IsPlayerAdmin(playerid))
    {
        if(RCON2LoggedIn[playerid] == false)
        {
            new
                Lname[MAX_PLAYER_NAME],
                string[128];
            GetPlayerName(playerid, Lname, sizeof(Lname));
            format(string, sizeof(string), "%s (ID:%d) has been automatically kicked from the server! (Reason : Delayed RCON confirmation)", Lname, playerid);
            SendClientMessageToAll(0xFF0000FF, string);
            return SetTimerEx("KickPlayer", 150, false, "d", playerid);
        }
    }
    return 1;
}

public KickPlayer(playerid) return Kick(playerid);
Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
It can be done without the need of a continuing timer and an array. I wrote this:
pawn Код:
#include <a_samp>
#include <foreach>

main() {}

public OnRconLoginAttempt(ip[], password[], success)
{
    if (success) SetTimerEx("RetrieveRconPlayer", 1000, false, "s", ip);
    return 1;
}

forward OnPlayerRconLogin(playerid);
public OnPlayerRconLogin(playerid)
{
    printf("OnPlayerRconLogin -> playerid (%i) has been RCON logged in!", playerid);
    return 1;
}

forward RetrieveRconPlayer(ip[]);
public RetrieveRconPlayer(ip[])
{
    new
        ip2[16];

    foreach(new i : Player)
    {
        GetPlayerIp(i, ip2, 16);
        if (!strcmp(ip, ip2) && IsPlayerAdmin(i))
        {
            CallRemoteFunction("OnPlayerRconLogin", "i", i);
        }
    }
    return 1;
}
and it works very well.
It may work, however not very well. What if there are members with same IP address who have already RCON logged in?

EDIT:
I've tested your code right now to confirm well and yes I was right. It don't work well in case if there's already admins logged in as RCON with same IP address.
Код:
[22:57:45] [join] yolo has joined the server (...)
[22:57:55] RCON (In-Game): Player #1 (yolo) has logged in.
[22:57:56] OnPlayerRconLogin -> playerid (1) has been RCON logged in!
[22:58:09] RCON (In-Game): Player #0 (blabla) has logged in.
[22:58:10] OnPlayerRconLogin -> playerid (0) has been RCON logged in!
[22:58:10] OnPlayerRconLogin -> playerid (1) has been RCON logged in!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)