...
 
Commits (4)
......@@ -568,7 +568,10 @@ module.exports = {
setPassword: async function (config) {
let keys = Object.keys(config);
let username = keys[0];
let username = keys[0]
.split('_')
.join(' ');
let hashedPassword = keys[1];
await io.setAsync({
......
......@@ -7,3 +7,4 @@ global.leaderboard = require('./leaderboard/leaderboard');
global.clientConfig = require('./config/clientConfig');
global.consts = require('./config/consts');
global.perf = require('./misc/perflog');
const fs = require('fs');
const ticksPerLog = 171;
let ticksLeft = ticksPerLog;
let logCount = 0;
let fileName = null;
let stats = {};
let lastId = 0;
let timers = {};
const reset = () => {
lastId = 0;
timers = {};
stats = {
components: {},
modules: {}
};
ticksLeft = ticksPerLog;
};
const log = (isModule, name, id) => {
const timerKey = `${name}-${id || ++lastId}`;
if (!id) {
timers[timerKey] = +new Date();
return log.bind(this, isModule, name, lastId);
}
const obj = isModule ? stats.modules : stats.components;
let statKey = obj[name];
if (!statKey) {
statKey = obj[name] = {
time: 0,
count: 0
};
}
statKey.time += (+new Date()) - timers[timerKey];
statKey.count++;
};
const serializeStats = obj => {
return Object.entries(obj)
.map(([k, v]) => {
return ~~(v.time / ticksPerLog);
})
.join('\t');
};
const persist = () => {
['modules', 'components'].forEach(o => {
let obj = stats[o];
let res = '';
if (!logCount)
res += Object.keys(obj).join('\t') + '\r\n';
res += serializeStats(obj) + '\r\n';
fs.appendFile(`../../data/${fileName}_${o}.log`, res, () => {});
});
logCount++;
};
module.exports = {
init: useZone => {
const day = new Date();
fileName = `${useZone}_${day.getMonth()}_${day.getDay()}_${day.getHours()}_${day.getMinutes()}`;
reset();
},
logModule: name => {
return log(true, name);
},
logComponent: name => {
return log(false, name);
},
tick: function () {
ticksLeft--;
if (!ticksLeft) {
persist();
reset();
}
}
};
......@@ -67,13 +67,18 @@ module.exports = {
len--;
i--;
} else if (c.update) {
const timer = perf.logComponent(c.type);
if (c.update())
usedTurn = true;
timer();
}
}
if (!usedTurn)
if (!usedTurn) {
const timer = perf.logModule('performQueue');
this.performQueue();
timer();
}
},
getSimple: function (self, isSave, isTransfer) {
......
......@@ -65,16 +65,21 @@ module.exports = {
[resourceSpawner, syncer, objects, questBuilder, events, mail].forEach(i => i.init(fakeInstance));
perf.init(args.name);
this.tick();
},
tick: function () {
events.update();
objects.update();
resourceSpawner.update();
spawners.update();
syncer.update();
scheduler.update();
const moduleNames = ['events', 'objects', 'resourceSpawner', 'spawners', 'syncer', 'scheduler'];
[events, objects, resourceSpawner, spawners, syncer, scheduler].forEach((m, i) => {
const moduleName = moduleNames[i];
const timer = perf.logModule(moduleName);
m.update();
timer();
});
perf.tick();
setTimeout(this.tick.bind(this), this.speed);
},
......
......@@ -3,6 +3,7 @@ global.io = require('../security/io');
global._ = require('../misc/helpers');
global.consts = require('../config/consts');
global.instancer = require('./instancer');
global.perf = require('../misc/perflog');
let components = require('../components/components');
let mods = require('../misc/mods');
......