PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/web/sig.php

https://bitbucket.org/psychonic/hlstatsxce
PHP | 468 lines | 360 code | 55 blank | 53 comment | 69 complexity | 6aaee1405b23f3a660508a8558f8f865 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. HLstatsX Community Edition - Real-time player and clan rankings and statistics
  4. Copyleft (L) 2008-20XX Nicholas Hastings (nshastings@gmail.com)
  5. http://www.hlxcommunity.com
  6. HLstatsX Community Edition is a continuation of
  7. ELstatsNEO - Real-time player and clan rankings and statistics
  8. Copyleft (L) 2008-20XX Malte Bayer (steam@neo-soft.org)
  9. http://ovrsized.neo-soft.org/
  10. ELstatsNEO is an very improved & enhanced - so called Ultra-Humongus Edition of HLstatsX
  11. HLstatsX - Real-time player and clan rankings and statistics for Half-Life 2
  12. http://www.hlstatsx.com/
  13. Copyright (C) 2005-2007 Tobias Oetzel (Tobi@hlstatsx.com)
  14. HLstatsX is an enhanced version of HLstats made by Simon Garner
  15. HLstats - Real-time player and clan rankings and statistics for Half-Life
  16. http://sourceforge.net/projects/hlstats/
  17. Copyright (C) 2001 Simon Garner
  18. This program is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU General Public License
  20. as published by the Free Software Foundation; either version 2
  21. of the License, or (at your option) any later version.
  22. This program is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. GNU General Public License for more details.
  26. You should have received a copy of the GNU General Public License
  27. along with this program; if not, write to the Free Software
  28. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  29. For support and installation notes visit http://www.hlxcommunity.com
  30. Originally idea for sig.php by Tankster
  31. */
  32. foreach ($_SERVER as $key => $entry) {
  33. if ($key !== 'HTTP_COOKIE') {
  34. $search_pattern = array('/<script>/', '/<\/script>/', '/[^A-Za-z0-9.\-\/=:;_?#&~]/');
  35. $replace_pattern = array('', '', '');
  36. $entry = preg_replace($search_pattern, $replace_pattern, $entry);
  37. if ($key == 'PHP_SELF') {
  38. if ((strrchr($entry, '/') !== '/hlstats.php') &&
  39. (strrchr($entry, '/') !== '/ingame.php') &&
  40. (strrchr($entry, '/') !== '/show_graph.php') &&
  41. (strrchr($entry, '/') !== '/sig.php') &&
  42. (strrchr($entry, '/') !== '/sig2.php') &&
  43. (strrchr($entry, '/') !== '/index.php') &&
  44. (strrchr($entry, '/') !== '/status.php') &&
  45. (strrchr($entry, '/') !== '/top10.php') &&
  46. (strrchr($entry, '/') !== '/config.php') &&
  47. (strrchr($entry, '/') !== '/') &&
  48. ($entry !== '')) {
  49. header('Location: http://'.$_SERVER['HTTP_HOST'].'/hlstats.php');
  50. exit;
  51. }
  52. }
  53. $_SERVER[$key] = $entry;
  54. }
  55. }
  56. define('IN_HLSTATS', true);
  57. header("Content-Type: image/png");
  58. // Load database classes
  59. require ('config.php');
  60. require (INCLUDE_PATH . '/class_db.php');
  61. require (INCLUDE_PATH . '/functions.php');
  62. $db_classname = 'DB_' . DB_TYPE;
  63. if (class_exists($db_classname))
  64. {
  65. $db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
  66. }
  67. else
  68. {
  69. error('Database class does not exist. Please check your config.php file for DB_TYPE');
  70. }
  71. $g_options = getOptions();
  72. @error_reporting(E_ALL ^ E_NOTICE);
  73. function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){
  74. $opacity=$pct;
  75. // getting the watermark width
  76. $w = imagesx($src_im);
  77. // getting the watermark height
  78. $h = imagesy($src_im);
  79. // creating a cut resource
  80. $cut = imagecreatetruecolor($src_w, $src_h);
  81. // copying that section of the background to the cut
  82. imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
  83. // inverting the opacity
  84. $opacity = 100 - $opacity;
  85. // placing the watermark now
  86. imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
  87. imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity);
  88. }
  89. function f_num($number) {
  90. if (($number >= 10) &&($number < 20))
  91. return $number.'th';
  92. else {
  93. switch ($number % 10) {
  94. case 1:
  95. return $number.'st';
  96. break;
  97. case 2:
  98. return $number.'nd';
  99. break;
  100. case 3:
  101. return $number.'rd';
  102. break;
  103. default:
  104. return $number.'th';
  105. break;
  106. }
  107. }
  108. }
  109. if (!isset($g_options['scripturl']))
  110. $g_options['scripturl'] = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
  111. $player_id = 0;
  112. if (isset($_GET['player_id'])) {
  113. $player_id = valid_request($_GET['player_id'], 1);
  114. } elseif (isset($_GET['steam_id']) && isset($_GET['game'])) {
  115. $steam_id = valid_request($_GET['steam_id'], 0);
  116. $steam_id = preg_replace('/^STEAM_\d+?\:/i','',$steam_id);
  117. $game = valid_request($_GET['game'], 0);
  118. $steam_id_escaped=$db->escape($steam_id);
  119. $game_escaped=$db->escape($game);
  120. // Obtain realgame from hlstats_Games
  121. $db->query("
  122. SELECT
  123. realgame
  124. FROM
  125. hlstats_Games
  126. WHERE
  127. code = '$game_escaped'
  128. ");
  129. $realgame = $db->fetch_row();
  130. // Obtain player_id from the steam_id and game code
  131. $db->query("
  132. SELECT
  133. playerId
  134. FROM
  135. hlstats_PlayerUniqueIds
  136. WHERE
  137. uniqueId = '{$steam_id_escaped}' AND
  138. game = '{$game_escaped}'
  139. ");
  140. if ($db->num_rows() != 1)
  141. error("No such player '$player'.");
  142. list($player_id) = $db->fetch_row();
  143. }
  144. $show_flags = $g_options['countrydata'];
  145. if ((isset($_GET['show_flags'])) && (is_numeric($_GET['show_flags'])))
  146. $show_flags = valid_request($_GET['show_flags'], 1);
  147. if (file_exists(IMAGE_PATH.'/progress/sig_'.$player_id.'.png')) {
  148. $file_timestamp = @filemtime(IMAGE_PATH.'/progress/sig_'.$player_id.'.png');
  149. if ($file_timestamp + IMAGE_UPDATE_INTERVAL > time()) {
  150. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
  151. $browser_timestamp = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
  152. if ($browser_timestamp + IMAGE_UPDATE_INTERVAL > time()) {
  153. header('HTTP/1.0 304 Not Modified');
  154. exit;
  155. }
  156. }
  157. $mod_date = date('D, d M Y H:i:s \G\M\T', $file_timestamp);
  158. header('Last-Modified:'.$mod_date);
  159. exit;
  160. }
  161. }
  162. ////
  163. //// Main
  164. ////
  165. if ((isset($_GET['color'])) && (is_string($_GET['color'])))
  166. $color = hex2rgb(valid_request($_GET['color'], 0));
  167. if ((isset($_GET['caption_color'])) && (is_string($_GET['caption_color'])))
  168. $caption_color = hex2rgb(valid_request($_GET['caption_color'], 0));
  169. if ((isset($_GET['link_color'])) && (is_string($_GET['link_color'])))
  170. $link_color = hex2rgb(valid_request($_GET['link_color'], 0));
  171. if ($player_id > 0) {
  172. $db->query("
  173. SELECT
  174. playerId,
  175. game,
  176. FROM_UNIXTIME((last_event), '%a %D %b %k:%H') as lastevent,
  177. connection_time,
  178. last_skill_change,
  179. unhex(replace(hex(lastName), 'E280AE', '')) as lastName,
  180. country,
  181. flag,
  182. kills,
  183. deaths,
  184. suicides,
  185. skill,
  186. shots,
  187. hits,
  188. headshots, IFNULL(ROUND(headshots/kills * 100), '-') AS hpk,
  189. IFNULL(kills/deaths, '-') AS kpd,
  190. IFNULL(ROUND((hits / shots * 100), 1), 0.0) AS acc,
  191. activity,
  192. hideranking
  193. FROM
  194. hlstats_Players
  195. WHERE
  196. playerId='$player_id'
  197. ");
  198. if ($db->num_rows() != 1)
  199. error("No such player '$player'.");
  200. $playerdata = $db->fetch_array();
  201. $db->free_result();
  202. $pl_name = $playerdata['lastName'];
  203. if(function_exists('imagettftext')) {
  204. if (strlen($pl_name) > 30) {
  205. $pl_name = substr($pl_name, 0, 27) . '...';
  206. }
  207. } else {
  208. if (strlen($pl_name) > 30) {
  209. $pl_shortname = substr($pl_name, 0, 27) . '...';
  210. } else {
  211. $pl_shortname = $pl_name;
  212. $pl_name = htmlspecialchars($pl_name, ENT_COMPAT);
  213. $pl_shortname = htmlspecialchars($pl_shortname, ENT_COMPAT);
  214. $pl_urlname = urlencode($playerdata['lastName']);
  215. }
  216. }
  217. $db->query("
  218. SELECT
  219. COUNT(*) as count
  220. FROM
  221. hlstats_Players
  222. WHERE
  223. game='".$playerdata['game']."'");
  224. $pl_count = $db->fetch_array();
  225. $db->free_result();
  226. if (($playerdata['activity'] > 0) && ($playerdata['hideranking'] == 0)) {
  227. $rank = get_player_rank($playerdata);
  228. } else {
  229. if ($playerdata['hideranking'] == 1)
  230. $rank = 'Hidden';
  231. elseif ($playerdata['hideranking'] == 2)
  232. $rank = 'Banned';
  233. else
  234. $rank = 'Not active';
  235. }
  236. if ($playerdata['activity'] == -1)
  237. $playerdata['activity'] = 0;
  238. $skill_change = '0';
  239. if ($playerdata['last_skill_change'] > 0)
  240. $skill_change = $playerdata['last_skill_change'];
  241. else if ($playerdata['last_skill_change'] < 0)
  242. $skill_change = $playerdata['last_skill_change'];
  243. $background='random';
  244. if ((isset($_GET['background'])) && ( (($_GET['background'] > 0) && ($_GET['background'] < 12)) || ($_GET['background']=='random')) )
  245. $background = valid_request($_GET['background'], 0);
  246. if ($background == 'random')
  247. $background = rand(1,11);
  248. $hlx_sig_image = getImage('/games/'.$playerdata['game'].'/sig/'.$background);
  249. if ($hlx_sig_image)
  250. {
  251. $hlx_sig = $hlx_sig_image['path'];
  252. }
  253. elseif ($hlx_sig_image = getImage('/games/'.$realgame.'/sig/'.$background))
  254. {
  255. $hlx_sig = $hlx_sig_image['path'];
  256. }
  257. else
  258. {
  259. $hlx_sig = IMAGE_PATH."/sig/$background.png";
  260. }
  261. switch ($background) {
  262. case 1: $caption_color = array('red' => 0, 'green' => 0, 'blue' => 255);
  263. $link_color = array('red' => 0, 'green' => 0, 'blue' => 255);
  264. $color = array('red' => 0, 'green' => 0, 'blue' => 0);
  265. break;
  266. case 2: $caption_color = array('red' => 147, 'green' => 23, 'blue' => 18);
  267. $link_color = array('red' => 147, 'green' => 23, 'blue' => 18);
  268. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  269. break;
  270. case 3: $caption_color = array('red' => 150, 'green' => 180, 'blue' => 99);
  271. $link_color = array('red' => 150, 'green' => 180, 'blue' => 99);
  272. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  273. break;
  274. case 4: $caption_color = array('red' => 255, 'green' => 203, 'blue' => 4);
  275. $link_color = array('red' => 255, 'green' => 203, 'blue' => 4);
  276. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  277. break;
  278. case 5: $caption_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  279. $link_color = array('red' => 0, 'green' => 102, 'blue' => 204);
  280. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  281. break;
  282. case 6: $caption_color = array('red' => 0, 'green' => 0, 'blue' => 0);
  283. $link_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  284. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  285. break;
  286. case 7: $caption_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  287. $link_color = array('red' => 100, 'green' => 100, 'blue' => 100);
  288. $color = array('red' => 0, 'green' => 0, 'blue' => 0);
  289. break;
  290. case 8: $caption_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  291. $link_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  292. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  293. break;
  294. case 9: $caption_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  295. $link_color = array('red' => 0, 'green' => 0, 'blue' => 0);
  296. $color = array('red' => 0, 'green' => 0, 'blue' => 0);
  297. break;
  298. case 10: $caption_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  299. $link_color = array('red' => 255, 'green' => 255, 'blue' => 255);
  300. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  301. break;
  302. case 11: $caption_color = array('red' => 150, 'green' => 180, 'blue' => 99);
  303. $link_color = array('red' => 150, 'green' => 180, 'blue' => 99);
  304. $color = array('red' => 255, 'green' => 255, 'blue' => 255);
  305. break;
  306. default: $caption_color = array('red' => 0, 'green' => 0, 'blue' => 255);
  307. $link_color = array('red' => 0, 'green' => 155, 'blue' => 0);
  308. $color = array('red' => 0, 'green' => 0, 'blue' => 0);
  309. break;
  310. }
  311. $image = imagecreatetruecolor(400, 75);
  312. imagealphablending($image, false);
  313. imagesavealpha($image, true);
  314. $white = imagecolorallocate($image, 255, 255, 255);
  315. $bgray = imagecolorallocate($image, 192, 192, 192);
  316. $yellow = imagecolorallocate($image, 255, 255, 0);
  317. $black = imagecolorallocate($image, 0, 0, 0);
  318. $red = imagecolorallocate($image, 255, 0, 0);
  319. $green = imagecolorallocate($image, 0, 155, 0);
  320. $blue = imagecolorallocate($image, 0, 0, 255);
  321. $grey_shade = imagecolorallocate($image, 204, 204, 204);
  322. $font_color = imagecolorallocate($image, $color['red'], $color['green'], $color['blue']);
  323. $caption_color = imagecolorallocate($image, $caption_color['red'], $caption_color['green'], $caption_color['blue']);
  324. $link_color = imagecolorallocate($image, $link_color['red'], $link_color['green'], $link_color['blue']);
  325. //$font_colorb = imagecolorallocate($image, $colorb['red'], $colorb['green'], $colorb['blue']);
  326. //$caption_colorb = imagecolorallocate($image, $caption_colorb['red'], $caption_colorb['green'], $caption_colorb['blue']);
  327. //$link_colorb = imagecolorallocate($image, $link_colorb['red'], $link_colorb['green'], $link_colorb['blue']);
  328. $background_img = imagecreatefrompng($hlx_sig);
  329. if ($background_img) {
  330. imagecopy($image, $background_img, 0, 0, 0, 0, 400, 75);
  331. imagedestroy($background_img);
  332. }
  333. if ($background == 0)
  334. imagerectangle($image, 0, 0, 400, 75, $bgray);
  335. $start_header_name = 9;
  336. if ($show_flags > 0) {
  337. $flag = imagecreatefromgif(getFlag($playerdata['flag'], 'path'));
  338. if ($flag) {
  339. imagecopy($image, $flag, 8, 4, 0, 0, 18, 12);
  340. $start_header_name += 22;
  341. imagedestroy($flag);
  342. }
  343. }
  344. imagealphablending($image, true);
  345. $timestamp = $playerdata['connection_time'];
  346. $days = floor($timestamp / 86400);
  347. $hours = $days * 24;
  348. $hours += floor($timestamp / 3600 % 24);
  349. if ($hours < 10)
  350. $hours = '0'.$hours;
  351. $min = floor($timestamp / 60 % 60);
  352. if ($min < 10)
  353. $min = '0'.$min;
  354. $sec = floor($timestamp % 60);
  355. if ($sec < 10)
  356. $sec = '0'.$sec;
  357. $con_time = $hours.':'.$min.':'.$sec;
  358. if ($playerdata['last_skill_change'] == '')
  359. $playerdata['last_skill_change'] = 0;
  360. if ($playerdata['last_skill_change'] == 0)
  361. $trend_image_name = IMAGE_PATH.'/t1.gif';
  362. elseif ($playerdata['last_skill_change'] > 0)
  363. $trend_image_name = IMAGE_PATH.'/t0.gif';
  364. elseif ($playerdata['last_skill_change'] < 0)
  365. $trend_image_name = IMAGE_PATH.'/t2.gif';
  366. $trend = imagecreatefromgif($trend_image_name);
  367. if(function_exists('imagettftext'))
  368. {
  369. $font = IMAGE_PATH.'/sig/font/DejaVuSans.ttf';
  370. imagettftext($image, 10, 0, 30, 15, $caption_color, $font, $pl_name);
  371. }
  372. else
  373. {
  374. imagestring($image, 9, $start_header_name, 2, $playerdata['lastName'], $caption_color);
  375. }
  376. imagestring($image, 2, 15, 22, 'Position ', $font_color);
  377. if (is_numeric($rank)) {
  378. imagestring($image, 3, 70, 22, number_format($rank), $font_color);
  379. $start_pos_x = 71 + (imagefontwidth(3) * strlen(number_format($rank))) + 7;
  380. } else {
  381. imagestring($image, 3, 70, 22, $rank, $font_color);
  382. $start_pos_x = 71 + (imagefontwidth(3) * strlen($rank)) + 7;
  383. }
  384. $ranktext = 'of '.$pl_count['count'].' players with '.$playerdata['skill'].' (';
  385. imagestring($image, 2, $start_pos_x, 22, $ranktext, $font_color);
  386. $start_pos_x += (imagefontwidth(2) * strlen($ranktext));
  387. if ($trend) {
  388. imagecopy($image, $trend, $start_pos_x, 26, 0, 0, 7, 7);
  389. $start_header_name += 22;
  390. imagedestroy($trend);
  391. $start_pos_x += 10;
  392. }
  393. imagestring($image, 2, $start_pos_x, 22, $skill_change.') points', $font_color);
  394. imagestring($image, 2, 15, 34, 'Frags: '.$playerdata['kills'].' kills : '.$playerdata['deaths'].' deaths ('.$playerdata['kpd'].'), '.$playerdata['headshots'].' headshots ('.$playerdata['hpk'].'%)', $font_color);
  395. imagestring($image, 2, 15, 45, 'Activity: '.$playerdata['lastevent'].' ('.$playerdata['activity'].'%), Time: '.$con_time.' hours', $font_color);
  396. imagestring($image, 2, 15, 56, 'Statistics: ', $font_color);imagestring($image, 2, 85, 56, $g_options['siteurl'], $link_color);
  397. $watermark = imagecreatefrompng(IMAGE_PATH.'/watermark.png');
  398. imagecopymerge_alpha($image, $watermark, 334, 58, 0, 0, 60, 12, 50);
  399. $mod_date = date('D, d M Y H:i:s \G\M\T', time());
  400. Header('Last-Modified:'.$mod_date);
  401. imagepng($image);
  402. imagedestroy($image);
  403. imagedestroy($watermark);
  404. }
  405. ?>