Merge error and fatal

This commit is contained in:
Michael Morrison 2014-02-02 05:58:36 -06:00
parent e857eb1b47
commit 9ebb95c69d
7 changed files with 17 additions and 20 deletions

View file

@ -12,7 +12,7 @@ module.exports = require('./protocols/core').extend({
uri: 'http://'+this.options.address+':'+this.options.port+'/', uri: 'http://'+this.options.address+':'+this.options.port+'/',
timeout: 3000, timeout: 3000,
}, function(e,r,body) { }, function(e,r,body) {
if(e) return self.error('HTTP error'); if(e) return self.fatal('HTTP error');
var m = body.match(/status server for (.*?)\r|\n/); var m = body.match(/status server for (.*?)\r|\n/);
if(m) state.name = m[1]; if(m) state.name = m[1];

View file

@ -12,7 +12,7 @@ module.exports = require('./protocols/core').extend({
uri: 'http://mutantfactions.net/game/receiveLobby.php', uri: 'http://mutantfactions.net/game/receiveLobby.php',
timeout: 3000, timeout: 3000,
}, function(e,r,body) { }, function(e,r,body) {
if(e) return self.error('Lobby request error'); if(e) return self.fatal('Lobby request error');
var split = body.split('<br/>'); var split = body.split('<br/>');

View file

@ -22,11 +22,8 @@ module.exports = Class.extend(EventEmitter,{
},10000); },10000);
}, },
fatal: function(err) { fatal: function(err,noretry) {
this.error(err,true); if(!noretry && this.attempt < this.maxAttempts) {
},
error: function(err,fatal) {
if(!fatal && this.attempt < this.maxAttempts) {
this.attempt++; this.attempt++;
this.start(); this.start();
return; return;
@ -115,7 +112,7 @@ module.exports = Class.extend(EventEmitter,{
function resolveStandard(host,c) { function resolveStandard(host,c) {
dns.lookup(host, function(err,address,family) { dns.lookup(host, function(err,address,family) {
if(err) return self.error(err); if(err) return self.fatal(err);
self.options.address = address; self.options.address = address;
c(); c();
}); });
@ -248,10 +245,10 @@ module.exports = Class.extend(EventEmitter,{
}); });
if(!ondata) return; if(!ondata) return;
//self.tcpTimeoutTimer = self.setTimeout(function() { self.tcpTimeoutTimer = self.setTimeout(function() {
// self.tcpCallback = false; self.tcpCallback = false;
// self.error('timeout'); self.fatal('TCP Watchdog Timeout');
//},1000); },1000);
self.tcpCallback = ondata; self.tcpCallback = ondata;
}); });
}, },
@ -269,7 +266,7 @@ module.exports = Class.extend(EventEmitter,{
self.udpCallback = false; self.udpCallback = false;
var timeout = false; var timeout = false;
if(!ontimeout || ontimeout() !== true) timeout = true; if(!ontimeout || ontimeout() !== true) timeout = true;
if(timeout) self.error('timeout'); if(timeout) self.fatal('UDP Watchdog Timeout');
},1000); },1000);
self.udpCallback = onpacket; self.udpCallback = onpacket;
}); });

View file

@ -151,7 +151,7 @@ module.exports = require('./core').extend({
var list = []; var list = [];
for(var i = 0; i < numPackets; i++) { for(var i = 0; i < numPackets; i++) {
if(!(i in packets)) { if(!(i in packets)) {
self.error('Missing packet #'+i); self.fatal('Missing packet #'+i);
return true; return true;
} }
list.push(packets[i]); list.push(packets[i]);

View file

@ -34,13 +34,13 @@ module.exports = require('./core').extend({
if(cmd == 'Connect') { if(cmd == 'Connect') {
var client = self.gbxclient = gbxremote.createClient(self.options.port,self.options.host, function(err) { var client = self.gbxclient = gbxremote.createClient(self.options.port,self.options.host, function(err) {
if(err) return self.error('GBX error '+JSON.stringify(err)); if(err) return self.fatal('GBX error '+JSON.stringify(err));
c(); c();
}); });
client.on('error',function(){}); client.on('error',function(){});
} else { } else {
self.gbxclient.methodCall(cmd, params, function(err, value) { self.gbxclient.methodCall(cmd, params, function(err, value) {
if(err) return self.error('XMLRPC error '+JSON.stringify(err)); if(err) return self.fatal('XMLRPC error '+JSON.stringify(err));
results.push(value); results.push(value);
c(); c();
}); });

View file

@ -240,7 +240,7 @@ module.exports = require('./core').extend({
var list = []; var list = [];
for(var i = 0; i < numPackets; i++) { for(var i = 0; i < numPackets; i++) {
if(!(i in packets)) { if(!(i in packets)) {
self.error('Missing packet #'+i); self.fatal('Missing packet #'+i);
return true; return true;
} }
list.push(packets[i]); list.push(packets[i]);

View file

@ -16,15 +16,15 @@ module.exports = require('./protocols/core').extend({
token: this.options.token token: this.options.token
} }
}, function(e,r,body) { }, function(e,r,body) {
if(e) return self.error('HTTP error'); if(e) return self.fatal('HTTP error');
var json; var json;
try { try {
json = JSON.parse(body); json = JSON.parse(body);
} catch(e) { } catch(e) {
return self.error('Invalid JSON'); return self.fatal('Invalid JSON');
} }
if(json.status != 200) return self.error('Invalid status'); if(json.status != 200) return self.fatal('Invalid status');
json.players.forEach(function(one) { json.players.forEach(function(one) {
state.players.push({name:one.nickname,team:one.team}); state.players.push({name:one.nickname,team:one.team});