public static function execute(SR_Player $player, array $args) { $bot = Shadowrap::instance($player); if (count($args) !== 2) { $bot->reply(Shadowhelp::getHelp($player, 'gmloot')); return false; } $target = Shadowrun4::getPlayerByShortName($args[0]); if ($target === -1) { $player->message('The username is ambigious.'); return false; } if ($target === false) { $player->message('The player is not in memory or unknown.'); return false; } if (false === $target->isCreated()) { $bot->reply(sprintf('The player %s has not started a game yet.', $args[0])); return false; } if (Common::isNumeric($args[1])) { $target->giveItems(Shadowfunc::randLoot($target, $args[1]), 'gmloot'); } else { } return true; }
/** * Called like * #quests SmithHammer * #quests Lovers * #quests open 1 * #quests open * #quests done 1 * @param SR_Player $player * @param array $args */ public static function execute(SR_Player $player, array $args) { if (count($args) === 0) { $args = array('open'); } $quests = SR_Quest::getAllQuests($player); switch ($args[0]) { case 'miss': case 'missing': return self::displayMissing($player, $quests, $args); case 'open': case 'deny': case 'done': case 'fail': case 'abort': return self::displaySection($player, $quests, $args[0], $args); case 'stats': case 's': return self::displayStats($player, $quests); case 'citystats': case 'cstats': case 'cs': return self::displayCityStats($player); default: if (Common::isNumeric($args[0])) { return self::onDisplayQuestByNum($player, $quests, $args); } return self::onSearchQuests($player, $quests, $args); } }
public static function execute(SR_Player $player, array $args) { if (count($args) === 0) { $args = array(1); } if (count($args) === 1 && Common::isNumeric($args[0])) { return self::displaySets($player, (int) $args[0]); } elseif (count($args) === 1) { return self::displaySet($player, $args[0]); } }
public static function generate(array $extensions_data) { $extensions = array(); foreach ($extensions_data as $extension_name => $data) { if (Common::isNumeric($extension_name)) { $extension_name = $data; $data = null; } $extensions[] = self::createExtension($extension_name, $data); } usort($extensions, array(__CLASS__, 'sort_priority_asc')); return $extensions; }
function merge_use_mapping(GDO_Database $db_from, GDO_Database $db_to, $classname, $colname, array $map, $numerical = true) { GDO::setCurrentDB($db_from); $table = GDO::table($classname); foreach ($map as $from => $to) { if (Common::isNumeric($from)) { if (false === $table->update("`{$colname}` = 0x40000000|{$to}", "`{$colname}` = {$from}")) { return false; } } } return $table->update("`{$colname}` = `{$colname}` - 0x40000000", "`{$colname}` >= 0x40000000"); }
private function onDisplay($message = '') { if ($message === '') { return $this->displayQuote(Dog_Quote::getRandomID()); } if (Common::isNumeric($message)) { return $this->displayQuote(intval($message)); } $ids = Dog_Quote::searchQuotes($message); if (count($ids) === 0) { return sprintf('No quote found with search term "%s"', $message); } if (count($ids) === 1) { return $this->displayQuote($ids[0]); } return sprintf('Matching IDs: %s.', implode(', ', $ids)); }
public function getRecipe(SR_Player $player, $arg) { $recipes = $this->getRecipesB($player); if (Common::isNumeric($arg)) { if ($arg > 0 && $arg <= count($recipes)) { return $recipes[$arg - 1]; } } else { $arg = strtolower($arg); foreach ($recipes as $recipe) { if (strcasecmp($recipe[0], $arg) === 0) { return $recipe; } } } return false; }
private function getFieldData(SR_Player $player, $arg) { $fields = $this->getFields($player); if (Common::isNumeric($arg)) { if ($arg < 1 || $arg > count($fields)) { return false; } $back = array_slice($fields, $arg - 1, 1); return $back[0]; } foreach ($fields as $data) { if ($arg === $data[0]) { return $data; } } return false; }
public static function execute(SR_Player $player, array $args) { $bot = Shadowrap::instance($player); if (count($args) < 2 || count($args) > 3) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } if (false === ($spell = SR_Spell::getSpell($args[1]))) { $bot->reply("The spell {$args[1]} is unknown."); return false; } $server = $player->getUser()->getServer(); if (false === ($user = Dog::getUserByArg($args[0]))) { $bot->reply(sprintf('The user %s is unknown.', $args[0])); return false; } if (false === ($target = Shadowrun4::getPlayerByUID($user->getID()))) { $bot->reply(sprintf('The player %s is unknown.', $user->getName())); return false; } if (false === $target->isCreated()) { $bot->reply(sprintf('The player %s has not started a game yet.', $args[0])); return false; } $by = 1; if (count($args) === 3) { if (!Common::isNumeric($args[2])) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } if (false === ($base = $player->getSpellBaseLevel($args[1]))) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } $by = $args[2] - $base; } $target->levelupSpell($spell->getName(), $by); $target->modify(); $base = $target->getSpellBaseLevel($args[1]); return $bot->reply(sprintf('The target got changed spells!')); }
public static function execute(SR_Player $player, array $args) { $bot = Shadowrap::instance($player); # Own info if (count($args) === 0) { return self::showClanInfo($player, $player); } # 1 Numeric == clan history. if (count($args) === 1 && Common::isNumeric($args[0])) { if ($args[0] < 1) { $bot->reply(Shadowhelp::getHelp($player, 'clan')); return false; } return self::showHistoryPage($player, (int) $args[0]); } # !members shows your clan members. if (count($args) === 1 || count($args) === 2) { if ($args[0] === '!m' || $args[0] === '!members') { $page = isset($args[1]) ? (int) $args[1] : 1; return self::showMembers($player, $page); } } # Show another player. if (count($args) !== 1) { $bot->reply(Shadowhelp::getHelp($player, 'clan')); return false; } if (false === ($target = Shadowrun4::getPlayerByShortName($args[0]))) { self::rply($player, '1017'); // $bot->reply('This player is unknown or not in memory.'); return false; } else { if ($target === -1) { self::rply($player, '1018'); // $bot->reply('This playername is ambigous.'); return false; } } return self::showClanInfo($player, $target); }
/** * Convert a human duration to seconds. * Input may be like 3d5h8i 7s. * Also possible is 1 month 3 days or 1year2sec. * Note that 'i' is used for minutes and 'm' for months. * No unit means default unit, which is seconds. * Supported units are: * s, sec, second, seconds, * i, min, minute, minutes, * h, hour, hours, * d, day, days, * w, week, weeks, * m, month, months, * y, year, years. * @param $duration string is the duration in human format. * @return int duration as seconds * */ public static function humanToSeconds($duration) { if (is_int($duration)) { return $duration; } if (!is_string($duration)) { return 0; } if (Common::isNumeric($duration)) { return (int) $duration; } $duration = trim(strtolower($duration)); if (!preg_match('/^(?:(?:[0-9 ]+[sihdwmy])+)$/', $duration)) { return 0; } $multis = array('s' => 1, 'i' => 60, 'h' => 3600, 'd' => 86400, 'w' => 604800, 'm' => 2592000, 'y' => 31536000); $replace = array('seconds' => 's', 'second' => 's', 'sec' => 's', 'minutes' => 'i', 'minute' => 'i', 'min' => 'i', 'hours' => 'h', 'hour' => 'h', 'days' => 'd', 'day' => 'd', 'weeks' => 'w', 'week' => 'w', 'months' => 'm', 'month' => 'm', 'mon' => 'm', 'years' => 'y', 'year' => 'y'); $negative = 1; $duration = strtolower(trim($duration)); if ($duration[0] == '-') { $negative = -1; } $duration = trim($duration, '-'); $duration = str_replace(array_keys($replace), array_values($replace), $duration); // $duration = preg_replace('/[^sihdwmy0-9]/', '', $duration); $duration = preg_replace('/([sihdwmy])/', '$1 ', $duration); $duration = explode(' ', trim($duration)); $back = 0; foreach ($duration as $d) { $unit = substr($d, -1); if (is_numeric($unit)) { $unit = 's'; } else { $d = substr($d, 0, -1); } $d = intval($d); $back += $multis[$unit] * $d; } return $negative * $back; }
<?php $lang = array('en' => array('help' => 'Usage: %CMD% [<cocktail>] [<nickname>]. Virtually get someone a c**k or list them.', 'c**k' => 'hands %s a nice %s.', 'list' => 'Available cocktails: %s.')); $cocktails = array('Woo Woo', 'Piña Colada', 'Blue Lagoon', 'Sex on the Beach', 'Caipirinha', 'Tequila Sunrise', 'Cosmopolitan'); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); $argc = count($argv); $showlist = false; if ($argc === 0) { $showlist = true; } elseif ($argc <= 2) { if (Common::isNumeric($argv[0])) { $target = isset($argv[1]) ? $argv[1] : Dog::getUser()->getName(); $coknum = (int) $argv[0] - 1; if (isset($cocktails[$coknum])) { $plugin->rplyAction('c**k', array($target, $cocktails[$coknum])); } else { $showlist = true; } } else { $plugin->showHelp(); } } else { $plugin->showHelp(); } if ($showlist) { $i = 1; $out = ''; foreach ($cocktails as $c**k) { $out .= ', ' . $i++ . '-' . $c**k; }
private function onAddWTB(SR_Player $player, array $args) { $have = $this->getWTBSlots($player); $used = SR_BazarWTB::getItemcountForPlayer($player); if ($used >= $have) { return Dog::reply($player->lang('1191')); } $price = round($args[1]); if ($price < self::MIN_PRICE) { return Dog::reply($player->lang('1109', array(self::MIN_PRICE))); } if ($price > 10000000) { return Dog::reply($player->lang('1110')); } $amt = $args[2]; if (!Common::isNumeric($amt) || $amt < 1) { return Dog::reply($player->lang('1038')); } if (false === ($item = SR_Item::createByName($args[0], $amt, false))) { return Dog::reply($player->lang('1192')); } if ($item->isItemStatted()) { return Dog::reply($player->lang('1193')); } if (false === SR_BazarWTB::insertEntry($player, $item, $price)) { return Dog::reply('Database Error 1b'); } }
<?php $lang = array('en' => array('help' => 'Usage: %CMD% <integer>. Predict the next sequential integer polled from rand(). $100 won by noother!', 'good' => 'Well done!', 'wrong' => 'You predicted %s but the outcome was %s.')); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); if (count($argv) !== 1 || !Common::isNumeric($argv[0])) { return $plugin->showHelp(); } $predicted = (int) $argv[0]; $rand = rand(0, getrandmax()); if ($rand === $predicted) { $plugin->rply('good'); } else { $plugin->rply('wrong', array($predicted, $rand)); }
public static function isValid($type, $value) { switch ($type) { case 'b': return $value === '0' || $value === '1'; case 'i': return Common::isNumeric($value, false); case 'f': return Common::isNumeric($value, true); case 's': case 'v': return true; default: return false; } }
/** * Get an item from an array. * @param string $itemname * @param array $items * @param boolean $shortcuts * @param boolean $verbose * @return SR_Item */ public function getItemByNameB($itemname, array $items, $shortcuts = true, $verbose = true) { # ID match if (Common::isNumeric($itemname)) { if ($itemname > 0 && $itemname <= count($items)) { $back = array_slice($items, $itemname - 1, 1); return $back[0]; } } $itemname = strtolower($itemname); # Full name match foreach (array_reverse($items) as $item) { $item instanceof SR_Item; if (!strcasecmp($item->displayFullName($this, false, false), $itemname) || !strcasecmp($item->getItemName(), $itemname)) { return $item; } } # Full base name match foreach (array_reverse($items) as $item) { $item instanceof SR_Item; if (!strcasecmp($item->getName(), $itemname)) { return $item; } } # Try shortcuts return strlen($itemname) > 2 && $shortcuts === true ? $this->getItemByShortNameB($itemname, $items, $verbose) : false; }
public function on_sell(SR_Player $player, array $args) { $bot = Shadowrap::instance($player); $argc = count($args); if ($argc < 1 || $argc > 2) { $bot->reply(Shadowhelp::getHelp($player, 'sell')); return false; } // Multisell if (preg_match('/^\\d*-\\d*$/', $args[0]) && $argc === 1) { return $this->on_sellall($player, $args); } # Item $itemname = array_shift($args); if (false === ($item = $player->getInvItem($itemname))) { $bot->rply('1029'); // $bot->reply('You don\'t have that item.'); return false; } $itemname = $item->getItemName(); if (!$item->isItemSellable()) { $bot->rply('1151', array($item->getItemName())); // $bot->reply(sprintf('I don\'t want your %s.', $item->getItemName())); return false; } # Price $price = $item->getItemPrice(); # / $item->getItemDefaultAmount(); $total = 0.0; # Amount $amt = isset($args[0]) ? array_shift($args) : 1; if (!Common::isNumeric($amt)) { $bot->rply('1040', array($item->getItemName())); return false; } if ($amt < 1) { $bot->rply('1038', array($item->getItemName())); return false; } # A stackable? if ($item->isItemStackable()) { $have_amt = $item->getAmount(); # Split item if ($amt > $have_amt) { $bot->rply('1040', array($item->getItemName())); // $bot->reply(sprintf('You have not that much %s.', $item->getItemName())); return false; } if (!$item->useAmount($player, $amt)) { $bot->reply('Database Error R2 D2.'); return false; } } else { $items2 = $player->getInvItems($item->getItemName(), $amt); if (count($items2) < $amt) { $bot->rply('1040', array($item->getItemName())); // $bot->reply(sprintf('You have not that much %s.', $item->getItemName())); return false; } $stored = 0; foreach ($items2 as $item2) { $item2 instanceof SR_Item; if (!$item2->useAmount($player, 1)) { $bot->reply('Database Error R3 D3.'); return false; } } } $total = $this->calcSellPrice($player, $item, $amt); $player->giveNuyen($total); return $bot->rply('5191', array($amt, $item->displayFullName($player), Shadowfunc::displayNuyen($total), Shadowfunc::displayWeight($player->get('weight')), Shadowfunc::displayWeight($player->get('max_weight')))); // $bot->reply(sprintf('You sold %d of your %s for %s. You now carry %s/%s.', // $amt, $item->getItemName(), Shadowfunc::displayNuyen($total), // Shadowfunc::displayWeight($player->get('weight')), Shadowfunc::displayWeight($player->get('max_weight')) // )); // return true; }
public function validate_percent(Module_WeChall $module, $arg) { if (!Common::isNumeric($arg, true) || $arg < 0 || $arg > 100) { return $module->lang('err_percent'); } return false; }
public function fetchEntries($gwf_date, $limit) { if (false === ($content = $this->sendRequest($gwf_date, $limit))) { return false; } $entries = array(); $lines = explode("\n", $content); foreach ($lines as $line) { if ('' === ($line = trim($line))) { continue; } $thedata = explode('::', $line); if (count($thedata) !== 6) { echo 'Invalid line in dog_wc_forum: ' . $line . PHP_EOL; return false; } $thedata = array_map(array(__CLASS__, 'unescape_csv_like'), $thedata); # Fetch line list($threadid, $lastdate, $boardid, $url, $username, $title) = $thedata; if ($lastdate < $gwf_date) { continue; } if (!Common::isNumeric($threadid)) { echo 'Invalid threadid in dog_wc_forum: ' . $line . PHP_EOL; return false; } if (!GWF_Time::isValidDate($lastdate, false, 14)) { echo 'Invalid date in dog_wc_forum: ' . $line . PHP_EOL; return false; } if (!Common::isNumeric($boardid)) { echo 'Invalid boardid in dog_wc_forum: ' . $line . PHP_EOL; return false; } $entries[] = new Dog_ForumEntry($thedata); } if (count($entries) > 0) { $deleting = 1; foreach ($entries as $id => $entry) { $entry instanceof Dog_ForumEntry; if ($entry->getLastDate() === $this->getDate()) { if ($deleting) { if ($entry->getThreadID() === $this->getLast()) { $deleting = 0; } unset($entries[$id]); } } } } return array_values($entries); }
/** * Get a location in current city. * @param SR_Player $player * @param int|string $arg */ public static function getTLCByArgMulticity(SR_Player $player, $arg) { if (Common::isNumeric($arg)) { return self::getTLCByID($player, $arg); } if (strpos($arg, '_') === false) { return self::getTLCByName($player, $arg); } else { return self::getTLCByNameMulticity($player, $arg); } }
<?php $lang = array('en' => array('help' => 'Usage: %CMD% <URL|SID>. Join a server. URL format is ircs://irc.gizmore.org:6697.', 'err_url' => 'The URL is invalid.', 'connect' => 'Trying to connect.')); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); $argc = count($argv); if ($argc !== 1) { return $plugin->showHelp(); } if (Common::isNumeric($argv[0]) && false !== ($server = Dog::getServerByID($argv[0]))) { $prot = $server->isSSL() ? 'ircs' : 'irc'; $port = $server->getPort(); } else { $url = parse_url($argv[0]); if (!isset($url['host'])) { return $plugin->rply('err_url'); } $host = $url['host']; $prot = isset($url['scheme']) ? strtolower($url['scheme']) : 'irc'; if ($prot !== 'irc' && $prot !== 'ircs') { return $plugin->rply('err_url'); } $default_port = $prot === 'ircs' ? 6697 : 6667; $port = isset($url['port']) ? intval($url['port']) : $default_port; $options = Dog_Server::DEFAULT_OPTIONS; $options |= $prot === 'ircs' ? Dog_Server::SSL : 0; } if (false !== ($server = Dog::getServerByArg($argv[0])) || false !== ($server = Dog::getServerByArg($host))) { $plugin->reply('reconnecting'); $server->saveOption(Dog_Server::ACTIVE, true); $server->saveOption(Dog_Server::SSL, $prot === 'ircs');
private static function getGenericView(SR_Player $player, array $items, array $args, $is_store, $text, $raw = true) { $bot = Shadowrap::instance($player); if (count($args) > 2) { return self::arrayGet($text, 'usage', Shadowhelp::getHelp($player, 'view')); // $bot->reply(self::arrayGet($text, 'usage', Shadowhelp::getHelp($player, 'viewi'))); // return false; } $items = Shadowfunc::getItemsIndexed($items, $is_store, $raw); # Setup pattern and args if (count($args) === 2) { $pattern = $args[0]; $page = (int) $args[1]; } elseif (count($args) === 1) { if (Common::isNumeric($args[0])) { $pattern = NULL; $page = (int) $args[0]; } else { $pattern = $args[0]; $page = 1; } } else { $pattern = NULL; $page = 1; } # Filter on pattern if ($pattern !== NULL) { $items = Shadowfunc::filterIndexedBySubstring($args[0], $items); } # Display page if (count($items) === 0) { if ($pattern !== NULL) { return self::arrayGet($text, 'empty_search', Shadowrun4::lang('1007')); // $bot->reply(self::arrayGet($text, 'empty_search', Shadowrun4::lang('1007'))); } else { return self::arrayGet($text, 'empty', Shadowrun4::lang('1008')); // $bot->reply(self::arrayGet($text, 'empty', Shadowrun4::lang('1008'))); } // return true; } if (false === ($pageStr = Shadowfunc::getItemPage($page, $items, $is_store))) { return self::arrayGet($text, 'no_page', Shadowrun4::lang('1009')); // $bot->reply(self::arrayGet($text, 'no_page', Shadowrun4::lang('1009'))); // return false; } $code = self::arrayGet($text, 'code', '5276'); return $player->lang($code, array(sprintf('%s%s', self::arrayGet($text, 'prefix', Shadowrun4::lang('items')), $pageStr))); // return sprintf('%s, %s', self::arrayGet($text, 'prefix', Shadowrun4::lang('items')), $pageStr); }
public function on_surgery(SR_Player $player, array $args) { if (count($args) === 0) { return $this->displaySurgeryPrices($player); } if (count($args) !== 1) { return $this->displaySurgeryHelp($player); } # Section overview $section = $args[0]; if (true === Common::isNumeric($section)) { if (false === ($section = $this->getSectionFromNumber($section))) { return $this->displaySurgeryHelp($player); } } if (true === in_array($section, self::$SECTIONS)) { return $this->displaySurgeryPrices($player, $section); } # Suregery downgrade return $this->onSurgeryB($player, $section); }
public function on_view(SR_Player $player, array $args) { if (false === ($clan = SR_Clan::getByPlayer($player))) { $player->msg('1019'); // $player->message("You don't have a clan, chummer!"); return false; } if (count($args) === 0) { $player->message(Shadowhelp::getHelp($player, 'clan_view')); return false; } if (count($args) === 1 && Common::isNumeric($args[0])) { return $this->onViewPage($clan, $player, (int) $args[0]); } elseif (count($args) <= 2) { $page = isset($args[1]) ? (int) $args[1] : 1; return $this->onViewItems($clan, $player, $args[0], $page); } else { $player->message(Shadowhelp::getHelp($player, 'clan_view')); return false; } }
/** * Get a server by ID or name abbreviation. * @return Dog_Server */ public static function getServerByArg($arg) { return Common::isNumeric($arg) ? self::getServerByID($arg) : self::getServerByShortName($arg); }