Jump to content

Recommended Posts

Hello, i'm a PHP Learner, i'm in a situation where i'm stuck and really need some help. I'm trying to re-code a Dynamic Signature Generator Script for a Multiplayer Game

I got the site setup fixed and it works.

 

But the Generator is pulling stats and information from another Game Query since the script was like that.

So i need it to pull the Stats and Information of the Game i'm trying to re-code it for. Luckily i have a Query for that

 

This is the site:

http://mpgenerator.clubos.net/

 

Try it on: 91.204.210.28:7786

 

It takes stats from the game SAMP - and i need it to take Stats from M2MP

So how would i go by having it pull stats from the M2MP Query i'm stuck need help from an expert thank you so much in advance.

 

 

M2MP QUERY:

 

<?php


/*------------------------------------------------------------
| M2MP Query Script
|------------------------------------------------------------
| This class enables you to connect to a M2MP server
| and get info about it.
|------------------------------------------------------------
| Author: Lordkire
------------------------------------------------------------*/


class M2MPServer {

private $ip, $port, $timeout, $retries, $maxretries, $socket, $connected;

public function __construct($ip, $port = 27016, $timeout = 2, $retries = 1) {
$this->ip = $ip;
$this->port = $port;
$this->timeout = $timeout;
$this->retries = 0;
$this->maxretries = $retries;

$this->socket = @fsockopen('udp://' . $this->ip, $this->port, $errno, $errstr, $this->timeout);
socket_set_timeout($this->socket, $this->timeout);

if (!$this->socket) {
$this->connected = false;
return;
}

if ($this->sendPacket('p')) {
$this->connected = true;
return;
}
else {
$this->connected = false;
}
}

private function sendPacket($opcode) {
fwrite($this->socket, 'M2MP' . $opcode);
$packet = fread($this->socket, 1024);
if (!$packet) {
if ($this->retries < $this->maxretries) {
$this->retries += 1;
return $this->sendPacket($opcode);
}
else {
$this->retries = 0;
return false;
}
}
else {
$this->retries = 0;
$packet = rtrim($packet, "\x00");
return $packet;
}
}

// This function is used to get the IP address and (query) port number of the server.
// Returns an array with:
// - index 0: IP addres (str)
// - index 1: Query port (int)
public function getAddress() {
return array($this->ip, $this->port);
}

// This function is used to check if the script is connected to the server.
// It is best to check this first before using the other functions (saves time-out time).
// Returns true if connected, false if not connected.
public function isConnected() {
return $this->connected;
}

// This function is used to get the ping from the webserver that runs the script to the M2MP server.
// Returns the ping (int) if the query succeeded, and false if it failed.
public function getPing() {
$startTime = microtime();
fwrite($this->socket, 'M2MPp');
$packet = fread($this->socket, 1024);
$stopTime = microtime();
if (!$packet) {
if ($this->retries < $this->maxretries) {
$this->retries += 1;
return $this->getPing();
}
else {
$this->retries = 0;
return false;
}
}
else {
$this->retries = 0;
return ceil(($stopTime - $startTime) * 1000);
}
}

// This function is used to get basic info about the server.
// The function returns an array with the following keys if the query succeeded:
// - 'hostname': name of the server (str)
// - 'players': number of players in the server (int)
// - 'maxplayers': maximum number of players (int)
// - 'gamemode': name of the gamemode (str)
// - 'passworded': wether the server requires a password (bool)
// - 'mapname': name of the map (str)
// - 'version': server version (str)
// - 'weburl': web URL as specified in the server's config (str)
// - 'httpport' : httpport as specified in the server's config (str)
// Or it returns false in case the query failed.
public function getInfo() {
$packet = $this->sendPacket('i');
if ($packet) {
$packet = explode('<info>', $packet);
$info = array(
'hostname' => $packet[1],
'players' => (int)$packet[2],
'maxplayers' => (int)$packet[3],
'gamemode' => $packet[4],
'passworded' => (bool)$packet[5],
'mapname' => $packet[6],
'version' => $packet[7],
'weburl' => $packet[8],
'httpport' => $packet[9]);
return $info;
}
else {
return false;
}
}

// This function is used to get the playerlist of the server.
// It returns an array with players arrays if the query succeeded, or false if the query failed.
// The player arrays have the following keys:
// - 'id': the playerid (int)
// - 'name': the player's nickname (str)
// - 'score': the player's score (int)
public function getPlayers() {
$packet = $this->sendPacket('l');
if ($packet) {
$packet = explode('<info>', $packet);
if ($packet[1] > 0) {
$packet = explode('<player>', $packet[2]);
foreach ($packet as $player) {
$player = explode('<data>', $player);
$players[] = array(
'id' => (int)$player[0],
'name' => $player[1],
'score' => (int)$player[2]);
}
return $players;
}
else {
return false;
}
}
else {
return false;
}
}

// This function checks if a player with name == $name is on the server.
// It returns true if there is, and false if there isn't, or if the query failed.
public function isPlayerOnline($name) {
if ($players = $this->getPlayers()) {
foreach ($players as $player) {
if ($player['name'] == $name) {
return true;
}
}
return false;
}
else {
return false;
}
}

// This static function returns an array of M2MPServer objects based on the master list.
// If the master list could not be found, it returns false.
public static function getMasterList($url = 'http://www.m2-multiplayer.com/master/list.php') {
$data = file_get_contents($url);
if ($data) {
$data = explode('<br />', $data);
unset($data[count($data) - 1]);
foreach ($data as $server) {
$server = explode(':', $server);
$servers[] = new M2MPServer($server[0], $server[1] + 1);
}
return $servers;
}
else {
return false;
}
}

// This static function returns an array with info about the master list, with the following keys:
// - 'players': the total number of players online (int)
// - 'maxplayers': the total number of player slots (int)
// - 'servers': the nummber of servers online (int)
// Or it returns false in case the master list could not be found.
public static function getMasterInfo($url = 'http://www.m2-multiplayer.com/master/list.php') {
if ($servers = self::getMasterList($url)) {
$masterInfo = array(
'players' => 0,
'maxplayers' => 0,
'servers' => 0);
foreach ($servers as $server) {
if ($server->isConnected() && ($info = $server->getInfo())) {
$masterInfo['players'] += $info['players'];
$masterInfo['maxplayers'] += $info['maxplayers'];
$masterInfo['servers'] += 1;
}
}
return $masterInfo;
}
else {
return false;
}
}

public function __destruct() {
@fclose($this->socket);
}

}

?>

 

 

BIG Signature

 

<?php
/*********************************************
*** SA-MP Server BIG Signature v1.0 ***
*** by MrConso99 ***
*********************************************/
//Thanks to RyDeR for the function <<list($server_ip, $server_port) = explode(':', $data);>>
//========================================================
$data = $_GET['ip'];
$htmlcolor = $_GET['textcolor'];
list($server_ip, $server_port) = explode(':', $data);
require "SampQueryAPI.php";
//=========================================================
function R($color)
{
if ($color[0] == '#')
$color = substr($color, 1);

if (strlen($color) == 6)
list($r, $g, $B) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $B) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;

$r = hexdec($r); $g = hexdec($g); $b = hexdec($B);

return $r;
}
function G($color)
{
if ($color[0] == '#')
$color = substr($color, 1);

if (strlen($color) == 6)
list($r, $g, $B) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $B) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;

$r = hexdec($r); $g = hexdec($g); $b = hexdec($B);

return $g;
}
function B($color)
{
if ($color[0] == '#')
$color = substr($color, 1);

if (strlen($color) == 6)
list($r, $g, $B) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $B) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;

$r = hexdec($r); $g = hexdec($g); $b = hexdec($B);

return $b;
}
//=========================================================
header("Content-type: image/png");
$img = imagecreatefrompng('image.png');
$font = "font_big.ttf";
imagealphablending($img, true);
imagesavealpha($img, true);
//=========================================================
$black = imagecolorallocate($img, R($htmlcolor), G($htmlcolor), B($htmlcolor));
/*
Here you can make the color that u like 
Examples:
$red = imagecolorallocate($img, 255, 0, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
$yellow = imagecolorallocate($img, 255, 255, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$black = imagecolorallocate($img, 0, 0, 0);
*/
//=========================================================
$query = new SampQueryAPI($server_ip,$server_port);
if ($query->isOnline())
{
$aInformation = $query->getInfo();
$aServerRules = $query->getRules();
imagettftext($img, 10, 0, 8, 17, $black, $font, $aInformation['hostname']);
imagettftext($img, 8, 0, 7, 40, $black, $font, "GameMode: ".$aInformation['gamemode']);
imagettftext($img, 8, 0, 7, 55, $black, $font, "IP: ".$server_ip.":".$server_port);
imagettftext($img, 8, 0, 7, 70, $black, $font, "Players: ".$aInformation['players']."/".$aInformation['maxplayers']);
imagettftext($img, 8, 0, 7, 85, $black, $font, "Map: ".$aServerRules['mapname']);
imagepng($img);
}
else
{
imagettftext($img, 8, 0, 150, 15, $black, $font,"This Server is offline...");
imagepng($img);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/271403-dynamic-signature-generator/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.