@@ -425,6 +425,7 @@ module.exports = { | |||||
msg.callback(); | msg.callback(); | ||||
}, | }, | ||||
/* eslint-disable-next-line max-lines-per-function */ | |||||
createCharacter: async function (msg) { | createCharacter: async function (msg) { | ||||
let data = msg.data; | let data = msg.data; | ||||
let name = data.name; | let name = data.name; | ||||
@@ -458,8 +459,14 @@ module.exports = { | |||||
return; | return; | ||||
} | } | ||||
console.log('Starting new character create for', name); | |||||
const t1 = +new Date(); | |||||
const releaseCreateLock = await getCreateLock(); | const releaseCreateLock = await getCreateLock(); | ||||
const t2 = +new Date(); | |||||
console.log('Took', t2 - t1, 'ms to get a create lock'); | |||||
let exists = await io.getAsync({ | let exists = await io.getAsync({ | ||||
key: name, | key: name, | ||||
ignoreCase: true, | ignoreCase: true, | ||||
@@ -467,6 +474,9 @@ module.exports = { | |||||
noDefault: true | noDefault: true | ||||
}); | }); | ||||
const t3 = +new Date(); | |||||
console.log('Took', t3 - t2, 'ms to check if the character exists'); | |||||
if (exists) { | if (exists) { | ||||
releaseCreateLock(); | releaseCreateLock(); | ||||
msg.callback(messages.login.charExists); | msg.callback(messages.login.charExists); | ||||
@@ -488,7 +498,13 @@ module.exports = { | |||||
let simple = this.obj.getSimple(true); | let simple = this.obj.getSimple(true); | ||||
const t4 = +new Date(); | |||||
console.log('Took', t4 - t3, 'ms to build the simpleObj'); | |||||
await this.verifySkin(simple); | await this.verifySkin(simple); | ||||
const t5 = +new Date(); | |||||
console.log('Took', t5 - t4, 'ms to verify the skin'); | |||||
let prophecies = (data.prophecies || []).filter(p => p); | let prophecies = (data.prophecies || []).filter(p => p); | ||||
@@ -507,6 +523,9 @@ module.exports = { | |||||
eventEmitter.emit('beforeSaveCharacter', eBeforeSaveCharacter); | eventEmitter.emit('beforeSaveCharacter', eBeforeSaveCharacter); | ||||
const t6 = +new Date(); | |||||
console.log('Took', t6 - t5, 'ms to run beforeSaveCharacter'); | |||||
await io.setAsync({ | await io.setAsync({ | ||||
key: name, | key: name, | ||||
table: 'character', | table: 'character', | ||||
@@ -516,6 +535,9 @@ module.exports = { | |||||
this.characters[name] = simple; | this.characters[name] = simple; | ||||
this.characterList.push(name); | this.characterList.push(name); | ||||
const t7 = +new Date(); | |||||
console.log('Took', t7 - t6, 'ms to save the character'); | |||||
await io.setAsync({ | await io.setAsync({ | ||||
key: this.username, | key: this.username, | ||||
@@ -524,6 +546,9 @@ module.exports = { | |||||
serialize: true | serialize: true | ||||
}); | }); | ||||
const t8 = +new Date(); | |||||
console.log('Took', t8 - t7, 'ms to save the character list'); | |||||
releaseCreateLock(); | releaseCreateLock(); | ||||
this.initTracker(); | this.initTracker(); | ||||
@@ -137,7 +137,16 @@ module.exports = { | |||||
}) | }) | ||||
.run(); | .run(); | ||||
} catch (e) { | } catch (e) { | ||||
this.logError(e, table, id); | |||||
this.logError({ | |||||
sourceModule: 'ioRethink', | |||||
sourceMethod: 'setAsync', | |||||
error: e, | |||||
info: { | |||||
table, | |||||
key: id, | |||||
value: JSON.stringify(value) | |||||
} | |||||
}); | |||||
} | } | ||||
}, | }, | ||||
@@ -151,7 +160,15 @@ module.exports = { | |||||
.insert(value, { conflict }) | .insert(value, { conflict }) | ||||
.run(); | .run(); | ||||
} catch (e) { | } catch (e) { | ||||
this.logError(e, table, JSON.stringify(value)); | |||||
this.logError({ | |||||
sourceModule: 'ioRethink', | |||||
sourceMethod: 'setFlat', | |||||
error: e, | |||||
info: { | |||||
table, | |||||
value: JSON.stringify(value) | |||||
} | |||||
}); | |||||
} | } | ||||
}, | }, | ||||
@@ -193,7 +210,17 @@ module.exports = { | |||||
}) | }) | ||||
.run(); | .run(); | ||||
} catch (e) { | } catch (e) { | ||||
this.logError(e, table, key); | |||||
this.logError({ | |||||
sourceModule: 'ioRethink', | |||||
sourceMethod: 'append', | |||||
error: e, | |||||
info: { | |||||
table, | |||||
key, | |||||
field, | |||||
value: JSON.stringify(value) | |||||
} | |||||
}); | |||||
} | } | ||||
}, | }, | ||||
@@ -208,19 +235,26 @@ module.exports = { | |||||
return !!res; | return !!res; | ||||
}, | }, | ||||
logError: async function (error, table, key) { | |||||
logError: async function ({ sourceModule, sourceMethod, error, info }) { | |||||
try { | try { | ||||
const errorValue = `${error.toString()} | ${error.stack.toString()} | ${table} | ${key}`; | |||||
await this.setAsync({ | await this.setAsync({ | ||||
key: new Date(), | |||||
table: 'error', | table: 'error', | ||||
value: errorValue | |||||
value: { | |||||
date: new Date(), | |||||
sourceModule, | |||||
sourceMethod, | |||||
error: error.toString(), | |||||
stack: error.stack.toString(), | |||||
info | |||||
} | |||||
}); | }); | ||||
} catch (e) {} | } catch (e) {} | ||||
process.send({ | |||||
event: 'onCrashed' | |||||
}); | |||||
if (process.send) { | |||||
process.send({ | |||||
event: 'onCrashed' | |||||
}); | |||||
} else | |||||
process.exit(); | |||||
} | } | ||||
}; | }; |
@@ -253,15 +253,8 @@ module.exports = { | |||||
if (!storeEntry) { | if (!storeEntry) { | ||||
const playerObj = objects.find(o => o.id === toId); | const playerObj = objects.find(o => o.id === toId); | ||||
if (!playerObj || playerObj.zoneName !== sourceZone) { | |||||
io.setAsync({ | |||||
key: new Date(), | |||||
table: 'error', | |||||
value: `ignoring ${e}` | |||||
}); | |||||
if (!playerObj || playerObj.zoneName !== sourceZone) | |||||
continue; | continue; | ||||
} | |||||
store[toId] = { | store[toId] = { | ||||
obj: playerObj, | obj: playerObj, | ||||
@@ -213,6 +213,21 @@ const getThread = async ({ zoneName, zoneId }) => { | |||||
thread = getThreadFromName(map.name); | thread = getThreadFromName(map.name); | ||||
} | } | ||||
if (!thread) { | |||||
io.logError({ | |||||
sourceModule: 'threadManager', | |||||
sourceMethod: 'getThread', | |||||
error: 'No thread found', | |||||
info: { | |||||
requestedZoneName: zoneName, | |||||
requestedZoneId: zoneId, | |||||
useMapName: map.name | |||||
} | |||||
}); | |||||
process.exit(); | |||||
} | |||||
if (!thread.isReady) | if (!thread.isReady) | ||||
await thread.promise; | await thread.promise; | ||||