Skip to content

Commit

Permalink
botguard: first pass at full implementation. fingers crossed...
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatkins committed Sep 15, 2014
1 parent bbbc349 commit 92aae95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions code/boot.js
Expand Up @@ -571,6 +571,7 @@ function boot() {
}});

window.extractFromStock();
window.iitc_bg.init(); //NOTE: needs to be early (before any requests sent), but after extractFromStock()
window.setupIdle();
window.setupTaphold();
window.setupStyles();
Expand Down
10 changes: 7 additions & 3 deletions code/botguard_interface.js
Expand Up @@ -40,7 +40,7 @@ iitc_bg.init = function() {
// B - a key(?). set in the main web page HTML, name isn't changed on site updates
// CS - initialisation data for botguard - again in the main page, again name is constant
// a list of method names to protect. varies on site updates (sometimes) - in window.niantic_params.botguard_protected_methods
// a (smaller) list of methods for group a - in window.niantic_params.botguard_group_methods
// a (smaller) list of methods for group a - in window.niantic_params.botguard_group_a_methods


var botguard_key = B;
Expand Down Expand Up @@ -111,9 +111,14 @@ iitc_bg.process_key = function(key,serverEval) {
// server wants us to eval some code! risky, and impossible to be certain we can do it safely
// however... reports say that it only interacts with the botguard.bg code, so we might be fine just running it
try {
console.warn('Server-generated javascript eval requested:\n'+serverExec);
debugger;
if (!confirm('The server asked IITC to run (eval) some javascript. This may or may not be safe. Run and continue?\n\nScript:\n'+serverEval)) { console.error('server javascript eval cancelled') } else
eval(serverEval);
console.log('Server-generated javascript ran OK');
} catch(e) {
console.warn('Server-generated javascript - threw an exception');
console.warn(e);
caught = true;
}
}
Expand All @@ -135,7 +140,7 @@ iitc_bg.get_method_group = function(method) {
// undefined for no group

if (window.niantic_params.botguard_protected_methods.indexOf(method) != -1) {
if (window.niantic_params.botguard_group_methods.indexOf(method) != -1) {
if (window.niantic_params.botguard_group_a_methods.indexOf(method) != -1) {
return "group-a-actions";
} else {
return "group-b-actions";
Expand Down Expand Up @@ -198,7 +203,6 @@ iitc_bg.get_request_data = function(method) {

iitc_bg.dummy_botguard = function() {};
iitc_bg.dummy_botguard.prototype.invoke = function(callback) {
debugger;
callback("dkxm");
};

Expand Down
10 changes: 8 additions & 2 deletions code/chat.js
Expand Up @@ -451,8 +451,14 @@ window.chat.toggle = function() {

window.chat.request = function() {
console.log('refreshing chat');
chat.requestFaction(false);
chat.requestPublic(false);
var tab = chat.getActive();
//TODO: add 'alerts' tab, and add the matching case in here
if (tab == 'faction') {
chat.requestFaction(false);
} else {
// the 'public', 'full' and 'compact' tabs are all based off the 'public' COMM data
chat.requestPublic(false);
}
}


Expand Down
10 changes: 5 additions & 5 deletions code/extract_niantic_parameters.js
Expand Up @@ -72,7 +72,7 @@ window.extractFromStock = function() {
// botguard group-a or group-b, while the others is just a list of those in one group

window.niantic_params.botguard_protected_methods = [];
window.niantic_params.botguard_group_methods = [];
window.niantic_params.botguard_group_a_methods = [];

var countMethods = function(arr) {
var methods = ['artifacts', 'getGameScore', 'getPlexts', 'getPortalDetails', 'redeemReward', 'sendInviteEmail', 'sendPlext'];
Expand All @@ -92,12 +92,12 @@ window.extractFromStock = function() {
var arr = arrays[i];
var arrCount = countMethods(arr);

// now store the longest in niantic_params.botguard_protected_methods, and 2nd longest in .niantic_params.botguard_group_methods
// now store the longest in niantic_params.botguard_protected_methods, and 2nd longest in .niantic_params.botguard_group_a_methods

if (arrCount > protectedMethodsCount) {
// longest found - copy any existing longest to the 2nd longest

window.niantic_params.botguard_group_methods = window.niantic_params.botguard_protected_methods;
window.niantic_params.botguard_group_a_methods = window.niantic_params.botguard_protected_methods;
groupMethodsCount = protectedMethodsCount;

//... and set the longest
Expand All @@ -106,14 +106,14 @@ window.extractFromStock = function() {

} else if (arrCount > groupMethodsCount) {
// 2nd longest - store
window.niantic_params.botguard_group_methods = arr;
window.niantic_params.botguard_group_a_methods = arr;
groupMethodsCount = arrCount;
}

}


if (niantic_params.CURRENT_VERSION === undefined || window.niantic_params.botguard_protected_methods.length == 0 || window.niantic_params.botguard_group_methods == 0) {
if (niantic_params.CURRENT_VERSION === undefined || window.niantic_params.botguard_protected_methods.length == 0 || window.niantic_params.botguard_group_a_methods == 0) {
dialog({
title: 'IITC Broken',
html: '<p>IITC failed to extract the required parameters from the intel site</p>'
Expand Down
3 changes: 2 additions & 1 deletion code/send_request.js
Expand Up @@ -34,6 +34,7 @@ window.postAjax = function(action, data, successCallback, errorCallback) {

var onSuccess = function(data, textStatus, jqXHR) {
window.requests.remove(jqXHR);
iitc_bg.process_response_params(action,data);

// the Niantic server can return a HTTP success, but the JSON response contains an error. handle that sensibly
if (data && data.error && data.error == 'out of date') {
Expand Down Expand Up @@ -64,7 +65,7 @@ window.postAjax = function(action, data, successCallback, errorCallback) {
}

var versionStr = niantic_params.CURRENT_VERSION;
var post_data = JSON.stringify($.extend({}, data, {v: versionStr, b: "", c: ""}));
var post_data = JSON.stringify($.extend({}, data, {v: versionStr}, iitc_bg.extra_request_params(action)));

var result = $.ajax({
url: '/r/'+action,
Expand Down

0 comments on commit 92aae95

Please sign in to comment.