diff --git a/admin/pages/players.php b/admin/pages/players.php
index 17e8f7d1..c0be81f4 100644
--- a/admin/pages/players.php
+++ b/admin/pages/players.php
@@ -35,6 +35,7 @@ $skills = array(
$hasBlessingsColumn = $db->hasColumn('players', 'blessings');
$hasBlessingColumn = $db->hasColumn('players', 'blessings1');
$hasLookAddons = $db->hasColumn('players', 'lookaddons');
+$hasCapColumn = $db->hasColumn('players', 'cap');
$skull_type = array("None", "Yellow", "Green", "White", "Red", "Black", "Orange");
?>
@@ -167,8 +168,11 @@ else if (isset($_REQUEST['search'])) {
$town = $_POST['town'];
verify_number($town, 'Town', 11);
- $capacity = $_POST['capacity'];
- verify_number($capacity, 'Capacity', 11);
+ if ($hasCapColumn) {
+ $capacity = $_POST['capacity'];
+ verify_number($capacity, 'Capacity', 11);
+ }
+
$sex = $_POST['sex'];
verify_number($sex, 'Sex', 1);
@@ -273,16 +277,20 @@ else if (isset($_REQUEST['search'])) {
$player->setLookHead($look_head);
$player->setLookLegs($look_legs);
$player->setLookType($look_type);
- if ($hasLookAddons)
+ if ($hasLookAddons) {
$player->setLookAddons($look_addons);
- if ($db->hasColumn('players', 'offlinetraining_time'))
- $player->setCustomField('offlinetraining_time', $offlinetraining);
+ }
+
$player->setPosX($pos_x);
$player->setPosY($pos_y);
$player->setPosZ($pos_z);
$player->setSoul($soul);
$player->setTownId($town);
- $player->setCap($capacity);
+
+ if ($hasCapColumn) {
+ $player->setCap($capacity);
+ }
+
$player->setSex($sex);
$player->setLastLogin($lastlogin);
$player->setLastLogout($lastlogout);
@@ -299,23 +307,11 @@ else if (isset($_REQUEST['search'])) {
if ($hasBlessingsColumn)
$player->setBlessings($blessings);
- if ($hasBlessingColumn) {
- for ($i = 1; $i <= $bless_count; $i++) {
- $a = 'blessing' . $i;
- $player->setCustomField('blessings' . $i, ${'blessing' . $i} ? '1' : '0');
- }
- }
$player->setBalance($balance);
if ($db->hasColumn('players', 'stamina'))
$player->setStamina($stamina);
- if ($db->hasColumn('players', 'deletion'))
- $player->setCustomField('deletion', $deleted ? '1' : '0');
- else
- $player->setCustomField('deleted', $deleted ? '1' : '0');
- $player->setCustomField('hide', $hide ? '1' : '0');
- $player->setCustomField('created', $created);
- if (isset($comment))
- $player->setCustomField('comment', $comment);
+
+ $player->setDeleted($deleted ? '1' : '0');
foreach ($_POST['skills'] as $skill => $value) {
$player->setSkill($skill, $value);
@@ -324,6 +320,24 @@ else if (isset($_REQUEST['search'])) {
$player->setSkillTries($skill, $value);
}
$player->save();
+
+ if ($db->hasColumn('players', 'offlinetraining_time')) {
+ $player->setCustomField('offlinetraining_time', $offlinetraining);
+ }
+
+ if ($hasBlessingColumn) {
+ for ($i = 1; $i <= $bless_count; $i++) {
+ $a = 'blessing' . $i;
+ $player->setCustomField('blessings' . $i, ${'blessing' . $i} ? '1' : '0');
+ }
+ }
+
+ $player->setCustomField('hide', $hide ? '1' : '0');
+ $player->setCustomField('created', $created);
+ if (isset($comment)) {
+ $player->setCustomField('comment', $comment);
+ }
+
echo_success('Player saved at: ' . date('G:i'));
$player->load($id);
}
@@ -555,10 +569,12 @@ else if (isset($_REQUEST['search'])) {
+
+
diff --git a/common.php b/common.php
index 9298da3a..0bddea1e 100644
--- a/common.php
+++ b/common.php
@@ -27,7 +27,7 @@ if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is
const MYAAC = true;
const MYAAC_VERSION = '2.0-dev';
-const DATABASE_VERSION = 48;
+const DATABASE_VERSION = 49;
const TABLE_PREFIX = 'myaac_';
define('START_TIME', microtime(true));
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));
diff --git a/install/includes/import_base_data.php b/install/includes/import_base_data.php
index 45c803ed..59bb923e 100644
--- a/install/includes/import_base_data.php
+++ b/install/includes/import_base_data.php
@@ -3,6 +3,7 @@ defined('MYAAC') or die('Direct access not allowed!');
use MyAAC\Models\Changelog;
use MyAAC\Models\Config;
+use MyAAC\Models\FAQ;
use MyAAC\Models\ForumBoard;
use MyAAC\Models\Gallery;
use MyAAC\Models\NewsCategory;
@@ -66,4 +67,11 @@ if (Gallery::count() === 0) {
]);
}
+if(FAQ::count() == 0) {
+ FAQ::create([
+ 'question' => 'What is this?',
+ 'answer' => 'This is website for OTS powered by MyAAC.',
+ ]);
+}
+
success($locale['step_database_success_import_data']);
diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php
index 9c64382b..2b429e37 100644
--- a/install/tools/7-finish.php
+++ b/install/tools/7-finish.php
@@ -2,8 +2,6 @@
define('MYAAC_INSTALL', true);
use MyAAC\DataLoader;
-use MyAAC\Models\FAQ as ModelsFAQ;
-use MyAAC\Plugins;
require_once '../../common.php';
@@ -25,34 +23,9 @@ if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['save
require SYSTEM . 'init.php';
-if ($db->hasTable('players')) {
- $deleted = 'deleted';
- if ($db->hasColumn('players', 'deletion'))
- $deleted = 'deletion';
-
- $time = time();
- function insert_sample_if_not_exist($p)
- {
- global $db, $success, $deleted, $time;
-
- $query = $db->query('SELECT `id` FROM `players` WHERE `name` = ' . $db->quote($p['name']));
- if ($query->rowCount() == 0) {
- if (!query("INSERT INTO `players` (`id`, `name`, `group_id`, `account_id`, `level`, `vocation`, `health`, `healthmax`, `experience`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`, `maglevel`, `mana`, `manamax`, `manaspent`, `soul`, `town_id`, `posx`, `posy`, `posz`, `conditions`, `cap`, `sex`, `lastlogin`, `lastip`, `save`, `lastlogout`, `balance`, `$deleted`, `created`, `hide`, `comment`) VALUES (null, " . $db->quote($p['name']) . ", 1, " . getSession('account') . ", " . $p['level'] . ", " . $p['vocation_id'] . ", " . $p['health'] . ", " . $p['healthmax'] . ", " . $p['experience'] . ", 118, 114, 38, 57, " . $p['looktype'] . ", 0, " . $p['mana'] . ", " . $p['manamax'] . ", 0, " . $p['soul'] . ", 1, 1000, 1000, 7, '', " . $p['cap'] . ", 1, " . $time . ", 2130706433, 1, " . $time . ", 0, 0, " . $time . ", 1, '');"))
- $success = false;
- }
- }
-
- $success = true;
- insert_sample_if_not_exist(array('name' => 'Rook Sample', 'level' => 1, 'vocation_id' => 0, 'health' => 150, 'healthmax' => 150, 'experience' => 0, 'looktype' => 130, 'mana' => 0, 'manamax' => 0, 'soul' => 100, 'cap' => 400));
- insert_sample_if_not_exist(array('name' => 'Sorcerer Sample', 'level' => 8, 'vocation_id' => 1, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 130, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470));
- insert_sample_if_not_exist(array('name' => 'Druid Sample', 'level' => 8, 'vocation_id' => 2, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 130, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470));
- insert_sample_if_not_exist(array('name' => 'Paladin Sample', 'level' => 8, 'vocation_id' => 3, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 129, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470));
- insert_sample_if_not_exist(array('name' => 'Knight Sample', 'level' => 8, 'vocation_id' => 4, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 131, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470));
-
- if ($success) {
- success($locale['step_database_imported_players']);
- }
-}
+// add player samples
+require_once SYSTEM . 'migrations/49.php';
+$up();
DataLoader::setLocale($locale);
DataLoader::load();
@@ -61,10 +34,6 @@ DataLoader::load();
require_once SYSTEM . 'migrations/17.php';
$up();
-// update config.highscores_ids_hidden
-require_once SYSTEM . 'migrations/20.php';
-$up();
-
// add z_polls tables
require_once SYSTEM . 'migrations/22.php';
$up();
@@ -83,13 +52,6 @@ $up();
require_once SYSTEM . 'migrations/45.php';
$up();
-if(ModelsFAQ::count() == 0) {
- ModelsFAQ::create([
- 'question' => 'What is this?',
- 'answer' => 'This is website for OTS powered by MyAAC.',
- ]);
-}
-
$hooks->trigger(HOOK_INSTALL_FINISH);
$db->setClearCacheAfter(true);
diff --git a/system/libs/pot/OTS_Player.php b/system/libs/pot/OTS_Player.php
index fbd77aac..c4befcd4 100644
--- a/system/libs/pot/OTS_Player.php
+++ b/system/libs/pot/OTS_Player.php
@@ -1,20 +1,6 @@
NULL,
- 'loss_items' => NULL,
- 'guild_info' => NULL,
- 'skull_type' => NULL,
- 'skull_time' => NULL,
- 'blessings' => NULL,
- 'direction' => NULL,
- 'stamina' => NULL,
- 'world_id' => NULL,
- 'online' => NULL,
- 'deletion' => NULL,
- 'promotion' => NULL,
- 'marriage' => NULL
-);*/
+
+use MyAAC\Models\Player as PlayerModel;
/**#@+
* @version 0.0.1
@@ -109,6 +95,10 @@ class OTS_Player extends OTS_Row_DAO
POT::SKILL_FISH => array('value' => 0, 'tries' => 0)
);
+ private array $columns = ['name', 'account_id', 'group_id', 'sex', 'vocation', 'experience', 'level', 'maglevel', 'health', 'healthmax', 'mana', 'manamax', 'manaspent', 'soul', 'lookbody', 'lookfeet', 'lookhead', 'looklegs', 'looktype', 'posx', 'posy', 'posz', 'lastlogin', 'lastlogout', 'lastip', 'town_id', 'balance', 'created', 'comment', 'hide'];
+
+ private array $optionalColumns = ['cap', 'skull', 'skull_type', 'skull_time', 'loss_experience', 'loss_mana', 'loss_skills', 'loss_items', 'loss_containers', 'guildnick', 'rank_id', 'promotion', 'direction', 'blessings', 'stamina', 'lookaddons', 'save', 'conditions', 'world_id', 'online', 'deletion', 'deleted', 'marriage'];
+
private static array $playersOnline;
/**
* Magic PHP5 method.
@@ -133,90 +123,14 @@ class OTS_Player extends OTS_Row_DAO
*/
public function load($id, $fields = null, $load_skills = true)
{
- global $__load;
-
- if(!isset($__load['loss_experience']))
- {
- $loss = '';
- if($this->db->hasColumn('players', 'loss_experience')) {
- $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
+ $columns = $this->columns;
+ foreach ($this->optionalColumns as $column) {
+ if ($this->db->hasColumn('players', $column)) {
+ $columns[] = $column;
}
-
- $__load['loss_experience'] = $loss;
- }
-
- if(!isset($__load['loss_items']))
- {
- $loss_items = '';
- if($this->db->hasColumn('players', 'loss_items')) {
- $loss_items = ', `loss_items`, `loss_containers`';
- }
-
- $__load['loss_items'] = $loss_items;
- }
-
- if(!isset($__load['guild_info']))
- {
- $guild_info = '';
- if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
- $guild_info = ', `guildnick`, `rank_id`';
- }
-
- $__load['guild_info'] = $guild_info;
- }
-
- if(!isset($__load['skull_type']))
- {
- $skull_type = 'skull';
- if($this->db->hasColumn('players', 'skull_type')) {
- $skull_type = 'skull_type';
- }
-
- $__load['skull_type'] = $skull_type;
- }
-
- if(!isset($__load['skull_time']))
- {
- $skull_time = 'skulltime';
- if($this->db->hasColumn('players', 'skull_time')) {
- $skull_time = 'skull_time';
- }
-
- $__load['skull_time'] = $skull_time;
- }
-
- if(!isset($__load['blessings'])) {
- $__load['blessings'] = $this->db->hasColumn('players', 'blessings');
- }
- if(!isset($__load['direction'])) {
- $__load['direction'] = $this->db->hasColumn('players', 'direction');
- }
- if(!isset($__load['stamina'])) {
- $__load['stamina'] = $this->db->hasColumn('players', 'stamina');
- }
- if(!isset($__load['world_id'])) {
- $__load['world_id'] = $this->db->hasColumn('players', 'world_id');
- }
- if(!isset($__load['online'])) {
- $__load['online'] = $this->db->hasColumn('players', 'online');
- }
- if(!isset($__load['deletion'])) {
- $__load['deletion'] = $this->db->hasColumn('players', 'deletion');
- }
- if(!isset($__load['promotion'])) {
- $__load['promotion'] = $this->db->hasColumn('players', 'promotion');
- }
- if(!isset($__load['marriage'])) {
- $__load['marriage'] = $this->db->hasColumn('players', 'marriage');
}
if(isset($fields)) { // load only what we wish
- if(in_array('promotion', $fields)) {
- if(!$this->db->hasColumn('players', 'promotion')) {
- unset($fields[array_search('promotion', $fields)]);
- }
- }
-
if(in_array('deleted', $fields)) {
if($this->db->hasColumn('players', 'deletion')) {
unset($fields[array_search('deleted', $fields)]);
@@ -224,21 +138,21 @@ class OTS_Player extends OTS_Row_DAO
}
}
- if(in_array('online', $fields)) {
- if(!$this->db->hasColumn('players', 'online')) {
- unset($fields[array_search('online', $fields)]);
+ $columns = [];
+ foreach ($fields as $field) {
+ if ($this->db->hasColumn('players', $field)) {
+ $columns[] = $field;
}
}
- $this->data = $this->db->query('SELECT ' . implode(', ', $fields) . ' FROM `players` WHERE `id` = ' . (int)$id)->fetch();
- }
- else {
- // SELECT query on database
- $this->data = $this->db->query('SELECT `id`, `name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . ($this->db->hasColumn('players', 'lookaddons') ? ', `lookaddons`' : '') . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $__load['skull_time'] . '` as `skulltime`, `' . $__load['skull_type'] . '` as `skull`' . $__load['guild_info'] . ', `town_id`' . $__load['loss_experience'] . $__load['loss_items'] . ', `balance`' . ($__load['blessings'] ? ', `blessings`' : '') . ($__load['direction'] ? ', `direction`' : '') . ($__load['stamina'] ? ', `stamina`' : '') . ($__load['world_id'] ? ', `world_id`' : '') . ($__load['online'] ? ', `online`' : '') . ', `' . ($__load['deletion'] ? 'deletion' : 'deleted') . '`' . ($__load['promotion'] ? ', `promotion`' : '') . ($__load['marriage'] ? ', `marriage`' : '') . ', `comment`, `created`, `hide` FROM `players` WHERE `id` = ' . (int)$id)->fetch();
}
+ array_unshift($columns, 'id');
+
+ $query = PlayerModel::where('id', $id)->first($columns);
+ $this->data = $query ? $query->toArray() : [];
+
// loads skills
- if( $this->isLoaded() && $load_skills)
- {
+ if( $this->isLoaded() && $load_skills) {
if($this->db->hasColumn('players', 'skill_fist')) {
$skill_ids = array(
@@ -318,153 +232,65 @@ class OTS_Player extends OTS_Row_DAO
*/
public function save()
{
- $skull_type = 'skull';
- if($this->db->hasColumn('players', 'skull_type')) {
- $skull_type = 'skull_type';
+ $defaultValues = [
+ 'cap' => 0,
+ 'skull' => 0,
+ 'skull_type' => 0,
+ 'skull_time' => 0,
+ 'loss_experience' => 100,
+ 'loss_mana' => 100,
+ 'loss_skills' => 100,
+ 'loss_items' => 100,
+ 'loss_containers' => 100,
+ 'guildnick' => '',
+ 'rank_id' => 0,
+ 'promotion' => 0,
+ 'direction' => 0,
+ 'blessings' => 0,
+ 'stamina' => 0,
+ 'lookaddons' => 0,
+ 'save' => 1,
+ 'conditions' => '',
+ 'town_id' => 1,
+ 'world_id' => 1,
+ 'online' => 0,
+ 'deletion' => 0,
+ 'deleted' => 0,
+ 'marriage' => 0,
+ ];
+
+ foreach ($defaultValues as $key => $value) {
+ if (!isset($this->data[$key])) {
+ $this->data[$key] = $value;
+ }
}
- $skull_time = 'skulltime';
- if($this->db->hasColumn('players', 'skull_time')) {
- $skull_time = 'skull_time';
+ $columns = $this->columns;
+ foreach ($this->optionalColumns as $column) {
+ if ($this->db->hasColumn('players', $column)) {
+ $columns[] = $column;
+ }
}
- if(!isset($this->data['loss_experience']))
- $this->data['loss_experience'] = 100;
+ $values = [];
+ foreach ($columns as $column) {
+ $value = $this->data[$column];
- if(!isset($this->data['loss_mana']))
- $this->data['loss_mana'] = 100;
-
- if(!isset($this->data['loss_skills']))
- $this->data['loss_skills'] = 100;
-
- if(!isset($this->data['loss_items']))
- $this->data['loss_items'] = 10;
-
- if(!isset($this->data['loss_containers']))
- $this->data['loss_containers'] = 100;
-
- if(!isset($this->data['guildnick']))
- $this->data['guildnick'] = '';
-
- if(!isset($this->data['rank_id']))
- $this->data['rank_id'] = 0;
-
- if(!isset($this->data['promotion']))
- $this->data['promotion'] = 0;
-
- if(!isset($this->data['direction']))
- $this->data['direction'] = 0;
-
- if(!isset($this->data['conditions']))
- $this->data['conditions'] = '';
-
- if(!isset($this->data['town_id']))
- $this->data['town_id'] = 1;
+ $values[$column] = $value;
+ }
// updates existing player
- if( isset($this->data['id']) )
- {
- $loss = '';
- if($this->db->hasColumn('players', 'loss_experience')) {
- $loss = ', `loss_experience` = ' . $this->data['loss_experience'] . ', `loss_mana` = ' . $this->data['loss_mana'] . ', `loss_skills` = ' . $this->data['loss_skills'];
- }
-
- $loss_items = '';
- if($this->db->hasColumn('players', 'loss_items')) {
- $loss_items = ', `loss_items` = ' . $this->data['loss_items'] . ', `loss_containers` = ' . $this->data['loss_containers'];
- }
-
- $guild_info = '';
- if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
- $guild_info = ', `guildnick` = ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->db->fieldName('rank_id') . ' = ' . $this->data['rank_id'];
- }
-
- $direction = '';
- if($this->db->hasColumn('players', 'direction')) {
- $direction = ', `direction` = ' . $this->db->quote($this->data['direction']);
- }
-
- $blessings = '';
- if($this->db->hasColumn('players', 'blessings')) {
- $blessings = ', `blessings` = ' . $this->db->quote($this->data['blessings']);
- }
-
- $stamina = '';
- if($this->db->hasColumn('players', 'stamina')) {
- $stamina = ', `stamina` = ' . $this->db->quote($this->data['stamina']);
- }
-
- $lookaddons = '';
- if($this->db->hasColumn('players', 'lookaddons')) {
- $lookaddons = ', `lookaddons` = ' . $this->db->quote($this->data['lookaddons']);
- }
-
- // UPDATE query on database
- $this->db->query('UPDATE ' . $this->db->tableName('players') . ' SET ' . $this->db->fieldName('name') . ' = ' . $this->db->quote($this->data['name']) . ', ' . $this->db->fieldName('account_id') . ' = ' . $this->data['account_id'] . ', ' . $this->db->fieldName('group_id') . ' = ' . $this->data['group_id'] . ', ' . $this->db->fieldName('sex') . ' = ' . $this->data['sex'] . ', ' . $this->db->fieldName('vocation') . ' = ' . $this->data['vocation'] . ', ' . $this->db->fieldName('experience') . ' = ' . $this->data['experience'] . ', ' . $this->db->fieldName('level') . ' = ' . $this->data['level'] . ', ' . $this->db->fieldName('maglevel') . ' = ' . $this->data['maglevel'] . ', ' . $this->db->fieldName('health') . ' = ' . $this->data['health'] . ', ' . $this->db->fieldName('healthmax') . ' = ' . $this->data['healthmax'] . ', ' . $this->db->fieldName('mana') . ' = ' . $this->data['mana'] . ', ' . $this->db->fieldName('manamax') . ' = ' . $this->data['manamax'] . ', ' . $this->db->fieldName('manaspent') . ' = ' . $this->data['manaspent'] . ', ' . $this->db->fieldName('soul') . ' = ' . $this->data['soul'] . ', ' . $this->db->fieldName('lookbody') . ' = ' . $this->data['lookbody'] . ', ' . $this->db->fieldName('lookfeet') . ' = ' . $this->data['lookfeet'] . ', ' . $this->db->fieldName('lookhead') . ' = ' . $this->data['lookhead'] . ', ' . $this->db->fieldName('looklegs') . ' = ' . $this->data['looklegs'] . ', ' . $this->db->fieldName('looktype') . ' = ' . $this->data['looktype'] . $lookaddons . ', ' . $this->db->fieldName('posx') . ' = ' . $this->data['posx'] . ', ' . $this->db->fieldName('posy') . ' = ' . $this->data['posy'] . ', ' . $this->db->fieldName('posz') . ' = ' . $this->data['posz'] . ', ' . $this->db->fieldName('cap') . ' = ' . $this->data['cap'] . ', ' . $this->db->fieldName('lastlogin') . ' = ' . $this->data['lastlogin'] . ', ' . $this->db->fieldName('lastlogout') . ' = ' . $this->data['lastlogout'] . ', ' . $this->db->fieldName('lastip') . ' = ' . $this->db->quote($this->data['lastip']) . ', ' . $this->db->fieldName('save') . ' = ' . (int) $this->data['save'] . ', ' . $this->db->fieldName('conditions') . ' = ' . $this->db->quote($this->data['conditions']) . ', `' . $skull_time . '` = ' . $this->data['skulltime'] . ', `' . $skull_type . '` = ' . (int) $this->data['skull'] . $guild_info . ', ' . $this->db->fieldName('town_id') . ' = ' . $this->data['town_id'] . $loss . $loss_items . ', ' . $this->db->fieldName('balance') . ' = ' . $this->data['balance'] . $blessings . $stamina . $direction . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
+ if( isset($this->data['id']) ) {
+ PlayerModel::where('id', $this->data['id'])->update($values);
}
// creates new player
- else
- {
- $loss = '';
- $loss_data = '';
- if($this->db->hasColumn('players', 'loss_experience')) {
- $loss = ', `loss_experience`, `loss_mana`, `loss_skills`';
- $loss_data = ', ' . $this->data['loss_experience'] . ', ' . $this->data['loss_mana'] . ', ' . $this->data['loss_skills'];
- }
+ else {
+ $values['created'] = time();
- $loss_items = '';
- $loss_items_data = '';
- if($this->db->hasColumn('players', 'loss_items')) {
- $loss_items = ', `loss_items`, `loss_containers`';
- $loss_items_data = ', ' . $this->data['loss_items'] . ', ' . $this->data['loss_containers'];
- }
+ $player = PlayerModel::create($values);
- $guild_info = '';
- $guild_info_data = '';
- if(!$this->db->hasTable('guild_members') && $this->db->hasColumn('players', 'guildnick')) {
- $guild_info = ', `guildnick`, `rank_id`';
- $guild_info_data = ', ' . $this->db->quote($this->data['guildnick']) . ', ' . $this->data['rank_id'];
- }
-
- $promotion = '';
- $promotion_data = '';
- if($this->db->hasColumn('players', 'promotion')) {
- $promotion = ', `promotion`';
- $promotion_data = ', ' . $this->data['promotion'];
- }
-
- $direction = '';
- $direction_data = '';
- if($this->db->hasColumn('players', 'direction')) {
- $direction = ', `direction`';
- $direction_data = ', ' . $this->data['direction'];
- }
-
- $blessings = '';
- $blessings_data = '';
- if($this->db->hasColumn('players', 'blessings')) {
- $blessings = ', `blessings`';
- $blessings_data = ', ' . $this->data['blessings'];
- }
-
- $stamina = '';
- $stamina_data = '';
- if($this->db->hasColumn('players', 'stamina')) {
- $stamina = ', `stamina`';
- $stamina_data = ', ' . $this->data['stamina'];
- }
-
- $lookaddons = '';
- $lookaddons_data = '';
- if($this->db->hasColumn('players', 'lookaddons')) {
- $lookaddons = ', `lookaddons`';
- $lookaddons_data = ', ' . $this->data['lookaddons'];
- }
-
- // INSERT query on database
- $this->db->query('INSERT INTO `players` (`name`, `account_id`, `group_id`, `sex`, `vocation`, `experience`, `level`, `maglevel`, `health`, `healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `lookbody`, `lookfeet`, `lookhead`, `looklegs`, `looktype`' . $lookaddons . ', `posx`, `posy`, `posz`, `cap`, `lastlogin`, `lastlogout`, `lastip`, `save`, `conditions`, `' . $skull_time . '`, `' . $skull_type . '`' . $guild_info . ', `town_id`' . $loss . $loss_items . ', `balance`' . $blessings . $stamina . $direction . ', `created`' . $promotion . ', `comment`) VALUES (' . $this->db->quote($this->data['name']) . ', ' . $this->data['account_id'] . ', ' . $this->data['group_id'] . ', ' . $this->data['sex'] . ', ' . $this->data['vocation'] . ', ' . $this->data['experience'] . ', ' . $this->data['level'] . ', ' . $this->data['maglevel'] . ', ' . $this->data['health'] . ', ' . $this->data['healthmax'] . ', ' . $this->data['mana'] . ', ' . $this->data['manamax'] . ', ' . $this->data['manaspent'] . ', ' . $this->data['soul'] . ', ' . $this->data['lookbody'] . ', ' . $this->data['lookfeet'] . ', ' . $this->data['lookhead'] . ', ' . $this->data['looklegs'] . ', ' . $this->data['looktype'] . $lookaddons_data . ', ' . $this->data['posx'] . ', ' . $this->data['posy'] . ', ' . $this->data['posz'] . ', ' . $this->data['cap'] . ', ' . $this->data['lastlogin'] . ', ' . $this->data['lastlogout'] . ', ' . $this->data['lastip'] . ', ' . (int) $this->data['save'] . ', ' . $this->db->quote($this->data['conditions']) . ', ' . $this->data['skulltime'] . ', ' . (int) $this->data['skull'] . $guild_info_data . ', ' . $this->data['town_id'] . $loss_data . $loss_items_data . ', ' . $this->data['balance'] . $blessings_data . $stamina_data . $direction_data . ', ' . time() . $promotion_data . ', "")');
- // ID of new group
- $this->data['id'] = $this->db->lastInsertId();
+ // ID of new player
+ $this->data['id'] = $player->id;
}
// updates skills - doesn't matter if we have just created character - trigger inserts new skills
@@ -490,7 +316,7 @@ class OTS_Player extends OTS_Row_DAO
$set .= ',';
}
- $skills = $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
+ $this->db->query('UPDATE `players` SET ' . $set . ' WHERE `id` = ' . $this->data['id']);
}
else if($this->db->hasTable('player_skills')) {
foreach($this->skills as $id => $skill)
@@ -748,21 +574,25 @@ class OTS_Player extends OTS_Row_DAO
public function isDeleted()
{
- $field = 'deleted';
+ $column = 'deleted';
if($this->db->hasColumn('players', 'deletion'))
- $field = 'deletion';
+ $column = 'deletion';
- if( !isset($this->data[$field]) )
+ if( !isset($this->data[$column]) )
{
throw new E_OTS_NotLoaded();
}
- return $this->data[$field] > 0;
+ return $this->data[$column] > 0;
}
public function setDeleted($deleted)
{
- $this->data['deleted'] = (int) $deleted;
+ $column = 'deleted';
+ if($this->db->hasColumn('players', 'deletion'))
+ $column = 'deletion';
+
+ $this->data[$column] = (int) $deleted;
}
public function isOnline()
@@ -1568,12 +1398,7 @@ class OTS_Player extends OTS_Row_DAO
*/
public function getCap()
{
- if( !isset($this->data['cap']) )
- {
- throw new E_OTS_NotLoaded();
- }
-
- return $this->data['cap'];
+ return $this->data['cap'] ?? 0;
}
/**
@@ -1786,12 +1611,12 @@ class OTS_Player extends OTS_Row_DAO
*/
public function getSkullTime()
{
- if( !isset($this->data['skulltime']) )
- {
- throw new E_OTS_NotLoaded();
+ $column = 'skulltime';
+ if($this->db->hasColumn('players', 'skull_time')) {
+ $column = 'skull_time';
}
- return $this->data['skulltime'];
+ return $this->data[$column] ?? 0;
}
/**
@@ -1805,7 +1630,12 @@ class OTS_Player extends OTS_Row_DAO
*/
public function setSkullTime($skulltime)
{
- $this->data['skulltime'] = (int) $skulltime;
+ $column = 'skulltime';
+ if($this->db->hasColumn('players', 'skull_time')) {
+ $column = 'skull_time';
+ }
+
+ $this->data[$column] = (int) $skulltime;
}
/**
@@ -3244,6 +3074,10 @@ class OTS_Player extends OTS_Row_DAO
return 0;
}
+ public function setData(array $data): void{
+ $this->data = $data;
+ }
+
/**
* Magic PHP5 method.
*
diff --git a/system/migrations/20.php b/system/migrations/20.php
index ccc20a51..b1166bbd 100644
--- a/system/migrations/20.php
+++ b/system/migrations/20.php
@@ -1,5 +1,6 @@
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`;");
+ $players = PlayerModel::where('name', 'Rook Sample')
+ ->orWhere('name', 'Sorcerer Sample')
+ ->orWhere('name', 'Druid Sample')
+ ->orWhere('name', 'Paladin Sample')
+ ->orWhere('name', 'Knight Sample')
+ ->orWhere('name', 'Monk Sample')
+ ->orWhere('name', 'Account Manager')
+ ->orderBy('id')
+ ->select('id')
+ ->get();
- $highscores_ignored_ids = array();
- if ($query->rowCount() > 0) {
- foreach ($query->fetchAll() as $result)
- $highscores_ignored_ids[] = $result['id'];
+ $highscores_ignored_ids = [];
+ if (count($players) > 0) {
+ foreach ($players as $result) {
+ $highscores_ignored_ids[] = $result->id;
+ }
} else {
$highscores_ignored_ids[] = 0;
}
diff --git a/system/migrations/49.php b/system/migrations/49.php
new file mode 100644
index 00000000..1cc57c05
--- /dev/null
+++ b/system/migrations/49.php
@@ -0,0 +1,81 @@
+find($p['name']);
+
+ if (!$player->isLoaded()) {
+
+ $player->setData([
+ 'name' => $p['name'],
+ 'group_id' => 1,
+ 'account_id' => getSession('account'),
+ 'level' => $p['level'],
+ 'vocation' => $p['vocation_id'],
+ 'health' => $p['health'],
+ 'healthmax' => $p['healthmax'],
+ 'experience' => $p['experience'],
+ 'lookbody' => 118,
+ 'lookfeet' => 114,
+ 'lookhead' => 38,
+ 'looklegs' => 57,
+ 'looktype' => $p['looktype'],
+ 'maglevel' => 0,
+ 'mana' => $p['mana'],
+ 'manamax' => $p['manamax'],
+ 'manaspent' => 0,
+ 'soul' => $p['soul'],
+ 'town_id' => 1,
+ 'posx' => 1000,
+ 'posy' => 1000,
+ 'posz' => 7,
+ 'conditions' => '',
+ 'cap' => $p['cap'],
+ 'sex' => 1,
+ 'lastlogin' => $time,
+ 'lastip' => 2130706433,
+ 'save' => 1,
+ 'lastlogout' => $time,
+ 'balance' => 0,
+ 'created' => $time,
+ 'hide' => 1,
+ 'comment' => '',
+ ]);
+
+ $player->save();
+ }
+}
+
+$up = function () use ($db) {
+ if (!$db->hasTable('players')) {
+ return;
+ }
+
+ insert_sample_if_not_exist(['name' => 'Rook Sample', 'level' => 1, 'vocation_id' => 0, 'health' => 150, 'healthmax' => 150, 'experience' => 0, 'looktype' => 130, 'mana' => 0, 'manamax' => 0, 'soul' => 100, 'cap' => 400]);
+ insert_sample_if_not_exist(['name' => 'Sorcerer Sample', 'level' => 8, 'vocation_id' => 1, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 130, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470]);
+ insert_sample_if_not_exist(['name' => 'Druid Sample', 'level' => 8, 'vocation_id' => 2, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 130, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470]);
+ insert_sample_if_not_exist(['name' => 'Paladin Sample', 'level' => 8, 'vocation_id' => 3, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 129, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470]);
+ insert_sample_if_not_exist(['name' => 'Knight Sample', 'level' => 8, 'vocation_id' => 4, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 131, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470]);
+ insert_sample_if_not_exist(['name' => 'Monk Sample', 'level' => 8, 'vocation_id' => 9, 'health' => 185, 'healthmax' => 185, 'experience' => 4200, 'looktype' => 128, 'mana' => 90, 'manamax' => 90, 'soul' => 100, 'cap' => 470]);
+
+ if (defined('MYAAC_INSTALL')) {
+ global $locale;
+
+ success($locale['step_database_imported_players']);
+ }
+
+ require_once __DIR__ . '/20.php';
+ updateHighscoresIdsHidden();
+};
+
+$down = function () {
+ // nothing
+};
diff --git a/system/src/CreateCharacter.php b/system/src/CreateCharacter.php
index 594eda9d..86a81696 100644
--- a/system/src/CreateCharacter.php
+++ b/system/src/CreateCharacter.php
@@ -149,7 +149,10 @@ class CreateCharacter
if($db->hasColumn('players', 'direction'))
$player->setDirection($playerSample->getDirection());
- $player->setConditions($playerSample->getConditions());
+ if($db->hasColumn('players', 'conditions')) {
+ $player->setConditions($playerSample->getConditions());
+ }
+
$rank = $playerSample->getRank();
if($rank->isLoaded()) {
$player->setRank($playerSample->getRank());
@@ -183,7 +186,11 @@ class CreateCharacter
$player->setLookHead($playerSample->getLookHead());
$player->setLookLegs($playerSample->getLookLegs());
$player->setLookType($playerSample->getLookType());
- $player->setCap($playerSample->getCap());
+
+ if($db->hasColumn('players', 'cap')) {
+ $player->setCap($playerSample->getCap());
+ }
+
$player->setBalance(0);
$player->setPosX(0);
$player->setPosY(0);
diff --git a/system/src/Models/Player.php b/system/src/Models/Player.php
index 479967c8..949b07a7 100644
--- a/system/src/Models/Player.php
+++ b/system/src/Models/Player.php
@@ -23,6 +23,8 @@ class Player extends Model {
public $timestamps = false;
+ protected $guarded = [];
+
protected $casts = [
'worldid' => 'integer',
'sex' => 'integer',