Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------------------------------------------------------------------------------------------
- #include <a_samp>
- // ---------------------------------------------------------------------------------------------------------
- #define MAX_RCON_LENGHT 32 // What is the max lenght for a new RCON password?
- #define MAX_RCON_WARNINGS 5 // How many times a player can input a wrong RCON password before he gets punished?
- #define MAX_WRONG_INPUTS 3 // How many wrong RCON password inputs are needed for a new password?
- #define PUNISHMENT 1 // How should a player, who exceeded the MAX_RCON_WARNINGS limit, should be punished? 1 - ban, 2 - kick.
- // ---------------------------------------------------------------------------------------------------------
- static const rcon_characters [63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- new rcon_whiteList[] =
- {
- // "your_name",
- // "another_name", .... and so.
- };
- static
- playerWarnings [MAX_PLAYERS char],
- wrongInputs
- ;
- // ---------------------------------------------------------------------------------------------------------
- public OnPlayerConnect (playerid)
- playerWarnings {playerid} = 0;
- public OnPlayerCommandText (playerid, cmdtext[])
- {
- if (!strcmp (cmdtext, "/rcon_password", true))
- {
- new playerName [MAX_PLAYER_NAME];
- GetPlayerName (playerid, playerName, MAX_PLAYER_NAME);
- for (new i; i <= sizeof (rcon_whiteList); i++)
- {
- if (!strcmp (playerName, rcon_whiteList[i], true))
- {
- new
- currentRCON [64 + 1],
- message [128]
- ;
- GetServerVarAsString("rcon_password", currentRCON, 64);
- format (message, 128, "[ {ff0000}* {ffffff}] Current RCON is: %s", currentRCON);
- SendClientMessage (playerid, 0xFFFFFFFF, message);
- break;
- }
- else
- return SendClientMessage (playerid, 0xFFFFFFFF, "[ {ff0000}* {ffffff}] You can't use this command.");
- }
- }
- return (true);
- }
- public OnRconLoginAttempt (ip [], password [], success)
- {
- if (!success)
- {
- static playerIP [16 + 1];
- for (new i, j = GetPlayerPoolSize(); i <= j; i++)
- {
- GetPlayerIp (i, playerIP, 16);
- if (!strcmp (playerIP, ip, true))
- {
- playerWarnings {i} ++;
- wrongInputs ++;
- if (playerWarnings {i} == MAX_RCON_WARNINGS)
- {
- PunishPlayer (i);
- break;
- }
- if (wrongInputs == MAX_WRONG_INPUTS)
- {
- ChangeRCONPassword ();
- wrongInputs = 0;
- break;
- }
- break;
- }
- }
- }
- return (true);
- }
- // ---------------------------------------------------------------------------------------------------------
- ChangeRCONPassword ()
- {
- static newRCON [64], message [128];
- for (new i; i <= MAX_RCON_LENGHT; i++)
- newRCON[i] = rcon_characters [random (0-62) + 62];
- for (new i, j = GetPlayerPoolSize (); i <= j; i++)
- {
- if (!IsPlayerAdmin (i)) continue;
- format (message, 128, "[ {ff0000}* {ffffff}] The RCON password has changed: {ff0000}%s", newRCON);
- SendClientMessage (i, 0xFFFFFFFF, message);
- return (true);
- }
- format (message, 128, "rcon_password %s", newRCON);
- SendRconCommand (message);
- printf ("[ * ] The RCON password has changed: %s", newRCON);
- return (true);
- }
- PunishPlayer (playerid)
- {
- new playerName [MAX_PLAYER_NAME], message [110 + 1];
- GetPlayerName (playerid, playerName, MAX_PLAYER_NAME);
- #if PUNISHMENT == 1
- format (message, 110, "[ {ff0000}* {ffffff}] %s has been banned for several invalid RCON login tries.", playerName);
- SendClientMessageToAll (0xFFFFFFFF, message);
- BanEx (playerid, "Exceeded warnings for RCON login tries");
- #else
- format (message, 110, "[ {ff0000}* {ffffff}] %s has been kicked for several invalid RCON login tries.", playerName);
- SendClientMessageToAll (0xFFFFFFFF, message);
- Kick (playerid);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment