View Full Version : Halo Server Query API
souless
December 24th, 2012, 08:51 AM
Halo Server Querying has been butchered to death over the past 10 years, so this is nothing groundbreaking. My plan is create a public API that exposes many details about the server (from gametype names, all the way to weapon sets). The whole application is written in Node.JS, so naturally the exposed API will only be available in JSON. I hope this will make it easier for people to develop applications in PHP or even client-side Javascript.
I'm honestly not expecting this to fly high or gain any acceptance, so I've decided to release the source as well.
Enjoy fellow coders: http://bot.haloindex.com/query/
Github: https://github.com/soulcyon/halo-query
Cortexian
December 24th, 2012, 12:28 PM
http://www.modacity.net/forums/showthread.php?24947-AJAX-J-Server-Status&p=640506#post640506
Beat you to the punch by a few days :P
I believe it has API capabilities as well.
Limited
December 26th, 2012, 03:07 PM
http://www.modacity.net/forums/showthread.php?24947-AJAX-J-Server-Status&p=640506#post640506
Beat you to the punch by a few days :P
I believe it has API capabilities as well.The one you linked to isnt really an API Freelancer, you cannot put in your own query parameters and grab data back, which you can with the one Souless posted. That said BTC could amend the code to add that functionality.
I do have a question Souless, the one running on your website, thats using NodeJS right? How did you find a webhost to host your Node?
Btcc22
December 26th, 2012, 04:10 PM
you cannot put in your own query parameters and grab data back
You can if you're willing to host the PHP file. I didn't see any reason to allow people to grab the raw data from my example, although you could if you really wanted to by sending the query to ajax.php manually.
souless
December 26th, 2012, 11:44 PM
Btcc, many people cannot run UDP/socket requests on their PHP hosts. Which is why I created this service, to ease the pain of many developers. Furthermore, this enables users to use their own languages, as long as they know how to do simple REST/JSON requests.
I'm running this on VexxHost + CentOS. Not exactly a top-notch NodeJS hoster, but I don't have the bank to afford another host right now.
souless
December 26th, 2012, 11:46 PM
I might post a few samples of how this service can be useful, hopefully to get the creative juices running :D
Btcc, is your source code available for review?
Limited
December 27th, 2012, 12:20 PM
Btcc, many people cannot run UDP/socket requests on their PHP hosts. Which is why I created this service, to ease the pain of many developers. Furthermore, this enables users to use their own languages, as long as they know how to do simple REST/JSON requests.
I'm running this on VexxHost + CentOS. Not exactly a top-notch NodeJS hoster, but I don't have the bank to afford another host right now.
That is true, but most hosters won't allow for NodeJS either. Here is a list you might find useful though:
https://github.com/joyent/node/wiki/Node-Hosting
I forked both projects by the way :)
souless
December 27th, 2012, 01:19 PM
Thanks limited :3
Btw, you don't have to host my script to use it. Check out the main page @ http://bot.haloindex.com/query/ (http://bot.haloindex.com)
Just call a GET request with the proper parameters, and parse the JSON to your liking.
Like I said, I'll make some sample use cases (PHP, Java and some other language) so you guys get an idea of the possibilities.
Limited
December 27th, 2012, 01:35 PM
Well I'm wanting to work on 2 things really, Btcc's can cover both of those, yours only one. So thats why I using his codebase right now, that said though what I'm working on could work on either if both returned back same json :D
souless
December 27th, 2012, 10:45 PM
O.o what use is the UDP over PHP when you get similar JSON without doing any UDP calls?
Btcc22
December 27th, 2012, 10:52 PM
O.o what use is the UDP over PHP when you get similar JSON without doing any UDP calls?
Huh?
souless
December 27th, 2012, 10:57 PM
<?php
$ip = "127.0.0.1";
$port = "2302";
$ch = curl_init();
// BTCC22
// curl_setopt($ch, CURLOPT_URL, "osvex.com/halostatus/script/ajax.php?ip=$ip&port=$port");
curl_setopt($ch, CURLOPT_URL, "http://bot.haloindex.com/query/$ip:$port");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result);
?>
That's all you need to do to use my service. No need to learn NodeJS or copy PHP scripts/enable fsock. I also posted BTCC's URL, you will notice very different JSON objects.
Limited
December 28th, 2012, 12:06 PM
<?php
$ip = "127.0.0.1";
$port = "2302";
$ch = curl_init();
// BTCC22
// curl_setopt($ch, CURLOPT_URL, "osvex.com/halostatus/script/ajax.php?ip=$ip&port=$port");
curl_setopt($ch, CURLOPT_URL, "http://bot.haloindex.com/query/$ip:$port");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result);
?>
That's all you need to do to use my service. No need to learn NodeJS or copy PHP scripts/enable fsock. I also posted BTCC's URL, you will notice very different JSON objects.
Well yes, you could CURL either and get the JSON. At that stage you just pick which you'd rather use and parse.
I adopted Btcc's code to work on an api style environment. You could call it just via URL:
http://limited.osvex.com/api/46.249.47.12/2332/server_info
http://limited.osvex.com/api/46.249.47.12/2332/all
Or I offer the helper class file and an example that allows people to easily tap into the API.
<?php
include('api.inc.php');
echo "<pre>";
print_r(HaloStatus::getServerInfo("46.249.47.12","2332"));
// print_r(HaloStatus::getAll("46.249.47.12","2332")); // All Information
// print_r(HaloStatus::getPlayers("46.249.47.12","2332")); // Player Information
// print_r(HaloStatus::getTeamScore("46.249.47.12","2332")); // Team Information
echo "</pre>";
?>
souless
December 28th, 2012, 11:06 PM
Hmm, I would change your approach since it seems you need to query the server again to grab each of the details. To save UDP calls, which will ultimately save processing time, I would do something like this:
<?php
$hq = new HaloStatus("46.249.47.12:2332");
$hq->getTeamScore();
$hq->getPlayers();
// add any number of processing methods here
Furthermore, my API correctly parses the team score (ignores the one sent by the server). Try it with this IP address, http://bot.haloindex.com/query/74.91.119.188:2306
You can see in BTCC's team score API, it says "score_t0: 0", while mine shows the correct team score.
Btcc22
December 29th, 2012, 12:27 AM
It's not really a parsing problem or a question of being incorrect when it's displaying the data returned by the server. It's CTF except there are no flags to capture so you've added some kind of game type exception to your script. ;)
Having to make exceptions is not a good thing.
Limited
December 29th, 2012, 10:23 AM
Hmm, I would change your approach since it seems you need to query the server again to grab each of the details. To save UDP calls, which will ultimately save processing time, I would do something like this:
<?php
$hq = new HaloStatus("46.249.47.12:2332");
$hq->getTeamScore();
$hq->getPlayers();
// add any number of processing methods here
Furthermore, my API correctly parses the team score (ignores the one sent by the server). Try it with this IP address, http://bot.haloindex.com/query/74.91.119.188:2306
You can see in BTCC's team score API, it says "score_t0: 0", while mine shows the correct team score.
If you would want to be doing multiple calls then your approach makes sense, I see it from a standpoint of separating the calls, in case you want to have a list of servers, and have predefined ip/port and want to just grab server name, or players in server etc for a widget.
How did you get your htaccess to allow colon? You are doing a rewrite correct?
souless
December 29th, 2012, 12:06 PM
@BTCC, The player's "score" in a CTF game is the number of flags captured anyways. So this works completely fine in a normal CTF game as well as this modded Zombies gametype.
There are no exceptions here, just a generic sum of player scores - which works for all gametypes. You may think its an exception because of the one example I gave you. I'm focusing on making the Halo Server Queries easier to use and read, so future developers don't have to jump through hoops just to understand the raw data.
souless
December 29th, 2012, 12:09 PM
If you would want to be doing multiple calls then your approach makes sense, I see it from a standpoint of separating the calls, in case you want to have a list of servers, and have predefined ip/port and want to just grab server name, or players in server etc for a widget.
How did you get your htaccess to allow colon? You are doing a rewrite correct?
This is written in Node.js - I do not use Apache, PHP or Mysql.
I don't see the advantage of having separate calls, which all do the same thing except for parse the data differently. From an API standpoint, you should try to cover as many use-cases without sacrificing usability. It's just my recommendation that you use a class to initialize the UDP data, then use separate functions to returned the parsed data as needed. Take it or leave it, I wish you luck in your project.
Limited
December 29th, 2012, 12:21 PM
This is written in Node.js - I do not use Apache, PHP or Mysql.
Don't you use PHP to parse the URL given?
I don't see the advantage of having separate calls, which all do the same thing except for parse the data differently. From an API standpoint, you should try to cover as many use-cases without sacrificing usability. It's just my recommendation that you use a class to initialize the UDP data, then use separate functions to returned the parsed data as needed. Take it or leave it, I wish you luck in your project.
I suppose your right, if you wanted to combine multiple servers you'd just have an object variable for each server. Maybe I should go down that root.
I did want to keep all the parsing server-side, in case I want to parse the JSON differently, or perhaps the json returned gets updated, if all the parsing/selecting of elements is done on the 'client-side files', theres no way of updating that easily, without the user having to redownload the API files.
souless
December 29th, 2012, 12:53 PM
Don't you use PHP to parse the URL given?.NodeJS replaces the web server and application language (and to come extent, the database as well). Please look at the source code on Github, there is no PHP required to make my service.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.