+
+ ob_get_clean(), 'script' => $javascript];
+ }
+
+ #[\ReturnTypeWillChange]
+ public function offsetSet($offset, $value)
+ {
+ if (is_null($offset)) {
+ throw new \RuntimeException("Settings: You cannot set empty offset with value: $value!");
+ }
+
+ $this->loadPlugin($offset);
+
+ $pluginKeyName = $this->valuesAsked['pluginKeyName'];
+ $key = $this->valuesAsked['key'];
+
+ // remove whole plugin settings
+ if (!isset($value)) {
+ $this->offsetUnset($offset);
+ $this->deleteFromDatabase($pluginKeyName, $key);
+ return;
+ }
+
+ $this->settingsDatabase[$pluginKeyName][$key] = $value;
+ $this->updateInDatabase($pluginKeyName, $key, $value);
+ }
+
+ #[\ReturnTypeWillChange]
+ public function offsetExists($offset): bool
+ {
+ $this->loadPlugin($offset);
+
+ $pluginKeyName = $this->valuesAsked['pluginKeyName'];
+ $key = $this->valuesAsked['key'];
+
+ // remove specified plugin settings (all)
+ if(is_null($key)) {
+ return isset($this->settingsDatabase[$offset]);
+ }
+
+ return isset($this->settingsDatabase[$pluginKeyName][$key]);
+ }
+
+ #[\ReturnTypeWillChange]
+ public function offsetUnset($offset)
+ {
+ $this->loadPlugin($offset);
+
+ $pluginKeyName = $this->valuesAsked['pluginKeyName'];
+ $key = $this->valuesAsked['key'];
+
+ if (isset($this->cache[$offset])) {
+ unset($this->cache[$offset]);
+ }
+
+ // remove specified plugin settings (all)
+ if(!isset($key)) {
+ unset($this->settingsFile[$pluginKeyName]);
+ unset($this->settingsDatabase[$pluginKeyName]);
+ $this->deleteFromDatabase($pluginKeyName);
+ return;
+ }
+
+ unset($this->settingsFile[$pluginKeyName]['settings'][$key]);
+ unset($this->settingsDatabase[$pluginKeyName][$key]);
+ $this->deleteFromDatabase($pluginKeyName, $key);
+ }
+
+ /**
+ * Get settings
+ * Usage: $setting['plugin_name.key']
+ * Example: $settings['shop_system.paypal_email']
+ *
+ * @param mixed $offset
+ * @return array|mixed
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetGet($offset)
+ {
+ // try cache hit
+ if(isset($this->cache[$offset])) {
+ return $this->cache[$offset];
+ }
+
+ $this->loadPlugin($offset);
+
+ $pluginKeyName = $this->valuesAsked['pluginKeyName'];
+ $key = $this->valuesAsked['key'];
+
+ // return specified plugin settings (all)
+ if(!isset($key)) {
+ if (!isset($this->settingsFile[$pluginKeyName]['settings'])) {
+ throw new RuntimeException('Unknown plugin settings: ' . $pluginKeyName);
+ }
+ return $this->settingsFile[$pluginKeyName]['settings'];
+ }
+
+ $ret = [];
+ if(isset($this->settingsFile[$pluginKeyName]['settings'][$key])) {
+ $ret = $this->settingsFile[$pluginKeyName]['settings'][$key];
+ }
+
+ if(isset($this->settingsDatabase[$pluginKeyName][$key])) {
+ $value = $this->settingsDatabase[$pluginKeyName][$key];
+
+ $ret['value'] = $value;
+ }
+ else {
+ $ret['value'] = $this->settingsFile[$pluginKeyName]['settings'][$key]['default'];
+ }
+
+ if(isset($ret['type'])) {
+ switch($ret['type']) {
+ case 'boolean':
+ $ret['value'] = getBoolean($ret['value']);
+ break;
+
+ case 'number':
+ if (!isset($ret['step']) || (int)$ret['step'] == 1) {
+ $ret['value'] = (int)$ret['value'];
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (isset($ret['callbacks']['get'])) {
+ $ret['value'] = $ret['callbacks']['get']($ret['value']);
+ }
+
+ $this->cache[$offset] = $ret;
+ return $ret;
+ }
+
+ private function updateValuesAsked($offset)
+ {
+ $pluginKeyName = $offset;
+ if (strpos($offset, '.')) {
+ $explode = explode('.', $offset, 2);
+
+ $pluginKeyName = $explode[0];
+ $key = $explode[1];
+
+ $this->valuesAsked = ['pluginKeyName' => $pluginKeyName, 'key' => $key];
+ }
+ else {
+ $this->valuesAsked = ['pluginKeyName' => $pluginKeyName, 'key' => null];
+ }
+ }
+
+ private function loadPlugin($offset)
+ {
+ $this->updateValuesAsked($offset);
+
+ $pluginKeyName = $this->valuesAsked['pluginKeyName'];
+ $key = $this->valuesAsked['key'];
+
+ if (!isset($this->settingsFile[$pluginKeyName])) {
+ if ($pluginKeyName === 'core') {
+ $settingsFilePath = SYSTEM . 'settings.php';
+ } else {
+ //$pluginSettings = Plugins::getPluginSettings($pluginKeyName);
+ $settings = Plugins::getAllPluginsSettings();
+ if (!isset($settings[$pluginKeyName])) {
+ warning("Setting $pluginKeyName does not exist or does not have settings defined.");
+ return;
+ }
+
+ $settingsFilePath = BASE . $settings[$pluginKeyName]['settingsFilename'];
+ }
+
+ if (!file_exists($settingsFilePath)) {
+ throw new \RuntimeException('Failed to load settings file for plugin: ' . $pluginKeyName);
+ }
+
+ $this->settingsFile[$pluginKeyName] = require $settingsFilePath;
+ }
+ }
+
+ public static function saveConfig($config, $filename, &$content = '')
+ {
+ $content = " $value) {
+ $content .= "\$config['$key'] = ";
+ $content .= var_export($value, true);
+ $content .= ';' . PHP_EOL;
+ }
+
+ $success = file_put_contents($filename, $content);
+
+ // we saved new config.php, need to revalidate cache (only if opcache is enabled)
+ if (function_exists('opcache_invalidate')) {
+ opcache_invalidate($filename);
+ }
+
+ return $success;
+ }
+
+ public static function testDatabaseConnection($config): bool
+ {
+ $user = null;
+ $password = null;
+ $dns = [];
+
+ if( isset($config['database_name']) ) {
+ $dns[] = 'dbname=' . $config['database_name'];
+ }
+
+ if( isset($config['database_user']) ) {
+ $user = $config['database_user'];
+ }
+
+ if( isset($config['database_password']) ) {
+ $password = $config['database_password'];
+ }
+
+ if( isset($config['database_host']) ) {
+ $dns[] = 'host=' . $config['database_host'];
+ }
+
+ if( isset($config['database_port']) ) {
+ $dns[] = 'port=' . $config['database_port'];
+ }
+
+ try {
+ $connectionTest = new PDO('mysql:' . implode(';', $dns), $user, $password);
+ $connectionTest->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ }
+ catch(PDOException $error) {
+ error('MySQL connection failed. Settings has been reverted.');
+ error($error->getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+ public function getErrors() {
+ return $this->errors;
+ }
+}
diff --git a/system/libs/forum.php b/system/libs/forum.php
index 4922a9c3..c7f303f7 100644
--- a/system/libs/forum.php
+++ b/system/libs/forum.php
@@ -10,7 +10,7 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
-$configForumTablePrefix = config('forum_table_prefix');
+$configForumTablePrefix = setting('core.forum_table_prefix');
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_".');
@@ -47,7 +47,7 @@ class Forum
return
$db->query(
'SELECT `id` FROM `players` WHERE `account_id` = ' . $db->quote($account->getId()) .
- ' AND `level` >= ' . $db->quote($config['forum_level_required']) .
+ ' AND `level` >= ' . $db->quote(setting('core.forum_level_required')) .
' LIMIT 1')->rowCount() > 0;
}
diff --git a/system/libs/plugins.php b/system/libs/plugins.php
index c3b548dc..c2b8f594 100644
--- a/system/libs/plugins.php
+++ b/system/libs/plugins.php
@@ -168,6 +168,36 @@ class Plugins {
return $hooks;
}
+ public static function getAllPluginsSettings()
+ {
+ $cache = Cache::getInstance();
+ if ($cache->enabled()) {
+ $tmp = '';
+ if ($cache->fetch('plugins_settings', $tmp)) {
+ return unserialize($tmp);
+ }
+ }
+
+ $settings = [];
+ foreach (self::getAllPluginsJson() as $plugin) {
+ if (isset($plugin['settings'])) {
+ $settingsFile = require BASE . $plugin['settings'];
+ if (!isset($settingsFile['key'])) {
+ warning("Settings file for plugin - {$plugin['name']} does not contain 'key' field");
+ continue;
+ }
+
+ $settings[$settingsFile['key']] = ['pluginFilename' => $plugin['filename'], 'settingsFilename' => $plugin['settings']];
+ }
+ }
+
+ if ($cache->enabled()) {
+ $cache->set('plugins_settings', serialize($settings), 600); // cache for 10 minutes
+ }
+
+ return $settings;
+ }
+
public static function getAllPluginsJson($disabled = false)
{
$cache = Cache::getInstance();
@@ -180,30 +210,66 @@ class Plugins {
$plugins = [];
foreach (get_plugins($disabled) as $filename) {
- $string = file_get_contents(PLUGINS . $filename . '.json');
- $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.';
+ $plugin = self::getPluginJson($filename);
+
+ if (!$plugin) {
continue;
}
+ $plugin['filename'] = $filename;
$plugins[] = $plugin;
}
if ($cache->enabled()) {
- $cache->set('plugins', serialize($plugins), 600);
+ $cache->set('plugins', serialize($plugins), 600); // cache for 10 minutes
}
return $plugins;
}
- public static function install($file) {
+ public static function getPluginSettings($filename)
+ {
+ $plugin_json = self::getPluginJson($filename);
+ if (!$plugin_json) {
+ return false;
+ }
+
+ if (!isset($plugin_json['settings']) || !file_exists(BASE . $plugin_json['settings'])) {
+ return false;
+ }
+
+ return $plugin_json['settings'];
+ }
+
+ public static function getPluginJson($filename = null)
+ {
+ if(!isset($filename)) {
+ return self::$plugin_json;
+ }
+
+ $pathToPlugin = PLUGINS . $filename . '.json';
+ if (!file_exists($pathToPlugin)) {
+ self::$warnings[] = "Cannot load $filename.json. File doesn't exist.";
+ return false;
+ }
+
+ $string = file_get_contents($pathToPlugin);
+ $plugin_json = json_decode($string, true);
+ if ($plugin_json == null) {
+ self::$warnings[] = "Cannot load $filename.json. File might be not a valid json code.";
+ return false;
+ }
+
+ if (isset($plugin_json['enabled']) && !getBoolean($plugin_json['enabled'])) {
+ self::$warnings[] = 'Skipping ' . $filename . '... The plugin is disabled.';
+ return false;
+ }
+
+ return $plugin_json;
+ }
+
+ public static function install($file): bool
+ {
global $db;
if(!\class_exists('ZipArchive')) {
@@ -242,6 +308,12 @@ class Plugins {
return false;
}
+ $pluginFilename = str_replace('.json', '', basename($json_file));
+ if (self::existDisabled($pluginFilename)) {
+ success('The plugin already existed, but was disabled. It has been enabled again and will be now reinstalled.');
+ self::enable($pluginFilename);
+ }
+
$string = file_get_contents($file_name);
$plugin_json = json_decode($string, true);
self::$plugin_json = $plugin_json;
@@ -442,13 +514,23 @@ class Plugins {
return false;
}
- public static function enable($pluginFileName): bool
+ public static function isEnabled($pluginFileName): bool
{
+ $filenameJson = $pluginFileName . '.json';
+ return !is_file(PLUGINS . 'disabled.' . $filenameJson) && is_file(PLUGINS . $filenameJson);
+ }
+
+ public static function existDisabled($pluginFileName): bool
+ {
+ $filenameJson = $pluginFileName . '.json';
+ return is_file(PLUGINS . 'disabled.' . $filenameJson);
+ }
+
+ public static function enable($pluginFileName): bool {
return self::enableDisable($pluginFileName, true);
}
- public static function disable($pluginFileName): bool
- {
+ public static function disable($pluginFileName): bool {
return self::enableDisable($pluginFileName, false);
}
@@ -526,7 +608,8 @@ class Plugins {
return false;
}
- public static function is_installed($plugin_name, $version) {
+ public static function is_installed($plugin_name, $version): bool
+ {
$filename = BASE . 'plugins/' . $plugin_name . '.json';
if(!file_exists($filename)) {
return false;
@@ -534,7 +617,7 @@ class Plugins {
$string = file_get_contents($filename);
$plugin_info = json_decode($string, true);
- if($plugin_info == false) {
+ if(!$plugin_info) {
return false;
}
@@ -557,10 +640,6 @@ class Plugins {
return self::$error;
}
- public static function getPluginJson() {
- return self::$plugin_json;
- }
-
/**
* Install menus
* Helper function for plugins
diff --git a/system/libs/pot/OTS_ServerInfo.php b/system/libs/pot/OTS_ServerInfo.php
index 30a81f7b..eebe0d2e 100644
--- a/system/libs/pot/OTS_ServerInfo.php
+++ b/system/libs/pot/OTS_ServerInfo.php
@@ -14,7 +14,7 @@
/**
* Various server status querying methods.
- *
+ *
* @package POT
* @property-read OTS_InfoRespond|bool $status status() method wrapper.
* @property-read OTS_ServerStatus|bool $info Full info() method wrapper.
@@ -23,21 +23,21 @@ class OTS_ServerInfo
{
/**
* Server address.
- *
+ *
* @var string
*/
private $server;
/**
* Connection port.
- *
+ *
* @var int
*/
private $port;
/**
* Creates handler for new server.
- *
+ *
* @param string $server Server IP/domain.
* @param int $port OTServ port.
*/
@@ -49,7 +49,7 @@ class OTS_ServerInfo
/**
* Sends packet to server.
- *
+ *
* @param OTS_Buffer|string $packet Buffer to send.
* @return OTS_Buffer|null Respond buffer (null if server is offline).
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
@@ -57,7 +57,7 @@ class OTS_ServerInfo
private function send(OTS_Buffer $packet)
{
// connects to server
- $socket = @fsockopen($this->server, $this->port, $error, $message, config('status_timeout'));
+ $socket = @fsockopen($this->server, $this->port, $error, $message, setting('core.status_timeout'));
// if connected then checking statistics
if($socket)
@@ -75,7 +75,7 @@ class OTS_ServerInfo
// reads respond
//$data = stream_get_contents($socket);
- $data = '';
+ $data = '';
while (!feof($socket))
$data .= fgets($socket, 1024);
@@ -97,11 +97,11 @@ class OTS_ServerInfo
/**
* Queries server status.
- *
+ *
*
* Sends 'info' packet to OTS server and return output. Returns {@link OTS_InfoRespond OTS_InfoRespond} (wrapper for XML data) with results or false if server is online.
*
- *
+ *
* @return OTS_InfoRespond|bool Respond content document (false when server is offline).
* @throws DOMException On DOM operation error.
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
@@ -135,11 +135,11 @@ class OTS_ServerInfo
/**
* Queries server information.
- *
+ *
*
* This method uses binary info protocol. It provides more infromation then {@link OTS_Toolbox::serverStatus() XML way}.
*
- *
+ *
* @param int $flags Requested info flags.
* @return OTS_ServerStatus|bool Respond content document (false when server is offline).
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
@@ -169,11 +169,11 @@ class OTS_ServerInfo
/**
* Checks player online status.
- *
+ *
*
* This method uses binary info protocol.
*
- *
+ *
* @param string $name Player name.
* @return bool True if player is online, false if player or server is online.
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
@@ -204,7 +204,7 @@ class OTS_ServerInfo
/**
* Magic PHP5 method.
- *
+ *
* @param string $name Property name.
* @param mixed $value Property value.
* @throws OutOfBoundsException For non-supported properties.
diff --git a/system/libs/validator.php b/system/libs/validator.php
index eb958583..e7bffd6a 100644
--- a/system/libs/validator.php
+++ b/system/libs/validator.php
@@ -117,7 +117,7 @@ class Validator
return false;
}
- if(config('account_mail_block_plus_sign')) {
+ if(setting('core.account_mail_block_plus_sign')) {
$explode = explode('@', $email);
if(isset($explode[0]) && (strpos($explode[0],'+') !== false)) {
self::$lastError = 'Please do not use plus (+) sign in your e-mail.';
@@ -180,15 +180,16 @@ class Validator
return false;
}
- $minLength = config('character_name_min_length');
- $maxLength = config('character_name_max_length');
-
// installer doesn't know config.php yet
// that's why we need to ignore the nulls
- if(is_null($minLength) || is_null($maxLength)) {
+ if(defined('MYAAC_INSTALL')) {
$minLength = 4;
$maxLength = 21;
}
+ else {
+ $minLength = setting('core.create_character_name_min_length');
+ $maxLength = setting('core.create_character_name_max_length');
+ }
$length = strlen($name);
if($length < $minLength)
@@ -221,16 +222,6 @@ class Validator
return false;
}
- $npcCheck = config('character_name_npc_check');
- if ($npcCheck) {
- require_once LIBS . 'npc.php';
- NPCS::load();
- if(NPCS::$npcs && in_array(strtolower($name), NPCS::$npcs)) {
- self::$lastError = "Invalid name format. Do not use NPC Names";
- return false;
- }
- }
-
return true;
}
@@ -246,14 +237,9 @@ class Validator
global $db, $config;
$name_lower = strtolower($name);
- $custom_first_words_blocked = [];
- if (isset($config['character_name_blocked']['prefix']) && $config['character_name_blocked']['prefix']) {
- $custom_first_words_blocked = $config['character_name_blocked']['prefix'];
- }
- $first_words_blocked = array_merge($custom_first_words_blocked, array('admin ', 'administrator ', 'gm ', 'cm ', 'god ','tutor ', "'", '-'));
- foreach($first_words_blocked as $word)
- {
+ $first_words_blocked = array_merge(["'", '-'], setting('core.create_character_name_blocked_prefix'));
+ foreach($first_words_blocked as $word) {
if($word == substr($name_lower, 0, strlen($word))) {
self::$lastError = 'Your name contains blocked words.';
return false;
@@ -275,8 +261,7 @@ class Validator
return false;
}
- if(preg_match('/ {2,}/', $name))
- {
+ if(preg_match('/ {2,}/', $name)) {
self::$lastError = 'Invalid character name format. Use only A-Z and numbers 0-9 and no double spaces.';
return false;
}
@@ -286,26 +271,16 @@ class Validator
return false;
}
- $custom_names_blocked = [];
- if (isset($config['character_name_blocked']['names']) && $config['character_name_blocked']['names']) {
- $custom_names_blocked = $config['character_name_blocked']['names'];
- }
- $names_blocked = array_merge($custom_names_blocked, array('admin', 'administrator', 'gm', 'cm', 'god', 'tutor'));
- foreach($names_blocked as $word)
- {
+ $names_blocked = setting('core.create_character_name_blocked_names');
+ foreach($names_blocked as $word) {
if($word == $name_lower) {
self::$lastError = 'Your name contains blocked words.';
return false;
}
}
- $custom_words_blocked = [];
- if (isset($config['character_name_blocked']['words']) && $config['character_name_blocked']['words']) {
- $custom_words_blocked = $config['character_name_blocked']['words'];
- }
- $words_blocked = array_merge($custom_words_blocked, array('admin', 'administrator', 'gamemaster', 'game master', 'game-master', "game'master", '--', "''","' ", " '", '- ', ' -', "-'", "'-", 'fuck', 'sux', 'suck', 'noob', 'tutor'));
- foreach($words_blocked as $word)
- {
+ $words_blocked = array_merge(['--', "''","' ", " '", '- ', ' -', "-'", "'-"], setting('core.create_character_name_blocked_words'));
+ foreach($words_blocked as $word) {
if(!(strpos($name_lower, $word) === false)) {
self::$lastError = 'Your name contains illegal words.';
return false;
@@ -321,7 +296,7 @@ class Validator
}
}
- //check if was namelocked previously
+ // check if was namelocked previously
if($db->hasTable('player_namelocks') && $db->hasColumn('player_namelocks', 'name')) {
$namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name));
if($namelock->rowCount() > 0) {
@@ -330,39 +305,41 @@ class Validator
}
}
- $monsters = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'monsters` WHERE `name` LIKE ' . $db->quote($name_lower));
- if($monsters->rowCount() > 0) {
- self::$lastError = 'Your name cannot contains monster name.';
- return false;
- }
-
- $spells_name = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'spells` WHERE `name` LIKE ' . $db->quote($name_lower));
- if($spells_name->rowCount() > 0) {
- self::$lastError = 'Your name cannot contains spell name.';
- return false;
- }
-
- $spells_words = $db->query('SELECT `words` FROM `' . TABLE_PREFIX . 'spells` WHERE `words` = ' . $db->quote($name_lower));
- if($spells_words->rowCount() > 0) {
- self::$lastError = 'Your name cannot contains spell name.';
- return false;
- }
-
- if(isset($config['npc']))
- {
- if(in_array($name_lower, $config['npc'])) {
- self::$lastError = 'Your name cannot contains NPC name.';
+ $monstersCheck = setting('core.create_character_name_monsters_check');
+ if ($monstersCheck) {
+ $monsters = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'monsters` WHERE `name` LIKE ' . $db->quote($name_lower));
+ if ($monsters->rowCount() > 0) {
+ self::$lastError = 'Your name cannot contains monster name.';
return false;
}
}
- $npcCheck = config('character_name_npc_check');
+ $spellsCheck = setting('core.create_character_name_spells_check');
+ if ($spellsCheck) {
+ $spells_name = $db->query('SELECT `name` FROM `' . TABLE_PREFIX . 'spells` WHERE `name` LIKE ' . $db->quote($name_lower));
+ if ($spells_name->rowCount() > 0) {
+ self::$lastError = 'Your name cannot contains spell name.';
+ return false;
+ }
+
+ $spells_words = $db->query('SELECT `words` FROM `' . TABLE_PREFIX . 'spells` WHERE `words` = ' . $db->quote($name_lower));
+ if ($spells_words->rowCount() > 0) {
+ self::$lastError = 'Your name cannot contains spell name.';
+ return false;
+ }
+ }
+
+ $npcCheck = setting('core.create_character_name_npc_check');
if ($npcCheck) {
require_once LIBS . 'npc.php';
NPCS::load();
- if(NPCS::$npcs && in_array($name_lower, NPCS::$npcs)) {
- self::$lastError = "Invalid name format. Do not use NPC Names";
- return false;
+ if(NPCS::$npcs) {
+ foreach (NPCs::$npcs as $npc) {
+ if(strpos($name_lower, $npc) !== false) {
+ self::$lastError = 'Your name cannot contains NPC name.';
+ return false;
+ }
+ }
}
}
diff --git a/system/migrations/20.php b/system/migrations/20.php
index d0012fde..b0e09471 100644
--- a/system/migrations/20.php
+++ b/system/migrations/20.php
@@ -1,47 +1,15 @@
query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;");
+
+$highscores_ignored_ids = array();
+if($query->rowCount() > 0) {
+ foreach($query->fetchAll() as $result)
+ $highscores_ignored_ids[] = $result['id'];
+}
+else {
+ $highscores_ignored_ids[] = 0;
}
-function databaseMigration20(&$content = '') {
- global $db;
-
- $config_file = BASE . 'config.local.php';
- if(!is_writable($config_file)) { // we can't do anything, just ignore
- return false;
- }
-
- $content_of_file = trim(file_get_contents($config_file));
- if(strpos($content_of_file, 'highscores_ids_hidden') !== false) { // already present
- return true;
- }
-
- $query = $db->query("SELECT `id` FROM `players` WHERE (`name` = " . $db->quote("Rook Sample") . " OR `name` = " . $db->quote("Sorcerer Sample") . " OR `name` = " . $db->quote("Druid Sample") . " OR `name` = " . $db->quote("Paladin Sample") . " OR `name` = " . $db->quote("Knight Sample") . " OR `name` = " . $db->quote("Account Manager") . ") ORDER BY `id`;");
-
- $highscores_ignored_ids = array();
- if($query->rowCount() > 0) {
- foreach($query->fetchAll() as $result)
- $highscores_ignored_ids[] = $result['id'];
- }
- else {
- $highscores_ignored_ids[] = 0;
- }
-
- $php_on_end = substr($content_of_file, -2, 2) == '?>';
- $content = PHP_EOL;
- if($php_on_end) {
- $content .= '';
- }
-
- file_put_contents($config_file, $content, FILE_APPEND);
- return true;
-}
+$settings = Settings::getInstance();
+$settings->updateInDatabase('core', 'highscores_ids_hidden', implode(', ', $highscores_ignored_ids));
diff --git a/system/migrations/36.php b/system/migrations/36.php
new file mode 100644
index 00000000..d88e9d28
--- /dev/null
+++ b/system/migrations/36.php
@@ -0,0 +1,14 @@
+hasTable(TABLE_PREFIX . 'settings')) {
+ $db->exec("CREATE TABLE `" . TABLE_PREFIX . "settings`
+ (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` VARCHAR(255) NOT NULL DEFAULT '',
+ `key` VARCHAR(255) NOT NULL DEFAULT '',
+ `value` TEXT NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `key` (`key`)
+ ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;");
+}
diff --git a/system/pages/account/change_name.php b/system/pages/account/change_name.php
index 48b6bb4d..ef82b9ad 100644
--- a/system/pages/account/change_name.php
+++ b/system/pages/account/change_name.php
@@ -19,17 +19,17 @@ if(!$logged) {
$player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL;
$name = isset($_POST['name']) ? stripslashes(ucwords(strtolower($_POST['name']))) : NULL;
-if((!$config['account_change_character_name']))
+if((!setting('core.account_change_character_name')))
echo 'Changing character name for premium points is disabled on this server.';
else
{
- $points = $account_logged->getCustomField('premium_points');
+ $points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['changenamesave']) && $_POST['changenamesave'] == 1) {
- if($points < $config['account_change_character_name_points'])
- $errors[] = 'You need ' . $config['account_change_character_name_points'] . ' premium points to change name. You have '.$points.' premium points.';
+ if($points < setting('core.account_change_character_name_price'))
+ $errors[] = 'You need ' . setting('core.account_change_character_name_price') . ' premium points to change name. You have '.$points.' premium points.';
- $minLength = config('character_name_min_length');
- $maxLength = config('character_name_max_length');
+ $minLength = setting('core.create_character_name_min_length');
+ $maxLength = setting('core.create_character_name_max_length');
if(empty($errors) && empty($name))
$errors[] = 'Please enter a new name for your character!';
@@ -86,7 +86,7 @@ else
}
}
- $account_logged->setCustomField("premium_points", $points - $config['account_change_character_name_points']);
+ $account_logged->setCustomField(setting('core.donate_column'), $points - setting('core.account_change_character_name_price'));
$account_logged->logAction('Changed name from ' . $old_name . ' to ' . $player->getName() . '.');
$twig->display('success.html.twig', array(
'title' => 'Character Name Changed',
diff --git a/system/pages/account/change_password.php b/system/pages/account/change_password.php
index deef3602..95e15159 100644
--- a/system/pages/account/change_password.php
+++ b/system/pages/account/change_password.php
@@ -69,7 +69,7 @@ else
$account_logged->logAction('Account password changed.');
$message = '';
- if($config['mail_enabled'] && $config['send_mail_when_change_password']) {
+ if(setting('core.mail_enabled') && setting('core.mail_send_when_change_password')) {
$mailBody = $twig->render('mail.password_changed.html.twig', array(
'new_password' => $org_pass,
'ip' => get_browser_real_ip(),
@@ -89,4 +89,4 @@ else
));
setSession('password', $new_password);
}
-}
\ No newline at end of file
+}
diff --git a/system/pages/account/change_sex.php b/system/pages/account/change_sex.php
index 2f944564..7e43b6ff 100644
--- a/system/pages/account/change_sex.php
+++ b/system/pages/account/change_sex.php
@@ -20,14 +20,14 @@ if(!$logged) {
$sex_changed = false;
$player_id = isset($_POST['player_id']) ? (int)$_POST['player_id'] : NULL;
$new_sex = isset($_POST['new_sex']) ? (int)$_POST['new_sex'] : NULL;
-if((!$config['account_change_character_sex']))
+if((!setting('core.account_change_character_sex')))
echo 'You cant change your character sex';
else
{
- $points = $account_logged->getCustomField('premium_points');
+ $points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['changesexsave']) && $_POST['changesexsave'] == 1) {
- if($points < $config['account_change_character_sex_points'])
- $errors[] = 'You need ' . $config['account_change_character_sex_points'] . ' premium points to change sex. You have '.$points.' premium points.';
+ if($points < setting('core.account_change_character_sex_price'))
+ $errors[] = 'You need ' . setting('core.account_change_character_sex_price') . ' premium points to change sex. You have '.$points.' premium points.';
if(empty($errors) && !isset($config['genders'][$new_sex])) {
$errors[] = 'This sex is invalid.';
@@ -66,7 +66,7 @@ else
$new_sex_str = $config['genders'][$new_sex];
$player->save();
- $account_logged->setCustomField("premium_points", $points - $config['account_change_character_name_points']);
+ $account_logged->setCustomField(setting('core.donate_column'), $points - setting('core.account_change_character_name_price'));
$account_logged->logAction('Changed sex on character ' . $player->getName() . ' from ' . $old_sex_str . ' to ' . $new_sex_str . '.');
$twig->display('success.html.twig', array(
'title' => 'Character Sex Changed',
diff --git a/system/pages/account/create.php b/system/pages/account/create.php
index dd7c7713..2aa7c544 100644
--- a/system/pages/account/create.php
+++ b/system/pages/account/create.php
@@ -219,7 +219,7 @@ if($save)
$tmp_account = (USE_ACCOUNT_NAME ? $account_name : $account_id);
}
- if($config['mail_enabled'] && $config['account_mail_verify'])
+ if(setting('core.mail_enabled') && $config['account_mail_verify'])
{
$hash = md5(generateRandomString(16, true, true) . $email);
$new_account->setCustomField('email_hash', $hash);
@@ -294,7 +294,7 @@ if($save)
'custom_buttons' => config('account_create_character_create') ? '' : null
));
- if($config['mail_enabled'] && $config['account_welcome_mail'])
+ if(setting('core.mail_enabled') && $config['account_welcome_mail'])
{
$mailBody = $twig->render('account.welcome_mail.html.twig', array(
'account' => $tmp_account
@@ -313,7 +313,7 @@ if($save)
}
$country_recognized = null;
-if($config['account_country_recognize']) {
+if(setting('core.account_country_recognize')) {
$country_session = getSession('country');
if($country_session !== false) { // get from session
$country_recognized = $country_session;
diff --git a/system/pages/account/lost.php b/system/pages/account/lost.php
index 3ea0957e..664cee9c 100644
--- a/system/pages/account/lost.php
+++ b/system/pages/account/lost.php
@@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Lost Account Interface';
-if(!$config['mail_enabled'])
+if(!setting('core.mail_enabled'))
{
echo 'Account maker is not configured to send e-mails, you can\'t use Lost Account Interface. Contact with admin to get help.';
return;
@@ -59,7 +59,7 @@ elseif($action == 'step1' && $action_type == 'email')
$minutesleft = floor($insec / 60);
$secondsleft = $insec - ($minutesleft * 60);
$timeleft = $minutesleft.' minutes '.$secondsleft.' seconds';
- echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil($config['email_lai_sec_interval'] / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.';
+ echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil(setting('core.mail_lost_account_interval') / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.';
}
}
else
@@ -104,7 +104,7 @@ elseif($action == 'sendcode')
if(_mail($account_mail, $config['lua']['serverName'].' - Recover your account', $mailBody))
{
$account->setCustomField('email_code', $newcode);
- $account->setCustomField('email_next', (time() + $config['email_lai_sec_interval']));
+ $account->setCustomField('email_next', (time() + setting('core.mail_lost_account_interval')));
echo ' Details about steps required to recover your account has been sent to ' . $account_mail . '. You should receive this email within 15 minutes. Please check your inbox/spam directory.';
}
else
@@ -122,7 +122,7 @@ elseif($action == 'sendcode')
$minutesleft = floor($insec / 60);
$secondsleft = $insec - ($minutesleft * 60);
$timeleft = $minutesleft.' minutes '.$secondsleft.' seconds';
- echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil($config['email_lai_sec_interval'] / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.';
+ echo 'Account of selected character ('.$nick.') received e-mail in last '.ceil(setting('core.mail_lost_account_interval') / 60).' minutes. You must wait '.$timeleft.' before you can use Lost Account Interface again.';
}
}
else
diff --git a/system/pages/account/manage.php b/system/pages/account/manage.php
index b2af3cee..c4a8402a 100644
--- a/system/pages/account/manage.php
+++ b/system/pages/account/manage.php
@@ -35,7 +35,7 @@ if(empty($recovery_key))
$account_registered = 'No';
else
{
- if($config['generate_new_reckey'] && $config['mail_enabled'])
+ if(setting('core.account_generate_new_reckey') && setting('core.mail_enabled'))
$account_registered = 'Yes ( Buy new Recovery Key )';
else
$account_registered = 'Yes';
diff --git a/system/pages/account/register.php b/system/pages/account/register.php
index 1d16d905..f33f0b17 100644
--- a/system/pages/account/register.php
+++ b/system/pages/account/register.php
@@ -31,7 +31,7 @@ if(isset($_POST['registeraccountsave']) && $_POST['registeraccountsave'] == "1")
$account_logged->logAction('Generated recovery key.');
$message = '';
- if($config['mail_enabled'] && $config['send_mail_when_generate_reckey'])
+ if(setting('core.mail_enabled') && setting('core.mail_send_when_generate_reckey'))
{
$mailBody = $twig->render('mail.account.register.html.twig', array(
'recovery_key' => $new_rec_key
diff --git a/system/pages/account/register_new.php b/system/pages/account/register_new.php
index fb2e8ea3..04e8bf33 100644
--- a/system/pages/account/register_new.php
+++ b/system/pages/account/register_new.php
@@ -21,18 +21,18 @@ if(isset($_POST['reg_password']))
$reg_password = encrypt((USE_ACCOUNT_SALT ? $account_logged->getCustomField('salt') : '') . $_POST['reg_password']);
$reckey = $account_logged->getCustomField('key');
-if((!$config['generate_new_reckey'] || !$config['mail_enabled']) || empty($reckey)) {
+if((!setting('core.account_generate_new_reckey') || !setting('core.mail_enabled')) || empty($reckey)) {
$errors[] = 'You cant get new recovery key.';
$twig->display('error_box.html.twig', array('errors' => $errors));
}
else
{
- $points = $account_logged->getCustomField('premium_points');
+ $points = $account_logged->getCustomField(setting('core.donate_column'));
if(isset($_POST['registeraccountsave']) && $_POST['registeraccountsave'] == '1')
{
if($reg_password == $account_logged->getPassword())
{
- if($points >= $config['generate_new_reckey_price'])
+ if($points >= setting('core.account_generate_new_reckey_price'))
{
$show_form = false;
$new_rec_key = generateRandomString(10, false, true, true);
@@ -43,10 +43,10 @@ else
if(_mail($account_logged->getEMail(), $config['lua']['serverName']." - new recovery key", $mailBody))
{
- $account_logged->setCustomField("key", $new_rec_key);
- $account_logged->setCustomField("premium_points", $account_logged->getCustomField("premium_points") - $config['generate_new_reckey_price']);
- $account_logged->logAction('Generated new recovery key for ' . $config['generate_new_reckey_price'] . ' premium points.');
- $message = ' Your recovery key were send on email address '.$account_logged->getEMail().' for '.$config['generate_new_reckey_price'].' premium points.';
+ $account_logged->setCustomField('key', $new_rec_key);
+ $account_logged->setCustomField(setting('core.donate_column'), $account_logged->getCustomField(setting('core.donate_column')) - setting('core.account_generate_new_reckey_price'));
+ $account_logged->logAction('Generated new recovery key for ' . setting('core.account_generate_new_reckey_price') . ' premium points.');
+ $message = ' Your recovery key were send on email address '.$account_logged->getEMail().' for '.setting('core.account_generate_new_reckey_price').' premium points.';
}
else
$message = '
An error occurred while sending email ( '.$account_logged->getEMail().' ) with recovery key! Recovery key not changed. Try again later. For Admin: More info can be found in system/logs/mailer-error.log
-
\ No newline at end of file
+
diff --git a/system/templates/account.create.html.twig b/system/templates/account.create.html.twig
index 38907c74..a43d6e7d 100644
--- a/system/templates/account.create.html.twig
+++ b/system/templates/account.create.html.twig
@@ -59,7 +59,7 @@
{% if errors.email is defined %}{{ errors.email }}{% endif %}
- {% if config.mail_enabled and config.account_mail_verify %}
+ {% if setting('core.mail_enabled') and config.account_mail_verify %}
Please use real address! We will send a link to validate your Email.
{% endif %}
@@ -122,7 +122,7 @@
{{ hook('HOOK_ACCOUNT_CREATE_BETWEEN_BOXES_1') }}
- {% if (not config.mail_enabled or not config.account_mail_verify) and config.account_create_character_create %}
+ {% if (not setting('core.mail_enabled') or not config.account_mail_verify) and config.account_create_character_create %}
@@ -140,7 +140,7 @@
Character Name:
-
+
diff --git a/system/templates/account.create_character.html.twig b/system/templates/account.create_character.html.twig
index 045c749c..acb57f5c 100644
--- a/system/templates/account.create_character.html.twig
+++ b/system/templates/account.create_character.html.twig
@@ -45,7 +45,7 @@ In any case the name must not violate the naming conventions stated in the
-
\ No newline at end of file
+
diff --git a/system/templates/account.generate_new_recovery_key.html.twig b/system/templates/account.generate_new_recovery_key.html.twig
index f1ec611b..6f3e5c50 100644
--- a/system/templates/account.generate_new_recovery_key.html.twig
+++ b/system/templates/account.generate_new_recovery_key.html.twig
@@ -1,5 +1,5 @@
To generate new recovery key for your account please enter your password.
-New recovery key cost {{ config.generate_new_reckey_price }} Premium Points. You have {{ points }} premium points. You will receive e-mail with this recovery key.
+New recovery key cost {{ setting('core.account_generate_new_reckey_price') }} Premium Points. You have {{ points }} premium points. You will receive e-mail with this recovery key.
@@ -56,4 +56,4 @@ To generate new recovery key for your account please enter your password.
-
\ No newline at end of file
+
diff --git a/system/templates/account.management.html.twig b/system/templates/account.management.html.twig
index 510c90a1..95fc0975 100644
--- a/system/templates/account.management.html.twig
+++ b/system/templates/account.management.html.twig
@@ -39,10 +39,10 @@
{% for name, link in menus %}
{{ name }}
{% endfor %}
- {% if config.account_change_character_name %}
+ {% if setting('core.account_change_character_name') %}
Change Name
{% endif %}
- {% if config.account_change_character_sex %}
+ {% if setting('core.account_change_character_sex') %}
Change Sex
{% endif %}
Logout
@@ -192,7 +192,7 @@
{% include('buttons.base.html.twig') %}
- {% if config.account_change_character_name %}
+ {% if setting('core.account_change_character_name') %}
{% endif %}
- {% if config.account_change_character_sex %}
+ {% if setting('core.account_change_character_sex') %}
{% set button_name = 'Change Sex' %}
diff --git a/system/templates/admin.settings.html.twig b/system/templates/admin.settings.html.twig
new file mode 100644
index 00000000..e5d3ef9b
--- /dev/null
+++ b/system/templates/admin.settings.html.twig
@@ -0,0 +1,105 @@
+
+
+
Settings
+
+
+
+
+
+
+
+
+
+
+ {{ settingsParsed|raw }}
+
+
+
+
+
+
+
+
+{{ script|raw }}
+
+
+
+
diff --git a/system/templates/characters.html.twig b/system/templates/characters.html.twig
index 4234f2ab..9553d20c 100644
--- a/system/templates/characters.html.twig
+++ b/system/templates/characters.html.twig
@@ -284,7 +284,7 @@
{{ hook(constant('HOOK_CHARACTERS_BEFORE_SIGNATURE')) }}
- {% if config.signature_enabled %}
+ {% if setting('core.signature_enabled') %}
\ No newline at end of file
+
diff --git a/system/templates/install.config.html.twig b/system/templates/install.config.html.twig
index 0776d540..ab4fc361 100644
--- a/system/templates/install.config.html.twig
+++ b/system/templates/install.config.html.twig
@@ -9,7 +9,7 @@
- {% for value in ['server_path', 'mail_admin'] %}
+ {% for value in ['server_path'] %}
diff --git a/system/templates/mail.password_changed.html.twig b/system/templates/mail.password_changed.html.twig
index d87601f0..a43af3a2 100644
--- a/system/templates/mail.password_changed.html.twig
+++ b/system/templates/mail.password_changed.html.twig
@@ -4,4 +4,4 @@ The request was made on {{ "now"|date("F j, Y, g:i a") }} by a user with the IP:
The new password is: {{ new_password }}
-If this was you, please ignore this email. If it was not you, please contact our support department at {{ config.mail_admin }}.
\ No newline at end of file
+If this was you, please ignore this email. If it was not you, please contact our support department.
diff --git a/system/templates/team.html.twig b/system/templates/team.html.twig
index bbbe35cd..a979e670 100644
--- a/system/templates/team.html.twig
+++ b/system/templates/team.html.twig
@@ -25,7 +25,7 @@
Group
- {% if config.team_display_outfit %}
+ {% if setting('core.team_outfit') %}
Outfit
@@ -35,19 +35,19 @@
Name
- {% if config.team_display_status %}
+ {% if setting('core.team_status') %}
Status
{% endif %}
- {% if (config.multiworld or config.team_display_world) %}
+ {% if (setting('core.multiworld') or setting('core.team_world')) %}
World
{% endif %}
- {% if config.team_display_lastlogin %}
+ {% if setting('core.team_lastlogin') %}
Last login
@@ -61,7 +61,7 @@
{{ group.group_name|capitalize }}
- {% if config.team_display_outfit %}
+ {% if setting('core.team_outfit') %}
@@ -74,7 +74,7 @@
{{ member.link|raw }}
- {% if config.team_display_status %}
+ {% if setting('core.team_status') %}
{% if member.status %}
Online
@@ -84,13 +84,13 @@
{% endif %}
- {% if (config.multiworld or config.team_display_world) %}
+ {% if (setting('core.multiworld') or setting('core.team_world')) %}
{{ member.world_name }}
{% endif %}
- {% if config.team_display_lastlogin %}
+ {% if setting('core.team_lastlogin') %}
{{ member.last_login }}
@@ -107,7 +107,7 @@
- {% if config.team_display_outfit %}
+ {% if setting('core.team_outfit') %}
Outfit
@@ -117,19 +117,19 @@
Name
- {% if config.team_display_status %}
+ {% if setting('core.team_status') %}
Status
{% endif %}
- {% if (config.multiworld or config.team_display_world) %}
+ {% if (setting('core.multiworld') or setting('core.team_world')) %}
World
{% endif %}
- {% if config.team_display_lastlogin %}
+ {% if setting('core.team_lastlogin') %}
Last login
@@ -139,7 +139,7 @@
{% for member in group.members %}
{% set i = i + 1 %}
- {% if config.team_display_outfit %}
+ {% if setting('core.team_outfit') %}
@@ -152,7 +152,7 @@
{{ member.link|raw }}
- {% if config.team_display_status %}
+ {% if setting('core.team_status') %}
{% if member.status %}
Online
@@ -162,13 +162,13 @@
{% endif %}
- {% if (config.multiworld or config.team_display_world) %}
+ {% if (setting('core.multiworld') or setting('core.team_world')) %}
{{ member.world_name }}
{% endif %}
- {% if config.team_display_lastlogin %}
+ {% if setting('core.team_lastlogin') %}
{{ member.last_login }}
diff --git a/system/twig.php b/system/twig.php
index 4fc7c5ec..5eb35c68 100644
--- a/system/twig.php
+++ b/system/twig.php
@@ -107,6 +107,11 @@ $function = new TwigFunction('config', function ($key) {
});
$twig->addFunction($function);
+$function = new TwigFunction('setting', function ($key) {
+ return setting($key);
+});
+$twig->addFunction($function);
+
$function = new TwigFunction('getCustomPage', function ($name) {
$success = false;
return getCustomPage($name, $success);
diff --git a/templates/tibiacom/account.management.html.twig b/templates/tibiacom/account.management.html.twig
index 7c387c36..e1106e8c 100644
--- a/templates/tibiacom/account.management.html.twig
+++ b/templates/tibiacom/account.management.html.twig
@@ -470,7 +470,7 @@
- {% if config.account_change_character_name %}
+ {% if setting('core.account_change_character_name') %}
@@ -483,7 +483,7 @@
{% endif %}
- {% if config.account_change_character_sex %}
+ {% if setting('core.account_change_character_sex') %}