MadMakz
/
Misc-Tools
Archived
1
0
Fork 0
This repository has been archived on 2022-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
Misc-Tools/PHP/HLXCE/ServerStatusImage/serverimage.php

199 lines
7.1 KiB
PHP

<?php
/*
HLstatsX Community Edition - Real-time player and clan rankings and statistics
Copyleft (L) 2008-20XX Nicholas Hastings (nshastings@gmail.com)
http://www.hlxcommunity.com
HLstatsX Community Edition is a continuation of
ELstatsNEO - Real-time player and clan rankings and statistics
Copyleft (L) 2008-20XX Malte Bayer (steam@neo-soft.org)
http://ovrsized.neo-soft.org/
ELstatsNEO is an very improved & enhanced - so called Ultra-Humongus Edition of HLstatsX
HLstatsX - Real-time player and clan rankings and statistics for Half-Life 2
http://www.hlstatsx.com/
Copyright (C) 2005-2007 Tobias Oetzel (Tobi@hlstatsx.com)
HLstatsX is an enhanced version of HLstats made by Simon Garner
HLstats - Real-time player and clan rankings and statistics for Half-Life
http://sourceforge.net/projects/hlstats/
Copyright (C) 2001 Simon Garner
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
For support and installation notes visit http://www.hlxcommunity.com
*/
//------------------------------------------------------------------------------------------------------------+
// Server Image Status addon for HLstatsX:CE v1.6+ by MadMakz (http://madmakz.com)(http://sourcepowered.net/)
// v1.0
// Based on the code from the "Basic Dynamic Server Image Status addon for LGSL by MadMakz (http://madmakz.com)
// for The Source Powered Network (http://sourcepowered.net/)"
// Thanks to Perry (from LGSL), bonzo, psychonic
//------------------------------------------------------------------------------------------------------------+
// FIRST TELL THE STUPID BROWSER THAT IT IS AN IMAGE & TURN OFF ERROR REPORTING BECAUSE WE CAN
error_reporting("0");
Header("Content-type: image/png");
//------------------------------------------------------------------------------------------------------------+
// GET THE REQUIRED INFOS FROM HLX
define('IN_HLSTATS', true);
require('config.php');
require(INCLUDE_PATH . "/class_db.php");
require(INCLUDE_PATH . "/functions.php");
$db_classname = 'DB_' . DB_TYPE;
if ( class_exists($db_classname) )
{
$db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
}
else
{
die;
}
$server_id = '1';
if ((isset($_GET['server_id'])) && (is_numeric($_GET['server_id'])))
$server_id = valid_request($_GET['server_id'], 1);
$result = $db->query("
SELECT
IF(publicaddress != '', publicaddress, concat(address, ':', port)) AS addr,
name,
publicaddress,
act_map,
kills,
act_players,
max_players,
ct_wins,
ts_wins,
country,
game
FROM
hlstats_Servers
WHERE
serverId='$server_id'");
$server_data = $db->fetch_array($result);
//------------------------------------------------------------------------------------------------------------+
// THE MAGIC STARTS HERE
// OUR BASIC BACKGROUND (YUP, WE SUPPORT GAMETYPE BASED IMAGES^^)
$bgimg = IMAGE_PATH."/games/{$server_data['game']}/serverimage.png";
if (!file_exists($bgimg)){
$bgimg = IMAGE_PATH."/serverimage.png"; // If we have no gamebased background we use always the default
}
$im = imagecreatefrompng($bgimg);
// MAP
$mapimg = getImage("/games/{$server_data['game']}/maps/{$server_data['act_map']}");
if (!file_exists($mapimg['path'])) {
$mapimg['path'] = IMAGE_PATH."/unknown.jpg";
}
$im_map_info = getimagesize($mapimg['path']);
if ($im_map_info[2] == 1) { $im_map = imagecreatefromgif($mapimg['path']); }
if ($im_map_info[2] == 2) { $im_map = imagecreatefromjpeg($mapimg['path']); }
if ($im_map_info[2] == 3) { $im_map = imagecreatefrompng($mapimg['path']); }
// GAMEICON
$gico = getImage("/games/{$server_data['game']}/game");
if (!file_exists($gico['path'])) {
$gico['path'] = IMAGE_PATH."/server.gif";
}
$im_icon_info = getimagesize($gico['path']);
if ($im_icon_info[2] == 1) { $im_icon = imagecreatefromgif($gico['path']); }
if ($im_icon_info[2] == 2) { $im_icon = imagecreatefromjpeg($gico['path']); }
if ($im_icon_info[2] == 3) { $im_icon = imagecreatefrompng($gico['path']); }
// COUNTRY FLAG
$country = $server_data['country'];
// Workarround to get the 2 digit Country code.
$result = $db->query("
SELECT
name,
flag
FROM
hlstats_Countries
WHERE
name='$country'");
$country_data = $db->fetch_array($result);
//
$cimg = getImage("/flags/".strtolower($country_data['flag'])."");
$cimage_info = getimagesize($cimg['path']);
if ($cimage_info[2] == 1) { $cimage = imagecreatefromgif($cimg['path']); }
if ($cimage_info[2] == 2) { $cimage = imagecreatefromjpeg($cimg['path']); }
if ($cimage_info[2] == 3) { $cimage = imagecreatefrompng($cimg['path']); }
// FONT COLOR
$text_color0 = ImageColorAllocate($im,255,255,255);
// GET TEXT
$string0 = $server_data['name'];
$string1 = $server_data['publicaddress'];
$string2 = $server_data['act_map'];
$string3 = "{$server_data['act_players']}/{$server_data['max_players']}";
$string4 = $server_data['kills'];
$string5 = "{$server_data['ct_wins']}/{$server_data['ts_wins']}";
// MAP/GAMEIMAGE LOCATION ON BASE BACKGROUND
$im_map_width = 130;
$im_map_height = 120;
$im_map_posx = 25;
$im_map_posy = 112;
$im_icon_width = 20;
$im_icon_height = 20;
$im_icon_posx = 26;
$im_icon_posy = 113;
// SPRINT TO THE FINISH LINE
// Mapimage, Gameicon
imagecopyresampled($im, $im_map, $im_map_posx, $im_map_posy, 0, 0, $im_map_width, $im_map_height, $im_map_info[0], $im_map_info[1]);
imagecopyresampled($im, $im_icon, $im_icon_posx, $im_icon_posy, 0, 0, $im_icon_width, $im_icon_height, $im_icon_info[0], $im_icon_info[1]);
imagecopyresampled($im, $cimage, $im_icon_posx + 111, $im_icon_posy + 3, 0, 0, 16, 11, $cimage_info[0], $cimage_info[1]);
// Servername
imagestring($im, 1, 6, 11, substr($string0,0,34), $text_color0);
// IP:Port
imagestring($im, 1, 6, 28, " IP:Port: {$string1}",$text_color0);
// Map
imagestring($im, 1, 6, 45, " Map: {$string2}",$text_color0);
// Players
imagestring($im, 1, 6, 60, " Players: {$string3}",$text_color0);
// Kills
imagestring($im, 1, 6, 76, " Kills: {$string4} (Total)",$text_color0);
// CT/T Wins
imagestring($im, 1, 6, 92, " CT/T Wins: {$string5} (Total)",$text_color0);
// NOW LET THE MAGIC HAPPEN AND PULL ALL THAT SHIT INTO AN IMAGE
imagepng($im);
imagedestroy($im);
//------------------------------------------------------------------------------------------------------------+
?>