17.09.2009, 14:45
(
Последний раз редактировалось Calgon; 31.08.2010 в 14:27.
)
A very simple RCON automatic password changer, just really to show you how it's changed (for the newbies), may come in useful.
The timer is set to automatically change the RCON password and print it to the server console every half an hour.
FYI.. I don't care about credits for this as long as you don't re-produce this with the exact same code or just modified (unless you're contributing an update/fix, in this thread).
Older Version (a little less efficient)
Added /forcepasschange for connected RCON admins. It executes PasswordChange() and resets the timer.
Added (thanks to Popz) alphanumeric support; passwords are now alphanumeric and differ in case.
Added definable password length, you can change it by editing the PASSWORD_LENGTH variable.
[31st of August 2010] Added improved code written by ****** (below)
The timer is set to automatically change the RCON password and print it to the server console every half an hour.
FYI.. I don't care about credits for this as long as you don't re-produce this with the exact same code or just modified (unless you're contributing an update/fix, in this thread).
Older Version (a little less efficient)
pawn Код:
#include <a_samp>
/*
---------------------------
Automatic RCON Password Changer (ARPC).
Created by Calgon.
---------------------------
Credits to DracoBlue, using DCMD. Would use ZCMD, but couldn't be bothered to use a billion includes.
Credits to Popz, for the alphanumeric password idea (and a vast amount of the code for it).
Credits to ******, for the simple but effective RandomEx().
*/
#define PASSWORD_LENGTH 20
new RconPass[PASSWORD_LENGTH];
new changer;
forward PasswordChange();
forward RandomEx(min, max);
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
public OnFilterScriptInit()
{
print(" ARPC has been initiated.");
PasswordChange();
changer = SetTimer("PasswordChange", 300000, 1);
return 1;
}
dcmd_forcepasschange(playerid, params[])
{
#pragma unused params
if(IsPlayerAdmin(playerid))
{
PasswordChange();
KillTimer(changer);
changer = SetTimer("PasswordChange", 300000, 1);
}
else
{
SendClientMessage(playerid, 0xFFFFFFAA, "You must connect to RCON.");
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(forcepasschange, 15, cmdtext);
return 0;
}
public RandomEx(min, max)
{
return random(max - min) + min;
}
public PasswordChange()
{
new string[128];
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && IsPlayerAdmin(i))
{
SendClientMessage(i, 0xFFFFFFAA, "The RCON password is changing!");
}
}
new charset[63] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(new i = 0; i < PASSWORD_LENGTH; i++)
{
RconPass[i] = charset[RandomEx(0,62)];
}
format(string, sizeof(string), "rcon_password %s", RconPass);
SendRconCommand(string);
printf(" [SYSTEM] A new RCON password has been set (%s).", RconPass);
return 1;
}
public OnFilterScriptExit()
{
KillTimer(changer);
print("ARPC is now de-initializing..");
return 1;
}
Added (thanks to Popz) alphanumeric support; passwords are now alphanumeric and differ in case.
Added definable password length, you can change it by editing the PASSWORD_LENGTH variable.
[31st of August 2010] Added improved code written by ****** (below)
pawn Код:
#include <a_samp>
/*
---------------------------
Automatic RCON Password Changer (ARPC).
Created by Calgon.
---------------------------
Credits to DracoBlue, using DCMD. Would use ZCMD, but couldn't be bothered to use a billion includes.
Credits to Popz, for the alphanumeric password idea (and a vast amount of the code for it).
Credits to ******, for the simple but effective RandomEx() & for re-writing this version.
*/
#define PASSWORD_LENGTH 20
new
gTimer;
forward PasswordChange();
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
public OnFilterScriptInit()
{
print(" ARPC has been initiated.");
PasswordChange();
gTimer = SetTimer("PasswordChange", 300000, 1);
return 1;
}
dcmd_forcepasschange(playerid, params[])
{
#pragma unused params
if(IsPlayerAdmin(playerid))
{
PasswordChange();
KillTimer(gTimer);
gTimer = SetTimer("PasswordChange", 300000, 1);
}
else
{
SendClientMessage(playerid, 0xFFFFFFAA, "You must connect to RCON.");
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
dcmd(forcepasschange, 15, cmdtext);
return 0;
}
RandomEx(min, max)
{
return random(max - min) + min;
}
public PasswordChange()
{
new
string[PASSWORD_LENGTH + 15];
static const
charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for(new i = 0; i < PASSWORD_LENGTH; i++)
{
string[i] = charset[RandomEx(0, sizeof (charset) - 1)];
}
printf(" [SYSTEM] A new RCON password has been set (%s).", string);
format(string, sizeof(string), "rcon_password %s", string);
SendRconCommand(string);
return 1;
}
public OnFilterScriptExit()
{
KillTimer(gTimer);
print("ARPC is now de-initializing..");
return 1;
}