game/bankCronRestart.php
2022-06-07 00:30:34 +03:00

142 lines
3.9 KiB
PHP

<?php
/*
Îáíîâëåíèå äàííûõ î êóðñå âíóòðåíåé âàëþòû
*/
function getIP() {
if(isset($_SERVER['HTTP_X_REAL_IP'])) return $_SERVER['HTTP_X_REAL_IP'];
return $_SERVER['REMOTE_ADDR'];
}
# Ïîëó÷àåì IP
function getIPblock() {
if(isset($_SERVER['HTTP_X_REAL_IP'])) return $_SERVER['HTTP_X_REAL_IP'];
return $_SERVER['REMOTE_ADDR'];
}
# Âûïîëíÿåì ïðîâåðêó áåçîïàñíîñòè.
if(!isset($_GET['robot'])) {
//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() != '91.228.152.24') {
die(getIPblock().'<br>'.$_SERVER['SERVER_ADDR']);
}
}
//$curency = 5.21; //êóðñò 1 åêð. ê 1 ðóá. ðô.
$true = array(
'AUD' => true,
'AZN' => true,
'AMD' => true,
'BYR' => true,
'BGN' => true,
'BRL' => true,
'HUF' => true,
'KRW' => true,
'DKK' => true,
'USD' => true,
'EUR' => true,
'INR' => true,
'KZT' => true,
'CAD' => true,
'KGS' => true,
'CNY' => true,
'LVL' => true,
'LTL' => true,
'MDL' => true,
'RON' => true,
'TMT' => true,
'NOK' => true,
'PLN' => true,
'XDR' => true,
'SGD' => true,
'TJS' => true,
'TRY' => true,
'UZS' => true,
'UAH' => true,
'GBP' => true,
'CZK' => true,
'SEK' => true,
'CHF' => true,
'ZAR' => true,
'JPY' => true
);
define('GAME',true);
setlocale(LC_CTYPE ,"ru_RU.CP1251");
include('_incl_data/__config.php');
include('_incl_data/class/__db_connect.php');
//Îáíóëåíèå ïåðåäà÷ ðàç â ñóòêè
mysql_query('UPDATE `stats` SET `transfers` = 100 WHERE `transfers` < 200');
function str_count($str,$col) {
if (strlen($str) > $col)
{
$str = substr($str,0,$col);
}
return ($str);
}
function getCurs(){
// ñîçäàåì îáúåêò äëÿ ðàáîòû ñ XML
$xml = new DOMDocument();
// ññûëêà íà ñàéò áàíêà
$url = 'https://www.cbr.ru/scripts/XML_daily.asp?date_req=' . date('d.m.Y');
// ïîëó÷àåì xml ñ êóðñàìè âñåõ âàëþò
if ($xml->load($url)){
// ìàññèâ äëÿ õðàíåíèÿ êóðñîâ âàëþò
$result = array();
// ðàçáèðàåì xml
$root = $xml->documentElement;
// áåðåì âñå òåãè 'Valute' è èõ ñîäåðæèìîå
$items = $root->getElementsByTagName('Valute');
// ïåðåáåðåì òåãè 'Valute' ïî îäíîìó
foreach ($items as $item){
// ïîëó÷àåì êîä âàëþòû
$code = $item->getElementsByTagName('CharCode')->item(0)->nodeValue;
// ïîëó÷àåì çíà÷åíèå êóðñà âàëþòû, îòíîñèòåëüíî ðóáëÿ
$value = $item->getElementsByTagName('Value')->item(0)->nodeValue;
// íîìèíàë
$nominal = $item->getElementsByTagName('Nominal')->item(0)->nodeValue;
// çàïèñûâàåì â ìàññèâ, ïðåäâàðèòåëüíî çàìåíèâ çàïÿòóþ íà òî÷êó
$result[$code] = round(str_replace(',', '.', $value),5)/$nominal;
}
// âîçâðàùàåì çíà÷åíèå êóðñà, äëÿ çàïðîøåííîé âàëþòû
return $result;
}else{
// åñëè íå ïîëó÷èëè xml âîçâðàùàåì false
return false;
}
}
$get = getCurs();
//
if( $c['curency_name'] == 'RUB' ) {
$curency = $c['curency_value'];
}else{
$curency = round($get[$c['curency_name']]*$c['curency_value'],4);
}
//
if( $get['USD'] > 0 ) {
$price = array(
'AUD','AZN','AMD','BYR','BGN','BRL','HUF','KRW','DKK','USD','EUR','INR','KZT','CAD','KGS','CNY','LVL','LTL','MDL','RON','TMT','NOK','PLN','XDR','SGD','TJS','TRY','UZS','UAH','GBP','CZK','SEK','CHF','ZAR','JPY'
);
$i = 0;
while( $i < count($price) ) {
if( isset($price[$i]) && $get[$price[$i]] > 0 ) {
if( $price[$i] == 'UAH' || $price[$i] == 'BYR' ) {
//$get[$price[$i]] -= round($get[$price[$i]]/6,4);
}
$r .= ',`'.$price[$i].'`="'.$get[$price[$i]].'"';
}
$i++;
}
//echo 'INSERT INTO `bank_table` SET `time` = "'.time().'",`cur` = "'.$curency.'",`data` = "'.date('d.m.Y').'"'.$r.'<br>';
mysql_query('INSERT INTO `bank_table` SET `time` = "'.time().'",`cur` = "'.$curency.'",`data` = "'.date('d.m.Y').'"'.$r.'');
}
?>