AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   PHP - Server banner (https://forums.alliedmods.net/showthread.php?t=245028)

bboygrun 07-27-2014 08:41

PHP - Server banner
 
3 Attachment(s)
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.

zmd94 07-27-2014 09:42

Re: PHP - Server banner
 
Thank you for sharing. This will be very useful.

Kia 07-27-2014 10:59

Re: PHP - Server banner
 
Nice, thanks for sharing.

bboygrun 07-27-2014 14:22

Re: PHP - Server banner
 
You're welcome, nice to see i didn't post for nothing :).

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

Eagle07 07-27-2014 18:18

Re: PHP - Server banner
 
Thanks for sharing :)

WildCard65 07-27-2014 19:31

Re: PHP - Server banner
 
Thx for sharing, using it in my sig

bboygrun 07-27-2014 19:34

Re: PHP - Server banner
 
I didn't make the l4d2 icon, i will add it in the .zip file ASAP.

WildCard65 07-27-2014 19:36

Re: PHP - Server banner
 
Suggestion: Make TFC icon not like the TF2 icon and make the TF2 not have the 2 in it

bboygrun 07-27-2014 19:47

Re: PHP - Server banner
 
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

WildCard65 07-27-2014 19:53

Re: PHP - Server banner
 
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.


All times are GMT -4. The time now is 10:28.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.