mirror of
https://github.com/gooba42/adventureland.git
synced 2026-10-14 18:39:27 -05:00
Update master.js
This commit is contained in:
+46
-37
@@ -5,33 +5,23 @@ const { Worker, SHARE_ENV } = require('worker_threads');
|
|||||||
// for global.gc();
|
// for global.gc();
|
||||||
var G=null;
|
var G=null;
|
||||||
var fs=require("fs");
|
var fs=require("fs");
|
||||||
eval(""+fs.readFileSync("common_functions.js")); // Manually copy/paste common_functions.js from libraries/ to this directory
|
eval(""+fs.readFileSync("../../js/common_functions.js")); // Manually copy/paste common_functions.js from libraries/ to this directory
|
||||||
eval(""+fs.readFileSync("functions.js"));
|
eval(""+fs.readFileSync("functions.js"));
|
||||||
|
|
||||||
var auth="5818821692620800-gjxqztPovvpiaKTGnjEtT"; // show_json(parent.Cookies.get("auth"))
|
var auth="5818821692620800-gjxqztPovvpiaKTGnjEtT"; // show_json(parent.Cookies.get("auth"))
|
||||||
var characters=[
|
var characters=[
|
||||||
{
|
{
|
||||||
"name":"Wizard",
|
"name":"GG",
|
||||||
"region":"EU",
|
"region":"EU",
|
||||||
"server":"I",
|
"server":"I",
|
||||||
"code":"PhoenixHunter",
|
"code":"local_cm_receiver",
|
||||||
//"code":"Performance Tests",
|
},
|
||||||
"run":false,
|
{
|
||||||
|
"name":"MERC",
|
||||||
|
"region":"EU",
|
||||||
|
"server":"I",
|
||||||
|
"code":"local_cm_sender",
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// "name":"Fun",
|
|
||||||
// "region":"EU",
|
|
||||||
// "server":"I",
|
|
||||||
// "code":"Phoenix Hunter",
|
|
||||||
// "run":false,
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "name":"Healer",
|
|
||||||
// "region":"EU",
|
|
||||||
// "server":"I",
|
|
||||||
// "code":"Phoenix Hunter",
|
|
||||||
// "run":false,
|
|
||||||
// }
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function run_character(workerData)
|
function run_character(workerData)
|
||||||
@@ -40,7 +30,7 @@ function run_character(workerData)
|
|||||||
const worker = new Worker('./character.js', { workerData:workerData, env: SHARE_ENV, execArgv:["expose-gc","inspect"]});
|
const worker = new Worker('./character.js', { workerData:workerData, env: SHARE_ENV, execArgv:["expose-gc","inspect"]});
|
||||||
worker.on('message',function(data){
|
worker.on('message',function(data){
|
||||||
if(data.type=="update")
|
if(data.type=="update")
|
||||||
this.character.last_update=new Date();
|
worker.info.last_update=new Date();
|
||||||
else if(data.type=="smart_move")
|
else if(data.type=="smart_move")
|
||||||
{
|
{
|
||||||
G=data.G;
|
G=data.G;
|
||||||
@@ -58,15 +48,32 @@ function run_character(workerData)
|
|||||||
console.log(smart.plot);
|
console.log(smart.plot);
|
||||||
worker.postMessage({type:"smart_move",found:smart.found,plot:smart.plot});
|
worker.postMessage({type:"smart_move",found:smart.found,plot:smart.plot});
|
||||||
}
|
}
|
||||||
|
else if(data.type=="cm")
|
||||||
|
{
|
||||||
|
var sent=false;
|
||||||
|
characters.forEach(function(char_info){
|
||||||
|
if(char_info.run && char_info.name==data['to'])
|
||||||
|
{
|
||||||
|
char_info.worker.postMessage(data);
|
||||||
|
sent=true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!sent) console.log("[UNSENT CM] TO: "+data['to']);
|
||||||
|
}
|
||||||
|
else if(data.type=="code_active")
|
||||||
|
{
|
||||||
|
worker.info.code_active=true;
|
||||||
|
worker.postMessage({type:"hello","from":"master.js"});
|
||||||
|
}
|
||||||
else if(data.type=="kill") process.exit();
|
else if(data.type=="kill") process.exit();
|
||||||
});
|
});
|
||||||
worker.on('error',function(data){
|
worker.on('error',function(data){
|
||||||
console.log("[MASTER] "+this.character.name+" error: "+data);
|
console.log("[MASTER] "+worker.info.name+" error: "+data);
|
||||||
});
|
});
|
||||||
worker.on('exit',function(code){
|
worker.on('exit',function(code){
|
||||||
if (code !== 0)
|
if (code !== 0)
|
||||||
console.log("[MASTER] "+this.character.name+" stopped with code: "+code);
|
console.log("[MASTER] "+worker.info.name+" stopped with code: "+code);
|
||||||
worker.character.run=false;
|
worker.info.run=false;
|
||||||
});
|
});
|
||||||
return worker;
|
return worker;
|
||||||
}
|
}
|
||||||
@@ -75,28 +82,30 @@ setInterval(function(){
|
|||||||
|
|
||||||
var current=new Date(),delay=false;
|
var current=new Date(),delay=false;
|
||||||
|
|
||||||
characters.forEach(function(character){
|
characters.forEach(function(info){
|
||||||
if(character.run && (current-character.last_update)>40000)
|
if(info.run && (current-info.last_update)>40000)
|
||||||
{
|
{
|
||||||
console.log("[MASTER] Reloading "+character.name);
|
console.log("[MASTER] Reloading "+info.name);
|
||||||
character.run=false;
|
info.run=false;
|
||||||
character.worker.terminate();
|
info.code_active=false;
|
||||||
|
info.worker.terminate();
|
||||||
delay=true;
|
delay=true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(delay) return; // worker.on('exit') needs to fire first
|
if(delay) return; // worker.on('exit') needs to fire first
|
||||||
|
|
||||||
characters.forEach(function(character){
|
characters.forEach(function(info){
|
||||||
if(!character.run)
|
if(!info.run)
|
||||||
{
|
{
|
||||||
if(!character.auth) character.auth=auth;
|
if(!info.auth) info.auth=auth;
|
||||||
character.run=true;
|
info.run=true;
|
||||||
character.last_update=new Date();
|
info.code_active=false;
|
||||||
delete character.worker;
|
info.last_update=new Date();
|
||||||
var workerData={}; Object.assign(workerData,character);
|
delete info.worker;
|
||||||
character.worker=run_character(workerData);
|
var workerData={}; Object.assign(workerData,info);
|
||||||
character.worker.character=character;
|
info.worker=run_character(info);
|
||||||
|
info.worker.info=info;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user