09 Hit And Run System

Started by Mindless, July 20, 2012, 08:39:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#3
Well think your best bet is to go to the u-232 versions of this mod, then edit all the downloadpos lines to use int instead of yes/no

https://u-232-forum.duckdns.org/index.php?topic=210.0.html

BACDAFUCUP

Thanks for this mod... Works perfectly. :) But i have one little problem..
I have tried to put in Privilege Mods when the downloadpos is in.. but in this hit and run mod.. is has the yes / no function where the Privilege Mod has 1 / 0 function..
What should the code look like. i have tried now for a couple of hours and can not see what it should look like. :)
Can some one please help me about that little problem ?

Mindless

Quote
'Sir_SnuggleBunny'

new totally fair automatic hit and run system...

I know you're thinking it can't be done... I beg to differ  :pardon:

I spent ages arguing with my staff about a H&R auto system, and I finally agreed to code one up, but it had to be 110% more then fair. Most H&R scripts I've seen just dont' take into account stuff like rebooting your comp, shutting down for the night etc. and I personally find it offensive to have to re-boot my comp, only to return to the site 5 minutes later with 20 PMs saying I have hit and ran :blink:

so... I coded...
I have had this running at my site for ages now, and I have shared the code with Bigjoos so far, and I think he got it working fine as well on the latest TBDev code, so perhaps he'll be kind enough to help us debug it here for you peeps ;)

what this script does is it takes stuff into account stuff like

  • time seeded (per member class)
  • age of torrent (older torrents don't have to be seeded as long)
  • amount uploaded so far (removed from time needing to be seeded)
  • a delay before anything happens (they have a full 3 days to get back and seed it) except there is a H&R gif added to their completed torrents list and they are notified about it.
  • after 3 days, if they have not started re-seeding it, it is set to a "real" H&R and receives the "mark of cain"
  • a total number of "mark of cain" H&Rs (set to 3, then they can no longer download)
  • to be totally fair, if they start seeding the torrents again, the H&R / "mark of cain" is removed, however, it stays on their permanant record, and they lose their "badge of honour" :lol:
... and a few more things :P

it uses the info from a snatched list - without some form of snatched list, this mod won't work at all..

this one is the one that is compatible  :

It also requires the downloadpos sql from this mod but good chances are you have it already - note you can install just download restriction part :



Slight updates added - Tested all possibilitys and i dont see any issues however that dont mean theres none :)
Xhtml valid :)

Run this additional sql :

Code (sql) Select
ALTER TABLE `snatched` ADD `hit_and_run` int(11) NOT NULL;
ALTER TABLE `snatched` ADD `mark_of_cain` enum('yes','no') NOT NULL default 'no';
ALTER TABLE snatched ADD `finished` enum('yes','no') NOT NULL default 'no';
ALTER TABLE `users` ADD `hnrwarn` enum('yes','no') NOT NULL default 'no';
ALTER TABLE `users` ADD `hit_and_run_total` int(9) default '0';

   
@ file include/cleanup.php add this code where you want but within the last brace on clean up :) 
   
Code (php) Select
//===09 hnr by sir_snugglebunny
    //=== hit and run part... after 3 days, add the mark of Cain... adjust $secs value if you wish
  $secs = 3 * 86400;
    $hnr = time() - $secs;
  $res = mysql_query('SELECT id FROM snatched WHERE hit_and_run <> \'0\' AND hit_and_run < '.sqlesc($hnr).'') or sqlerr(__FILE__, __LINE__);
  while ($arr = mysql_fetch_assoc($res))
  {
  mysql_query('UPDATE snatched SET mark_of_cain = \'yes\' WHERE id='.sqlesc($arr['id'])) or sqlerr(__FILE__, __LINE__);
  }
    //=== hit and run... disable Downloading rights if they have 3 marks of cain
  $res_fuckers = mysql_query('SELECT COUNT(*) AS poop, snatched.userid, users.username, users.modcomment, users.hit_and_run_total, users.downloadpos FROM snatched LEFT JOIN users ON snatched.userid = users.id WHERE snatched.mark_of_cain = \'yes\' AND users.hnrwarn = \'no\' GROUP BY snatched.userid') or sqlerr(__FILE__, __LINE__);
  while ($arr_fuckers = mysql_fetch_assoc($res_fuckers))
  {
if ($arr_fuckers['poop'] > 3 && $arr_fuckers['downloadpos'] == 'yes')
{
//=== set them to no DLs
$subject = sqlesc('Download disabled by System');
$msg = sqlesc("Sorry ".$arr_fuckers['username'].",\n Because you have 3 or more torrents that have not been seeded to either a 1:1 ratio, or for the expected seeding time, your downloading rights have been disabled by the Auto system !\nTo get your Downloading rights back is simple,\n just start seeding the torrents in your profile [ click your username, then click your [url=".$TBDEV['baseurl']."/userdetails.php?id=".$arr_fuckers['userid']."&completed=1]Completed Torrents[/url] link to see what needs seeding ] and your downloading rights will be turned back on by the Auto system after the next clean-time [ updates 4 times per hour ].\n\nDownloads are disabled after a member has three or more torrents that have not been seeded to either a 1 to 1 ratio, OR for the required seed time [ please see the [url=".$TBDEV['baseurl']."/faq.php]FAQ[/url] or [url=".$TBDEV['baseurl']."/rules.php]Site Rules[/url] for more info ]\n\nIf this message has been in error, or you feel there is a good reason for it, please feel free to PM a staff member with your concerns.\n\n we will do our best to fix this situation.\n\nBest of luck!\n ".$TBDEV['site_name']." staff.\n");
$modcomment = htmlspecialchars($arr_fuckers['modcomment']);
$modcomment =  get_date( time(), 'DATE', 1 ) . " - Download rights removed for H and R - AutoSystem.\n". $modcomment;
$modcom =  sqlesc($modcomment);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject, poster) VALUES(0, $arr_fuckers[userid], ".sqlesc(time()).", $msg, $subject, 0)") or sqlerr(__FILE__, __LINE__);
mysql_query('UPDATE users SET hit_and_run_total = hit_and_run_total + '.$arr_fuckers['poop'].', downloadpos = \'no\', hnrwarn = \'yes\', modcomment = '.$modcom.'  WHERE downloadpos = \'yes\' AND id='.sqlesc($arr_fuckers['userid'])) or sqlerr(__FILE__, __LINE__);
}
  }
    //=== hit and run... turn their DLs back on if they start seeding again
    $res_good_boy = mysql_query('SELECT id, username, modcomment FROM users WHERE hnrwarn = \'yes\' AND downloadpos = \'no\'') or sqlerr(__FILE__, __LINE__);
    while ($arr_good_boy = mysql_fetch_assoc($res_good_boy))
  {
  $res_count = mysql_query('SELECT COUNT(*) FROM snatched WHERE userid = '.sqlesc($arr_good_boy['id']).' AND mark_of_cain = \'yes\'') or sqlerr(__FILE__, __LINE__);
  $arr_count = mysql_fetch_row($res_count);
if ($arr_count[0] < 3)
{
//=== set them to yes DLs
$subject = sqlesc('Download restored by System');
$msg = sqlesc("Hi ".$arr_good_boy['username'].",\n Congratulations ! Because you have seeded the torrents that needed seeding, your downloading rights have been restored by the Auto System !\n\nhave fun !\n ".$TBDEV['site_name']." staff.\n");
$modcomment = htmlspecialchars($arr_good_boy['modcomment']);
$modcomment =  get_date( time(), 'DATE', 1 ) . " - Download rights restored from H and R - AutoSystem.\n". $modcomment;
$modcom =  sqlesc($modcomment);
mysql_query("INSERT INTO messages (sender, receiver, added, msg, subject, poster) VALUES(0, ".sqlesc($arr_good_boy['id']).", ".sqlesc(time()).", $msg, $subject, 0)") or sqlerr(__FILE__, __LINE__);
mysql_query('UPDATE users SET downloadpos = \'yes\', hnrwarn = \'no\', modcomment = '.$modcom.'  WHERE id = '.sqlesc($arr_good_boy['id'])) or sqlerr(__FILE__, __LINE__);
}
  }
  //==End

    
@ file announce.php at the top where your globals and defines are - make sure you define all classes you intend to use this for - default announce has VIP only :) :

Code (php) Select
////////////////// GLOBAL VARIABLES ////////////////////////////
$TBDEV['baseurl'] = 'http://localhost/TB_ALPHA/';
$TBDEV['announce_interval'] = 60 * 30;
$TBDEV['user_ratios'] = 0;
$TBDEV['connectable_check'] = 0;
define ('UC_VIP', 2);


Next find this line :

Code (php) Select
if (isset($self) && $event == "stopped") {
mysql_query("DELETE FROM peers WHERE $selfwhere") or err("D Err");


Under it add this :

Code (php) Select
//===09 sir_snuggles hit and run
$res_snatch = mysql_query("SELECT seedtime, uploaded, downloaded, finished, start_date AS start_snatch FROM snatched WHERE torrentid = $torrentid AND userid = $userid") or err('Snatch Error 1');
$a = mysql_fetch_array($res_snatch);
//=== only run the function if the ratio is below 1
if( ($a['uploaded'] + $upthis) < ($a['downloaded'] + $downthis) && $a['finished'] == 'yes')
{
$HnR_time_seeded = ($a['seedtime'] + $self['announcetime']);
//=== get times per class
switch (true)
{
//=== user
case ($user['class'] < UC_POWER_USER):
$days_3 = 3*86400; //== 3 days
$days_14 = 2*86400; //== 2 days
$days_over_14 = 86400; //== 1 day
break;
//=== poweruser
case ($user['class'] == UC_POWER_USER):
$days_3 = 2*86400; //== 2 days
$days_14 = 129600; //== 36 hours
$days_over_14 = 64800; //== 18 hours
break;
//=== vip / donor?
case ($user['class'] == UC_VIP):
$days_3 = 129600; //== 36 hours
$days_14 = 86400; //== 24 hours
$days_over_14 = 43200; //== 12 hours
break;
//=== uploader / staff and above (we don't need this for uploaders now do we?
case ($user['class'] >= UC_UPLOADER):
$days_3 = 86400; //== 24 hours
$days_14 = 43200; //== 12 hours
$days_over_14 = 21600; //== 6 hours
break;
}

switch(true)
{
case (($a['start_snatch'] - $torrent['ts']) < 7*86400):
$minus_ratio = ($days_3 - $HnR_time_seeded);
break;
case (($a['start_snatch'] - $torrent['ts']) < 21*86400):
$minus_ratio = ($days_14 - $HnR_time_seeded);
break;
case (($a['start_snatch'] - $torrent['ts']) >= 21*86400):
$minus_ratio = ($days_over_14 - $HnR_time_seeded);
break;
}
$hit_and_run = (($minus_ratio > 0 && ($a['uploaded'] + $upthis) < ($a['downloaded'] + $downthis)) ? ", seeder='no', hit_and_run= '".time()."'" : ", hit_and_run = '0'");
} //=== end if not 1:1 ratio
else
$hit_and_run = ", hit_and_run = '0'";
//=== end hit and run


Note i tweaked the $hit_and_run - i added seeder='no' due to the fact i could stop the minute my torrent completed and remain a seeder in snatched - so if you trigger the hit_and_run you have stopped seeding no doubt about it so i think its essential to have seeder='no' there :)

Next find this query right below :

Code (sql) Select
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, to_go = $left, upspeed = $upspeed, downspeed = $downspeed, $announcetime, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent)." WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 1");

Replace it with this :

Code (sql) Select
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', uploaded = uploaded + $upthis, downloaded = downloaded + $downthis, to_go = $left, upspeed = $upspeed, downspeed = $downspeed, $announcetime, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent)." $hit_and_run WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 1");

Find this line again just a bit lower :

Code (php) Select
$finished1 = ", complete_date = ".time()."";

Replace it with this :

Code (php) Select
$finished1 = ", complete_date = ".time().", finished = 'yes'";

Find this query :

Code (sql) Select
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', to_go = $left, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent).", $anntime WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 3");

Replace it with this :

Code (php) Select
mysql_query("UPDATE snatched SET ip = ".sqlesc($ip).", port = $port, connectable = '$connectable', to_go = $left, last_action = ".time().", seeder = '$seeder', agent = ".sqlesc($agent).", $anntime, hit_and_run = '0', mark_of_cain = 'no' WHERE torrentid = $torrentid AND userid = {$user['id']}") or err("SL Err 3");

@ file lang/en/lang_userdetails.php add


Code (html) Select
'userdetails_type' => 'Type',
'userdetails_name' => 'Name',
'userdetails_s' => 'S',
'userdetails_l' => 'L',
'userdetails_ul' => 'UL',
'userdetails_dl' => 'DL',
'userdetails_ratio' => 'Ratio',
'userdetails_wcompleted' => 'When Completed',
'userdetails_laction' => 'Last Action',
'userdetails_speed' => 'Speed',
'userdetails_completedt' => 'Completed Torrents',


@ file userdetails.php add this in the top section as your member will be able to see his own completed torrents - how long to seed for and if warned :)

Above this line :

Code (php) Select
if ($user["info"])
     $HTMLOUT .= "<tr valign='top'><td align='left' colspan='2' class='text' bgcolor='#F4F4F0'>" . format_comment($user["info"]) . "</td></tr>\n";

     
Add this :

Code (php) Select
//==09 Hnr mod - sir_snugglebunny
    $completed = "";
    $r = mysql_query("SELECT torrents.name,torrents.added AS torrent_added, snatched.start_date AS s, snatched.complete_date AS c, snatched.downspeed, snatched.seedtime, snatched.seeder, snatched.torrentid as id, categories.id as category, categories.image, categories.name as catname, snatched.uploaded, snatched.downloaded, snatched.hit_and_run, snatched.mark_of_cain, snatched.complete_date, snatched.last_action, torrents.seeders, torrents.leechers, torrents.owner, snatched.start_date AS st, snatched.start_date FROM snatched JOIN torrents ON torrents.id = snatched.torrentid JOIN categories ON categories.id = torrents.category WHERE snatched.finished='yes' AND userid=$id AND torrents.owner != $id ORDER BY snatched.id DESC") or sqlerr(__FILE__, __LINE__);
    //=== completed
    if (mysql_num_rows($r) > 0){
    $completed .= "<table class='main' border='1' cellspacing='0' cellpadding='3'>
    <tr>
    <td class='colhead'>{$lang['userdetails_type']}</td>
    <td class='colhead'>{$lang['userdetails_name']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_s']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_l']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_ul']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_dl']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_ratio']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_wcompleted']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_laction']}</td>
    <td class='colhead' align='center'>{$lang['userdetails_speed']}</td></tr>";
    while ($a = mysql_fetch_assoc($r)){
    //=======change colors
    $count2='';
    $count2= (++$count2)%2;
    $class = 'clearalt'.($count2 == 0 ? 6 : 7);
    $torrent_needed_seed_time = ($a['st'] - $a['torrent_added']);
    //=== get times per class
    switch (true)
    {
    //=== user
    case ($user['class'] < UC_POWER_USER):
    $days_3 = 3*86400; //== 3 days
    $days_14 = 2*86400; //== 2 days
    $days_over_14 = 86400; //== 1 day
    break;
    //=== poweruser
    case ($user['class'] == UC_POWER_USER):
    $days_3 = 2*86400; //== 2 days
    $days_14 = 129600; //== 36 hours
    $days_over_14 = 64800; //== 18 hours
    break;
    //=== vip donor
    case ($user['class'] == UC_VIP):
    $days_3 = 129600; //== 36 hours
    $days_14 = 86400; //== 24 hours
    $days_over_14 = 43200; //== 12 hours
    break;
    //=== uploader / staff and above (we don't need this for uploaders + now do we lol?)
    case ($user['class'] >= UC_UPLOADER):
    $days_3 = 86400; //== 24 hours
    $days_14 = 43200; //== 12 hours
    $days_over_14 = 21600; //== 6 hours
    break;
    }
    //=== times per torrent based on age
    switch(true)
    {
    case (($a['st'] - $a['torrent_added']) < 7*86400):
    //$minus_ratio = ($days_3 - $a['seedtime']);
    //=== or using ratio in the equation
    $minus_ratio = ($days_3 - $a['seedtime']) - ($a['uploaded'] / $a['downloaded'] * 3 * 86400);
    break;
    case (($a['st'] - $a['torrent_added']) < 21*86400):
    //$minus_ratio = ($days_14 - $a['seedtime']);
    //=== or using ratio in the equation
    $minus_ratio = ($days_14 - $a['seedtime']) - ($a['uploaded'] / $a['downloaded'] * 2 * 86400);
    break;
    case (($a['st'] - $a['torrent_added']) >= 21*86400):
    //$minus_ratio = ($days_over_14 - $a['seedtime']);
    //=== or using ratio in the equation
    $minus_ratio = ($days_over_14 - $a['seedtime']) - ($a['uploaded'] / $a['downloaded'] * 86400);
    break;
    }
    $color = (($minus_ratio > 0 && $a['uploaded'] < $a['downloaded']) ? get_ratio_color($minus_ratio) : 'limegreen');
    $minus_ratio = mkprettytime($minus_ratio);
    //=== speed color red fast green slow ;)
    if ($arr["downspeed"] > 0)
    $dl_speed = ($a["downspeed"] > 0 ? mksize($a["downspeed"]) : ($a["leechtime"] > 0 ? mksize($a["downloaded"] / $a["leechtime"]) : mksize(0)));
    else
    $dl_speed = mksize(($a["downloaded"] / ( $a['c'] - $a['s'] + 1 )));
    $dlc="";
    switch (true){
    case ($dl_speed > 600):
    $dlc = 'red';
    break;
    case ($dl_speed > 300 ):
    $dlc = 'orange';
    break;
    case ($dl_speed > 200 ):
    $dlc = 'yellow';
    break;
    case ($dl_speed < 100 ):
    $dlc = 'Chartreuse';
    break;
    }
    //=== mark of cain / hit and run
    $checkbox_for_delete = ($CURUSER['class'] >=  UC_MODERATOR ? " [<a href='".$TBDEV['baseurl']."/userdetails.php?id=".$id."&amp;delete_hit_and_run=".$a['id']."'>Remove</a>]" : '');
    $mark_of_cain = ($a['mark_of_cain'] == 'yes' ? "<img src='{$TBDEV['pic_base_url']}moc.gif' alt='Mark Of Cain' title='the mark of Cain!' />".$checkbox_for_delete : '');
    $hit_n_run = ($a['hit_and_run'] > 0 ? "<img src='{$TBDEV['pic_base_url']}hnr.gif' alt='hit and run' title='hit and run!' />" : '');
    $completed .= "<tr><td style='padding: 0px' class='$class'><img src='{$TBDEV['pic_base_url']}caticons/$a[image]' alt='$a[name]' title='$a[name]' /></td>
    <td class='$class'><a class='altlink' href='{$TBDEV['baseurl']}/details.php?id=".$a['id']."&amp;hit=1'><b>".htmlspecialchars($a['name'])."</b></a>
    <br /><font color='.$color.'>  ".(($CURUSER['class'] >= UC_MODERATOR || $user['id'] == $CURUSER['id']) ? "seeded for: ".mkprettytime($a['seedtime']).(($minus_ratio != '0:00' && $a['uploaded'] < $a['downloaded']) ? "<br />should still seed for: ".$minus_ratio."</font>&nbsp;&nbsp;" : '').
    ($a['seeder'] == 'yes' ? "&nbsp;<font color='limegreen'> [<b>seeding</b>]</font>" : $hit_n_run."&nbsp;".$mark_of_cain) : '')."</td>
    <td align='center' class='$class'>".$a['seeders']."</td>
    <td align='center' class='$class'>".$a['leechers']."</td>
    <td align='center' class='$class'>".mksize($a['uploaded'])."</td>
    <td align='center' class='$class'>".mksize($a['downloaded'])."</td>
    <td align='center' class='$class'>".($a['downloaded'] > 0 ? "<font color='" . get_ratio_color(number_format($a['uploaded'] / $a['downloaded'], 3)) . "'>".number_format($a['uploaded'] / $a['downloaded'], 3)."</font>" : ($a['uploaded'] > 0 ? 'Inf.' : '---'))."<br /></td>
    <td align='center' class='$class'>".get_date($a['complete_date'], 'DATE')."</td>
    <td align='center' class='$class'>".get_date($a['last_action'], 'DATE')."</td>
    <td align='center' class='$class'><font color='$dlc'>[ DLed at: $dl_speed ]</font></td></tr>";
    }
    $completed .= "</table>";
    }
    if ($completed && $CURUSER['class'] >= UC_POWER_USER || $completed && $user['id'] == $CURUSER['id']){
    if (!isset($_GET['completed']))
    $HTMLOUT .= tr(''.$lang['userdetails_completedt'].'<br />','[ <a href=\'./userdetails.php?id='.$id.'&amp;completed=1#completed\' class=\'sublink\'>Show</a> ]&nbsp;&nbsp;-&nbsp;'.mysql_num_rows($r), 1);
    elseif (mysql_num_rows($r) == 0)
    $HTMLOUT .= tr(''.$lang['userdetails_completed'].'<br />','[ <a href=\'./userdetails.php?id='.$id.'&amp;completed=1\' class=\'sublink\'>Show</a> ]&nbsp;&nbsp;-&nbsp;'.mysql_num_rows($r), 1);
    else
    $HTMLOUT .= tr('<a name=\'completed\'>'.$lang['userdetails_completed'].'</a><br />[ <a href=\'./userdetails.php?id='.$id.'#history\' class=\'sublink\'>Hide list</a> ]', $completed, 1);
    }
    //==End hnr

   
Note above code has 2 gifs - one named hnr.gif and moc.gif - You can decide what you want to use yourself - From here staff can delete hit and runs and see which have mark of cain ect

Massive thanks to sir_snugglebunny for sharing this one and sending me the required code :)