Skip to content

Commit

Permalink
Improved command sending and errors management
Browse files Browse the repository at this point in the history
  • Loading branch information
Rauks authored Feb 27, 2017
1 parent cb5e975 commit 56b71e0
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,19 +757,35 @@ function sendCommand(command){
}
logMsg(command, ">", "success");
$.post("rcon/index.php", { cmd: command })
.done(function( data ){
if(data.indexOf("Unknown command") != -1){
alertDanger("Unknown command.");
logDanger(data);
return;
.done(function(json){
if(json.status){
if(json.status == 'success' && json.response && json.command){
if(json.response.indexOf("Unknown command") != -1){
alertDanger("Unknown command : " + json.command);
logDanger(json.response);
}
else if(json.response.indexOf("Usage") != -1){
alertWarning(json.response);
logWarning(json.response);
}
else{
alertSuccess("Send success.");
logInfo(json.response);
}
}
else if(json.status == 'error' && json.error){
alertDanger(json.error);
logDanger(json.error);
}
else{
alertDanger("Malformed RCON api response");
logDanger("Malformed RCON api response");
}
}
else if(data.indexOf("Usage") != -1){
alertWarning(data);
logWarning(data);
return;
else{
alertDanger("RCON api error (no status returned)");
logDanger("RCON api error (no status returned)");
}
alertSuccess("Send success.");
logInfo(data);
})
.fail(function() {
alertDanger("RCON error.");
Expand Down

0 comments on commit 56b71e0

Please sign in to comment.