Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Rekord użytkowników na serwerach.
Forum PHP.pl > Forum > Przedszkole
zagi195
Witam
Mam stronę na której można dodać serwery popularnej gry counter strike, strona pokazuje ile graczy jest aktualnie na wszystkich serwerach i co chwile aktualizuję te dane. Chcę zrobić taki napis: Rekordowa ilość graczy online: xxxx. tylko nie wiem jak to zrobić.
Podam tutaj kod tej podstrony.

  1. <?php
  2. $server = array();
  3. $main = array();
  4. $cache = array();
  5. include_once("config.php");
  6. ///////////////////////////////////////////////////////////////////////////////////////////////////
  7. if($main['debug'])
  8. else
  9. error_reporting(E_ALL & !E_NOTICE);
  10.  
  11. include_once("inc/functions.php");
  12. include_once("inc/class_PQ.php");
  13. if(!class_exists("XTemplate")) include_once("inc/xtemplate.php");
  14. ///////////////////////////////////////////////////////////////////////////////////////////////////
  15. // $id represents server id, depending on config.php, notice, id cannot be zero (it refers to all servers)
  16. if(isset($_GET['id'])) $id = (int) $_GET['id']; else $id = 0;
  17.  
  18. ////////////////////////////////////////////////////////////////////////////
  19. ////////////////////////////////////////////////////////////////////////////
  20. ////////////////////////////////////////////////////////////////////////////
  21. if($id) // show specific server
  22. {
  23. $id--;
  24. if(cache_read($cache,$main['cache'],$id) && ( (time() - $cache[$id]['hlss_update_time']) < $main['cache_outdate']))
  25. { //cache read ok and no need for update
  26. $pqinfo = $cache[$id];
  27. }
  28. else
  29. {
  30. $pq = PQ::create($server[$id]);
  31. $pqinfo = $pq->query(array('info','rules','players')); //this is the moment when we check server status
  32. $pqinfo['hlss_update_time'] = time();// mark the date when server was visited last time
  33. $pqinfo['update_time'] = date($main['dateformat'],$pqinfo['hlss_update_time']);
  34.  
  35. }
  36. if(!@$pqinfo['ping']) $pqinfo['timeout'] = 1 ; else $pqinfo['timeout'] = 0 ;
  37. $server[$id]['id'] = $id+1;
  38. $server[$id]["name"] = htmlspecialchars($server[$id]["name"],ENT_QUOTES);// replace strange chars with html equivalents
  39. $server[$id]["ha"] = htmlspecialchars($server[$id]["ha"],ENT_QUOTES);
  40. $server[$id]['skin'] = substr($server[$id]['template'],0,strrpos($server[$id]['template'],"."));
  41. if(!@$server[$id]["offline_img"]) $server[$id]["offline_img"] = $main['offline_img'];
  42. if(!@$server[$id]["online_img"]) $server[$id]["online_img"] = $main['online_img'];
  43. if(!@$server[$id]['nicklength']) $server[$id]['nicklength'] = $main['nicklength'];
  44. $server[$id]['online_percent'] = floor(100*@$pqinfo['totalplayers']/@$pqinfo['maxplayers']);
  45.  
  46. if(!isset($_GET['img']))
  47. {
  48. //default is template display mode, otherwise return image contents
  49. // image return mode works only for single server!!!
  50. load_template($tpl,$server[$id]['template']);
  51. $tpl->assign($server[$id]);
  52. $tpl->assign($pqinfo);
  53. }
  54.  
  55. if($pqinfo['timeout'])
  56. {
  57. if(isset($_GET['img']))
  58. {
  59. if(isset($_GET['plr']))
  60. {// if we got plr var then we want to return players number on server
  61. switch($_GET['plr'])
  62. {
  63. default:
  64. case "1": //image depend on player number
  65. if(!isset($server[$id]["online_img_plr_off"]))
  66. $server[$id]["online_img_plr_off"] = @$main["online_img_plr_off"];
  67. output_img($server[$id]["online_img_plr_off"]);
  68. break;
  69. case "2": //return image depend on percentage of server fill
  70. if(!isset($server[$id]["online_img_plr_off%"]))
  71. $server[$id]["online_img_plr_off%"] = @$main["online_img_plr_off%"];
  72. output_img($server[$id]["online_img_plr_off%"]);
  73. break;
  74. }
  75. }
  76. else
  77. {
  78. output_img($server[$id]["offline_img"]); //automaticaly invoked php exit on
  79. }
  80. }
  81. else
  82. {
  83. $tpl->parse("MAIN.TIMEOUT");
  84. }
  85. }
  86. else
  87. {
  88.  
  89. // fix images, transport from $main to $server[$id]
  90. for ($i=0;$i<=32;$i++) //server maxplayers is 32, we run from 0 slot server to 32 (yea, a bit ugly)
  91. {
  92. if(!isset($server[$id]["online_img_plr_".$i]))
  93. $server[$id]["online_img_plr_".$i] = @$main["online_img_plr_".$i];
  94. for ($j=0;$j<=$i;$j++)
  95. { if($i==0) break;//division by zero fix
  96. $plr = floor(100*$j/$i);
  97. if(!isset($server[$id]["online_img_plr_".$plr."%"]))
  98. $server[$id]["online_img_plr_".$plr."%"] = @$main["online_img_plr_".$plr."%"];
  99. }
  100. }
  101. $plr = "";
  102. if(isset($_GET['img']))
  103. {
  104. if(isset($_GET['plr']))
  105. {
  106. switch($_GET['plr'])
  107. {
  108. default:
  109. case "1": //image depend on player number
  110. $plr = $pqinfo['totalplayers'];
  111. output_img($server[$id]["online_img_plr_".$plr]);
  112. break;
  113. case "2": //return image depend on percentage of server fill, but
  114. $plr = floor(100*$pqinfo['totalplayers']/$pqinfo['maxplayers']);
  115. output_img($server[$id]["online_img_plr_".$plr."%"]);
  116. break;
  117. }
  118. }
  119. else
  120. {
  121. output_img($server[$id]["online_img"]);//automaticaly invoked php exit on
  122. }
  123. }
  124. else
  125. {
  126.  
  127. ////////////////////////////////////////////////////////////////////////////
  128. $jj=0;
  129.  
  130. ////////////////////////////////////////////////////////////////////////////
  131. }
  132. }
  133.  
  134. if($main['showall'])
  135. $tpl->assign(array("showall" => showall($tpl)));
  136. else
  137. $tpl->assign(array("showall" => ""));
  138.  
  139. $tpl->assign($main);
  140. $tpl->parse("MAIN");
  141. $tpl->out("MAIN");
  142. $cache[$id] = $pqinfo;
  143. }
  144. ////////////////////////////////////////////////////////////////////////////
  145. ////////////////////////////////////////////////////////////////////////////
  146. ////////////////////////////////////////////////////////////////////////////
  147. ////////////////////////////////////////////////////////////////////////////
  148. // show all servers
  149. else
  150. {
  151. load_template($tpl,$main['template']);
  152.  
  153. $totalPlayers = 0;
  154. $maxPlayers = 0;
  155.  
  156. foreach ($server as $skey =>$sval){
  157.  
  158. if($sval['disable']) continue;//server disabled, do not display it in list mode
  159. unset($pq,$pqinfo);// make sure we do not get wrong values from previous foreach() loop
  160.  
  161. if(cache_read($cache,$main['cache'],$skey) && ( (time() - $cache[$skey]['hlss_update_time']) < $main['cache_outdate']))
  162. { //cache read ok and no need for update
  163. $pqinfo = $cache[$skey];
  164. }
  165. else
  166. {
  167. $pq = PQ::create($server[$skey]);
  168. $pqinfo = $pq->query(array('info','rules','players')); //this is the moment when we check server status
  169. $pqinfo['hlss_update_time'] = time();// mark the date when server was visited last time
  170. $pqinfo['update_time'] = date($main['dateformat'],$pqinfo['hlss_update_time']);
  171. // notice that udate_time is set only everytime server query is performed, even if server is not responding
  172. }
  173.  
  174. if(!@$pqinfo['ping']) $pqinfo['timeout'] = 1 ; else $pqinfo['timeout'] = 0 ;
  175. $sval['id'] = $skey+1;
  176. $sval["name"] = htmlspecialchars($sval["name"],ENT_QUOTES);
  177. $sval["ha"] = htmlspecialchars($sval["ha"],ENT_QUOTES);
  178. $sval['skin'] = substr($main['template'],0,strrpos($main['template'],"."));
  179. if(!@$sval['nicklength']) $sval['nicklength'] = $main['nicklength'];
  180. $sval['online_percent'] = floor(100*@$pqinfo['totalplayers']/@$pqinfo['maxplayers']);
  181. $totalPlayers += $pqinfo['totalplayers'];
  182. $maxPlayers += $pqinfo['maxplayers'];
  183. $wolnych = ($maxPlayers - $totalPlayers);
  184.  
  185.  
  186. $tpl->assign($sval);
  187. $tpl->assign($pqinfo);
  188. if($pqinfo['timeout'])
  189. {
  190. $tpl->parse("MAIN.TIMEOUT");
  191. }
  192. else
  193. {
  194.  
  195. ////////////////////////////////////////////////////////////////////////////
  196. $jj=0;
  197. foreach($pqinfo['players'] as $plr)
  198. {
  199. unset($player);//make sure w will not get values from previous row
  200. $player['player_name'] = htmlspecialchars($plr['name'],ENT_QUOTES);
  201.  
  202. if(strlen($player['player_name'])>@$sval['nicklength'])
  203. $player['player_shortname'] = htmlspecialchars(substr($player['player_name'],0,$sval['nicklength']-3)."...",ENT_QUOTES);
  204.  
  205. $player['player_id'] = $plr['id'];
  206. $player['player_kills'] = $plr['kills'];
  207. $player['player_time'] = $plr['onlinetime']; //seconds
  208. $player['player_time_min'] = date("H:i:s",$plr['onlinetime']-3600); //seconds, need to fix it
  209. $player['j']=$jj;
  210. $player['i']=($jj++%2);
  211. $tpl->assign($player);
  212. $tpl->parse("MAIN.STATUS.PLAYERS.PLAYER");
  213. }
  214. $tpl->parse("MAIN.STATUS.PLAYERS");
  215.  
  216. $tpl->parse("MAIN.STATUS");
  217. ////////////////////////////////////////////////////////////////////////////
  218. }
  219. $cache[$skey] = $pqinfo;
  220. }
  221.  
  222. if($main['showall'])
  223. $tpl->assign(array("showall" => showall($tpl)));
  224. else
  225. $tpl->assign(array("showall" => ""));
  226.  
  227. $tpl->assign( 'graczy', $totalPlayers );
  228. $tpl->assign( 'wolnych', $wolnych );
  229.  
  230. $tpl->assign($main);
  231. $tpl->parse("MAIN");
  232. $tpl->out("MAIN");
  233. }
  234. ////////////////////////////////////////////////////////////////////////////
  235. ////////////////////////////////////////////////////////////////////////////
  236. cache_write($cache,$main['cache']);
  237.  
  238. //ob_flush();
  239. ?>


Damonsson
Pole w MySQL REKORDGRACZY
i w php dajesz przykładowo
jeżeli TOTALPLAYERS jest większe od REKORDGRACZY
to zmień wartość w polu REKORDGRACZY na TOTALPLAYERS

Bynajmniej ja bym to tak rozwiązał.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.