Advertisement
Sosowski

Ludum Dare Theme Slaughter Code

Dec 6th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.33 KB | None | 0 0
  1. <?php
  2.  
  3. function get_ip() {
  4. $ip;
  5. if (getenv("HTTP_CLIENT_IP"))
  6. $ip = getenv("HTTP_CLIENT_IP");
  7. else if(getenv("HTTP_X_FORWARDED_FOR"))
  8. $ip = getenv("HTTP_X_FORWARDED_FOR");
  9. else if(getenv("REMOTE_ADDR"))
  10. $ip = getenv("REMOTE_ADDR");
  11. else
  12. $ip = "UNKNOWN";
  13. return $ip;
  14. }
  15.  
  16. function is_bot($user_agent)
  17. {
  18.   //if no user agent is supplied then assume it's a bot
  19.   if($user_agent == "")
  20.     return 1;
  21.  
  22.   //array of bot strings to check for
  23.   $bot_strings = Array(  "google",     "bot",
  24.             "yahoo",     "spider",
  25.             "archiver",   "curl",
  26.             "python",     "nambu",
  27.             "twitt",     "perl",
  28.             "sphere",     "PEAR",
  29.             "java",     "wordpress",
  30.             "radian",     "crawl",
  31.             "yandex",     "eventbox",
  32.             "monitor",   "mechanize",
  33.             "facebookexternal"
  34.           );
  35.   foreach($bot_strings as $bot)
  36.   {
  37.     if(strpos($user_agent,$bot) !== false)
  38.     { return 1; }
  39.   }
  40.  
  41.   return 0;
  42. }
  43.  
  44. if (is_bot($_SERVER['HTTP_USER_AGENT'])) die;
  45.  
  46. $bans = file('ban.txt');
  47. foreach ($bans as $b)
  48. {
  49.     if (trim($b)==get_ip())
  50.     {
  51.         echo '<H1>FUCK YOU!</h1>';
  52.         ECHO '<H1>Sincerely, Sos ( just.sos.it@gmail.com )</h1>';
  53.         die;
  54.     }
  55.    
  56. }
  57.  
  58.  
  59. function get_db()
  60. {
  61.     $link = mysql_connect('localhost', 'me', '*****');
  62.     if (!$link) die('Could not connect: ' . mysql_error());
  63.     if (!mysql_select_db('themes')) die('Could not select database');
  64.     return $link;
  65. }
  66. $themes = array();
  67. $link = get_db();
  68. $query = 'SELECT * FROM `themes` WHERE `id`<808080 ORDER BY rand() LIMIT 1;';
  69. $c=0;
  70. $result = mysql_query($query);
  71. while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
  72. {
  73.     $themes[$c]=$line;
  74.     $c++;
  75. }
  76. $total = array();
  77. $query = 'SELECT * FROM `themes` WHERE `id`=888888;';
  78. $result2 = mysql_query($query);
  79. while ($line = mysql_fetch_array($result2, MYSQL_ASSOC))
  80. {
  81.     $total=$line;
  82. }
  83.  
  84. $target=500000;
  85. $pixs = ($total['up'])/($target/100);
  86. //if ($pixs>100) $pixs=100;
  87.  
  88. //echo'<center style="font-family:sans-serif;"><br/><br/><h1>IT ENDED, the slaughter!</H1></CENTER>';
  89. //echo'<center style="font-family:sans-serif;"><br/><br/><h1>'.$total['up'].' votes were given</H1></CENTER>';
  90. //echo'<center style="font-family:sans-serif;"><br/><br/><h1>I am too sleepy to do post results tonight.</H1></CENTER>';
  91.  
  92. //$_GET['shit']='all';
  93. if (isset($_GET['shit']))
  94. {
  95.     //$number = ($_GET['view']='all');
  96.     mysql_free_result($result);
  97.     $sort = '(`up`-`down`) DESC';
  98.     if (isset($_GET['sort']))
  99.     {
  100.         if (($_GET['sort'])=='0') $sort = '(`up`-`down`) DESC';
  101.         if (($_GET['sort'])=='1') $sort = '(`theme`)';
  102.         if (($_GET['sort'])=='2') $sort = '(`up`) DESC';
  103.         if (($_GET['sort'])=='3') $sort = '(`down`)';
  104.     }
  105.     $query = 'SELECT * FROM `themes` WHERE `id`<808080 ORDER BY '.$sort.' '.(($_GET['shit']=='all') ? '' : 'LIMIT 100').';';
  106.     $c=0;
  107.     $result = mysql_query($query);
  108.     if (!$result) die('Query error: ' . mysql_error());
  109.     echo '<h1 style="color:red;font-family:sans-serif;text-align:center;">THEME KILLING RESULTS!</h1>';              
  110.     echo '<b style="color:#48f;font-family:sans-serif;text-align:center;display:block;">'.$total['up'].' votes given</b>';  
  111.  
  112.     echo '<table style="width:90%;font-family:sans-serif;">';
  113.     echo '<tr>
  114. <td width=40><b><a href="?shit='.$_GET['shit'].'&sort=0">RANK</a></b></td>
  115. <td width=200><b><a href="?shit='.$_GET['shit'].'&sort=1">THEME</a></b></td>
  116. <td width=600><b><a href="?shit='.$_GET['shit'].'&sort=2">VOTES</a></b></td>
  117. <td><b><a href="?shit='.$_GET['shit'].'&sort=3">DOWNVOTES</a></b></td></tr>';
  118.     $c=0;
  119.     $ups=0;
  120.     $downs=0;
  121.     while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
  122.     {
  123.     $votes = $line['up'];
  124.     $downvotes = $line['down'];
  125.            
  126.         echo '<tr style="background:'. (($c&1) ? '#eee' : '#ddd').';">
  127.     <td width=40><center><b>'.($c+1).'.</b></center></td>
  128.     <td width=200>'.$line['theme'].'</td>
  129.     <td><img src="'.(($votes > 500 ) ? 'redbar.png' : 'greenbar.png').'" width="'.(($votes > 500 ) ? 500 : $votes).'" height="20"/>&nbsp;'.$votes.'</td>
  130.     <td><img src="'.(($downvotes > 100 ) ? 'redbar.png' : 'greenbar.png').'" width="'.(($downvotes > 100 ) ? 100 : $downvotes).'" height="20"/>&nbsp;'.$downvotes.'</td></tr>';
  131.         $c++;
  132.         $ups+=$line['up'];
  133.         $downs+=$line['down'];
  134.     }
  135.     echo '</table>';
  136.     echo '<b style="color:#4f8;font-family:sans-serif;text-align:center;display:block;">'.$ups.' upvotes given</b>';   
  137.     echo '<b style="color:#f84;font-family:sans-serif;text-align:center;display:block;">'.$downs.' downvotes given</b>';   
  138.         mysql_free_result($result);
  139.         mysql_free_result($result2);
  140.         mysql_close($link);
  141.         die;
  142. }
  143. $agent = "BOT BOT BOT BOT BOT BOT";
  144. if (isset($_SERVER['HTTP_USER_AGENT'])) $agent = $_SERVER['HTTP_USER_AGENT'];
  145. if (isset($_GET['up']))
  146. {
  147.     //die;
  148.     $up = mysql_real_escape_string($_GET['up']);
  149.  
  150.     $query = 'UPDATE `themes` SET `up`=`up`+1, `time`='.time().' WHERE `id`='.$up.' AND `time`<'.(time()-20).';';
  151.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  152.     $query = 'UPDATE `themes` SET `up`=`up`+1 WHERE `id`=888888;';
  153.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  154.    
  155.     $ff = fopen('log.txt','a');
  156.     fwrite($ff,'IP: '.get_ip().' | UP: '.$up.' | TIME: '.date('d-m-y H:i:s').' | ' . $agent . "\n");
  157.     fclose($ff);
  158. }
  159.  
  160. if ( isset($_GET['down']))
  161. {
  162.     //die;
  163.     $down = mysql_real_escape_string($_GET['down']);
  164.  
  165.     $query = 'UPDATE `themes` SET `down`=`down`+1, `time`='.time().' WHERE `id`='.$down.' AND `time`<'.(time()-20).';';
  166.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  167.     $query = 'UPDATE `themes` SET `up`=`up`+1 WHERE `id`=888888;';
  168.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  169.    
  170.     $ff = fopen('log.txt','a');
  171.     fwrite($ff,'IP: '.get_ip().' | DOWN: '.$down.' | TIME: '.date('d-m-y H:i:s').' | ' . $agent . "\n");
  172.     fclose($ff);
  173. }
  174.  
  175. if ( isset($_GET['kill']))
  176. {
  177.     //die;
  178.     $down = mysql_real_escape_string($_GET['kill']);
  179.  
  180.     $query = 'UPDATE `themes` SET `down`=`down`+10, `time`='.time().' WHERE `id`='.$down.' AND `time`<'.(time()-20).';';
  181.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  182.     $query = 'UPDATE `themes` SET `up`=`up`+1 WHERE `id`=888888;';
  183.     if (!mysql_query($query)) die('Query error: ' . mysql_error());
  184.    
  185.     $ff = fopen('log.txt','a');
  186.     fwrite($ff,'IP: '.get_ip().' | KILL: '.$down.' | TIME: '.date('d-m-y H:i:s').' | ' . $agent . "\n");
  187.     fclose($ff);
  188. }
  189.  
  190. echo'<center style="font-family:sans-serif;"><br/><br/><img src="SLAUGHTER.gif"><br/><br/><table style="border:1px solid #555;font-size:250%;font-family:sans-serif;text-align:center;width:700px;">';
  191. echo'<tr><td style="border:1px solid #555;padding:20px;text-align:center;" colspan=2><a target="_blank" style="color:#4b7aa0;" href="https://www.google.com/search?q='.urlencode($themes[0]['theme']).'">'.$themes[0]['theme'].'</a></td></tr>';
  192. echo'<tr><td style="border:1px solid #555;padding:20px;text-align:center;width:50%;"><a style="color:#080;" href="?up='.$themes[0]['id'].'">GOOD</a></td>';
  193. echo'<td style="border:1px solid #555;padding:20px;text-align:center;width:50%;"><a style="color:#800;" href="?down='.$themes[0]['id'].'">BAD</a></td></tr>';
  194. echo'<tr><td style="border:1px solid #555;padding:20px;text-align:center;" colspan=2;><a style="color:#f00;" href="?kill='.$themes[0]['id'].'">SLAUGHTER</a></td></tr>';
  195. echo '<tr><td style="border:1px solid #555;padding:20px;text-align:center;" colspan=2>';
  196. echo '<b>Slaughter progress:</b> '.sprintf("%1.4f",$pixs).'%<br/>';
  197. echo '<i style="font-size:50%">Target kill count: <del>100000</del> '.$target.'</i><br/>';
  198. echo '<div style="text-align:left;border:1px solid black; width:100%;"><img src="greenbar.png" width="'.$pixs.'%" height="32"></div>';
  199. echo '<span style="color:#501;font-size:50%;">Slaughter ends on friday the 7th regardless of this bar</span>';
  200. echo '</td></tr>';
  201. echo '</table>';
  202. echo '<br/><br/><br/><br/><b>How does it work:</b><br/>';
  203. echo '
  204. You get a theme clickie <b>GOOD</b> or <b>BAD</b>!<br/>
  205. If it\'s not a theme, hit <b>SLAUGHTER</b><br/>
  206. <b>no hacking plz!</b><br/><br>
  207. <b style="color:#248;font-size:250%;">NOTE:</b><br/>
  208. <span style="color:#048;font-size:150%;">Stuff like <i>\'2-bit art\' or \'one button controls\' or \'racing game\'</i><br/>and any other implying genre, technical or any other limitations are <B>NOT THEMES</b><br/>Please vote them down. I will remove them regardless of votes anyways.</span>
  209. ';
  210. mysql_free_result($result);
  211. mysql_free_result($result2);
  212. mysql_close($link);
  213. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement