removing deprecated mysql

This commit is contained in:
Igor Barkov (iwork) 2020-06-23 18:57:20 +03:00
parent f0ede8a311
commit 86de79a7ef

View File

@ -9,7 +9,9 @@ require_once 'config.php';
* Класс-заглушка для работы глобальных переменных в функциях.
* Возвращает массив данных таблицы users.
*/
if (isset($_SESSION['uid'])) $user = (new users_row($_SESSION['uid']))->result();
if (isset($_SESSION['uid'])) {
$user = (new users_row($_SESSION['uid']))->result();
}
if (isset($user['id']) && $user['block'] == 1) {
die();
@ -20,11 +22,9 @@ if (isset($user['id']) && $user['block'] == 1) {
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
if (isset($_GET['goto']) and isset($_GET['tStamp']) and isset($_GET['vcode'])) {
if ($_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']);
}
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']);
}
function createbot($bot, $login = "")
@ -45,8 +45,8 @@ function createbot($bot, $login = "")
function getuserdata($id = 0)
{
if (!$id) $id = isset($_SESSION['uid']) ? $_SESSION['uid'] : null; // Хорошее решение проверок, кстати.
if (!$id) return [];
if (!$id) $id = {isset($_SESSION['uid']) ? $_SESSION['uid'] : null;} // Хорошее решение проверок, кстати.
if (!$id) {return [];}
$rec = db::c()->query('SELECT `hp`, `maxhp`, `fullhptime`, `battle` FROM `users` WHERE `id` = "?s"', $id)->fetch_assoc();
if ($rec['hp'] < $rec['maxhp'] && time() > $rec['fullhptime'] && !$rec['battle'] && ($rec['hp'] > 0)) {
// regenhp($rec, 0);
@ -71,15 +71,14 @@ $var_map = [
'cell_25' => 'Полесье'
];
function get_out($u)
{
$pers = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $u . '" LIMIT 1'));
function get_out($u){
$pers = db::c()->query('SELECT * FROM users WHERE id = ?i', $u)->fetch_assoc_array();
undressall($pers['id']);
mysql_query('UPDATE `inventory` SET `owner` = "' . $pers['id'] . '" WHERE `owner` = "' . ($pers['id'] + _BOTSEPARATOR_) . '"');
db::c()->query('UPDATE inventory SET owner = ?i WHERE owner = ?i', $pers['id'], $pers['id'] + _BOTSEPARATOR_);
###
$row = mysql_query('SELECT * FROM `effects` WHERE `owner` = "' . ($pers['id'] + _BOTSEPARATOR_) . '"');
$row = db::c()->query('SELECT * FROM `effects` WHERE `owner` = ?i',$pers['id'] + _BOTSEPARATOR_);
$travm = [11, 12, 13, 14];
while ($efs = mysql_fetch_array($row)) {
while ($efs = $row->fetch_assoc()) {
if (in_array($efs['type'], $travm)) {
$pers['sila'] -= $efs['sila'];
$pers['lovk'] -= $efs['lovk'];
@ -93,8 +92,8 @@ function get_out($u)
$pers['maxhp'] += $efs['hp'];
}
$efs['owner'] = $_SESSION['uid'];
mysql_query('UPDATE `effects` SET `owner` = "' . $efs['owner'] . '" WHERE `id` = "' . $efs['id'] . '" LIMIT 1');
mysql_query('UPDATE `users` SET `sila` = "' . $pers['sila'] . '", `lovk` = "' . $pers['lovk'] . '", `inta` = "' . $pers['inta'] . '", `vinos` = "' . $pers['vinos'] . '", `maxhp` = "' . $pers['maxhp'] . '" WHERE `id` = "' . $pers['id'] . '" LIMIT 1');
//mysql_query('UPDATE `effects` SET `owner` = "' . $efs['owner'] . '" WHERE `id` = "' . $efs['id'] . '" LIMIT 1');
//mysql_query('UPDATE `users` SET `sila` = "' . $pers['sila'] . '", `lovk` = "' . $pers['lovk'] . '", `inta` = "' . $pers['inta'] . '", `vinos` = "' . $pers['vinos'] . '", `maxhp` = "' . $pers['maxhp'] . '" WHERE `id` = "' . $pers['id'] . '" LIMIT 1');
}
###
}
@ -108,24 +107,24 @@ function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '',
$uid = $user['id'];
}
$r = mysql_query("SHOW FIELDS FROM $table");
$r2 = mysql_query("SHOW FIELDS FROM inventory");
$r = db::c()->query('SHOW FIELDS FROM ?f', $table);
$r2 = db::c()->query('SHOW FIELDS FROM inventory');
while ($rec = mysql_fetch_assoc($r2)) {
while ($rec = $r2->fetch_assoc()) {
$flds[$rec['Field']] = 1;
}
$rec1 = mysql_fetch_array(mysql_query("SELECT * FROM `$table` WHERE `id` = '$item' LIMIT 1"));
$rec1 = db::c()->query('SELECT * FROM ?f WHERE id = ?i', $table, $item)->fetch_assoc_array();
if ($rec1['koll']) {
mysql_query("UPDATE `inventory` SET `koll` = (`koll`+$koll), `massa` = (`massa`+" . ($rec1['massa'] * $koll) . "), `cost` = (`cost`+" . $rec1['cost'] . ") WHERE `owner` = '$uid' AND `prototype` = '$item' LIMIT 1");
if (mysql_affected_rows() > 0) return ["img" => $rec1['img'], "name" => $rec1['name']];
db::c()->query('UPDATE inventory SET koll = (koll + ?i), massa = (massa + ?i), cost = (cost + ?i) WHERE owner = ?i AND prototype = ?i', $koll, $rec1['massa'] * $koll, $rec1['cost'], $uid, $item);
if (db::c()->getAffectedRows() > 0) return ["img" => $rec1['img'], "name" => $rec1['name']];
$rec1['koll'] = $koll;
$rec1['massa'] *= $koll;
}
if ($rec1['onlyone']) {
$i = mysql_fetch_row(mysql_query("SELECT `id` FROM `inventory` WHERE `owner` = '$uid' AND `prototype` = '$item'"));
$i = db::c()->query('SELECT id FROM inventory WHERE owner = ?i AND prototype = ?i', $uid, $item)->fetch_row();
if ($i) {
return ["error" => "У вас слишком много таких вещей."];
}
@ -138,7 +137,7 @@ function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '',
}
$sql = "";
while ($rec = mysql_fetch_assoc($r)) {
while ($rec = $r->fetch_assoc()) {
if (!$flds[$rec['Field']]) continue;
if ($rec['Field'] == "dategoden") {
$goden = $rec1[$rec['Field']];
@ -240,10 +239,10 @@ function nick($user)
function nick4($id, $st)
{
$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '{$id}' LIMIT 1"));
$user = db::c()->query('SELECT * FROM `users` WHERE `id` = ?i', $id)->fetch_assoc();
if ($user[0]) {
$effect = mysql_fetch_array(mysql_query("SELECT `time` FROM `effects` WHERE `owner` = '{$id}' AND `type` = '1022' LIMIT 1"));
$effect = db::c()->query('SELECT time FROM effects WHERE type = 1022 and owner = ?i', $id)->fetch_assoc_array();
if ($effect) {
$user['level'] = '??';
$user['login'] = '</a><b><i>невидимка</i></b>';
@ -255,12 +254,13 @@ function nick4($id, $st)
}
return "<span onclick=\"top.AddTo('" . $user['login'] . "')\" oncontextmenu=\"return OpenMenu(event," . $user['level'] . ")\" class={$st}>" . $user['login'] . "</span> [" . $user['hp'] . "/" . $user['maxhp'] . "]";
}
return false;
}
function check_proc($u)
{
$r = 100;
$usr = mysql_fetch_array(mysql_query('SELECT `id`, `vip`, `vip_time` FROM `users` WHERE `id` = "' . $u . '" LIMIT 1'));
$usr = db::c()->query('SELECT `id`, `vip`, `vip_time` FROM `users` WHERE `id` = ?i', $u)->fetch_assoc_array();
if ($usr['vip_time'] > time()) {
if ($usr['vip'] == 1) {
$r += 10;
@ -270,7 +270,8 @@ function check_proc($u)
$r += 20;
}
}
$effes = mysql_fetch_array(mysql_query('SELECT SUM(`proc_exp`) AS `sums` FROM `effects` WHERE `owner` = "' . $usr['id'] . '" AND `proc_exp` > 0'));
$effes = db::c()->query('SELECT SUM(`proc_exp`) AS `sums` FROM `effects` WHERE proc_exp > 0 AND owner = ?i', $usr['id'])->fetch_assoc_array();
if ($effes['sums'] > 0) {
$r += $effes['sums'];
}
@ -2113,10 +2114,10 @@ function addOnePoint($name, $param = null)
'mgray' => 'Магия серости',
'mdark' => 'Магия тьмы'
];
if ($param == 'stat' AND in_array($name, $allowed_stats)) {
if ($param == 'stat' and in_array($name, $allowed_stats)) {
db::c()->query('UPDATE `users` SET ?f = ?f + 1, `stats` = `stats` - 1 WHERE `id` = ?i', $name, $name, $_SESSION['uid']);
echo "<span style='color:darkgreen'>Параметр {$naming[$name]} увеличен на 1 ед.</span>";
} elseif ($param == 'mastery' AND in_array($name, $allowed_mastery)) {
} elseif ($param == 'mastery' and in_array($name, $allowed_mastery)) {
$mastery_level = db::c()->query('SELECT ?f FROM `users` WHERE `id` = ?i', $name, $_SESSION['uid'])->fetch_assoc();
if ($mastery_level[$name] < 10) {
db::c()->query('UPDATE `users` SET ?f = ?f + 1, `master` = `master` - 1 WHERE `id` = ?i', $name, $name, $_SESSION['uid']);