mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +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!');
|
||||
}).on('connected', function () {
|
||||
console.log('Connected!');
|
||||
getID();
|
||||
// getID();
|
||||
}).on('disconnected', function () {
|
||||
console.log('Disconnected!');
|
||||
// now reconnect
|
||||
@@ -208,28 +208,34 @@ write-data=__PATH__executable__/../../../instances/" + instance + "\r\n\
|
||||
lastSignalCheck = Date.now();
|
||||
|
||||
// world IDs ------------------------------------------------------------------
|
||||
setInterval(getID, 10000);
|
||||
function getID() {
|
||||
var payload = {
|
||||
time: Date.now(),
|
||||
rconPort: instanceconfig.clientPort,
|
||||
rconPassword: instanceconfig.clientPassword,
|
||||
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
|
||||
hashMods(instance, function(modHashes){
|
||||
setInterval(getID, 10000);
|
||||
getID()
|
||||
function getID() {
|
||||
var payload = {
|
||||
time: Date.now(),
|
||||
rconPort: instanceconfig.clientPort,
|
||||
rconPassword: instanceconfig.clientPassword,
|
||||
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 -----------------------------------------------
|
||||
// get mod names and hashes
|
||||
// string: instance, function: callback
|
||||
|
||||
@@ -3,6 +3,7 @@ const masterModFolder = "./database/masterMods/"
|
||||
|
||||
// Library for create folder recursively if it does not exist
|
||||
const mkdirp = require("mkdirp");
|
||||
mkdirp.sync("./database");
|
||||
mkdirp.sync(masterModFolder);
|
||||
|
||||
const fs = require("fs")
|
||||
@@ -22,10 +23,8 @@ app.use(fileUpload());
|
||||
|
||||
// Set folder to serve static content from (the website)
|
||||
app.use(express.static('static'));
|
||||
// Set convenient paths to 3rd party libs like metroUI and jquery from their bower installs
|
||||
// Use this to make it nice an easy to change without touching the HTML in production
|
||||
app.use(express.static('bower_components/metro-dist'));
|
||||
app.use(express.static('bower_components/jquery/dist'));
|
||||
// mod downloads
|
||||
app.use(express.static(masterModFolder));
|
||||
|
||||
// set up database
|
||||
var Datastore = require('nedb');
|
||||
@@ -66,12 +65,9 @@ app.post("/getID", function(req,res) {
|
||||
// mod management
|
||||
// should handle uploading and checking if mods are uploaded
|
||||
app.post("/checkMod", function(req,res) {
|
||||
console.log("Checking mod")
|
||||
let files = fs.readdirSync(masterModFolder)
|
||||
let found = false;
|
||||
console.log(files)
|
||||
files.forEach(file => {
|
||||
console.log(file);
|
||||
if(file == req.body.modName) {
|
||||
found = true;
|
||||
}
|
||||
@@ -85,8 +81,6 @@ app.post("/checkMod", function(req,res) {
|
||||
res.end()
|
||||
});
|
||||
app.post("/uploadMod", function(req,res) {
|
||||
console.log("/uploadMod")
|
||||
|
||||
if (!req.files) {
|
||||
res.send('No files were uploaded.');
|
||||
return;
|
||||
@@ -97,6 +91,7 @@ app.post("/uploadMod", function(req,res) {
|
||||
res.status(500).send(err);
|
||||
} else {
|
||||
res.send('File uploaded!');
|
||||
console.log("Uploaded mod: " + req.files.file.name)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user