diff --git a/admin/index.php b/admin/index.php
index d0a16a2e..2045059c 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -1 +1 @@
-install/ directory exists. Please visit this url to start MyAAC Installation.
Delete install/ directory if you already installed MyAAC.
Remember to REFRESH this page when you\'re done!');
}
$content = '';
// validate page
$page = isset($_GET['p']) ? $_GET['p'] : '';
if(empty($page) || preg_match("/[^a-zA-Z0-9_\-]/", $page))
$page = 'dashboard';
$page = strtolower($page);
define('PAGE', $page);
require(SYSTEM . 'functions.php');
require(SYSTEM . 'init.php');
require(SYSTEM . 'status.php');
require(SYSTEM . 'login.php');
require(ADMIN . 'includes/functions.php');
// if we're not logged in - show login box
if(!$logged || !admin()) {
$page = 'login';
}
// include our page
$file = SYSTEM . 'pages/admin/' . $page . '.php';
if(!@file_exists($file)) {
$page = '404';
$file = SYSTEM . 'pages/404.php';
}
ob_start();
include($file);
$content .= ob_get_contents();
ob_end_clean();
// template
$template_path = 'templates/clean/';
require(ADMIN . $template_path . 'template.php');
?>
\ No newline at end of file
+install/ directory exists. Please visit this url to start MyAAC Installation.
Delete install/ directory if you already installed MyAAC.
Remember to REFRESH this page when you\'re done!');
}
$content = '';
// validate page
$page = isset($_GET['p']) ? $_GET['p'] : '';
if(empty($page) || preg_match("/[^a-zA-Z0-9_\-]/", $page))
$page = 'dashboard';
$page = strtolower($page);
define('PAGE', $page);
require(SYSTEM . 'functions.php');
require(SYSTEM . 'init.php');
require(SYSTEM . 'status.php');
require(SYSTEM . 'login.php');
require(ADMIN . 'includes/functions.php');
// if we're not logged in - show login box
if(!$logged || !admin()) {
$page = 'login';
}
// include our page
$file = SYSTEM . 'pages/admin/' . $page . '.php';
if(!@file_exists($file)) {
$page = '404';
$file = SYSTEM . 'pages/404.php';
}
ob_start();
include($file);
$content .= ob_get_contents();
ob_end_clean();
// template
$template_path = 'templates/clean/';
require(ADMIN . $template_path . 'template.php');
?>
\ No newline at end of file
diff --git a/common.php b/common.php
index 57d08275..48543716 100644
--- a/common.php
+++ b/common.php
@@ -28,6 +28,7 @@ session_start();
define('MYAAC', true);
define('MYAAC_VERSION', '0.0.6');
+define('DATABASE_VERSION', 1);
define('TABLE_PREFIX', 'myaac_');
define('START_TIME', microtime(true));
define('MYAAC_OS', (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? 'WINDOWS' : 'LINUX');
diff --git a/config.php b/config.php
index 2b67b13b..a3973e99 100644
--- a/config.php
+++ b/config.php
@@ -84,6 +84,8 @@ $config = array(
'account_welcome_mail' => true, // send welcome email when user registers
'account_mail_change' => 2, // how many days user need to change email to account - block hackers
'account_country' => true, // user will be able to set country of origin when registering account, this information will be viewable in others places aswell
+ 'account_change_character_name' => false, // can user change their character name for premium points?
+ 'account_change_character_name_points' => 30, // cost of name change
// mail
'mail_enabled' => false, // is aac maker configured to send e-mails?
diff --git a/index.php b/index.php
index c32044da..57640fdf 100644
--- a/index.php
+++ b/index.php
@@ -1 +1 @@
-
* @copyright 2017 MyAAC
* @version 0.0.6
* @link http://my-aac.org
*/
require_once('common.php');
require_once(BASE . 'config.local.php');
if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed']))
{
header('Location: ' . BASE_DIR . '/install/');
die('Setup detected that install/ directory exists. Please visit this url to start MyAAC Installation.
Delete install/ directory if you already installed MyAAC.
Remember to REFRESH this page when you\'re done!');
}
// define page visited, so it can be used within events system
$page = isset($_REQUEST['subtopic']) ? $_REQUEST['subtopic'] : (isset($_GET['p']) ? $_GET['p'] : '');
if(empty($page) || preg_match('/[^A-z0-9_\-]/', $page))
$page = 'news';
$page = strtolower($page);
define('PAGE', $page);
$template_place_holders = array();
// event system
require_once(SYSTEM . 'events.php');
$events = new Events();
$events->trigger('STARTUP');
require_once(SYSTEM . 'functions.php');
require_once(SYSTEM . 'init.php');
require_once(SYSTEM . 'login.php');
require_once(SYSTEM . 'status.php');
require_once(SYSTEM . 'template.php');
if($config['views_counter'])
require_once(SYSTEM . 'counter.php');
if($config['visitors_counter'])
{
require_once(SYSTEM . 'libs/visitors.php');
$visitors = new Visitors($config['visitors_counter_ttl']);
}
// page content loading
if(!isset($content[0]))
$content = '';
$load_it = true;
// check if site has been closed
if($config['site_closed'])
{
if(!admin())
{
$title = $config['site_closed_title'];
$content .= $config['site_closed_message'];
$load_it = false;
}
if(!$logged)
{
ob_start();
require(SYSTEM . 'pages/accountmanagement.php');
$content .= ob_get_contents();
ob_end_clean();
$load_it = false;
}
}
// backward support for gesior
if($config['backward_support']) {
define('INITIALIZED', true);
$SQL = $db;
$layout_header = template_header();
$layout_name = $template_path;
$config['access_admin_panel'] = 2;
$group_id_of_acc_logged = 0;
if($logged && $account_logged)
$group_id_of_acc_logged = $account_logged->getGroupId();
$config['site'] = &$config;
$config['server'] = &$config['lua'];
$config['site']['shop_system'] = $config['gifts_system'];
$config['serverinfo_page'] = 1;
$config['download_page'] = 1;
if($config['forum'] != '')
$config['forum_link'] = (strtolower($config['forum']) == 'site' ? internalLayoutLink('forum') : $config['forum']);
foreach($status as $key => $value)
$config['status']['serverStatus_' . $key] = $value;
}
if($load_it)
{
if($config['site_closed'] && admin())
$content .= '
Site is under maintenance (closed mode). Only privileged users can see it.
'; if($config['backward_support']) require(SYSTEM . 'compat_pages.php'); $ignore = false; $file = SYSTEM . 'pages/' . $page . '.php'; if(!@file_exists($file)) { $logged_access = 0; if($logged && $account_logged && $account_logged->isLoaded()) { $logged_access = $account_logged->getAccess(); } $query = $db->query( 'SELECT `title`, `body`, `php`' . ' FROM `' . TABLE_PREFIX . 'pages`' . ' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access)); if($query->rowCount() > 0) // found page { $ignore = true; $query = $query->fetch(); $title = $query['title']; if($query['php'] == '1') // execute it as php code { $tmp = substr($query['body'], 0, 10); if(($pos = strpos($tmp, ' $errno, 'errstr' => $errstr); } set_error_handler('error_handler'); ob_start(); eval($tmp); $content .= ob_get_contents(); ob_end_clean(); restore_error_handler(); if(isset($php_errors[0]) && superAdmin()) { var_dump($php_errors); } } else $content .= $query['body']; // plain html } else { $page = '404'; $file = SYSTEM . 'pages/404.php'; } } ob_start(); if($events->trigger('BEFORE_PAGE')) { if(!$ignore) require($file); } if($config['backward_support'] && isset($main_content)) $content .= $main_content; $content .= ob_get_contents(); ob_end_clean(); $events->trigger('AFTER_PAGE'); } if($config['backward_support']) { $main_content = $content; if(!isset($title)) $title = ucfirst($page); } $title_full = (isset($title) ? $title . $config['title_separator'] : '') . $config['lua']['serverName']; if(file_exists($template_path . '/index.php')) require($template_path . '/index.php'); else if(file_exists($template_path . '/template.php')) // deprecated require($template_path . '/template.php'); else if($config['backward_support'] && file_exists($template_path . '/layout.php')) { require($template_path . '/layout.php'); } else { // TODO: save more info to log file die('ERROR: Cannot load template.'); } echo '' . "\n"; if(($config['debug_level'] & 1) == 1) echo ''; if(($config['debug_level'] & 2) == 2) echo "\n" . ''; if(($config['debug_level'] & 4) == 4 && function_exists('memory_get_peak_usage')) echo "\n" . ''; $events->trigger('FINISH'); ?> \ No newline at end of file + * @copyright 2017 MyAAC * @version 0.0.6 * @link http://my-aac.org */ // uncomment if your php.ini have display_errors disabled and you want to see errors // ini_set('display_errors', 1); // ini_set('display_startup_errors', 1); // error_reporting(E_ALL); require_once('common.php'); require_once(BASE . 'config.local.php'); if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed'])) { header('Location: ' . BASE_URL . 'install/'); die('Setup detected that install/ directory exists. Please visit this url to start MyAAC Installation.Site is under maintenance (closed mode). Only privileged users can see it.
'; if($config['backward_support']) require(SYSTEM . 'compat_pages.php'); $ignore = false; $file = SYSTEM . 'pages/' . $page . '.php'; if(!@file_exists($file)) { $logged_access = 0; if($logged && $account_logged && $account_logged->isLoaded()) { $logged_access = $account_logged->getAccess(); } $query = $db->query( 'SELECT `title`, `body`, `php`' . ' FROM `' . TABLE_PREFIX . 'pages`' . ' WHERE `name` LIKE ' . $db->quote($page) . ' AND `hidden` != 1 AND `access` <= ' . $db->quote($logged_access)); if($query->rowCount() > 0) // found page { $ignore = true; $query = $query->fetch(); $title = $query['title']; if($query['php'] == '1') // execute it as php code { $tmp = substr($query['body'], 0, 10); if(($pos = strpos($tmp, ' $errno, 'errstr' => $errstr); } set_error_handler('error_handler'); ob_start(); eval($tmp); $content .= ob_get_contents(); ob_end_clean(); restore_error_handler(); if(isset($php_errors[0]) && superAdmin()) { var_dump($php_errors); } } else $content .= $query['body']; // plain html } else { $page = '404'; $file = SYSTEM . 'pages/404.php'; } } ob_start(); $hooks->trigger(HOOK_BEFORE_PAGE); if(!$ignore) require($file); if($config['backward_support'] && isset($main_content[0])) $content .= $main_content; $content .= ob_get_contents(); ob_end_clean(); $hooks->trigger(HOOK_AFTER_PAGE); } if($config['backward_support']) { $main_content = $content; if(!isset($title)) $title = ucfirst($page); $topic = $title; } $title_full = (isset($title) ? $title . $config['title_separator'] : '') . $config['lua']['serverName']; if(file_exists($template_path . '/index.php')) require($template_path . '/index.php'); else if(file_exists($template_path . '/template.php')) // deprecated require($template_path . '/template.php'); else if($config['backward_support'] && file_exists($template_path . '/layout.php')) { require($template_path . '/layout.php'); } else { // TODO: save more info to log file die('ERROR: Cannot load template.'); } echo '' . "\n"; if(($config['debug_level'] & 1) == 1) echo ''; if(($config['debug_level'] & 2) == 2) echo "\n" . ''; if(($config['debug_level'] & 4) == 4 && function_exists('memory_get_peak_usage')) echo "\n" . ''; $hooks->trigger(HOOK_FINISH); ?> \ No newline at end of file diff --git a/install/includes/schema.sql b/install/includes/schema.sql index 216f58d4..ffe3e1df 100644 --- a/install/includes/schema.sql +++ b/install/includes/schema.sql @@ -60,7 +60,7 @@ CREATE TABLE `myaac_faq` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `question` VARCHAR(255) NOT NULL DEFAULT '', - `answer` VARCHAR(1020) NOT NULL, + `answer` VARCHAR(1020) NOT NULL DEFAULT '', `ordering` INT(11) NOT NULL DEFAULT 0, `hidden` TINYINT(1) NOT NULL DEFAULT 0, PRIMARY KEY (`id`) @@ -105,6 +105,15 @@ CREATE TABLE `myaac_forum` KEY `section` (`section`) ) ENGINE = MyISAM; +CREATE TABLE `myaac_hooks` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(30) NOT NULL DEFAULT '', + `type` INT(2) NOT NULL DEFAULT 0, + `file` VARCHAR(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = MyISAM; + CREATE TABLE `myaac_monsters` ( `hide_creature` tinyint(1) NOT NULL default '0', `name` varchar(255) NOT NULL, @@ -125,7 +134,7 @@ CREATE TABLE `myaac_monsters` ( CREATE TABLE `myaac_movies` ( `id` INT(11) NOT NULL AUTO_INCREMENT, - `title` VARCHAR(50) NOT NULL DEFAULT '', + `title` VARCHAR(100) NOT NULL DEFAULT '', `youtube_id` VARCHAR(20) NOT NULL, `author` VARCHAR(50) NOT NULL DEFAULT '', `ordering` INT(11) NOT NULL DEFAULT 0, diff --git a/install/steps/finish.php b/install/steps/finish.php index 12ee5fd1..8ddb7cf7 100644 --- a/install/steps/finish.php +++ b/install/steps/finish.php @@ -72,6 +72,8 @@ else { $account_db->setCustomField('country', 'us'); if(fieldExist('group_id', 'accounts')) $account_db->setCustomField('group_id', $groups->getHighestId()); + if(fieldExist('type', 'accounts')) + $account_db->setCustomField('type', 5); if(!$player_db->isLoaded()) $player->setAccountId($account_db->getId()); @@ -96,6 +98,9 @@ else { $new_account->setCustomField('country', 'us'); if(fieldExist('group_id', 'accounts')) $new_account->setCustomField('group_id', $groups->getHighestId()); + if(fieldExist('type', 'accounts')) + $new_account->setCustomField('type', 5); + $new_account->logAction('Account created.'); if(!$player_db->isLoaded()) diff --git a/plugins/example.json b/plugins/example.json new file mode 100644 index 00000000..3ba2834a --- /dev/null +++ b/plugins/example.json @@ -0,0 +1,14 @@ +{ + "name": "Example Plugin", + "description": "This is just an example of a Plugin for MyAAC.", + "version": "1.0", + "author": "nobody", + "contact": "nobody@example.org", + "install": "plugins/example/install.php", + "hooks": { + "Example Hook": { + "type": "BEFORE_PAGE", + "file": "plugins/example/before.php" + } + } + } \ No newline at end of file diff --git a/system/events.php b/system/events.php deleted file mode 100644 index 1748eaea..00000000 --- a/system/events.php +++ /dev/null @@ -1,61 +0,0 @@ - - * @copyright 2017 MyAAC - * @version 0.0.6 - * @link http://my-aac.org - */ -defined('MYAAC') or die('Direct access not allowed!'); -class Event -{ - private $_name, $_type, $_callback; - - public function __construct($name, $type, $callback) { - $this->_name = $name; - $this->_type = $type; - $this->_callback = $callback; - } - - public function execute($params) - { - $ret = false; - if(is_callable($this->_callback)) - { - $tmp = $this->_callback; - $ret = $tmp($params); - } - - return $ret; - } - - public function name() {return $this->_name;} - public function type() {return $this->_type;} -} - -class Events -{ - private static $_events = array(); - - public function register($event, $type = '', $callback = null) { - if(!($event instanceof Event)) - $event = new Event($event, $type, $callback); - - self::$_events[$event->type()][] = $event; - } - - public function trigger($type, $params = array()) - { - $ret = true; - if(isset(self::$_events[$type])) - { - foreach(self::$_events[$type] as $name => $event) - $ret = $event->execute($params); - } - - return $ret; - } -} -?> diff --git a/system/functions.php b/system/functions.php index 8bff6e2e..0905fc5e 100644 --- a/system/functions.php +++ b/system/functions.php @@ -598,6 +598,22 @@ function check_name_new_char($name, &$error = '') } } + $player = new OTS_Player(); + $player->find($name); + if($player->isLoaded()) { + $error = 'Player with this name already exist.'; + return false; + } + + //check if was namelocked previously + if(tableExist('player_namelocks') && fieldExist('name', 'player_namelocks')) { + $namelock = $db->query('SELECT `player_id` FROM `player_namelocks` WHERE `name` = ' . $db->quote($name)); + if($namelock->rowCount() > 0) { + $error = 'Character with this name has been namelocked.'; + return false; + } + } + $monsters = $db->query( 'SELECT ' . $db->fieldName('name') . ' FROM ' . $db->tableName(TABLE_PREFIX . 'monsters') . @@ -808,8 +824,8 @@ function template_header($is_admin = false) '; if(admin()) - $ret .= ' - '; if($config['recaptcha_enabled']) @@ -852,18 +868,17 @@ function template_ga_code() if(!isset($config['google_analytics_id'][0])) return ''; - return ' -'; + ga('create', '" . $config['google_analytics_id'] . "', 'auto'); + ga('send', 'pageview'); + +"; } function template_form() diff --git a/system/hooks.php b/system/hooks.php new file mode 100644 index 00000000..8827ea5f --- /dev/null +++ b/system/hooks.php @@ -0,0 +1,92 @@ + + * @copyright 2017 MyAAC + * @version 0.0.6 + * @link http://my-aac.org + */ +defined('MYAAC') or die('Direct access not allowed!'); + +define('HOOK_STARTUP', 1); +define('HOOK_BEFORE_PAGE', 2); +define('HOOK_AFTER_PAGE', 3); +define('HOOK_FINISH', 4); +define('HOOK_TIBIACOM_ARTICLE', 5); +define('HOOK_TIBIACOM_BORDER_3', 6); +define('HOOK_FIRST', HOOK_STARTUP); +define('HOOK_LAST', HOOK_TIBIACOM_BORDER_3); + +$hook_types = array( + 'STARTUP' => HOOK_STARTUP, + 'BEFORE_PAGE' => HOOK_BEFORE_PAGE, + 'AFTER_PAGE' => HOOK_AFTER_PAGE, + 'FINISH' => HOOK_FINISH, + 'TIBIACOM_ARTICLE' => HOOK_TIBIACOM_ARTICLE, + 'TIBIACOM_BORDER_3' => HOOK_TIBIACOM_BORDER_3 +); + +class Hook +{ + private $_name, $_type, $_file; + + public function __construct($name, $type, $file) { + $this->_name = $name; + $this->_type = $type; + $this->_file = $file; + } + + public function execute($params) + { + /*if(is_callable($this->_callback)) + { + $tmp = $this->_callback; + $ret = $tmp($params); + }*/ + + global $db, $config, $template_path, $ots; + if(file_exists(BASE . $this->_file)) { + require(BASE . $this->_file); + } + + return false; + } + + public function name() {return $this->_name;} + public function type() {return $this->_type;} +} + +class Hooks +{ + private static $_hooks = array(); + + public function register($hook, $type = '', $file = null) { + if(!($hook instanceof Hook)) + $hook = new Hook($hook, $type, $file); + + self::$_hooks[$hook->type()][] = $hook; + } + + public function trigger($type, $params = array()) + { + $ret = true; + if(isset(self::$_hooks[$type])) + { + foreach(self::$_hooks[$type] as $name => $hook) + $ret = $hook->execute($params); + } + + return $ret; + } + + public function load() + { + global $db; + $hooks = $db->query('SELECT `name`, `type`, `file` FROM `' . TABLE_PREFIX . 'hooks`;'); + foreach($hooks as $hook) + $this->register($hook['name'], $hook['type'], $hook['file']); + } +} +?> diff --git a/system/libs/pot/OTS_Account.php b/system/libs/pot/OTS_Account.php index 1e7894cd..0d2579e2 100644 --- a/system/libs/pot/OTS_Account.php +++ b/system/libs/pot/OTS_Account.php @@ -187,9 +187,6 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable */ public function find($name) { - if(check_number($name)) - $this->load((int)$name); - // finds player's ID $id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($name) )->fetch(); @@ -311,6 +308,25 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable return $this->data['web_flags']; } + public function hasFlag($flag) + { + if(!isset($this->data['web_flags'])) { + throw new E_OTS_NotLoaded(); + } + + return ($this->data['web_flags'] & $flag) == $flag; + } + + public function isAdmin() + { + return $this->hasFlag(FLAG_ADMIN) || $this->isSuperAdmin(); + } + + public function isSuperAdmin() + { + return $this->hasFlag(FLAG_SUPER_ADMIN); + } + public function getPremDays() { if( !isset($this->data['lastday']) ) diff --git a/system/migrations/1.php b/system/migrations/1.php new file mode 100644 index 00000000..8d12f421 --- /dev/null +++ b/system/migrations/1.php @@ -0,0 +1,16 @@ +query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `ip` INT(11) NOT NULL DEFAULT 0;"); + $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `date` INT(11) NOT NULL DEFAULT 0;"); + $db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` MODIFY `action` VARCHAR(255) NOT NULL DEFAULT '';"); + $db->query(" + CREATE TABLE `myaac_hooks` +( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `name` VARCHAR(30) NOT NULL DEFAULT '', + `type` INT(2) NOT NULL DEFAULT 0, + `file` VARCHAR(100) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = MyISAM; +"); + +?> \ No newline at end of file diff --git a/system/pages/accountmanagement.php b/system/pages/accountmanagement.php index 9d884651..a8c0f391 100644 --- a/system/pages/accountmanagement.php +++ b/system/pages/accountmanagement.php @@ -222,7 +222,21 @@ Please enter your account name and your password.Note: | A request has been submitted to change the email address of this account to '.$account_email_new.'. After '.date("j F Y, G:i:s", $account_email_new_time).' you can accept the new email address and finish the process. Please cancel the request if you do not want your email address to be changed! Also cancel the request if you have no access to the new email address! |
|
|