<?php
$lgsl_random
= 0;
$lgsl_cachetime
= 1;
$lgsl_hostnamelength
= 20;
$lgsl_hide_offline
= 1;
$lgsl_hide_empty
= 0;
$lgsl_hide_full
= 0;
$lgsl_hostname_to_ip
= 0;
$lgsl_path
=
"lgsl/"
;
require_once
(
$lgsl_path
.
"lgsl_protocol.php"
);
if
(!
is_writable
(
$lgsl_path
.
"lgsl_module_cache.dat"
)) {
echo
"THE FILE LGSL_MODULE_CACHE.DAT IS NOT WRITABLE"
;
exit
; }
$lines
= file(
$lgsl_path
.
"lgsl_module_cache.dat"
);
$last_line
=
count
(
$lines
) - 1;
$last_update
=
intval
(
$lines
[
$last_line
]);
$time_check
= time() - (
$lgsl_cachetime
* 60);
if
(
$time_check
<
$last_update
)
{
unset(
$lines
[
$last_line
]);
unset(
$data_cache
);
foreach
(
$lines
as
$line_number
=>
$line
)
{
$data_cache
[
$line_number
] = unserialize(
$line
);
}
}
else
{
if
(
$lgsl_random
> 0)
{
unset(
$data_cache
);
unset(
$data_counter
);
unset(
$random_file
);
$lines
= file(
$lgsl_path
.
"lgsl_servers.txt"
);
$data_counter
= 0;
unset(
$data_cache
);
unset(
$random_file
);
foreach
(
$lines
as
$line
)
{
if
(!trim(
$line
)) {
continue
; }
$data_counter
+= 1;
$data_cache
[
$data_counter
] =
$line
;
}
if
(
$lgsl_random
>
count
(
$data_cache
))
{
$lgsl_random
=
count
(
$data_cache
);
}
while
(
count
(
$random_file
) <
$lgsl_random
)
{
$random
= rand(1,
count
(
$data_cache
));
if
(!
$random_file
[
$random
])
{
$part
=
explode
(
":"
,
$data_cache
[
$random
]);
$random_file
[
$random
] = trim(
$part
[0]).
":"
.trim(
$part
[1]).
":"
.trim(
$part
[2]).
":on"
;
}
}
}
ignore_user_abort(true);
if
(
$lgsl_random
> 0)
{
$lines
=
$random_file
;
}
else
{
$lines
= file(
$lgsl_path
.
"lgsl_servers.txt"
);
}
$data_counter
= 0;
unset(
$data_cache
);
foreach
(
$lines
as
$line
)
{
if
(!trim(
$line
)) {
continue
; }
$part
=
explode
(
":"
,
$line
);
$server_ip
= trim(
$part
[0]);
$server_port
= trim(
$part
[1]);
$server_type
= trim(
$part
[2]);
$server_module
= trim(
$part
[3]);
if
(
$server_module
!=
"on"
) {
continue
; }
$data
= lgsl_query(
$server_ip
,
$server_port
,
$server_type
,
"info"
);
$data
[mapname] = preg_replace(
"/[^A-Za-z0-9 \_\-]/"
,
"_"
,
strtolower
(
$data
[mapname]));
$data
[gamemod] = preg_replace(
"/[^A-Za-z0-9 \_\-]/"
,
"_"
,
strtolower
(
$data
[gamemod]));
$data_counter
+= 1;
$data_cache
[
$data_counter
] =
$data
;
}
$fh
=
fopen
(
$lgsl_path
.
"lgsl_module_cache.dat"
,
"w"
);
foreach
(
$data_cache
as
$line
)
{
$line
= serialize(
$line
).
"\r\n"
;
fwrite(
$fh
,
$line
);
}
fwrite(
$fh
, time());
fclose(
$fh
);
ignore_user_abort(false);
}
if
(
count
(
$data_cache
) == 0) {
echo
"no servers with :on set"
;
exit
; }
foreach
(
$data_cache
as
$data
)
{
if
(
$lgsl_hide_offline
&& !
$data
[status]) {
continue
; }
if
(
$lgsl_hide_empty
&&
$data
[status] &&
$data
[players] == 0) {
continue
; }
if
(
$lgsl_hide_full
&&
$data
[status] &&
$data
[players] ==
$data
[maxplayers]) {
continue
; }
if
(!
$data
[status])
{
$lgsl_image_map
=
$lgsl_path
.
"images/status/noresponse.jpg"
;
$data
[hostname] =
"Unknown"
;
$data
[mapname] =
"unknown"
;
}
else
{
$lgsl_image_map
=
$lgsl_path
.
"images/maps/$data[gametype]/$data[gamemod]/$data[mapname].jpg"
;
if
(!
file_exists
(
$lgsl_image_map
))
{
$lgsl_image_map
=
$lgsl_path
.
"images/status/noimage.jpg"
;
}
}
$lgsl_image_map
=
str_replace
(
" "
,
"%20"
,
$lgsl_image_map
);
if
(!
$data
[password])
{
$lgsl_image_pass
=
$lgsl_path
.
"images/status/nopassword.gif"
;
}
else
{
$lgsl_image_pass
=
$lgsl_path
.
"images/status/password.gif"
;
}
if
(
strlen
(
$data
[hostname]) >
$lgsl_hostnamelength
)
{
$data
[hostname] =
substr
(
$data
[hostname], 0,
$lgsl_hostnamelength
- 3) .
"..."
;
}
$data
[hostname] = htmlentities(
$data
[hostname], ENT_QUOTES);
if
(
$lgsl_hostname_to_ip
) {
$data
[ip] =
gethostbyname
(
$data
[ip]); }
$lgsl_launch
= lgsl_get(
"launch"
,
$data
[ip],
$data
[port],
$data
[gametype]);
echo
"
<div style=
'width:160px; text-align:center; border:none; font-size:11px; font-family:verdana;'
>
<table width=
'160'
border=
'0'
style=
'font-size:11px; font-family:verdana;'
><tr><td align=
'center'
valign=
'middle'
><img src=
'lgsl/images/icons/$data[gametype]/$data[gamemod].gif'
alt=
''
title=
'$data[gametype] - $data[gamemod]'
/></td><td>
<a style=
'text-decoration:none'
href=
'?lgsl_settings&ip=$data[ip]&port=$data[port]'
title=
'CLICK TO VIEW SERVER SETTINGS'
>
$data
[hostname]</a><br />
<a style=
'text-decoration:none'
href=
'$lgsl_launch'
title=
'CLICK TO VIEW IN THE A.S.E.'
>
$data
[ip]:
$data
[port]</a></td>
</tr></table>
<div style=
'border:none; background-image:url($lgsl_image_map); background-repeat:no-repeat; background-position:center'
>
<img src=
'$lgsl_image_pass'
alt=
''
title=
'$data[gametype] - $data[gamemod]'
/>
</div>
$data
[mapname]<br />
<a style=
'text-decoration:none'
href=
'?lgsl_players&ip=$data[ip]&port=$data[port]'
title=
'CLICK TO VIEW PLAYER INFO'
>PLAYERS:
$data
[players]/
$data
[maxplayers]</a><br />
<br />
</div>
";
}
?>