mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Final fix for crash on closing slave related to getMac
This commit is contained in:
1 parent
c7744b5189
commit
d858f1da69
2 files changed
+10
-21
No files matched your search
@@ -10,10 +10,12 @@ var Rcon = require('simple-rcon');
|
|||||||
var hashFiles = require('hash-files');
|
var hashFiles = require('hash-files');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var deepmerge = require("deepmerge");
|
var deepmerge = require("deepmerge");
|
||||||
|
var getMac = require('getmac').getMac;
|
||||||
|
|
||||||
// internal libraries
|
// internal libraries
|
||||||
var objectOps = require("./lib/objectOps.js");
|
var objectOps = require("./lib/objectOps.js");
|
||||||
var fileOps = require("./lib/fileOps.js");
|
var fileOps = require("./lib/fileOps.js");
|
||||||
|
var stringUtils = require("./lib/stringUtils.js");
|
||||||
|
|
||||||
// require config.json
|
// require config.json
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
@@ -33,18 +35,6 @@ const instancedirectory = './instances/' + instance;
|
|||||||
const command = process.argv[2];
|
const command = process.argv[2];
|
||||||
var instanceInfo = {};
|
var instanceInfo = {};
|
||||||
|
|
||||||
// simple string hasher
|
|
||||||
String.prototype.hashCode = function () {
|
|
||||||
var hash = 0;
|
|
||||||
if (this.length == 0) return hash;
|
|
||||||
for (let i = 0; i < this.length; i++) {
|
|
||||||
char = this.charCodeAt(i);
|
|
||||||
hash = ((hash << 5) - hash) + char;
|
|
||||||
hash = hash & hash; // Convert to 32bit integer
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
// function to handle sending commands into the game
|
// function to handle sending commands into the game
|
||||||
function messageInterface(command, callback) {
|
function messageInterface(command, callback) {
|
||||||
// try to save us if you send a buffer instead of string
|
// try to save us if you send a buffer instead of string
|
||||||
@@ -177,7 +167,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
// Exit if no instance specified (it should be, just a safeguard);
|
// Exit if no instance specified (it should be, just a safeguard);
|
||||||
if(instancedirectory != "./instances/undefined"){
|
if(instancedirectory != "./instances/undefined"){
|
||||||
var instanceconfig = require(instancedirectory + '/config');
|
var instanceconfig = require(instancedirectory + '/config');
|
||||||
instanceconfig.unique = instanceconfig.clientPassword.hashCode();
|
instanceconfig.unique = stringUtils.hashCode(instanceconfig.clientPassword);
|
||||||
if(process.env.FACTORIOPORT){
|
if(process.env.FACTORIOPORT){
|
||||||
instanceconfig.factorioPort = process.env.FACTORIOPORT;
|
instanceconfig.factorioPort = process.env.FACTORIOPORT;
|
||||||
}
|
}
|
||||||
@@ -420,9 +410,10 @@ function instanceManagement() {
|
|||||||
playerCount: instanceInfo.playerCount || 0,
|
playerCount: instanceInfo.playerCount || 0,
|
||||||
instanceName: instance,
|
instanceName: instance,
|
||||||
}
|
}
|
||||||
try {
|
getMac(function (err, mac) {
|
||||||
require('getmac').getMac(function (err, mac) {
|
if (err) {
|
||||||
if (err) throw err
|
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
|
||||||
|
} else {
|
||||||
payload.mac = mac
|
payload.mac = mac
|
||||||
console.log("Registered our precense with master "+config.masterIP+" at " + payload.time);
|
console.log("Registered our precense with master "+config.masterIP+" at " + payload.time);
|
||||||
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, function (err, response, body) {
|
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, function (err, response, body) {
|
||||||
@@ -434,10 +425,8 @@ function instanceManagement() {
|
|||||||
console.log(response.body);
|
console.log(response.body);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
} catch (e){
|
});
|
||||||
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
|
|
||||||
}
|
|
||||||
},1000)});
|
},1000)});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
function hashCode(string){
|
function hashCode(string){
|
||||||
if(typeof string !== "string") throw "ERROR: Not a string";
|
if(typeof string !== "string") throw "ERROR stringUtils: Not a string";
|
||||||
var hash = 0;
|
var hash = 0;
|
||||||
if (string.length == 0) return hash;
|
if (string.length == 0) return hash;
|
||||||
for (let i = 0; i < string.length; i++) {
|
for (let i = 0; i < string.length; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user