Server Count - Web Upload

smoochy boys on tour

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Written a small program that reads your Server Count and Uploads a file containing

"ServerName - Players : Qty"

in a Text file to an FTP of your Choice..

This can then by grabbed by a PHP script to embed in an image.

Screenie >>
ServerCount.JPG

File (Extract the 3 files and then run Setup.exe) >>

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

To Use >
Edit the UserCount.ini file with your details
Run UserCount from your start menu
Click "Connect" to see your user count
Click "Send Data to FTP" to upload the file you just created
Click "Run Every 15 Minutes" to repeatedly send your UserCount file to your FTP


Sample PHP Script to put it into an image (I have no idea when it comes to PHP so I just grabbed a script and edited it) > >

Here is Mine >
stingimage.php


Code:
<?php
/*
    Dynamic Heading Generator
    By Stewart Rosenberger
    http://www.stewartspeak.com/headings/    

    This script generates PNG images of text, written in
    the font/size that you specify. These PNG images are passed
    back to the browser. Optionally, they can be cached for later use. 
    If a cached image is found, a new image will not be generated,
    and the existing copy will be sent to the browser.

    Additional documentation on PHP's image handling capabilities can
    be found at http://www.php.net/image/    
*/


$font_file  = 'tahoma.ttf' ;
$font_size  = 20 ;
$font_color = '#ffffff' ;
$background_color = '#0A0644' ;
$transparent_background  = false ;
$cache_images = true ;
$cache_folder = 'cache' ;


/*
  ---------------------------------------------------------------------------
   For basic usage, you should not need to edit anything below this comment.
   If you need to further customize this script's abilities, make sure you
   are familiar with PHP and its image handling capabilities.
  ---------------------------------------------------------------------------
*/

$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') ;

// clean up text
//if(empty($_GET['text']))
//   fatal_error('Error: No text specified.') ;
    
//$text = $_GET['text'] ;
$text = file_get_contents("Mir3Users.txt");
//if(get_magic_quotes_gpc())
//   $text = stripslashes($text) ;
//$text = javascript_to_html($text) ;

// 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. '%u2018' => '‘'). 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 ;
}

?>

If you want support, please PM me on MSN as I do not read stuff on LOMCN.
 

JoeAshton

Golden Oldie
Golden Oldie
Mar 4, 2006
641
1
124
hehehehe nice work just tested it works for me :):):):):)

may be make a better map maker 1 i using atm sucks
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Updated PHP Script - with a tiny bit of basic understanding :) (sort of :P)

Code:
<?php
header("Content-type: image/png");
$font_file  = 'tahoma.ttf' ;                             //Name of the True Type Font located in the same place as this File
$font_size  = 20 ;                                       //Size of the Font
$string = file_get_contents("Mir3Users.txt");            //Either use to fetch the information from a file
//$string = $_GET['text'];                               //Or use this to get the information from the HTML using
//                                                         something like www.sting3g.com/newone.php?text=Hello
$im     = imagecreatefrompng("header_logo_08.png");      //This is the name of the image.. also must be located in the same place as this file
$co     = imagecolorallocate($im, 220, 210, 60);         //Sets the Colour using RGB
$px     = (imagesx($im) - 10 * strlen($string)) / 2;     //Sets the X position
ImageTTFText($im,$font_size,0,$px,85,
    $co,$font_file,$string) ;                            //Draws the image and sets the text
imagepng($im);                                           //Sends the .png output
imagedestroy($im);                                       //Deletes the image from memory
?>

This creates something like this >>

newone.php


I am going to edit the program so it will customize the text output to file..

i.e.

Sting - Players : 8

or

Players : 8

or

Sting : 8 Online

or

Whatever you want :P I will upload and remove the old one once I have it completed.
 
Upvote 0

Kaori

LOMCN MiR3 Queen!
VIP
Jun 3, 2004
3,584
38
285
Canada
I like the fact that it uploads to ftp.

I didn't use the app yet... Questions:
does it use port 3000? and only port 3000?
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
For reading the server info yeah, I got LeoCrashers UserCount app that fetches the user count for Mir 2 servers, apapted for Mir 3 and then modified like hell :)

It now allows you to specifiy the Output of the Text.

%S = ServerName
%C = ServerCount

So you could use ANY combination.. BUT only 1 of each..

So..

%S, %C Players Online
%S : %C Online
%C Players Online
%S - Who Cares how many online :P
Server: %S - Players Online: %C

Whatever...

To get the New Files that include the latest option, download the rar file shown above.. if you just want the exe and ini, just extract them to where you installed it originally.


Some Screenies below..

ServerCount1.JPG
ServerCount2.JPG
ServerCount3.JPG
ServerCount4.JPG
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
bit late to this post :) nice additions to your last post, will the new version of this application be available for public use?
 
Last edited:
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Its still too rough to release, and I really don't have time to do much with it at the moment.... but... all of that information is available to anyone who has AMS set up, Just need to figure out how to do the php.

/Mick
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
i no enough how to display my own information on a website with kaori's ams. dont no how to stick it into an image hehe. but ill try to google it and find out. thanks for the info. :)
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
If you can grab the info, putting it into an image is quite easy.

I have posted some php code that puts text into a png image, just manipulate that using the text from your SQL queries.
 
Upvote 0

Sammy

Dedicated Member
Dedicated Member
Sep 9, 2007
66
1
54
How would i get the information to show up on my forum banner, vBulletin templates aint easiest thing to play with when you not got a coding mind :P id pm u on msn but u aint allowed me yet :P i added u tho :)


Nevermind managed to get it on now :P hehe thanks for script tho Ida :)
 
Last edited:
Upvote 0

dilina

Dedicated Member
Dedicated Member
Oct 9, 2008
129
2
44
ok so i downloaded the server count , configed the ini to suite my files and ftp bla bla , i have in the "public_html/banner/" i have the banner.php were i added this code
Code:
<?php
header("Content-type: image/png");
$font_file  = 'tahoma.ttf' ;                             //Name of the True Type Font located in the same place as this File
$font_size  = 20 ;                                       //Size of the Font
$string = file_get_contents("Mir3Users.txt");            //Either use to fetch the information from a file
//$string = $_GET['text'];                               //Or use this to get the information from the HTML using
//                                                         something like www.sting3g.com/newone.php?text=Hello
$im     = imagecreatefrompng("[COLOR=Red]banner[/COLOR].png");      //This is the name of the image.. also must be located in the same place as this file
$co     = imagecolorallocate($im, 220, 210, 60);         //Sets the Colour using RGB
$px     = (imagesx($im) - 10 * strlen($string)) / 2;     //Sets the X position
ImageTTFText($im,$font_size,0,$px,85,
    $co,$font_file,$string) ;                            //Draws the image and sets the text
imagepng($im);                                           //Sends the .png output
imagedestroy($im);                                       //Deletes the image from memory
?>
, and in same folder i have the banner.png and the mir3users.txt , the program connect's to my ftp and writes the info its supose to write , i mean the server count in the mir3users.txt, but when i try open the
"hasekura.org/banner/banner.php" i get this error "The image "http://www.hasekura.org/banner/banner.php" cannot be displyed becouse it contains errors " ,
 
Last edited:
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Couple of things.. when I run it I get these errors

Code:
Warning: imagecreatefrompng(header_logo_banner.png) [function.imagecreatefrompng]: failed to open stream: No such file or directory in /home/hasekur/public_html/banner/banner.php on line 8

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/hasekur/public_html/banner/banner.php on line 9

Warning: imagesx(): supplied argument is not a valid Image resource in /home/hasekur/public_html/banner/banner.php on line 10

Warning: imagettftext() expects parameter 1 to be resource, boolean given in /home/hasekur/public_html/banner/banner.php on line 12

Warning: imagepng(): supplied argument is not a valid Image resource in /home/hasekur/public_html/banner/banner.php on line 13

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/hasekur/public_html/banner/banner.php on line 14

This first line suggests that imagecreatefrompng("banner.png") actually reads.. imagecreatefrompng(header_logo_banner.png)

Also make sure you upload tahoma.ttf into that folder you can get it from your windows system folder
 
Upvote 0

dilina

Dedicated Member
Dedicated Member
Oct 9, 2008
129
2
44
i added the font in the folder and still doesnt work , and i changed the "header_log_banner.png"(this was something i tryed to see if maybe i didnt understood wot im supose to do) back into "banner.png" but still have same error
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
The one I have above has this line commented out, maybe it should be??


Change
Code:
$px     = (imagesx($im) - 10 * strlen($string)) / 2;     //Sets the X position

To
Code:
//$px     = (imagesx($im) - 10 * strlen($string)) / 2;     //Sets the X position
 
Upvote 0

dilina

Dedicated Member
Dedicated Member
Oct 9, 2008
129
2
44
nope still doesnt work , and i tryed blocking em all 1 by 1 , all in the same time , i still get same error
 
Upvote 0

Kaori

LOMCN MiR3 Queen!
VIP
Jun 3, 2004
3,584
38
285
Canada
'banner.png' is not a valid PNG file.

It's a JPEG. You have to change it to PNG. (not just the filename)
 
Upvote 0