Author Topic: [PHP | REL] IV:MP Query v0.2 (for IVMP 0.1 Beta T4/5/6)  (Read 9090 times)

0 Members and 1 Guest are viewing this topic.

April 21, 2010, 11:38:42 PM

Offline Boylett

  • Administrator
  • *****
  • Posts: 595
    • View Profile
IV:MP Query v0.2
For IVMP 0.1 Beta T4

This PHP class lets you query IV:MP servers.

It is released under GNU/GPL.

Version 0.2: http://pastebin.com/ZV1gLmg1
Version 0.1: http://pastebin.com/GVRe70yp

Change Log
Version 0.2 Released
Added ServerRules(), Players() and Ping()

Version 0.1 Released

Example of usage:
Code: [Select]
<?php

require_once('ivmpquery.php');

$q = new IVMPQuery;

if(!
$q->Query('62.178.158.185',9999,$errno,$errstr,2))
{
    echo 
'Failed to query server ('.$errstr.')';
}
else
{
    echo 
'Info:<br />';
    
var_dump($q->ServerData());
    echo 
'<br /><br />Rules:<br />';
    
var_dump($q->ServerRules());
    echo 
'<br /><br />Players:<br />';
    
var_dump($q->Players());
    echo 
'<br /><br />Ping:<br />';
    
var_dump($q->Ping());

    
$q->Close();
}

?>
« Last Edit: November 26, 2010, 07:51:20 AM by Boylett [ServerHex.com] »
hai

April 21, 2010, 11:52:34 PM
Reply #1

Offline Chris Canfield

  • Maniac
  • ****
  • Posts: 638
  • Chillin' all day
    • View Profile
    • xUltimate
Dude sweet  8D
Owner of xUltimate.

Owner of Realistic-Mods.
(Currently Offline)

April 22, 2010, 12:24:52 AM
Reply #2

Offline evilwind

  • Master
  • ***
  • Posts: 468
    • View Profile

April 22, 2010, 01:02:15 AM
Reply #3

Offline shark

  • Newbie
  • *
  • Posts: 45
    • View Profile
Nice, Boylett!
tk!

April 22, 2010, 08:10:02 AM
Reply #4

Offline Zecko

  • Newbie
  • *
  • Posts: 19
    • View Profile
Useful, thanks.

April 22, 2010, 11:12:56 AM
Reply #5

Offline Settings

  • Regular
  • **
  • Posts: 172
  • +Yuval+
    • View Profile

April 22, 2010, 01:27:21 PM
Reply #6

Offline Zecko

  • Newbie
  • *
  • Posts: 19
    • View Profile
Why would cURL be better ?

If someone is interested I coded that to list all the servers : http://pastebin.com/LvQwLWQT

April 22, 2010, 02:20:47 PM
Reply #7

Offline Christopher

  • Developer
  • *****
  • Posts: 437
    • View Profile
    • Atom-Host
Nice release boylett, I will integrate this with the panel :D

April 22, 2010, 05:21:01 PM
Reply #8

Offline Boylett

  • Administrator
  • *****
  • Posts: 595
    • View Profile
The benefit of cURL is therefore better because it is easier to handle, it is faster and also much, much larger! You can work intensively with the data!
If you want to change it to cURL, you can do that yourself, it is released under GPL afterall.
hai

April 22, 2010, 05:54:29 PM
Reply #9

Offline MaVe

  • Developer
  • *****
  • Posts: 116
    • View Profile
    • mavecoder.com
I think cURL is more like designed for fetching websites' contents rather than querying a gameserver.

Anyways, nice one Boylett

April 23, 2010, 09:14:26 AM
Reply #10

Offline BlueRey

  • Newbie
  • *
  • Posts: 36
    • View Profile
Better that way:
Code: [Select]
<?php

require_once('ivmpquery.php');

$ip1 $_GET["ip"];
$port1 $_GET["port"];

$q = new IVMPQuery;

if(!
$q->Query($ip1,$port1,$errno,$errstr,2))
{
    echo 
'Failed to query server ('.$errstr.')';
}
else
{
    
$server $q->ServerData();

    if(
$server['maxplayers'] == 0)
    {
        echo 
'Failed to query server (no reply)';
    }
    else
    {
        echo 
$server['hostname'].' | '.$server['players'].' / '.$server['maxplayers'].($server['passworded'] ? ' | Passworded' '');
    }

    
$q->Close();
}

?>
usage (PHP): http://domain.com/ivmp.php?ip=79.178.123.219&port=7777

Thanks ;)


April 23, 2010, 11:56:43 AM
Reply #11

Offline evilwind

  • Master
  • ***
  • Posts: 468
    • View Profile
by the way (for ppl that are not that into php and stuff) you need to enable this in your php.ini to make this script work...

(as my webhost this was disabled, so had to uncomment it, remove ";")
;extension=php_sockets.dll[/color]

April 24, 2010, 11:05:12 AM
Reply #12

Offline DarkKostas

  • Regular
  • **
  • Posts: 59
    • View Profile
I tried it and it always prints 'Failed to query server (no reply)' in every server. Also i did a test with this
Code: [Select]
<?php
if(function_exists("fsockopen"))
{
echo "Function Exists";
}
else echo 
"Function does NOT Exist";
?>


To see if sockets are enabled and it prints 'Function Exists', so everything is ok.

April 24, 2010, 11:24:42 AM
Reply #13

Offline evilwind

  • Master
  • ***
  • Posts: 468
    • View Profile
DarkKostas

i had the same problem until i enabled sockets. if that dont fix it i have no idea...

April 24, 2010, 12:34:16 PM
Reply #14

Offline jenksta

  • Administrator
  • *****
  • Posts: 375
  • Lead Developer
    • View Profile
I tried it and it always prints 'Failed to query server (no reply)' in every server. Also i did a test with this
Code: [Select]
<?php
if(function_exists("fsockopen"))
{
echo "Function Exists";
}
else echo 
"Function does NOT Exist";
?>


To see if sockets are enabled and it prints 'Function Exists', so everything is ok.
Just because it exists it doesn't mean it works.
Quote
<TrojaA> <19:18:33> <&jenksta> how can we seriously open source junk code like that :/ <- Thou just hast to promote it like apple and thou canst