09 Crazyhour mod by pdq

Started by Mindless, July 21, 2012, 09:37:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mindless

#1
Credits to pdq :)
Xhtml valid.

09 Crazyhour - After converting the exsisting mod on the forum i had decided to let pdq see it and after 5-10 minutes pdq sent me new code.

So here it is the Crazyhour mod for 09.

Add a text file to cache folder named crazy_hour.txt - chmod to 777

@File include/config.php add :

For default source that uses ROOT_PATH use this :

Code (php) Select
$TBDEV["cache"] = ROOT_PATH.'cache';

If you use pdq's defined directories use this instead :

Code (php) Select
$TBDEV["cache"] = ROOT_DIR.'cache';

Add this as well :

Code (php) Select
$TBDEV['crazy_title'] ="w00t It's Crazyhour!";
$TBDEV['crazy_message'] ="All torrents are FREE and upload stats are TRIPLED!";


@File announce.php :

For Default source that uses ROOT_PATH Only add :

Code (php) Select
if ( strtoupper( substr(PHP_OS, 0, 3) ) == 'WIN' )
  {
    $file_path = str_replace( "\\", "/", dirname(__FILE__) );
    $file_path = str_replace( "/include", "", $file_path );
  }
  else
  {
    $file_path = dirname(__FILE__);
    $file_path = str_replace( "/include", "", $file_path );
  }
 
define('ROOT_PATH', $file_path);


Add this underneath it :

Code (php) Select
$TBDEV["cache"] = ROOT_PATH.'cache';

If you use pdq's defined directores use this instead :

@File announce.php add :

Code (php) Select
$TBDEV['cache'] = dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;

Still on announce.php add this beside all other function def's :

Code (php) Select
function crazyhour_announce() {
   global $TBDEV;
   $transfer_filename   = $TBDEV['cache'].'transfer_crazyhour.txt';
   $crazyhour_filename = $TBDEV['cache'].'crazy_hour.txt';
   $crazyhour_cache = fopen($crazyhour_filename,'r+');
   $crazyhour_var = fread($crazyhour_cache, filesize($crazyhour_filename));
   fclose($crazyhour_cache);
   if ($crazyhour_var >= TIME_NOW && $crazyhour_var < TIME_NOW + 3600) { // is crazyhour
   //return true; // oops
   if (is_file($transfer_filename))
        unlink($transfer_filename);
    return true;
    }
    elseif ($crazyhour_var < TIME_NOW + 3600 && !is_file($transfer_filename)) {   // crazyhour over
        $transfer_file_created = fopen($transfer_filename, 'w') or die('no perms?');
        fclose($transfer_file_created);
        $crazyhour['crazyhour_new']       = mktime(23, 59, 59, date('m'), date('d'), date('y'));
        $crazyhour['crazyhour']['var']    = mt_rand($crazyhour['crazyhour_new'], ($crazyhour['crazyhour_new'] + 86400));
        $fp = fopen($crazyhour_filename, 'w');
        fwrite($fp, $crazyhour['crazyhour']['var']);
        fclose($fp);
        /** log, shoutbot **/
        $text = 'Next Crazyhour is at '.get_date($crazyhour['crazyhour']['var'], 'LONG', 0, 1);
        mysql_query('INSERT INTO sitelog (added, txt)
                     VALUES('.TIME_NOW.', '.sqlesc($text).')') or err(mysql_error());       
        //==Remember to set your userid in the query - presently userid 2
        mysql_query('INSERT INTO shoutbox (userid, date, text, text_parsed) VALUES (2, '.
                     TIME_NOW.', '.sqlesc($text).', '.sqlesc($text).')') or err(mysql_error());
        return false;
    }
   else
return false;
}
// crazyhour end


If you run pdq's freeleech/freeslot mod for 09 replace this :
   
 
Code (php) Select
if ($upthis > 0 || $downthis > 0)
  {
  /** free addon start **/
  $isfree =   '';
  $isdouble = '';
  include("cache/free_cache.php");
  if (isset($free))
  {
  foreach ($free as $fl) {
  $isfree =   ($fl['modifier'] == 1 || $fl['modifier'] == 3) && $fl['expires'] > TIME_NOW;
  $isdouble = ($fl['modifier'] == 2 || $fl['modifier'] == 3) && $fl['expires'] > TIME_NOW;
  }
  }
  if (!($user['free_switch'] != 0 || $isfree || $torrent['free'] != 0 || ($torrent['freeslot'] != 0)))
  $updq[0] = "downloaded = downloaded + $downthis";
  $updq[1] = "uploaded = uploaded + ".(($torrent['doubleslot'] != 0 || $isdouble) ? ($upthis*2) : $upthis);
  $udq=implode(',',$updq);
  mysql_query("UPDATE users SET $udq WHERE id=".$user['id']) or err('Tracker error 3');
  }

   
With this :
   
   
Code (php) Select
if ($upthis > 0 || $downthis > 0)
   {
   $isfree =   '';
   $isdouble = '';
   include("cache/free_cache.php");
   if (isset($free))
   {
   foreach ($free as $fl) {
   $isfree =   ($fl['modifier'] == 1 || $fl['modifier'] == 3) && $fl['expires'] > TIME_NOW;
   $isdouble = ($fl['modifier'] == 2 || $fl['modifier'] == 3) && $fl['expires'] > TIME_NOW;
   }
   }
   $crazyhour = crazyhour_announce();
   if (!($crazyhour || $user['free_switch'] != 0 || $isfree || $torrent['free'] != 0 || ($torrent['freeslot'] != 0)))
   $updq[0] = "downloaded = downloaded + $downthis";
   if ($crazyhour) // crazyhour
   $updq[1]="uploaded = uploaded + ($upthis*3)";
   else
   $updq[1] = "uploaded = uploaded + ".(($torrent['doubleslot'] != 0 || $isdouble) ? ($upthis*2) : $upthis);
   $udq=implode(',',$updq);
   mysql_query("UPDATE users SET $udq WHERE id=".$user['id']) or err('Tracker error 3');
   }


Default announce replace :
   
   
Code (php) Select
if ($upthis > 0 || $downthis > 0)
mysql_query("UPDATE users SET uploaded = uploaded + $upthis, downloaded = downloaded + $downthis WHERE id=".$user['id']) or err("Tracker error 3");
}


With :

   
Code (php) Select
$crazyhour = crazyhour_announce();
   if ($upthis > 0 || $downthis > 0)
   mysql_query("UPDATE users SET uploaded = uploaded + ".(!$crazyhour?"$upthis":"$upthis*3").(!$crazyhour?", downloaded = downloaded + $downthis ":'')." WHERE id=$userid") or err("Tracker error 3");
}


@File bittorrent.php or template.php add this in stdhead function beside pm notification :

Code (php) Select
//==pdq crazyhour
if (isset($CURUSER)) {
   $transfer_filename  = $TBDEV['cache'].'/transfer_crazyhour.txt';
   $crazyhour_filename = $TBDEV['cache'].'/crazy_hour.txt';
   $crazyhour_cache = fopen($crazyhour_filename,'r+');
   $crazyhour_var = fread($crazyhour_cache, filesize($TBDEV['cache'].'/crazy_hour.txt'));
   fclose($crazyhour_cache);
   $cimg = '<img src=\''.$TBDEV["pic_base_url"].'cat_free.gif\' alt=\'FREE!\' />';
   if ($crazyhour_var >= TIME_NOW && $crazyhour_var < TIME_NOW + 3600) { // is crazyhour
       $htmlout .="<table width='50%'><tr><td class='colhead' colspan='3' align='center'>
       ".$TBDEV['crazy_title']." Ends in ".mkprettytime($crazyhour_var - TIME_NOW)."</td></tr>
       <tr><td width='42px' align='center' valign='middle'>". $cimg."</td>
       <td><div align='center'>". $TBDEV['crazy_message']."</div></td>
       <td width='42px' align='center' valign='middle'>".$cimg."</td></tr></table><br />";
        if (is_file($transfer_filename))
            unlink($transfer_filename);
    }
    elseif ($crazyhour_var < TIME_NOW + 3600 && !is_file($transfer_filename)) { //== crazyhour over
        $transfer_file_created = fopen($transfer_filename, 'w') or die('no perms?');
        fclose($transfer_file_created);
        $crazyhour['crazyhour_new']       = mktime(23, 59, 59, date('m'), date('d'), date('y'));
        $crazyhour['crazyhour']['var']    = mt_rand($crazyhour['crazyhour_new'], ($crazyhour['crazyhour_new'] + 86400));
        $fp = fopen($crazyhour_filename, 'w');
        fwrite($fp, $crazyhour['crazyhour']['var']);
        fclose($fp);
        write_log('Next Crazyhour is at '.date('F j, g:i a T', $crazyhour['crazyhour'] ['var']));
        $htmlout .="<table cellpadding='3'><tr><td class='colhead' colspan='3' align='center'>"." Crazyhour will be ".get_date($crazyhour['crazyhour']['var'], '')."  ".mkprettytime($crazyhour['crazyhour']['var'] - TIME_NOW)." remaining till Crazyhour</td></tr></table><br />";
        }
        else // make date look prettier with countdown etc even :]
        $htmlout .="<table cellpadding='3'><tr><td class='colhead' colspan='3' align='center'>"." Crazyhour will be ".get_date($crazyhour_var, '')."  ".mkprettytime($crazyhour_var - TIME_NOW)." remaining till Crazyhour</td></tr></table><br />";
        }
      // crazyhour end

        
Thats it - i've tested the system and verified it on Crazyhour and off and all is fine.