Skip to content

Instantly share code, notes, and snippets.

@foglio1024
Last active June 23, 2022 19:35
Show Gist options
  • Save foglio1024/08f871d98323cae07e51f4aaddfe013b to your computer and use it in GitHub Desktop.
Save foglio1024/08f871d98323cae07e51f4aaddfe013b to your computer and use it in GitHub Desktop.
TeraBackup
const path = require('path');
const fs = require('fs');
module.exports = function TeraBackup(mod) {
let enabled = true;
let file = path.join(__dirname, 'tera-log-' + Date.now() + '.log');
mod.hook('*', 'raw', { order: -Infinity, filters: { fake: null } }, (code, data, fromServer) => {
if (!enabled) return
const now = new Date();
const timeStr = `[${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}:${now.getSeconds().toString().padStart(2, '0')}.${now.getMilliseconds().toString().padStart(3, '0')}] `;
fs.appendFileSync(file, timeStr + (fromServer ? '<-' : '->') + ' ' + ((mod.dispatch.protocolMap ? mod.dispatch.protocolMap.code.get(code) : null) || code) + ' ' + ((data.length > 4) ? data.slice(4).toString('hex').match(/.{2}/g).join(' ') : '') + '\n')
});
}
{
"name": "terabackup",
"author": "Foglio",
"disableAutoUpdate": true,
"keywords": ["network"],
"options": {
"cliName": "terabackup",
"guiName": "TERA Backup"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment