In norms place and other server sites, there is some scripting that tells who is playing, and the ladder, how do you do this?
Please help.

Code: Select all
<html>
<head>
<title></title>
</head>
<body>
<?php
// start configuration
$scriptdir = "/var/www/web1/html/cgi-bin"; //absolute location of overall.pl
$statsdir = "/server1/var"; // absolute location of highscores.txt, players.txt, etc.
$max_items = 101; // max_items = number of rows +1 defaults to the "top 100"
// end configuration
$list="";
$counter=0;
$fileonline = fopen($statsdir . "/players.txt", "r");
while(!feof($fileonline)) {
$counter++;
$online = fgets($fileonline, 4096);
$playername = substr($online, 0, 16);
if($counter != 1) {
if($playername > "") {
$list=$list."<li>".$playername."</li>\n";
}
}
}
fclose($fileonline);
if($counter > 2) {
echo "<ul>";
echo $list;
echo "</ul>";
}
else
{
echo "nobody online.";
}
?>
<table border=1>
<tr>
<td>no.</td>
<td><a href=<? $_SERVER["SCRIPT_NAME"] ?>"?orderby=name">name</a></td>
<td><a href=<? $_SERVER["SCRIPT_NAME"] ?>"?orderby=rating">rating</a></td>
<td><a href=<? $_SERVER["SCRIPT_NAME"] ?>"?orderby=matches">won matches</a></td>
<td><a href=<? $_SERVER["SCRIPT_NAME"] ?>"?orderby=rounds">won rounds</a></td>
<td><a href=<? $_SERVER["SCRIPT_NAME"] ?>"?orderby=score">single player highscore</a></td>
</tr>
<?php
if(isset($_GET['orderby'])){
$orderby = $_GET['orderby'];
} else {
$orderby = "rating";
}
echo `$scriptdir/overall.pl $statsdir $orderby $max_items`;
?>
</table>
</body>
</html>
Code: Select all
#!/usr/bin/perl
my $armadir = shift || "/home/armagetronad/.armagetronad/var/";
my %players;
my $orderby = shift || "rating";
my $max_items = shift || 101;
open PLAYERS, $armadir . "/ladder.txt";
my @rawladder = <PLAYERS>;
close PLAYERS;
foreach my $player (@rawladder)
{
(my($rating), my($name)) = ($player =~ /^([-0-9.]+)\s*(.*$)/gio);
$players{$name}->{'name'} = $name;
$players{$name}->{'rating'} = $rating;
}
open PLAYERS, $armadir . "/highscores.txt";
my @rawscores = <PLAYERS>;
close PLAYERS;
foreach my $player (@rawscores)
{
(my($score), my($name)) = ($player =~ /^([-0-9.]+)\s*(.*$)/gio);
$players{$name}->{'name'} = $name;
$players{$name}->{'score'} = $score;
}
open PLAYERS, $armadir . "/won_matches.txt";
my @rawmatches = <PLAYERS>;
close PLAYERS;
foreach my $player (@rawmatches)
{
(my($matches), my($name)) = ($player =~ /^([-0-9.]+)\s*(.*$)/gio);
$players{$name}->{'name'} = $name;
$players{$name}->{'matches'} = $matches;
}
open PLAYERS, $armadir . "/won_rounds.txt";
my @rawrounds = <PLAYERS>;
close PLAYERS;
foreach my $player (@rawrounds)
{
(my($rounds), my($name)) = ($player =~ /^([-0-9.]+)\s*(.*$)/gio);
$players{$name}->{'name'} = $name;
$players{$name}->{'rounds'} = $rounds;
}
my @ordered;
if ($orderby eq "name") {
@ordered = sort {lc($a->{$orderby}) cmp lc($b->{$orderby})} values %players;
}
else {
@ordered = sort {$b->{$orderby} <=> $a->{$orderby}} values %players;
}
my $i = 1;
foreach my $player (@ordered)
{
last if $i == $max_items;
print " <tr>\r\n";
print " <td>" . $i++ . "</td>\n";
print " <td>" . $player->{'name'} . "</td>\r\n";
print " <td>" . $player->{'rating'} . "</td>\r\n";
print " <td>" . $player->{'matches'} . "</td>\r\n";
print " <td>" . $player->{'rounds'} . "</td>\r\n";
print " <td>" . $player->{'score'} . "</td>\r\n";
print " </tr>\r\n";
}