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

/tux-target/www/stats.php

http://tux-target.googlecode.com/
PHP | 406 lines | 332 code | 60 blank | 14 comment | 61 complexity | f8593d48afc64936fd3c7431fa509dcd MD5 | raw file
Possible License(s): GPL-2.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  6. <title>mtp-target</title>
  7. <link rel="stylesheet" type="text/css" href="http://www.mtp-target.org/mtptarget.css">
  8. </head>
  9. <body>
  10. <?php
  11. function generateHtml($server)
  12. {
  13. if (!function_exists('fprintf')) {
  14. if (function_exists('vsprintf')) { // >= 4.1.0
  15. function fprintf() {
  16. $args = func_get_args();
  17. $fp = array_shift($args);
  18. $format = array_shift($args);
  19. return fwrite($fp, vsprintf($format, $args));
  20. }
  21. } else { // < 4.1.0
  22. function fprintf() {
  23. $args = func_get_args();
  24. $fp = array_shift($args);
  25. $format = array_shift($args);
  26. $code = '';
  27. for ($i = 0; $i < count($args); ++$i) {
  28. if ($code) {
  29. $code .= ',';
  30. }
  31. $code .= '$args[' . $i . ']';
  32. }
  33. $code = 'return sprintf($format, ' . $code . ');';
  34. $rv = eval($code);
  35. return $rv ? fwrite($fp, $rv) : false;
  36. }
  37. }
  38. }
  39. $html_fp = fopen("stats_$server.html", "wt");
  40. if($server == "easy")
  41. {
  42. $filename = "/home/ace/cvs/mtp-target/server/connection.stat";
  43. $servername = "easy";
  44. }
  45. else if($server == "adv")
  46. {
  47. $filename = "/home/ace/cvs/mtp-target/adv_server/connection.stat";
  48. $servername = "advanced";
  49. }
  50. else
  51. {
  52. die("ERROR: Unknown server $server");
  53. }
  54. $fp = fopen($filename, "r");
  55. if (!$fp) {echo "<p>Unable to open remote file.</p>"; exit;}
  56. $userCountPerHourTotal;
  57. $userCountPerHourToday;
  58. $userCountPerHourTodayMax;
  59. $userCountPerMinuteTodayMax;
  60. $lastHour = 0;
  61. $lastDay = 0;
  62. $lastMinute = 0;
  63. $once = 0;
  64. $firstDate = mktime();
  65. $lastRestartTime = mktime();
  66. for($i=0;$i<24;$i++)
  67. {
  68. $userCountPerHourTotal[$i]=0;
  69. $userCountPerHourToday[$i]=0;
  70. $userCountPerHourTodayMax[$i]=0;
  71. }
  72. $userCountPerMinuteTodayMax = array_fill(0,60,-1);
  73. $playerCount = 0;
  74. while (!feof($fp)):
  75. $line = fgets($fp, 2048);
  76. $out = array(substr($line,0,strlen($line)-1));//remove \n
  77. list ($ttime, $syear, $smonth, $sday, $shour, $smin, $ssec, $inout, $sname)= split (" ", $out[0]);
  78. $name = str_replace("'","",$sname);
  79. //fprintf($html_fp,"[%s] -> [%s]<br>",$sname,$name);
  80. $hour = intval($shour);
  81. $minute = intval($smin);
  82. $sec = intval($ssec);
  83. $day = intval($sday);
  84. $month = intval($smonth);
  85. $year = intval($syear);
  86. if(strlen($line)!=0 && $ttime!="c")
  87. {
  88. if($lastHour!=$hour)
  89. {
  90. //fprintf($html_fp,"%dh0 = %d<br>",$lastHour,$userCountPerHourTotal[$lastHour]);
  91. $lastHour=$hour;
  92. $userCountPerMinuteTodayMax = array_fill(0,60,-1);
  93. $userCountPerMinuteTodayMax[0]=$playerCount;
  94. /*
  95. for($i=0;$i<60;$i++)
  96. {
  97. fprintf($html_fp,"%d<br>",$userCountPerMinuteTodayMax[$i]);
  98. }
  99. fprintf($html_fp,"<hr>");
  100. */
  101. }
  102. if($lastDay!=$day)
  103. {
  104. $lastDay=$day;
  105. for($i=0;$i<24;$i++)
  106. {
  107. $userCountPerHourToday[$i]=0;
  108. $userCountPerHourTodayMax[$i]=0;
  109. }
  110. //fprintf($html_fp,"<hr>");
  111. }
  112. if($inout=='+')
  113. {
  114. $lastMinute = $minute;
  115. $playerCount++;
  116. $userCountPerHourTotal[$hour]++;
  117. $userCountPerHourToday[$hour]++;
  118. if($playerCount>$userCountPerHourTodayMax[$hour])
  119. $userCountPerHourTodayMax[$hour] = $playerCount;
  120. if($playerCount>$userCountPerMinuteTodayMax[$minute])
  121. $userCountPerMinuteTodayMax[$minute] = $playerCount;
  122. //fprintf($html_fp,"%d:%d [%s] comes(%d,%d,%d) in<br>",$hour,$minute,$name,$playerCount,$userCountPerHourToday[$hour],$userCountPerMinuteTodayMax[$minute]);
  123. }
  124. else if($inout=='#')
  125. {
  126. $lastRestartTime = mktime($hour,$minute,$sec,$month,$day,$year);
  127. if($once==0)
  128. {
  129. $firstDate = $lastRestartTime;
  130. $once = 0;
  131. }
  132. $playerCount = 0;
  133. //fprintf($html_fp,"<hr>",$name);
  134. }
  135. else if($inout=='?')
  136. {
  137. if(strlen($name)>0)
  138. $playerCount++;
  139. //fprintf($html_fp,"invalid login(%d) %s(%d)<br>",$playerCount,$name,strlen($name));
  140. }
  141. else if($inout=='-')
  142. {
  143. if(strlen($name)>0)
  144. $playerCount--;
  145. //fprintf($html_fp,"[%s](%d) leaves(%d)<br>",$name,strlen($name),$playerCount);
  146. }
  147. }
  148. $fp++;
  149. endwhile;
  150. fclose($fp);
  151. $t1 = strtotime(date("Y-m-d H:i:s"));
  152. $t2 = strtotime(date("Y-m-d H:i:s",$lastRestartTime));
  153. $t3 = $t1-$t2;
  154. $upSec = $t3%60;
  155. $upMin = ($t3/60)%60;
  156. $upHour = (($t3/60)/60)%24;
  157. $upDay = ((($t3/60)/60)/24)%100;
  158. fprintf($html_fp,"Server : %s<br>\n",$servername);
  159. fprintf($html_fp,"Stats generated : %s<br>\n",date("l dS of F Y H:i:s"));
  160. if($upDay == 1)
  161. fprintf($html_fp,"Server uptime : %d day %02d:%02d:%02d <br>",$upDay,$upHour,$upMin,$upSec);
  162. else if($upDay > 1)
  163. fprintf($html_fp,"Server uptime : %d days %02d:%02d:%02d <br>",$upDay,$upHour,$upMin,$upSec);
  164. else
  165. fprintf($html_fp,"Server uptime : %02d:%02d:%02d <br>",$upHour,$upMin,$upSec);
  166. fprintf($html_fp,"Current logged user : %d<br>\n",$playerCount);
  167. fprintf($html_fp,"Last restart : %s<br>\n",date("l dS of F Y H:i:s",$lastRestartTime));
  168. fprintf($html_fp,"<br>\n");
  169. fprintf($html_fp,"<br>\n");
  170. fprintf($html_fp,"<b>Total</b> login :<br>\n");
  171. fprintf($html_fp,"Since %s\n",date("l dS of F Y h:i:s A",$firstDate));
  172. fprintf($html_fp,"<table bgcolor=\"#FFFAEA\">\n");
  173. fprintf($html_fp,"<tr valign=\"bottom\">\n");
  174. $maxTotal = 0;
  175. for($i=0;$i<24;$i++)
  176. {
  177. if($userCountPerHourTotal[$i]>$maxTotal)
  178. $maxTotal = $userCountPerHourTotal[$i];
  179. }
  180. for($i=0;$i<24;$i++)
  181. {
  182. //fprintf($html_fp,"=>%dh0 : %d<br>",$i,$userCountPerHourTotal[$i]);
  183. fprintf($html_fp,"<td valign=\"bottom\">\n");
  184. if($maxTotal!=0)
  185. fprintf($html_fp,"\t<img align=\"bottom\" src=\"./img/vp.png\" height=\"%d\" width=\"6\" alt='total login : %d' title='total login : %d' />\n",$userCountPerHourTotal[$i]*100/$maxTotal,$userCountPerHourTotal[$i],$userCountPerHourTotal[$i]);
  186. fprintf($html_fp,"</td>\n");
  187. }
  188. fprintf($html_fp,"</tr>\n");
  189. fprintf($html_fp,"<tr>\n");
  190. for($i=0;$i<24;$i++)
  191. {
  192. fprintf($html_fp,"<td width=20>%d</td>\n",$userCountPerHourTotal[$i]);
  193. }
  194. fprintf($html_fp,"</tr>\n");
  195. fprintf($html_fp,"<tr>\n");
  196. for($i=0;$i<24;$i++)
  197. {
  198. fprintf($html_fp,"<td><img src=\"./img/hr%d.png\" width=\"10\"/></td>\n",($i%12)+1);
  199. }
  200. fprintf($html_fp,"</tr>\n");
  201. fprintf($html_fp,"<tr>\n");
  202. for($i=0;$i<24;$i++)
  203. {
  204. fprintf($html_fp,"<td>%d</td>\n",$i);
  205. }
  206. fprintf($html_fp,"</tr>\n");
  207. fprintf($html_fp,"</table>\n");
  208. fprintf($html_fp,"<br>\n");
  209. fprintf($html_fp,"<br>\n");
  210. fprintf($html_fp,"Today login :\n");
  211. fprintf($html_fp,"<table bgcolor=\"#FFFAEA\">\n");
  212. fprintf($html_fp,"<tr valign=\"bottom\">\n");
  213. $maxToday = 0;
  214. for($i=0;$i<24;$i++)
  215. {
  216. if($userCountPerHourToday[$i]>$maxToday)
  217. $maxToday = $userCountPerHourToday[$i];
  218. }
  219. for($i=0;$i<24;$i++)
  220. {
  221. fprintf($html_fp,"<td valign=\"bottom\">\n");
  222. if($maxToday!=0)
  223. fprintf($html_fp,"\t<img align=\"bottom\" src=\"./img/vh.png\" height=\"%d\" width=\"6\" alt='today login : %d' title='today login : %d' />\n",$userCountPerHourToday[$i]*100/$maxToday,$userCountPerHourToday[$i],$userCountPerHourToday[$i]);
  224. fprintf($html_fp,"</td>\n");
  225. }
  226. fprintf($html_fp,"</tr>\n");
  227. fprintf($html_fp,"<tr>\n");
  228. for($i=0;$i<24;$i++)
  229. {
  230. fprintf($html_fp,"<td width=20>%d</td>\n",$userCountPerHourToday[$i]);
  231. }
  232. fprintf($html_fp,"</tr>\n");
  233. fprintf($html_fp,"<tr>\n");
  234. for($i=0;$i<24;$i++)
  235. {
  236. fprintf($html_fp,"<td><img src=\"./img/hr%d.png\" width=\"10\"/></td>\n",($i%12)+1);
  237. }
  238. fprintf($html_fp,"</tr>\n");
  239. fprintf($html_fp,"<tr>\n");
  240. for($i=0;$i<24;$i++)
  241. {
  242. fprintf($html_fp,"<td>%d</td>\n",$i);
  243. }
  244. fprintf($html_fp,"</tr>\n");
  245. fprintf($html_fp,"</table>\n");
  246. fprintf($html_fp,"<br>\n");
  247. fprintf($html_fp,"<br>\n");
  248. fprintf($html_fp,"Today Max simultaneous user :\n");
  249. fprintf($html_fp,"<table bgcolor=\"#FFFAEA\">\n");
  250. fprintf($html_fp,"<tr valign=\"bottom\">\n");
  251. $maxTodayMax = 0;
  252. for($i=0;$i<24;$i++)
  253. {
  254. if($userCountPerHourTodayMax[$i]>$maxTodayMax)
  255. $maxTodayMax = $userCountPerHourTodayMax[$i];
  256. }
  257. for($i=0;$i<24;$i++)
  258. {
  259. fprintf($html_fp,"<td valign=\"bottom\">\n");
  260. if($maxTodayMax!=0)
  261. fprintf($html_fp,"\t<img align=\"bottom\" src=\"./img/vh.png\" height=\"%d\" width=\"6\" alt='today simultaneous user : %d' title='today simultaneous user : %d' />\n",$userCountPerHourTodayMax[$i]*100/$maxTodayMax,$userCountPerHourTodayMax[$i],$userCountPerHourTodayMax[$i]);
  262. fprintf($html_fp,"</td>\n");
  263. }
  264. fprintf($html_fp,"</tr>\n");
  265. fprintf($html_fp,"<tr>\n");
  266. for($i=0;$i<24;$i++)
  267. {
  268. fprintf($html_fp,"<td width=20>%d</td>\n",$userCountPerHourTodayMax[$i]);
  269. }
  270. fprintf($html_fp,"</tr>\n");
  271. fprintf($html_fp,"<tr>\n");
  272. for($i=0;$i<24;$i++)
  273. {
  274. fprintf($html_fp,"<td><img src=\"./img/hr%d.png\" width=\"10\"/></td>\n",($i%12)+1);
  275. }
  276. fprintf($html_fp,"</tr>\n");
  277. fprintf($html_fp,"<tr>\n");
  278. for($i=0;$i<24;$i++)
  279. {
  280. fprintf($html_fp,"<td>%d</td>\n",$i);
  281. }
  282. fprintf($html_fp,"</tr>\n");
  283. fprintf($html_fp,"</table>\n");
  284. fprintf($html_fp,"<br>\n");
  285. fprintf($html_fp,"<br>\n");
  286. fprintf($html_fp,"Last hour max simultaneous user :\n");
  287. fprintf($html_fp,"<table bgcolor=\"#FFFAEA\">\n");
  288. fprintf($html_fp,"<tr valign=\"bottom\">\n");
  289. $maxHourMax = 0;
  290. for($i=0;$i<60 && $i<$lastMinute;$i++)
  291. {
  292. if($userCountPerMinuteTodayMax[$i]==-1 && $i>0 && $i<$lastMinute)
  293. $userCountPerMinuteTodayMax[$i]=$userCountPerMinuteTodayMax[$i-1];
  294. if($userCountPerMinuteTodayMax[$i]>$maxHourMax)
  295. $maxHourMax = $userCountPerMinuteTodayMax[$i];
  296. }
  297. for($i=0;$i<60;$i++)
  298. {
  299. fprintf($html_fp,"<td valign=\"bottom\">\n");
  300. if($maxHourMax!=0)
  301. fprintf($html_fp,"\t<img align=\"bottom\" src=\"./img/vp.png\" height=\"%d\" width=\"6\" alt='today simultaneous user : %d' title='today simultaneous user : %d' />\n",$userCountPerMinuteTodayMax[$i]*100/$maxHourMax,$userCountPerMinuteTodayMax[$i],$userCountPerMinuteTodayMax[$i]);
  302. fprintf($html_fp,"</td>\n");
  303. }
  304. fprintf($html_fp,"</tr>\n");
  305. fprintf($html_fp,"<tr>\n");
  306. for($i=0;$i<60 && $i<=$lastMinute;$i++)
  307. {
  308. fprintf($html_fp,"<td>%d</td>\n",$userCountPerMinuteTodayMax[$i]);
  309. }
  310. fprintf($html_fp,"</tr>\n");
  311. fprintf($html_fp,"<tr>\n");
  312. for($i=0;$i<60 && $i<=$lastMinute;$i++)
  313. {
  314. fprintf($html_fp,"<td>%02d</td>\n",$i);
  315. }
  316. fprintf($html_fp,"</tr>\n");
  317. /*
  318. fprintf($html_fp,"<tr>\n");
  319. for($i=0;$i<24;$i++)
  320. {
  321. fprintf($html_fp,"<td><img src=\"./img/hr%d.png\" width=\"10\"/></td>\n",($i%12)+1);
  322. }
  323. fprintf($html_fp,"</tr>\n");
  324. */
  325. fprintf($html_fp,"</table>\n");
  326. fclose($html_fp);
  327. }
  328. if(!isset($server)) $server = "easy";
  329. //$lastModeTime = strtotime(date("Y-m-d H:i:s")) - filemtime("stats_$server.html");
  330. //printf("%d<br>",$lastModeTime);
  331. if (!file_exists("stats_$server.html") || (strtotime(date("Y-m-d H:i:s")) - filemtime("stats_$server.html"))>60*5)
  332. generateHtml($server);
  333. $html_fp = fopen("stats_$server.html", "rt");
  334. while (!feof($html_fp)):
  335. $line = fgets($html_fp, 2048);
  336. echo $line;
  337. $html_fp++;
  338. endwhile;
  339. fclose($html_fp);
  340. ?>
  341. </body>
  342. </html>