1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
284.
285.
286.
287.
288.
289.
290.
291.
292.
293.
294.
295.
296.
297.
298.
299.
300.
301.
302.
303.
304.
305.
306.
307.
308.
309.
310.
311.
312.
313.
314.
315.
316.
317.
318.
319.
320.
321.
322.
323.
324.
325.
326.
327.
328.
329.
330.
331.
332.
333.
334.
335.
336.
337.
338.
339.
340.
341.
342.
343.
344.
345.
346.
347.
348.
349.
350.
351.
352.
353.
354.
355.
356.
357.
358.
359.
360.
361.
362.
363.
364.
365.
366.
367.
368.
369.
370.
371.
372.
373.
374.
375.
376.
377.
378.
379.
380.
381.
382.
383.
384.
385.
386.
387.
388.
389.
390.
391.
392.
393.
394.
395.
396.
397.
398.
399.
400.
401.
402.
403.
404.
405.
406.
407.
408.
409.
410.
411.
412.
413.
414.
415.
416.
417.
418.
419.
420.
421.
422.
423.
424.
425.
426.
427.
428.
429.
430.
431.
432.
433.
434.
435.
436.
437.
438.
439.
440.
441.
442.
443.
444.
445.
446.
447.
448.
449.
450.
451.
452.
453.
454.
455.
456.
457.
458.
459.
460.
461.
462.
463.
464.
465.
466.
467.
468.
469.
470.
471.
472.
473.
474.
475.
476.
477.
478.
479.
480.
481.
482.
483.
484.
485.
486.
487.
488.
489.
490.
491.
492.
493.
494.
495.
496.
497.
498.
499.
500.
501.
502.
503.
504.
505.
506.
507.
508.
509.
510.
511.
512.
513.
514.
515.
516.
517.
518.
519.
520.
521.
522.
523.
524.
525.
526.
527.
528.
529.
530.
531.
532.
533.
534.
535.
536.
537.
538.
539.
540.
541.
542.
543.
544.
| 1. / 2. / ...
class bf2
{
var $host = false;
var $port = false;
var $socket = false;
var $write = "xFExFDx00x10x20x30x40xFFxFFxFFx01";
var $s_info = false;
var $g_info = false;
var $response = false;
function getvalue($srv_value, $srv_data)
{
// search the value of selected rule and return it
$srv_value = array_search ($srv_value, $srv_data);
if ($srv_value === false)
{
return false;
}
else
{
$srv_value = $srv_data[$srv_value+1];
return $srv_value;
}
}
function splitdata()
{
$g_end = strpos($this->s_info, 'player_');
$g_info = substr($this->s_info, 0, $g_end);
$this->g_info = explode("x00", $g_info);
// now get the player data
$p_end = strlen($this->s_info);
$p_info = substr($this->s_info, $g_end, $p_end);
$this->p_info = $p_info;
}
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function connect()
{
if (($this->socket = fsockopen('udp://'. $this->host, $this->port, $errno, $errstr, 30)))
{
return true;
}
return false;
}
function disconnect()
{
if (fclose($this->socket))
{
return true;
}
return false;
}
function get_split($info)
{
$end = strpos($info, "num") +3;
$split = substr($info, $end+1, 2);
$number = ord($split);
return $number;
}
function rm_split($info)
{
$info = substr($info, 15);
return $info;
}
function rm_end($info)
{
$reverse = '';
$cache = '';
$cache = substr($info, 0, -1);
$end = strlen($cache);
while ($end != -1)
{
if ($end--)
{
$reverse .= $cache[$end];
}
}
$cut = substr($reverse, strpos($reverse, "x00"));
$end = strlen($cut);
$info = '';
while ($end != -1)
{
if ($end--)
{
$info .= $cut[$end];
}
}
return $info;
}
function get_status()
{
$timeout = false;
$ready = false;
$data[0] = false;
$data[1] = false;
$data[2] = false;
$packets[0] = false;
$packets[1] = false;
$packets[128] = false;
$packets[129] = false;
$packets[130] = false;
if ($this->connect() === false)
{
return false;
}
socket_set_timeout($this->socket, 1);
$time_begin = $this->microtime_float();
fwrite($this->socket, $this->write);
while ($ready == false && $timeout == false)
{
$info = fread($this->socket, 1);
$status = socket_get_status($this->socket);
$length = $status['unread_bytes'];
$time_end = $this->microtime_float();
$this->response = $time_end - $time_begin;
if ($length > 0)
{
$info = fread($this->socket, $length);
}
// first of more packets (1/n)
if ($this->get_split($info) == 0)
{
$info = $this->rm_split($info);
$data[0] = $this->rm_end($info);
$packets[0] = true;
if ($packets[129] == true)
{
$ready = true;
}
elseif ($packets[1] == true && $packets[130] == true)
{
$ready = true;
}
else
{
$ready = false;
}
}
// second packet of three (2/3)
elseif ($this->get_split($info) == 1)
{
$info = $this->rm_split($info);
$info = substr($info, strpos($info, "x00")+1);
$data[1] = $this->rm_end($info);
$packets[1] = true;
if ($packets[0] == true && $packets[130] == true)
{
$ready = true;
}
else
{
$ready = false;
}
}
// only this one packet (1/1)
elseif ($this->get_split($info) == 128)
{
$info = $this->rm_split($info);
$data[0] = $info;
$ready = true;
}
// second packet of two (2/2)
elseif ($this->get_split($info) == 129)
{
$info = $this->rm_split($info);
$info = substr($info, strpos($info, "x00")+1);
$data[1] = $info;
$packets[129] = true;
if ($packets[0] == true)
{
$ready = true;
}
else
{
$ready = false;
}
}
// third packet of three (3/3)
elseif ($this->get_split($info) == 130)
{
$info = $this->rm_split($info);
$info = substr($info, strpos($info, "x00")+1);
$data[2] = $info;
$packets[130] = true;
if ($packets[0] == true && $packets[1] == true)
{
$ready = true;
}
else
{
$ready = false;
}
}
if ($status['timed_out'] == true)
{
$timeout = true;
}
}
$info = $data[0] . $data[1] . $data[2];
if (empty($info) || $info > 100)
{
return false;
}
// response time
$this->response = ($this->response * 1000);
$this->response = (int)$this->response;
if ($this->disconnect() === false)
{
return false;
}
return $info;
}
function getstream($host, $port, $queryport)
{
if (empty($queryport))
{
$this->port = $port + 13333;
}
else
{
$this->port = $queryport;
}
$this->host = $host;
// get the infostream from server
$this->s_info = $this->get_status();
if ($this->s_info)
{
$this->splitdata();
return true;
}
else
{
return false;
}
}
function check_color($text)
{
$clr = array ( // colors
""#000000"", ""#DA0120"", ""#00B906"", ""#E8FF19"", // 1
""#170BDB"", ""#23C2C6"", ""#E201DB"", ""#FFFFFF"", // 2
""#CA7C27"", ""#757575"", ""#EB9F53"", ""#106F59"", // 3
""#5A134F"", ""#035AFF"", ""#681EA7"", ""#5097C1"", // 4
""#BEDAC4"", ""#024D2C"", ""#7D081B"", ""#90243E"", // 5
""#743313"", ""#A7905E"", ""#555C26"", ""#AEAC97"", // 6
""#C0BF7F"", ""#000000"", ""#DA0120"", ""#00B906"", // 7
""#E8FF19"", ""#170BDB"", ""#23C2C6"", ""#E201DB"", // 8
""#FFFFFF"", ""#CA7C27"", ""#757575"", ""#CC8034"", // 9
""#DBDF70"", ""#BBBBBB"", ""#747228"", ""#993400"", // 10
""#670504"", ""#623307"" // 11
);
// colored numbers
if ($text <= 39)
{
$ctext = "<font color=$clr[7]>$text</font>";
}
elseif ($text <= 69)
{
$ctext = "<font color=$clr[5]>$text</font>";
}
elseif ($text <= 129)
{
$ctext = "<font color=$clr[8]>$text</font>";
}
elseif ($text <= 399)
{
$ctext = "<font color=$clr[9]>$text</font>";
}
else
{
$ctext = "<font color=$clr[1]>$text</font>";
}
return $ctext;
}
function getrules($phgdir)
{
$srv_rules['sets'] = false;
// response time
$srv_rules['response'] = $this->response . ' ms';
// bfv setting pics
$sets['pb'] = '<img src="' . $phgdir . 'privileges/pb.gif" alt="pb">';
$sets['pass'] = '<img src="' . $phgdir . 'privileges/pass.gif" alt="pw">';
// get the info strings from server info stream
$srv_rules['hostname'] = $this->getvalue('hostname', $this->g_info);
$srv_rules['gametype'] = $this->getvalue('gametype', $this->g_info);
$srv_rules['gamename'] = $this->getvalue('gamename', $this->g_info);
$srv_rules['version'] = $this->getvalue('gamever', $this->g_info);
$srv_rules['mapname'] = $this->getvalue('mapname', $this->g_info);
$srv_rules['maxplayers'] = $this->getvalue('maxplayers', $this->g_info);
$srv_rules['anticheat'] = $this->getvalue('bf2_anticheat', $this->g_info);
$srv_rules['needpass'] = $this->getvalue('password', $this->g_info);
// path to map picture and default info picture
$srv_rules['map_path'] = 'maps/bf2';
$srv_rules['map_default'] = 'default.jpg';
// get the connected player
$srv_rules['nowplayers'] = $this->getvalue('numplayers', $this->g_info);
// complete the gamename
$srv_rules['gamename'] = 'Battlefield 2<br>(' . $srv_rules['version'] .')';
// server privileges
if ($srv_rules['needpass'] == 1)
{
$srv_rules['sets'] .= $sets['pass'];
}
if ($srv_rules['anticheat'] == 1)
{
$srv_rules['sets'] .= $sets['pb'];
}
if ($srv_rules['sets'] === false)
{
$srv_rules['sets'] = '-';
}
// General server Info
global $cs_lang;
$srv_rules['htmlinfo'] = cs_html_roco(1,'rightb',0,0,'50%') . $cs_lang['map:'];
$srv_rules['htmlinfo'] .= cs_html_roco(2,'leftb') . $srv_rules['mapname'] . cs_html_roco(0);
$srv_rules['htmlinfo'] .= cs_html_roco(1,'rightb') . $cs_lang['players'];
$srv_rules['htmlinfo'] .= cs_html_roco(2,'leftb') . $srv_rules['nowplayers'] . ' / ' . $srv_rules['maxplayers'] . cs_html_roco(0);
$srv_rules['htmlinfo'] .= cs_html_roco(1,'rightb') . $cs_lang['response'];
$srv_rules['htmlinfo'] .= cs_html_roco(2,'leftb') . $srv_rules['response'] . cs_html_roco(0);
$srv_rules['htmlinfo'] .= cs_html_roco(1,'rightb') . $cs_lang['privileges'];
$srv_rules['htmlinfo'] .= cs_html_roco(2,'leftb') . $srv_rules['sets'] . cs_html_roco(0);
// server detail info
$srv_rules['htmldetail'] = cs_html_roco(1,'leftb') . $cs_lang['game'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['gamename'] . cs_html_roco(0);
$srv_rules['htmldetail'] .= cs_html_roco(1,'leftb') . $cs_lang['gamemod'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['gametype'] . cs_html_roco(0);
$srv_rules['htmldetail'] .= cs_html_roco(1,'leftb') . $cs_lang['map:'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['mapname'] . cs_html_roco(0);
$srv_rules['htmldetail'] .= cs_html_roco(1,'leftb') . $cs_lang['players'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['nowplayers'] . ' / ' . $srv_rules['maxplayers'] . cs_html_roco(0);
$srv_rules['htmldetail'] .= cs_html_roco(1,'leftb') . $cs_lang['response'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['response'] . cs_html_roco(0);
$srv_rules['htmldetail'] .= cs_html_roco(1,'leftb') . $cs_lang['privileges'];
$srv_rules['htmldetail'] .= cs_html_roco(2,'leftb') . $srv_rules['sets'] . cs_html_roco(0);
// return all server rules
return $srv_rules;
}
function getplayers()
{
$players = array();
$clients = 0;
// set html thead for playerlist without teams
global $cs_lang;
$thead = cs_html_roco(1,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['rank'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(2,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['name'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(3,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['score'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(4,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['team'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(5,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['skill'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(6,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['death'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(7,'headb');
$thead .= cs_html_div(1,'text-align:center');
$thead .= $cs_lang['ping'];
$thead .= cs_html_div(0);
$thead .= cs_html_roco(0);
// how many players must search
$nowplayers = $this->getvalue('numplayers', $this->g_info);
if ($nowplayers == 0)
{
$thead .= cs_html_roco(1,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(2,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(3,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(4,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(5,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(6,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0);
$thead .= cs_html_roco(7,'leftb') . cs_html_div(1,'text-align:center') . '--' . cs_html_div(0) . cs_html_roco(0);
}
else
{
$nowplayers = $nowplayers - 1;
// sort the data to can scan it better
$cache = explode ("x00x00", $this->p_info);
$c_pl = explode("x00", $cache[1]);
$c_score = explode("x00", $cache[3]);
$c_ping = explode("x00", $cache[5]);
$c_team = explode("x00", $cache[7]);
$c_deaths = explode("x00", $cache[9]);
$c_pid = explode("x00", $cache[11]);
$c_skill = explode("x00", $cache[13]);
// get the data of each player and add the team status
while ($nowplayers != -1)
{
$pl = $c_pl[$nowplayers];
$pl_score = $c_score[$nowplayers];
$pl_ping = $c_ping[$nowplayers];
$pl_team = $c_team[$nowplayers];
$pl_deaths = $c_deaths[$nowplayers];
$pl_pid = $c_pid[$nowplayers];
$pl_skill = $c_skill[$nowplayers];
// no player data
if ($pl == '')
{
$pl = '-';
$pl_score = '-';
$pl_ping = '-';
$pl_team = '-';
$pl_deaths = '-';
$pl_pid = '-';
$pl_skill = '-';
}
else
{
$players[$clients] =
$pl_score . ' ' .
$pl_team . ' ' .
$pl_deaths . ' ' .
$pl_skill . ' ' .
$pl_ping . ' ' .
""$pl"";
}
$nowplayers--;
$clients++;
}
sort($players, SORT_NUMERIC);
}
// store the html table line to the info array
$srv_player = $thead;
// manage the player data in the following code
$index = 1;
while ($clients != 0)
{
$clients--;
list ($cache[$index], $player[$index]) = split ('"', $players[$clients]);
list ($score[$index],
$team[$index],
$deaths[$index],
$skill[$index],
$ping[$index]) = split (' ', $cache[$index]);
$player[$index] = htmlentities($player[$index]);
$ping[$index] = $this->check_color($ping[$index]);
$tdata = cs_html_roco(1,'leftb') . cs_html_div(1,'text-align:center') . $index . cs_html_div(0);
$tdata .= cs_html_roco(2,'leftb') . cs_html_div(1,'text-align:center') . $player[$index] . cs_html_div(0);
$tdata .= cs_html_roco(3,'leftb') . cs_html_div(1,'text-align:center') . $score[$index] . cs_html_div(0);
$tdata .= cs_html_roco(4,'leftb') . cs_html_div(1,'text-align:center') . $team[$index] . cs_html_div(0);
$tdata .= cs_html_roco(5,'leftb') . cs_html_div(1,'text-align:center') . $skill[$index] . cs_html_div(0);
$tdata .= cs_html_roco(6,'leftb') . cs_html_div(1,'text-align:center') . $deaths[$index] . cs_html_div(0);
$tdata .= cs_html_roco(7,'leftb') . cs_html_div(1,'text-align:center') . $ping[$index] . cs_html_div(0) . cs_html_roco(0);
$srv_player = $srv_player . $tdata;
$index++;
}
return $srv_player;
}
} |