Jump to content

  • Log In with Google Log In with Steam
  • Sign In
  • Create Account

Did you vote today?

Did you know we depend on your votes? Please Vote! http://goo.gl/RsLpq Vote Often!


* - - - -

Server List Improvement


Like what I have done here (http://tigur.com/mutts/mutts.html), have the server list give an indication of up/down. It will help players at least know whether or not they should be able to get to a particular server or not. Code in use generating my page should easily move to your web server (simple perl script) and cron it to run at as desired.


#!/usr/bin/perl
use strict;
use warnings;
use feature qw{ switch };
use IO::Socket;
use Encode			 qw(decode);
## List servers to check
my @servers = ('creative.muttsworldmine.com', 'survival.muttsworldmine.com', 'l2d.muttsworldmine.com', 'tekkit.muttsworldmine.com', '<acronym title='Player vs Player' class='bbc ipSeoAcronym'>pvp</acronym>.muttsworldmine.com', 'hcpvp.muttsworldmine.com');
## Which port to use (for all servers)
my $port = 25565;
my $lockfile = "mutts.html.lock";
my $finalfile = "mutts.html";

open STATBLOCK, ">$lockfile" or die $!;
## Print the block header info
#print STATBLOCK '<div class="clearfix general_box">'."\n"
#	 . "\t". '<div style="text-align:center;margin:auto;padding-bottom:10px;margin-bottom:10px;background-image:url(http://muttsworldmine.com/forums/public/MuttsWorldServers.jpg.pagespeed.ce.N0MNTI7s8V.jpg);color:#fff;font-size:150%;line-height:200%">'."\n";
print STATBLOCK '<div class="clearfix general_box">'."\n"
	 . '<div style="text-align:center;margin:auto;padding-bottom:10px;margin-bottom:10px;color:#fff;font-size:150%;line-height:200%">'."\n";

## Process the servers and output for each line
foreach (@servers) {
	 ping_server($_, $port);
}
## Print the block footer info
#print STATBLOCK '<a href="https://plus.google.com/108545445522390676264" rel="publisher">Find us on Google+</a><br>'."\n"
#	 . "<!-- Place this tag where you want the badge to render -->\n"
#	 . '<g:plus href="https://plus.google.com/108545445522390676264" rel="author" width="200" height="69" theme="dark"></g:plus>'."\n"
#	 . "</div>\n";
rename($lockfile, $finalfile);
exit 0;
sub ping_server {
	 my ($host, $port) = @_;
## The logfile to use for each server stats (keeping it simple)
my $sock = IO::Socket->new(
			 Domain		 =>	 AF_INET,
			 PeerAddr	 =>	 $host,
			 PeerPort	 =>	 $port,
			 Proto		 =>	 'tcp',
			 Timeout	 => '15',
	 );
	 given($sock) {
			 when (undef) {
					 ## The server did not respond at all. There is a connection issue of some sort.
					 print STATBLOCK '<div style="color:red;font-family=sans-serif">'."$host</div>\n";
			 }
			 default {
					 ## If it got here, the socket connected. Now we test the response
					 print $sock "\xFE";
					 sysread($sock, my $resp, 256);
					 given($resp) {
							 when (/^\xFF/) {
									 ## The server responded normally. This is good.
									 substr($resp, 0, 3, '');
									 $resp = decode('UCS-2', $resp);
									 my($motd, $players, $maxplayers) = split /\x{A7}/, $resp;
									 print STATBLOCK '<div style="color:green;">'."$host</div>\n";
							 }
							 default {
									 ## The server did not respond normally. This is not good.
									 print STATBLOCK '<div style="color:red;">'."$host</div>\n";
							 }
					 }
			 }
	 }
}

Attachments




Relationship:
Status: Open


3 Comments

Nice! This will help the admins out a lot! Congrats on this :3
Oh god! CODE!
Looks awesome man +1 x100