Update character.js

This commit is contained in:
Kaan Soral
2020-06-24 22:07:33 +03:00
committed by GitHub
parent 0a1f820faa
commit ee5a54f4a4
+14 -9
View File
@@ -5,8 +5,7 @@ if(!workerData) // for chrome://inspect with "node --expose-gc --inspect charact
"name":"Wizard", "name":"Wizard",
"region":"EU", "region":"EU",
"server":"I", "server":"I",
"code":"PhoenixHunter", "code":"cli_tests",
// "code":"Performance Tests",
"auth":"5818821692620800-gjxqztPovvpiaKTGnjEtT", "auth":"5818821692620800-gjxqztPovvpiaKTGnjEtT",
}; };
parentPort={postMessage:function(){},on:function(){}}; parentPort={postMessage:function(){},on:function(){}};
@@ -18,7 +17,7 @@ if(!workerData) // for chrome://inspect with "node --expose-gc --inspect charact
console.log(workerData.name); console.log(workerData.name);
global.gc(); global.gc();
var jsdom,request; var jsdom,request,localstorager,localStorage=null;
try{ try{
jsdom=require("jsdom"); jsdom=require("jsdom");
}catch(e){ }catch(e){
@@ -32,11 +31,17 @@ try{
console.log("You need to run: npm install request"); console.log("You need to run: npm install request");
process.exit(); process.exit();
} }
try{
localstorager=require('node-localstorage').LocalStorage;
localStorage=new localstorager("./storage");
}catch(e){
console.log("You need to run: npm install node-localstorage for functioning localStorage support!");
}
var base_url="http://adventure.land"; var base_url="https://adventure.land";
var url=base_url+"/character/"+workerData.name+"/in/EU/I/?no_html=bot&is_bot=1&is_cli=1&code="+workerData.code+"&auth="+workerData.auth; var url=base_url+"/character/"+workerData.name+"/in/EU/I/?no_html=bot&is_bot=1&is_cli=1&code="+workerData.code+"&auth="+workerData.auth;
var dom=false; var dom=false,code_active=false;
request(url, (error, response, body) => { request(url, (error, response, body) => {
var virtualConsole=new jsdom.VirtualConsole(); var virtualConsole=new jsdom.VirtualConsole();
@@ -53,6 +58,8 @@ request(url, (error, response, body) => {
} }
dom=new JSDOM(body,options); dom=new JSDOM(body,options);
dom.name=workerData.name; dom.name=workerData.name;
if(localStorage && !dom.window.ls_emulation) dom.window.ls_emulation=localStorage;
dom.window.cli_require=require;
//console.log(dom.window.document.body.innerHTML); //console.log(dom.window.document.body.innerHTML);
}); });
@@ -78,13 +85,11 @@ setInterval(function(){
else parentPort.postMessage(m); else parentPort.postMessage(m);
}); });
dom.window.CLI_OUT=[]; dom.window.CLI_OUT=[];
if(!code_active && dom.window.code_active) code_active=true,parentPort.postMessage({"type":"code_active"});
},10); },10);
parentPort.on("message",function(data){ parentPort.on("message",function(data){
if(data.type=="smart_move") dom.window.CLI_IN.push(data);
{
dom.window.CLI_IN.push(data);
}
}); });
setInterval(function(){ setInterval(function(){