server count for mir2

smoochy boys on tour

koni

V.I.P
VIP
Mar 14, 2006
1,111
1
185
Southampton UK
hiya,

is there anyone who would be willing to make a program that will display the amount of users online for each server like leo's site used to do, and possibly be in a siggy image ?
 
Last edited:

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
I will upload one on Monday if I get chance. It will depend on each server owner (or someone willing to run the program full time PER SERVER) using the program to upload their server's server count.

Kaori does it for Mir 3 and Mir 2 server count isn't much different (Although Sting uses my own). She might be able to offer a more elegant solution.
 

Kaori

LOMCN MiR3 Queen!
VIP
Jun 3, 2004
3,584
38
285
Canada
I can provide a server status thingy. (like the mir3 one)
I need some info from all servers...
This is the excel columns that I use for mir3... and example

ServerName,ServerType,ExpRate,IP/FQDN,Port7000,Port7100,Port7200,Port3000,Since,Poster
KaoriEI,EI,4x,kaorimir.com,7000,7100,7200,3000,Apr'03,Kaori

If you can get this list to me, I can set it up right away.

as for siggy, if you want just the user count and any of the above info, I can add a siggy.

But stuff like level, exp %, etc... I can't get those info remotely. idabiga already made something like that for mir3. not sure if mir2 uses the same config/sql.
 

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
bandet.php


evilmir.php


My Program now works with DM2 Servers - Not sure on others.

You can download it here > >

http://www.sting3g.com/idaBigA/ServerCountInstallFiles.rar

Image - Just input the details shown (Make sure you click "Mir 2?")- there is a small walkthrough on Mir 3's Server Help section.

ServerCountA.JPG


This does NOT need to be run on the server PC, it can be run on ANY PC ANYWHERE that has access to the internet. You will need web space that has PHP installed to get the image (a demo is below).

Php is as follows..

Code:
<?php
$font_file  = 'tahoma.ttf' ;
$font_size  = 20 ;
$font_color = '#ffffff' ;
$background_color = '#0A0644' ;
$transparent_background  = false ;
$cache_images = true ;
$cache_folder = 'cache' ;
$mime_type = 'image/png' ;
$extension = '.png' ;
$send_buffer_size = 4096 ;

// check for GD support
if(!function_exists('ImageCreate'))
    fatal_error('Error: Server does not support PHP image generation') ;
$text = file_get_contents("bandet.txt");
// look for cached copy, send if it exists
$hash = md5(basename($font_file) . $font_size . $font_color .
            $background_color . $transparent_background . $text) ;
$cache_filename = $cache_folder . '/' . $hash . $extension ;
if($cache_images && ($file = @fopen($cache_filename,'rb')))
{
    header('Content-type: ' . $mime_type) ;
    while(!feof($file))
        print(($buffer = fread($file,$send_buffer_size))) ;
    fclose($file) ;
    exit ;
}

// check font availability
$font_found = is_readable($font_file) ;
if(!$font_found)
{
    fatal_error('Error: The server is missing the specified font.') ;
}
// create image
$background_rgb = hex_to_rgb($background_color) ;
$font_rgb = hex_to_rgb($font_color) ;
$dip = get_dip($font_file,$font_size) ;
$box = @ImageTTFBBox($font_size,0,$font_file,$text) ;
$image = @ImageCreate(abs($box[2]-$box[0]),abs($box[5]-$dip)) ;
if(!$image || !$box)
{
    fatal_error('Error: The server could not create this heading image.') ;
}

// allocate colors and draw text
$background_color = @ImageColorAllocate($image,$background_rgb['red'],
    $background_rgb['green'],$background_rgb['blue']) ;
$font_color = ImageColorAllocate($image,$font_rgb['red'],
    $font_rgb['green'],$font_rgb['blue']) ;   
ImageTTFText($image,$font_size,0,-$box[0],abs($box[5]-$box[3])-$box[1],
    $font_color,$font_file,$text) ;



// set transparency
if($transparent_background)
    ImageColorTransparent($image,$background_color) ;

header('Content-type: ' . $mime_type) ;
ImagePNG($image) ;

// save copy of image for cache
if($cache_images)
{
    @ImagePNG($image,$cache_filename) ;
}

ImageDestroy($image) ;
exit ;


/*
	try to determine the "dip" (pixels dropped below baseline) of this
	font for this size.
*/
function get_dip($font,$size)
{
	$test_chars = 'abcdefghijklmnopqrstuvwxyz' .
			      'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
				  '1234567890' .
				  '!@#$%^&*()\'"\\/;.,`~<>[]{}-+_-=' ;
	$box = @ImageTTFBBox($size,0,$font,$test_chars) ;
	return $box[3] ;
}


/*
    attempt to create an image containing the error message given. 
    if this works, the image is sent to the browser. if not, an error
    is logged, and passed back to the browser as a 500 code instead.
*/
function fatal_error($message)
{
    // send an image
    if(function_exists('ImageCreate'))
    {
        $width = ImageFontWidth(5) * strlen($message) + 10 ;
        $height = ImageFontHeight(5) + 10 ;
        if($image = ImageCreate($width,$height))
        {
            $background = ImageColorAllocate($image,255,255,255) ;
            $text_color = ImageColorAllocate($image,0,0,0) ;
            ImageString($image,5,5,5,$message,$text_color) ;    
            header('Content-type: image/png') ;
            ImagePNG($image) ;
            ImageDestroy($image) ;
            exit ;
        }
    }

    // send 500 code
    header("HTTP/1.0 500 Internal Server Error") ;
    print($message) ;
    exit ;
}


/* 
    decode an HTML hex-code into an array of R,G, and B values.
    accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff 
*/    
function hex_to_rgb($hex)
{
    // remove '#'
    if(substr($hex,0,1) == '#')
        $hex = substr($hex,1) ;

    // expand short form ('fff') color
    if(strlen($hex) == 3)
    {
        $hex = substr($hex,0,1) . substr($hex,0,1) .
               substr($hex,1,1) . substr($hex,1,1) .
               substr($hex,2,1) . substr($hex,2,1) ;
    }

    if(strlen($hex) != 6)
        fatal_error('Error: Invalid color "'.$hex.'"') ;

    // convert
    $rgb['red'] = hexdec(substr($hex,0,2)) ;
    $rgb['green'] = hexdec(substr($hex,2,2)) ;
    $rgb['blue'] = hexdec(substr($hex,4,2)) ;

    return $rgb ;
}


/*
    convert embedded, javascript unicode characters into embedded HTML
    entities. (e.g. '‘' => '‘'). returns the converted string.
*/
function javascript_to_html($text)
{
    $matches = null ;
    preg_match_all('/%u([0-9A-F]{4})/i',$text,$matches) ;
    if(!empty($matches)) for($i=0;$i<sizeof($matches[0]);$i++)
        $text = str_replace($matches[0][$i],
                            '&#'.hexdec($matches[1][$i]).';',$text) ;

    return $text ;
}

?>

Change this line >

$text = file_get_contents("bandet.txt");

to the name of the file the program has uploaded case sensitive.

i.e. as shown in the Demo above - "EvilMir23.txt"

$text = file_get_contents("EvilMir24.txt");


Then save that file as a *.php file where you have uploaded the txt file, and then you can call that as an image (as shown above).
 
Last edited:

daydie

Banned
Banned
Golden Oldie
Aug 26, 2004
635
0
123
Nice work mate, Can the refresh rate not be edited? Quicker?


Thanks...
 

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
I will add an option now and update the installer.

Done

Download link above..

ServerCountB.JPG


You just edit the drop down box, options added from 2 to 30.

Also added credits mentioning LeoCrasher for the basic usercount program.
 
Last edited:

daydie

Banned
Banned
Golden Oldie
Aug 26, 2004
635
0
123
okay thanks :) BTW i have a litle prob =/

In evilmir.php i changed the Txt location to Mir2Users.txt... its in the same file as the test file. no writing appears. =/
Port 3000 is open etc
 
Last edited:

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Does it show an image not available graphic (X) or just no text?

If no text it means the text file it uploaded was empty. If the settings were altered after fetching the usercount and before uploading to FTP it will send an empty file.

If its an image not available graphix (X) then it probably cannot find the text file, ensure that it is in the same place and that it is the CaSe SeNsItIvE Correct filename.

Mick

P.S.. Last post updated
 

daydie

Banned
Banned
Golden Oldie
Aug 26, 2004
635
0
123
it is a X yer, But when i type the destination of the broken image it says this on a new page:

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\EvilMir.php on line 7


EDIT:

a sorted it, a image now come sup saying specified font missing from server.
 
Last edited:

daydie

Banned
Banned
Golden Oldie
Aug 26, 2004
635
0
123
what do i do about it then mate to fix, or have u got summat for me :) lol
 

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Just upload the "tahoma.ttf" font into your web space.. its available in the windows/font directory.
 

daydie

Banned
Banned
Golden Oldie
Aug 26, 2004
635
0
123
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\EvilMir1.php:1) in C:\xampp\htdocs\EvilMir1.php on line 61

Whys this happening


I sorted it :)
 
Last edited: