Перевод functions.php и основных направлений на класс User.

This commit is contained in:
lopar 2020-08-30 03:09:53 +03:00
parent 427149b90e
commit 8d8342d197
3 changed files with 93 additions and 175 deletions

View File

@ -11,24 +11,21 @@ require_once 'config.php';
* Возвращает массив данных таблицы users.
*/
if (isset($_SESSION['uid'])) {
$user = (new users_row($_SESSION['uid']))->result();
$userr = new User($_SESSION['uid']);
//$user = (new users_row($_SESSION['uid']))->result();
$user = new User($_SESSION['uid']);
} else {
echo "Не могу проинициализировать игрока!";
}
if (isset($user['id']) && $user['block'] == 1) {
die('user blocked!');
if ($user->id && $user->block) {
exit('user blocked!');
}
// ???
//define("HPADDICTIONEFFECT", 33);
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
if (isset($_GET['goto']) && isset($_GET['tStamp']) && isset($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
db::c()->query('UPDATE `users`,`online` SET `users`.`room` = ?i, `online`.`room` = ?i WHERE `online`.`id` = `users`.`id` AND `online`.`id` = ?i', $_GET['goto'], $_GET['goto'], $_SESSION['uid']);
$user['room'] = intval($_GET['goto']);
$user->room = intval($_GET['goto']);
}
function createbot($bot, $login = "")
@ -91,7 +88,7 @@ function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '',
$flds = [];
$goden = '';
if (!$uid) {
$uid = $user['id'];
$uid = $user->id;
}
$r = db::c()->query('SHOW FIELDS FROM ?f', $table);
@ -243,19 +240,19 @@ function echoscroll($slot)
{
global $user;
$all_magic = 0;
if ($user['battle']) {
if ($user->battle) {
$script = 'fbattle';
$bat = db::c()->query('SELECT `magic` FROM `battle` WHERE `id` = ?i', $user['battle'])->fetch_assoc();
$bat = db::c()->query('SELECT `magic` FROM `battle` WHERE `id` = ?i', $user->battle)->fetch_assoc();
$all_magic = unserialize($bat['magic']);
} else {
$script = 'main';
}
$dress = db::c()->query('SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i', $user[$slot])->fetch_assoc();
$dress = db::c()->query('SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i', $user->$slot)->fetch_assoc();
$need_charge = db::c()->query('SELECT `needcharge` FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
if (($user[$slot] > 0) && ($all_magic[$user['id']] < 1 || empty($need_charge['needcharge']))) {
$row['id'] = $user[$slot];
if (($user->$slot > 0) && ($all_magic[$user->id] < 1 || empty($need_charge['needcharge']))) {
$row['id'] = $user->$slot;
if ($dress['magic']) {
$magic = db::c()->query('SELECT targeted FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
echo "<a onclick=\"";
@ -272,7 +269,7 @@ function echoscroll($slot)
echo <<<ACTIVE_SCROLL
<img class='tooltip' src="i/sh/{$dress['img']}" width='40' title="<b>{$dress['name']}</b><br> Прочность {$dress['duration']} / {$dress['maxdur']} " height='25' alt="Свиток"></a>
ACTIVE_SCROLL;
} elseif (($user[$slot] > 0) && ($all_magic[$user['id']] >= 1) && $need_charge['needcharge'] > 0) {
} elseif (($user->$slot > 0) && ($all_magic[$user->id] >= 1) && $need_charge['needcharge'] > 0) {
echo <<<INACTIVE_SCROLL
<img src="i/sh/magicclock.gif" width="40" height="25" title='Произведите размен ударами и магия снова станет доступна' alt="Свиток">
INACTIVE_SCROLL;
@ -444,6 +441,7 @@ function undressall($user_id)
function dropitemid($slot, $id)
{
global $user;
switch ($slot) {
case 1:
$slot1 = 'sergi';
@ -522,7 +520,7 @@ function dropitemid($slot, $id)
if ($checkid->getNumRows()) {
if (mysql_query('UPDATE `users`, `inventory` SET `users`.`' . $slot1 . '` = 0, `inventory`.`dressed` = 0, `users`.`sila` = `users`.`sila` - `inventory`.`gsila`, `users`.`lovk` = `users`.`lovk` - `inventory`.`glovk`, `users`.`inta` = `users`.`inta` - `inventory`.`ginta`, `users`.`intel` = `users`.`intel` - `inventory`.`gintel`, `users`.`maxhp` = `users`.`maxhp` - `inventory`.`ghp`, `users`.`noj` = `users`.`noj` - `inventory`.`gnoj`, `users`.`topor` = `users`.`topor` - `inventory`.`gtopor`, `users`.`dubina` = `users`.`dubina` - `inventory`.`gdubina`, `users`.`mec` = `users`.`mec` - `inventory`.`gmech`, `users`.`mfire` = `users`.`mfire` - `inventory`.`gfire`, `users`.`mwater` = `users`.`mwater` - `inventory`.`gwater`, `users`.`mair` = `users`.`mair` - `inventory`.`gair`, `users`.`mearth` = `users`.`mearth` - `inventory`.`gearth`, `users`.`mlight` = `users`.`mlight` - `inventory`.`glight`, `users`.`mgray` = `users`.`mgray` - `inventory`.`ggray`, `users`.`mdark` = `users`.`mdark` - `inventory`.`gdark`, `users`.`fkrit` = `users`.`fkrit` - `inventory`.`mfkrit`, `users`.`fakrit` = `users`.`fakrit` - `inventory`.`mfakrit`, `users`.`fuvorot` = `users`.`fuvorot` - `inventory`.`mfuvorot`, `users`.`fauvorot` = `users`.`fauvorot` - `inventory`.`mfauvorot`, `users`.`ubron1` = `users`.`ubron1` - `inventory`.`bron1`, `users`.`ubron2` = `users`.`ubron2` - `inventory`.`bron2`, `users`.`ubron3` = `users`.`ubron3` - `inventory`.`bron3`, `users`.`ubron4` = `users`.`ubron4` - `inventory`.`bron4`, `users`.`uminu` = `users`.`uminu` - `inventory`.`minu`, `users`.`umaxu` = `users`.`umaxu` - `inventory`.`maxu` WHERE `inventory`.`id` = `users`.`' . $slot1 . '` AND `inventory`.`dressed` = 1 AND `inventory`.`owner` = "' . $id . '" AND `users`.`id` = "' . $id . '"')) {
db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $id);
$user[$slot1] = 0;
$user->$slot1 = 0;
}
return true;
} else {
@ -609,7 +607,7 @@ function dropitem($slot)
$slot1 = '';
break;
}
{
if (db::c()->query('UPDATE `users` as `u`, `inventory` as `i` SET `u`.?f = 0, `i`.`dressed` = 0,
`u`.`sila` = `u`.`sila` - `i`.`gsila`,
`u`.`lovk` = `u`.`lovk` - `i`.`glovk`,
@ -637,16 +635,16 @@ function dropitem($slot)
`u`.`fauvorot` = `u`.`fauvorot` - `i`.`mfauvorot`,
`u`.`uminu` = `u`.`uminu` - `i`.`minu`,
`u`.`umaxu` = `u`.`umaxu` - `i`.`maxu`
WHERE `i`.`id` = `u`.?f AND `i`.`dressed` = 1 AND `i`.`owner` = ?i AND u.id = ?i', $slot1, $slot1, $user['id'], $user['id'])) {
db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $user['id']);
WHERE `i`.`id` = `u`.?f AND `i`.`dressed` = 1 AND `i`.`owner` = ?i AND u.id = ?i', $slot1, $slot1, $user->id, $user->id)) {
db::c()->query('UPDATE `users` SET `hp` = `maxhp`, `fullhptime` = ?i WHERE `hp` > `maxhp` AND `id` = ?i', time(), $user->id);
}
$wear_raw = db::c()->query('SELECT * FROM `inventory` where `owner` = ?i AND `dressed` = 1', $user['id']);
$wear_raw = db::c()->query('SELECT * FROM `inventory` where `owner` = ?i AND `dressed` = 1', $user->id);
while ($wear_list = $wear_raw->fetch_assoc()) {
$wear_arr[] = $wear_list['prototype'];
}
$item['id'] = $user[$slot1];
$item['id'] = $user->$slot1;
$get_pro = db::c()->query('SELECT * FROM `inventory` where `id` = ?i', $item['id'])->fetch_assoc();
/////////////////////
@ -701,22 +699,18 @@ function dropitem($slot)
`u`.`mlight = `u`.`mlight - `s`.`glight`,
`u`.`mgray = `u`.`mgray - `s`.`ggray`
WHERE
`u`.`id` = ?i AND `s`.`set_id`= ?i', $user['id'], $set_id);
`u`.`id` = ?i AND `s`.`set_id`= ?i', $user->id, $set_id);
}
}
return true;
}
}
//FIXME роняем вещи, которые больше не можем держать
function ref_drop()
{
# global $user;
//сможет держать
function derj($id)
{
//global $user;
$user = db::c()->query('SELECT `id`, `align` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
$ts = db::c()->query('SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i', $id)->fetch_assoc();
$al = '(1 = 1)';
@ -763,94 +757,17 @@ function ref_drop()
}
}
// убить предмет
/**
* Уничтожить предмет, принадлежащий игроку, вызывающего функцию.
* @param $id - ID предмета игрока.
* @throws \Krugozor\Database\Mysql\Exception
*/
function destructitem($id)
{
global $user;
$slot1 = '';
$dress = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND `id` = ?i', $user['id'], $id)->fetch_assoc();
switch ($dress['type']) {
case 1:
$slot1 = 'sergi';
break;
case 2:
$slot1 = 'kulon';
break;
case 3:
$slot1 = 'weap';
break;
case 4:
$slot1 = 'bron';
break;
case 5:
$slot1 = 'r1';
break;
case 6:
$slot1 = 'r2';
break;
case 7:
$slot1 = 'r3';
break;
case 8:
$slot1 = 'helm';
break;
case 9:
$slot1 = 'perchi';
break;
case 10:
$slot1 = 'shit';
break;
case 11:
$slot1 = 'boots';
break;
case 12:
$slot1 = 'm1';
break;
case 22:
$slot1 = 'rybax';
break;
case 23:
$slot1 = 'plaw';
break;
default:
$slot1 = 'weap';
break;
}
if ($dress['type'] == 5) {
if ($user['r1'] == $dress['id']) {
$slot1 = 'r1';
} elseif ($user['r2'] == $dress['id']) {
$slot1 = 'r2';
} elseif ($user['r3'] == $dress['id']) {
$slot1 = 'r3';
}
} elseif ($dress['type'] == 12) {
if ($user['m1'] == $dress['id']) {
$slot1 = 'm1';
} elseif ($user['m2'] == $dress['id']) {
$slot1 = 'm2';
} elseif ($user['m3'] == $dress['id']) {
$slot1 = 'm3';
} elseif ($user['m4'] == $dress['id']) {
$slot1 = 'm4';
} elseif ($user['m5'] == $dress['id']) {
$slot1 = 'm5';
} elseif ($user['m6'] == $dress['id']) {
$slot1 = 'm6';
} elseif ($user['m7'] == $dress['id']) {
$slot1 = 'm7';
} elseif ($user['m8'] == $dress['id']) {
$slot1 = 'm8';
} elseif ($user['m9'] == $dress['id']) {
$slot1 = 'm9';
} elseif ($user['m10'] == $dress['id']) {
$slot1 = 'm10';
}
}
if ($dress['owner'] == $user['id']) {
if ($dress['dressed'] == 1) {
db::c()->query('UPDATE `users` SET ?f = 0 WHERE `id` = ?i', $slot1, $user['id']);
}
$item = db::c()->query('SELECT 1 FROM inventory WHERE owner_id = ?i AND item_id = ?i', $user->id, $id);
if ($item->getNumRows()) {
db::c()->query('DELETE FROM `inventory` WHERE `id` = ?i', $id);
}
}
@ -859,8 +776,8 @@ function destructitem($id)
function usemagic($id, $target)
{
global $user;
$row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', $user['id'], $id)->fetch_assoc_array();
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user['battle'])->fetch_assoc_array();
$row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', $user->id, $id)->fetch_assoc_array();
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user->battle)->fetch_assoc_array();
$all_magic = unserialize($bat['magic']);
$charge = 0;
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $row['magic'])->fetch_assoc_array();
@ -873,27 +790,27 @@ function usemagic($id, $target)
if ($incmagic['needcharge'] > 0) {
$charge = $incmagic['needcharge'];
}
if ((($all_magic[$user['id']] < 1) || ($charge == '0')) &&
(($user['sila'] >= $row['nsila']) &&
($user['lovk'] >= $row['nlovk']) &&
($user['inta'] >= $row['ninta']) &&
($user['vinos'] >= $row['nvinos']) &&
($user['intel'] >= $row['nintel']) &&
($user['level'] >= $row['nlevel']) &&
//FIXME Переделать под новую базу
if (($all_magic[$user->id] < 1 || $charge == 0) &&
($user['sila'] >= $row['nsila'] &&
$user['lovk'] >= $row['nlovk'] &&
$user['inta'] >= $row['ninta'] &&
$user['vinos'] >= $row['nvinos'] &&
$user['intel'] >= $row['nintel'] &&
$user['level'] >= $row['nlevel'] &&
(($user['align'] > 7 && $user['align'] < 8) || ((int)$user['align'] == (int)$row['nalign']) || ($row['nalign'] == 0)) &&
($user['noj'] >= $row['nnoj']) &&
($user['topor'] >= $row['ntopor']) &&
($user['dubina'] >= $row['ndubina']) &&
($user['mec'] >= $row['nmech']) &&
$user['noj'] >= $row['nnoj'] &&
$user['topor'] >= $row['ntopor'] &&
$user['dubina'] >= $row['ndubina'] &&
$user['mec'] >= $row['nmech'] &&
($row['type'] < 13 || $row['type'] == 50) && ($user['mfire'] >= $row['nfire']) &&
($user['mwater'] >= $row['nwater']) &&
($user['mair'] >= $row['nair']) &&
($user['mearth'] >= $row['nearth']) &&
($user['mlight'] >= $row['nlight']) &&
($user['mgray'] >= $row['ngray']) &&
($user['mdark'] >= $row['ndark']) &&
($row['needident'] == 0)
$user['mwater'] >= $row['nwater'] &&
$user['mair'] >= $row['nair'] &&
$user['mearth'] >= $row['nearth'] &&
$user['mlight'] >= $row['nlight'] &&
$user['mgray'] >= $row['ngray'] &&
$user['mdark'] >= $row['ndark'] &&
$row['needident'] == 0
) || $row['magic'] == 48 || $row['magic'] == 50) {
@ -927,16 +844,16 @@ function usemagic($id, $target)
$charge = 0;
}
//ограничение по кол-ву за ход
if ($user['battle'] > 0) {
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user['battle'])->fetch_assoc_array();
if ($user->battle > 0) {
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user->battle)->fetch_assoc_array();
}
if ($bat['magic'] == '') {
$all_magic = [];
} else {
$all_magic = unserialize($bat['magic']);
}
$all_magic[$user['id']] += $charge;
db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), $user['battle']);
$all_magic[$user->id] += $charge;
db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), $user->battle);
}
}
return false;
@ -946,7 +863,7 @@ function addch($text, $room = 0)
{
global $user;
if ($room == 0) {
$room = $user['room'];
$room = $user->room;
}
if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
@ -962,7 +879,7 @@ function addchp($text, $who, $room = 0)
{
global $user;
if ($room == 0) {
$room = $user['room'];
$room = $user->room;
}
$fp = fopen("tmp/chat.txt", "a"); //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
@ -1178,7 +1095,7 @@ function get_meshok()
{
global $user;
$d = db::c()->query('SELECT SUM(`gmeshok`) AS `ves` FROM `inventory` WHERE `owner` = ?i AND `setsale` = 0 AND `gmeshok` > 0', $_SESSION['uid'])->fetch_assoc();
return ($user['sila'] * 4 + $d['ves']);
return ($user->strength * 4 + $d['ves']);
}
/**

View File

@ -11,6 +11,7 @@ if (!isset($_SESSION['uid'])) {
}
require_once 'functions.php';
$user = $userr;
try {
db::c()->query('UPDATE `online` SET `real_time` = ?i WHERE `user_id` = ?i', time(), $user->id);
@ -342,7 +343,7 @@ function setShadow($image)
];
if (in_array($image, $shadows)) {
$i = $image . '.png';
db::c()->query('UPDATE `users` SET `shadow` = "?s" WHERE `id` = ?i', $i, $user['id']);
db::c()->query('UPDATE `users` SET `shadow` = "?s" WHERE `id` = ?i', $i, $user->id);
} else {
err('Ошибка!');
}
@ -353,7 +354,7 @@ if ($obraz && ($user->shadow == 'g0.gif' || $user->shadow == 'man0.gif')) {
}
if ($del == 1 && $effectId > 0) {
$pl = db::c()->query('SELECT type FROM users_effects WHERE owner_id = ?i AND effect_id = ?i', $user['id'], $effectId)->fetch_assoc();
$pl = db::c()->query('SELECT type FROM users_effects WHERE owner_id = ?i AND effect_id = ?i', $user->id, $effectId)->fetch_assoc();
if (isset($pl['type'])) {
echo del_efs($effectId, $pl['type']);
} else {
@ -363,7 +364,7 @@ if ($del == 1 && $effectId > 0) {
if ($brons && $ids) {
try {
$cur = db::c()->query('SELECT free_bron, bron1, bron2, bron3, bron4 FROM inventory WHERE owner = ?i AND id = ?i', $user['id'], $ids)->fetch_assoc();
$cur = db::c()->query('SELECT free_bron, bron1, bron2, bron3, bron4 FROM inventory WHERE owner = ?i AND id = ?i', $user->id, $ids)->fetch_assoc();
} catch (\Krugozor\Database\Mysql\Exception $e) {
echo "<div style='background-color: #ffaaaa;'>Ошибка: " . $e->getMessage() . "<br> В файле: " . $e->getFile() . " (" . $e->getLine() . ")</div>";
}
@ -461,7 +462,7 @@ if ($edit) {
$q = $q->fetch_assoc();
if (empty($q['dressed'])) {
destructitem($q['id']);
addToDelo($user['login'] . " выбросил предмет " . $q['name'] . " id:(cap" . $q['id'] . ")");
addToDelo($user->login . " выбросил предмет " . $q['name'] . " id:(cap" . $q['id'] . ")");
err('Предмет ' . $q['name'] . ' выброшен.');
} else {
err('Ошибка: нельзя выбросить одетый предмет!');
@ -528,7 +529,7 @@ if ($edit) {
<div align="center">
<a href='main.php?edit=1&undress=all'>Снять все</a><BR>
<div class="effectList" style="padding-top: 15px; max-height: 150px; width: 220px;">
<?= show_eff_inf($user['id'], 2) ?>
<?= show_eff_inf($user->id, 2) ?>
</div>
</div>
<br>
@ -585,7 +586,7 @@ if ($edit) {
<td valign=top>
<div class="button-container"> <!--Меню-кнопки-->
<FORM METHOD=POST ACTION="?edit=1" name=f1>
<?php if ($user['shadow'] == '0.gif' || $user['admin'] == 1): ?>
<?php if ($user->shadow == '0.gif' || $user->admin == 1): ?>
<INPUT class="button primary icon user" TYPE="submit" name="setshadow" value="Образы"
title="Образы">
<?php endif; ?>

View File

@ -1,6 +1,6 @@
<?php
$frt=mysql_query("select user_id from `labirint` where glava='".$glava."'");
while($rbb=mysql_fetch_array($frt)){
addchp ('<b>'.$user["login"].'</b> поднял предмет "'.$mis.'". ','{[]}'.Nick::id($rbb["user_id"])->short().'{[]}');
addchp ('<b>'.$user->login.'</b> поднял предмет "'.$mis.'". ','{[]}'.Nick::id($rbb["user_id"])->short().'{[]}');
}