<?php
/**
*
* @package ppkBB3cker
* @version $Id: tanotself2.php 1.000 2009-03-19 20:38: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 (portblacklisted($port))
		{
			err("Port $port is blacklisted.");
		}
		else
		{
			$sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
			if (!$sockres)
			{
				$connectable = "no";
			}
			else
			{
				$connectable = "yes";
				@fclose($sockres);
			}
		}

		$sql="SELECT torrent, userid FROM ". TRACKER_SNATCHED_TABLE ." WHERE torrent = '$torrentid' AND userid = '$userid'";
		$result=my_sql_query($sql);
		$check = mysql_fetch_array($result);
		mysql_free_result($result);
		if (!$check)
		{
			my_sql_query("INSERT INTO ". TRACKER_SNATCHED_TABLE ." (torrent, userid, port, startdat, last_action) VALUES ('$torrentid', '$userid', '$port', '$dt', '$dt')");
		}

		$ret = my_sql_query("INSERT INTO ". TRACKER_PEERS_TABLE ." (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, startdat, last_action, seeder, userid, agent, rights) VALUES ('$connectable', '$torrentid', '$peer_id', '" . $ip . "', '".$port."', '".$uploaded."', '".$downloaded."', '".$left."', '$dt', '$dt', '$seeder', '$userid', '" . $agent . "', '".$s_rights."')");
		if ($ret)
		{
			if ($seeder == "yes")
			{
				$updateset[] = isset($t_seeders) ? "seeders = '".($t_seeders + 1 > 0 ? $t_seeders + 1 : 0)."'" : "seeders = seeders + 1";
				$t_updated=1;
			}
			else
			{
				$updateset[] = isset($t_leechers) ? "leechers = '".($t_leechers + 1 > 0 ? $t_leechers + 1 : 0)."'" : "leechers = leechers + 1";
				$t_updated=1;
			}
		}

?>