<?php

/*

	Ядро для обработки данных.
	Обработка поединков, обработка заявок, обработка ботов, обработка пещер, обработка турниров, обработка временных генераций

*/

if(isset($_GET['m1'])) {
	define('GAME',true);
	
	setlocale(LC_CTYPE ,"ru_RU.CP1251");
	
	include('_incl_data/__config.php');
	include('_incl_data/class/__db_connect.php');
	
	$sp = mysql_query('SELECT * FROM `users_recombats` WHERE `email` != "" ORDER BY `name` DESC LIMIT 7000');
	while( $pl = mysql_fetch_array($sp) ) {
		echo "<br>".$pl['email'];
	}
}elseif(isset($_GET['bk1'])) {
	define('GAME',true);
	
	setlocale(LC_CTYPE ,"ru_RU.CP1251");
	
	include('_incl_data/__config.php');
	include('_incl_data/class/__db_connect.php');
	include('_incl_data/class/__user.php');
	
	$ins = 'Вещи БК-1:<hr>';
	$sp = mysql_query('SELECT * FROM `items_main` WHERE `geni` = 1');
	while( $pl = mysql_fetch_array($sp) ) {
		
		$po = mysql_fetch_array(mysql_query('SELECT * FROM `items_main_data` WHERE `items_id` = "'.$pl['id'].'" LIMIT 1'));
		$po = $u->lookStats($po['data']);
		
		if(!isset($po['add_minAtack']) && isset($po['sv_minAtack'])) {
			$po['add_minAtack'] = $po['sv_minAtack'];
			$po['add_maxAtack'] = $po['sv_maxAtack'];
		}
		
		$ins .= 'INSERT INTO `items_main` (
				`id`, `name`, `img`, `art`, `type`, `inslot`, `use_magic`, `price`, `price2`, `iznosMAXi`, `massa`, `tr_level`, `tr_s1`, `tr_s2`, `tr_s3`, `tr_s4`, `tr_s5`, `tr_s6`, `add_s1`, `add_s2`, `add_s3`, `add_s4`, `add_s5`, `add_s6`, `add_hp`, `add_mp`, `add_m1`, `add_m2`, `add_m3`, `add_m4`, `add_b1`, `add_b2`, `add_b3`, `add_b4`, `add_attack_min`, `add_attack_max`
				,`tr_a1`,`tr_a2`,`tr_a3`,`tr_a4`,`tr_mg1`,`tr_mg2`,`tr_mg3`,`tr_mg4`,`tr_mg5`,`tr_mg6`,`tr_mg7`
				,`add_a1`,`add_a2`,`add_a3`,`add_a4`,`add_mg1`,`add_mg2`,`add_mg3`,`add_mg4`,`add_mg5`,`add_mg6`,`add_mg7`
			) VALUES ';
		$ins .= '(
				NULL,
				"'.$pl['name'].'",
				"'.$pl['img'].'",
				"'.( 0 + round( $po['art'] ) ).'",
				"'.$pl['type'].'",
				"'.$pl['inslot'].'",
				"",
				"'.$pl['price1'].'",
				"'.$pl['price2'].'",
				"'.$pl['iznosMAXi'].'",
				"'.$pl['massa'].'",
				"'.( 0 + round( $po['tr_lvl'] ) ).'",
				"'.( 0 + round( $po['tr_s1'] ) ).'",
				"'.( 0 + round( $po['tr_s2'] ) ).'",
				"'.( 0 + round( $po['tr_s3'] ) ).'",
				"'.( 0 + round( $po['tr_s4'] ) ).'",
				"'.( 0 + round( $po['tr_s5'] ) ).'",
				"'.( 0 + round( $po['tr_s6'] ) ).'",
				"'.( 0 + round( $po['add_s1'] ) ).'",
				"'.( 0 + round( $po['add_s2'] ) ).'",
				"'.( 0 + round( $po['add_s3'] ) ).'",
				"'.( 0 + round( $po['add_s4'] ) ).'",
				"'.( 0 + round( $po['add_s5'] ) ).'",
				"'.( 0 + round( $po['add_s6'] ) ).'",
				"'.( 0 + round( $po['add_hpAll'] ) ).'",
				"'.( 0 + round( $po['add_mpAll'] ) ).'",
				"'.( 0 + round( $po['add_m1'] ) ).'",
				"'.( 0 + round( $po['add_m2'] ) ).'",
				"'.( 0 + round( $po['add_m3'] ) ).'",
				"'.( 0 + round( $po['add_m4'] ) ).'",
				"'.( 0 + round( $po['add_mib1'] ) ).'",
				"'.( 0 + round( $po['add_mib2'] ) ).'",
				"'.( 0 + round( $po['add_mib3'] ) ).'",
				"'.( 0 + round( $po['add_mib4'] ) ).'",
				"'.( 0 + round( $po['add_minAtack'] ) ).'",
				"'.( 0 + round( $po['add_maxAtack'] ) ).'",
				"'.( 0 + round( $po['tr_a1'] ) ).'",
				"'.( 0 + round( $po['tr_a2'] ) ).'",
				"'.( 0 + round( $po['tr_a3'] ) ).'",
				"'.( 0 + round( $po['tr_a4'] ) ).'",
				"'.( 0 + round( $po['tr_mg1'] ) ).'",
				"'.( 0 + round( $po['tr_mg2'] ) ).'",
				"'.( 0 + round( $po['tr_mg3'] ) ).'",
				"'.( 0 + round( $po['tr_mg4'] ) ).'",
				"'.( 0 + round( $po['tr_mg5'] ) ).'",
				"'.( 0 + round( $po['tr_mg6'] ) ).'",
				"'.( 0 + round( $po['tr_mg7'] ) ).'",
				"'.( 0 + round( $po['add_a1'] ) ).'",
				"'.( 0 + round( $po['add_a2'] ) ).'",
				"'.( 0 + round( $po['add_a3'] ) ).'",
				"'.( 0 + round( $po['add_a4'] ) ).'",
				"'.( 0 + round( $po['add_mg1'] ) ).'",
				"'.( 0 + round( $po['add_mg2'] ) ).'",
				"'.( 0 + round( $po['add_mg3'] ) ).'",
				"'.( 0 + round( $po['add_mg4'] ) ).'",
				"'.( 0 + round( $po['add_mg5'] ) ).'",
				"'.( 0 + round( $po['add_mg6'] ) ).'",
				"'.( 0 + round( $po['add_mg7'] ) ).'"
		);';
		$ins .= "\n".'<br>';
	}
	
	echo $ins;
	
	die();
}

if( isset($_GET['test'])) {
	$i = 3;
	
	
	function yrn($sila) {
		$r = 0;
		
		$level = $_GET['test'];
		
		$r = 2 + $level + $sila - round($sila / 5);
		
		return $r;
	}
	
	
	while( $i <= 100 ) {
		echo '<div';
		if( $i == 8 || $i == 13 || $i == 18 || $i == 23 ) { 
			echo ' style="background-color:green;color:#fff;"';
		}elseif( $i == 7 || $i == 12 || $i == 17 || $i == 22 ) { 
			echo ' style="background-color:grey;color:#fff;"';
		}
		echo '>&nbsp;';
		echo $i.' = '.yrn($i).'';
		echo '</div>';
		$i++;
	}
	
	die();
}

function getIP() {
   if(isset($_SERVER['HTTP_X_REAL_IP'])) return $_SERVER['HTTP_X_REAL_IP'];
   return $_SERVER['REMOTE_ADDR'];
}

if(isset($_GET['robot'])) {
	
}elseif(getIP() != $_SERVER['SERVER_ADDR'] && getIP() != '127.0.0.1' && getIP() != '' && getIP() != '31.131.116.166') {
	if( !isset($_GET['test'])) {
		die(getIP().'<br>'.$_SERVER['SERVER_ADDR']);
	}
}


define('GAME',true);

setlocale(LC_CTYPE ,"ru_RU.CP1251");

include('_incl_data/__config.php');
include('_incl_data/class/__db_connect.php');
include('_incl_data/class/__user.php');
include('_incl_data/class/bot.priem.php');
include('_incl_data/class/bot.logic.php');

function e($t) {
	mysql_query('INSERT INTO `chat` (`text`,`city`,`to`,`type`,`new`,`time`) VALUES ("core #'.date('d.m.Y').' %'.date('H:i:s').' (Критическая ошибка): <b>'.mysql_real_escape_string($t).'</b>","capitalcity","LEL","6","1","-1")');
}

$count = array(
	0,
	0,
	0,
	0,
	0,
	0
);

function inuser_go_btl($id) {
	if(isset($id['id'])) {
		file_get_contents('https://new-combats.com/jx/battle/refresh.php?uid='.$id['id'].'&cron_core='.md5($id['id'].'_brfCOreW@!_'.$id['pass']).'&pass='.$id['pass']);
	}
}

$sp = mysql_query('SELECT `u`.* , `s`.* FROM `stats` AS `s` LEFT JOIN `users` AS `u` ON `u`.`id` = `s`.`id` WHERE `u`.`pass` = "botforpeople" ORDER BY `s`.`nextAct` ASC LIMIT 200');

$btltest = array();

while($pl = mysql_fetch_array($sp)) {
	
	$i++;

	if( $pl['zv'] == 0 && ($pl['battle'] == 0 || !isset($btltest[$pl['battle']]) || $btltest[$pl['battle']] < 10)) {
		
		$btltest[$pl['battle']]++;
		
		if( $pl['timereg'] == 0 ) {
			mysql_query('UPDATE `users` SET `timereg` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}else{
			mysql_query('UPDATE `users` SET `online` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}
		
		if( $pl['bot'] == 0 ) {
			mysql_query('UPDATE `stats` SET `bot` = "2" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}
		
		mysql_query('UPDATE `users` SET `online` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		
		botLogic::start( $pl['id'] );
		
	}else{
		
		if( $pl['zv'] > 0 ) {
			botLogic::start( $pl['id'] );
		}
		
		if( $pl['timereg'] == 0 ) {
			mysql_query('UPDATE `users` SET `timereg` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}else{
			mysql_query('UPDATE `users` SET `online` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}
		
		if( $pl['bot'] == 0 ) {
			mysql_query('UPDATE `stats` SET `bot` = "2" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		}
		mysql_query('UPDATE `stats` SET `nextAct` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		mysql_query('UPDATE `users` SET `online` = "'.time().'" WHERE `id` = "'.$pl['id'].'" LIMIT 1');
		
		echo '*';
	}
	echo '+';
	echo '['.$pl['login'].'] -> Действие: '.$pl['ipreg'].' , ожидаем: '.($pl['timeMain']-time()).' сек., заявка: '.$pl['zv'].', поединок: '.$pl['battle'].'';
	echo '<hr>';
}
?>
