193 lines
8.6 KiB
PHP
193 lines
8.6 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace Clan;
|
|||
|
|
|||
|
use Core\ConversionHelper;
|
|||
|
use Core\Db;
|
|||
|
use User;
|
|||
|
use User\ItemsModel;
|
|||
|
|
|||
|
class ItemStorage
|
|||
|
{
|
|||
|
private string $error = '';
|
|||
|
|
|||
|
private function isGoodForStorage(array $item, $userClanId): bool
|
|||
|
{
|
|||
|
if (empty($item['inslot']) || !empty($item['gift'])) {
|
|||
|
$this->error = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.';
|
|||
|
}
|
|||
|
$idata = ConversionHelper::dataStringToArray($item['data']);
|
|||
|
if (
|
|||
|
!empty($idata['frompisher']) ||
|
|||
|
!empty($idata['sudba']) ||
|
|||
|
!empty($idata['icos']) ||
|
|||
|
!empty($idata['fromlaba'])
|
|||
|
) {
|
|||
|
$this->error = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.';
|
|||
|
}
|
|||
|
if (!empty($idata['toclan']) && explode('#', $idata['toclan'])[0] == $userClanId) {
|
|||
|
$this->error = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>.';
|
|||
|
}
|
|||
|
return empty($this->error);
|
|||
|
}
|
|||
|
|
|||
|
public function put(int $itemId, int $clanId): string
|
|||
|
{
|
|||
|
$user = User::start()->info;
|
|||
|
$item = ItemsModel::getOwnedItemById($itemId, $user['id']);
|
|||
|
$clanName = Db::getValue('select name from clan where id = ?', [$clanId]) ?? '';
|
|||
|
if (empty($clanName)) {
|
|||
|
return '<27><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.';
|
|||
|
}
|
|||
|
if (!$this->isGoodForStorage($item, $user['clan'])) {
|
|||
|
return $this->error;
|
|||
|
}
|
|||
|
$col = User::start()->itemsX(($itemId));
|
|||
|
$idata = ConversionHelper::dataStringToArray($item['data']);
|
|||
|
if (!isset($idata['toclan'])) {
|
|||
|
$idata['toclan'] = $user['clan'] . '#' . $user['id'];
|
|||
|
$item['data'] = ConversionHelper::arrayToDataString($idata);
|
|||
|
User::start()->addDelo(
|
|||
|
2,
|
|||
|
$user['id'],
|
|||
|
'"System.transfer.MONEY": <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "' . $item['name'] . '" (#id : "' . $itemId . '") (x' . $col . ') <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> "' . $clanName . '" (' . $clanId . ').',
|
|||
|
time(),
|
|||
|
$user['city'],
|
|||
|
'System.transfer.clan',
|
|||
|
0,
|
|||
|
0
|
|||
|
);
|
|||
|
$sendType = 4;
|
|||
|
} else {
|
|||
|
$sendType = 3;
|
|||
|
}
|
|||
|
Db::sql(
|
|||
|
'insert into clan_operations (clan, time, type, text, val, uid) values (?,unix_timestamp(),?,?,?,?)',
|
|||
|
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col <20><>: [$itemId]"), $user['id']]
|
|||
|
);
|
|||
|
Db::sql(
|
|||
|
'update items_users set lastUPD = unix_timestamp(), uid = ?, data = ? where id = ?',
|
|||
|
['-21' . $user['clan'], $item['data'], $itemId]
|
|||
|
);
|
|||
|
|
|||
|
return '<27><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "' . $item['name'] . '" <20><><EFBFBD><EFBFBD><EFBFBD>.';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public function ungive_itm_cl($id, $user, $cl): string
|
|||
|
{
|
|||
|
$itm_ = mysql_fetch_array(
|
|||
|
mysql_query(
|
|||
|
'SELECT `iu`.*, `im`.* FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON `iu`.`item_id` = `im`.`id` WHERE `iu`.`uid` >= 0 AND `iu`.`delete` = 0 AND `iu`.`id` = "' . $id . '" LIMIT 1'
|
|||
|
)
|
|||
|
);
|
|||
|
$res = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "' . $cl . '" LIMIT 1'));
|
|||
|
$user_itm = mysql_fetch_array(
|
|||
|
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><3E><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD></strong></font><br />';
|
|||
|
} elseif (isset($itm_['id'])) {
|
|||
|
|
|||
|
if ($itm_['inOdet'] != 0) {
|
|||
|
$o = ', `inOdet` = 0';
|
|||
|
} else {
|
|||
|
$o = '';
|
|||
|
}
|
|||
|
$r = '<font color="#FF0000"><strong><3E><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "' . $itm_['name'] . '"</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 . ') <20><> : [' . $id . '] | <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
|||
|
) . '", `uid` = "-21' . $res['id'] . '" ' . $o . ' WHERE `id` = "' . $id . '" LIMIT 1'
|
|||
|
);
|
|||
|
|
|||
|
} else {
|
|||
|
$r = '<font color="#FF0000"><strong><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.</strong></font><br />';
|
|||
|
}
|
|||
|
return $r;
|
|||
|
}
|
|||
|
|
|||
|
public function take_itm_cl($id, $user, $cl): string
|
|||
|
{
|
|||
|
$itm_ = mysql_fetch_array(
|
|||
|
mysql_query(
|
|||
|
'SELECT `iu`.*, `im`.* FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON `iu`.`item_id` = `im`.`id` WHERE `iu`.`uid` = "-21' . $user['clan'] . '" AND `iu`.`delete` = 0 AND `iu`.`id` = "' . $id . '" LIMIT 1'
|
|||
|
)
|
|||
|
);
|
|||
|
$res = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "' . $cl . '" LIMIT 1'));
|
|||
|
if (isset($itm_['id'])) {
|
|||
|
$po = ConversionHelper::dataStringToArray($itm_['data']);
|
|||
|
if (isset($po['toclan'])) {
|
|||
|
$cls = explode('#', $po['toclan']);
|
|||
|
$cls = $cls[1];
|
|||
|
}
|
|||
|
|
|||
|
$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 . ') <20><> : [' . $id . '] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : [' . $cls . ']", "' . $user['id'] . '")'
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
|||
|
) . '", `uid` = "' . $user['id'] . '" WHERE `id` = "' . $id . '" LIMIT 1'
|
|||
|
);
|
|||
|
$r = '<font color="#FF0000"><strong><3E><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "' . $itm_['name'] . '" <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></strong></font><br />';
|
|||
|
|
|||
|
} else {
|
|||
|
$r = '<font color="#FF0000"><strong><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.</strong></font><br />' . $id;
|
|||
|
}
|
|||
|
return $r;
|
|||
|
}
|
|||
|
|
|||
|
public function rem_itm_cl($user, $cl, $type)
|
|||
|
{
|
|||
|
$itms = mysql_query(
|
|||
|
'SELECT * FROM `items_users` WHERE (`uid` = "-21' . $user['clan'] . '" OR `data` LIKE "%toclan=' . $user['clan'] . '#%")'
|
|||
|
);
|
|||
|
while ($pl = mysql_fetch_array($itms)) {
|
|||
|
$po = ConversionHelper::dataStringToArray($pl['data']);
|
|||
|
if (isset($po['toclan'])) {
|
|||
|
$cls = explode('#', $po['toclan']);
|
|||
|
$cls = $cls[1];
|
|||
|
}
|
|||
|
if ($cls == $user['id']) {
|
|||
|
if ($pl['uid'] != $user['id']) {
|
|||
|
if ($pl['inOdet'] != 0) {
|
|||
|
mysql_query('UPDATE `items_users` SET `inOdet` = 0 WHERE `id` = "' . $pl['id'] . '"');
|
|||
|
}
|
|||
|
}
|
|||
|
unset($po['toclan']);
|
|||
|
$pl['data'] = ConversionHelper::arrayToDataString($po);
|
|||
|
$col = $this->itemsX(((int)$pl['id']));
|
|||
|
$it_n = mysql_fetch_array(
|
|||
|
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
|||
|
) . '", `uid` = "' . $user['id'] . '", `data` = "' . $pl['data'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
|||
|
) . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') <20><> : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
|||
|
);
|
|||
|
} elseif ($pl['uid'] == $user['id']) {
|
|||
|
$col = $this->itemsX(((int)$pl['id']));
|
|||
|
$it_n = mysql_fetch_array(
|
|||
|
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'UPDATE `items_users` SET `lastUPD` = "' . time(
|
|||
|
) . '", `uid` = "-21' . $user['clan'] . '" WHERE `id` = "' . $pl['id'] . '"'
|
|||
|
);
|
|||
|
mysql_query(
|
|||
|
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
|
|||
|
) . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') <20><> : [' . $pl['id'] . ']", "' . $user['id'] . '")'
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|