mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-05-05 21:17:43 -05:00
Merge pull request #1869 from Slayer95/dependants
Dependant support: make sure that relative paths are resolved properly
This commit is contained in:
commit
a7c7b37553
11
app.js
11
app.js
|
|
@ -59,6 +59,7 @@ function runNpm(command) {
|
|||
var isLegacyEngine = !global.Map;
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
try {
|
||||
require('sugar');
|
||||
if (isLegacyEngine) require('es6-shim');
|
||||
|
|
@ -80,14 +81,14 @@ try {
|
|||
|
||||
// Copy it over synchronously from config-example.js since it's needed before we can start the server
|
||||
console.log("config.js doesn't exist - creating one with default settings...");
|
||||
fs.writeFileSync('./config/config.js',
|
||||
fs.readFileSync('./config/config-example.js')
|
||||
fs.writeFileSync(path.resolve(__dirname, 'config/config.js'),
|
||||
fs.readFileSync(path.resolve(__dirname, 'config/config-example.js'))
|
||||
);
|
||||
global.Config = require('./config/config.js');
|
||||
}
|
||||
|
||||
if (Config.watchconfig) {
|
||||
fs.watchFile('./config/config.js', function (curr, prev) {
|
||||
fs.watchFile(path.resolve(__dirname, 'config/config.js'), function (curr, prev) {
|
||||
if (curr.mtime <= prev.mtime) return;
|
||||
try {
|
||||
delete require.cache[require.resolve('./config/config.js')];
|
||||
|
|
@ -215,7 +216,7 @@ global.ResourceMonitor = {
|
|||
for (var i in this.networkUse) {
|
||||
buf += '' + this.networkUse[i] + '\t' + this.networkCount[i] + '\t' + i + '\n';
|
||||
}
|
||||
fs.writeFile('logs/networkuse.tsv', buf);
|
||||
fs.writeFile(path.resolve(__dirname, 'logs/networkuse.tsv'), buf);
|
||||
},
|
||||
clearNetworkUse: function () {
|
||||
this.networkUse = {};
|
||||
|
|
@ -398,7 +399,7 @@ Rooms.global.formatListText = Rooms.global.getFormatListText();
|
|||
global.TeamValidator = require('./team-validator.js');
|
||||
|
||||
// load ipbans at our leisure
|
||||
fs.readFile('./config/ipbans.txt', function (err, data) {
|
||||
fs.readFile(path.resolve(__dirname, 'config/ipbans.txt'), function (err, data) {
|
||||
if (err) return;
|
||||
data = ('' + data).split("\n");
|
||||
var rangebans = [];
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ const MESSAGE_COOLDOWN = 5 * 60 * 1000;
|
|||
const MAX_PARSE_RECURSION = 10;
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
/*********************************************************
|
||||
* Load command files
|
||||
|
|
@ -40,7 +41,7 @@ var commands = exports.commands = require('./commands.js').commands;
|
|||
|
||||
// Install plug-in commands
|
||||
|
||||
fs.readdirSync('./chat-plugins').forEach(function (file) {
|
||||
fs.readdirSync(path.resolve(__dirname, 'chat-plugins')).forEach(function (file) {
|
||||
if (file.substr(-3) === '.js') Object.merge(commands, require('./chat-plugins/' + file).commands);
|
||||
});
|
||||
|
||||
|
|
@ -48,7 +49,7 @@ fs.readdirSync('./chat-plugins').forEach(function (file) {
|
|||
* Parser
|
||||
*********************************************************/
|
||||
|
||||
var modlog = exports.modlog = {lobby: fs.createWriteStream('logs/modlog/modlog_lobby.txt', {flags:'a+'}), battle: fs.createWriteStream('logs/modlog/modlog_battle.txt', {flags:'a+'})};
|
||||
var modlog = exports.modlog = {lobby: fs.createWriteStream(path.resolve(__dirname, 'logs/modlog/modlog_lobby.txt'), {flags:'a+'}), battle: fs.createWriteStream(path.resolve(__dirname, 'logs/modlog/modlog_battle.txt'), {flags:'a+'})};
|
||||
|
||||
/**
|
||||
* Can this user talk?
|
||||
|
|
@ -282,7 +283,7 @@ var parse = exports.parse = function (message, room, user, connection, levelsDee
|
|||
if (room.battle) {
|
||||
modlog[room.id] = modlog['battle'];
|
||||
} else {
|
||||
modlog[room.id] = fs.createWriteStream('logs/modlog/modlog_' + room.id + '.txt', {flags:'a+'});
|
||||
modlog[room.id] = fs.createWriteStream(path.resolve(__dirname, 'logs/modlog/modlog_' + room.id + '.txt'), {flags:'a+'});
|
||||
}
|
||||
}
|
||||
modlog[room.id].write('[' + (new Date().toJSON()) + '] (' + room.id + ') ' + result + '\n');
|
||||
|
|
@ -456,7 +457,7 @@ var parse = exports.parse = function (message, room, user, connection, levelsDee
|
|||
};
|
||||
|
||||
exports.package = {};
|
||||
fs.readFile('package.json', function (err, data) {
|
||||
fs.readFile(path.resolve(__dirname, 'package.json'), function (err, data) {
|
||||
if (err) return;
|
||||
exports.package = JSON.parse(data);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@
|
|||
module.exports = (function () {
|
||||
var lastCrashLog = 0;
|
||||
var transport;
|
||||
var logPath = require('path').resolve(__dirname, 'logs/errors.txt');
|
||||
return function (err, description) {
|
||||
console.log("\nCRASH: " + (err.stack || err) + "\n");
|
||||
require('fs').createWriteStream('logs/errors.txt', {'flags': 'a'}).on("open", function (fd) {
|
||||
require('fs').createWriteStream(logPath, {'flags': 'a'}).on("open", function (fd) {
|
||||
this.write("\n" + err.stack + "\n");
|
||||
this.end();
|
||||
}).on("error", function (err) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ var battles = Object.create(null);
|
|||
|
||||
var SimulatorProcess = (function () {
|
||||
function SimulatorProcess() {
|
||||
this.process = require('child_process').fork('battle-engine.js');
|
||||
this.process = require('child_process').fork('battle-engine.js', {cwd: __dirname});
|
||||
this.process.on('message', function (message) {
|
||||
var lines = message.split('\n');
|
||||
var battle = battles[lines[0]];
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ global.Config = require('./config/config');
|
|||
|
||||
if (cluster.isMaster) {
|
||||
cluster.setupMaster({
|
||||
exec: 'sockets.js'
|
||||
exec: require('path').resolve(__dirname, 'sockets.js')
|
||||
});
|
||||
|
||||
var workers = exports.workers = {};
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ if (!process.send) {
|
|||
|
||||
var ValidatorProcess = (function () {
|
||||
function ValidatorProcess() {
|
||||
this.process = require('child_process').fork('team-validator.js');
|
||||
this.process = require('child_process').fork('team-validator.js', {cwd: __dirname});
|
||||
var self = this;
|
||||
this.process.on('message', function (message) {
|
||||
// Protocol:
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ before('initialization', function (done) {
|
|||
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
||||
|
||||
console.log("config.js doesn't exist - creating one with default settings...");
|
||||
fs.writeFileSync(path.resolve(process.cwd(), './config/config.js'),
|
||||
fs.readFileSync(path.resolve(process.cwd(), './config/config-example.js'))
|
||||
fs.writeFileSync(path.resolve(__dirname, '../config/config.js'),
|
||||
fs.readFileSync(path.resolve(__dirname, '../config/config-example.js'))
|
||||
);
|
||||
config = require('./../config/config.js');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ if (!process.send) {
|
|||
var callbacks = {};
|
||||
var callbackData = {};
|
||||
|
||||
var child = require('child_process').fork('verifier.js');
|
||||
var child = require('child_process').fork('verifier.js', {cwd: __dirname});
|
||||
exports.verify = function (data, signature, callback) {
|
||||
var localGuid = guid++;
|
||||
callbacks[localGuid] = callback;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user