Изменено поле в БД, вынесены лишние функции их functions в профильные файлы. Оказывается, давно не работал логин и плохо работали сессии. Проверяется. Прочие мелкие баги и чистка самых хвостов.
This commit is contained in:
+79
-128
@@ -10,23 +10,18 @@ use Battles\DressedItems;
|
||||
use Battles\InventoryItem;
|
||||
use Battles\Travel;
|
||||
use Battles\User;
|
||||
use Battles\UserInfo;
|
||||
use Battles\UserStats;
|
||||
|
||||
require_once 'config.php';
|
||||
|
||||
if (empty($_SESSION['uid'])) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
if (empty($user) && $_SESSION['uid']) {
|
||||
$user = new User($_SESSION['uid']);
|
||||
}
|
||||
|
||||
if (empty(User::$current) && $_SESSION['uid']) {
|
||||
User::$current = new User($_SESSION['uid']);
|
||||
}
|
||||
} elseif (empty($user)) {
|
||||
$user = new User($_SESSION['uid']);
|
||||
}
|
||||
if (User::$current->getId() && User::$current->getBlock()) {
|
||||
|
||||
if (User::$current->getBlock()) {
|
||||
exit('user blocked!');
|
||||
}
|
||||
|
||||
@@ -83,9 +78,9 @@ if (in_array(User::$current->getRoom(), $roomsCheck)
|
||||
exit;
|
||||
}
|
||||
|
||||
$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']);
|
||||
if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
|
||||
$query = 'update users u, online o set u.room = ?, o.room = ? where user_id = id and user_id = ?';
|
||||
DBPDO::$db->execute($query, [$_GET['goto'], $_GET['goto'], User::$current->getId()]);
|
||||
User::$current->setRoom(intval($_GET['goto']));
|
||||
}
|
||||
|
||||
@@ -143,74 +138,6 @@ function get_out($u)
|
||||
###
|
||||
}
|
||||
|
||||
function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '', $fields = 0, $uid = 0, $koll = 1, $podzem = 0)
|
||||
{
|
||||
$flds = [];
|
||||
$goden = '';
|
||||
if (!$uid) {
|
||||
$uid = User::$current->getId();
|
||||
}
|
||||
|
||||
$r = db::c()->query('SHOW FIELDS FROM ?f', $table);
|
||||
$r2 = db::c()->query('SHOW FIELDS FROM inventory');
|
||||
|
||||
while ($rec = $r2->fetch_assoc()) {
|
||||
$flds[$rec['Field']] = 1;
|
||||
}
|
||||
|
||||
$rec1 = db::c()->query('SELECT * FROM ?f WHERE id = ?i', $table, $item)->fetch_assoc_array();
|
||||
|
||||
if ($rec1['koll']) {
|
||||
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 = db::c()->query('SELECT id FROM inventory WHERE owner = ?i AND prototype = ?i', $uid, $item)->fetch_row();
|
||||
if ($i) {
|
||||
return ["error" => "У вас слишком много таких вещей."];
|
||||
}
|
||||
}
|
||||
|
||||
if ($present) {
|
||||
$rec1['present'] = $present;
|
||||
$rec1['cost'] = 0;
|
||||
$rec1['ecost'] = 0;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
while ($rec = $r->fetch_assoc()) {
|
||||
if (!$flds[$rec['Field']]) {
|
||||
continue;
|
||||
}
|
||||
if ($rec['Field'] == "dategoden") {
|
||||
$goden = $rec1[$rec['Field']];
|
||||
}
|
||||
if ($rec['Field'] == "goden") {
|
||||
$goden = $rec1[$rec['Field']];
|
||||
}
|
||||
if ($rec['Field'] == "id" || $rec['Field'] == "prototype" || $rec['Field'] == "dategoden") {
|
||||
continue;
|
||||
}
|
||||
$sql .= ", `$rec[Field]` = '" . $rec1[$rec['Field']] . "' ";
|
||||
}
|
||||
|
||||
if ($podzem) {
|
||||
$rec1['podzem'] = $podzem;
|
||||
}
|
||||
|
||||
if ($fields['goden']) {
|
||||
$goden = $fields["goden"];
|
||||
}
|
||||
|
||||
mysql_query("INSERT INTO `inventory` SET " . ($present ? "`present` = '$present'," : "") . ($rec1['podzem'] ? "`podzem` = '$rec1[podzem]'," : "") . " `owner` = '$uid', `otdel` = $rec1[razdel] , `prototype` = '$item' " . ($onlyonetrip ? ", `foronetrip` = 1" : "") . ($goden ? ", `dategoden` = '" . ($goden * 60 * 60 * 24 + time()) . "'" : "") . " $sql");
|
||||
return ["img" => $rec1['img'], "name" => $rec1['name'], "id" => mysql_insert_id()];
|
||||
}
|
||||
|
||||
const _BOTSEPARATOR_ = 10000000;
|
||||
|
||||
function savecavedata($cavedata, $caveleader, $floor)
|
||||
@@ -227,11 +154,6 @@ function GiveExp($id, $exp)
|
||||
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id);
|
||||
}
|
||||
|
||||
function GiveRep($id, $rep)
|
||||
{
|
||||
db::c()->query('UPDATE users SET doblest = (doblest + ?i), rep_laba = (rep_laba + ?i) WHERE `id` = ?i', $rep, $rep, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Генератор прогрессбара.
|
||||
* @param $current - Текущее значение.
|
||||
@@ -505,17 +427,18 @@ function usemagic($id, $target)
|
||||
InventoryItem::destroyItem($row['id']);
|
||||
} else {
|
||||
if (!$row['magic']) {
|
||||
db::c()->query('UPDATE `inventory` SET `includemagicdex` =`includemagicdex` - ?i WHERE id = ?i', $bat, $row['id']);
|
||||
$query = 'update inventory set includemagicdex = includemagicdex - ? where item_id = ?';
|
||||
} else {
|
||||
db::c()->query('UPDATE `inventory` SET duration = duration + ?i WHERE id = ?i', $bat, $row['id']);
|
||||
$query = 'update inventory set durability = durability + ? where item_id = ?';
|
||||
}
|
||||
DBPDO::$db->execute($query, [$bat, $row['id']]);
|
||||
}
|
||||
if (!$charge) {
|
||||
$charge = 0;
|
||||
}
|
||||
//ограничение по кол-ву за ход
|
||||
if (User::$current->getBattle()) {
|
||||
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', User::$current->getBattle())->fetch_assoc_array();
|
||||
$bat = DBPDO::$db->fetch('select * from battle where battle_id = ?', User::$current->getBattle());
|
||||
}
|
||||
if ($bat['magic'] == '') {
|
||||
$all_magic = [];
|
||||
@@ -523,12 +446,20 @@ function usemagic($id, $target)
|
||||
$all_magic = unserialize($bat['magic']);
|
||||
}
|
||||
$all_magic[User::$current->getId()] += $charge;
|
||||
db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), User::$current->getBattle());
|
||||
DBPDO::$db->execute('update battle set magic = ? where battle_id = ?', [serialize($all_magic), User::$current->getBattle()]);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ВАЖНО! (#44)
|
||||
* addch() и addchp() заменяются на Chat::class->addSYSMessage($message, [optional]$receiver);
|
||||
* Для addchp() используется второй опциональный ключ.
|
||||
* Это 150+ вхождений в куче файлов, где надо менять структуру вызова функции из-за их несовместимости.
|
||||
* Возможно, приоритетом стоит сделать унификацию свитков нападения, которых самих около 20 и которые
|
||||
* по нескольку раз вызывают эти функции.
|
||||
*/
|
||||
|
||||
function addch($text, $room = 0)
|
||||
{
|
||||
if ($room == 0) {
|
||||
@@ -560,7 +491,6 @@ function addchp($text, $who, $room = 0)
|
||||
function err($t)
|
||||
{
|
||||
echo '<span class="error">' . $t . '</span>';
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -576,52 +506,60 @@ function telegraph(int $userId, string $text)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Надеюсь временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
|
||||
* @return string
|
||||
*/
|
||||
function getItemsMassaInfo(): string
|
||||
function SolveExp($at_id, $def_id, $damage): float
|
||||
{
|
||||
$itemRow = DBPDO::INIT()->ofetch("select sum(weight) as all_weight from inventory where owner_id = ?", $_SESSION['uid']);
|
||||
$userRow = DBPDO::INIT()->ofetch("select strength * 4 as max_weight from users where id = ?", $_SESSION['uid']);
|
||||
$textStyle = '';
|
||||
if ($itemRow->all_weight > $userRow->max_weight) {
|
||||
$textStyle = " style='color:maroon;'";
|
||||
}
|
||||
return "<span$textStyle>$itemRow->all_weight / $userRow->max_weight</span>";
|
||||
}
|
||||
|
||||
function SolveExp($at_id, $def_id, $damage)
|
||||
{
|
||||
$mods = ['bloodb' => 1.2, 'btl_1' => 1, 'btl_2' => 0.5, 'btl_3' => 0.05];
|
||||
$baseexp = ["0" => "2", "1" => "5", "2" => "10", "3" => "15", "4" => "30", "5" => "60", "6" => "90", "7" => "115", "8" => "300", "9" => "400", "10" => "500", "11" => "600", "12" => "700", "13" => "800", "14" => "900", "15" => "1000", "16" => "1100", "17" => "1200", "18" => "1300", "19" => "1400", "20" => "1500", "21" => "1600"];
|
||||
$mods = [
|
||||
'bloodb' => 1.2,
|
||||
'btl_1' => 1,
|
||||
'btl_2' => 0.5,
|
||||
'btl_3' => 0.05,
|
||||
];
|
||||
$baseexp = [
|
||||
"0" => "2",
|
||||
"1" => "5",
|
||||
"2" => "10",
|
||||
"3" => "15",
|
||||
"4" => "30",
|
||||
"5" => "60",
|
||||
"6" => "90",
|
||||
"7" => "115",
|
||||
"8" => "300",
|
||||
"9" => "400",
|
||||
"10" => "500",
|
||||
"11" => "600",
|
||||
"12" => "700",
|
||||
"13" => "800",
|
||||
"14" => "900",
|
||||
"15" => "1000",
|
||||
"16" => "1100",
|
||||
"17" => "1200",
|
||||
"18" => "1300",
|
||||
"19" => "1400",
|
||||
"20" => "1500",
|
||||
"21" => "1600",
|
||||
];
|
||||
$expmf = 0;
|
||||
$bot_active = false;
|
||||
$bot_def = false;
|
||||
|
||||
if ($at_id > _BOTSEPARATOR_) {
|
||||
$bots = db::c()->query('SELECT * FROM bots WHERE id = ?i', $at_id)->fetch_assoc_array();
|
||||
$bots = DBPDO::$db->fetch('select * from bots where bot_id = ?', $at_id);
|
||||
$at_id = $bots['prototype'];
|
||||
$bot_active = true;
|
||||
}
|
||||
|
||||
$at = db::c()->query('SELECT `level` FROM `users` WHERE `id` = ?i', $at_id)->fetch_assoc();
|
||||
$def = db::c()->query('SELECT `level` FROM `users` WHERE `id` = ?i', $def_id)->fetch_assoc();
|
||||
$at_cost = db::c()->query('SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i', $at_id)->fetch_assoc_array();
|
||||
$def_cost = db::c()->query('SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i', $def_id)->fetch_assoc_array();
|
||||
$query = 'select greatest(1, sum(price)) as allprice from users left join inventory on users.id = inventory.owner_id where id = ?';
|
||||
$at = DBPDO::$db->fetch($query, $at_id);
|
||||
$def = DBPDO::$db->fetch($query, $def_id);
|
||||
|
||||
if ($at_id > _BOTSEPARATOR_) {
|
||||
$table_name = 'bots';
|
||||
} else {
|
||||
$table_name = 'users';
|
||||
}
|
||||
$bat_raw = db::c()->query('SELECT battle FROM ?f WHERE id = ?i', $table_name, $at_id)->fetch_assoc_array();
|
||||
$bat = $bat_raw['battle'];
|
||||
$bt = db::c()->query('SELECT `blood`,`type`,`t1`,`t2` FROM `battle` WHERE `id` = ?i', $bat)->fetch_assoc();
|
||||
$atInfo = new UserStats($at_id);
|
||||
$defInfo = new UserStats($def_id);
|
||||
|
||||
$table_name = $at_id > _BOTSEPARATOR_ ? 'bots' : 'users';
|
||||
$bt = DBPDO::$db->fetch('select blood, type, t1, t2 from battle where battle_id = (select battle from ? where id = ?)', [$table_name, $at_id]);
|
||||
|
||||
if ($def_id > _BOTSEPARATOR_) {
|
||||
$bots = db::c()->query('SELECT * FROM bots WHERE id = ?i', $def_id)->fetch_assoc_array();
|
||||
$bots = DBPDO::$db->fetch('select * from bots where bot_id = ?', $def_id);
|
||||
$def_id = $bots['prototype'];
|
||||
$bot_def = true;
|
||||
}
|
||||
@@ -662,9 +600,22 @@ function SolveExp($at_id, $def_id, $damage)
|
||||
"10" => 919,
|
||||
"11" => 919,
|
||||
"12" => 919,
|
||||
"13" => 919, "14" => 919, "15" => 919, "16" => 919, "17" => 919, "18" => 919, "19" => 919, "20" => 919, "21" => 919, "22" => 919, "23" => 919, "24" => 919, "25" => 919];
|
||||
"13" => 919,
|
||||
"14" => 919,
|
||||
"15" => 919,
|
||||
"16" => 919,
|
||||
"17" => 919,
|
||||
"18" => 919,
|
||||
"19" => 919,
|
||||
"20" => 919,
|
||||
"21" => 919,
|
||||
"22" => 919,
|
||||
"23" => 919,
|
||||
"24" => 919,
|
||||
"25" => 919
|
||||
];
|
||||
|
||||
$mfit = ($at_cost[0] / ($standart[$at['level']] / 3));
|
||||
$mfit = ($at['allprice'] / ($standart[$atInfo->getLevel()] / 3));
|
||||
if ($mfit < 0.8) {
|
||||
$mfit = 0.8;
|
||||
}
|
||||
@@ -684,5 +635,5 @@ function SolveExp($at_id, $def_id, $damage)
|
||||
$expmf = 1;
|
||||
}
|
||||
|
||||
return round((($baseexp[$def['level']]) * ($def_cost[0] / (($at_cost[0] + $def_cost[0]) / 2)) * ($damage / $def['maxhp']) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
|
||||
}
|
||||
return round((($baseexp[$defInfo->getLevel()]) * ($def['allprice'] / (($at['allprice'] + $def['allprice']) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
|
||||
}
|
||||
Reference in New Issue
Block a user