patch-dressedcheck #57

Merged
lopar merged 4 commits from patch-dressedcheck into master 2022-06-11 00:18:38 +00:00
6 changed files with 94 additions and 70 deletions
Showing only changes of commit b8f837b6cf - Show all commits

View File

@ -45,8 +45,7 @@ if (isset($_GET['remclan'])) {
# Телеграф.
if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) {
$receiver = Db::getInstance()->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']);
Chat::sendTelegraf($_POST['tgmsg'], $receiver->id);
Chat::sendTelegraf($_POST['tgmsg'], User::getInstance($_POST['receiver'])->getId());
echo "Успешно.";
}
@ -78,26 +77,49 @@ Template::header('ᐰdminка');
<button disabled><img src="../i/magic/check.gif" alt="check"> Проверка</button>
<form method='post'>
<fieldset>
<legend>Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр.</legend>
<input name='ldnick' placeholder='Логин'> <input name='ldtext' size='50' placeholder='Сообщение'>
<label>
<input name='ldnick' placeholder='Логин'>
</label>
<label>
<input name='ldtext' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Добавить'><br>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Отправить системное сообщение в чат</legend>
<label>
<input name='syschatmsg' size='74' placeholder='Введите сообщение'>
</label>
<input type='submit' value='Отправить'>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Телеграф</legend>
<label>
<input name='receiver' placeholder='Логин'>
</label>
<label>
<input name='tgmsg' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Отправить'>
</fieldset>
</form>
<form method='post'>
<fieldset>
<legend>Поменять статус</legend>
<label>
<input name='login' placeholder='Логин'>
</label>
<label>
<input name='status' placeholder='Статус'>
</label>
<input type='submit' value='Изменить статус'>
</fieldset>
</form>
<span class="legend">Невидимки</span><br>

View File

@ -48,7 +48,12 @@ class CureInjury extends Magic
{
$this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target);
$this->login = $this->target->getLogin();
return ($this->isVisible(User::getInstance(), $this->target) && $this->isNotDead(User::getInstance()) && $this->enoughMana(User::getInstance()) && $this->isNotInBattle(User::getInstance()));
return (
$this->isVisible(User::getInstance(), $this->target) &&
$this->isNotDead(User::getInstance()) &&
$this->enoughMana(User::getInstance()) &&
$this->isNotInBattle(User::getInstance())
);
}
public static function cast($target, $type): self

View File

@ -1,9 +1,24 @@
<?php
# Date: 16.09.2020 (08:45)
namespace Battles\Magic;
use Battles\Database\Db;
class Magic
{
protected $status;
protected string $status;
private Db $db;
private object $magic;
public function __construct(Db $db, int $id)
{
$this->magic = $db->ofetch('select * from magic where id = ?', $id);
}
public function getMagic(): object
{
return $this->magic;
}
protected function isVisible($caster, $target): bool
{

View File

@ -216,6 +216,11 @@ class User
return $this->experience;
}
public function addExperience(int $amount): void
{
$this->experience += max($amount, 0);
}
public function getBattle(): int
{
return $this->battle;

View File

@ -6,9 +6,6 @@
* Project name: Battles-Game
*/
use Battles\Database\Db;
use Battles\User;
include_once 'classes/Database/db.php';
include_once 'classes/Database/Mysql.php';
include_once 'classes/Database/Statement.php';

View File

@ -5,6 +5,7 @@
* Project name: Battles-Game
*/
use Battles\Chat;
use Battles\Database\Db;
use Battles\DressedItems;
use Battles\InventoryItem;
@ -24,7 +25,7 @@ if (User::getInstance()->getBlock()) {
}
//Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
Travel::roomRedirects(User::$current->getRoom(), User::$current->getBattle(), User::$current->getInTower());
Travel::roomRedirects(User::getInstance()->getRoom(), User::getInstance()->getBattle(), User::getInstance()->getInTower());
///*
// * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
@ -78,26 +79,26 @@ Travel::roomRedirects(User::$current->getRoom(), User::$current->getBattle(), Us
// exit;
//}
if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
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 = ?';
Db::getInstance()->execute($query, [$_GET['goto'], $_GET['goto'], User::getInstance()->getId()]);
User::getInstance()->setRoom(intval($_GET['goto']));
}
function createbot($bot, $login = "")
function createbot($bot, $login = null)
{
$rec = db::c()->query('SELECT `id`, `login`, `maxhp` FROM `users` WHERE `id` = "?s" LIMIT 1', $bot)->fetch_assoc();
if (isset($rec['id'])) {
if ($login) {
$rec['login'] = $login;
}
$botname = $rec['login'];
db::c()->query('INSERT INTO `bots` (`name`, `prototype`, `hp`) VALUES ("?s", "?s", "?s")', $botname, $bot, $rec['maxhp']);
$nid = db::c()->getLastInsertId();
return ["id" => $nid, "login" => $botname];
} else {
if (!User::getInstance($bot)->getId()) {
return false;
}
$botname = $login ?: User::getInstance($bot)->getLogin();
Db::getInstance()->execute('insert into bots (name, prototype, hp) values (?, ?, ?)',
[$botname, $bot, (new UserStats($bot))->getMaxHealth()]);
return ["id" => Db::getInstance()->lastInsertId(), "login" => $botname];
}
$var_map = [
@ -123,7 +124,7 @@ function savecavedata($cavedata, $caveleader, $floor)
function GiveExp($id, $exp)
{
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id);
User::getInstance($id)->addExperience($exp);
}
/**
@ -199,22 +200,18 @@ EMPTY_SLOT;
}
// ссылка на магию
function showhrefmagic($dress)
function showhrefmagic(array $dress): string
{
$user = db::c()->query('SELECT `battle` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $dress['includemagic'])->fetch_assoc();
$magic = new Battles\Magic\Magic(Db::getInstance(), $dress['includemagic']);
$r = '';
$script = 'main';
if ($user['battle']) {
$script = 'fbattle';
}
$script = User::getInstance()->getBattle() ? 'fbattle' : 'main';
$r .= "<a onclick=\"";
if ($magic['targeted'] == 1) {
if ($magic->getMagic()->targeted == 1) {
$r .= "okno('Введите название предмета', '{$script}.php?use={$dress['id']}', 'target')";
} elseif ($magic['targeted'] == 2) {
$r .= "findlogin('" . $magic['name'] . "', '{$script}.php?use={$dress['id']}', 'target')";
} elseif ($magic->getMagic()->targeted == 2) {
$r .= "findlogin('" . $magic->getMagic()->name . "', '{$script}.php?use={$dress['id']}', 'target')";
} else {
$r .= "if (confirm('Использовать сейчас?')) window.location='" . $script . ".php?use=" . $dress['id'] . "';";
}
@ -435,30 +432,13 @@ function usemagic($id, $target)
function addch($text, $room = 0)
{
if ($room == 0) {
$room = User::getInstance()->getRoom();
}
if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
fwrite($fp, ":[" . time() . "]:[!sys!!]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом
fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ
fclose($fp); //закрытие
}
Chat::sendSys($text);
}
function addchp($text, $who, $room = 0)
{
if ($room == 0) {
$room = User::getInstance()->getRoom();
}
$fp = fopen("tmp/chat.txt", "a"); //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
fwrite($fp, ":[" . time() . "]:[{$who}]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом
fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ
flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ
fclose($fp); //закрытие
Chat::sendSys($text, $who);
}
function err($t)