// ==UserScript==
// @name KocMapper
// @namespace KocMapper
// @include http://*.gloryofrome.com/src/gameChrome_src.php*
// @include https://*.gloryofrome.com/src/gameChrome_src.php*
// @include http://*.ryrome.com/src/gameChrome_src.php*
// @include https://*.ryrome.com/src/gameChrome_src.php*
// @include http://*.kingdomsofcamelot.com/*/main_src.php*
// @include https://*.kingdomsofcamelot.com/*/main_src.php*
// @include http://*.rycamelot.com/*/main_src.php*
// @include https://*.rycamelot.com/*/main_src.php*
// @include http://*.castle.wonderhill.com/platforms/facebook/game
// @include https://*.castle.wonderhill.com/platforms/facebook/game
// @include https://*.castle.wonderhill.com/platforms/kabam/game
// @include https://*.godfather.wonderhill.com/platforms/kabam/game
// @include https://*.godfather.rykaiju.com/platforms/kabam/game
// @include https://*.godfather.rykaiju.com/platforms/facebook/game
// @include https://castle.rykaiju.com/*
// @include https://*.castle.rykaiju.com/platforms/plinga/game*
// @include http://*.castle.rykaiju.com/platforms/plinga/game*
// @include https://*.castle.rykaiju.com/platforms/kabam/game
// @include https://*.castle.rykaiju.com/platforms/facebook/game*
// @include https://*.googleusercontent.com/gadgets/ifr?url=app://659749063556/game*
// @include https://*.googleusercontent.com/gadgets/ifr?url=app://216622099218/game*
// @include https://*.googleusercontent.com/gadgets/ifr?url=app://49807058318/game*
// @connect secure.weezeewig.com
// @updateURL https://secure.weezeewig.com/koc/kocmapper.meta.js
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @version 1.0.0.20181002
// ==/UserScript==
// @include http://*.globalwarfaregame.com/src/main_src.php*
// @include https://*.globalwarfaregame.com/src/main_src.php*
// @include https://www.thirstofnight.com/platforms/kabam/game*
//
// http://www.gioco.it/gioco/dragons-of-atlantis
// http://realm357.c10.castle.rykaiju.com/platforms/plinga/game?userid=2587067&sessionid=ba54b0fb6b3a75debf05dfc5a9880336&sessionkey=1449786787&platform=spielen.com&lang=it&locale=it&i18n_locale=it&platformSPIL=gioco.it&xdm_e=http%3A%2F%2Fwww.gioco.it&xdm_c=default6115&xdm_p=1
///////////////////////////////////////////////////////////////////////////////
GM_log = function (message) {
console.log(message);
};
try {
var hasGetValue=false;
try {
GM_getValue("test");
hasGetValue=true;
} catch(e) {
}
if (window.chrome && !hasGetValue) {
GM_setValue = function (n,v) {
localStorage.setItem(n,v);
};
GM_getValue = function (n,v) {
var newv=localStorage.getItem(n);
// Stupid getItem/setItem problem.
// If you setItem to null. The next getItem will be a string of 'null'
if(newv=='null' || newv==null || newv===undefined) { newv=v; }
return newv;
};
GM_deleteValue = function (n) {
localStorage.remove(n);
};
GM_xmlhttpRequest=function(o) {
var req=new XMLHttpRequest();
req.onreadystatechange=function() {
if(req.readyState==4) {
if(req.status==200)
o.onload(req);
else o.onerror(req);
}
};
req.open(o.method,o.url,true);
for(var n in o.headers) {
req.setRequestHeader(n,o.headers[n]);
}
req.send(o.data);
};
}
} catch(e) { }
var GetQuery=function() {
var div=document.getElementById('castlemania_swf_container');
if(!div) {
GM_log('Cannot find swf container:'+location.href);
return false;
}
var params=div.getElementsByTagName('param');
var v='';
for(var p=0; p
//
//
Setup:function() {
var q=GetQuery();
var attrs=this.GetCAttrs();
this.apiServer=q['api_server'] || attrs.apiServer;
var m=/realm([0-9]+)/.exec(this.apiServer);
if(!m) {
GM_log('api server has no realm:'+this.apiServer);
}
this.serverId=m[1];
},
GetCAttrs:function() {
var attrs={};
document.body.innerHTML.replace(/C\.attrs\.(\S+)\s*=\s*([^;]+);/g,function(m,m1,m2) {
m2=m2.replace(/^["']/,'').replace(/["']$/,'');
attrs[m1]=m2;
});
return attrs;
},
GetSignedRequest:function(gameName,endFunc) {
var q=GetQuery();
var attrs=this.GetCAttrs();
//console.log('q'+JSON.stringify(q));
//console.log('attrs'+JSON.stringify(attrs));
endFunc({
'tvuid':1,
'fbuid':q['facebook_id'] || attrs.facebookId,
'kabamuid':q['user_id'] || attrs.userId,
// *** kabamNaid
'tpuid':q['user_hash'], // not found
'signed_request':q['dragon_heart'] || attrs.dragonHeart,
'api_server':q['api_server'],
cookie:JSON.stringify(attrs),
'kraken_session':q['session_id'] || attrs.sessionId
});
},
GetServerId:function() {
if(!this.apiServer) {
this.Setup();
}
return this.serverId;
}
};
var KabamMapper={
//version:"20101123",
version:"20110804",
urlPrefix:'http://koc.weezeewig.com/index.sjs',
gameName:null,
game:null,
SetGameName:function(gameName) {
this.gameName=gameName;
// this.urlPrefix='http://'+gameName+'.map.weezeewig.com/index.sjs';
// Chrome needs a secure url
this.urlPrefix='https://secure.weezeewig.com/index.sjs';
},
DetectGameName:function() {
if(location.href.indexOf('.thirstofnight.com')>=0) {
this.SetGameName('thirst');
this.game=Thirst;
} else if(location.href.indexOf('.godfather.')>=0 || location.search.indexOf('49807058318/game')>=0) {
this.SetGameName('godfather');
this.game=GodFather;
} else if(location.href.indexOf('.kingdomsofcamelot.')>=0 || location.href.indexOf('.rycamelot.')>=0) {
this.SetGameName('koc');
this.game=Koc;
} else if(location.href.indexOf('.globalwarfaregame.')>=0 || location.search.indexOf('216622099218/game')>=0) {
this.SetGameName('globalwarfare');
this.game=Koc;
} else if(location.href.indexOf('.gloryofrome.')>=0 || location.href.indexOf('.ryrome.')>=0) {
this.SetGameName('gloryofrome');
this.game=Koc;
} else if(location.href.indexOf('/castle.')>=0 || location.href.indexOf('.castle.')>=0 || location.search.indexOf('659749063556/game')>=0) {
this.SetGameName('doa');
this.game=DragonsOfAtlantis;
} else {
GM_log('Failed to detect game name:'+location.href);
return false;
}
this.server_id=this.game.GetServerId();
if(this.server_id==='' || this.server_id===null) {
GM_log("Cannot find server id:"+location.href);
return false;
}
return true;
},
SendSignedRequest:function(endFunc) {
var t=this;
t.game.GetSignedRequest(t.gameName,function(s) {
var client_id;
if(typeof(GM_deleteValue)!='undefined') {
client_id=GM_getValue('ClientId',parseInt(Math.random()*100000000,10));
GM_setValue('ClientId',client_id);
} else {
client_id=s.kabamuid;
}
var postData='server_id='+t.server_id+
'&game='+t.gameName+
'&client_id='+client_id+
'&version='+t.version+
'&tvuid='+escape(s['tvuid'])+
'&fbuid='+escape(s['fbuid'])+
'&kabamuid='+escape(s['kabamuid'])+
'&tpuid='+escape(s['tpuid'])+
'&kraken_session='+escape(s['kraken_session'])+
'&signed_request='+escape(s['signed_request'])+
(s.realms===undefined?'':'&realms='+escape(s['realms']) )+
'&cookie='+escape(s['cookie'])+
((s['api_server']!=="" && s['api_server']!==undefined)? ('&api_server='+escape(s['api_server'])) :"" );
GM_xmlhttpRequest({
'url':t.urlPrefix+'?f=UpdateSignedRequest',
method: 'POST',
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: postData,
onload: function(r) {
var res;
try {
res=JSON.parse(r.responseText);
if(t.version!=res.version) {
window.alert("You don't have the latest version of the mapper");
GM_openInTab('https://secure.weezeewig.com/koc/kocmapper.user.js');
} else { endFunc(true); }
} catch(e) {
GM_log('Error could not get map_time_id:'+r.responseText);
window.alert('Error:'+r.responseText+','+e);
return;
}
},
onerror:function() {
var mess='Could not contact server:'+t.urlPrefix;
GM_log(mess);
window.alert(mess);
}
});
});
},
RunMapper:function() {
var yesterdaySecs=parseInt( (new Date().getTime()/1000)-this.game.MinSecsSinceLastUpdate() ,10);
if(!this.DetectGameName()) { return; }
var nameId=this.gameName+this.server_id;
var lastMapperUpdate;
lastMapperUpdate=parseInt(GM_getValue('lastMapperUpdate_'+nameId,0),10);
// lastMapperUpdate=0; //uncomment this to force it to update anyways
//console.log('aaa'+lastMapperUpdate+','+yesterdaySecs);
if(this.game.alwaysUpdate || lastMapperUpdate