示例#1
0
 /**
  * Send a message to all shadowlamb main channels.
  * @param unknown_type $message
  */
 public static function sendGlobalMessage($message)
 {
     foreach (Dog::getServers() as $server) {
         $server instanceof Dog_Server;
         self::sendServerMessage($server, $message);
     }
 }
示例#2
0
 public function claim()
 {
     foreach (Dog::getServers() as $server) {
         $server instanceof Dog_Server;
         if ($this->isEnabled($server, false) && $server->isConnected()) {
             $this->claimServer($server);
         }
     }
 }
示例#3
0
 public static function cleanup($message = 'Clean shutdown!')
 {
     GWF_CachedCounter::persist();
     if (NULL !== Dog_Init::getStartupTime()) {
         GWF_Counter::increaseCount('dog_uptime', Dog_Init::getUptime());
     }
     if (self::$CLEANED === false) {
         self::$CLEANED = true;
         foreach (Dog::getServers() as $server) {
             $server instanceof Dog_Server;
             if ($server->isConnected()) {
                 $server->disconnect($message);
             }
         }
     }
     die(0);
 }
示例#4
0
 public function randomQuote()
 {
     foreach (Dog::getServers() as $server) {
         $server instanceof Dog_Server;
         foreach ($server->getChannels() as $channel) {
             $channel instanceof Dog_Channel;
             if (!$this->isEnabled($server, $channel) || ($minutes = $this->getConfig('rand_quote', 'c')) <= 0) {
                 continue;
             }
             $now = time();
             $seconds = $minutes * 60;
             $last = (int) $this->getConfig('rand_quote_t', 'c');
             $elapsed = $now - $last;
             if ($last > 0) {
                 $this->randomQuoteChannel($channel);
             }
             $this->setConfigVar('c', 'rand_quote_t', $now);
         }
     }
 }
示例#5
0
 private function announce_commit(Dog_Repo $repo)
 {
     printf("DOGMOD_CVS::announce_commit()\n");
     $subscribe_channels = Dog_RepoSubscribes::getSubscriptionsFor($repo);
     $subscribe_users = Dog_RepoUsers::getSubscriptionsFor($repo);
     foreach (Dog::getServers() as $server) {
         $server instanceof Dog_Server;
         if ($server->isConnected()) {
             foreach ($server->getUsers() as $user) {
                 $user instanceof Dog_User;
                 if (in_array($user->getID(), $subscribe_users, true)) {
                     $user->sendPRIVMSG($this->commit_message($repo, $user->getLangISO()));
                 }
             }
             foreach ($server->getChannels() as $chan) {
                 if (in_array($chan->getID(), $subscribe_channels, true)) {
                     $chan->sendPRIVMSG($this->commit_message($repo, $chan->getLangISO()));
                 }
             }
         }
     }
 }
示例#6
0
<?php

$lang = array('en' => array('help' => 'Usage: %CMD% [<message here...>]. Initiate a reboot and quit with a message.', 'default' => '%s is rebooting me :O'));
// GWF_HTTP::getFromURL("")
return Dog::reply('YOU FOUND A TODO!');
$plugin = Dog::getPlugin();
$message = $plugin->argc() === 0 ? $plugin->lang('default', array(Dog::getUser()->displayName())) : $plugin->msg();
foreach (Dog::getServers() as $server) {
    $server instanceof Dog_Server;
    $server->disconnect($message);
}
Dog_Launcher::kill();
示例#7
0
function dog_wc_solvers($key, $name, $url, $channels = array(), $max_solvercount = 100, $format)
{
    # Date we want to query
    $lastdate = GWF_Settings::getSetting('DOG_SOLVERS_DATE_' . $key, '');
    if (strlen($lastdate) !== 14) {
        $lastdate = date('YmdHis');
        GWF_Settings::setSetting('DOG_SOLVERS_DATE_' . $key, $lastdate);
    }
    $lastpair = GWF_Settings::getSetting('DOG_SOLVERS_PAIR_' . $key, '');
    # Query URL
    $url = str_replace(array('%DATE%'), array($lastdate), $url);
    // 	echo $url.PHP_EOL;
    GWF_HTTP::setTimeout(3);
    GWF_HTTP::setConnectTimeout(2);
    if (false === ($content = GWF_HTTP::getFromURL($url))) {
        return;
    }
    GWF_HTTP::setTimeout();
    GWF_HTTP::setConnectTimeout();
    // 	echo $content.PHP_EOL;
    # Nothing happened
    if ($content === '') {
        return;
    }
    $lines = explode("\n", $content);
    $changed = false;
    $badlines = 0;
    $latestdate = $lastdate;
    $firstpair = false;
    foreach ($lines as $line) {
        // 		echo "$line\n";
        if ('' === ($line = trim($line))) {
            continue;
        }
        $thedata = explode('::', $line);
        if (count($thedata) !== 12) {
            $badlines++;
            echo 'Invalid line in dog_wc_solvers: ' . $line . PHP_EOL;
            if ($badlines > 3) {
                echo "BAD URL IS: {$url}\n";
                return;
            }
            continue;
        }
        $badlines = 0;
        $thedata = array_map('unescape_csv_like', $thedata);
        # Fetch line
        # uid::cid::solve_date::1st_look::viewcount::options::time_taken::tries::username::challname::solvecount::url
        list($uid, $cid, $solvedate, $firstdate, $views, $options, $timetaken, $tries, $username, $challname, $solvercount, $challurl) = $thedata;
        if (strlen($solvedate) !== 14) {
            echo "Dateformat in {$url} is invalid: {$solvedate}\n";
            return false;
        }
        $latestdate = $solvedate;
        $pair = "{$uid}:{$cid}";
        if ($firstpair === false) {
            $firstpair = $pair;
        }
        if ($pair === $lastpair) {
            break;
        }
        if ($solvercount > $max_solvercount) {
            continue;
        }
        $msg = sprintf($format, $name, $username, $challname, $solvercount, $challurl);
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getName();
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    echo $channel . PHP_EOL;
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
        $changed = true;
    }
    # Save state
    if ($changed) {
        GWF_Settings::setSetting('DOG_SOLVERS_DATE_' . $key, $latestdate);
        GWF_Settings::setSetting('DOG_SOLVERS_PAIR_' . $key, $firstpair);
    }
}
示例#8
0
function dog_wc_forum($key, $name, $url, $channels = array(), $limit = 5, $onlygids = false, $skipgids = false)
{
    # Date we want to query
    $date = GWF_Settings::getSetting('DOG_FORUM_DATE_' . $key, date('Ymd000000'));
    if (strlen($date) !== 14) {
        $date = date('Ymd000000');
    }
    # We already know these threads for the current data stored
    $known = GWF_Settings::getSetting('DOG_FORUM_LAST_' . $key, ',');
    # Query URL
    $url = str_replace(array('%DATE%', '%LIMIT%'), array($date, $limit), $url);
    //	echo $url.PHP_EOL;
    GWF_HTTP::setTimeout(3);
    GWF_HTTP::setConnectTimeout(2);
    if (false === ($content = GWF_HTTP::getFromURL($url))) {
        return;
    }
    GWF_HTTP::setTimeout();
    GWF_HTTP::setConnectTimeout();
    //	echo $content.PHP_EOL;
    # Nothing happened
    if ($content === '') {
        return;
    }
    $latest_date = $date;
    $new_known = $known;
    $lines = explode("\n", $content);
    $changed = false;
    $badlines = 0;
    foreach ($lines as $line) {
        if ('' === ($line = trim($line))) {
            continue;
        }
        $thedata = explode('::', $line);
        if (count($thedata) !== 6) {
            $badlines++;
            echo 'Invalid line in dog_wc_forum: ' . $line . PHP_EOL;
            if ($badlines === 1) {
                echo "BAD URL IS: {$url}\n";
            }
            if ($badlines > 3) {
                return;
            }
            continue;
        }
        $badlines = 0;
        $thedata = array_map('unescape_csv_like', $thedata);
        # Fetch line
        list($threadid, $lastdate, $lock, $url, $username, $title) = $thedata;
        if (strlen($lastdate) !== 14) {
            echo "Dateformat in {$url} is invalid: {$lastdate}\n";
            return false;
        }
        $gid = (int) $lock;
        if (is_array($onlygids)) {
            if (!in_array($gid, $onlygids, true)) {
                //				echo "Not an only gid: $gid\n";
                continue;
            }
        }
        if (is_array($skipgids)) {
            if (in_array($gid, $skipgids, true)) {
                //				echo "Skipped gid: $gid\n";
                continue;
            }
        }
        # Duplicate output?
        if ($lastdate === $date && strpos($known, ',' . $threadid . ',') !== false) {
            continue;
        }
        # Is it private?
        $lock = $lock === '0' ? '' : ' locked';
        # does the date change?
        if ($latest_date !== $lastdate) {
            $latest_date = $lastdate;
            $new_known = ',';
        }
        # Mark this thread as known for this datestamp
        $new_known .= $threadid . ',';
        if (strpos($url, 'http') !== 0) {
            $url = 'http://' . $url;
        }
        # Output message
        if ($lock === ' locked') {
            $msg = sprintf('%s New%s post: %s', $name, $lock, $url);
        } else {
            $msg = sprintf('%s New post by %s in %s: %s', $name, $username, $title, $url);
        }
        if (count($channels) === 0) {
            # To all servers in the main channel
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels = $server->getChannels();
                if (count($channels) > 0) {
                    $channel = array_shift($channels);
                    $channel = $channel->getVar('chan_name');
                    $server->sendPRIVMSG($channel, $msg);
                }
            }
        } else {
            # To all servers in matching channels
            foreach (Dog::getServers() as $server) {
                $server instanceof Dog_Server;
                $channels_now = $server->getChannels();
                foreach ($channels_now as $channel) {
                    $channel instanceof Dog_Channel;
                    $channel = $channel->getName();
                    echo $channel . PHP_EOL;
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
        $changed = true;
    }
    # Save state
    if ($changed) {
        GWF_Settings::setSetting('DOG_FORUM_DATE_' . $key, $lastdate);
        GWF_Settings::setSetting('DOG_FORUM_LAST_' . $key, $new_known);
    }
}
示例#9
0
 private function onBoardTimer(Dog_Forum $board)
 {
     if (false === ($entries = $board->fetchNewEntries(10))) {
         return Dog_Log::warn('Forum Board Activities corrupt!');
     }
     if (count($entries) > 0) {
         foreach (Dog::getServers() as $server) {
             $this->onBoardServerTimer($entries, $board, $server);
         }
         $board->updateDatestamp(array_pop($entries));
     }
 }
示例#10
0
 public static function initTimers()
 {
     # Modules
     foreach (Dog_Module::getModules() as $module) {
         $module instanceof Dog_Module;
         $module->onInitTimers();
     }
     # One timer for each server.
     $d = self::getTimerDir();
     $dir = $d . 'all_servers_all';
     foreach (Dog::getServers() as $server) {
         $server instanceof Dog_Server;
         GWF_File::filewalker($dir, true, array(__CLASS__, 'initTimersDir'), false, $server);
     }
     # One timer per server for all servers.
     $dir = $d . 'all_servers_one';
     GWF_File::filewalker($dir, true, array(__CLASS__, 'initTimersDir'), false, $server);
     # One timer per server for a single server.
     $dir = $d . 'one_server_one';
     GWF_File::filewalker($dir, true, array(__CLASS__, 'initTimersDirServer'), false, NULL);
 }