So I started to work on changing the cron some, not because I was in need of a change right now, but because I had thought about this a while when doing other things.
With the new cron, scripts aren't executed when the bot start, but instead after the cron interval (so for instance, roster update wont happend when the bot start, but 24h later).
RightsManagement and Que both have to be edited, and change "function cron()" to "function cron($cron=false)"
I want comments on this, possible changes etc as it's not meant to be for some newbie to install into their own bot, but to make it into future versions of bebot (and for advance users who like it and doesn't want to upgrade to later bebot versions).
var $crons;
....
$this->crons = Array(
"1sec"=>1,
"2sec"=>2,
"5sec"=>5,
"10sec"=>10,
"30sec"=>30,
"1min"=>60,
"2min"=>(2*60),
"5min"=>(5*60),
"1hour"=>(60*60),
"3hour"=>(3*60*60),
"6hour"=>(6*60*60),
"12hour"=>(12*60*60),
"18hour"=>(18*60*60),
"24hour"=>(24*60*60)
);
.....
function cron() {
$time = time();
foreach($this->crons as $cron => $timer) {
if (!isset($this->crontimer[$cron]) && !empty($this->cron[$cron]))
$this->crontimer[$cron] = time() + $timer; //Thoguht about using $this->crondelay here, but this way timers will actually be set with their timer from when they're set instead of from when bot starts
elseif (isset($this->crontimer[$cron]) && (empty($this->cron[$cron]) || !isset($this->cron[$cron])))
unset($this->crontimer[$cron]); //Unset if there's no active cron for it, that way the timer will be reset when a script sets a new cron
elseif (is_numeric($this->crontimer[$cron]) && $this->crontimer[$cron] < $time) {
$this->crontimer[$cron] += $timer;
foreach ($this->cron[$cron] as $ecron=>$val)
$this->cron[$cron][$ecron]->cron((is_numeric($ecron)?"":$ecron)); //the is_numeric is required for backwards compatability
}
}
}
<?php
$ct = new CronTest($bot);
$cron["7sec"]["7sectest"] = &$ct;
$cron["15sec"]["15sectest"] = &$ct;
$cron["30sec"]["resetcron"] = &$ct;
class CronTest {
var $bot;
function CronTest(&$bot) {
$this->bot = &$bot;
/*
Using 7sec and 15sec as names are not needed, it's just for simplicity of reading.
It's here the time interval is set in seconds.
Not setting for 1min because that interval is default and specificed in Bot.php
*/
$this->bot->crons["7sec"]=7;
$this->bot->crons["15sec"]=15;
}
function cron($cron=false) {
if ($cron == "7sectest") {
echo date("[H:i:s]")." This was the 7 second test - Removing it from cron\n\n";
unset($this->bot->cron["7sec"]["7sectest"]);
}
elseif ($cron == "15sectest") {
echo date("[H:i:s]")." This was the 15 second test - Removing it from cron\n\n";
unset($this->bot->cron["15sec"]["15sectest"]);
}
elseif ($cron == "resetcron") {
echo date("[H:i:s]")." 30 seconds has passed, time to start 7 and 15 second tests again\n\n";
$this->bot->cron["7sec"]["7sectest"] = &$this;
$this->bot->cron["15sec"]["15sectest"] = &$this;
}
}
}
?>