示例#1
0
 public function event_join()
 {
     $user = Dog::getUser();
     $server = Dog::getServer();
     $channel = Dog::getChannel();
     $cid = $channel->getID();
     if (Dog::isItself() || Dog_Greeting::hasBeenGreeted($user->getID(), $cid) || false === ($greeting = Dog_GreetMsg::getGreetMsg($server, $channel)) || $greeting->isDisabled()) {
         return;
     }
     $message = $greeting->getVar('dgm_msg');
     switch ($greeting->getGreetMode()) {
         case Dog_GreetMsg::MODE_CHAN:
             $server->sendPRIVMSG($channel->getName(), $user->getName() . ': ' . $message);
             break;
         case Dog_GreetMsg::MODE_NOTICE:
             $server->sendNOTICE($user->getName(), $message);
             break;
         case Dog_GreetMsg::MODE_PRIVMSG:
             $server->sendPRIVMSG($user->getName(), $message);
             break;
         default:
             Dog_Log::error('Invalid type of greeting in ' . __FILE__ . ' line ' . __LINE__ . '!');
             return;
     }
     Dog_Greeting::markGreeted($user->getID(), $cid);
 }
示例#2
0
 /**
  * Beam a party to a target location.
  * @param SR_Player $player
  * @param string $target
  * @param string $action
  */
 public function beam(SR_Player $player, $target = 'Redmond_Hotel', $action = 'inside')
 {
     if (false === ($location = Shadowrun4::getLocationByTarget($target))) {
         $player->message('Unknown location to beam to, report to gizmore!');
         Dog_Log::error('Unknown $target "' . $target . '" for ' . __METHOD__ . ' in ' . __FILE__ . ' line ' . __LINE__ . '.');
         return false;
     }
     $party = $player->getParty();
     # City changed?
     $oldcity = $party->getCity();
     $party->pushAction($action, $target);
     $newcity = $party->getCity();
     if ($oldcity !== $newcity) {
         $city = $party->getCityClass();
         $city->onCityEnter($party);
     }
     // 		if ($action === 'inside')
     // 		{
     // 			foreach ($party->getMembers() as $member)
     // 			{
     // 				$member->message($location->getEnterText($member));
     // 			}
     // 		}
     $party->giveKnowledge('places', $target);
     return true;
 }
示例#3
0
 public function onInitServer(Dog_Server $server)
 {
     //		echo __METHOD__.PHP_EOL;
     if (false === ($dir = glob('dog_module/Warfare/ports/*.php'))) {
         Dog_Log::error('Warfare cannot read ports directory.');
         return false;
     }
     self::$PORTS = $dir;
 }
示例#4
0
 public static function validate()
 {
     $servers = Dog::getServers();
     if (count($servers) === 0) {
         return Dog_Log::error('No server available!');
     }
     foreach ($servers as $server) {
         $server instanceof Dog_Server;
         if ($server->isWebsocket()) {
         } elseif (false === Dog_Nick::getNickFor($server)) {
             return Dog_Log::error(sprintf('Server %s has no nickname setup!', $server->displayName()));
         }
     }
     return true;
 }
示例#5
0
 public static function updateScumStats(Dog_ScumGame $game)
 {
     $server = $game->getServer();
     $won = 1;
     $score = $game->getPlayerCountStart();
     foreach ($game->getWinners() as $name) {
         $score--;
         if (false === ($user = $server->getUserByName($name))) {
             Dog_Log::error('Can not find user ' . $name);
             continue;
         }
         $userid = $user->getID();
         if (false === ($row = self::getOrCreateStatsRow($userid))) {
             Dog_Log::error('Can not find stats for user ' . $name);
             continue;
         }
         $row->updateRow("scums_games=scums_games+1, scums_won=scums_won+{$won}, scums_score=scums_score+{$score}");
         $won = 0;
     }
 }
示例#6
0
 public function connect(Dog_Server $server, $blocking = 0)
 {
     $this->server = $server;
     if (false === ($this->context = @stream_context_create())) {
         return Dog_Log::error('Dog_IRC::connect() ERROR: stream_context_create()');
     }
     $url = $server->getURL();
     if (false === ($socket = @stream_socket_client($url, $errno, $errstr, $server->getTimeout(), STREAM_CLIENT_CONNECT, $this->context))) {
         Dog_Log::error("Dog_IRC::connect() ERROR: stream_socket_client(): URL={$url} CONNECT_TIMEOUT=" . $server->getTimeout());
         return Dog_Log::error(sprintf('Dog_IRC::connect() $errno=%d; $errstr=%s', $errno, $errstr));
     }
     if ($server->isSSL()) {
         if (false === @stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             return Dog_Log::error('Dog_IRC::connect() ERROR: stream_socket_enable_crypto(true, STREAM_CRYPTO_METHOD_TLS_CLIENT)');
         }
     }
     if (false === @stream_set_blocking($socket, 0)) {
         return Dog_Log::error('Dog_IRC::connect() ERROR: stream_set_blocking(): $blocked=0');
     }
     $this->timestamp = time();
     $this->socket = $socket;
     return true;
 }
示例#7
0
 public function giveKnowledge($field, $knowledge, $announce = true)
 {
     static $txt = array('places' => 'location', 'words' => 'word');
     $b = chr(2);
     $args = func_get_args();
     $field = array_shift($args);
     if (!isset($txt[$field])) {
         Dog_Log::error("WARNING: Unknown knowledge type: {$field}");
         return false;
     }
     foreach ($args as $knowledge) {
         if ($this->hasKnowledge($field, $knowledge)) {
             continue;
         }
         $k = $this->getKnowledge($field);
         if (false === $this->saveVar('sr4pl_known_' . $field, $k . $knowledge . ',')) {
             return false;
         }
         // 			if ($field === 'places')
         // 			{
         // 				$this->setOption(self::LOCATION_DIRTY, true);
         // 			}
         // 			elseif ($field === 'words')
         // 			{
         // 				$this->setOption(self::WORDS_DIRTY, true);
         // 			}
         if ($announce) {
             $this->msg('5250', array($this->lang('ks_' . $field), $knowledge, $field));
             // 				$this->message(sprintf('You know a new %s: %s.', $txt[$field], $b.$knowledge.$b));
         }
     }
     return true;
 }
示例#8
0
文件: QUIT.php 项目: sinfocol/gwf3
<?php

# :krashed__!~dig@mx.renome.ua QUIT :Excess Flood
if (false !== ($user = Dog::setupUser())) {
    Dog::getServer()->removeUser($user);
} else {
    Dog_Log::error('Cannot get use from quit');
    Dog_Log::error(Dog::getMessage());
}
示例#9
0
 private function getDescription($url)
 {
     # Get page content
     # TODO: Only download .txt and .html content!
     GWF_HTTP::setTimeout(10);
     GWF_HTTP::setConnectTimeout(3);
     $content = GWF_HTTP::getFromURL($url, true);
     GWF_HTTP::setTimeout();
     GWF_HTTP::setConnectTimeout();
     if ($content === false) {
         Dog_Log::error('Mod_Link::getDescription(): getFromURL() failed. URL: ' . $url);
         return false;
     }
     list($head, $content) = preg_split("/[\r\n]{4}/", $content, 2);
     $type = Common::regex('/Content-Type: *(.*)/Di', $head);
     echo $type . PHP_EOL;
     if (Common::startsWith($type, 'image')) {
         return array('image', $content);
     }
     # Get Title from html
     if (0 === preg_match('#< *title *>([^<]+)< */ *title *>#i', $content, $matches)) {
         return false;
     }
     $title = $this->decode($matches[1]);
     $descr = '';
     if (1 === preg_match('#(< *meta.*description[^>]*>)#i', $content, $matchesB)) {
         $tag = $matchesB[1];
         if (1 === preg_match('#content=["\']([^"\']+)["\']#', $tag, $matchesB)) {
             $descr = ' - ' . $this->decode($matchesB[1]);
         }
     }
     return array('html', $title . ' - ' . $descr);
 }
示例#10
0
 private function onLearn(SR_Player $player, $field, $price)
 {
     $have = false;
     $type = 'skill';
     if (false !== ($spell = SR_Spell::getSpell($field))) {
         $type = 'spell';
         if ($spell->getBaseLevel($player) > -1) {
             $have = true;
         }
     } elseif ($player->getBase($field) > -1) {
         $have = true;
     }
     if ($type !== 'spell') {
         if ($player->getBase($field) < -1) {
             $player->msg('1145', array($field));
             // 				$player->message(sprintf('Your character cannot learn %s.', $field));
             return false;
         }
     }
     if ($have === true) {
         $player->msg('1146', array($field));
         // 			$player->message(sprintf('You already learned the %s %s.', $type, $field));
         return false;
     }
     if ($type === 'spell') {
         if (false !== ($error = $spell->checkRequirements($player))) {
             $player->msg('1147', array($error));
             // 				$player->message(sprintf('You need %s to learn this spell.', $error));
             return false;
         }
     }
     $dp = Shadowfunc::displayNuyen($price);
     if (false === $player->pay($price)) {
         $player->msg('1063', array($dp, $player->displayNuyen()));
         // 			$player->message(sprintf('It cost %s to learn the %s %s, but you only have %s.', $dp, $type, $field, $player->displayNuyen()));
         return false;
     }
     if ($type === 'spell') {
         $player->levelupSpell($field, 1);
     } elseif ($type === 'skill') {
         $player->levelupFieldTo($field, 0);
     } else {
         $player->message('Database error!');
         return Dog_Log::error(sprintf('Learned field "%s" is neither a skill nor a spell!', $field));
     }
     // 		$player->modify();
     $player->msg('5184', array($dp, $field));
     // 		$player->message(sprintf('You pay %s and learned the %s %s.', $dp, $type, $field));
     return true;
 }
示例#11
0
 /**
  * Magic method. All unknown commands are handled as talk commands.
  * @param string $name
  * @param array $args
  */
 public function __call($name, $args)
 {
     if ($args !== NULL) {
         $player = array_shift($args);
         $args = array_shift($args);
         $npcs = $this->getNPCS($player);
         $word = count($args) > 0 ? array_shift($args) : '';
         if (isset($npcs[$name])) {
             if (false !== ($npc = Shadowrun4::getNPC($npcs[$name]))) {
                 return $npc->onNPCTalkA($player, $word, $args);
             }
         }
     }
     Dog_Log::error("ERROR: Unknown function '{$name}'.");
     return false;
 }
示例#12
0
 /**
  * Spawn a copy of this NPC.
  * @return SR_NPC
  */
 public function spawn(SR_Party $party, SR_Party $attackers = NULL)
 {
     if (false === ($npc = self::createNPC($this->getNPCClassName(), $party, $attackers))) {
         Dog_Log::error(sprintf('SR_NPC::spawn() failed for NPC class: %s.', $this->getNPCClassName()));
         return false;
     }
     foreach ($this->getNPCEquipment() as $field => $itemname) {
         if (is_array($itemname)) {
             $itemname = Shadowfunc::randomListItem($itemname);
         }
         if (!in_array($field, SR_Player::$EQUIPMENT, true)) {
             Dog_Log::error(sprintf('NPC %s has invalid equipment type: %s.', $this->getNPCPlayerName(), $field));
             $npc->deletePlayer();
             return false;
         }
         if (false === ($item = SR_Item::createByName($itemname))) {
             Dog_Log::error(sprintf('NPC %s has invalid %s: %s.', $this->getNPCPlayerName(), $field, $itemname));
             $npc->deletePlayer();
             return false;
         }
         $item->changeOwnerAndPosition($npc->getID(), $field);
         $npc->setEquipment($field, $item);
     }
     foreach ($this->getNPCCyberware() as $itemname) {
         $npc->addCyberware(SR_Item::createByName($itemname));
     }
     foreach ($this->getNPCMountInventory() as $itemname) {
         $npc->putInMountInv(SR_Item::createByName($itemname));
     }
     $inv = array();
     foreach ($this->getNPCInventory() as $itemname) {
         if (false === ($item = SR_Item::createByName($itemname))) {
             Dog_Log::error(sprintf('NPC %s has invalid inventory item: %s.', $this->getNPCPlayerName(), $itemname));
             $npc->deletePlayer();
             return false;
         }
         $inv[] = $item;
     }
     $npc->giveItems($inv);
     $npc->saveSpellData($this->getNPCSpells());
     $npc->modify();
     $npc->healHP(10000);
     $npc->healMP(10000);
     return $npc;
 }
示例#13
0
 public function on_delete($done)
 {
     foreach ($this->getMembers() as $member) {
         if ($member->isHuman()) {
             $this->pushAction('outside', 'Redmond', 0);
             $this->pushAction('outside', 'Redmond', 0);
             Dog_Log::error(sprintf('ERROR: Human party %d got action delete!', $this->getID()));
             return;
         }
     }
     $this->deleteParty();
 }
示例#14
0
文件: Dog.php 项目: sinfocol/gwf3
 public static function err($key, $args = NULL)
 {
     $message = GWF_HTML::lang($key, $args);
     Dog_Log::error($message);
     self::reply($message);
 }
示例#15
0
 /**
  * Get an NPC by name.
  * @param string $name
  * @return SR_NPC
  */
 public static function getNPC($name)
 {
     if (false === ($cityname = Common::substrUntil($name, '_', false))) {
         return Dog_Log::error(sprintf('Shadowrun4::getNPC(%s) failed no cityname.', $name));
     }
     if (false === ($city = self::getCity($cityname))) {
         return Dog_Log::error(sprintf('Shadowrun4::getNPC(%s) failed no city.', $name));
     }
     if (false === ($npc = $city->getNPC($name))) {
         return Dog_Log::error(sprintf('Shadowrun4::getNPC(%s) failed no such NPC.', $name));
     }
     return $npc;
 }
示例#16
0
 public function checkRequirements(SR_Player $player)
 {
     $back = '';
     foreach ($this->getRequirements() as $require => $level) {
         if (false !== ($spell = self::getSpell($require))) {
             if ($spell->getBaseLevel($player) < $level) {
                 $back .= sprintf(', %s level %s', $require, $level);
             }
         } elseif (in_array($require, SR_Player::$ATTRIBUTE)) {
             if ($player->getBase($require) < $level) {
                 $back .= sprintf(', %s level %s', $require, $level);
             }
         } elseif (in_array($require, SR_Player::$SKILL)) {
             if ($player->getBase($require) < $level) {
                 $back .= sprintf(', %s level %s', $require, $level);
             }
         } else {
             Dog_Log::error(sprintf('Unknown requirement for Spell "%s": %s.', $this->getName(), $require));
         }
     }
     return $back === '' ? false : substr($back, 2);
 }
示例#17
0
文件: SR_Item.php 项目: sinfocol/gwf3
 /**
  * Use the amount of an item. Delete item when empty.
  * @param SR_Player $player
  * @param int $amount
  * @return true|false
  */
 public function useAmount(SR_Player $player, $amount = 1, $modify = true)
 {
     if ($amount > $this->getAmount()) {
         Dog_Log::error(sprintf('Item %s(%d) has not %d amount to use!', $this->getItemName(), $this->getID(), $amount));
         return false;
     }
     if (false === $this->increase('sr4it_amount', -$amount)) {
         Dog_Log::error(sprintf('Item %s(%d) can not decrease amount %d!', $this->getItemName(), $this->getID(), $amount));
         return false;
     }
     if ($modify) {
         $player->modify();
     }
     return $this->getAmount() < 1 ? $this->deleteItem($player) : true;
 }
示例#18
0
文件: ERROR.php 项目: sinfocol/gwf3
<?php

Dog_Log::error(Dog::getIRCMsg()->getArg(0));
示例#19
0
 private function insertChannelItem(Dog_Server $server, $xml)
 {
     $news = GDO::table('Dog_News');
     $fid = $this->feed->getID();
     $url = (string) $xml->link;
     $title = (string) $xml->title;
     $descr = (string) $xml->description;
     if (false === ($item = Dog_News::getByTitle($fid, $title)) && false === ($item = Dog_News::getByURL($this->feed->getID(), (string) $xml->title))) {
         // New News
         $item = new Dog_News(array('ln_id' => 0, 'ln_fid' => $fid, 'ln_date' => GWF_Time::getDate(GWF_Date::LEN_SECOND), 'ln_title' => $title, 'ln_url' => $url, 'ln_descr' => $descr, 'ln_options' => 0));
         if (false === $item->insert()) {
             Dog_Log::error('Database error in Mod_News::insertChannelItem()');
         } else {
             $this->queue[] = $item;
         }
     } elseif ($this->origin === $server->getBotsNickname() || !$item->isDisplayed()) {
         $this->queue[] = $item;
     }
     return true;
 }