botguard: first pass at full implementation. fingers crossed...
This commit is contained in:
		@@ -571,6 +571,7 @@ function boot() {
 | 
				
			|||||||
  }});
 | 
					  }});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  window.extractFromStock();
 | 
					  window.extractFromStock();
 | 
				
			||||||
 | 
					  window.iitc_bg.init(); //NOTE: needs to be early (before any requests sent), but after extractFromStock()
 | 
				
			||||||
  window.setupIdle();
 | 
					  window.setupIdle();
 | 
				
			||||||
  window.setupTaphold();
 | 
					  window.setupTaphold();
 | 
				
			||||||
  window.setupStyles();
 | 
					  window.setupStyles();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					  // 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
 | 
					  // 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 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;
 | 
					  var botguard_key = B;
 | 
				
			||||||
@@ -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
 | 
					      // 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
 | 
					      // however... reports say that it only interacts with the botguard.bg code, so we might be fine just running it
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
 | 
					        console.warn('Server-generated javascript eval requested:\n'+serverExec);
 | 
				
			||||||
debugger;
 | 
					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);
 | 
					        eval(serverEval);
 | 
				
			||||||
 | 
					console.log('Server-generated javascript ran OK');
 | 
				
			||||||
      } catch(e) {
 | 
					      } catch(e) {
 | 
				
			||||||
 | 
					console.warn('Server-generated javascript - threw an exception');
 | 
				
			||||||
 | 
					console.warn(e);
 | 
				
			||||||
        caught = true;
 | 
					        caught = true;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -135,7 +140,7 @@ iitc_bg.get_method_group = function(method) {
 | 
				
			|||||||
// undefined for no group
 | 
					// undefined for no group
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (window.niantic_params.botguard_protected_methods.indexOf(method) != -1) {
 | 
					  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";
 | 
					      return "group-a-actions";
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      return "group-b-actions";
 | 
					      return "group-b-actions";
 | 
				
			||||||
@@ -198,7 +203,6 @@ iitc_bg.get_request_data = function(method) {
 | 
				
			|||||||
  
 | 
					  
 | 
				
			||||||
iitc_bg.dummy_botguard = function() {};
 | 
					iitc_bg.dummy_botguard = function() {};
 | 
				
			||||||
iitc_bg.dummy_botguard.prototype.invoke = function(callback) {
 | 
					iitc_bg.dummy_botguard.prototype.invoke = function(callback) {
 | 
				
			||||||
debugger;
 | 
					 | 
				
			||||||
  callback("dkxm");
 | 
					  callback("dkxm");
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -451,8 +451,14 @@ window.chat.toggle = function() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
window.chat.request = function() {
 | 
					window.chat.request = function() {
 | 
				
			||||||
  console.log('refreshing chat');
 | 
					  console.log('refreshing chat');
 | 
				
			||||||
 | 
					  var tab = chat.getActive();
 | 
				
			||||||
 | 
					//TODO: add 'alerts' tab, and add the matching case in here
 | 
				
			||||||
 | 
					  if (tab == 'faction') {
 | 
				
			||||||
    chat.requestFaction(false);
 | 
					    chat.requestFaction(false);
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    // the 'public', 'full' and 'compact' tabs are all based off the 'public' COMM data
 | 
				
			||||||
    chat.requestPublic(false);
 | 
					    chat.requestPublic(false);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					  // 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_protected_methods = [];
 | 
				
			||||||
  window.niantic_params.botguard_group_methods = [];
 | 
					  window.niantic_params.botguard_group_a_methods = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var countMethods = function(arr) {
 | 
					  var countMethods = function(arr) {
 | 
				
			||||||
    var methods = ['artifacts', 'getGameScore', 'getPlexts', 'getPortalDetails', 'redeemReward', 'sendInviteEmail', 'sendPlext'];
 | 
					    var methods = ['artifacts', 'getGameScore', 'getPlexts', 'getPortalDetails', 'redeemReward', 'sendInviteEmail', 'sendPlext'];
 | 
				
			||||||
@@ -92,12 +92,12 @@ window.extractFromStock = function() {
 | 
				
			|||||||
    var arr = arrays[i];
 | 
					    var arr = arrays[i];
 | 
				
			||||||
    var arrCount = countMethods(arr);
 | 
					    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) {
 | 
					    if (arrCount > protectedMethodsCount) {
 | 
				
			||||||
      // longest found - copy any existing longest to the 2nd longest
 | 
					      // 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;
 | 
					      groupMethodsCount = protectedMethodsCount;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      //... and set the longest
 | 
					      //... and set the longest
 | 
				
			||||||
@@ -106,14 +106,14 @@ window.extractFromStock = function() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    } else if (arrCount > groupMethodsCount) {
 | 
					    } else if (arrCount > groupMethodsCount) {
 | 
				
			||||||
      // 2nd longest - store
 | 
					      // 2nd longest - store
 | 
				
			||||||
      window.niantic_params.botguard_group_methods = arr;
 | 
					      window.niantic_params.botguard_group_a_methods = arr;
 | 
				
			||||||
      groupMethodsCount = arrCount;
 | 
					      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({
 | 
					    dialog({
 | 
				
			||||||
      title: 'IITC Broken',
 | 
					      title: 'IITC Broken',
 | 
				
			||||||
      html: '<p>IITC failed to extract the required parameters from the intel site</p>'
 | 
					      html: '<p>IITC failed to extract the required parameters from the intel site</p>'
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,6 +34,7 @@ window.postAjax = function(action, data, successCallback, errorCallback) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  var onSuccess = function(data, textStatus, jqXHR) {
 | 
					  var onSuccess = function(data, textStatus, jqXHR) {
 | 
				
			||||||
    window.requests.remove(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
 | 
					    // 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') {
 | 
					    if (data && data.error && data.error == 'out of date') {
 | 
				
			||||||
@@ -64,7 +65,7 @@ window.postAjax = function(action, data, successCallback, errorCallback) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var versionStr = niantic_params.CURRENT_VERSION;
 | 
					  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({
 | 
					  var result = $.ajax({
 | 
				
			||||||
    url: '/r/'+action,
 | 
					    url: '/r/'+action,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user