quake-live-api
Version:
Quake Live API library
103 lines (88 loc) • 3.39 kB
JavaScript
// Generated by CoffeeScript 1.4.0
(function() {
var Match, Player, request;
request = require('request');
exports.Player = Player = (function() {
function Player() {}
return Player;
})();
exports.Match = Match = (function() {
Match.fromMatchList = function(matchList) {
var matchPayload, _i, _len, _ref, _results;
_ref = matchList.servers;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
matchPayload = _ref[_i];
_results.push(new Match(matchPayload));
}
return _results;
};
Match.fetch = function(options, callback) {
var encodedOptions, _ref, _ref1, _ref2, _ref3, _ref4;
if ((_ref = options.arena_type) == null) {
options.arena_type = "";
}
if ((_ref1 = options.players) == null) {
options.players = [];
}
if ((_ref2 = options.filters) == null) {
options.filters = {
"arena": "any",
"difficulty": "any",
"game_type": "any",
"group": "any",
"invitation_only": 0,
"location": "ALL",
"premium_only": 0,
"private": 0,
"ranked": "any",
"state": "any"
};
}
if ((_ref3 = options.game_types) == null) {
options.game_types = [];
}
if ((_ref4 = options.ig) == null) {
options.ig = 0;
}
if (options.players.length > 0) {
options.filters.group = "friends";
}
console.log(options);
encodedOptions = Buffer(JSON.stringify(options)).toString('base64');
return request.get("http://www.quakelive.com/browser/list?filter=" + encodedOptions, function(error, response, body) {
var match, matches, matches_json, _i, _len;
matches_json = JSON.parse(body);
matches = Match.fromMatchList(matches_json);
for (_i = 0, _len = matches.length; _i < _len; _i++) {
match = matches[_i];
console.log(match.toString());
}
return callback(matches);
});
};
function Match(_arg) {
var player;
this.public_id = _arg.public_id, this.g_customSettings = _arg.g_customSettings, this.g_instagib = _arg.g_instagib, this.g_needpass = _arg.g_needpass, this.game_type = _arg.game_type, this.host_address = _arg.host_address, this.host_name = _arg.host_name, this.location_id = _arg.location_id, this.map = _arg.map, this.max_clients = _arg.max_clients, this.num_clients = _arg.num_clients, this.num_players = _arg.num_players, this.premium = _arg.premium, this.ranked = _arg.ranked, this.ruleset = _arg.ruleset, this.skillDelta = _arg.skillDelta, this.teamsize = _arg.teamsize, this.players = _arg.players;
if (this.players) {
this.players = (function() {
var _i, _len, _ref, _results;
_ref = this.players;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
player = _ref[_i];
_results.push(player.name);
}
return _results;
}).call(this);
}
}
Match.prototype.joinUrl = function() {
return "http://www.quakelive.com/#!join/" + this.public_id;
};
Match.prototype.toString = function() {
return "Match (" + this.num_clients + "/" + this.max_clients + ") @ " + this.host_name;
};
return Match;
})();
}).call(this);