Esempio n. 1
0
<?php

/**
 * Ultima PHP - OpenSource Ultima Online Server written in PHP
 * Version: 0.1 - Pre Alpha
 */
set_time_limit(0);
ini_set('memory_limit', '2048M');
ini_set('default_charset', 'UTF-8');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'core/server.php';
$server = new UltimaPHP(dirname(__FILE__));
$server->start();
Esempio n. 2
0
 /**
  * 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);
 }
Esempio n. 3
0
 public static function setStatus($status, $args = array())
 {
     switch ($status) {
         case self::STATUS_START:
             $message = "Starting server";
             $type = self::LOG_NORMAL;
             break;
         case self::STATUS_STOP:
             $message = "Stoping server";
             $type = self::LOG_NORMAL;
             break;
         case self::STATUS_FATAL:
             $message = "Server crashed suddenly";
             $type = self::LOG_DANGER;
             $shutdown = true;
             break;
         case self::STATUS_FILE_LOADING:
             $message = "Loading file: " . $args[0];
             $type = self::LOG_NORMAL;
             break;
         case self::STATUS_FILE_LOAD_FAIL:
             $message = "Loading file failed";
             $type = self::LOG_DANGER;
             break;
         case self::STATUS_FILE_LOADED:
             $message = null;
             $type = self::LOG_NORMAL;
             break;
         case self::STATUS_DATABASE_CONNECTING:
             $message = "Trying to connect to the database";
             $type = SELF::LOG_NORMAL;
             break;
         case self::STATUS_DATABASE_CONNECTED:
             $message = "Database connected successfully";
             $type = SELF::LOG_NORMAL;
             break;
         case self::STATUS_DATABASE_CONNECTION_FAILED:
             $message = "Server could not connect to the database with error: " . $args[0];
             $type = SELF::LOG_DANGER;
             $shutdown = true;
             break;
         case self::STATUS_UNKNOWN:
             $message = "Unknown status set";
             $type = self::LOG_WARNING;
             break;
         case self::STATUS_LISTENING:
             $message = "Server is listening on " . $args[0] . " at port " . $args[1];
             $type = self::LOG_NORMAL;
             break;
         case self::STATUS_RUNNING:
             $message = "Server is running on " . $args[0] . " at port " . $args[1];
             $type = self::LOG_NORMAL;
             break;
         default:
             $message = "Wrong status set. restoring last status.";
             $type = self::LOG_DANGER;
             $status = self::$status;
             break;
     }
     self::$status = $status;
     self::log($message, $type);
     if (isset($shutdown)) {
         self::stop();
     }
 }
Esempio n. 4
0
 /**
  * Receive the selected server from client
  */
 public static function packet_0xA0($data, $client)
 {
     $server = dechex($data[1] . $data[2]);
     UltimaPHP::$socketClients[$client]['connected_server'] = (int) $server - 1;
     UltimaPHP::log("Account " . UltimaPHP::$socketClients[$client]['account']->account . " connecting on server " . UltimaPHP::$servers[UltimaPHP::$socketClients[$client]['connected_server']]['name']);
     UltimaPHP::$socketClients[$client]['account']->sendConnectionConfirmation();
 }
Esempio n. 5
0
 public function __construct()
 {
     $actualMap = 0;
     /**
      * Render the maps inside chunk arrays
      */
     while (isset(UltimaPHP::$conf["muls"]["map{$actualMap}"])) {
         $mapFile = UltimaPHP::$conf['muls']['location'] . "map{$actualMap}.mul";
         $mapSize = explode(",", UltimaPHP::$conf["muls"]["map{$actualMap}"]);
         UltimaPHP::setStatus(UltimaPHP::STATUS_FILE_LOADING, array($mapFile));
         if (!is_file($mapFile)) {
             UltimaPHP::setStatus(UltimaPHP::STATUS_FILE_LOAD_FAIL);
             UltimaPHP::stop();
         }
         $chunks_x = ceil($mapSize[0] / self::$chunkSize);
         $chunks_y = ceil($mapSize[1] / self::$chunkSize);
         // Build the array that will store map chunks
         for ($xChunk = 0; $xChunk < $chunks_x; $xChunk++) {
             self::$chunks[$xChunk] = array();
             for ($yChunk = 0; $yChunk < $chunks_y; $yChunk++) {
                 self::$chunks[$xChunk][$yChunk] = array('objects' => array(), 'players' => array(), 'npcs' => array());
             }
         }
         // Store information about the map muls and size
         self::$maps[$actualMap] = array('mul' => null, 'size' => array('x' => null, 'y' => null));
         self::$mapSizes[$actualMap]['x'] = $mapSize[0];
         self::$mapSizes[$actualMap]['y'] = $mapSize[1];
         self::$maps[$actualMap]['mul'] = fopen($mapFile, "rb");
         self::$maps[$actualMap]['size']['x'] = (int) $mapSize[0] >> 3;
         self::$maps[$actualMap]['size']['y'] = (int) $mapSize[1] >> 3;
         for ($x = 0; $x < self::$maps[$actualMap]['size']['x']; ++$x) {
             self::$maps[$actualMap][$x] = array();
             for ($y = 0; $y < self::$maps[$actualMap]['size']['y']; ++$y) {
                 self::$maps[$actualMap][$x][$y] = array();
                 fseek(self::$maps[$actualMap]['mul'], ($x * self::$maps[$actualMap]['size']['y'] + $y) * 196, SEEK_SET);
                 $header = hexdec(bin2hex(fread(self::$maps[$actualMap]['mul'], 4)));
                 for ($i = 0; $i < 64; ++$i) {
                     $tile = bin2hex(fread(self::$maps[$actualMap]['mul'], 2));
                     $z = hexdec(bin2hex(fread(self::$maps[$actualMap]['mul'], 1)));
                     if (hexdec($tile) < 0 || $tile >= 0x4000) {
                         $tile = 0;
                     }
                     if ($z < -128) {
                         $z = -128;
                     }
                     if ($z > 127) {
                         $z = 127;
                     }
                     if ($tile > 0) {
                         echo "{$tile}|{$x},{$y},{$z},{$actualMap}\n";
                         // self::$maps[$actualMap][$x][$y][$z] = $tile;
                     }
                 }
             }
         }
         /* Send the server proccess and map the statics from actual map */
         // self::readStaticsFromPosition(0, 1429, 1695);
         // self::readStatics($actualMap);
         UltimaPHP::setStatus(UltimaPHP::STATUS_FILE_LOADED);
         $actualMap++;
     }
     $chunks_x = ceil($mapSize[0] / self::$chunkSize);
     $chunks_y = ceil($mapSize[1] / self::$chunkSize);
     // Build the array that will store map chunks
     for ($x = 0; $x < $chunks_x; $x++) {
         self::$chunks[$x] = array();
         for ($y = 0; $y < $chunks_y; $y++) {
             self::$chunks[$x][$y] = array('objects' => array(), 'players' => array(), 'npcs' => array());
         }
     }
 }
Esempio n. 6
0
 /**
  * Register an $event to run in $client after $time seconds.
  *
  */
 public static function addEvent($client, $event, $time, $runInLot = false, $dispatchLot = false)
 {
     $mt = microtime(true);
     if (!is_array($event)) {
         UltimaPHP::log("Unknow event was send to the server.", UltimaPHP::LOG_WARNING);
         return false;
     } else {
         UltimaPHP::$socketEvents[$mt][] = array('event' => $event, 'client' => $client, 'time' => $mt + $time, 'lot' => array($runInLot, $dispatchLot));
         return true;
     }
 }