Raised This Month: $252 Target: $400
 63% 

PHP - Server banner


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-27-2014 , 08:41   PHP - Server banner
Reply With Quote #1

Hey all, i've worked on a personal server banner long time ago.
Since my community doesn't exist more and i don't have more servers, why not share it.

I hope it will be useful for some of you.

Here is the way to use it : (replace bold text)

www.mywebsite.com/tracker.php?Address=IP:PORT&Engine=0or1

About Engine, 0 is for GoldSource | 1 is for Source.

Here is the code :

PHP Code:
<?php
    
// Thanks to xPaw, link to SourceQuery (check for updates) : https://github.com/xPaw/PHP-Source-Query-Class
    // Author : bboygrun / https://forums.alliedmods.net/member.php?u=77390
    
    
require 'SourceQuery/SourceQuery.class.php';
    
    
define"DEF__TIME_OUT");
    
// ****
    
define"DEF__IMAGE_NAME""server_banner.png" );
    
// ****
    
define"DEF__COLOR_RED"255 );
    
define"DEF__COLOR_GREEN"255 );
    
define"DEF__COLOR_BLUE"255 );
    
// ****
    
define"DEF__HOSTNAME_MAX_TEXT_LEN"55 );
    
define"DEF__HOSTNAME_TEXT_SIZE");
    
define"DEF__HOSTNAME_X"48 );
    
define"DEF__HOSTNAME_Y");
    
// ****
    
define"DEF__ADDRESS_TEXT_SIZE");
    
define"DEF__ADDRESS_X"48 );
    
define"DEF__ADDRESS_Y"20 );
    
// ****
    
define"DEF__PLAYERS_TEXT_SIZE");
    
define"DEF__PLAYERS_X"190 );
    
define"DEF__PLAYERS_Y"20 );
    
// ****
    
define"DEF__MAP_MAX_TEXT_LEN"16 );
    
define"DEF__MAP_TEXT_SIZE");
    
define"DEF__MAP_X"240 );
    
define"DEF__MAP_Y"20 );
    
// ****
    
define"DEF__ICON_X");
    
define"DEF__ICON_Y");
    
    if( isSet( 
$_GET'Address' ] ) AND isSet( $_GET'Engine' ] ) )
    {
        
$iEngine $_GET'Engine' ]; // 0 -> GOLDSRC / 1 -> SOURCE
        
$szAddress $_GET'Address' ];
        
$szExploded explode":"$szAddress );
        
$szServerIP $szExploded];
        
$szServerPort $szExploded];
        
        
$Query = new SourceQuery( );

        
$Info    = Array( );
        
$Rules   = Array( );
        
$Players = Array( );
        
        try
        {
            
$Query -> Connect$szServerIP$szServerPortDEF__TIME_OUT$iEngine );
        
            
$Info    $Query -> GetInfo( );
            
$Players $Query -> GetPlayers( );
            
$Rules   $Query -> GetRules( );
        }
        catch( 
Exception $e )
        {
            
$Exception $e;
        }
        
        
$Query -> Disconnect( );
        
        
header"Content-type: image/png" );
        
$rImage imagecreatefrompngDEF__IMAGE_NAME );
        
$iColor imagecolorallocate$rImageDEF__COLOR_REDDEF__COLOR_GREENDEF__COLOR_BLUE );
        
        
// Import game icon by server AppID
        
        
$szGameFileName "tracker_img/"$Info'AppID' ]. ".png";
        
$rIcon imagecreatefrompng$szGameFileName );
        
        
imagecopy$rImage$rIconDEF__ICON_XDEF__ICON_Y00imagesx$rIcon ), imagesy$rIcon ) );
        
        
// bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color )
        
        
imagestring$rImageDEF__ADDRESS_TEXT_SIZEDEF__ADDRESS_XDEF__ADDRESS_Y$szAddress$iColor );
        
        if( 
$Info'MaxPlayers' ] != )
        {
            
$szHostName $Info'HostName' ];
            
$szMapName $Info'Map' ];
            
            if( 
strlen$szHostName ) > DEF__HOSTNAME_MAX_TEXT_LEN )
            {
                
$szHostName substr$Info'HostName' ], 0DEF__HOSTNAME_MAX_TEXT_LEN ). ' ...';
            }
            
            if( 
strlen$szMapName ) > DEF__MAP_MAX_TEXT_LEN )
            {
                
$szMapName substr$szMapName0DEF__MAP_MAX_TEXT_LEN ). '..';
            }
            
            
imagestring$rImageDEF__HOSTNAME_TEXT_SIZEDEF__HOSTNAME_XDEF__HOSTNAME_Y$szHostName$iColor );
            
imagestring$rImageDEF__MAP_TEXT_SIZEDEF__MAP_XDEF__MAP_Y$szMapName$iColor );
            
            
imagestring$rImageDEF__PLAYERS_TEXT_SIZEDEF__PLAYERS_XDEF__PLAYERS_Y$Info'Players' ]. '/' .$Info'MaxPlayers' ], $iColor );
        }
        else
        {
            
imagestring$rImageDEF__PLAYERS_TEXT_SIZEDEF__PLAYERS_XDEF__PLAYERS_Y"SERVER OFF"$iColor );
        }

        
imagepng$rImage );
        
imagedestroy$rImage );
        
imagedestroy$rIcon );
    }
?>
Here are examples :
Code:
http://127.0.0.1/scripts/tracker.php?Address=127.0.0.1:27020&Engine=0



There is an icon for most games on GoldSource & Source (less on Source btw), if some icons are missing, you can tell me and i'll add them.

Icons registered for :
- Counter Strike
- Counter Strike : Condition Zero
- Counter Strike : Source
- Counter Strike : Global Offensive
- Day Of Defeat
- Deathmatch Classic
- Dota 2
- Half-Life 2: Deathmatch
- Left 4 Dead 2
- Opposing Force
- Ricochet
- Team Fortress Classic
- Team Fortress 2

Icons are in the "tracker_img" folder, the files names are the AppID of the game, if some games are missing, you can add them with the AppID (AND MAKE IT PNG FILE).
Here is the documentation where you can find the AppIDs : https://developer.valvesoftware.com/...pplication_IDs
Icons size are 28x27.
Attached Thumbnails
Click image for larger version

Name:	tracker.png
Views:	2563
Size:	11.8 KB
ID:	136253   Click image for larger version

Name:	tracker (1).png
Views:	2569
Size:	11.5 KB
ID:	136255  
Attached Files
File Type: zip scripts.zip (45.6 KB, 596 views)
__________________

Last edited by bboygrun; 07-27-2014 at 19:50. Reason: L4D2 Added & TF2 modification.
bboygrun is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 07-27-2014 , 09:42   Re: PHP - Server banner
Reply With Quote #2

Thank you for sharing. This will be very useful.
__________________
Problem with ZP?
ZP Helper!
zmd94 is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-27-2014 , 10:59   Re: PHP - Server banner
Reply With Quote #3

Nice, thanks for sharing.
__________________
Kia is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-27-2014 , 14:22   Re: PHP - Server banner
Reply With Quote #4

You're welcome, nice to see i didn't post for nothing .

I probably have to put defines for the colors of each text.
__________________

Last edited by bboygrun; 07-27-2014 at 18:31.
bboygrun is offline
Eagle07
Veteran Member
Join Date: May 2014
Location: Morocco :D
Old 07-27-2014 , 18:18   Re: PHP - Server banner
Reply With Quote #5

Thanks for sharing
__________________
Eagle07 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-27-2014 , 19:31   Re: PHP - Server banner
Reply With Quote #6

Thx for sharing, using it in my sig
__________________
WildCard65 is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-27-2014 , 19:34   Re: PHP - Server banner
Reply With Quote #7

I didn't make the l4d2 icon, i will add it in the .zip file ASAP.
__________________

Last edited by bboygrun; 07-27-2014 at 19:35.
bboygrun is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-27-2014 , 19:36   Re: PHP - Server banner
Reply With Quote #8

Suggestion: Make TFC icon not like the TF2 icon and make the TF2 not have the 2 in it
__________________
WildCard65 is offline
bboygrun
CHOMP
Join Date: May 2010
Location: France
Old 07-27-2014 , 19:47   Re: PHP - Server banner
Reply With Quote #9

TF2 icon changed (it still has the "2" but it is now better).

Feel free to create/modify icons and post them here, i'll update the attachment, the icons sizes are : 28x27
__________________
bboygrun is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-27-2014 , 19:53   Re: PHP - Server banner
Reply With Quote #10

Mind making the banner a bit bigger as the OGC is in the way of the map name for my tf2 server and so I can have the mod description a little further over? Other then that, it's a great banner.
__________________

Last edited by WildCard65; 07-27-2014 at 19:57.
WildCard65 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:56.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode