<?php
/**
*
* @package ppkBB3cker
* @version $Id: taself1.php 1.000 2009-03-21 16:56:00 PPK $
* @copyright (c) 2008, 2009 PPK
* http://ppkbb3cker.rx22.ru, http://protoneutron.narod.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

	if (!$event && $dt - $attachment['last_action'] < ($ppkbb_tcminannounce_interval - 10))
	{
		err("Sorry, minimum announce interval = {$ppkbb_tcminannounce_interval} sec.");
	}

	$uploaded ? $upthis=$uploaded - $attachment['uploaded'] : $upthis=0;
	$upthis > 0 ? '' : $upthis=0;
	$ppkbb_tcignored_upload=intval($ppkbb_tcignored_upload);
	if($ppkbb_tcignored_upload && $upthis)
	{
		if($upthis > $ppkbb_tcignored_upload * 1024 * 1024 * 1024)
		{
			$upthis=0;
		}
	}

	$downloaded ? $downthis = $downloaded - $attachment['downloaded'] : $downthis=0;
	$downthis > 0 ? '' : $downthis=0;
	$shadowdownthis=$downthis;

	if($rights[4])
	{
		$downthis=0;
	}
	else if($rights[3])
	{
		$downthis=$downthis/2;
	}
	else
	{
		if($user['free'] && $rights[5])
		{
			$user['free'] > 100 ? $user['free']=100 : '';
			$downthis=$downthis*((100-$user['free'])/100);
		}
	}

	if($upthis && $rights[6] && $user['size'] > ($ppkbb_tcbonus_fsize * 1024 * 1024))
	{
		$sql = 'SELECT bonus_count FROM '.TRACKER_SNATCHED_TABLE." WHERE userid='$userid' AND torrent='$torrentid' LIMIT 1";
		$result=my_sql_query($sql);
		$user_bonus=mysql_fetch_array($result);
		mysql_free_result($result);

		$bonus_value = ($upthis + $user_bonus['bonus_count']) / 1024 / 1024;
		$bonus_value = intval($bonus_value / $ppkbb_tcbonus_upvalue);

		if($bonus_value > 0)
		{
			$bonus_left = intval(($upthis + $user_bonus['bonus_count']) - ($bonus_value * $ppkbb_tcbonus_upvalue * 1024 * 1024));
			$bonus_left ? $updatesnatch[] =  "bonus_count = '$bonus_left'" : '';
			$updateuser[]='user_bonus=user_bonus + '. ($bonus_value * $ppkbb_tcbonus_value);
		}
		else
		{
			$upthis ? $updatesnatch[] = 'bonus_count = bonus_count + '.$upthis : '';
		}
	}

	if($upthis)
	{
		$updateuser[] = 'user_uploaded = user_uploaded + '.$upthis;
		$updatesnatch[] = 'uploaded = uploaded + '.$upthis;
		$updatepeers[] = 'uploaded = uploaded + '.$upthis;
		$updatepeers[] = "uploadoffset = '".$upthis."'";
	}
	if($downthis)
	{
		$updateuser[] = 'user_downloaded = user_downloaded + '.$downthis;
		$updatesnatch[] = 'downloaded = downloaded + '.$shadowdownthis;
		$updatepeers[] = 'downloaded = downloaded + '.$shadowdownthis;
		$updatepeers[] = "downloadoffset = '".$shadowdownthis."'";
	}
	$shadowdownthis ? $updateuser[] = 'user_shadow_downloaded = user_shadow_downloaded + '.$shadowdownthis : '';

	if ($updateuser)
	{
		my_sql_query('UPDATE '. USERS_TABLE .' SET '.implode(', ', $updateuser)." WHERE user_id='$userid' LIMIT 1") or err("Tracker error 3");
	}

?>