mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Client can download mods from master
This commit is contained in:
1 parent
fd577054c5
commit
91438c32d9
2 files changed
+32
-31
No files matched your search
@@ -196,7 +196,7 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
console.log('Authenticated!');
|
console.log('Authenticated!');
|
||||||
}).on('connected', function () {
|
}).on('connected', function () {
|
||||||
console.log('Connected!');
|
console.log('Connected!');
|
||||||
getID();
|
// getID();
|
||||||
}).on('disconnected', function () {
|
}).on('disconnected', function () {
|
||||||
console.log('Disconnected!');
|
console.log('Disconnected!');
|
||||||
// now reconnect
|
// now reconnect
|
||||||
@@ -208,28 +208,34 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
|||||||
lastSignalCheck = Date.now();
|
lastSignalCheck = Date.now();
|
||||||
|
|
||||||
// world IDs ------------------------------------------------------------------
|
// world IDs ------------------------------------------------------------------
|
||||||
setInterval(getID, 10000);
|
hashMods(instance, function(modHashes){
|
||||||
function getID() {
|
setInterval(getID, 10000);
|
||||||
var payload = {
|
getID()
|
||||||
time: Date.now(),
|
function getID() {
|
||||||
rconPort: instanceconfig.clientPort,
|
var payload = {
|
||||||
rconPassword: instanceconfig.clientPassword,
|
time: Date.now(),
|
||||||
serverPort: instanceconfig.factorioPort,
|
rconPort: instanceconfig.clientPort,
|
||||||
unique: instanceconfig.clientPassword.hashCode(),
|
rconPassword: instanceconfig.clientPassword,
|
||||||
publicIP: config.publicIP, // IP of the server should be global for all instances, so we pull that straight from the config
|
serverPort: instanceconfig.factorioPort,
|
||||||
|
unique: instanceconfig.clientPassword.hashCode(),
|
||||||
|
publicIP: config.publicIP, // IP of the server should be global for all instances, so we pull that straight from the config
|
||||||
|
mods:modHashes
|
||||||
|
}
|
||||||
|
require('getmac').getMac(function (err, mac) {
|
||||||
|
if (err) throw err
|
||||||
|
payload.mac = mac
|
||||||
|
console.log(payload)
|
||||||
|
needle.post(config.masterIP + ":" + config.masterPort + '/getID', payload, function (err, response, body) {
|
||||||
|
if (response && response.body) {
|
||||||
|
// In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care.
|
||||||
|
console.log(response.body)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
}
|
}
|
||||||
require('getmac').getMac(function (err, mac) {
|
})
|
||||||
if (err) throw err
|
|
||||||
payload.mac = mac
|
|
||||||
console.log(payload)
|
|
||||||
needle.post(config.masterIP + ":" + config.masterPort + '/getID', payload, function (err, response, body) {
|
|
||||||
if (response && response.body) {
|
|
||||||
// In the future we might be interested in whether or not we actually manage to send it, but honestly I don't care.
|
|
||||||
console.log(response.body)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Mod uploading and management -----------------------------------------------
|
// Mod uploading and management -----------------------------------------------
|
||||||
// get mod names and hashes
|
// get mod names and hashes
|
||||||
// string: instance, function: callback
|
// string: instance, function: callback
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const masterModFolder = "./database/masterMods/"
|
|||||||
|
|
||||||
// Library for create folder recursively if it does not exist
|
// Library for create folder recursively if it does not exist
|
||||||
const mkdirp = require("mkdirp");
|
const mkdirp = require("mkdirp");
|
||||||
|
mkdirp.sync("./database");
|
||||||
mkdirp.sync(masterModFolder);
|
mkdirp.sync(masterModFolder);
|
||||||
|
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
@@ -22,10 +23,8 @@ app.use(fileUpload());
|
|||||||
|
|
||||||
// Set folder to serve static content from (the website)
|
// Set folder to serve static content from (the website)
|
||||||
app.use(express.static('static'));
|
app.use(express.static('static'));
|
||||||
// Set convenient paths to 3rd party libs like metroUI and jquery from their bower installs
|
// mod downloads
|
||||||
// Use this to make it nice an easy to change without touching the HTML in production
|
app.use(express.static(masterModFolder));
|
||||||
app.use(express.static('bower_components/metro-dist'));
|
|
||||||
app.use(express.static('bower_components/jquery/dist'));
|
|
||||||
|
|
||||||
// set up database
|
// set up database
|
||||||
var Datastore = require('nedb');
|
var Datastore = require('nedb');
|
||||||
@@ -66,12 +65,9 @@ app.post("/getID", function(req,res) {
|
|||||||
// mod management
|
// mod management
|
||||||
// should handle uploading and checking if mods are uploaded
|
// should handle uploading and checking if mods are uploaded
|
||||||
app.post("/checkMod", function(req,res) {
|
app.post("/checkMod", function(req,res) {
|
||||||
console.log("Checking mod")
|
|
||||||
let files = fs.readdirSync(masterModFolder)
|
let files = fs.readdirSync(masterModFolder)
|
||||||
let found = false;
|
let found = false;
|
||||||
console.log(files)
|
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
console.log(file);
|
|
||||||
if(file == req.body.modName) {
|
if(file == req.body.modName) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@@ -85,8 +81,6 @@ app.post("/checkMod", function(req,res) {
|
|||||||
res.end()
|
res.end()
|
||||||
});
|
});
|
||||||
app.post("/uploadMod", function(req,res) {
|
app.post("/uploadMod", function(req,res) {
|
||||||
console.log("/uploadMod")
|
|
||||||
|
|
||||||
if (!req.files) {
|
if (!req.files) {
|
||||||
res.send('No files were uploaded.');
|
res.send('No files were uploaded.');
|
||||||
return;
|
return;
|
||||||
@@ -97,6 +91,7 @@ app.post("/uploadMod", function(req,res) {
|
|||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
} else {
|
} else {
|
||||||
res.send('File uploaded!');
|
res.send('File uploaded!');
|
||||||
|
console.log("Uploaded mod: " + req.files.file.name)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user