Raised This Month: $51 Target: $400
 12% 

Trash this one


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
omer
Senior Member
Join Date: Nov 2011
Old 04-16-2012 , 05:00   Trash this one
Reply With Quote #1

Trash this one

Last edited by omer; 05-08-2012 at 10:52.
omer is offline
8088
Veteran Member
Join Date: Jan 2008
Old 04-16-2012 , 07:48   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #2

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.
__________________
steamID converter with OpenSearch browser plugin

Last edited by 8088; 04-16-2012 at 07:59. Reason: err0r
8088 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-16-2012 , 08:17   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #3

@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.
__________________

Last edited by xPaw; 04-16-2012 at 08:18.
xPaw is offline
8088
Veteran Member
Join Date: Jan 2008
Old 04-16-2012 , 08:28   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #4

I noticed the change, but don't they all use the same protocol, except for HLTV?
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-16-2012 , 08:32   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #5

Quote:
Originally Posted by 8088 View Post
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.
__________________

Last edited by xPaw; 04-16-2012 at 08:32.
xPaw is offline
8088
Veteran Member
Join Date: Jan 2008
Old 04-16-2012 , 10:33   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #6

Alright, I'll remember that. Thanks!
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
8088
Veteran Member
Join Date: Jan 2008
Old 04-16-2012 , 13:58   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #7

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.
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
8088
Veteran Member
Join Date: Jan 2008
Old 04-16-2012 , 14:30   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #8

Quote:
Originally Posted by omer View Post
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.
__________________
steamID converter with OpenSearch browser plugin
8088 is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 04-16-2012 , 14:57   Re: Want an simple PHP script for website with div id="serverstatus"
Reply With Quote #9

Quote:
Originally Posted by omer View Post
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.
__________________
xPaw is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 04-16-2012 , 15:18  
Reply With Quote #10

Quote:
Originally Posted by omer View Post
So if the server is nonsteam that can not be...?
No steam = no support
Doc-Holiday is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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