Minified PHP Code



  • Continuing the discussion from Do I? Don't I? Advice plz.:

    @riking said:

    You may also be interested in this monstrosity, which I did not write:

    Okay, but seriously? Minified PHP code. It's a bit of an eye strain.

    Code reproduced below for posterity:

    <php,map=steamid>define('_A','ranks');define('_B','rankst');define('_C','//table[@id="table-apps"]/tbody');define('_D','data-sort');ob_start(function($_){return trim($_);});function cmptime($a,$b){return$a[2]<$b[2];}function cmpvalue($a,$b){$_=1000000;$c=1000000;if(($a[2]!==0)&&($a[3]!==0)){$_=$a[3]/$a[2];}else if($a[2]===0){$_+=$a[3];}if(($b[2]!==0)&&($b[3]!==0)){$c=$b[3]/$b[2];}else if($b[2]===0){$c+=$b[3];}return$_>$c;}function cmpvalue2($a,$b){$_=-1000000;$c=-1000000;if(($a[2]!==0)&&($a[3]!==0)){$_=$a[3]/$a[2];}else if($a[2]===0){$_+=$a[3];}if(($b[2]!==0)&&($b[3]!==0)){$c=$b[3]/$b[2];}else if($b[2]===0){$c+=$b[3];}return$_<$c;}function cmpwasted($a,$b){return$a[3]<$b[3];}function cmpstrmoney($a,$b){return floatval(substr($a,1))*100<floatval(substr($b,1))*100;}function cmpint($a,$b){return$a<$b;}function money($d,$e,$f){if($e===0)return'Free';if($f===0)return'N/A';$g='*';$h='%1$s%2$.2f';switch($d){case'au':case'us':$g='$';break;case'de':case'no':$g='€';$h='%2$.2f%1$s';break;case'uk':$g='£';break;case'ru':$g='р.';$h='%2$.2f%1$s';break;case'br':$g='R$';break;}return sprintf($h,$g,($e/100)/($f/60));}function todiff($i){$j=new DateTime();$k=new DateTime();$k->add(new DateInterval('PT'.$i));$l=$k->diff($j);$m=[];if($l->days>0)$m[]=sprintf('%dd',$l->days);if($l->h>0)$m[]=sprintf('%dh',$l->h);if($l->i>0)$m[]=sprintf('%dm',$l->i);if(count($m)==0)return'N/A';return implode(' ',$m);}function loadstate(){global $n,$_STATE;$n=json_decode(json_encode($_STATE),true);if(!isset($n)||$n==[]||gettype($n)!=='array')$n=[_A=>[],_B=>[]];return$n;}try{if($argc===1||$argc===2){$o=strtolower($sender);$p=$argc===2?strtolower($arg[1]):$o;switch(strtolower($arg[0])){case'ranking':printf('Ranking: ');$n=loadstate();uasort($n[_A],'cmpstrmoney');foreach($n[_A]as$q=>$r){printf("\$odd(%s): %s\n",$q,$r);}break;case'rankingtime':printf('Ranking (time): ');$n=loadstate();uasort($n[_B],'cmpint');foreach($n[_B]as$q=>$r){$s=(int)$r;$t=(int)(($r-$s)*60);printf("\$odd(%s): %s\n",$q,todiff($s.'H'.$t.'M'));}break;case'dump':$n=loadstate();echo json_encode($n);break;}throw new Exception('');}else if($argc<4){throw new Exception('usage: <type[time|value|value2|wasted|list|ids|roulette]> <region[us|de|no|uk|ru|br|au]> <gamelimit> <name> OR <type[ranking|rankingtime]> <id[?]>');}$u=$arg[0];$d=$arg[1];$v=(int)$arg[2];$w=implode(' ',array_splice($arg,3));$x=strtolower($w);$n=loadstate();if(isset($map)){$map=array_change_key_case($map);if(array_key_exists($x,$map)){$x=strtolower($map[$x]);}}$y=Requests::get('http://steamdb.info/calculator/?'.http_build_query(['currency'=>$d,'player'=>$x]),[],['timeout'=>10]);if($y->status_code!==200)throw new Exception('failed steamdb.info');$z=$y->body;$A='';try{$y=Requests::get('http://steamcommunity.com/id/'.urlencode($x).'/badges/',[],['timeout'=>5]);if($y->status_code===200){$A=$y->body;if(preg_match('#<h3>The specified profile could not be found.</h3>#',$A)!==false){$y=Requests::get('http://steamcommunity.com/profiles/'.urlencode($x).'/badges/',[],['timeout'=>5]);if(count($y->history)>0){if(preg_match('#http://steamcommunity.com/id/(.*?)/badges/?#',$y->history[0]->headers->offsetGet("location"),$B)){unset($n[_A][$x]);unset($n[_B][$x]);$x=$B[1];}$A=$y->body;}}}}catch(Exception $C){}if(preg_match('#Failed to resolve CustomURL#',$z,$D))throw new Exception($x.': does not exist');if(preg_match('#This profile is private#',$z,$D))throw new Exception($x.': profile is private');if(preg_match('#Failed to receive player\'s games#',$z,$D))throw new Exception($x.': failed to recieve game list');$E=preg_match('#has not purchased any games on Steam#',$z,$D)===1;$F=new DOMDocument();@$F->loadHTML($z);$G=new DOMXPath($F);if(strtolower($u)=='ids'){$H=[];$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr/td[1]');foreach($I as$K){$H[]=intval($K->textContent);}}die(json_encode($H));}else if(strtolower($u)=='roulette'){$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr/td[3]');if($I->length!==0){$L=rand()%$I->length;printf('%s: %s [%d/%d]',$w,$I->item($L)->textContent,$L,$I->length);die();}}die($w.' has no games :(');}$I=$G->query('//h1[contains(@class,"header-title")]/a[contains(@href,"profiles")]');if($I->length===1){printf("%s: ",$I->item(0)->textContent);if($E)printf("doesn't own any games\n");$I=$G->query('//span[contains(concat(" ", normalize-space(@class), " "), " calculator-price ")]');if($I->length===1){$M='';$N=$G->query('//span[contains(@class,"calculator-price-lowest")]');if($N->length===1){$M=sprintf(' (%s)',$N->item(0)->textContent);}printf("%s%s\n",$I->item(0)->textContent,$M);$O=str_replace(',','.',$I->item(0)->textContent);if($O[0]==='$'){$n[_A][$x]=$O;uasort($n[_A],'cmpstrmoney');$P=array_chunk($n[_A],10,true);$n[_A]=$P[0];$_STATE=$n;}}else if(!$E)printf("failed cost\n");$I=$G->query('//tr[contains(td/text(),"Status")]/td[2]');if($I->length===1)printf("%s\n",$I->item(0)->textContent);else{printf("failed status\n");$Q=-1;}if(strlen($A)>0){$R=new DOMDocument();@$R->loadHTML($A);$S=new DOMXPath($R);$I=$S->query('//div/span[@class="profile_xp_block_level"]/span/span');if($I->length===1){printf("Level: %d",$I->item(0)->textContent);$I=$S->query('//div/span[@class="profile_xp_block_xp"]');if($I->length===1)$T=preg_replace('#[^\d]#','',$I->item(0)->textContent);else$T=-1;$I=$S->query('//div/div[@class="profile_xp_block_remaining"]');if($I->length===1)$U=preg_replace('#(Level \d+|[^\d])#','',$I->item(0)->textContent);else$U=-1;if($T>0&&$U>0)printf(" (%d/%d)",$T,$T+$U);printf("\n");$I=$S->query('//div[@class="badge_info_unlocked"]');printf("Badges: %d\n",$I->length);}else printf("failed level\n");}$I=$G->query('//tr[contains(td/text(),"Games owned")]/td[2]');$Q=-1;if($I->length===1)$Q=$I->item(0)->textContent;else if(!$E)printf("failed owned\n");$V=0;$H=[];$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr');foreach($I as$K){$W=$K->getElementsByTagName('td');$H[]=[$W->item(1)->textContent,$W->item(2)->textContent,(int)$W->item(3)->getAttribute(_D),(int)$W->item(4)->getAttribute(_D)];if((int)$W->item(3)->getAttribute(_D)===0)$V++;}}else if(!$E)printf("failed games\n");if($Q>0)printf("Games played/owned: %d/%d (%.1f%%)\n",$Q-$V,$Q,100*($Q-$V)/$Q);$I=$G->query('//tr[contains(td/text(),"Hours spent")]/td[2]');if($I->length===1){$m=floatval(preg_replace('#h$#','',str_replace(',','',$I->item(0)->textContent)));$n[_B][$x]=$m;uasort($n[_B],'cmpint');$P=array_chunk($n[_B],10,true);$n[_B]=$P[0];$_STATE=$n;$s=(int)$m;$t=(int)(($m-$s)*60);printf("Time spent: %s\n",todiff($s.'H'.$t.'M'));}else if(!$E)printf("failed hours spent\n");$I=$G->query('//tr[contains(td/text(),"Profile creation")]/td[2]/span/@title');if($I->length===1)printf("Profile created: %s\n",date('M j, Y',strtotime($I->item(0)->textContent)));else printf("failed profile creation\n");$I=$G->query('//tr[contains(td/text(),"Last log off")]/td[2]/span/@title');if($I->length===1)printf("Last seen: %s\n",date('M j, Y',strtotime($I->item(0)->textContent)));else printf("failed last seen\n");if(count($H)>0){switch($u){case'time':usort($H,'cmptime');break;case'value':usort($H,'cmpvalue');break;case'value2':usort($H,'cmpvalue2');break;case'wasted':usort($H,'cmpwasted');break;}$j=new DateTime();switch($u){case'time':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){printf("\x02%s\x02: %s\n",trim($H[$L][1]),todiff($H[$L][2].'M'));$X++;}break;case'value':case'value2':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){if($H[$L][3]>0){printf("\x02%s\x02: %s per hour (%s)\n",trim($H[$L][1]),money($d,$H[$L][3],$H[$L][2]),money($d,$H[$L][3],60));$X++;}}break;case'wasted':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){if($H[$L][2]==0){printf("\x02%s\x02 (%s)\n",trim($H[$L][1]),money($d,$H[$L][3],60));$X++;}}break;case'list':ob_clean();$P=[];for($L=0;$L<count($H);$L++){$P[]=trim($H[$L][1]);}echo json_encode($P);break;}}}else printf("Profile %s doesn't exist.",$x);}catch(Exception $Y){printf('%s',$Y->getMessage());}
    

    Any other minified PHP you've seen? Or anyone feel like taking a crack at making sense of this? (It's called !steamcalcbase.)



  • Another great one for you. Try to figure out what it does! Although you'd probably figure it out from the strings.

    <php>function cmp($_,$a){return$_[1]<$a[1];}try{$b=$_STATE;$c=strtolower($sender);$d=count($arg)>0?strtolower(array_shift($arg)):'pull';$e=count($arg)>0?min(max(array_shift($arg),1),6):1;if($b===null||!is_object($b))$b=json_decode('{}');if(!property_exists($b,'last'))$b->last='';if(!property_exists($b,'rank'))$b->rank=json_decode('{}');if($d==='reload'||$d==='set'||!property_exists($b,'chamber')){$b->chamber=[];for($f=0;$f<$e;$f++){$b->chamber[]=1;}for($f=0;$f<6-$e;$f++){$b->chamber[]=0;}$b->last='';throw new Exception(sprintf('Revolver loaded with %d bullet%s!',$e,$e>1?'s':''));}if($d==='rank'||$d==='revrank'){$g=[];foreach($b->rank as$h=>$i){$g[]=[$h,$i];}usort($g,'cmp');if($d==='revrank'){$g=array_reverse($g);}$j='';foreach($g as$h){$j .= sprintf("\$odd(%s): %s\n",$h[0],$h[1]);if(strlen($j)>380)break;}throw new Exception('Leaderboard: '.$j);}if(!in_array(1,$b->chamber))throw new Exception('No bullets in the revolver! Reload!');if($c==$b->last)throw new Exception($sender.': don\'t rush it!');if(!property_exists($b->rank,$c)){$b->rank->$c=0;}$k=array_count_values($b->chamber);$l=array_key_exists(0,$k)?$k[0]:0;$e=array_key_exists(1,$k)?$k[1]:0;shuffle($b->chamber);$m=array_shift($b->chamber);if($m===1){$b->rank->$c-=1+$l;}else{$b->rank->$c+=1;}printf('%s: *%s*',$sender,$m===1?'BANG':'click');$b->last=$c;$_STATE=$b;}catch(Exception $n){$_STATE=$b;printf('%s',$n->getMessage());}
    

    The great part about this one is that it gets a global $_STATE variable that is automatically saved and reloaded across invocations. Which is promptly assigned to $b, because that's shorter. Minified, remember?



  • Looks more like somebody was making a bot for an fps, by the strings. I don't see minimized code as a wtf inherently. If that's how it was being maintained, then yeah. But there's any number of formatters online that will at least format it in a sane way - and this script is short enough to not be crazy hard to figure out. It's mostly just getting data from the server, parsing it, then executing [do something].

    Now, throwing exceptions when you can't shoot due to being out of ammo, or time between shots... that's a different discussion.



  • @Matches said:

    It's mostly just getting data from the server, parsing it, then executing [do something].

    Noooot quite... the only data it uses is from $_STATE $arg $args $argc $sender, which are defined, then the script is run, then the output is displayed to the user.

    @Matches said:

    Now, throwing exceptions when you can't shoot due to being out of ammo, or time between shots... that's a different discussion.

    It also throws an exception on success.

    throw new Exception('Leaderboard: '.$j);
    

    This code is used like so:

    <Riking> !roulette
    <Shocky> No bullets in the revolver! Reload!
    <Riking> !roulette reload
    <Shocky> Revolver loaded with 1 bullet!
    <Riking> !roulette
    <Shocky> Riking: *click*
    <Player2> !roulette
    <Shocky> Player2: *click*
    <Riking> !roulette
    <Shocky> Riking: *BANG*
    <Riking> gg




  • In other words, they are passing messages like minecraft servers.



  • @Matches said:

    minecraft servers

    www.mediafire.com/view/6l8mkp78cd6idii/realserverlog



  • I wonder if there's some way to share text... Maybe somewhere you can "paste" the text? Maybe some kind of "bin"?



  • Minecraft servers would probably be a lot faster if they didn't log all that shit to disk and just kept it in memory.



  • I tried. Chrome rejected the ctrl-v. The Forge startup logs are pretty insane.

    Shocky also has transient paste storage. This link will die the next time the bot restarts: http://bots.axxim.net:8000/p/e

    This will probably have content a month from now - no telling what it is, though: http://bots.axxim.net:8000/p/1
    This too, but it'll probably be a RSS feed entry: http://bots.axxim.net:8000/s/1



  • Those are all plugins written by 12 year olds.

    Source: I wrote some plugins when I was 12.



  • In an amazing show of consistency, I present the !rr command:

    <js>r=["Click.","Click.","Click.","Bang.","Click.","Click."];sender+": "+r[Math.floor(Math.random()*6)];
    


  • Why not just

    <js>sender+": "+(Math.random()*6|0?"Click":"Bang")
    


  • Or even:

    <alias>roulette %inp%


  • <roulettescript>
    


  • That's not an installed scripting module, unfortunately.



  • Note that there is all kinds of fun recursion in there.

    For example, you can have multiple layers of <alias>es pointing to a <php> factoid that outputs <lua> code which spits out an <action>.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.