ipcs.php
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
<?php
/*
* ----[ Info ]----
* Clase IP-CS v2.0 by DarkSoldier ( darksoldi@gmail.com )
* Te da la información básica de algun servidor del counter-strike dada una IP y puerto.
*
* ----[ Mod ]----
* No modifiqueis nada a no ser que sepais lo que haceis
* La función muestra es la encargada de mostrar todo los datos, podeis modificarla a vuestro gusto
*
* ----[ Spam ]----
* #php_para_torpes @ irc-hispano.org || www.php-hispano.org
* #AiM.es @ irc.quakenet.org
*
* ----[ IMPORTANTE ]----
* NO la pongais en vuestra web sin mi aviso y menos quitando el autor (usea, yo :P)
*
*/
class ipcs {
function ipcs($ip, $puerto, $dir = 'mapas/') {
if(!ctype_digit($puerto) || empty($puerto)) {
trigger_error('El puerto esta vacio o no es numérico', E_USER_WARNING);
return false;
}
if(ip2long($ip) == -1 || ip2long($ip) == false) {
trigger_error('La ip no es correcta', E_USER_WARNING);
return false;
}
$cs = fsockopen('udp://'.$ip, $puerto, &$ErrNo, &$ErrStr, 2);
if(!$cs) {
trigger_error($ErrStr, E_USER_WARNING);
return false;
}
fwrite($cs,'˙˙˙˙infostring');
$data=fread($cs, 337);
fclose($cs);
$data=explode('\\',$data);
$info = array();
$info['server'] = $data[20];
$info['ip'] = $data[4];
$info['juego'] = $data[18];
$info['players'] = $data[6];
$info['players_max'] = $data[12];
$info['mapa'] = $data[22];
$info['pass'] = ($data[26] == 0) ? 'No' : 'Si';
$this->info = $info;
$this->imagen = $dir.$info['mapa'].'.jpg';
}
function get_map($mapa) {
$imagens = file_exists($mapa)? $mapa : 'no_disponible.jpg';
$def = '<img style="width: 100px; height: 80px; border: 3px double Gray;" src="'.$imagens.'" alt="'.$imagens.'" />';
return($def);
}
function muestra() {
if(empty($this->info['server'])) {
trigger_error('No se ha podido conectar a la IP', E_USER_WARNING);
return false;
}
echo $this->get_map($this->imagen).'<br />';
echo '<strong>Nombre del server:</strong> '.$this->info['server'] . '<br />';
echo '<strong>Ip:</strong> '.$this->info['ip']. '<br />';
echo '<strong>Juego:</strong> '.$this->info['juego']. '<br />';
echo '<strong>Players:</strong> '.$this->info['players'].'/'.$this->info['players_max']. '<br />';
echo '<strong>Mapa:</strong> '.$this->info['mapa']. '<br />';
echo '<strong>Password:</strong> '.$this->info['pass']. '<br />';
}
}
// Ejemplo de uso
$ipcs = New ipcs('217.75.230.91', 27025);
$ipcs->muestra();
?>