Exemple #1
0
 function fetchFunctionDescription($func, $language = 'en')
 {
     global $message, $redirects;
     $notfoundtext = 'Nothing matches your query, try search:';
     Dog_Log::debug('phpmanual: fetching ' . $func . ' info');
     $res = GWF_HTTP::getFromUrl('http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/' . $func, false, 'LAST_LANG=' . $language);
     if ($res === false) {
         return 'Timeout on contacting ' . ($language != 'en' ? $language . '.' : '') . 'php.net';
     }
     if (preg_match('/<span class=\\"refname\\">(.*?)<\\/span> &mdash; <span class=\\"dc\\-title\\">(.*?)<\\/span>/si', $res, $match)) {
         $match[2] = str_replace(array("\n", "\r"), ' ', strip_tags($match[2]));
         preg_match('/<div class=\\"methodsynopsis dc\\-description\\">(.*?)<\\/div>/si', $res, $descmatch);
         $decl = isset($descmatch[1]) ? strip_tags($descmatch[1]) : $match[1];
         $decl = html_entity_decode(str_replace(array("\n", "\r"), ' ', $decl));
         $decl = str_replace($func, "" . $func . "", $decl);
         $output = $decl . ' - ' . html_entity_decode($match[2]) . ' ( http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/' . $func . ' )';
     } else {
         // if several possibilities
         $output = '';
         if (preg_match_all('/<a href=\\"\\/manual\\/[a-z]+\\/(?:.*?)\\.php\\">(?:<b>)?(.*?)(?:<\\/b>)?<\\/a><br/i', $res, $matches, PREG_SET_ORDER)) {
             if ($redirects++ < 2) {
                 return fetchFunctionDescription($matches[0][1]);
             } else {
                 return $notfoundtext . ' http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/search.php?show=wholesite&pattern=' . $message;
             }
         } else {
             $output = $notfoundtext . ' http://' . ($language != 'en' ? $language . '.' : '') . 'php.net/search.php?show=wholesite&pattern=' . $func;
         }
     }
     return $output;
 }
Exemple #2
0
 public function pullTimer()
 {
     Dog_Log::debug('DOGMOD_CVS::pullTimer()');
     if ($this->pulling) {
     } elseif (false === ($repo = Dog_Repo::table('Dog_Repo')->selectFirstObject('*', "repo_id > {$this->pull_cycle_num}"))) {
         $this->pull_cycle_num = 0;
     } else {
         $this->pull_cycle_num = $repo->getID();
         $this->doPull($repo);
     }
 }
Exemple #3
0
 /**
  * Remove all items from array that are not a decision.
  * @param array $args
  * @return array
  */
 public static function filterDecisions(array &$args)
 {
     foreach ($args as $i => $arg) {
         if (!$arg instanceof SR_AIDecision) {
             Dog_Log::debug('filterDecisions argument is not a decision.');
             GWF_Debug::backtrace('filterDecisions argument is not a decision.', $args);
             unset($args[$i]);
         }
     }
     return $args;
 }
Exemple #4
0
 public static function decideCombat(SR_Player $player, array $args)
 {
     if (count($args) !== 3) {
         Dog_Log::debug(sprintf('Call to AI: if expects 3 args. %s given!', count($args)));
         return NULL;
     }
     if (self::evaluateExpression($args[0])) {
         return self::evaluateExpression($args[1]);
     } else {
         return self::evaluateExpression($args[2]);
     }
 }
Exemple #5
0
 public static function combatTimer(SR_Player $player)
 {
     $ai = $player->getVar('sr4pl_combat_ai');
     if ($ai === NULL) {
         if ($player->isHuman()) {
             return;
         } else {
             $ai = self::DEFAULT_COMBAT_AI;
         }
     }
     //		$data = array();
     //		$total = 0;
     $decisions = array();
     $ai = explode(';', $ai);
     foreach ($ai as $func) {
         $func = trim($func);
         if (preg_match('/([a-z_]+)(\\([^\\)]+\\))?([-+*\\/]\\d+)?/i', $func, $matches)) {
             $funcname = $matches[1];
             $classname = 'ShadowAI_' . $funcname;
             if (class_exists($classname)) {
                 $args = isset($matches[1]) ? explode(',', $matches[1]) : NULL;
                 $multi = isset($matches[2]) ? $matches[2] : '*1';
                 $decision = call_user_func(array($classname, 'decideCombat'), $player, $args);
                 if ($decision !== NULL) {
                     $command = $decision[0];
                     $prefer = $decision[1];
                     $prefer = eval("{$prefer}{$multi};");
                     //						$chance = (int)($prefer*100);
                     //						$total += $chance;
                     //						$data[] = array($command, $chance);
                     $decisions[$command] = $prefer;
                 }
             } else {
                 Dog_Log::debug(sprintf('%s has an invalid AI method: %s.', $player->getName(), $funcname));
             }
         } else {
             Dog_Log::debug(sprintf('PREG MATCH FAILED: %s.', $func));
         }
     }
     # Best
     if (count($decisions) > 0) {
         arsort($decisions);
         $command = key($decisions);
         $player->combatPush($command);
     }
     # Rand
     //		if (false !== ($command = Shadowfunc::randomData($data, $total)))
     //		{
     //			$player->combatPush($command);
     //		}
 }
Exemple #6
0
function dog_svn_info($key, $repo, $user = '', $pass = '', $displayurl = '', $channels = array())
{
    $keyshort = $key;
    $key = 'DOG_SVNINFO_REVISION_' . $key;
    $svninfo = new GWF_SvnInfo();
    $svninfo->setRepository($repo, $user, $pass);
    if (0 == ($currentRevision = $svninfo->getCurrentRevision())) {
        return Dog_Log::debug('Fetching current revision failed.');
    }
    $lastRevision = GWF_Settings::getSetting($key, $currentRevision);
    if ($currentRevision <= $lastRevision) {
        GWF_Settings::setSetting($key, $currentRevision);
        return;
    }
    $svnlog = $svninfo->getLog($lastRevision + 1, $currentRevision);
    foreach ($svnlog as $entry) {
        $msg = sprintf('[%s] New revision %s by %s: %s', $keyshort, $entry['version-name'], $entry['creator-displayname'], html_entity_decode($entry['comment']));
        if ($displayurl != '') {
            $msg .= ' ( ' . str_replace('%REV%', $entry['version-name'], $displayurl) . ' )';
        }
        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();
                    foreach ($channels as $c) {
                        if (!strcasecmp($c, $channel)) {
                            $server->sendPRIVMSG($channel, $msg);
                        }
                    }
                }
            }
        }
    }
    GWF_Settings::setSetting($key, $currentRevision);
}
Exemple #7
0
 public static function onInstall($dropTable = false)
 {
     Dog_Log::debug(__METHOD__);
     $dir = Shadowrun4::getShadowDir();
     foreach (self::$TABLES as $classname) {
         require_once $dir . 'core/' . $classname . '.php';
         if (false !== ($table = GDO::table($classname))) {
             // 				Dog_Log::debug('SR_Install::onInstall('.$classname.')');
             if (false === $table->createTable($dropTable)) {
                 return false;
             }
         }
     }
     return true;
 }
Exemple #8
0
 public static function decideCombat(SR_Player $player, array $args)
 {
     # NULL?
     if (count($args) === 0) {
         return NULL;
     }
     # ARG missing!
     if (count($args) === 1) {
         Dog_Log::debug(sprintf('Missing parameter for AI: mul.'));
         return $args[0];
     }
     # Is it a decision?
     $decision = $args[0];
     if (!$decision instanceof SR_AIDecision) {
         return $args[0] * $args[1];
     }
     # Multiply all the decisions!
     $decision instanceof SR_AIDecision;
     $decision->setPreference($decision->getPreference() * $args[1]);
     return $decision;
 }
Exemple #9
0
 public static function init()
 {
     Dog_Log::debug(__METHOD__);
     static $inited = false;
     if ($inited === false) {
         $inited = true;
         Shadowlang::onLoadLanguage();
         Shadowrap::init();
         self::$sr_timestamp = GWF_CachedCounter::getCount('SR4_TIME');
         $path = self::getShadowDir();
         self::initCore($path);
         self::initCmds($path);
         Shadowcmd::init();
         self::initItems($path);
         // 			self::initQuests($path);
         self::initCityBases($path);
         self::initSpells($path);
         self::initCityQuests($path);
         self::initCityNPCs($path);
         self::initCityLocations($path);
         // 			self::initCities($path);
         self::initCityAfter();
         SR_Player::init();
         // 			require_once DOG_PATH.'Lamb_IRCFrom.php';
         // 			require_once DOG_PATH.'Lamb_IRCTo.php';
         if (defined('SL4_REALS')) {
             self::initRealNPCs();
         }
         Shadowcleanup::cleanup();
     }
 }
Exemple #10
0
 private function looseItem(SR_Player $killer)
 {
     Dog_Log::debug(sprintf('%s could loose an item!', $this->getName()));
     $items = array_merge($this->sr4_equipment, $this->sr4_inventory);
     foreach ($items as $i => $item) {
         $item instanceof SR_Item;
         if ($item instanceof SR_Mount || !$item->isItemDropable()) {
             unset($items[$i]);
         }
     }
     if (0 !== ($rand = rand(0, count($items)))) {
         shuffle($items);
         $item = array_pop($items);
         $item instanceof SR_Item;
         if ($item->isEquipped($this)) {
             $this->unequip($item, false);
         }
         $this->removeFromInventory($item);
         $killer->giveItems(array($item), 'killing ' . $this->getName());
         $this->msg('5255', array($item->getAmount(), $item->getItemName()));
         // 			$this->message(sprintf('You lost your %s.', $item->getItemName()));
     }
 }
Exemple #11
0
 /**
  * NPC messages are queued to a player on remote commands.
  * @see SR_Player::message()
  */
 public function message($message)
 {
     Dog_Log::debug($message);
     $this->redirectRemoteMessage($message);
 }
Exemple #12
0
 public static function initTimersDirServer($entry, $fullpath, $null = NULL)
 {
     if (false !== ($server = Dog_Server::getByTLD($entry))) {
         if (false !== ($server = Dog::getServerByID($server->getID()))) {
             GWF_File::filewalker($fullpath, true, array(__CLASS__, 'initTimersDir'), false, $server);
         } else {
             Dog_Log::debug(sprintf("Server %d-%s for Timer in path \"%s\" is not Online.", $serverid, $entry, $fullpath));
         }
     } else {
         Dog_Log::debug(sprintf('Timer in path "%s" could not find it\'s server: %s.', $fullpath, $entry));
     }
 }
Exemple #13
0
 public static function mainloop()
 {
     Dog_Log::debug('Dog::mainloop() - start');
     while (!Dog_Launcher::shouldRestart()) {
         foreach (self::$SERVERS as $server) {
             $server instanceof Dog_Server;
             if ($server->isActive()) {
                 self::processServer($server);
             }
         }
         Dog_Timer::sleepAndTrigger();
         self::$WORKER->executeCallbacks();
     }
     Dog_Launcher::cleanup();
     Dog_Log::debug('Dog::mainloop() - exited');
 }
Exemple #14
0
 public function onHacked(SR_Player $player, $hits)
 {
     $message = sprintf('You have hacked the %s box with %s hits.', $this->getName(), $hits);
     Dog_Log::debug($message);
 }