Skip to content

Commit

Permalink
add H&R include rate
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Sep 13, 2023
1 parent b868742 commit e82530c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private function getHitAndRunSchema()
Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(),
Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(),
Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(),
Forms\Components\TextInput::make('hr.include_rate')->helperText(__('label.setting.hr.include_rate_help'))->label(__('label.setting.hr.include_rate'))->numeric(),
];
return apply_filter("hit_and_run_setting_schema", $default);
}
Expand Down
2 changes: 1 addition & 1 deletion include/constants.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-09-04');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2023-09-14');
defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
Expand Down
1 change: 1 addition & 0 deletions nexus/Install/settings.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@
'seed_time_minimum' => '',
'ignore_when_ratio_reach' => '',
'ban_user_when_counts_reach' => '',
'include_rate' => 1,
],
'seed_box' => [
'enabled' => 'no',
Expand Down
27 changes: 19 additions & 8 deletions public/announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,25 @@
if (!empty($snatchInfo)) {
sql_query("UPDATE snatched SET uploaded = uploaded + $trueupthis, downloaded = downloaded + $truedownthis, to_go = $left, $announcetime, last_action = ".$dt." $finished_snatched WHERE id = {$snatchInfo['id']}") or err("SL Err 2");
do_action('snatched_saved', $torrent, $snatchInfo);
if ($event == 'completed' && $az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS && !$isDonor && isset($torrent['mode'])) {
//think about H&R
// $hrMode = get_setting('hr.mode');
$hrMode = \App\Models\HitAndRun::getConfig('mode', $torrent['mode']);
if ($hrMode == \App\Models\HitAndRun::MODE_GLOBAL || ($hrMode == \App\Models\HitAndRun::MODE_MANUAL && $torrent['hr'] == \App\Models\Torrent::HR_YES)) {
$sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo['id']}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s'));
$affectedRows = sql_query($sql);
do_log("[INSERT_H&R], $sql, affectedRows: $affectedRows");
if ($az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS && !$isDonor && isset($torrent['mode'])) {
$includeRate = \App\Models\HitAndRun::getConfig('include_rate', $torrent['mode']);
if ($includeRate === "" || $includeRate === null) {
//not set yet
$includeRate = 1;
}
$includeHr = false;
if ($includeRate >= 1 && $event == "completed") {
$includeHr = true;
} elseif ($includeRate < 1 && $includeRate >= 0 && $seeder == "no" && ($left <= $torrent['size'] * (1 - $includeRate))) {
$includeHr = true;
}
if ($includeHr) {
$hrMode = \App\Models\HitAndRun::getConfig('mode', $torrent['mode']);
if ($hrMode == \App\Models\HitAndRun::MODE_GLOBAL || ($hrMode == \App\Models\HitAndRun::MODE_MANUAL && $torrent['hr'] == \App\Models\Torrent::HR_YES)) {
$sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo['id']}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s'));
$affectedRows = sql_query($sql);
do_log("[INSERT_H&R], $sql, affectedRows: $affectedRows");
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
'ignore_when_ratio_reach_help' => 'The minimum sharing rate to meet the standard',
'ban_user_when_counts_reach' => 'H&R counts limit',
'ban_user_when_counts_reach_help' => 'The number of H&R reaches this value and the account will be disabled',
'include_rate' => 'Require completion rate',
'include_rate_help' => 'Count H&R only when the download completion rate (decimal between 0 ~ 1) reaches this value. Default: 1'
],
'seed_box' => [
'tab_header' => 'SeedBox',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/zh_CN/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
'ignore_when_ratio_reach_help' => '达标的最小分享率',
'ban_user_when_counts_reach' => 'H&R 数量上限',
'ban_user_when_counts_reach_help' => 'H&R 数量达到此值,账号会被禁用',
'include_rate' => '计入完成率',
'include_rate_help' => '当下载完成率(0 ~ 1 之间的小数)达到此值时才计入 H&R。默认:1'
],
'seed_box' => [
'tab_header' => 'SeedBox',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/zh_TW/label.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
'ignore_when_ratio_reach_help' => '達標的最小分享率',
'ban_user_when_counts_reach' => 'H&R 數量上限',
'ban_user_when_counts_reach_help' => 'H&R 數量達到此值,賬號會被禁用',
'include_rate' => '計入完成率',
'include_rate_help' => '當下載完成率(0 ~ 1 之間的小數)達到此值時才計入 H&R。默認:1'
],
'seed_box' => [
'tab_header' => 'SeedBox',
Expand Down

0 comments on commit e82530c

Please sign in to comment.