Рефакторинг, очистка, работа над ошибками, связанными с базой, отказ от глобальной переменной $user во многих файлах.
Singleton в некоторых местах вместо решения #42. Новые шаги для решения #16 и #52. Closes #42. Closes #32. Closes #31.
This commit is contained in:
+26
-26
@@ -6,59 +6,59 @@
|
||||
* One file to rule 'em all!
|
||||
*/
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
use Battles\Database\Db;
|
||||
use Battles\Template;
|
||||
use Battles\User;
|
||||
|
||||
require_once 'functions.php';
|
||||
if (!empty($_GET['teleport']) && $user->getAdmin() == 1) {
|
||||
DBPDO::$db->execute('update users, online set users.room = 20, online.room = 20 where user_id = id and user_id = ?', User::$current->getId());
|
||||
if (!empty($_GET['teleport']) && User::getInstance()->getAdmin() == 1) {
|
||||
Db::getInstance()->execute('update users, online set users.room = 20, online.room = 20 where user_id = id and user_id = ?', User::getInstance()->getId());
|
||||
}
|
||||
|
||||
# ORDEN PHP
|
||||
$_POST['use'] ??= null;
|
||||
if ($user->getAdmin()) {
|
||||
$abil = DBPDO::$db->fetch('SELECT 1 FROM users WHERE id = ?i', $user->getId());
|
||||
if (User::getInstance()->getAdmin()) {
|
||||
$abil = Db::getInstance()->execute('SELECT 1 FROM users WHERE id = ?i', User::getInstance()->getId())->fetchColumn();
|
||||
//$abil = unserialize($abil['abil']);
|
||||
switch ($_POST['use']) {
|
||||
case "healing":
|
||||
include("./magic/Healing.php");
|
||||
break;
|
||||
case "ct1":
|
||||
if ($abil[0] > 0 && $user->getAlign() == 6) {
|
||||
if ($abil[0] > 0 && User::getInstance()->getAlign() == 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct1.php");
|
||||
if ($outok == 1) {
|
||||
$abil[0] -= 1;
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), $user->getId());
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), User::getInstance()->getId());
|
||||
}
|
||||
} elseif ($user->getAlign() != 6) {
|
||||
} elseif (User::getInstance()->getAlign() != 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct1.php");
|
||||
}
|
||||
break;
|
||||
case "ct2":
|
||||
if ($abil[1] > 0 && $user->getAlign() == 6) {
|
||||
if ($abil[1] > 0 && User::getInstance()->getAlign() == 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct2.php");
|
||||
if ($outok == 1) {
|
||||
$abil[1] -= 1;
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), $user->getId());
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), User::getInstance()->getId());
|
||||
}
|
||||
} elseif ($user->getAlign() != 6) {
|
||||
} elseif (User::getInstance()->getAlign() != 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct2.php");
|
||||
}
|
||||
break;
|
||||
case "ct3":
|
||||
if ($abil[2] > 0 && $user->getAlign() == 6) {
|
||||
if ($abil[2] > 0 && User::getInstance()->getAlign() == 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct3.php");
|
||||
if ($outok == 1) {
|
||||
$abil[2] -= 1;
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), $user->getId());
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), User::getInstance()->getId());
|
||||
}
|
||||
} elseif ($user->getAlign() != 6) {
|
||||
} elseif (User::getInstance()->getAlign() != 6) {
|
||||
//Заменён на CureInjury.php class. Придумать вызов.
|
||||
//include("./magic/ct3.php");
|
||||
}
|
||||
@@ -82,11 +82,11 @@ if ($user->getAdmin()) {
|
||||
break;
|
||||
|
||||
case "attackk_close":
|
||||
if ($abil[1] > 0 && $user->getAlign() == 2) {
|
||||
if ($abil[1] > 0 && User::getInstance()->getAlign() == 2) {
|
||||
include("./magic/attackk_close.php");
|
||||
if ($outok == 1) {
|
||||
$abil[1] -= 1;
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), $user->getId());
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), User::getInstance()->getId());
|
||||
header("Location:fbattle.php");
|
||||
exit();
|
||||
}
|
||||
@@ -98,11 +98,11 @@ if ($user->getAdmin()) {
|
||||
break;
|
||||
|
||||
case "attackk_open":
|
||||
if ($abil[1] > 0 && $user->getAlign() == 2) {
|
||||
if ($abil[1] > 0 && User::getInstance()->getAlign() == 2) {
|
||||
include("./magic/attackk_open.php");
|
||||
if ($outok == 1) {
|
||||
$abil[2] -= 1;
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), $user->getId());
|
||||
db::c()->query('UPDATE users SET abil = "?s" WHERE id = ?i', serialize($abil), User::getInstance()->getId());
|
||||
header("Location:fbattle.php");
|
||||
exit();
|
||||
}
|
||||
@@ -175,9 +175,9 @@ function show_byu($type)
|
||||
34 => 'mirror',
|
||||
35 => 'antimirror',
|
||||
];
|
||||
if ($user->getClan()) {
|
||||
$clan = db::c()->query('SELECT owner_id FROM clans WHERE short_name = "?s"', $user->getClan())->fetch_assoc();
|
||||
if ($clan['owner_id'] == $user->getId()) {
|
||||
if (User::getInstance()->getClan()) {
|
||||
$clan = db::c()->query('SELECT owner_id FROM clans WHERE short_name = "?s"', User::getInstance()->getClan())->fetch_assoc();
|
||||
if ($clan['owner_id'] == User::getInstance()->getId()) {
|
||||
$r = '<div style="text-align: center;"><a href="javascript:void(0);" class="byu_klan" id="' . $type . '">купить 1 шт.</a></div>';
|
||||
} else {
|
||||
$r = '<div style="text-align: center;"><a href="javascript:void(0);">Вы не глава</a></div>';
|
||||
@@ -216,7 +216,7 @@ echo <<<RELICTS
|
||||
<button disabled>clone</button>
|
||||
<button disabled>unclone</button>
|
||||
RELICTS;
|
||||
if ($user->getAdmin()) {
|
||||
if (User::getInstance()->getAdmin()) {
|
||||
echo <<<A
|
||||
<button onclick="location.href='?teleport=1'">Телепорт на ЦП</button>
|
||||
A;
|
||||
@@ -229,7 +229,7 @@ A;
|
||||
<div style="text-align: center;" id=hint3></div>
|
||||
<div>
|
||||
<?php
|
||||
if ($user->getAlign() == 2 || $user->getAdmin()) // Нейтралы
|
||||
if (User::getInstance()->getAlign() == 2 || User::getInstance()->getAdmin()) // Нейтралы
|
||||
{
|
||||
|
||||
$abil = db::c()->query('SELECT 1 FROM `users` WHERE `id`= ?i', $_SESSION['uid'])->fetch_assoc();
|
||||
@@ -245,7 +245,7 @@ A;
|
||||
echo("<img src='i/magic/attackk_open.gif' title='Кулачное закрытое нападение'> Кулачное закрытое нападение - " . $abil[2] . "<br />");
|
||||
}
|
||||
|
||||
if ($user->getAlign() == 6 || $user->getAdmin()) // Свет
|
||||
if (User::getInstance()->getAlign() == 6 || User::getInstance()->getAdmin()) // Свет
|
||||
{
|
||||
|
||||
$abil = db::c()->query('SELECT 1 FROM `users` WHERE `id`= ?i', $_SESSION['uid'])->fetch_assoc();
|
||||
@@ -449,7 +449,7 @@ A;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'fancy/buy.php',
|
||||
data: "type=" + type + "&user=" + <?= $user->getId() ?> + "",
|
||||
data: "type=" + type + "&user=" + <?= User::getInstance()->getId() ?> + "",
|
||||
success: function (data) {
|
||||
if (data === 'success') {
|
||||
$(".child").html('<b style="color: Red;">' + types_user[type - 1] + ' успешно куплено</b>');
|
||||
@@ -469,7 +469,7 @@ A;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'fancy/buy_klan.php',
|
||||
data: "type=" + type + "&user=" + <?= $user->getId() ?> + "",
|
||||
data: "type=" + type + "&user=" + <?= User::getInstance()->getId() ?> + "",
|
||||
success: function (data) {
|
||||
if (data === 'success') {
|
||||
$(".child").html('<b style="color: Red;">' + types_klan[type - 21] + ' успешно куплено</b>');
|
||||
|
||||
Reference in New Issue
Block a user