mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
fix announce.php seeder&leecher count directly
This commit is contained in:
@@ -33,13 +33,6 @@ function get_langfile_path($script_name ="", $target = false, $lang_folder = "")
|
||||
return "lang/" . ($target == false ? $lang_folder : "_target") ."/lang_". ( $script_name == "" ? substr(strrchr($_SERVER['SCRIPT_NAME'],'/'),1) : $script_name);
|
||||
}
|
||||
|
||||
function get_row_count($table, $suffix = "")
|
||||
{
|
||||
$r = sql_query("SELECT COUNT(*) FROM $table $suffix") or sqlerr(__FILE__, __LINE__);
|
||||
$a = mysql_fetch_row($r);
|
||||
return $a[0];
|
||||
}
|
||||
|
||||
function get_row_sum($table, $field, $suffix = "")
|
||||
{
|
||||
$r = sql_query("SELECT SUM($field) FROM $table $suffix") or sqlerr(__FILE__, __LINE__);
|
||||
@@ -1736,7 +1729,7 @@ function get_ip_location($ip)
|
||||
* @since 1.7.4
|
||||
*/
|
||||
$arr = get_ip_location_from_geoip($ip);
|
||||
$result = array($arr["name"], $lang_functions['text_user_ip'] . ": " . trim($ip, ','));
|
||||
$result = array($arr["name"] ?? $lang_functions['text_unknown'], $lang_functions['text_user_ip'] . ": " . trim($ip, ','));
|
||||
return $locations[$ip] = $result;
|
||||
|
||||
$cacheKey = "location_$ip";
|
||||
|
||||
@@ -682,6 +682,13 @@ function get_hr_ratio($uped, $downed)
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
function get_row_count($table, $suffix = "")
|
||||
{
|
||||
$r = sql_query("SELECT COUNT(*) FROM $table $suffix") or sqlerr(__FILE__, __LINE__);
|
||||
$a = mysql_fetch_row($r);
|
||||
return $a[0];
|
||||
}
|
||||
|
||||
function nexus()
|
||||
{
|
||||
return \Nexus\Nexus::instance();
|
||||
|
||||
+26
-6
@@ -71,6 +71,25 @@ if (!$port || $port > 0xffff)
|
||||
if (!ip2long($ip)) //Disable compact announce with IPv6
|
||||
$compact = 0;
|
||||
|
||||
$ipv4 = $ipv6 = '';
|
||||
if (isIPV4($ip)) {
|
||||
$ipv4 = $ip;
|
||||
} elseif (isset($_GET['ipv4']) && isIPV4($_GET['ipv4'])) {
|
||||
$ipv4 = $_GET['ipv4'];
|
||||
}
|
||||
if (isIPV6($ip)) {
|
||||
$ipv6 = $ip;
|
||||
} elseif (isset($_GET['ipv6']) && isIPV6($_GET['ipv6'])) {
|
||||
$ipv6 = $_GET['ipv6'];
|
||||
}
|
||||
$peerIPV46 = "";
|
||||
if ($ipv4) {
|
||||
$peerIPV46 .= ", ipv4 = " . sqlesc($ipv4);
|
||||
}
|
||||
if ($ipv6) {
|
||||
$peerIPV46 .= ", ipv6 = " . sqlesc($ipv6);
|
||||
}
|
||||
|
||||
// check port and connectable
|
||||
if (portblacklisted($port))
|
||||
err("Port $port is blacklisted.");
|
||||
@@ -249,7 +268,7 @@ if (!isset($self))
|
||||
}
|
||||
|
||||
// min announce time
|
||||
if(isset($self) && $self['prevts'] > (TIMENOW - $announce_wait)) {
|
||||
if(isset($self) && empty($_GET['event']) && $self['prevts'] > (TIMENOW - $announce_wait)) {
|
||||
do_log(sprintf(
|
||||
'timezone: %s, self prevts(%s, %s) > now(%s, %s) - announce_wait(%s)',
|
||||
ini_get('date.timezone'), $self['prevts'], date('Y-m-d H:i:s', $self['prevts']), TIMENOW, date('Y-m-d H:i:s', TIMENOW), $announce_wait
|
||||
@@ -421,7 +440,7 @@ if (isset($self) && $event == "stopped")
|
||||
sql_query("DELETE FROM peers WHERE $selfwhere") or err("D Err");
|
||||
if (mysql_affected_rows())
|
||||
{
|
||||
$updateset[] = ($self["seeder"] == "yes" ? "seeders = seeders - 1" : "leechers = leechers - 1");
|
||||
// $updateset[] = ($self["seeder"] == "yes" ? "seeders = seeders - 1" : "leechers = leechers - 1");
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -436,12 +455,13 @@ elseif(isset($self))
|
||||
$updateset[] = "times_completed = times_completed + 1";
|
||||
}
|
||||
|
||||
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");
|
||||
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 $peerIPV46 WHERE $selfwhere") or err("PL Err 1");
|
||||
|
||||
if (mysql_affected_rows())
|
||||
{
|
||||
if ($seeder <> $self["seeder"])
|
||||
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1, leechers = leechers - 1" : "seeders = seeders - 1, leechers = leechers + 1");
|
||||
//count directly since 1.7.4
|
||||
// $updateset[] = ($seeder == "yes" ? "seeders = seeders + 1, leechers = leechers - 1" : "seeders = seeders - 1, leechers = leechers + 1");
|
||||
$snatchInfo = \App\Models\Snatch::query()
|
||||
->where('torrentid', $torrentid)
|
||||
->where('userid', $userid)
|
||||
@@ -484,14 +504,14 @@ else
|
||||
$connectable = "yes";
|
||||
@fclose($sockres);
|
||||
}
|
||||
$insertPeerSql = "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).")";
|
||||
$insertPeerSql = "INSERT INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey, ipv4, ipv6) VALUES ($torrentid, $userid, ".sqlesc($peer_id).", ".sqlesc($ip).", $port, '$connectable', $uploaded, $downloaded, $left, $dt, $dt, '$seeder', ".sqlesc($agent).", $downloaded, $uploaded, ".sqlesc($passkey).",".sqlesc($ipv4).",".sqlesc($ipv6).")";
|
||||
do_log("[INSERT PEER] peer not exists for $selfwhere, do insert with $insertPeerSql");
|
||||
|
||||
try {
|
||||
sql_query($insertPeerSql) or err("PL Err 2");
|
||||
if (mysql_affected_rows())
|
||||
{
|
||||
$updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
|
||||
// $updateset[] = ($seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1");
|
||||
|
||||
$check = @mysql_fetch_row(@sql_query("SELECT COUNT(*) FROM snatched WHERE torrentid = $torrentid AND userid = $userid"));
|
||||
if (!$check['0'])
|
||||
|
||||
+1
-1
@@ -452,7 +452,7 @@ elseif ($action == 'basicsettings') // basic settings
|
||||
print ("<form method='post' action='".$_SERVER["SCRIPT_NAME"]."'><input type='hidden' name='action' value='savesettings_basic'>");
|
||||
tr($lang_settings['row_site_name'],"<input type='text' style=\"width: 300px\" name=SITENAME value='".($config["SITENAME"] ? $config["SITENAME"]: "Nexus")."'> ".$lang_settings['text_site_name_note'], 1);
|
||||
tr($lang_settings['row_base_url'],"<input type='text' style=\"width: 300px\" name=BASEURL value='".($config["BASEURL"] ? $config["BASEURL"] : $_SERVER["HTTP_HOST"])."'> ".$lang_settings['text_it_should_be'] . $_SERVER["HTTP_HOST"] . $lang_settings['text_base_url_note'], 1);
|
||||
tr($lang_settings['row_announce_url'],"<input type='text' style=\"width: 300px\" name=announce_url value='".($config["announce_url"] ? $config["announce_url"] : $_SERVER["HTTP_HOST"]."/announce.php")."'> ".$lang_settings['text_it_should_be'] . $_SERVER["HTTP_HOST"]."/announce.php", 1);
|
||||
tr($lang_settings['row_announce_url'],"<input type='text' style=\"width: 300px\" name=announce_url value='".($config["announce_url"] ? $config["announce_url"] : $_SERVER["HTTP_HOST"]."/api/announce")."'> ".$lang_settings['text_it_should_be'] . $_SERVER["HTTP_HOST"]."/api/announce", 1);
|
||||
// tr($lang_settings['row_mysql_host'],"<input type='text' style=\"width: 300px\" name=mysql_host value='".($config["mysql_host"] ? $config["mysql_host"] : "localhost")."'> ".$lang_settings['text_mysql_host_note'], 1);
|
||||
// tr($lang_settings['row_mysql_user'],"<input type='text' style=\"width: 300px\" name=mysql_user value='".($config["mysql_user"] ? $config["mysql_user"] : "root")."'> ".$lang_settings['text_mysql_user_note'], 1);
|
||||
// tr($lang_settings['row_mysql_password'],"<input type='password' style=\"width: 300px\" name=mysql_pass value=''> ".$lang_settings['text_mysql_password_note'], 1);
|
||||
|
||||
Reference in New Issue
Block a user