Регистратура объединяется со вкладкой кланы. #54. Closes #56.

This commit is contained in:
2023-07-19 15:36:13 +03:00
parent 1500eb9364
commit 92772463e6
22 changed files with 844 additions and 522 deletions
+2 -2
View File
@@ -3,8 +3,8 @@
use Core\Config;
use Insallah\Tournaments\Tournament;
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 'Off');
//error_reporting(E_ALL);
date_default_timezone_set('Europe/Moscow');
header('Cache-Control: no-cache, no-store, must-revalidate');
+1
View File
@@ -1,5 +1,6 @@
<?php
//error_reporting(E_ALL);
const GAME = true; // Для совместимости с этой "защитой".
const GAME_VERSION = 'alpha-7.4';
// Новая автозагрузка.
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Clan;
use Core\Db;
class ClanInfo
{
public static function isJoinable(string $name): bool
{
return Db::getValue('select count(name) from clan where name = ? and status = 1', [$name]) > 0;
}
}
+17 -17
View File
@@ -14,7 +14,7 @@ class ItemStorage
private function isGoodForStorage(array $item, $userClanId): bool
{
if (empty($item['inslot']) || !empty($item['gift'])) {
$this->error = 'Ïðåäìåò íå íàéäåí.';
$this->error = 'Предмет не найден.';
}
$idata = ConversionHelper::dataStringToArray($item['data']);
if (
@@ -23,10 +23,10 @@ class ItemStorage
!empty($idata['icos']) ||
!empty($idata['fromlaba'])
) {
$this->error = 'Ïðåäìåò íå ïîäõîäèò.';
$this->error = 'Предмет не подходит.';
}
if (!empty($idata['toclan']) && explode('#', $idata['toclan'])[0] == $userClanId) {
$this->error = 'Ïðåäìåò óæå ïðèíàäëåæèò êëàíó.';
$this->error = 'Предмет уже принадлежит клану.';
}
return empty($this->error);
}
@@ -37,7 +37,7 @@ class ItemStorage
$item = ItemsModel::getOwnedItemById($itemId, $user['id']);
$clanName = Db::getValue('select name from clan where id = ?', [$clanId]) ?? '';
if (empty($clanName)) {
return 'Êëàí íå íàéäåí.';
return 'Клан не найден.';
}
if (!$this->isGoodForStorage($item, $user['clan'])) {
return $this->error;
@@ -50,7 +50,7 @@ class ItemStorage
User::start()->addDelo(
2,
$user['id'],
'&quot;System.transfer.MONEY&quot;: Ïðåäìåò &quot;' . $item['name'] . '&quot; (#id : "' . $itemId . '") (x' . $col . ') áûë ïîæåðòâîâàí êëàíó &quot;' . $clanName . '&quot; (' . $clanId . ').',
'&quot;System.transfer.MONEY&quot;: Предмет &quot;' . $item['name'] . '&quot; (#id : "' . $itemId . '") (x' . $col . ') был пожертвован клану &quot;' . $clanName . '&quot; (' . $clanId . ').',
time(),
$user['city'],
'System.transfer.clan',
@@ -63,14 +63,14 @@ class ItemStorage
}
Db::sql(
'insert into clan_operations (clan, time, type, text, val, uid) values (?,unix_timestamp(),?,?,?,?)',
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col Èä: [$itemId]"), $user['id']]
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col Ид: [$itemId]"), $user['id']]
);
Db::sql(
'update items_users set lastUPD = unix_timestamp(), uid = ?, data = ? where id = ?',
['-21' . $user['clan'], $item['data'], $itemId]
);
return 'Âû ïåðåäàëè ïðåäìåò &quot;' . $item['name'] . '&quot; êëàíó.';
return 'Вы передали предмет &quot;' . $item['name'] . '&quot; клану.';
}
@@ -86,7 +86,7 @@ class ItemStorage
mysql_query('SELECT `id`,`bot`,`clone` FROM `stats` WHERE `id` = "' . $itm_['uid'] . '" LIMIT 1')
);
if ($user_itm['bot'] > 0 || $user_itm['clone'] > 0 || !isset($user_itm['id'])) {
$r = '<font color="#FF0000"><strong>Âû íå ìîæåòå èçüÿòü äàííûé ïðåäìåò, îí íå ïðèíàäëåæèò êëàíó</strong></font><br />';
$r = '<font color="#FF0000"><strong>Вы не можете изьять данный предмет, он не принадлежит клану</strong></font><br />';
} elseif (isset($itm_['id'])) {
if ($itm_['inOdet'] != 0) {
@@ -94,11 +94,11 @@ class ItemStorage
} else {
$o = '';
}
$r = '<font color="#FF0000"><strong>Âû óñïåøíî èçúÿëè ïðåäìåò &quot;' . $itm_['name'] . '&quot;</strong></font><br />';
$r = '<font color="#FF0000"><strong>Вы успешно изъяли предмет &quot;' . $itm_['name'] . '&quot;</strong></font><br />';
$col = $this->itemsX(((int)$id));
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "6", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] | Ó ïåðñîíàæà : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
) . '", "6", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Ид : [' . $id . '] | У персонажа : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
@@ -106,7 +106,7 @@ class ItemStorage
);
} else {
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />';
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />';
}
return $r;
}
@@ -129,16 +129,16 @@ class ItemStorage
$col = $this->itemsX(((int)$id));
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "5", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] Õîçÿèí : [' . $cls . ']", "' . $user['id'] . '")'
) . '", "5", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Ид : [' . $id . '] Хозяин : [' . $cls . ']", "' . $user['id'] . '")'
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
) . '", `uid` = "' . $user['id'] . '" WHERE `id` = "' . $id . '" LIMIT 1'
);
$r = '<font color="#FF0000"><strong>Âû óñïåøíî âçÿëè ïðåäìåò &quot;' . $itm_['name'] . '&quot; èç õðàíèëèùà</strong></font><br />';
$r = '<font color="#FF0000"><strong>Вы успешно взяли предмет &quot;' . $itm_['name'] . '&quot; из хранилища</strong></font><br />';
} else {
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />' . $id;
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />' . $id;
}
return $r;
}
@@ -172,7 +172,7 @@ class ItemStorage
);
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
) . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Ид : [' . $pl['id'] . ']", "' . $user['id'] . '")'
);
} elseif ($pl['uid'] == $user['id']) {
$col = $this->itemsX(((int)$pl['id']));
@@ -185,9 +185,9 @@ class ItemStorage
);
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
) . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Ид : [' . $pl['id'] . ']", "' . $user['id'] . '")'
);
}
}
}
}
}
+136
View File
@@ -0,0 +1,136 @@
<?php
namespace Clan;
use Core\Config;
use Core\Db;
use Uploader;
class Register
{
const REGISTER_COST_EKR = 50;
private string $name;
private int $align = 0;
private Uploader $logo;
private int $newClanId = 0;
/**
* @return int
*/
public function getNewClanId(): int
{
return $this->newClanId;
}
public function __construct()
{
if (!isset($_POST['newclanname'], $_POST['newclanalign'], $_FILES['newclanlogo'])) {
return;
}
$this->setName($_POST['newclanname']);
$this->setLogo();
$this->setAlign(intval($_POST['newclanalign']));
$this->new();
}
private function hasGoodName(): bool
{
return Db::getValue('select count(id) from clan where name = ?', [$this->name]) === 0;
}
public function new()
{
if (!$this->hasGoodName()) {
return;
}
$imageId = $this->logo->saveToDb();
if (!$imageId) {
echo $this->logo::$error;
return;
}
Db::sql('insert into clan (name, align, logo) values (?,?,?)', [$this->name, $this->align, $imageId]);
$this->newClanId = Db::lastInsertId();
}
public static function approve(int $clanId)
{
Db::sql('update clan set status = 1, time_reg = unix_timestamp() where id = ?', [$clanId]);
}
public static function reject(int $clanId)
{
Db::sql('delete from clan where id = ?', [$clanId]);
}
public static function printForm(): string
{
$img = Config::img() . '/i/align';
return <<<REGISTERFORM
<style>
div.regclangrid [type=radio] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
/* IMAGE STYLES */
div.regclangrid [type=radio] + img {
cursor: pointer;
}
/* CHECKED STYLES */
div.regclangrid [type=radio]:checked + img {
outline: 1px solid brown;
padding: 2px;
}
div.regclangrid {
display: grid;
grid-template-columns: 100px auto;
}
</style>
<form method="POST" enctype="multipart/form-data">
<div class="regclangrid">
<div><label for="clanname">Название:</label></div>
<div><input name="newclanname" id="clanname"></div>
<div><label for="clanlogo">Логотип:</label></div>
<div><input type="file" name="newclanlogo" accept="image/*" id="newclanlogo"> размер: 24×15, формат: png или gif, до 30Кб</div>
<div>Склонность:</div>
<div>
<label><input type="radio" name="newclanalign" value="0" checked><img src="$img/align0.gif" alt="none"></label>
<label><input type="radio" name="newclanalign" value="1"><img src="$img/align1.gif" alt="light"></label>
<label><input type="radio" name="newclanalign" value="3"><img src="$img/align3.gif" alt="dark"></label>
<label><input type="radio" name="newclanalign" value="7"><img src="$img/align7.gif" alt="neutral"></label>
</div>
<div></div>
<div><button type="submit">Подать заявку</button></div>
</div>
</form>
REGISTERFORM;
}
private function setName(string $name)
{
$this->name = $name;
}
private function setAlign(int $align)
{
if (!in_array($align, [0, 1, 3, 7])) {
$align = 0;
}
$this->align = $align;
}
private function setLogo()
{
$this->logo = new Uploader('newclanlogo');
$this->logo->setMaxFileSize(.03);
$this->logo->setDimensions(24, 15);
$this->logo->setExtentions(['gif', 'png']);
}
}
+6 -6
View File
@@ -2,7 +2,6 @@
namespace Core;
use Exception;
use PDO;
use PDOException;
use PDOStatement;
@@ -15,14 +14,14 @@ class Db
/**
* DB constructor.
* @throws Exception
* @throws PDOException
*/
public function __construct()
{
try {
self::$db = Database::pdoinit();
} catch (PDOException $e) {
throw new Exception($e->getMessage());
throw new PDOException($e->getMessage());
}
}
@@ -55,19 +54,20 @@ class Db
* @param string $query
* @return int
*/
static public function exec(string $query): int
public static function exec(string $query): int
{
self::init();
return self::$db->exec($query);
}
/**
* @param ?string $name [optional] Name of the sequence object from which the ID should be returned.
* @return string
*/
static public function lastInsertId(): string
public static function lastInsertId(?string $name = null): string
{
self::init();
return self::$db->lastInsertId();
return self::$db->lastInsertId($name);
}
/**
+27
View File
@@ -0,0 +1,27 @@
<?php
use Core\Db;
class Images
{
public static function getSrc(int $id): string
{
$i = Db::getRow('select mime_type, img from images where id = ?', [$id]);
return 'data:' . $i['mime_type'] . ';base64,' . base64_encode($i['img']);
}
public static function getSrcByName(string $name): string
{
$i = Db::getRow('select mime_type, img from images where id = (select logo from clan where name = ?)', [$name]);
return 'data:' . $i['mime_type'] . ';base64,' . base64_encode($i['img']);
}
public static function getJson(int $id)
{
$stmt = Db::getRow('select mime_type, img from images where id = ?', [$id]);
if (!$stmt) {
$stmt = [];
}
return json_encode($stmt);
}
}
+41 -16
View File
@@ -1,5 +1,7 @@
<?php
use Core\Db;
/**
* Единая функция для заливки файлов на сервер.
*
@@ -15,21 +17,29 @@ class Uploader
private string $savePath;
private string $extensions = 'jpg|png|jpeg|gif';
private array $extMatches = [];
private array $FILE;
private $cnm;
private array $file;
private string $customName;
public static string $error;
public function __construct($name, $cnm = null)
/**
* @param string $customName
*/
public function setCustomName(string $customName): void
{
$this->customName = $customName;
}
public function __construct($name)
{
if (!isset($_FILES[$name])) {
return;
}
$this->FILE = $_FILES[$name];
$this->cnm = $cnm;
$this->file = $_FILES[$name];
}
/**
* @param int $max
* @param int $max
* @param int|null $min
* @return void
*/
@@ -40,7 +50,7 @@ class Uploader
}
/**
* @param int $max
* @param int $max
* @param int|null $min
* @return void
*/
@@ -98,7 +108,7 @@ class Uploader
private function hasNormalDimensions(): bool
{
[$width, $height] = getimagesize($this->FILE['tmp_name']);
[$width, $height] = getimagesize($this->file['tmp_name']);
if (!$width || !$height) {
self::$error = 'Не подтянулись размеры файла.';
return false;
@@ -123,7 +133,7 @@ class Uploader
if (!$this->maxFileSizeMb) {
$this->setMaxFileSize(2);
}
if ($this->FILE['size'] > $this->maxFileSizeMb * (1024 * 1024) || $this->FILE['size'] <= 0) {
if ($this->file['size'] > $this->maxFileSizeMb * (1024 * 1024) || $this->file['size'] <= 0) {
self::$error = 'Неверный размер файла. Максимальный размер файла ' . $this->maxFileSizeMb . ' МБ';
return false;
}
@@ -133,8 +143,8 @@ class Uploader
private function hasNormalType(): bool
{
if (
!preg_match('/\.(' . $this->extensions . ')$/i', $this->FILE['name'], $this->extMatches) ||
!preg_match('/image/i', $this->FILE['type'])
!preg_match('/\.(' . $this->extensions . ')$/i', $this->file['name'], $this->extMatches) ||
!preg_match('/image/i', $this->file['type'])
) {
self::$error = 'Неверный тип файла. Допустимые типы : ' . $this->extensions;
return false;
@@ -156,17 +166,25 @@ class Uploader
$this->extMatches[1] = strtolower($this->extMatches[1]);
$fn = uniqid('f_', true) . '.' . $this->extMatches[1];
$fn2 = uniqid('f_', true) . '.gif';
if ($this->cnm) {
$fn = $this->cnm;
$fn2 = $this->cnm;
if ($this->customName) {
$fn = $this->customName . '.' . pathinfo($this->file['name'], PATHINFO_EXTENSION);
$fn2 = $this->customName;
}
if (!move_uploaded_file($this->FILE['tmp_name'], $this->savePath . $fn)) {
if (!move_uploaded_file($this->file['tmp_name'], $this->savePath . $fn)) {
self::$error = 'Ошибка загрузки файла';
return false;
}
var_dump([$fn2, $fn, $this->savePath . $fn]);
return [$fn2, $fn, $this->savePath . $fn];
}
private function uploadToDatabase(): int
{
$id = time();
Db::sql('insert into images (mime_type, img, id) VALUES (?,?,?)', [$this->file['type'], file_get_contents($this->file['tmp_name']), $id]);
return $id;
}
public function saveimg()
{
return $this->hasNormalFilePath() &&
@@ -174,4 +192,11 @@ class Uploader
$this->hasNormalFileSize() &&
$this->hasNormalType() ? $this->upload() : false;
}
}
public function saveToDb()
{
return $this->hasNormalDimensions() &&
$this->hasNormalFileSize() &&
$this->hasNormalType() ? $this->uploadToDatabase() : false;
}
}
+14 -29
View File
@@ -1276,18 +1276,19 @@ class User
return $plid;
}
public function microLogin2(array $userInfo): string
private function microLogin2(array $userInfo): string
{
$result = '';
if ($userInfo['align'] > 0) {
$result .= '<img src=' . Config::img() . '/i/align/align' . $userInfo['align'] . '.gif>';
}
if ($userInfo['clan'] > 0) {
$clanName = Db::getValue('select name_mini from clan where id = ?', [$userInfo['clan']]);
$result .= '<img src=' . Config::img() . '/i/clan/' . $clanName . '.gif>';
$result .= '<img src=' . Images::getSrc($userInfo['clan']) . ' alt="'. $userInfo['clanName'] .'">';
}
$result .= '<strong>' . $userInfo['login'] . '</strong>[' . $userInfo['level'] . ']';
$result .= '<a target=_blank href=/info/' . $userInfo['id'] . ' ><img src=' . Config::img() . '/i/inf_capitalcity.gif alt=""></a>';
if ($userInfo['login'] !== '<em>невидимка</em>') {
$result .= '<a target=_blank href=/info/' . $userInfo['id'] . ' ><img src=' . Config::img() . '/i/inf_capitalcity.gif alt=""></a>';
}
return $result;
}
@@ -1298,33 +1299,17 @@ class User
} else {
$inf = Db::getRow(
'select
users.id,
invis,
users.align,
align2,
clan,
cityreg,
login,
users.level,
c.name_mini
from users left join clan as c on c.id = users.clan
where users.id = ?',
[$id]
users.id,
if(invis = 1 or invis < unix_timestamp(), login, ?) as login,
if(invis = 1 or invis < unix_timestamp(), users.align, 0) as align,
if(status > 0, clan, 0) as clan,
if(invis = 1 or invis < unix_timestamp(), users.level, ?) as level,
if(status > 0, clan.name, ?) as clanName
from users left join clan on clan.id = users.clan and status > 0 where users.id = ?',
['<em>невидимка</em>', '??', '', $id]
);
}
$r = '';
if (
isset($inf['id']) &&
(
($inf['invis'] < time() && $inf['invis'] !== 1) ||
($this->info['id'] == $inf['id'] && $nnz === 1)
)
) {
$r = $this->microLogin2($inf);
} else {
$r = '<strong><i>Невидимка</i></strong> [??]';
}
return $r;
return isset($inf['id']) ? $this->microLogin2($inf) : '';
}
public function testHome(): array
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace User;
use Clan\ClanInfo;
use Core\Config;
use Core\Db;
use Images;
class Clan
{
private $userid;
private int $id = 0;
private ?string $name;
private ?int $align;
private ?int $logo;
private ?int $status;
public function __construct(array $userinfo)
{
$this->userid = $userinfo['id'];
if (isset($_POST['joinclan']) && ClanInfo::isJoinable($_POST['joinclan'])) {
$this->join($_POST['joinclan']);
exit('<script>window.location.replace("/main.php?clan=1");</script>');
}
$c = Db::getRow('select * from clan where id = ?', [$userinfo['clan']]);
if (!empty($c)) {
foreach ($c as $k => $v) {
$this->$k = $v;
}
}
}
private function join(string $clanname)
{
Db::sql('update users set clan = (select id from clan where clan.name = ?) where id = ?', [$clanname, $this->userid]);
}
public function getId(): int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function getAlign(): ?int
{
return $this->align;
}
public function printLogoImage(): string
{
return '<img style="vertical-align:text-bottom;" src = "'. Images::getSrc($this->logo) . '" width = "24px" height = "15px">';
}
public function getStatus(): ?int
{
return $this->status;
}
public function printClan()
{
echo '<img style="vertical-align:text-bottom;" src="' . Config::img() . '/i/align/align' . $this->getAlign() . '.gif" alt="Склонность">' . $this->printLogoImage() . $this->getName();
}
public function getLogo(): ?int
{
return $this->logo;
}
/**
* Клан зарегистрирован и подверждён.
* @return bool
*/
public function isRegistered(): bool
{
return !empty($this->id) && $this->status !== 0;
}
/**
* Клан зарегистрирован и ожидает подтверждения.
* @return bool
*/
public function isAwaitingConfirmation(): bool
{
return !empty($this->id) && $this->status === 0;
}
}
-1
View File
@@ -91,7 +91,6 @@ function delete_user_all( $uid , $login ) {
mysql_query('DELETE FROM `obraz` WHERE `uid` = "'.$uid.'" OR `login` = "'.$login.'"');
mysql_query('DELETE FROM `online` WHERE `uid` = "'.$uid.'"');
mysql_query('DELETE FROM `pirogi` WHERE `uid` = "'.$uid.'"');
mysql_query('DELETE FROM `post` WHERE `uid` = "'.$uid.'"');
mysql_query('DELETE FROM `reimage` WHERE `uid` = "'.$uid.'"');
mysql_query('DELETE FROM `rep` WHERE `uid` = "'.$uid.'"');
mysql_query('DELETE FROM `repass` WHERE `uid` = "'.$uid.'"');