public function start() { self::setStatus(self::STATUS_START); // Load the ini configuration file self::loadIni(); // Load the core files foreach (glob(self::$basedir . "core/*.core.php") as $file) { self::setStatus(self::STATUS_FILE_LOADING, array("core/" . basename($file))); if (!(require_once $file)) { self::setStatus(self::STATUS_FILE_LOAD_FAIL); self::stop(); } $name = basename($file, ".core.php"); $className = ucfirst($name); ${$name} = new $className(); self::setStatus(self::STATUS_FILE_LOADED); } // Load included classes foreach (glob(self::$basedir . "core/*.class.php") as $file) { self::setStatus(self::STATUS_FILE_LOADING, array("class/" . basename($file))); if (!(require_once $file)) { self::setStatus(self::STATUS_FILE_LOAD_FAIL); self::stop(); } self::setStatus(self::STATUS_FILE_LOADED); } self::setStatus(self::STATUS_DATABASE_CONNECTING); try { $dnsString = self::$conf['database']['type'] . ":host=" . self::$conf['database']['host'] . ";dbname=" . self::$conf['database']['schema'] . ";charset=utf8"; self::$db = new PDO($dnsString, self::$conf['database']['user'], self::$conf['database']['password']); self::setStatus(self::STATUS_DATABASE_CONNECTED); } catch (PDOException $e) { self::setStatus(self::STATUS_DATABASE_CONNECTION_FAILED, array("\n" . $e->getMessage())); } self::updateStartingLocations(); self::setStatus(self::STATUS_RUNNING, array(self::$conf['server']['ip'], self::$conf['server']['port'])); while (self::STATUS_FATAL != self::$status && self::STATUS_STOP != self::$status) { Sockets::monitor(); Sockets::runEvents(); } }
/** * Process request for module functionality that is not part of the core * @param $strCommand * @param $resUserSocket * @param $arrData */ public static function process($strCommand, $resUserSocket, $arrData) { if (array_key_exists(self::$arrApps, $strCommand)) { $intUserID = Sockets::getData($resUserSocket, 'user_id'); //Set the current class to be accessible from the object self::$arrApps[$strCommand]->processRequest($arrData, $intUserID); } else { //System not found System::sendErrorResponse($resUserSocket, $arrData, "Invalid requested 'system' parameter"); } }
/** * Disconnect account from server * * Reasons: * 0 - Incorrect namae/password. * 1 - Someone is already using this account. * 2 - Your account has been blocked. * 3 - Your account credentials are invalid. * 4 - Communication problem. [DEFAULT] * 5 - The IGR concurrency limit has been met. * 6 - The IGR time limit has been met. * 7 - General IGR authentication failure. */ public function disconnect($reason = 4) { $packet = chr(130) . chr(hexdec($reason)); UltimaPHP::log("Client " . UltimaPHP::$socketClients[$this->client]['ip'] . " disconnected from the server"); Sockets::out($this->client, $packet, false, true, true); }
public function updateCurrentStamina($runInLot = false) { $packet = "A3" . str_pad($this->serial, 8, "0", STR_PAD_LEFT) . str_pad(dechex($this->maxstam), 2, "0", STR_PAD_LEFT) . str_pad(dechex($this->stam), 2, "0", STR_PAD_LEFT); Sockets::out($this->client, $packet, $runInLot); }
/** * Send to the client the features from server */ public static function packet_0x91($data, $client, $redirected = false) { $command = $data[0]; $keyUsed = hexdec($data[1]) . hexdec($data[2]) . hexdec($data[3]) . hexdec($data[4]); $account = Functions::hexToChr($data, 5, 34, true); $password = Functions::hexToChr($data, 35, 64, true); $login = false; UltimaPHP::$socketClients[$client]['account'] = new Account($account, md5($password), $client); if (true === UltimaPHP::$socketClients[$client]['account']->isValid) { UltimaPHP::log("Account {$account} logged from " . UltimaPHP::$socketClients[$client]['ip']); // Set the flag on the connection to send next packets compressed UltimaPHP::$socketClients[$client]['compressed'] = true; Sockets::addEvent($client, array("option" => "account", "method" => "enableLockedFeatures"), 0.0, true); Sockets::addEvent($client, array("option" => "account", "method" => "sendCharacterList"), 0.0, true, true); } else { UltimaPHP::$socketClients[$client]['account']->disconnect(3); } }
/** * Use the Sockets transport implmentation to send logged data to KISSmetrics. * * Loads the contents of the log file and then sends it to KISSmetrics for * processing. If successful deletes the log file afterwards so that we do * not send duplicate events. * * @throws TransportException */ public function sendLoggedData() { // Load all stored queries. $data = file_get_contents($this->getLogFile()); $data = explode('\\n', $data); // Unserialize all the queries into a single array. $all_queries = array(); foreach ($data as $serialized_queries) { $queries = unserialize($serialized_queries); $all_queries += $queries; } try { // Send all the stored queries using the KISSmetrics/Transport/Sockets // implementation. parent::submitData($all_queries); // Cleanup the log file so we don't resend the same data again. unlink($this->getLogFile()); } catch (Exception $e) { throw new TransportException("Cannot send logged events to KISSmetrics: " . $e->getMessage()); } }
/** * Disconnect procedure for the payloads that have failed to be encoded/decoded successfully * @param resource $resSocket Socket resource the is to be disconnected * @param string $strMessage Message to be send to the socket upon disconnection */ protected static function dataError($resSocket, $strMessage) { //Remove the socket from the list of connected sockets if (Sockets::isTemporary($resSocket)) { Sockets::removeTemporary($resSocket); } else { Sockets::remove($resSocket); } //Close connection on unknown opcode System::log('Disconnected from server: ' . $strMessage); }
public function finalPacket($runInLot = false) { $packet = "254006D58B0EED00E6780029007A01400765090000"; Sockets::out($this->client, $packet, $runInLot); }
public function testDefaults() { $km_api = Sockets::initDefault(); $this->assertEquals('trk.kissmetrics.com', $km_api->getHost()); $this->assertEquals(80, $km_api->getPort()); }
/** * Send out the error responses message to the current resource * @param $resUserSocket * @param $arrData * @param $strMessage */ public static function sendErrorResponse($resUserSocket, $arrData, $strMessage) { $arrResponse = array('instance' => array_key_exists('instance', $arrData) ? $arrData['instance'] : null, 'system' => 'twist', 'action' => 'error', 'message' => $strMessage, 'data' => array()); Sockets::writeJSON($resUserSocket, $arrResponse); }
/** * Update players with objects from desired chunk */ public static function updateChunk($chunk) { $chunk = self::$chunks[$chunk['x']][$chunk['y']]; /* Update items on map */ foreach ($chunk['objects'] as $object) { $packet = "F3"; $packet .= "0001"; $packet .= "00"; $packet .= $object->serial; $packet .= str_pad(dechex($object->graphic), 4, "0", STR_PAD_LEFT); $packet .= "00"; $packet .= str_pad(dechex($object->amount), 4, "0", STR_PAD_LEFT); $packet .= str_pad(dechex($object->amount), 4, "0", STR_PAD_LEFT); $packet .= str_pad(dechex($object->pos_x), 4, "0", STR_PAD_LEFT); $packet .= str_pad(dechex($object->pos_y), 4, "0", STR_PAD_LEFT); $packet .= str_pad("00", 2, "0", STR_PAD_LEFT); $packet .= str_pad(dechex($object->layer), 2, "0", STR_PAD_LEFT); $packet .= str_pad(dechex($object->color), 4, "0", STR_PAD_LEFT); $packet .= "20"; $packet .= "0000"; $updateRange = array('from' => array('x' => $object->pos_x - 10, 'y' => $object->pos_y - 10), 'to' => array('x' => $object->pos_x + 10, 'y' => $object->pos_y + 10)); foreach ($chunk['players'] as $client => $alive) { $player = UltimaPHP::$socketClients[$client]['account']->player; if ($player->position['x'] >= $updateRange['from']['x'] && $player->position['x'] <= $updateRange['to']['x'] && $player->position['y'] >= $updateRange['from']['y'] && $player->position['y'] <= $updateRange['to']['y']) { Sockets::out($player->client, $packet, false); } } } }