设为首页收藏本站

ZMX - IT技术交流论坛 - 无限Perfect,追求梦想 - itzmx.com

 找回密码
 注册论坛

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

用百度帐号登录

只需两步,快速登录

搜索
查看: 249|回复: 2

NexusPHP1.5 如PT客户端有V4V6地址或多ip,做种汇报数据问题的处理过程

[复制链接]

签到天数: 282 天

[LV.8]以坛为家I

发表于 2024/12/7 13:59 | 显示全部楼层 |阅读模式
天涯海角搜一下: 百度 谷歌 360 搜狗 有道 雅虎 必应 即刻
本帖最后由 308760841 于 2024/12/8 17:12 编辑

本教程来自BTSCHOOL站网友的分享,感谢!!

停止网站访问!!!

1.清理snatched表重复数据。PHP命令脚本处理,脚本代码如下:
  1. <?php

  2. ini_set('memory_limit','4G');

  3. echo 'start    '.date('Y-m-d H:i:s')."\r\n";
  4. function connect_db_local(){
  5.     // 数据库连接信息
  6.     $host = "localhost";
  7.     $username = "root";
  8.     $password = "root";
  9.     $database = "nexusphp";

  10.     // 连接数据库
  11.     $conn = mysql_connect($host, $username, $password);
  12.     if (!$conn) {
  13.         die("连接失败: " . mysql_error());
  14.     }

  15.     // 选择数据库
  16.     mysql_select_db($database, $conn);


  17. }
  18. //连接数据库
  19. connect_db_local();

  20. //创建删除记录表
  21. create_del_table();

  22. //执行次数记录器
  23. $handle_times = 0;
  24. //一次执行,最大处理的重复数据数量
  25. $max_times = 9999;
  26. //每次查询30条有重复信息的数据
  27. $sql_limit = 100;

  28. //处理snateched表重复数据
  29. handle_snatched();

  30. echo 'end      '.date('Y-m-d H:i:s')."\r\n";
  31. exit('finished');



  32. function create_del_table(){
  33.     $snatched = "CREATE TABLE IF NOT EXISTS `snatched_del` (
  34.     `id` int(10) NOT NULL AUTO_INCREMENT,
  35.     `torrentid` mediumint(8) unsigned NOT NULL DEFAULT '0',
  36.     `userid` mediumint(8) unsigned NOT NULL DEFAULT '0',
  37.     `ip` varchar(64) NOT NULL DEFAULT '',
  38.     `port` smallint(5) unsigned NOT NULL DEFAULT '0',
  39.     `uploaded` bigint(20) unsigned NOT NULL DEFAULT '0',
  40.     `downloaded` bigint(20) unsigned NOT NULL DEFAULT '0',
  41.     `to_go` bigint(20) unsigned NOT NULL DEFAULT '0',
  42.     `seedtime` int(10) unsigned NOT NULL DEFAULT '0',
  43.     `leechtime` int(10) unsigned NOT NULL DEFAULT '0',
  44.     `last_action` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  45.     `startdat` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  46.     `completedat` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  47.     `finished` enum('yes','no') NOT NULL DEFAULT 'no',
  48.     `HR` enum('A','B','C','D') NOT NULL DEFAULT 'A',
  49.     PRIMARY KEY (`id`),
  50.     KEY `torrentid_userid` (`torrentid`,`userid`),
  51.     KEY `userid` (`userid`),
  52.     KEY `torrentid` (`torrentid`),
  53.     KEY `id` (`id`,`torrentid`,`userid`,`finished`,`HR`),
  54.     KEY `torrentid_2` (`torrentid`)
  55. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
  56.     sql_query($snatched);
  57. }

  58. function sql_query($sql){
  59.     return mysql_query($sql);
  60. }




  61. function handle_snatched(){
  62.     global $handle_times,$max_times,$sql_limit;
  63.    
  64.     if($handle_times > $max_times){
  65.         exit("run over {$handle_times} times exit");
  66.     }
  67.     $handle_times++;
  68.    

  69.     //查询snatched表有重复信息的数据
  70.     $sql = 'SELECT torrentid, userid, COUNT(*) AS num_duplicates FROM snatched GROUP BY torrentid, userid HAVING COUNT(*) > 1 limit ' . $sql_limit . ';';

  71.     $res = sql_query($sql);
  72.     if (mysql_num_rows($res) > 0){
  73.         while ($line = mysql_fetch_assoc($res)) {
  74.             $torrentid = $line['torrentid'];
  75.             $userid = $line['userid'];

  76.             // 查询具体重复的数据
  77.             $detail_sql = "SELECT * FROM snatched WHERE torrentid = $torrentid AND userid = $userid order by id asc;";

  78.             $result = sql_query($detail_sql);

  79.             // 删除重复的数据
  80.             $i = 0;
  81.             while ($row = mysql_fetch_assoc($result)) {
  82.                 $i++;
  83.                 if($i == 1){
  84.                     continue;
  85.                 }
  86.                 $insert_sql = 'insert into snatched_del (id, torrentid, userid,ip,port,uploaded,downloaded,to_go,seedtime,leechtime,last_action,startdat,completedat,finished,HR) values ('.$row['id'].','.$row['torrentid'].','.$row['userid'].',"'.$row['ip'].'",'.$row['port'].','.$row['uploaded'].','.$row['downloaded'].','.$row['to_go'].','.$row['seedtime'].','.$row['leechtime'].',"'.$row['last_action'].'","'.$row['startdat'].'","'.$row['completedat'].'","'.$row['finished'].'","'.$row['HR'].'");';
  87.                
  88.                 //var_dump($insert_sql);exit;
  89.                 sql_query($insert_sql);

  90.                 $delete_sql = 'DELETE FROM snatched where id = '.$row['id'];

  91.                 sql_query($delete_sql);
  92.             }
  93.         }
  94.         mysql_free_result($result); // 释放结果集
  95.         handle_snatched();
  96.     }
  97. }
复制代码


上面表字段有差别,自行改!

执行完,都提示finish了,去数据库执行  SELECT torrentid, userid, COUNT(*) AS num_duplicates FROM snatched GROUP BY torrentid, userid HAVING COUNT(*) > 1 limit 30;

看数据是否为0!

2.重启mysql,清理peer表。

3.给peers与snatched两张表加唯一约束的

ALTER TABLE peers ADD UNIQUE INDEX torrent_peer_id (torrent, peer_id);
ALTER TABLE snatched ADD UNIQUE INDEX torrentid_userid_unique (torrentid, userid);

4.改announce.php代码
01.jpg 02.jpg 04.jpg 03.jpg 05.jpg
详见如下
  1. <?php
  2. require_once('include/bittorrent_announce.php');
  3. require_once('include/benc.php');
  4. dbconn_announce();
  5. //1. BLOCK ACCESS WITH WEB BROWSERS AND CHEATS!
  6. $agent = $_SERVER["HTTP_USER_AGENT"];
  7. block_browser();
  8. //2. GET ANNOUNCE VARIABLES
  9. // get string type passkey, info_hash, peer_id, event, ip from client
  10. foreach (array("passkey","info_hash","peer_id","event") as $x)
  11. {
  12.         if(isset($_GET["$x"]))
  13.         $GLOBALS[$x] = $_GET[$x];
  14. }
  15. // get integer type port, downloaded, uploaded, left from client
  16. foreach (array("port","downloaded","uploaded","left","compact","no_peer_id") as $x)
  17. {
  18.         $GLOBALS[$x] = 0 + $_GET[$x];
  19. }
  20. //check info_hash, peer_id and passkey
  21. foreach (array("passkey","info_hash","peer_id","port","downloaded","uploaded","left") as $x)
  22.         if (!isset($x)) err("Missing key: $x");
  23. foreach (array("info_hash","peer_id") as $x)
  24.         if (strlen($GLOBALS[$x]) != 20) err("Invalid $x (" . strlen($GLOBALS[$x]) . " - " . rawurlencode($GLOBALS[$x]) . ")");
  25. if (strlen($passkey) != 32) err("Invalid passkey (" . strlen($passkey) . " - $passkey)");

  26. //4. GET IP AND CHECK PORT
  27. $ip = getip();        // avoid to get the spoof ip from some agent
  28. if (!$port || $port > 0xffff)
  29.         err("invalid port");
  30. if (!ip2long($ip)) //Disable compact announce with IPv6
  31.         $compact = 0;

  32. // check port and connectable
  33. if (portblacklisted($port))
  34.         err("Port $port is blacklisted.");

  35. //5. GET PEER LIST
  36. // Number of peers that the client would like to receive from the tracker.This value is permitted to be zero. If omitted, typically defaults to 50 peers.
  37. $rsize = 50;
  38. foreach(array("numwant", "num want", "num_want") as $k)
  39. {
  40.         if (isset($_GET[$k]))
  41.         {
  42.                 $rsize = 0 + $_GET[$k];
  43.                 break;
  44.         }
  45. }

  46. // set if seeder based on left field
  47. $seeder = ($left == 0) ? "yes" : "no";

  48. // check passkey
  49. if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){
  50.         $res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
  51.         $az = mysql_fetch_array($res);
  52.         $Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 950);
  53. }
  54. if (!$az) err("Invalid passkey! Re-download the .torrent from $BASEURL");
  55. $userid = 0+$az['id'];

  56. //3. CHECK IF CLIENT IS ALLOWED
  57. $clicheck_res = check_client($peer_id,$agent,$client_familyid);
  58. if($clicheck_res){
  59.         if ($az['showclienterror'] == 'no')
  60.         {
  61.                 sql_query("UPDATE users SET showclienterror = 'yes' WHERE id = ".sqlesc($userid));
  62.                 $Cache->delete_value('user_passkey_'.$passkey.'_content');
  63.         }
  64.         err($clicheck_res);
  65. }
  66. elseif ($az['showclienterror'] == 'yes'){
  67.         $USERUPDATESET[] = "showclienterror = 'no'";
  68.         $Cache->delete_value('user_passkey_'.$passkey.'_content');
  69. }

  70. // check torrent based on info_hash
  71. if (!$torrent = $Cache->get_value('torrent_hash_'.$info_hash.'_content')){
  72.         $res = sql_query("SELECT id, owner, sp_state, seeders, leechers, UNIX_TIMESTAMP(added) AS ts, banned FROM torrents WHERE " . hash_where("info_hash", $info_hash));
  73.         $torrent = mysql_fetch_array($res);
  74.         $Cache->cache_value('torrent_hash_'.$info_hash.'_content', $torrent, 350);
  75. }
  76. if (!$torrent) err("torrent not registered with this tracker");
  77. elseif ($torrent['banned'] == 'yes' && $az['class'] < $seebanned_class) err("torrent banned");
  78. // select peers info from peers table for this torrent
  79. $torrentid = $torrent["id"];
  80. $numpeers = $torrent["seeders"]+$torrent["leechers"];

  81. $re_announce = false;
  82. //20秒内的请求视为重复请求
  83. if($Cache->get_value('reannounce_time_'.$torrentid.'_'.$userid) == "yes"){
  84.         $re_announce = true;
  85. }else{
  86.         //非重复请求根据userid和torrentid设置memcached 限制请求的最小间隔
  87.         $Cache->cache_value('reannounce_time_'.$torrentid.'_'.$userid, "yes", 20);
  88. }


  89. if ($seeder == 'yes'){ //Don't report seeds to other seeders
  90.         $only_leech_query = " AND seeder = 'no' ";
  91.         $newnumpeers = $torrent["leechers"];
  92. }
  93. else{
  94.         $only_leech_query = "";
  95.         $newnumpeers = $numpeers;
  96. }
  97. if ($newnumpeers > $rsize)
  98.         $limit = " ORDER BY RAND() LIMIT $rsize";
  99. else $limit = "";
  100. $announce_wait = 30;

  101. $fields = "seeder, peer_id, ip, port, uploaded, downloaded, (".TIMENOW." - UNIX_TIMESTAMP(last_action)) AS announcetime, UNIX_TIMESTAMP(prev_action) AS prevts";
  102. $peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = ".$torrentid." AND connectable = 'yes' ".$only_leech_query.$limit;
  103. $res = sql_query($peerlistsql);

  104. $real_annnounce_interval = $announce_interval;
  105. if ($anninterthreeage && ($anninterthree > $announce_wait) && (TIMENOW - $torrent['ts']) >= ($anninterthreeage * 86400))
  106. $real_annnounce_interval = $anninterthree;
  107. elseif ($annintertwoage && ($annintertwo > $announce_wait) && (TIMENOW - $torrent['ts']) >= ($annintertwoage * 86400))
  108. $real_annnounce_interval = $annintertwo;

  109. $resp = "d" . benc_str("interval") . "i" . $real_annnounce_interval . "e" . benc_str("min interval") . "i" . $announce_wait . "e". benc_str("complete") . "i" . $torrent["seeders"] . "e" . benc_str("incomplete") . "i" . $torrent["leechers"] . "e" . benc_str("peers");

  110. $peer_list = "";
  111. unset($self);
  112. // bencoding the peers info get for this announce
  113. while ($row = mysql_fetch_assoc($res))
  114. {
  115.         $row["peer_id"] = hash_pad($row["peer_id"]);

  116.         // $peer_id is the announcer's peer_id while $row["peer_id"] is randomly selected from the peers table
  117.         if ($row["peer_id"] === $peer_id)
  118.         {
  119.                 $self = $row;
  120.                 continue;
  121.         }
  122. if ($compact == 1){
  123.         $longip = ip2long($row['ip']);
  124.         if ($longip) //Ignore ipv6 address
  125.                 $peer_list .= pack("Nn", sprintf("%d",$longip), $row['port']);
  126. }
  127. elseif ($no_peer_id == 1)
  128.         $peer_list .= "d" .
  129.         benc_str("ip") . benc_str($row["ip"]) .
  130.         benc_str("port") . "i" . $row["port"] . "e" .
  131.         "e";
  132. else
  133.         $peer_list .= "d" .
  134.         benc_str("ip") . benc_str($row["ip"]) .
  135.         benc_str("peer id") . benc_str($row["peer_id"]) .
  136.         benc_str("port") . "i" . $row["port"] . "e" .
  137.         "e";
  138. }
  139. if ($compact == 1)
  140. $resp .= benc_str($peer_list);
  141. else
  142. $resp .= "l".$peer_list."e";

  143. $resp .= "e";

  144. if($re_announce){
  145.         goto end_output;
  146. }

  147. $selfwhere = "torrent = $torrentid AND " . hash_where("peer_id", $peer_id);

  148. //no found in the above random selection
  149. if (!isset($self))
  150. {
  151.         $res = sql_query("SELECT $fields FROM peers WHERE $selfwhere LIMIT 1");
  152.         $row = mysql_fetch_assoc($res);
  153.         if ($row)
  154.         {
  155.                 $self = $row;
  156.         }
  157. }

  158. // min announce time
  159. if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait))
  160.         err('There is a minimum announce time of ' . $announce_wait . ' seconds');

  161. // current peer_id, or you could say session with tracker not found in table peers
  162. if (!isset($self))
  163. {
  164.         //2024-12-07 防止客户端硬重启后同一用户同一ip同一种子出现两个peerid
  165.         $sameIPRecord = mysql_fetch_assoc(sql_query("select id from peers where torrent = $torrentid and userid = $userid and ip = '$ip' limit 1"));
  166.     if (!empty($sameIPRecord) && $seeder == 'yes') {
  167.         err("You cannot seed the same torrent in the same location from more than 1 client.");
  168.     }
  169.         $valid = @mysql_fetch_row(@sql_query("SELECT COUNT(*) FROM peers WHERE torrent=$torrentid AND userid=" . sqlesc($userid)));
  170.         if ($valid[0] >= 1 && $seeder == 'no') err("You already are downloading the same torrent. You may only leech from one location at a time.");
  171.         if ($valid[0] >= 3 && $seeder == 'yes') err("You cannot seed the same torrent from more than 3 locations.");

  172.         if ($az["enabled"] == "no")
  173.         err("Your account is disabled!");
  174.         elseif ($az["parked"] == "yes")
  175.         err("Your account is parked! (Read the FAQ)");
  176.         elseif ($az["downloadpos"] == "no")
  177.         err("Your downloading priviledges have been disabled! (Read the rules)");

  178.         if ($az["class"] < UC_VIP)
  179.         {
  180.                 $ratio = (($az["downloaded"] > 0) ? ($az["uploaded"] / $az["downloaded"]) : 1);
  181.                 $gigs = $az["downloaded"] / (1024*1024*1024);
  182.                 if ($waitsystem == "yes")
  183.                 {
  184.                         if($gigs > 10)
  185.                         {
  186.                                 $elapsed = strtotime(date("Y-m-d H:i:s")) - $torrent["ts"];
  187.                                 if ($ratio < 0.4) $wait = 24;
  188.                                 elseif ($ratio < 0.5) $wait = 12;
  189.                                 elseif ($ratio < 0.6) $wait = 6;
  190.                                 elseif ($ratio < 0.8) $wait = 3;
  191.                                 else $wait = 0;

  192.                                 if ($elapsed < $wait)
  193.                                 err("Your ratio is too low! You need to wait " . mkprettytime($wait * 3600 - $elapsed) . " to start, please read $BASEURL/faq.php#id46 for details");
  194.                         }
  195.                 }
  196.                 if ($maxdlsystem == "yes")
  197.                 {
  198.                         if($gigs > 10)
  199.                         if ($ratio < 0.5) $max = 1;
  200.                         elseif ($ratio < 0.65) $max = 2;
  201.                         elseif ($ratio < 0.8) $max = 3;
  202.                         elseif ($ratio < 0.95) $max = 4;
  203.                         else $max = 0;
  204.                         if ($max > 0)
  205.                         {
  206.                                 $res = sql_query("SELECT COUNT(*) AS num FROM peers WHERE userid='$userid' AND seeder='no'") or err("Tracker error 5");
  207.                                 $row = mysql_fetch_assoc($res);
  208.                                 if ($row['num'] >= $max) err("Your slot limit is reached! You may at most download $max torrents at the same time, please read $BASEURL/faq.php#id66 for details");
  209.                         }
  210.                 }
  211.         }
  212. }
  213. else // continue an existing session
  214. {
  215.         $upthis = $trueupthis = max(0, $uploaded - $self["uploaded"]);
  216.         $downthis = $truedownthis = max(0, $downloaded - $self["downloaded"]);
  217.         $announcetime = ($self["seeder"] == "yes" ? "seedtime = seedtime + $self[announcetime]" : "leechtime = leechtime + $self[announcetime]");
  218.         $is_cheater = false;
  219.        
  220.         if ($cheaterdet_security){
  221.                 if ($az['class'] < $nodetect_security && $self['announcetime'] > 10)
  222.                 {
  223.                         $is_cheater = check_cheater($userid, $torrent['id'], $upthis, $downthis, $self['announcetime'], $torrent['seeders'], $torrent['leechers']);
  224.                 }
  225.         }

  226.         if (!$is_cheater && ($trueupthis > 0 || $truedownthis > 0))
  227.         {
  228.                 $global_promotion_state = get_global_sp_state();
  229.                 if($global_promotion_state == 1)// Normal, see individual torrent
  230.                 {
  231.                         if($torrent['sp_state']==3) //2X
  232.                         {
  233.                                 $USERUPDATESET[] = "uploaded = uploaded + 2*$trueupthis";
  234.                                 $USERUPDATESET[] = "downloaded = downloaded + $truedownthis";
  235.                         }
  236.                         elseif($torrent['sp_state']==4) //2X Free
  237.                         {
  238.                                 $USERUPDATESET[] = "uploaded = uploaded + 2*$trueupthis";
  239.                         }
  240.                         elseif($torrent['sp_state']==6) //2X 50%
  241.                         {
  242.                                 $USERUPDATESET[] = "uploaded = uploaded + 2*$trueupthis";
  243.                                 $USERUPDATESET[] = "downloaded = downloaded + $truedownthis/2";
  244.                         }
  245.                         else{
  246.                                 if ($torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  247.                                         $upthis = $trueupthis * $uploaderdouble_torrent;

  248.                                 if($torrent['sp_state']==2) //Free
  249.                                 {
  250.                                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  251.                                 }
  252.                                 elseif($torrent['sp_state']==5) //50%
  253.                                 {
  254.                                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  255.                                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis/2";
  256.                                 }
  257.                                 elseif($torrent['sp_state']==7) //30%
  258.                                 {
  259.                                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  260.                                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis*3/10";
  261.                                 }
  262.                                 elseif($torrent['sp_state']==1) //Normal
  263.                                 {
  264.                                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  265.                                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis";
  266.                                 }
  267.                         }
  268.                 }
  269.                 elseif($global_promotion_state == 2) //Free
  270.                 {
  271.                         if ($torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  272.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  273.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  274.                 }
  275.                 elseif($global_promotion_state == 3) //2X
  276.                 {
  277.                         if ($uploaderdouble_torrent > 2 && $torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  278.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  279.                         else $upthis = 2*$trueupthis;
  280.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  281.                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis";
  282.                 }
  283.                 elseif($global_promotion_state == 4) //2X Free
  284.                 {
  285.                         if ($uploaderdouble_torrent > 2 && $torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  286.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  287.                         else $upthis = 2*$trueupthis;
  288.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  289.                 }
  290.                 elseif($global_promotion_state == 5){ // 50%
  291.                         if ($torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  292.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  293.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  294.                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis/2";
  295.                 }
  296.                 elseif($global_promotion_state == 6){ //2X 50%
  297.                         if ($uploaderdouble_torrent > 2 && $torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  298.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  299.                         else $upthis = 2*$trueupthis;
  300.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  301.                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis/2";
  302.                 }
  303.                 elseif($global_promotion_state == 7){ //30%
  304.                         if ($torrent['owner'] == $userid && $uploaderdouble_torrent > 0)
  305.                                 $upthis = $trueupthis * $uploaderdouble_torrent;
  306.                         $USERUPDATESET[] = "uploaded = uploaded + $upthis";
  307.                         $USERUPDATESET[] = "downloaded = downloaded + $truedownthis*3/10";
  308.                 }
  309.         }
  310. }

  311. $dt = sqlesc(date("Y-m-d H:i:s"));
  312. $updateset = array();
  313. // set non-type event
  314. if (!isset($event))
  315.         $event = "";
  316. if (isset($self) && $event == "stopped")
  317. {
  318.         sql_query("DELETE FROM peers WHERE $selfwhere") or err("D Err");
  319.         if (mysql_affected_rows())
  320.         {
  321.                 $updateset[] = ($self["seeder"] == "yes" ? "seeders = seeders - 1" : "leechers = leechers - 1");
  322.                 sql_query("UPDATE snatched SET uploaded = uploaded + $trueupthis, downloaded = downloaded + $truedownthis, to_go = $left, $announcetime, last_action = ".$dt." WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 1");
  323.         }
  324. }
  325. elseif(isset($self))
  326. {
  327.         if ($event == "completed")
  328.         {
  329.                 //sql_query("UPDATE snatched SET  finished  = 'yes', completedat = $dt WHERE torrentid = $torrentid AND userid = $userid");
  330.                 $finished = ", finishedat = ".TIMENOW;
  331.                 $finished_snatched = ", completedat = ".$dt . ", finished  = 'yes'";
  332.                 $updateset[] = "times_completed = times_completed + 1";
  333.         }

  334.         sql_query("UPDATE peers SET ip = ".sqlesc($ip).", port = $port, uploaded = $uploaded, downloaded = $downloaded, to_go = $left, prev_action = last_action, last_action = $dt, seeder = '$seeder', agent = ".sqlesc($agent)." $finished WHERE $selfwhere") or err("PL Err 1");

  335.         if (mysql_affected_rows())
  336.         {
  337.                 if ($seeder <> $self["seeder"])
  338.                 $updateset[] = ($seeder == "yes" ? "seeders = seeders + 1, leechers = leechers - 1" : "seeders = seeders - 1, leechers = leechers + 1");
  339.                 sql_query("UPDATE snatched SET uploaded = uploaded + $trueupthis, downloaded = downloaded + $truedownthis, to_go = $left, $announcetime, last_action = ".$dt." $finished_snatched WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 2");
  340.         }
  341. }
  342. else
  343. {
  344.         $sockres = @pfsockopen($ip, $port, $errno, $errstr, 5);
  345.         if (!$sockres)
  346.         {
  347.                 $connectable = "no";
  348.         }
  349.         else
  350.         {
  351.                 $connectable = "yes";
  352.                 @fclose($sockres);
  353.         }
  354.         //查询peer 20241207
  355.         $check_peers_exist = sql_query("select id from peers where $selfwhere limit 1");
  356.     if (mysql_num_rows($check_peers_exist) == 0) {
  357.                 try{
  358.                         //sql_query("INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid, $userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, $dt, $dt, '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).")") or err("PL Err 2");
  359.                         if(!sql_query("INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES ($torrentid, $userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, $dt, $dt, '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).")")){
  360.                                 goto end_output;
  361.                         }
  362.                         if (mysql_affected_rows())
  363.                         {
  364.                                 $updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
  365.                                
  366.                                 //$check = @mysql_fetch_row(@sql_query("SELECT COUNT(*) FROM snatched WHERE torrentid = $torrentid AND userid = $userid"));
  367.                                 $check = mysql_fetch_assoc(sql_query("SELECT id FROM snatched WHERE torrentid = $torrentid AND userid = $userid limit 1"));
  368.                                 if (!isset($check['id']) || !$check['id'])
  369.                                         sql_query("INSERT INTO snatched (torrentid, userid, ip, port, uploaded, downloaded, to_go, startdat, last_action) VALUES ($torrentid, $userid, ".sqlesc($ip).", $port, $uploaded, $downloaded, $left, $dt, $dt)") or err("SL Err 4");
  370.                                 else
  371.                                         sql_query("UPDATE snatched SET to_go = $left, last_action = ".$dt ." WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 3.1");
  372.                         }
  373.                 }catch(\Exception $e){

  374.                 }
  375.                
  376.         }
  377. }

  378. if (count($updateset)) // Update only when there is change in peer counts
  379. {
  380.         $updateset[] = "visible = 'yes'";
  381.         $updateset[] = "last_action = $dt";
  382.         sql_query("UPDATE torrents SET " . join(",", $updateset) . " WHERE id = $torrentid");
  383. }

  384. if($client_familyid != 0 && $client_familyid != $az['clientselect'])
  385.         $USERUPDATESET[] = "clientselect = ".sqlesc($client_familyid);

  386. if(count($USERUPDATESET) && $userid)
  387. {
  388.         sql_query("UPDATE users SET " . join(",", $USERUPDATESET) . " WHERE id = ".$userid);
  389. }
  390. end_output:
  391. benc_resp_raw($resp);
  392. ?>
复制代码

其代码,替换前做好备份

最后删除数据表snatched_del

评分

参与人数 2樱币 +4 收起 理由
小樱 + 2 感谢分享!
algoblue + 2 赞一个!

查看全部评分

欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复

使用道具 举报

签到天数: 282 天

[LV.8]以坛为家I

 楼主| 发表于 2024/12/7 14:00 | 显示全部楼层 |Google Chrome 109.0.0.0|Windows 10
本帖最后由 308760841 于 2024/12/7 14:10 编辑

小樱,来些樱币
[发帖际遇]: 308760841 发帖时在路边捡到 4 樱币,偷偷放进了口袋. 幸运榜 / 衰神榜
欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复 支持 反对

使用道具 举报

 成长值: 336

签到天数: 4737 天

[LV.Master]伴坛终老

发表于 2024/12/7 18:12 | 显示全部楼层 |Google Chrome 131.0.0.0|Windows 10
感谢分享,目前看起来就是可能会触发用户列表有多个ip,流量汇报数据是正确的,不过本地测试并没复现多个ip的现象,能修复显示肯定是更好的啦
欢迎光临IT技术交流论坛:http://bbs.itzmx.com/
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册论坛 新浪微博账号登陆用百度帐号登录

本版积分规则

手机版|Archiver|Mail me|网站地图|IT技术交流论坛 ( 闽ICP备13013206号-7 )

GMT+8, 2024/12/23 02:40 , Processed in 0.138623 second(s), 24 queries , MemCache On.

Powered by itzmx! X3.4

© 2011- sakura

快速回复 返回顶部 返回列表