Net_GSQ API Question
| From: | Aidan Lister | Date: | Thu, 22 Apr 2004 10:38:05 +0000 |
| Subject: | Net_GSQ API Question | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-28252@lists.php.net to get a copy of this message | ||
Howdy,
I'm trying to work on a better API for Net_GameServerQuery.
The way it is now:
$base = new net_gameserverquery;
$server = $base->query(ip, port, game);
print $server->ping();
print_r $server->players();
print_r $server->rules();
The problems with this are:
If ping fails (because the server is down, not responding, etc) then the
other 3 will fail. Testing the first for false, then doing the other 2 isn't
very sexy.
Some servers allow you to send requests concurrently, i.e. if I send
/status/rules/ I'll get both the status, and the rules reply back. Although
it's not neccesary to take advantage of this, it's certainly faster.
So, what I'm thinking now:
// Put ip/port/game into the loading of the class (much like dom_document,
if you want to use the re-use the class, you create another instance)
$server = new net_gameserverquery(ip, port, game);
// query
print_r $server->query(NET_GAMESERVERQUERY_REQUEST_PING,
NET_GAMESERVERQUERY_REQUEST_STATUS,
NET_GAMESERVERQUERY_REQUEST_RULES)
Hardly very attractive
I think using strings instead of constants, ie. 'ping', 'status',
'rules' is
A Bad Thing.
Anyone have any comments?