1
Perl / Perl и оперативка
« : 08 Сентября 2003, 00:02:15 »
Вообщем тут дело такое... на web сервере стоит статистика для игры Counter-Strike. Есть мониторинг сервера КС, который отображает кто сейчас играет на сервере, количество игроков, текущю карту т.д. Скрипт написан на perl и в своей работе подгружает exe файл (QSTAT.org), который в свою очередь берет инфу с сервера кс. Perl скрипт в свою очередь является темплэйтом для вывода результатов. Через пару десяткой рефрешей все виснет!
Вот скрипт:
#!/usr/local/bin/perl
#print STDERR "hello\\n";
print "Content-type: text/html\\n\\n";
print <<EOF;
<html>
<head>
<title>Nautilus Net CS Stats - Мониторинг</title>
<meta HTTP-EQUIV="Refresh" content=20>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<style>
.plrheader {
background-color:
filter:
}
.plrmiddle {
background-color:
filter:
}
.plrrow {
background-color:
filter:
}
.toprow {
background-color:
filter:
}
.bottomrow {
background-color:
filter:
}
.stat_highlight {
background-color:
}
.table1 {
background-repeat:
background-position:
}
.plrheaderrow {
background-color:
}
.plrheaderfont {
color:
}
.tablecell2 {
background-color: black;
filter: alpha(opacity=80);
}
</style>
</head>
EOF
open(QSTAT, "E:/Users/AHTOHuO/Local/Stats/cgi-bin/qstat -P -sort T -tsw -nh -f server.lst |");
$count=0;
while(<QSTAT>) {
}
}
print \'</tr></table></td></tr><tr align="center" valign="bottom">\'."\\n";
print <<EOF;
</table>
</body>
</html>
EOF
Вот скрипт:
#!/usr/local/bin/perl
#print STDERR "hello\\n";
print "Content-type: text/html\\n\\n";
print <<EOF;
<html>
<head>
<title>Nautilus Net CS Stats - Мониторинг</title>
<meta HTTP-EQUIV="Refresh" content=20>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<style>
.plrheader {
background-color:
#142234;
filter:
alpha(opacity=80);
}
.plrmiddle {
background-color:
#142234;
filter:
alpha(opacity=00);
}
.plrrow {
background-color:
#142234;
filter:
alpha(opacity=70);
}
.toprow {
background-color:
#142234;
filter:
alpha(opacity=60);
}
.bottomrow {
background-color:
#142234;
filter:
alpha(opacity=60);
}
.stat_highlight {
background-color:
#142234;
}
.table1 {
background-repeat:
no-repeat;
background-position:
center;
}
.plrheaderrow {
background-color:
"black";
}
.plrheaderfont {
color:
"white";
}
.tablecell2 {
background-color: black;
filter: alpha(opacity=80);
}
</style>
</head>
EOF
open(QSTAT, "E:/Users/AHTOHuO/Local/Stats/cgi-bin/qstat -P -sort T -tsw -nh -f server.lst |");
$count=0;
while(<QSTAT>) {
chop;
if ($count == 0) {
($server, $players, $map, @servername) = (split(/[\\s]+/))[0, 1, 2, 7..20];
if (/DOWN/) {
$servername = "Сервер выключен!";
$countplayers = 0;
$maxplayers = 0;
$map = "Нет карты.";
} else {
$servername = join(\' \', @servername);
$servername =~ s/\\s+$//g;
($countplayers, $maxplayers) = (split(/[\\/]/, $players));
}
print \' <body background="../images/stat/\'.$map.\'.jpg" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>\'."\\n";
print \'<table width="300" height="225" border="0" cellpadding="0" cellspacing="0" align="left">\'."\\n";
print \'<tr align="left" height="99%" valign="center" align="center">\'."\\n";
print \'<td valign="top" style="background-image: none;">\'."\\n";
print \'<table width="100%" border="0" cellpadding="0" cellspacing="0">\'."\\n";
print \'<tr><td class="toprow" align="center"><font style="font-family: Arial; font-size: 15px; font-weight: bold; color: white;">Карта: \'.$map.\'</font></td></tr>\'."\\n";
print \'</table>\'."\\n";
print \'<center>\'."\\n";
print \'<table width="295" border="0" cellpadding="0" cellspacing="0">\'."\\n";
print \'<tr><td colspan="4" width="295"><font style="font-size: 6px;"> </font></td></tr><tr>\'."\\n";
print \'<td class="plrheader" style="background-image: none;" align="left" width="127">\'."\\n";
print \'<font style="font-family: Arial; font-size: 10px; color: white;"> Ник</font></td>\'."\\n";
print \'<td class="plrheader" style="background-image: none;" align="right" width="62">\'."\\n";
print \'<font style="font-family: Arial; font-size: 10px; color: white;">Фраги </font></td>\'."\\n";
print \'<td class="plrheader" style="background-image: none;" align="right" width="65">\'."\\n";
print \'<font style="font-family: Arial; font-size: 10px; color: white;"> Время</font></td></tr>\'."\\n";
$maxplayers = 20 if ($maxplayers == 0);
} else {
s/^\\s+//g;
($frags, $times, @username) = (split(/[\\s]+/))[0, 2, 3..10];
$username = join(\' \', @username);
$username =~ s/\\s+$//g;
print \' <tr>\'."\\n";
print \'<td class="plrrow" style="background-image: none;" align="left" width="127"><font style="font-family: Arial; font-size: 10px; color: white;"> \'.$username.\'</font></td>\'."\\n";
print \'<td class="plrrow" style="background-image: none;" align="right" width="62"><font style="font-family: Arial; font-size: 10px; color: white;">\'.$frags.\'</font></td>\'."\\n";
print \'<td class="plrrow" style="background-image: none;" align="right" width="65"><font style="font-family: Arial; font-size: 10px; color: white;"> \'.$times.\'</font></td>\'."\\n";
}
$count++;
}
print \'</tr></table></td></tr><tr align="center" valign="bottom">\'."\\n";
print \' <td class="bottomrow" style="background-image: none;"><font style="font-family: Arial; font-size: 12px; color: white;">Игроков на сервере: \'.$countplayers.\'/\'.$maxplayers.\'</font></td></tr>\'."\\n";
print <<EOF;
</table>
</body>
</html>
EOF