Created
October 25, 2025 01:40
-
-
Save nullfx/9f8fa02103c0699585e1f4a7d3ca29d5 to your computer and use it in GitHub Desktop.
old bf2 rank script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /**********************************************************************/ | |
| /** Battlefield 2 Rank avatar **/ | |
| /** by: Steve Whitley (aka [OinK]_MadHatter) **/ | |
| /** Copyright © 2005 NullFX Software **/ | |
| /** **/ | |
| /** Licensed under the Creative Commons **/ | |
| /** Attribution-NonCommercial-ShareAlike License **/ | |
| /** **/ | |
| /** http://creativecommons.org/licenses/by-nc-sa/2.5/ **/ | |
| /** **/ | |
| /**********************************************************************/ | |
| $do_text = !isset($_GET['no_text']); | |
| $do_score = isset($_GET['score']); | |
| $who = "nick=NOTHING"; | |
| $delta = isset($_GET['delta']); | |
| $std = !isset($_GET['delta']); | |
| define('PERCENT', 100); | |
| define('PRIVATE', 0); | |
| define('PRIVATE_FIRST_CLASS', 1); | |
| define('LANCE_CORP', 2); | |
| define('CORPORAL', 3); | |
| define('SERGANT', 4); | |
| define('STAFF_SERGANT', 5); | |
| define('GUNNERY_SERGANT', 6); | |
| define('MASTER_SERGANT', 7); | |
| define('FIRST_SERGANT', 8); | |
| define('MASTER_GUNNERY_SERGANT', 9); | |
| define('SERGEANT_MAJOR', 10); | |
| define('SERGEANT_MAJOR_OF_CORPS', 11); | |
| define('SECOND_LIEUTENANT', 12); | |
| define('FIRST_LIEUTENANT', 13); | |
| define('CAPTAIN', 14); | |
| define('MAJOR', 15); | |
| define('LIEUTENANT_COLONEL', 16); | |
| define('COLONEL', 17); | |
| define('BRIGADIER_GENERAL', 18); | |
| define('MAJOR_GENERAL', 19); | |
| define('LIEUTENANT_GENERAL', 20); | |
| define('GENERAL', 21); | |
| $ranks = array( | |
| PRIVATE => 0, | |
| PRIVATE_FIRST_CLASS => 150, | |
| LANCE_CORP => 500, | |
| CORPORAL => 800, | |
| SERGANT => 2500, | |
| STAFF_SERGANT => 5000, | |
| GUNNERY_SERGANT => 8000, | |
| MASTER_SERGANT => 20000, | |
| FIRST_SERGANT => 20000, | |
| MASTER_GUNNERY_SERGANT => 50000, | |
| SERGEANT_MAJOR => 50000, | |
| SERGEANT_MAJOR_OF_CORPS => 50000, | |
| SECOND_LIEUTENANT => 60000, | |
| FIRST_LIEUTENANT => 75000, | |
| CAPTAIN => 90000, | |
| MAJOR => 115000, | |
| LIEUTENANT_COLONEL => 125000, | |
| COLONEL => 150000, | |
| BRIGADIER_GENERAL => 180000, | |
| MAJOR_GENERAL => 180000, | |
| LIEUTENANT_GENERAL => 200000, | |
| GENERAL => 200000 | |
| ); | |
| // web request stuff | |
| require_once("http.php"); | |
| $query = "nick=NOTHING"; | |
| if(isset($_GET['pid'])) { | |
| $query = "pid=".$_GET['pid']; | |
| }else if(isset($_GET['nick'])) { | |
| $query = "pid=".get_pid($_GET['nick']); | |
| } | |
| $req = new http_class(); | |
| $req->timeout = 0; | |
| $req->data_timeout = 0; | |
| $req->user_agent="GameSpyHTTP/1.0"; | |
| // this is overkill I know but as of November 8 2005, EA requires this | |
| // entire query. If all columns are not present, nothing is returned | |
| $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?".$query."&info=per*,cmb*,twsc,cpcp,cacp,dfcp,kila,heal,rviv,rsup,rpar,tgte,dkas,dsab,cdsc,rank,cmsc,kick,kill,deth,suic,ospm,klpm,klpr,dtpr,bksk,wdsk,bbrs,tcdr,ban,dtpm,lbtl,osaa,vrk,tsql,tsqm,tlwf,mvks,vmks,mvn*,vmr*,fkit,fmap,fveh,fwea,wtm-,wkl-,wdt-,wac-,wkd-,vtm-,vkl-,vdt-,vkd-,vkr-,atm-,awn-,alo-,abr-,ktm-,kkl-,kdt-,kkd-"; | |
| $args = null; | |
| $error = $req->GetRequestArguments($url, $args); | |
| if($error != "") { | |
| $img = imagecreatefromjpeg("./unavailable.jpg"); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| die(); | |
| } | |
| $error = $req->Open($args); | |
| flush(); | |
| if($error != "") { | |
| $img = imagecreatefromjpeg("./unavailable.jpg"); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| die(); | |
| } | |
| $req->SendRequest($args); | |
| flush(); | |
| $headers = array(); | |
| $req->ReadReplyHeaders($headers); | |
| if($req->response_status != "200") { | |
| $img = imagecreatefromjpeg("./unavailable.jpg"); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| die(); | |
| } | |
| if($req->content_length_set && $req->content_length <= 0) { | |
| $img = imagecreatefromjpeg("./pid_change.jpg"); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| die(); | |
| } | |
| // read the reply and parse the info out | |
| $score = 0; | |
| $rank_val = 0; | |
| $next = 0.0; | |
| do { | |
| $error=$req->ReadReplyBody($body, 4096); | |
| $lines = split("\n", $body); | |
| $get_data = false; | |
| for($i = 0; $i < count($lines); $i++) { | |
| $line = $lines[$i]; | |
| $pieces = split("\t", $line); | |
| for($j = 0; $j < count($pieces); $j++) { | |
| $part = $pieces[$j]; | |
| if($part == "H") { | |
| if($pieces[$j+1] != "asof") { | |
| $get_data = true; | |
| break; | |
| }else { | |
| $get_data = false; | |
| } | |
| } | |
| if($part == "D" && $get_data) { | |
| $score = $pieces[$j+3]; | |
| $rank_val = $pieces[$j+39]; | |
| break; | |
| } | |
| } | |
| } | |
| }while($error == "" && strlen($body) != 0); | |
| if($score == 0 || $rank_val == 0) { | |
| $img = imagecreatefromjpeg("./unavailable.jpg"); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| die(); | |
| } | |
| switch ($rank_val) { | |
| case PRIVATE: { | |
| $next = ($score / $ranks[PRIVATE_FIRST_CLASS]) * PERCENT; | |
| }break; | |
| case PRIVATE_FIRST_CLASS: { | |
| $next = $std?($score / $ranks[LANCE_CORP]) * PERCENT : | |
| ((($score - $ranks[PRIVATE_FIRST_CLASS]) / ($ranks[LANCE_CORP] - $ranks[PRIVATE_FIRST_CLASS])) * PERCENT); | |
| }break; | |
| case LANCE_CORP: { | |
| $next = $std?($score / $ranks[CORPORAL]) * PERCENT : | |
| ((($score - $ranks[LANCE_CORP]) / ($ranks[CORPORAL] - $ranks[LANCE_CORP])) * PERCENT); | |
| }break; | |
| case CORPORAL: { | |
| $next = $std?($score / $ranks[SERGANT]) * PERCENT : | |
| ((($score - $ranks[CORPORAL]) / ($ranks[SERGANT] - $ranks[CORPORAL])) * PERCENT); | |
| }break; | |
| case SERGANT: { | |
| $next = $std?($score / $ranks[STAFF_SERGANT]) * PERCENT : | |
| ((($score - $ranks[SERGANT]) / ($ranks[STAFF_SERGANT] - $ranks[SERGANT])) * PERCENT); | |
| }break; | |
| case STAFF_SERGANT: { | |
| $next = $std?($score / $ranks[GUNNERY_SERGANT]) * PERCENT : | |
| ((($score - $ranks[STAFF_SERGANT]) / ($ranks[GUNNERY_SERGANT] - $ranks[STAFF_SERGANT])) * PERCENT); | |
| }break; | |
| case GUNNERY_SERGANT: { | |
| $next = $std?($score / $ranks[MASTER_SERGANT]) * PERCENT : | |
| ((($score - $ranks[GUNNERY_SERGANT]) / ($ranks[MASTER_SERGANT] - $ranks[GUNNERY_SERGANT])) * PERCENT); | |
| }break; | |
| case MASTER_SERGANT: { | |
| $next = $std?($score / $ranks[MASTER_GUNNERY_SERGANT]) * PERCENT : | |
| ((($score - $ranks[MASTER_SERGANT]) / ($ranks[MASTER_GUNNERY_SERGANT] - $ranks[MASTER_SERGANT])) * PERCENT); | |
| }break; | |
| case FIRST_SERGANT: { | |
| $next = $std?($score / $ranks[MASTER_GUNNERY_SERGANT]) * PERCENT : | |
| ((($score - $ranks[FIRST_SERGANT]) / ($ranks[MASTER_GUNNERY_SERGANT] - $ranks[FIRST_SERGANT])) * PERCENT); | |
| }break; | |
| case MASTER_GUNNERY_SERGANT: { | |
| $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : | |
| ((($score - $ranks[MASTER_GUNNERY_SERGANT]) / ($ranks[SECOND_LIEUTENANT] - $ranks[MASTER_GUNNERY_SERGANT])) * PERCENT); | |
| }break; | |
| case SERGEANT_MAJOR: { | |
| $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : | |
| ((($score - $ranks[SERGEANT_MAJOR]) / ($ranks[SECOND_LIEUTENANT] - $ranks[SERGEANT_MAJOR])) * PERCENT); | |
| }break; | |
| case SERGEANT_MAJOR_OF_CORPS: { | |
| $next = $std?($score / $ranks[SECOND_LIEUTENANT]) * PERCENT : | |
| ((($score - $ranks[SERGEANT_MAJOR_OF_CORPS]) / ($ranks[SECOND_LIEUTENANT] - $ranks[SERGEANT_MAJOR_OF_CORPS])) * PERCENT); | |
| }break; | |
| case SECOND_LIEUTENANT: { | |
| $next = $std?($score / $ranks[FIRST_LIEUTENANT]) * PERCENT : | |
| ((($score - $ranks[SECOND_LIEUTENANT]) / ($ranks[FIRST_LIEUTENANT] - $ranks[SECOND_LIEUTENANT])) * PERCENT); | |
| }break; | |
| case FIRST_LIEUTENANT: { | |
| $next = $std?($score / $ranks[CAPTAIN]) * PERCENT : | |
| ((($score - $ranks[FIRST_LIEUTENANT]) / ($ranks[CAPTAIN] - $ranks[FIRST_LIEUTENANT])) * PERCENT); | |
| }break; | |
| case CAPTAIN: { | |
| $next = $std?($score / $ranks[MAJOR]) * PERCENT : | |
| ((($score - $ranks[CAPTAIN]) / ($ranks[MAJOR] - $ranks[CAPTAIN])) * PERCENT); | |
| }break; | |
| case MAJOR: { | |
| $next = $std?($score / $ranks[LIEUTENANT_COLONEL]) * PERCENT : | |
| ((($score - $ranks[MAJOR]) / ($ranks[LIEUTENANT_COLONEL] - $ranks[MAJOR])) * PERCENT); | |
| }break; | |
| case LIEUTENANT_COLONEL: { | |
| $next = $std?($score / $ranks[COLONEL]) * PERCENT : | |
| ((($score - $ranks[LIEUTENANT_COLONEL]) / ($ranks[COLONEL] - $ranks[LIEUTENANT_COLONEL])) * PERCENT); | |
| }break; | |
| case COLONEL: { | |
| $next = $std?($score / $ranks[BRIGADIER_GENERAL]) * PERCENT : | |
| ((($score - $ranks[COLONEL]) / ($ranks[BRIGADIER_GENERAL] - $ranks[COLONEL])) * PERCENT); | |
| }break; | |
| case BRIGADIER_GENERAL: { | |
| $next = $std?($score / $ranks[LIEUTENANT_GENERAL]) * PERCENT : | |
| ((($score - $ranks[BRIGADIER_GENERAL]) / ($ranks[LIEUTENANT_GENERAL] - $ranks[BRIGADIER_GENERAL])) * PERCENT); | |
| }break; | |
| case MAJOR_GENERAL: { | |
| $next = $std?($score / $ranks[LIEUTENANT_GENERAL]) * PERCENT : | |
| ((($score - $ranks[MAJOR_GENERAL]) / ($ranks[LIEUTENANT_GENERAL] - $ranks[MAJOR_GENERAL])) * PERCENT); | |
| }break; | |
| case LIEUTENANT_GENERAL: { | |
| $next = $std?($score / $ranks[GENERAL]) * PERCENT : | |
| ((($score - $ranks[LIEUTENANT_GENERAL]) / ($ranks[GENERAL] - $ranks[LIEUTENANT_GENERAL])) * PERCENT); | |
| }break; | |
| case GENERAL: { | |
| $next = 100; | |
| }break; | |
| default: | |
| $next = -1; | |
| break; | |
| } | |
| if($next > 100) $next = 100; | |
| $img_path = "./rank_".$rank_val.".jpg"; | |
| $img = imagecreatefromjpeg($img_path); | |
| imagealphablending($img, true); | |
| $width = (($next / 100) * 76); | |
| $border = imagecolorallocatealpha($img, 255, 255, 255, 45); | |
| $color = imagecolorallocatealpha($img, 1, 1, 1, 50); | |
| if($do_text || $do_score) { | |
| $txt_shadow = imagecolorallocatealpha($img, 0, 0, 0, 25); | |
| $txt_color = imagecolorallocatealpha($img, 255, 255, 255, 25); | |
| // if the no_text option hasnt been selected, draw the text | |
| if($do_text && $std) { | |
| imagettftext($img, 8.25, 0, 4, 57, $txt_shadow, | |
| "./ARIALBD.TTF", "Next"); | |
| imagettftext($img, 8.25, 0, 3, 56, $txt_color, | |
| "./ARIALBD.TTF", "Next"); | |
| imagettftext($img, 8.25, 0, 4, 68, $txt_shadow, | |
| "./ARIALBD.TTF", "Rank: ".round($next, 1)."%"); | |
| imagettftext($img, 8.25, 0, 3, 67, $txt_color, | |
| "./ARIALBD.TTF", "Rank: ".round($next, 1)."%"); | |
| } | |
| // if the no_text option hasnt been selected, draw the text | |
| if($do_text && !$std) { | |
| imagettftext($img, 8.25, 0, 4, 57, $txt_shadow, | |
| "./ARIALBD.TTF", "Rank"); | |
| imagettftext($img, 8.25, 0, 3, 56, $txt_color, | |
| "./ARIALBD.TTF", "Rank"); | |
| imagettftext($img, 8.25, 0, 4, 68, $txt_shadow, | |
| "./ARIALBD.TTF", "Delta: ".round($next, 1)."%"); | |
| imagettftext($img, 8.25, 0, 3, 67, $txt_color, | |
| "./ARIALBD.TTF", "Delta: ".round($next, 1)."%"); | |
| } | |
| // if score option is present, add the score to the avatar | |
| if($do_score) { | |
| $txt_color_s = imagecolorallocatealpha($img, 255, 255, 255, 30); | |
| imagettftext($img, 8, 0, 4, 12, $txt_shadow, "./ARIALBD.TTF", | |
| "Score ".number_format($score)); | |
| imagettftext($img, 8, 0, 3, 11, $txt_color_s, "./ARIALBD.TTF", | |
| "Score ".number_format($score)); | |
| } | |
| } | |
| $light_background = imagecolorallocatealpha($img, 255, 255, 255, 105); | |
| imagefilledrectangle($img, 2, 69, 77, 77, $light_background); | |
| imagerectangle($img, 1, 70, 78, 78, $border); | |
| imagefilledrectangle($img, 3, 72, $width, 76, $color); | |
| header("Content-type: image/jpeg"); | |
| imagejpeg($img); | |
| imagedestroy($img); | |
| $req->Close(); | |
| function get_pid($player_nick) { | |
| $search_request = new http_class(); | |
| $search_request->timeout = 0; | |
| $search_request->data_timeout = 0; | |
| $search_request->user_agent="GameSpyHTTP/1.0"; | |
| $url = "http://BF2Web.gamespy.com/ASP/searchforplayers.aspx?where=x&nick=".$player_nick; | |
| $args = null; | |
| $error = $search_request->GetRequestArguments($url, $args); | |
| if($error != "") { | |
| $search_request->cl(); | |
| return -1; | |
| } | |
| $error = $search_request->Open($args); | |
| flush(); | |
| if($error != "") { | |
| $search_request->cl(); | |
| return -1; | |
| } | |
| $search_request->SendRequest($args); | |
| flush(); | |
| $headers = array(); | |
| $search_request->ReadReplyHeaders($headers); | |
| if($search_request->response_status != "200") { | |
| $search_request->cl(); | |
| return -1; | |
| } | |
| if($search_request->content_length_set && $search_request->content_length <= 0) { | |
| $search_request->cl(); | |
| return -1; | |
| } | |
| // read the reply and parse the unlocks info out | |
| $score = 0; | |
| $rank_val = 0; | |
| $next = 0.0; | |
| do { | |
| $error=$search_request->ReadReplyBody($body, 4096); | |
| $lines = split("\n", $body); | |
| $get_data = false; | |
| for($i = 0; $i < count($lines); $i++) { | |
| $line = $lines[$i]; | |
| $pieces = split("\t", $line); | |
| for($j = 0; $j < count($pieces); $j++) { | |
| $part = $pieces[$j]; | |
| if($part == "H") { | |
| if($pieces[$j+2] == "pid") { | |
| $get_data = true; | |
| break; | |
| }else { | |
| $get_data = false; | |
| } | |
| } | |
| if($part == "D" && $get_data) { | |
| $search_request->Close(); | |
| return $pieces[$j+2]; | |
| }else if(part == "$" && $get_data) { | |
| $search_request->Close(); | |
| return -1; | |
| } | |
| } | |
| } | |
| }while($error == "" && strlen($body) != 0); | |
| $search_request->Close(); | |
| return -1; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment