mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-19 20:13:27 +02:00
Merge branch 'develop' into feature/settings
This commit is contained in:
@@ -12,27 +12,44 @@
|
||||
class CreateCharacter
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $sex
|
||||
* @param int $vocation
|
||||
* @param int $town
|
||||
* @param array $errors
|
||||
* @param $name
|
||||
* @param $errors
|
||||
* @return bool
|
||||
*/
|
||||
public function check($name, $sex, &$vocation, &$town, &$errors) {
|
||||
public function checkName($name, &$errors)
|
||||
{
|
||||
$minLength = config('character_name_min_length');
|
||||
$maxLength = config('character_name_max_length');
|
||||
|
||||
if(empty($name))
|
||||
if(empty($name)) {
|
||||
$errors['name'] = 'Please enter a name for your character!';
|
||||
else if(strlen($name) > $maxLength)
|
||||
$errors['name'] = 'Name is too long. Max. length <b>'.$maxLength.'</b> letters.';
|
||||
else if(strlen($name) < $minLength)
|
||||
$errors['name'] = 'Name is too short. Min. length <b>'.$minLength.'</b> letters.';
|
||||
else {
|
||||
if(!admin() && !Validator::newCharacterName($name)) {
|
||||
$errors['name'] = Validator::getLastError();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($name) > $maxLength) {
|
||||
$errors['name'] = 'Name is too long. Max. length <b>' . $maxLength . '</b> letters.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($name) < $minLength) {
|
||||
$errors['name'] = 'Name is too short. Min. length <b>' . $minLength . '</b> letters.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$name_length = strlen($name);
|
||||
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '") != $name_length) {
|
||||
$errors['name'] = 'This name contains invalid letters, words or format. Please use only a-Z, - , \' and space.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!preg_match("/[A-z ']/", $name)) {
|
||||
$errors['name'] = 'Your name contains illegal characters.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!admin() && !Validator::newCharacterName($name)) {
|
||||
$errors['name'] = Validator::getLastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
$player = new OTS_Player();
|
||||
@@ -42,20 +59,38 @@ class CreateCharacter
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($sex) && $sex != "0")
|
||||
return empty($errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $sex
|
||||
* @param int $vocation
|
||||
* @param int $town
|
||||
* @param array $errors
|
||||
* @return bool
|
||||
*/
|
||||
public function check($name, $sex, &$vocation, &$town, &$errors)
|
||||
{
|
||||
$this->checkName($name, $errors);
|
||||
|
||||
if(empty($sex) && $sex != "0") {
|
||||
$errors['sex'] = 'Please select the sex for your character!';
|
||||
}
|
||||
|
||||
if(count(config('character_samples')) > 1)
|
||||
{
|
||||
if(!isset($vocation))
|
||||
$errors['vocation'] = 'Please select a vocation for your character.';
|
||||
}
|
||||
else
|
||||
else {
|
||||
$vocation = config('character_samples')[0];
|
||||
}
|
||||
|
||||
if(count(config('character_towns')) > 1) {
|
||||
if(!isset($town))
|
||||
if(!isset($town)) {
|
||||
$errors['town'] = 'Please select a town for your character.';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$town = config('character_towns')[0];
|
||||
@@ -158,8 +193,14 @@ class CreateCharacter
|
||||
$player->setManaSpent($char_to_copy->getManaSpent());
|
||||
$player->setSoul($char_to_copy->getSoul());
|
||||
|
||||
for($skill = POT::SKILL_FIRST; $skill <= POT::SKILL_LAST; $skill++)
|
||||
$player->setSkill($skill, 10);
|
||||
for($skill = POT::SKILL_FIRST; $skill <= POT::SKILL_LAST; $skill++) {
|
||||
$value = 10;
|
||||
if (config('use_character_sample_skills')) {
|
||||
$value = $char_to_copy->getSkill($skill);
|
||||
}
|
||||
|
||||
$player->setSkill($skill, $value);
|
||||
}
|
||||
|
||||
$player->setLookBody($char_to_copy->getLookBody());
|
||||
$player->setLookFeet($char_to_copy->getLookFeet());
|
||||
@@ -199,16 +240,22 @@ class CreateCharacter
|
||||
|
||||
if($db->hasTable('player_skills')) {
|
||||
for($i=0; $i<7; $i++) {
|
||||
$value = 10;
|
||||
if (config('use_character_sample_skills')) {
|
||||
$value = $char_to_copy->getSkill($i);
|
||||
}
|
||||
$skillExists = $db->query('SELECT `skillid` FROM `player_skills` WHERE `player_id` = ' . $player->getId() . ' AND `skillid` = ' . $i);
|
||||
if($skillExists->rowCount() <= 0) {
|
||||
$db->query('INSERT INTO `player_skills` (`player_id`, `skillid`, `value`, `count`) VALUES ('.$player->getId().', '.$i.', 10, 0)');
|
||||
$db->query('INSERT INTO `player_skills` (`player_id`, `skillid`, `value`, `count`) VALUES ('.$player->getId().', '.$i.', ' . $value . ', 0)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$loaded_items_to_copy = $db->query("SELECT * FROM player_items WHERE player_id = ".$char_to_copy->getId()."");
|
||||
foreach($loaded_items_to_copy as $save_item)
|
||||
$db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', '".$save_item['attributes']."');");
|
||||
foreach($loaded_items_to_copy as $save_item) {
|
||||
$blob = $db->quote($save_item['attributes']);
|
||||
$db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', $blob);");
|
||||
}
|
||||
|
||||
global $twig;
|
||||
$twig->display('success.html.twig', array(
|
||||
|
@@ -11,7 +11,7 @@
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$configForumTablePrefix = config('forum_table_prefix');
|
||||
if(!empty(trim($configForumTablePrefix))) {
|
||||
if(null !== $configForumTablePrefix && !empty(trim($configForumTablePrefix))) {
|
||||
if(!in_array($configForumTablePrefix, array('myaac_', 'z_'))) {
|
||||
throw new RuntimeException('Invalid value for forum_table_prefix in config.php. Can be only: "myaac_" or "z_".');
|
||||
}
|
||||
@@ -322,4 +322,4 @@ class Forum
|
||||
return $hasAccess;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@@ -8,12 +8,12 @@ class News
|
||||
$errors[] = 'Please fill all inputs.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($title) > TITLE_LIMIT) {
|
||||
$errors[] = 'News title cannot be longer than ' . TITLE_LIMIT . ' characters.';
|
||||
if(strlen($title) > NEWS_TITLE_LIMIT) {
|
||||
$errors[] = 'News title cannot be longer than ' . NEWS_TITLE_LIMIT . ' characters.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($body) > BODY_LIMIT) {
|
||||
$errors[] = 'News content cannot be longer than ' . BODY_LIMIT . ' characters.';
|
||||
if(strlen($body) > NEWS_BODY_LIMIT) {
|
||||
$errors[] = 'News content cannot be longer than ' . NEWS_BODY_LIMIT . ' characters.';
|
||||
return false;
|
||||
}
|
||||
if(strlen($article_text) > ARTICLE_TEXT_LIMIT) {
|
||||
@@ -138,4 +138,4 @@ class News
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -71,12 +71,117 @@ class Plugins {
|
||||
}
|
||||
}
|
||||
|
||||
public static function getRoutes()
|
||||
{
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$tmp = '';
|
||||
if ($cache->fetch('plugins_routes', $tmp)) {
|
||||
return unserialize($tmp);
|
||||
}
|
||||
}
|
||||
|
||||
$routes = [];
|
||||
foreach(get_plugins() as $filename) {
|
||||
$string = file_get_contents(PLUGINS . $filename . '.json');
|
||||
$string = self::removeComments($string);
|
||||
$plugin = json_decode($string, true);
|
||||
self::$plugin_json = $plugin;
|
||||
if ($plugin == null) {
|
||||
self::$warnings[] = 'Cannot load ' . $filename . '.json. File might be not a valid json code.';
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($plugin['enabled']) && !getBoolean($plugin['enabled'])) {
|
||||
self::$warnings[] = 'Skipping ' . $filename . '... The plugin is disabled.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$warningPreTitle = 'Plugin: ' . $filename . ' - ';
|
||||
|
||||
if (isset($plugin['routes'])) {
|
||||
foreach ($plugin['routes'] as $_name => $info) {
|
||||
// default method: get
|
||||
$method = $info['method'] ?? ['GET'];
|
||||
if ($method !== '*') {
|
||||
$methods = is_string($method) ? explode(',', $info['method']) : $method;
|
||||
foreach ($methods as $method) {
|
||||
if (!in_array($method, ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'])) {
|
||||
self::$warnings[] = $warningPreTitle . 'Not allowed method ' . $method . '... Disabling this route...';
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$methods = '*'; // all available methods
|
||||
}
|
||||
|
||||
if (!isset($info['priority'])) {
|
||||
$info['priority'] = 100; // default priority
|
||||
}
|
||||
|
||||
if (isset($info['redirect_from'])) {
|
||||
removeIfFirstSlash($info['redirect_from']);
|
||||
|
||||
$info['pattern'] = $info['redirect_from'];
|
||||
if (!isset($info['redirect_to'])) {
|
||||
self::$warnings[] = $warningPreTitle . 'redirect set without "redirect_to".';
|
||||
}
|
||||
else {
|
||||
removeIfFirstSlash($info['redirect_to']);
|
||||
$info['file'] = '__redirect__/' . $info['redirect_to'];
|
||||
}
|
||||
}
|
||||
|
||||
// replace first occurence of / in pattern if found (will be auto-added later)
|
||||
removeIfFirstSlash($info['pattern']);
|
||||
|
||||
foreach ($routes as $id => &$route) {
|
||||
if($route[1] == $info['pattern']) {
|
||||
if($info['priority'] < $route[3]) {
|
||||
self::$warnings[] = $warningPreTitle . "Duplicated route with lower priority: {$info['pattern']}. Disabling this route...";
|
||||
continue 2;
|
||||
}
|
||||
else {
|
||||
self::$warnings[] = $warningPreTitle . "Duplicated route with lower priority: {$route[1]} ({$route[3]}). Disabling this route...";
|
||||
unset($routes[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$routes[] = [$methods, $info['pattern'], $info['file'], $info['priority']];
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
usort($routes, function ($a, $b)
|
||||
{
|
||||
// key 3 is priority
|
||||
if ($a[3] == $b[3]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a[3] > $b[3]) ? -1 : 1;
|
||||
});
|
||||
*/
|
||||
// cleanup before passing back
|
||||
// priority is not needed anymore
|
||||
foreach ($routes as &$route) {
|
||||
unset($route[3]);
|
||||
}
|
||||
|
||||
if ($cache->enabled()) {
|
||||
$cache->set('plugins_routes', serialize($routes), 600);
|
||||
}
|
||||
|
||||
return $routes;
|
||||
}
|
||||
|
||||
public static function getHooks()
|
||||
{
|
||||
$cache = Cache::getInstance();
|
||||
if ($cache->enabled()) {
|
||||
$tmp = '';
|
||||
if ($cache->fetch('hooks', $tmp)) {
|
||||
if ($cache->fetch('plugins_hooks', $tmp)) {
|
||||
return unserialize($tmp);
|
||||
}
|
||||
}
|
||||
@@ -96,7 +201,7 @@ class Plugins {
|
||||
}
|
||||
|
||||
if ($cache->enabled()) {
|
||||
$cache->set('hooks', serialize($hooks), 600);
|
||||
$cache->set('plugins_hooks', serialize($hooks), 600);
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
@@ -259,27 +364,59 @@ class Plugins {
|
||||
}
|
||||
|
||||
if(in_array($req, array('php-ext', 'php-extension'))) { // require php extension
|
||||
if(!extension_loaded($version)) {
|
||||
self::$error = "This plugin requires php extension: " . $version . " to be installed.";
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
|
||||
foreach ($explode as $item) {
|
||||
if(!extension_loaded($item)) {
|
||||
$errors[] = "This plugin requires php extension: " . $item . " to be installed.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($req == 'table') {
|
||||
if(!$db->hasTable($version)) {
|
||||
self::$error = "This plugin requires table: " . $version . " to exist in the database.";
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
foreach ($explode as $item) {
|
||||
if(!$db->hasTable($item)) {
|
||||
$errors[] = "This plugin requires table: " . $item . " to exist in the database.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if($req == 'column') {
|
||||
$tmp = explode('.', $version);
|
||||
if(count($tmp) == 2) {
|
||||
if(!$db->hasColumn($tmp[0], $tmp[1])) {
|
||||
self::$error = "This plugin requires database column: " . $tmp[0] . "." . $tmp[1] . " to exist in database.";
|
||||
$continue = false;
|
||||
break;
|
||||
$tmpDisplayError = false;
|
||||
$explode = explode(',', $version);
|
||||
foreach ($explode as $item) {
|
||||
$tmp = explode('.', $item);
|
||||
|
||||
if(count($tmp) == 2) {
|
||||
if(!$db->hasColumn($tmp[0], $tmp[1])) {
|
||||
$errors[] = "This plugin requires database column: " . $tmp[0] . "." . $tmp[1] . " to exist in database.";
|
||||
$tmpDisplayError = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
self::$warnings[] = "Invalid plugin require column: " . $item;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpDisplayError) {
|
||||
self::$error = implode('<br/>', $errors);
|
||||
$continue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(strpos($req, 'ext-') !== false) {
|
||||
@@ -412,6 +549,10 @@ class Plugins {
|
||||
return self::$warnings;
|
||||
}
|
||||
|
||||
public static function clearWarnings() {
|
||||
self::$warnings = [];
|
||||
}
|
||||
|
||||
public static function getError() {
|
||||
return self::$error;
|
||||
}
|
||||
|
@@ -101,6 +101,37 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $email
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createWithEmail($email = null)
|
||||
{
|
||||
// if name is not passed then it will be generated randomly
|
||||
if( !isset($email) )
|
||||
{
|
||||
throw new Exception(__CLASS__ . ':' . __METHOD__ . ' createWithEmail called without e-mail.');
|
||||
}
|
||||
|
||||
// repeats until name is unique
|
||||
do
|
||||
{
|
||||
$name = uniqid();
|
||||
|
||||
$query = $this->db->query('SELECT `id` FROM `accounts` WHERE `name` = ' . $this->db->quote($name));
|
||||
} while($query->rowCount() >= 1);
|
||||
|
||||
// saves blank account info
|
||||
$this->db->exec('INSERT INTO `accounts` (`name`, `password`, `email`, `created`) VALUES (' . $this->db->quote($name) . ', ' . '\'\', ' . $this->db->quote($email) . ', ' . time() . ')');
|
||||
|
||||
// reads created account's ID
|
||||
$this->data['id'] = $this->db->lastInsertId();
|
||||
$this->data['name'] = $name;
|
||||
|
||||
// return name of newly created account
|
||||
return $name;
|
||||
}
|
||||
/**
|
||||
* Creates new account.
|
||||
*
|
||||
@@ -138,11 +169,32 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
*/
|
||||
public function create($name = NULL, $id = NULL)
|
||||
{
|
||||
// saves blank account info
|
||||
$this->db->exec('INSERT INTO `accounts` (' . (isset($id) ? '`id`,' : '') . (isset($name) ? '`name`,' : '') . '`password`, `email`, `created`) VALUES (' . (isset($id) ? $id . ',' : '') . (isset($name) ? $this->db->quote($name) . ',' : '') . ' \'\', \'\',' . time() . ')');
|
||||
if(isset($name)) {
|
||||
$nameOrNumber = 'name';
|
||||
$nameOrNumberValue = $name;
|
||||
}
|
||||
else {
|
||||
if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumber = 'number';
|
||||
$nameOrNumberValue = $id;
|
||||
$id = null;
|
||||
}
|
||||
else {
|
||||
$nameOrNumber = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($name))
|
||||
// saves blank account info
|
||||
$this->db->exec('INSERT INTO `accounts` (' . (isset($id) ? '`id`,' : '') . (isset($nameOrNumber) ? '`' . $nameOrNumber . '`,' : '') . '`password`, `email`, `created`) VALUES (' . (isset($id) ? $id . ',' : '') . (isset($nameOrNumber) ? $this->db->quote($nameOrNumberValue) . ',' : '') . ' \'\', \'\',' . time() . ')');
|
||||
|
||||
if(isset($name)) {
|
||||
$this->data['name'] = $name;
|
||||
}
|
||||
else {
|
||||
if (USE_ACCOUNT_NUMBER) {
|
||||
$this->data['number'] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
$lastInsertId = $this->db->lastInsertId();
|
||||
if($lastInsertId != 0) {
|
||||
@@ -179,15 +231,26 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @param int $id Account number.
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function load($id, $fresh = false)
|
||||
public function load($id, $fresh = false, $searchOnlyById = false)
|
||||
{
|
||||
if(!$fresh && isset(self::$cache[$id])) {
|
||||
$this->data = self::$cache[$id];
|
||||
return;
|
||||
}
|
||||
|
||||
$numberColumn = 'id';
|
||||
$nameOrNumber = '';
|
||||
if (!$searchOnlyById) {
|
||||
if (USE_ACCOUNT_NAME) {
|
||||
$nameOrNumber = '`name`,';
|
||||
} else if (USE_ACCOUNT_NUMBER) {
|
||||
$nameOrNumber = '`number`,';
|
||||
$numberColumn = 'number';
|
||||
}
|
||||
}
|
||||
|
||||
// SELECT query on database
|
||||
$this->data = $this->db->query('SELECT `id`, ' . ($this->db->hasColumn('accounts', 'name') ? '`name`,' : '') . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `id` = ' . (int) $id)->fetch();
|
||||
$this->data = $this->db->query('SELECT `id`, ' . $nameOrNumber . '`password`, `email`, `blocked`, `rlname`, `location`, `country`, `web_flags`, ' . ($this->db->hasColumn('accounts', 'premdays') ? '`premdays`, ' : '') . ($this->db->hasColumn('accounts', 'lastday') ? '`lastday`, ' : ($this->db->hasColumn('accounts', 'premend') ? '`premend`,' : ($this->db->hasColumn('accounts', 'premium_ends_at') ? '`premium_ends_at`,' : ''))) . '`created` FROM `accounts` WHERE `' . $numberColumn . '` = ' . (int) $id)->fetch();
|
||||
self::$cache[$id] = $this->data;
|
||||
}
|
||||
|
||||
@@ -306,6 +369,15 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
return $this->data['id'];
|
||||
}
|
||||
|
||||
public function getNumber()
|
||||
{
|
||||
if (isset($this->data['number'])) {
|
||||
return $this->data['number'];
|
||||
}
|
||||
|
||||
return $this->data['id'];
|
||||
}
|
||||
|
||||
public function getRLName()
|
||||
{
|
||||
if( !isset($this->data['rlname']) )
|
||||
@@ -1019,6 +1091,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return Iterator List of players.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getPlayersList();
|
||||
@@ -1033,7 +1106,7 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return int Count of players.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->getPlayersList()->count();
|
||||
}
|
||||
|
@@ -83,34 +83,47 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB
|
||||
$startTime = microtime(true);
|
||||
}
|
||||
|
||||
$ret = parent::query(...$args);;
|
||||
$ret = parent::query(...$args);
|
||||
if($this->logged) {
|
||||
$totalTime = microtime(true) - $startTime;
|
||||
$this->log .= round($totalTime, 4) . ' ms - ' . $query . PHP_EOL;
|
||||
$this->log .= round($totalTime, 4) . ' ms - ' . $args[0] . PHP_EOL;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function select($table, $where, $limit = null)
|
||||
public function select($table, $where = [], $limit = null)
|
||||
{
|
||||
$fields = array_keys($where);
|
||||
$values = array_values($where);
|
||||
$query = 'SELECT * FROM ' . $this->tableName($table) . ' WHERE (';
|
||||
$query = 'SELECT * FROM ' . $this->tableName($table);
|
||||
|
||||
$count = count($fields);
|
||||
for ($i = 0; $i < $count; $i++)
|
||||
$query.= $this->fieldName($fields[$i]).' = '.$this->quote($values[$i]).' AND ';
|
||||
if (!empty($where)) {
|
||||
$query .= ' WHERE (';
|
||||
|
||||
$count = count($fields);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$query .= $this->fieldName($fields[$i]) . ' = ' . $this->quote($values[$i]) . ' AND ';
|
||||
}
|
||||
|
||||
$query = substr($query, 0, -4);
|
||||
$query .= ')';
|
||||
}
|
||||
|
||||
$query = substr($query, 0, -4);
|
||||
if (isset($limit))
|
||||
$query .=') LIMIT '.$limit.';';
|
||||
$query .=' LIMIT '.$limit.';';
|
||||
else
|
||||
$query .=');';
|
||||
$query .=';';
|
||||
|
||||
$query = $this->query($query);
|
||||
if($query->rowCount() != 1) return false;
|
||||
return $query->fetch();
|
||||
$rowCount = $query->rowCount();
|
||||
if ($rowCount <= 0) return false;
|
||||
else if ($rowCount == 1) {
|
||||
return $query->fetch();
|
||||
}
|
||||
|
||||
return $query->fetchAll();
|
||||
|
||||
}
|
||||
|
||||
public function insert($table, $data)
|
||||
|
@@ -190,6 +190,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
* @version 0.1.3
|
||||
* @return OTS_Base_DAO Current row.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
$id = current($this->rows);
|
||||
@@ -203,7 +204,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
*
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->rows = $this->db->query( $this->getSQL() )->fetchAll();
|
||||
}
|
||||
@@ -211,7 +212,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
/**
|
||||
* Moves to next row.
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
next($this->rows);
|
||||
}
|
||||
@@ -221,6 +222,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
*
|
||||
* @return mixed Array key.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return key($this->rows);
|
||||
@@ -231,7 +233,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
*
|
||||
* @return bool Does next row exist.
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return key($this->rows) !== null;
|
||||
}
|
||||
@@ -243,7 +245,7 @@ abstract class OTS_Base_List implements IOTS_DAO, Iterator, Countable
|
||||
* @return int Number of rows.
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->db->query( $this->getSQL(true) )->fetchColumn();
|
||||
}
|
||||
|
@@ -15,11 +15,11 @@
|
||||
|
||||
/**
|
||||
* Container item representation.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This class represents items that can contain other items. It's {@link OTS_Container::count() count() method} has been overwritten so it now doesn't return count of current item (if it would even be possible for containers) but amount of items within (not recursively).
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
*/
|
||||
@@ -27,14 +27,14 @@ class OTS_Container extends OTS_Item implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* Contained items.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $items = array();
|
||||
|
||||
/**
|
||||
* Adds item to container.
|
||||
*
|
||||
*
|
||||
* @param OTS_Item $item Item.
|
||||
*/
|
||||
public function addItem(OTS_Item $item)
|
||||
@@ -44,11 +44,11 @@ class OTS_Container extends OTS_Item implements IteratorAggregate
|
||||
|
||||
/**
|
||||
* Removes given item from current container.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Passed item must be exacly instance of item which is stored in container, not it's copy. This method bases on PHP references.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param OTS_Item $item Item.
|
||||
* @tutorial POT/Players.pkg#deleting
|
||||
*/
|
||||
@@ -66,14 +66,14 @@ class OTS_Container extends OTS_Item implements IteratorAggregate
|
||||
|
||||
/**
|
||||
* Number of items inside container.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* OTS_Container implementation of Countable interface differs from {@link OTS_Item OTS_Item} implemention. {@link OTS_Item::count() OTS_Item::count()} returns count of given item, OTS_Container::count() returns number of items inside container. If somehow it would be possible to make container items with more then 1 in one place, you can use {@link OTS_Item::getCount() OTS_Item::getCount()} and {@link OTS_Item::setCount() OTS_Item::setCount()} in code where you are not sure if working with regular item, or container.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return int Number of items.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($items);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ class OTS_Container extends OTS_Item implements IteratorAggregate
|
||||
|
||||
/**
|
||||
* Returns iterator handle for loops.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @return ArrayIterator Items iterator.
|
||||
@@ -135,7 +135,7 @@ class OTS_Container extends OTS_Item implements IteratorAggregate
|
||||
|
||||
/**
|
||||
* Clones all contained items.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
*/
|
||||
|
@@ -6,7 +6,7 @@ if (PHP_VERSION_ID >= 80000) {
|
||||
/**
|
||||
* @return PDOStatement
|
||||
*/
|
||||
public function query(?string $query = null, ?int $fetchMode = null, mixed ...$fetchModeArgs)
|
||||
public function query(?string $query = null, ?int $fetchMode = null, mixed ...$fetchModeArgs): PDOStatement
|
||||
{
|
||||
return $this->doQuery($query, $fetchMode, ...$fetchModeArgs);
|
||||
}
|
||||
|
@@ -538,6 +538,7 @@ class OTS_Group extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return Iterator List of players.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getPlayersList();
|
||||
@@ -552,7 +553,7 @@ class OTS_Group extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return int Count of players.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->getPlayersList()->count();
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
$info['access'] = $group['name'];
|
||||
$this->groups[$group['id']] = new OTS_Group($info);
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
global $config;
|
||||
$file = $config['data_path'] . 'XML/groups.xml';
|
||||
}
|
||||
|
||||
|
||||
if(!@file_exists($file)) {
|
||||
error('Error: Cannot load groups.xml. More info in system/logs/error.log file.');
|
||||
log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.xml (' . $file . '). It doesnt exist.');
|
||||
@@ -99,7 +99,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.xml (' . $file . '). Error: ' . print_r(error_get_last(), true));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// loads groups
|
||||
foreach($groups->getElementsByTagName('group') as $group)
|
||||
{
|
||||
@@ -157,7 +157,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
if($id > $group_id)
|
||||
$group_id = $id;
|
||||
}
|
||||
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
@@ -196,6 +196,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
* @since 0.1.5
|
||||
* @return AppendIterator Iterator for all groups.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
$iterator = new AppendIterator();
|
||||
@@ -210,7 +211,7 @@ class OTS_Groups_List implements IteratorAggregate, Countable
|
||||
* @since 0.1.5
|
||||
* @return int Amount of all groups.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->groups);
|
||||
}
|
||||
|
@@ -709,6 +709,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return Iterator List of ranks.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getGuildRanksList();
|
||||
@@ -723,7 +724,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return int Count of ranks.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->getGuildRanksList()->count();
|
||||
}
|
||||
|
@@ -396,6 +396,7 @@ class OTS_GuildRank extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return Iterator List of players.
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getPlayersList();
|
||||
@@ -410,7 +411,7 @@ class OTS_GuildRank extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
* @throws PDOException On PDO operation error.
|
||||
* @return int Count of players.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->getPlayersList()->count();
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
/**
|
||||
* Wrapper for houses list.
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @tutorial POT/data_directory.pkg#towns.houses
|
||||
@@ -24,14 +24,14 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* List of houses elements.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $houses = array();
|
||||
|
||||
/**
|
||||
* Loads houses information.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $path Houses file.
|
||||
* @throws DOMException On DOM operation error.
|
||||
@@ -49,11 +49,11 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Allows object importing from {@link http://www.php.net/manual/en/function.var-export.php var_export()}.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param array $properties List of object properties.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -72,7 +72,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given house exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param string $name Name.
|
||||
@@ -94,7 +94,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns house information.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param int $id House ID.
|
||||
* @return OTS_House House information wrapper.
|
||||
@@ -112,7 +112,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given house ID exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param int $id ID.
|
||||
@@ -125,7 +125,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns ID of house with given name.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $name House name.
|
||||
* @return int House ID.
|
||||
@@ -147,17 +147,17 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns amount of houses.
|
||||
*
|
||||
*
|
||||
* @return int Count of houses.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->houses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns iterator handle for loops.
|
||||
*
|
||||
*
|
||||
* @return ArrayIterator Houses list iterator.
|
||||
*/
|
||||
public function getIterator()
|
||||
@@ -167,7 +167,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given element exists.
|
||||
*
|
||||
*
|
||||
* @param string|int $offset Array key.
|
||||
* @return bool True if it's set.
|
||||
*/
|
||||
@@ -185,7 +185,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns item from given position.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string|int $offset Array key.
|
||||
* @return OTS_House|int If key is an integer (type-sensitive!) then returns house instance. If it's a string then return associated ID found by house name.
|
||||
@@ -204,7 +204,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to houses list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @param string|int $offset Array key.
|
||||
* @param mixed $value Field value.
|
||||
* @throws E_OTS_ReadOnly Always - this class is read-only.
|
||||
@@ -216,7 +216,7 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to houses list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @param string|int $offset Array key.
|
||||
* @throws E_OTS_ReadOnly Always - this class is read-only.
|
||||
*/
|
||||
@@ -227,11 +227,11 @@ class OTS_HousesList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns string representation of object.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* If any display driver is currently loaded then it uses it's method.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @return string String representation of object.
|
||||
|
@@ -15,11 +15,11 @@
|
||||
|
||||
/**
|
||||
* Single item representation.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This class represents item that player has. It has no information about item feature, just it's handle in database. To get information about item type and it's features you have to use {@link OTS_ItemType OTS_ItemType class} - you can get it's object by calling {@link OTS_Item::getItemType() getItemType() method}, however you need to have global item types list loaded.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.0
|
||||
* @property int $count Amount of item.
|
||||
@@ -31,28 +31,28 @@ class OTS_Item implements Countable
|
||||
{
|
||||
/**
|
||||
* Item ID.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Item count.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $count = 0;
|
||||
|
||||
/**
|
||||
* Additional attributes.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* Creates item of given ID.
|
||||
*
|
||||
*
|
||||
* @param int $id Item ID.
|
||||
*/
|
||||
public function __construct($id)
|
||||
@@ -62,7 +62,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Returns item type.
|
||||
*
|
||||
*
|
||||
* @return int Item ID.
|
||||
*/
|
||||
public function getId()
|
||||
@@ -72,7 +72,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Returns count of item.
|
||||
*
|
||||
*
|
||||
* @return int Count of item.
|
||||
*/
|
||||
public function getCount()
|
||||
@@ -82,7 +82,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Sets count of item.
|
||||
*
|
||||
*
|
||||
* @param int $count Count.
|
||||
*/
|
||||
public function setCount($count)
|
||||
@@ -92,7 +92,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Returns item custom attributes.
|
||||
*
|
||||
*
|
||||
* @return string Attributes.
|
||||
*/
|
||||
public function getAttributes()
|
||||
@@ -102,7 +102,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Sets item attributes.
|
||||
*
|
||||
*
|
||||
* @param string $attributes Item Attributes.
|
||||
*/
|
||||
public function setAttributes($attributes)
|
||||
@@ -112,7 +112,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Returns type of item.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @return OTS_ItemType Returns item type of item (null if not exists).
|
||||
@@ -125,17 +125,17 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Count value for current item.
|
||||
*
|
||||
*
|
||||
* @return int Count of item.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string $name Property name.
|
||||
@@ -166,7 +166,7 @@ class OTS_Item implements Countable
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string $name Property name.
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
/**
|
||||
* Code in this file bases on oryginal OTServ items loading C++ code (itemloader.h, items.cpp, items.h).
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @author Wrzasq <wrzasq@gmail.com>
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
/**
|
||||
* Items list loader.
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @property-read int $otbVersion OTB file version.
|
||||
@@ -88,35 +88,35 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Temple positions.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $items = array();
|
||||
|
||||
/**
|
||||
* OTB version.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $otbVersion;
|
||||
|
||||
/**
|
||||
* Client version.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $clientVersion;
|
||||
|
||||
/**
|
||||
* Build version.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $buildVersion;
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Allows object unserialisation.
|
||||
* </p>
|
||||
@@ -129,11 +129,11 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Loads items.xml and items.otb files.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This method loads both items.xml and items.otb files. Both of them has to be in given directory.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $path Path to data/items directory.
|
||||
* @throws E_OTS_FileLoaderError When error occurs during file operation.
|
||||
@@ -191,7 +191,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Parses loaded file.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @throws E_OTS_FileLoaderError If file has invalid format.
|
||||
*/
|
||||
@@ -378,7 +378,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns OTB file version.
|
||||
*
|
||||
*
|
||||
* @return int OTB format version.
|
||||
*/
|
||||
public function getOTBVersion()
|
||||
@@ -388,7 +388,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns client version.
|
||||
*
|
||||
*
|
||||
* @return int Client version.
|
||||
*/
|
||||
public function getClientVersion()
|
||||
@@ -398,7 +398,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns build version.
|
||||
*
|
||||
*
|
||||
* @return int Build version.
|
||||
*/
|
||||
public function getBuildVersion()
|
||||
@@ -408,7 +408,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Checks if given item type exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param string $name Name.
|
||||
@@ -430,7 +430,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns given item type.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param int $id Item type (server) ID.
|
||||
* @return OTS_ItemType Returns item type of given ID.
|
||||
@@ -448,7 +448,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Checks if given type ID exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param int $id ID.
|
||||
@@ -461,11 +461,11 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Finds item type by it's name.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Note: If there are more then one items with same name this function will return first found server ID. It doesn't also mean that it will be the lowest ID - item types are ordered in order that they were loaded from items.xml file.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $name Item type name.
|
||||
* @return int Returns item type (server) ID.
|
||||
@@ -497,10 +497,10 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns amount of items loaded.
|
||||
*
|
||||
*
|
||||
* @return int Count of types.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
@@ -550,7 +550,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns iterator handle for loops.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @return ArrayIterator Items list iterator.
|
||||
@@ -562,7 +562,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Checks if given element exists.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -582,7 +582,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns item from given position.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -602,7 +602,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to items list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -616,7 +616,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to items list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -629,7 +629,7 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string $name Property name.
|
||||
@@ -652,11 +652,11 @@ class OTS_ItemsList extends OTS_FileLoader implements IteratorAggregate, Countab
|
||||
|
||||
/**
|
||||
* Returns string representation of object.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* If any display driver is currently loaded then it uses it's method.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @return string String representation of object.
|
||||
|
@@ -163,7 +163,7 @@ class OTS_MonstersList implements Iterator, Countable, ArrayAccess
|
||||
*
|
||||
* @return int Count of monsters.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->monsters);
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
/**
|
||||
* Code in this file bases on oryginal OTServ OTBM format loading C++ code (iomapotbm.h, iomapotbm.cpp).
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @author Wrzasq <wrzasq@gmail.com>
|
||||
@@ -20,11 +20,11 @@
|
||||
|
||||
/**
|
||||
* OTBM format reader.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* POT OTBM file parser is less strict then oryginal OTServ one. For instance it will read waypoints from version 1 OTBM file even that there were no waypoints in that format.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.6
|
||||
* @property-read OTS_HousesList $housesList Houses list loaded from associated houses file.
|
||||
@@ -95,56 +95,56 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
const OTBM_ATTR_HOUSEDOORID = 14;
|
||||
/**
|
||||
* Amount.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_COUNT = 15;
|
||||
/**
|
||||
* Time interval.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_DURATION = 16;
|
||||
/**
|
||||
* Metamorphic stage.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_DECAYING_STATE = 17;
|
||||
/**
|
||||
* Date of being written.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_WRITTENDATE = 18;
|
||||
/**
|
||||
* Sign author.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_WRITTENBY = 19;
|
||||
/**
|
||||
* Sleeping player ID.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_SLEEPERGUID = 20;
|
||||
/**
|
||||
* Time of sleep started.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_ATTR_SLEEPSTART = 21;
|
||||
/**
|
||||
* Number of charges.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
@@ -208,14 +208,14 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
const OTBM_NODE_HOUSETILE = 14;
|
||||
/**
|
||||
* Waypoints list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
const OTBM_NODE_WAYPOINTS = 15;
|
||||
/**
|
||||
* Waypoint.
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
*/
|
||||
@@ -223,56 +223,56 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Map width.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* Map height.
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
/**
|
||||
* Map description.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
|
||||
/**
|
||||
* List of towns.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $towns = array();
|
||||
|
||||
/**
|
||||
* Temple positions.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $temples = array();
|
||||
|
||||
/**
|
||||
* Directory path.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $directory;
|
||||
|
||||
/**
|
||||
* External houses file.
|
||||
*
|
||||
*
|
||||
* @var OTS_HousesList
|
||||
*/
|
||||
private $housesList;
|
||||
|
||||
/**
|
||||
* List of map tracks.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
@@ -281,11 +281,11 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Allows object unserialisation.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @throws E_OTS_FileLoaderError When error occurs during file operation.
|
||||
*/
|
||||
public function __wakeup()
|
||||
@@ -296,7 +296,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Loads OTBM file content.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @param string $file Filename.
|
||||
* @throws E_OTS_FileLoaderError When error occurs during file operation.
|
||||
@@ -316,7 +316,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Parses loaded file.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @throws E_OTS_FileLoaderError When error occurs during file operation.
|
||||
* @throws E_OTS_OutOfBuffer When there is read attemp after end of stream.
|
||||
@@ -476,7 +476,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Loads map's houses list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @return OTS_HousesList Houses from external file.
|
||||
@@ -488,7 +488,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns map width.
|
||||
*
|
||||
*
|
||||
* @return int Map width.
|
||||
*/
|
||||
public function getWidth()
|
||||
@@ -498,7 +498,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns map height.
|
||||
*
|
||||
*
|
||||
* @return int Map height.
|
||||
*/
|
||||
public function getHeight()
|
||||
@@ -508,7 +508,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns map description.
|
||||
*
|
||||
*
|
||||
* @return string Map description.
|
||||
*/
|
||||
public function getDescription()
|
||||
@@ -518,11 +518,11 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns map waypoints list.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Each item of returned array is sub-array with list of waypoints.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.6
|
||||
* @since 0.1.6
|
||||
* @return array List of tracks.
|
||||
@@ -534,7 +534,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Checks if given town ID exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param int $id ID.
|
||||
@@ -547,7 +547,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns town's ID.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $name Town.
|
||||
* @return int ID.
|
||||
@@ -567,7 +567,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Checks if given town name exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param string $name Town.
|
||||
@@ -580,7 +580,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns name of given town's ID.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param int $id Town ID.
|
||||
* @return string Name.
|
||||
@@ -607,7 +607,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns town's temple position.
|
||||
*
|
||||
*
|
||||
* @param int $id Town id.
|
||||
* @return OTS_MapCoords|bool Point on map (false if not found).
|
||||
*/
|
||||
@@ -625,12 +625,12 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns amount of towns loaded.
|
||||
*
|
||||
*
|
||||
* @version 0.0.8
|
||||
* @since 0.0.8
|
||||
* @return int Count of towns.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->towns);
|
||||
}
|
||||
@@ -690,7 +690,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns iterator handle for loops.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @return ArrayIterator Towns list iterator.
|
||||
@@ -702,7 +702,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Checks if given element exists.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -724,7 +724,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns item from given position.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -754,7 +754,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to towns list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -768,7 +768,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to towns list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string|int $offset Array key.
|
||||
@@ -781,7 +781,7 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @version 0.1.0
|
||||
* @since 0.1.0
|
||||
* @param string $name Property name.
|
||||
@@ -814,11 +814,11 @@ class OTS_OTBMFile extends OTS_FileLoader implements IteratorAggregate, Countabl
|
||||
|
||||
/**
|
||||
* Returns string representation of object.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* If any display driver is currently loaded then it uses it's method.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @return string String representation of object.
|
||||
|
@@ -602,7 +602,7 @@ class OTS_Player extends OTS_Row_DAO
|
||||
}
|
||||
|
||||
$account = new OTS_Account();
|
||||
$account->load($this->data['account_id']);
|
||||
$account->load($this->data['account_id'], false, true);
|
||||
return $account;
|
||||
}
|
||||
|
||||
@@ -2489,7 +2489,7 @@ class OTS_Player extends OTS_Row_DAO
|
||||
|
||||
$value = $this->db->query('SELECT ' . $this->db->fieldName('value') . ' FROM ' . $this->db->tableName('player_storage') . ' WHERE ' . $this->db->fieldName('key') . ' = ' . (int) $key . ' AND ' . $this->db->fieldName('player_id') . ' = ' . $this->data['id'])->fetch();
|
||||
|
||||
if($value !== false)
|
||||
if($value === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@@ -324,7 +324,7 @@ class OTS_SpellsList implements IteratorAggregate, Countable
|
||||
* @since 0.1.5
|
||||
* @return int Amount of all spells.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->runes) + count($this->instants) + count($this->conjures);
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@
|
||||
|
||||
/**
|
||||
* Wrapper for vocations.xml file.
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @example examples/vocations.php vocations.php
|
||||
@@ -25,14 +25,14 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
{
|
||||
/**
|
||||
* List of vocations.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $vocations = array();
|
||||
|
||||
/**
|
||||
* Loads vocations list from given file.
|
||||
*
|
||||
*
|
||||
* @param string $file vocations.xml file location.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -51,11 +51,11 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Allows object importing from {@link http://www.php.net/manual/en/function.var-export.php var_export()}.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param array $properties List of object properties.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -74,7 +74,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given vocation ID exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param int $id ID.
|
||||
@@ -87,7 +87,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns vocation's ID.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string $name Vocation.
|
||||
* @return int ID.
|
||||
@@ -108,7 +108,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given vocation name exists on list.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @param string $name Vocation.
|
||||
@@ -121,7 +121,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns name of given vocation's ID.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param int $id Vocation ID.
|
||||
* @return string Name.
|
||||
@@ -139,17 +139,17 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns amount of vocations loaded.
|
||||
*
|
||||
*
|
||||
* @return int Count of vocations.
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->vocations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns iterator handle for loops.
|
||||
*
|
||||
*
|
||||
* @return ArrayIterator Vocations list iterator.
|
||||
*/
|
||||
public function getIterator()
|
||||
@@ -159,7 +159,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Checks if given element exists.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string|int $offset Array key.
|
||||
* @return bool True if it's set.
|
||||
@@ -178,7 +178,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* Returns item from given position.
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @param string|int $offset Array key.
|
||||
* @return string|int If key is an integer (type-sensitive!) then returns vocation name. If it's a string then return associated ID.
|
||||
@@ -197,7 +197,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to vocations list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @param string|int $offset Array key.
|
||||
* @param mixed $value Field value.
|
||||
* @throws E_OTS_ReadOnly Always - this class is read-only.
|
||||
@@ -209,7 +209,7 @@ class OTS_VocationsList implements IteratorAggregate, Countable, ArrayAccess
|
||||
|
||||
/**
|
||||
* This method is implemented for ArrayAccess interface. In fact you can't write/append to vocations list. Any call to this method will cause {@link E_OTS_ReadOnly E_OTS_ReadOnly} raise.
|
||||
*
|
||||
*
|
||||
* @param string|int $offset Array key.
|
||||
* @throws E_OTS_ReadOnly Always - this class is read-only.
|
||||
*/
|
||||
|
285
system/libs/rfc6238.php
Normal file
285
system/libs/rfc6238.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/** https://github.com/Voronenko/PHPOTP/blob/08cda9cb9c30b7242cf0b3a9100a6244a2874927/code/base32static.php
|
||||
* Encode in Base32 based on RFC 4648.
|
||||
* Requires 20% more space than base64
|
||||
* Great for case-insensitive filesystems like Windows and URL's (except for = char which can be excluded using the pad option for urls)
|
||||
*
|
||||
* @package default
|
||||
* @author Bryan Ruiz
|
||||
**/
|
||||
class Base32Static {
|
||||
|
||||
private static $map = array(
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 7
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 15
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 23
|
||||
'Y', 'Z', '2', '3', '4', '5', '6', '7', // 31
|
||||
'=' // padding character
|
||||
);
|
||||
|
||||
private static $flippedMap = array(
|
||||
'A'=>'0', 'B'=>'1', 'C'=>'2', 'D'=>'3', 'E'=>'4', 'F'=>'5', 'G'=>'6', 'H'=>'7',
|
||||
'I'=>'8', 'J'=>'9', 'K'=>'10', 'L'=>'11', 'M'=>'12', 'N'=>'13', 'O'=>'14', 'P'=>'15',
|
||||
'Q'=>'16', 'R'=>'17', 'S'=>'18', 'T'=>'19', 'U'=>'20', 'V'=>'21', 'W'=>'22', 'X'=>'23',
|
||||
'Y'=>'24', 'Z'=>'25', '2'=>'26', '3'=>'27', '4'=>'28', '5'=>'29', '6'=>'30', '7'=>'31'
|
||||
);
|
||||
|
||||
/**
|
||||
* Use padding false when encoding for urls
|
||||
*
|
||||
* @return base32 encoded string
|
||||
* @author Bryan Ruiz
|
||||
**/
|
||||
public static function encode($input, $padding = true) {
|
||||
if(empty($input)) return "";
|
||||
|
||||
$input = str_split($input);
|
||||
$binaryString = "";
|
||||
|
||||
for($i = 0; $i < count($input); $i++) {
|
||||
$binaryString .= str_pad(base_convert(ord($input[$i]), 10, 2), 8, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$fiveBitBinaryArray = str_split($binaryString, 5);
|
||||
$base32 = "";
|
||||
$i=0;
|
||||
|
||||
while($i < count($fiveBitBinaryArray)) {
|
||||
$base32 .= self::$map[base_convert(str_pad($fiveBitBinaryArray[$i], 5,'0'), 2, 10)];
|
||||
$i++;
|
||||
}
|
||||
|
||||
if($padding && ($x = strlen($binaryString) % 40) != 0) {
|
||||
if($x == 8) $base32 .= str_repeat(self::$map[32], 6);
|
||||
else if($x == 16) $base32 .= str_repeat(self::$map[32], 4);
|
||||
else if($x == 24) $base32 .= str_repeat(self::$map[32], 3);
|
||||
else if($x == 32) $base32 .= self::$map[32];
|
||||
}
|
||||
|
||||
return $base32;
|
||||
}
|
||||
|
||||
public static function decode($input) {
|
||||
if(empty($input)) return;
|
||||
|
||||
$paddingCharCount = substr_count($input, self::$map[32]);
|
||||
$allowedValues = array(6,4,3,1,0);
|
||||
|
||||
if(!in_array($paddingCharCount, $allowedValues)) return false;
|
||||
|
||||
for($i=0; $i<4; $i++){
|
||||
if($paddingCharCount == $allowedValues[$i] &&
|
||||
substr($input, -($allowedValues[$i])) != str_repeat(self::$map[32], $allowedValues[$i])) return false;
|
||||
}
|
||||
|
||||
$input = str_replace('=','', $input);
|
||||
$input = str_split($input);
|
||||
$binaryString = "";
|
||||
|
||||
for($i=0; $i < count($input); $i = $i+8) {
|
||||
$x = "";
|
||||
|
||||
if(!in_array($input[$i], self::$map)) return false;
|
||||
|
||||
for($j=0; $j < 8; $j++) {
|
||||
$x .= str_pad(base_convert(@self::$flippedMap[@$input[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
$eightBits = str_split($x, 8);
|
||||
|
||||
for($z = 0; $z < count($eightBits); $z++) {
|
||||
$binaryString .= ( ($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48 ) ? $y:"";
|
||||
}
|
||||
}
|
||||
|
||||
return $binaryString;
|
||||
}
|
||||
}
|
||||
|
||||
// http://www.faqs.org/rfcs/rfc6238.html
|
||||
// https://github.com/Voronenko/PHPOTP/blob/08cda9cb9c30b7242cf0b3a9100a6244a2874927/code/rfc6238.php
|
||||
// Local changes: http -> https, consistent indentation, 200x200 -> 300x300 QR image size, PHP end tag
|
||||
class TokenAuth6238 {
|
||||
|
||||
/**
|
||||
* verify
|
||||
*
|
||||
* @param string $secretkey Secret clue (base 32).
|
||||
* @return bool True if success, false if failure
|
||||
*/
|
||||
public static function verify($secretkey, $code, $rangein30s = 3) {
|
||||
$key = base32static::decode($secretkey);
|
||||
$unixtimestamp = time()/30;
|
||||
|
||||
for($i=-($rangein30s); $i<=$rangein30s; $i++) {
|
||||
$checktime = (int)($unixtimestamp+$i);
|
||||
$thiskey = self::oath_hotp($key, $checktime);
|
||||
|
||||
if ((int)$code == self::oath_truncate($thiskey,6)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function getTokenCode($secretkey,$rangein30s = 3) {
|
||||
$result = "";
|
||||
$key = base32static::decode($secretkey);
|
||||
$unixtimestamp = time()/30;
|
||||
|
||||
for($i=-($rangein30s); $i<=$rangein30s; $i++) {
|
||||
$checktime = (int)($unixtimestamp+$i);
|
||||
$thiskey = self::oath_hotp($key, $checktime);
|
||||
$result = $result." # ".self::oath_truncate($thiskey,6);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getTokenCodeDebug($secretkey,$rangein30s = 3) {
|
||||
$result = "";
|
||||
print "<br/>SecretKey: $secretkey <br/>";
|
||||
|
||||
$key = base32static::decode($secretkey);
|
||||
print "Key(base 32 decode): $key <br/>";
|
||||
|
||||
$unixtimestamp = time()/30;
|
||||
print "UnixTimeStamp (time()/30): $unixtimestamp <br/>";
|
||||
|
||||
for($i=-($rangein30s); $i<=$rangein30s; $i++) {
|
||||
$checktime = (int)($unixtimestamp+$i);
|
||||
print "Calculating oath_hotp from (int)(unixtimestamp +- 30sec offset): $checktime basing on secret key<br/>";
|
||||
|
||||
$thiskey = self::oath_hotp($key, $checktime, true);
|
||||
print "======================================================<br/>";
|
||||
print "CheckTime: $checktime oath_hotp:".$thiskey."<br/>";
|
||||
|
||||
$result = $result." # ".self::oath_truncate($thiskey,6,true);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getBarCodeUrl($username, $domain, $secretkey, $issuer) {
|
||||
$url = "https://chart.apis.google.com/chart";
|
||||
$url = $url."?chs=300x300&chld=M|0&cht=qr&chl=otpauth://totp/";
|
||||
$url = $url.$username . "@" . $domain . "%3Fsecret%3D" . $secretkey . '%26issuer%3D' . rawurlencode($issuer);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function generateRandomClue($length = 16) {
|
||||
$b32 = "234567QWERTYUIOPASDFGHJKLZXCVBNM";
|
||||
$s = "";
|
||||
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
$s .= $b32[rand(0,31)];
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
private static function hotp_tobytestream($key) {
|
||||
$result = array();
|
||||
$last = strlen($key);
|
||||
for ($i = 0; $i < $last; $i = $i + 2) {
|
||||
$x = $key[$i] + $key[$i + 1];
|
||||
$x = strtoupper($x);
|
||||
$x = hexdec($x);
|
||||
$result = $result.chr($x);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function oath_hotp ($key, $counter, $debug=false) {
|
||||
$result = "";
|
||||
$orgcounter = $counter;
|
||||
$cur_counter = array(0,0,0,0,0,0,0,0);
|
||||
|
||||
if ($debug) {
|
||||
print "Packing counter $counter (".dechex($counter).")into binary string - pay attention to hex representation of key and binary representation<br/>";
|
||||
}
|
||||
|
||||
for($i=7;$i>=0;$i--) { // C for unsigned char, * for repeating to the end of the input data
|
||||
$cur_counter[$i] = pack ('C*', $counter);
|
||||
|
||||
if ($debug) {
|
||||
print $cur_counter[$i]."(".dechex(ord($cur_counter[$i])).")"." from $counter <br/>";
|
||||
}
|
||||
|
||||
$counter = $counter >> 8;
|
||||
}
|
||||
|
||||
if ($debug) {
|
||||
foreach ($cur_counter as $char) {
|
||||
print ord($char) . " ";
|
||||
}
|
||||
|
||||
print "<br/>";
|
||||
}
|
||||
|
||||
$binary = implode($cur_counter);
|
||||
|
||||
// Pad to 8 characters
|
||||
str_pad($binary, 8, chr(0), STR_PAD_LEFT);
|
||||
|
||||
if ($debug) {
|
||||
print "Prior to HMAC calculation pad with zero on the left until 8 characters.<br/>";
|
||||
print "Calculate sha1 HMAC(Hash-based Message Authentication Code http://en.wikipedia.org/wiki/HMAC).<br/>";
|
||||
print "hash_hmac ('sha1', $binary, $key)<br/>";
|
||||
}
|
||||
|
||||
$result = hash_hmac ('sha1', $binary, $key);
|
||||
|
||||
if ($debug) {
|
||||
print "Result: $result <br/>";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function oath_truncate($hash, $length = 6, $debug=false) {
|
||||
$result="";
|
||||
|
||||
// Convert to dec
|
||||
if($debug) {
|
||||
print "converting hex hash into characters<br/>";
|
||||
}
|
||||
|
||||
$hashcharacters = str_split($hash,2);
|
||||
|
||||
if($debug) {
|
||||
print_r($hashcharacters);
|
||||
print "<br/>and convert to decimals:<br/>";
|
||||
}
|
||||
|
||||
for ($j=0; $j<count($hashcharacters); $j++) {
|
||||
$hmac_result[]=hexdec($hashcharacters[$j]);
|
||||
}
|
||||
|
||||
if($debug) {
|
||||
print_r($hmac_result);
|
||||
}
|
||||
|
||||
// http://php.net/manual/ru/function.hash-hmac.php
|
||||
// adopted from brent at thebrent dot net 21-May-2009 08:17 comment
|
||||
|
||||
$offset = $hmac_result[19] & 0xf;
|
||||
|
||||
if($debug) {
|
||||
print "Calculating offset as 19th element of hmac:".$hmac_result[19]."<br/>";
|
||||
print "offset:".$offset;
|
||||
}
|
||||
|
||||
$result = (
|
||||
(($hmac_result[$offset+0] & 0x7f) << 24 ) |
|
||||
(($hmac_result[$offset+1] & 0xff) << 16 ) |
|
||||
(($hmac_result[$offset+2] & 0xff) << 8 ) |
|
||||
($hmac_result[$offset+3] & 0xff)
|
||||
) % pow(10,$length);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
@@ -354,16 +354,6 @@ class Validator
|
||||
}
|
||||
}
|
||||
|
||||
if(strspn($name, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM- '") != $name_length) {
|
||||
self::$lastError = 'This name contains invalid letters, words or format. Please use only a-Z, - , \' and space.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!preg_match("/[A-z ']/", $name)) {
|
||||
self::$lastError = 'Your name containst illegal characters.';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user