/** * Get the power id by his name. * * @param string $name The name of the power. * * @return int|false */ public static function getPowerIdByName($name = null) { if (is_null($name)) { return false; } return array_search(Inflector::camelize($name), static::$_groupPower); }
/** * Handle the response from the socket. * * @param bool|string $response The response from the socket. * * @return void */ protected function _handleResponse($response) { if ($response != false) { $length = strlen($response); while ($response[$length - 1] != '>' && $response[$length - 1] != chr(0)) { $response .= $this->Socket->read(); $length = strlen($response); } $packets = []; preg_match_all("/<([\\w]+)[^>]*>/", $response, $packets, PREG_SET_ORDER); foreach ($packets as $packet) { $packet[0] = Xml::toArray(Xml::build(Xml::repair($packet[0]))); debug($packet); $this->PacketManager->{'on' . Inflector::camelize($packet[1])}($packet[0]); } } }
/** * Check if we have loaded a certain module. * * @param string $module The module to check. * * @return bool */ public function offsetExists($module) { $module = Inflector::camelize($module); return isset($this->_loadedModules[$module]); }
/** * Handle the chat command. * * @param \Mars\Network\Server $server The server instance. * @param \Mars\Message\Message $message The message instance. * * @return bool|void */ protected function _handleChat(Server $server, $message) { switch ($message->arguments[0]) { case 'info': if (!isset($message->arguments[1])) { $phrase = $this->_getChatInfo($server->Room->roomInfos); $server->ModuleManager->message($phrase); break; } $powerId = Power::getPowerIdByName($message->arguments[1]); if ($powerId === false || !isset($server->Room->groupPowers['g' . $powerId])) { $server->ModuleManager->message('This power is not assigned in the room.'); break; } $phrase = Power::getPowerInfo($powerId, $server->Room->groupPowers['g' . $powerId]); if ($phrase === false) { $server->ModuleManager->message('Unable to get the information for the power ' . Inflector::camelize($message->arguments[1]) . '.'); break; } $server->ModuleManager->message($phrase); break; default: $server->ModuleManager->message('Unknown command. Syntax: ' . $this->_commands[$message->command]['syntax']); } }
/** * Check if we have loaded a certain packet. * * @param string $packet The packet to check. * * @return bool */ public function offsetExists($packet) { $packet = Inflector::camelize($packet); return isset($this->_loadedPackets[$packet]); }