<?php
/**
*
* @package ppkBB3cker
* @version $Id: taself2.php 1.000 2009-03-21 13:16: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;
}

		$sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
		if (!$sockres)
		{
			$connectable = "no";
		}
		else
		{
			$connectable = "yes";
			@fclose($sockres);
		}

		my_sql_query("UPDATE ". TRACKER_SNATCHED_TABLE ." SET port = '$port', connectable = '$connectable', last_action = '$dt', seeder = '$seeder'".($updatesnatch ? ', '.implode(', ', $updatesnatch) : '')." WHERE torrent = '$torrentid' AND userid = '$userid'");

		$result = my_sql_query("UPDATE ". TRACKER_PEERS_TABLE ." tp SET ip = '$ip', port = '$port', last_action = '$dt', prev_action = '{$attachment['last_action']}', agent = '$agent', seeder = '$seeder'".($updatepeers ? ', '.implode(', ', $updatepeers) : '')." WHERE $selfwhere");

		if (mysql_affected_rows() && $attachment['seeder'] != $seeder)
		{
			if ($seeder == "yes")
			{
				$updateset[] = isset($t_seeders) ? "seeders = '".($t_seeders + 1 > 0 ? $t_seeders + 1 : 0)."'" : "seeders = seeders + 1";
				isset($t_leechers) ? $updateset[] = "leechers = '$t_leechers'" : '';
				$t_updated=1;
			}
			else
			{
				isset($t_seeders) ? $updateset[] = "seeders = '$t_seeders'" : '';
				$updateset[] = isset($t_leechers) ? "leechers = '".($t_leechers + 1 > 0 ? $t_leechers + 1 : 0)."'" : "leechers = leechers + 1";
				$t_updated=1;
			}
		}

?>