game/cron_psh.php
2022-12-19 20:26:14 +02:00

112 lines
4.4 KiB
PHP

<?php
function getIP()
{
return getIPblock();
}
# Ïîëó÷àåì IP
function getIPblock()
{
if (isset($_SERVER['HTTP_X_REAL_IP'])) {
return $_SERVER['HTTP_X_REAL_IP'];
}
return $_SERVER['REMOTE_ADDR'];
}
# Âûïîëíÿåì ïðîâåðêó áåçîïàñíîñòè.
if ($_SERVER['HTTP_CF_CONNECTING_IP'] != $_SERVER['SERVER_ADDR'] && $_SERVER['HTTP_CF_CONNECTING_IP'] != '127.0.0.1') {
die('Hello pussy!');
}
if (getIPblock() != $_SERVER['SERVER_ADDR'] && getIPblock() != '127.0.0.1' && getIPblock() != '' && getIPblock(
) != '5.187.7.71') {
die(getIPblock() . '<br>' . $_SERVER['SERVER_ADDR']);
}
const GAME = true;
require_once('_incl_data/__config.php');
require_once('_incl_data/class/__db_connect.php');
$d = new Dungeon;
$d->start();
function send_chat($type, $from, $text, $time)
{
mysql_query(
'INSERT INTO `chat` (`text`,`city`,`login`,`to`,`type`,`new`,`time`,`room`) VALUES ("' . mysql_real_escape_string(
$text
) . '","capitalcity","' . mysql_real_escape_string(
$from
) . '","","' . $type . '","1","' . mysql_real_escape_string($time) . '","3")'
);
}
//Ðîçûãðûø ïðåäìåòîâ
$sp = mysql_query('SELECT * FROM `dungeon_items` WHERE `user` = 0 AND `take` = 0');
while ($pl = mysql_fetch_array($sp)) {
$fxv = ['itm' => mysql_fetch_array(
mysql_query(
'SELECT `im`.*,`ish`.* FROM `dungeon_items` AS `ish` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `ish`.`item_id`) WHERE `ish`.`id` = "' . mysql_real_escape_string(
$pl['id']
) . '" AND `ish`.`take` = "0" AND `ish`.`delete` = "0" LIMIT 1'
)
), 'luck_count' => mysql_fetch_array(
mysql_query(
'SELECT COUNT(*) FROM `dungeon_actions` WHERE `dn` = "' . $pl['dn'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string(
$pl['id']
) . '" LIMIT 1'
)
), 'user_count' => mysql_fetch_array(
mysql_query('SELECT COUNT(*) FROM `stats` WHERE `dnow` = "' . $pl['dn'] . '" LIMIT 1')
)];
$fxv['luck_count'] = $fxv['luck_count'][0];
$fxv['user_count'] = $fxv['user_count'][0];
if ($fxv['itm']['user'] <= 0 && $fxv['luck_count'] >= 1 && ($fxv['luck_count'] >= $fxv['user_count'] || $fxv['itm']['time'] + 300 < time(
))) {
$fxv['sp'] = mysql_query(
'SELECT * FROM `dungeon_actions` WHERE `dn` = "' . $pl['dn'] . '" AND `vars` = "luck_itm' . mysql_real_escape_string(
$pl['id']
) . '" ORDER BY `vals` DESC LIMIT ' . $fxv['luck_count']
);
$fxv['winner'] = [];
$fxv['win_val'] = 0;
while ($fxv['pl'] = mysql_fetch_array($fxv['sp'])) {
if ($fxv['pl']['vals'] > $fxv['win_val']) {
//Ïîáåäèòåëü
unset($fxv['winner']);
$fxv['winner'][] = $fxv['pl']['uid'];
$fxv['win_val'] = $fxv['pl']['vals'];
} elseif ($fxv['pl']['vals'] > 0 && $fxv['pl']['vals'] == $fxv['win_val']) {
//íè÷üÿ
$fxv['winner'][] = $fxv['pl']['uid'];
}
}
unset($fxv['pl'], $fxv['sp']);
if (count($fxv['winner']) > 1) {
//Ðîçûãðûø åùå ðàç ìåæäó ïîáåäèòåëÿìè
$fxv['text'] = 'test2';
} elseif (count($fxv['winner']) == 1) {
$fxv['user_win'] = mysql_fetch_array(
mysql_query(
'SELECT `id`,`login`,`sex`,`city`,`room` FROM `users` WHERE `id` = "' . $fxv['winner'][0] . '" LIMIT 1'
)
);
$fxv['text'] = '<b>' . $fxv['user_win']['login'] . '</b> âûèãðûâàåò â ñïîðå çà ïðåäìåò &quot;' . $fxv['itm']['name'] . '&quot;';
mysql_query(
"INSERT INTO `chat` (`dn`,`city`,`room`,`login`,`to`,`text`,`time`,`type`,`toChat`,`typeTime`,`new`) VALUES ('" . $pl['dn'] . "','" . $fxv['user_win']['city'] . "','" . $fxv['user_win']['room'] . "','','','" . $fxv['text'] . "','" . time(
) . "','6','0','1','1')"
);
mysql_query(
'UPDATE `dungeon_items` SET `time` = "' . time(
) . '",`user` = "' . $fxv['user_win']['id'] . '" WHERE `id` = "' . $fxv['itm']['id'] . '" LIMIT 1'
);
} else {
//Ëþáîé ìîæåò ïîäîáðàòü ïðåäìåò
mysql_query('UPDATE `dungeon_items` SET `user` = "1" WHERE `id` = "' . $pl['id'] . '" LIMIT 1');
}
}
unset($fxv);
}