Author Topic: how to make a script that sets a password on the server at a certain time  (Read 205 times)

I need a script to automatically remove the password of my server and then add it back. For example, it adds a password at 1:00 pm est and then removes it at 10:00 pm est, and that happens every day. would anybody know how to do this?

Something about getLocalTime or getRealTime. Look at chatlog mod it has functions that record the time of day. Once you have that you need a schedule loop that checks the time of day. It's basically a function that is scheduled to call itself every couple of seconds like:

function checktimeLoop() {
       CheckTime();
       $checktimeloop = schedule(30000,0,checktimeLoop);
}
And your CheckTime function should check the time and if it's between a certain time sets $pref::server::password to whatever
« Last Edit: April 06, 2019, 01:54:27 PM by PhantOS »

Format of getDateTime is
MM/DD/YY HH:MM:SS
and time is in 24h

so your checkTimeLoop would be something like
Code: [Select]
$PasswordOnTime = "6:00:00";
$PasswordOffTime = "22:00:00";
$AutoPassword = "password";

function passwordCheckLoop() {
cancel($PasswordCheckLoopSched);

if (!isObject(MissionCleanup)) { //if this is a non-dedi and the server is shut off
return;
}

%time = getWord(getDateTime(), 1);
%onTime = $PasswordOnTime;
%offTime = $PasswordOffTime;

%onTimeConcat = stripChars(%onTime, ":");
%offTimeConcat = stripChars(%offTime, ":");
%currTimeConcat = stripChars(%time, ":");

if (%onTimeConcat > %offTimeConcat) {
//its turned on overnight
if ( %offTimeConcat > %currTimeConcat || %onTimeConcat < %currTimeConcat) {
$Pref::Server::Password = $AutoPassword;
} else {
$Pref::Server::Password = "";
}
} else {
//its turned off overnight
if ( %onTimeConcat < %currTimeConcat && %currTimeConcat < %offTimeConcat ) {
$Pref::Server::Password = $AutoPassword;
} else {
$Pref::Server::Password = "";
}
}

$PasswordCheckLoopSched = schedule(30000, 0, passwordCheckLoop);
}

thanks, legopepper helped me out a bit more over discord and I got everything working.