AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   Trash this one (https://forums.alliedmods.net/showthread.php?t=183016)

omer 04-16-2012 05:00

Trash this one
 
Trash this one

8088 04-16-2012 07:48

Re: Want an simple PHP script for website with div id="serverstatus"
 
PHP Code:

<?php

require_once('JG_Cache.php');
require_once(
'SourceQuery.class.php');

$servers = array(
// add servers like this:
//'server_01' => array ('name' => 'My shitty server', 'ip' => 'abc.example.com', 'port' => '27015'),
//'server_02' => array ('name' => 'My crap server', 'ip' => '1.2.3.4', 'port' => '27015'),
  
'server_03' => array('name' => 'My awesome server''ip' => 'dks.servehalflife.com''port' => '27016')
);


foreach (
$servers as $server) {

  
$cache = new JG_Cache('/tmp');
  
$info $cache->get($server['name'], 60); // second paramater = cache time in seconds

  
if ($info === false) {
    
$query = new SourceQuery();
    try {
      
$query->Connect($server['ip'], $server['port']);
      
$info $query->GetInfo();
    } catch (
SourceQueryException $e) {
      
$info $e->getMessage();
    }
    
$cache->set($server['name'], $info);
  }

  if (
is_array($info)) {
    echo 
'<div style="color:#fff;">' $server['ip'] . ':' $server['port'] . ' | map: ' $info['Map'] . ' | players: ' $info['Players'] . '/' $info['MaxPlayers'] . '</div>';
  }
  else {
    echo 
'<div style="color:#ff0000;">' $server['ip'] . ':' $server['port'] . ' (offline)</div>';
  }
}

Requires these two classes:in the same directory.

I didn't add the id, because that will be a problem if you add more servers (ids need to be unique). Use a class instead.

xPaw 04-16-2012 08:17

Re: Want an simple PHP script for website with div id="serverstatus"
 
@8088, my class recently was updated and it requires $Engine param to be set in Connect(), so you might want to edit that. It defaults to Source.

8088 04-16-2012 08:28

Re: Want an simple PHP script for website with div id="serverstatus"
 
I noticed the change, but don't they all use the same protocol, except for HLTV?

xPaw 04-16-2012 08:32

Re: Want an simple PHP script for website with div id="serverstatus"
 
Quote:

Originally Posted by 8088 (Post 1690353)
I noticed the change, but don't they all use the same protocol, except for HLTV?

Using GetInfo() won't give any problems. However, when you will try to use GetPlayers, GetRules or RCON it will break.

8088 04-16-2012 10:33

Re: Want an simple PHP script for website with div id="serverstatus"
 
Alright, I'll remember that. Thanks!

8088 04-16-2012 13:58

Re: Want an simple PHP script for website with div id="serverstatus"
 
I haven't used e107 in years and I plan to keep it that way. You'll have to find a way to include the code I posted.

8088 04-16-2012 14:30

Re: Want an simple PHP script for website with div id="serverstatus"
 
Quote:

Originally Posted by omer (Post 1690574)
and i want one change when it was offline result should be this
Server addres: dks.servehalflife.com:27016 (offline) Mapname: UnKnown Players: Not available

Feel free to edit the script to your needs.
Quote:

and you script not working it says all servers offline following servers are 24/7
86.96.195.63:27017
92.98.125.211:27016
It does that because, apparently, they cannot be queried from where the script is running. And 24/7? Not from where I'm sitting.

xPaw 04-16-2012 14:57

Re: Want an simple PHP script for website with div id="serverstatus"
 
Quote:

Originally Posted by omer (Post 1690574)
and i want one change when it was offline result should be this
Server addres: dks.servehalflife.com:27016 (offline) Mapname: UnKnown Players: Not available
and you script not working it says all servers offline following servers are 24/7
86.96.195.63:27017
92.98.125.211:27016

Sweet non-steam on both of these servers.

Doc-Holiday 04-16-2012 15:18

Quote:

Originally Posted by omer (Post 1690600)
So if the server is nonsteam that can not be...?

No steam = no support


All times are GMT -4. The time now is 16:37.

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