Перенос разрозненных файлов в фабрику. Утилизация неиспользуемых функций. #49

This commit is contained in:
2023-12-05 03:01:04 +02:00
committed by Ivor Barhansky
parent c51dbaeae3
commit 8be1c6cd7e
79 changed files with 12178 additions and 12956 deletions
@@ -0,0 +1,49 @@
<?php
namespace Moderation;
use Chat;
use User;
class Announcement
{
public static function init(): void
{
self::printForm();
self::send();
}
public static function printForm(): void
{
echo <<<HTML
<div style="padding:0 10px 5px 10px; margin:5px; border-bottom:1px solid #cac9c7;">
<h4>Ìåãàôîí</h4>
<form method="post"></form>
<label for="announcementText">Ñîîáùåíèå</label>
<input name="announcementText" type="text" id="announcementText" size="70" maxlength="1000">
<input type="submit" name="announcementModeration" id="announcementModeration" class="btn" value="Íàïèñàòü"><br>
<input name="announcementIsSigned" type="checkbox" id="announcementIsSigned" value="1">
<label for="announcementIsSigned">îò ñâîåãî èìåíè</label>
</form>
</div>
HTML;
}
public static function send(): void
{
if (empty($_POST['announcementModeration'] || empty($_POST['announcementText']))) {
return;
}
$strippedMessage = strip_tags($_POST['announcementText']);
if (empty($strippedMessage)) {
return;
}
$sender = empty($_POST['announcementIsSigned']) ? '<b>Àäìèíèñòðàöèÿ</b>' : User::getLogin(User::start()->info['id']);
(new Chat())->sendsys("$sender: $strippedMessage");
echo '<span style="color: red; "><b>Ñîîáùåíèå óñïåøíî îòïðàâëåíî</b></span>';
}
}
+148
View File
@@ -0,0 +1,148 @@
<?php
namespace Moderation;
use Chat;
use ChatMessage;
use Core\Db;
use DateTime;
use User;
class ModFactory
{
private const ERROR_WRONG_DURATION = 'Íåâåðíî óêàçàí ñðîê íàêàçàíèÿ';
public readonly string $status;
private DateTime $time;
private ChatMessage $msg;
private Moderation $moderation;
private Chat $chat;
private array $targetUser;
public function __construct(
private readonly string $targetLogin,
private readonly string $reason,
int $moderatorsRoom // Êîìíàòà ãäå ñèäèò ìîäåðàòîð.
)
{
$this->targetUser = User::getInfo($this->targetLogin);
if (empty($this->targetUser)) {
$this->status = 'Ïåðñîíàæ íå íàéäåí!';
return;
}
$this->chat = new Chat();
$this->msg = new ChatMessage();
$this->msg->setType(6);
$this->msg->setTypeTime(1);
$this->msg->setRoom($moderatorsRoom);
$this->time = new DateTime();
$this->moderation = new Moderation($this->targetUser['id']);
}
public function silence(int $minutes): void
{
if ($minutes < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
$this->time->modify("+ $minutes minute");
$this->moderation->silence($this->time, $this->reason);
$this->status = "Ïåðñîíàæó $this->targetLogin çàïðåùåíî îáùàòüñÿ â ÷àòå äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}.";
$this->msg->setText("[img[items/silence.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unsilence(): void
{
if ($this->targetUser['molch1'] < $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ íå ìîë÷èò!';
return;
}
$this->moderation->unsilence();
$this->status = "Ñ ïåðñîíàæà $this->targetLogin ñíÿò çàïðåò íà îáùåíèå â ÷àòå.";
$this->msg->setText("[img[items/pal_button3.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function prison(int $days): void
{
if ($days < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
$this->time->modify("+ $days day");
$this->moderation->prison($this->time, $this->reason);
Db::sql('delete from dungeon_zv where uid = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè â ïåùåðû.
$this->status = "Ïåðñîíàæ $this->targetLogin áûë îòïðàâëåí â òþðüìó äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}.";
$this->msg->setText("[img[items/jail.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unprison(): void
{
$this->moderation->unprison();
$this->status = "Ïåðñîíàæ $this->targetLogin áûë âûïóùåí èç òþðüìû.";
$this->msg->setText("[img[items/jail_off.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function depersonalize(int $days): void
{
if ($days < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
if ($this->targetUser['info_delete'] === 1 || $this->targetUser['info_delete'] >= $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ óæå ïîä ïîäîçðåíèåì.';
return;
}
$this->time->modify("+ $days day");
$this->moderation->depersonalize($this->time, $this->reason);
$this->status = "Ïåðñîíàæ $this->targetLogin ïîä ïîäîçðåíèåì äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}";
$this->msg->setText("[img[items/cui.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function undepersonalize(): void
{
if ($this->targetUser['info_delete'] <= $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ íå ïîä ïîäîçðåíèåì.';
return;
}
$this->moderation->undepersonalize();
$this->status = "Ïåðñîíàæ $this->targetLogin áîëüøå íå ïîä ïîäîçðåíèåì";
$this->msg->setText("[img[items/uncui.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function ban(): void
{
$this->moderation->ban($this->reason);
Db::sql('delete from chat where login = ?', [$this->targetLogin]);
Db::sql('insert into ban_email (email, uid, nick_name) values (?,?,?)', [$this->targetUser['mail'], $this->targetUser['id'], $this->targetLogin]);
Db::sql('delete from zayvki where creator = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè íà áîé.
Db::sql('delete from dungeon_zv where uid = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè â ïåùåðû.
if (!empty($this->targetUser['battle'])) {
Db::sql(
'update users left join stats on users.id = stats.id set battle = default, regHP = unix_timestamp(), team = 0, battle_yron = 0, battle_exp = 0 where users.id = ?',
[$this->targetUser['id']]
);
}
$this->status = "Ïåðñîíàæ $this->targetLogin çàáëîêèðîâàí";
$this->msg->setText("[img[items/pal_button6.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unban(): void
{
if (empty($this->targetUser['banned'])) {
$this->status = 'Ïåðñîíàæ íå â áëîêå.';
return;
}
$this->moderation->unban();
Db::sql('delete from ban_email where email = ?', [$this->targetUser['mail']]);
$this->status = "Ïåðñîíàæ $this->targetLogin ðàçáëîêèðîâàí";
$this->msg->setText("[img[items/pal_button7.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
}
+7 -7
View File
@@ -15,7 +15,7 @@ class Moderation
private const CENTRAL_SQUARE_ROOM = 9;
private const JAIL_STORAGE = 1357908642; /* Ух, костыль! */
private const NOT_SET = 'Не указано.';
private const EXPIRATION_DATETIME_FORMAT = 'd M Y H:i';
public const EXPIRATION_DATETIME_FORMAT = 'd M Y H:i';
private int $target;
public function __construct(int $userid)
@@ -26,7 +26,7 @@ class Moderation
/**
* Молчание
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
*/
public function silence(DateTime $expiration, string $reason = self::NOT_SET): void
{
@@ -59,7 +59,7 @@ class Moderation
/**
* Обезличивание
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
*/
public function depersonalize(DateTime $expiration, string $reason = self::NOT_SET): void
{
@@ -77,7 +77,7 @@ class Moderation
*/
public function undepersonalize(): void
{
if (Db::getValue('select count(info_delete) from users where id = ? and info_delete != 0', [$this->target]) === 0) {
if (Db::getValue('select count(info_delete) from users where id = ? and info_delete <= unix_timestamp()', [$this->target]) === 0) {
return;
}
Db::sql('update users set info_delete = default where id = ?', [$this->target]);
@@ -92,13 +92,13 @@ class Moderation
/**
* Тюрьма
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
* @todo Корректно выбрасывать игрока из подземелья.
*/
public function prison(DateTime $expiration, string $reason = self::NOT_SET): void
{
Db::sql('update users set jail = ?, room = ? where id = ?', [$expiration->getTimestamp(), self::JAIL_ROOM, $this->target,]);
Db::sql('update items_users set `delete` = ? where `delete` = 0 and uid = ?', [self::JAIL_STORAGE, $this->target,]);
Db::sql('update items_users set is_arrested = 1 where uid = ?', [$this->target,]);
Delo::add(
10,
'moderation.prison',
@@ -113,7 +113,7 @@ class Moderation
public function unprison(): void
{
Db::sql('update users set jail = default, room = ? where id = ?', [self::CENTRAL_SQUARE_ROOM, $this->target,]);
Db::sql('update items_users set `delete` = default where `delete` = ? and uid = ?', [self::JAIL_STORAGE, $this->target,]);
Db::sql('update items_users set is_arrested = default where uid = ?', [$this->target,]);
Delo::add(
10,
'moderation.unprison',
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace Moderation;
use Core\Db;
readonly class Moderator
{
public bool $isModerator;
public bool $canBlockUsers;
public bool $isAdmin;
public function __construct(int $uid)
{
[
'uid' => $isModerator,
'can_block_users' => $canBlockUsers,
'is_admin' => $isAdmin,
] = Db::getRow('select uid, can_block_users, is_admin from moderators where uid = ?', [$uid]);
$this->isModerator = !empty($isModerator);
$this->canBlockUsers = !empty($isModerator) && !empty($canBlockUsers);
$this->isAdmin = !empty($isModerator) && !empty($isAdmin);
}
public static function add(int $uid): void
{
$user = new Moderator($uid);
if ($user->isModerator) {
return;
}
Db::sql('insert into moderators (uid) value (?)', [$uid]);
}
public static function modify(int $uid, bool $allowBlock, bool $adminRights): void
{
$user = new Moderator($uid);
if (!$user->isModerator) {
return;
}
Db::sql('update moderators set can_block_users = ?, is_admin = ? where uid = ?', [(int)$allowBlock, (int)$adminRights, $uid]);
}
public static function delete(int $uid): void
{
Db::sql('delete from moderators where uid = ?', [$uid]);
}
}
@@ -0,0 +1,36 @@
<?php
namespace Moderation;
use Core\Db;
use DateTime;
use DateTimeImmutable;
use User;
class UserRegistrationList
{
public function get(DateTime $date)
{
$from = $date->getTimestamp();
$to = $date->modify('+ 1 day')->getTimestamp();
$list = Db::getRows("select id, banned, molch1, battle, host_reg, online from users where timereg between ? and ? and bot_id = 0 and bithday != '01.01.1800' order by id", [$from, $to]);
$str = '';
foreach ($list as $user) {
$time = new DateTime();
$loginColor = 'black';
if ($user['banned']) {
$loginColor = 'red';
}
if ($user['online'] > $time->modify('- 10 minutes')->getTimestamp()) {
$loginColor = 'green';
}
if ($user['molch1'] > 0) {
$molch1Duration = new DateTimeImmutable($user['molch1']);
}
$str .= "<li><span style='color: $loginColor'>" . User::getLogin($user['id'] . "</span>");
}
}
}