Location: PHPKode > projects > Zitro-Stats > include/update_calc.inc.php
<?php

	// ANTIHACK
	defined('INSTATS') AND defined('UPDATE') OR die();

	fecho("\n==[ CALCULATING NEW ]================================\n");

	// MEMORY CLEANUP MANAGEMENT
	$event = 0;			// EVENT INCR
	$events = array();	// PLAYERS AND THEIR LAST EVENT

	$replacelogs	= array();
	$insertkilllog	= array();

	if($timemode = ini_get('max_execution_time'))
		fecho(" timelimit mode (".($timemode-time()+$starttime)."sec left)\n");

	fecho(" parsing new events from ".count($killlogs)." log(s)\n");

	// LOOP UNTIL ALL LOGS ARE PARSED
	while(true) {
		if($timemode && time()-$starttime > ini_get('max_execution_time')*3/4) {
			fecho(" timelimit stop!\n");
			foreach($killlogs as $i=>$killlog) {
				$replacelogs[] = $killlog->replace(true);
				fecho("  stopping $killlog->log (".$killlog->complete." of ".$killlog->size.")\n");
			}
			unset($killlogs);
			break;
		}
		// SEARCH IN EACH LOG FOR THE OLDEST KILL
		foreach($killlogs as $i=>$killlog) {
			// IF KILLLOG IS PARSED COMPLETELY
			if(!isset($killlog->current)) {
				unset($killlogs[$i]);
				$replacelogs[] = $killlog->replace();
				fecho("  complete $killlog->log".(count($killlogs)?repeat(" ",35,$killlog->log,count($killlogs)).count($killlogs)." left":repeat(" ",37,$killlog->log)."done")."\n");
			// SEARCH FIRST ACTION TO GET CORRECT ORDER
			} elseif(!isset($first) || $first > $killlog->current[0]) {
				$first = $killlog->current[0];
				$firsti = $i;
			}
		}
		// IF FIRST KILL FOUND
		if(isset($first)) {
			list($date,$day,$hour,$player,$opponent,$weapon) = $killlogs[$firsti]->current;
			$server = $killlogs[$firsti]->server;
			$killlogs[$firsti]->parsenext();
			unset($first);

			// IF KILL IS ALLREADY EXPIRED
			if($options['STATS_EXPIRE_TIME'] && $date<$expiredate) {
				// SERVERDAYS
				if($options['STATS_KEEP_DAYS']) {
					if(isset($serverdays[$server][$day]))
						$serverdays[$server][$day][$player == $opponent ? 1 : 0] ++;
					else
						$serverdays[$server][$day] = $player == $opponent ? array(0,1) : array(1,0);
				}

				// SERVERHOURS
				if($options['STATS_KEEP_HOURS']) {
					if(isset($serverdays[$server][$day]))
						$serverdays[$server][$day][$player == $opponent ? 1 : 0] ++;
					else
						$serverdays[$server][$day] = ($player == $opponent ? array(0,1) : array(1,0));
				}
			// IF KILL IS STILL VALID
			} else {
				checkplayer($player);
				$events[$player] = $event;

				// SELFKILL
				if($player == $opponent) {
					$options['UPDATE_NEW_SELFKILLS'] ++;

					// KILLER
					$players[$player]->selfkills ++;
					$players[$player]->last = $date;

					// SERVERDAYS
					if(isset($serverdays[$server][$day]))
						$serverdays[$server][$day][1] ++;
					else
						$serverdays[$server][$day] = array(0,1);

					// SERVERHOURS
					if(isset($serverhours[$server][$hour]))
						$serverhours[$server][$hour][1] ++;
					else
						$serverhours[$server][$hour] = array(0,1);

					$insertkilllog[] = "$server,'$date','".$sql->escape($player)."','".$sql->escape($player)."','',0";
				// KILL
				} else {
					$options['UPDATE_NEW_KILLS'] ++;

					checkplayer($opponent);
					$events[$opponent] = $event;
					if(!count($weapons)) load_weapons();
					$elo = round(50/(1+pow(10,($players[$player]->points - $players[$opponent]->points)/1000)));

					// PLAYERS
					$players[$player]->kills ++;
					$players[$player]->points += $elo;
					$players[$player]->last = max($players[$player]->last,$date);
					$players[$opponent]->deaths ++;
					$players[$opponent]->points -= $elo;
					$players[$opponent]->last = max($players[$opponent]->last,$date);
					if(isset($players[$player]->opponents[$opponent])) {
						$players[$player]->opponents[$opponent][0] ++;
						$players[$player]->opponents[$opponent][1] = max($players[$player]->opponents[$opponent][1],$date);
					} else
						$players[$player]->opponents[$opponent] = array(1,$date);
					if(isset($players[$player]->killweapons[$weapon])){
						$players[$player]->killweapons[$weapon][0] ++;
						$players[$player]->killweapons[$weapon][1] = max($players[$player]->killweapons[$weapon][1],$date);
					} else
						$players[$player]->killweapons[$weapon] = array(1,$date);
					if(isset($players[$opponent]->deathweapons[$weapon])) {
						$players[$opponent]->deathweapons[$weapon][0] ++;
						$players[$opponent]->deathweapons[$weapon][1] = max($players[$opponent]->deathweapons[$weapon][1],$date);
					} else
						$players[$opponent]->deathweapons[$weapon] = array(1,$date);

					// WEAPON
					$weapons[$weapon]->kills ++;
					$weapons[$weapon]->last = max($weapons[$weapon]->last,$date);

					// SERVERDAYS
					if(isset($serverdays[$server][$day]))
						$serverdays[$server][$day][0] ++;
					else
						$serverdays[$server][$day] = array(1,0);

					// SERVERHOURS
					if(isset($serverhours[$server][$hour]))
						$serverhours[$server][$hour][0] ++;
					else
						$serverhours[$server][$hour] = array(1,0);

					$insertkilllog[] = "$server,'$date','".$sql->escape($player)."','".$sql->escape($opponent)."','".$sql->escape($weapon)."',$elo";
				}
				// CHECK FOR TOO MUCH PLAYERS
				cleanmem($events);
				$event++;

				// CHECK FOR TOO MUCH KILLLOG LINES
				if(count($insertkilllog)>MEMORY_KILLLOG_MAX) {
					$sql->query("
						INSERT INTO `$options[SQL_TABPREFIX]killlog`
						(`server`,`date`,`player`,`opponent`,`weapon`,`points`)
						VALUES (".implode("),(",$insertkilllog).")
						");
					$insertkilllog = array();
				}
			}

		// END WHEN ALL LOGS PARSED
		} else break;
	}

?>
Return current item: Zitro-Stats