mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Steam Workshop Mods
This commit is contained in:
committed by
Björn Dahlgren
parent
a841ad5027
commit
59364c299b
9
app.js
9
app.js
@ -9,6 +9,7 @@ var config = require('./config');
|
||||
var Manager = require('./lib/manager');
|
||||
var Missions = require('./lib/missions');
|
||||
var Mods = require('./lib/mods');
|
||||
var SteamMods = require('./lib/steam_mods');
|
||||
var Logs = require('./lib/logs');
|
||||
|
||||
var app = express();
|
||||
@ -31,13 +32,13 @@ app.use(serveStatic(path.join(__dirname, 'public')));
|
||||
|
||||
var logs = new Logs(config);
|
||||
|
||||
var manager = new Manager(config, logs);
|
||||
manager.load();
|
||||
|
||||
var missions = new Missions(config);
|
||||
var mods = new Mods(config);
|
||||
var mods = new SteamMods(config);
|
||||
mods.updateMods();
|
||||
|
||||
var manager = new Manager(config, logs, mods);
|
||||
manager.load();
|
||||
|
||||
app.use('/api/logs', require('./routes/logs')(logs));
|
||||
app.use('/api/missions', require('./routes/missions')(missions));
|
||||
app.use('/api/mods', require('./routes/mods')(mods));
|
||||
|
@ -12,6 +12,9 @@ module.exports = {
|
||||
'@mod1',
|
||||
'@mod2',
|
||||
],
|
||||
steam: {
|
||||
path: 'path-to-main-steam-folder',
|
||||
},
|
||||
auth: { // If both username and password is set, HTTP Basic Auth will be used
|
||||
username: '', // Username for HTTP Basic Auth
|
||||
password: '', // Password for HTTP Basic Auth
|
||||
|
@ -5,9 +5,10 @@ var Server = require('./server');
|
||||
|
||||
var filePath = "servers.json";
|
||||
|
||||
var Manager = function (config, logs) {
|
||||
var Manager = function (config, logsManager, modsManager) {
|
||||
this.config = config;
|
||||
this.logs = logs;
|
||||
this.logsManager = logsManager;
|
||||
this.modsManager = modsManager;
|
||||
this.serversArr = [];
|
||||
this.serversHash = {};
|
||||
};
|
||||
@ -41,7 +42,7 @@ Manager.prototype.removeServer = (function (id) {
|
||||
});
|
||||
|
||||
Manager.prototype._addServer = (function (data) {
|
||||
var server = new Server(this.config, this.logs, data);
|
||||
var server = new Server(this.config, this.logsManager, this.modsManager, data);
|
||||
this.serversArr.push(server);
|
||||
this.serversArr.sort(function(a, b) {
|
||||
return a.title.localeCompare(b.title);
|
||||
|
@ -74,6 +74,12 @@ Mods.prototype.download = function (mod, cb) {
|
||||
});
|
||||
};
|
||||
|
||||
Mods.prototype.find = function (id) {
|
||||
this.mods.find(function (mod) {
|
||||
return mod.id == id;
|
||||
})
|
||||
};
|
||||
|
||||
Mods.prototype.updateMods = function () {
|
||||
var self = this;
|
||||
fs.readdir(self.config.path, function (err, files) {
|
||||
@ -89,8 +95,10 @@ Mods.prototype.updateMods = function () {
|
||||
var modPath = path.join(self.config.path, mod);
|
||||
self.isPlayWithSixMod(modPath, function (isPlayWithSixMod) {
|
||||
cb(null, {
|
||||
id: mod,
|
||||
name: mod,
|
||||
outdated: outdatedMods && outdatedMods.indexOf(mod) >= 0,
|
||||
path: mod,
|
||||
progress: null,
|
||||
playWithSix: isPlayWithSixMod,
|
||||
});
|
||||
|
@ -32,9 +32,10 @@ var createServerTitle = function(title) {
|
||||
return title;
|
||||
};
|
||||
|
||||
var Server = function (config, logs, options) {
|
||||
var Server = function (config, logsManager, modsManager, options) {
|
||||
this.config = config;
|
||||
this.logs = logs;
|
||||
this.logsManager = logsManager;
|
||||
this.modsManager = modsManager;
|
||||
this.update(options);
|
||||
};
|
||||
|
||||
@ -92,7 +93,15 @@ Server.prototype.queryStatus = function() {
|
||||
};
|
||||
|
||||
Server.prototype.start = function() {
|
||||
var self = this;
|
||||
var parameters = [];
|
||||
var mods = this.mods.map(function (mod) {
|
||||
return self.modsManager.find(mod);
|
||||
}).filter(function (mod) {
|
||||
return mod;
|
||||
}).map(function (mod) {
|
||||
return mod.path;
|
||||
});
|
||||
|
||||
if (config.parameters && Array.isArray(config.parameters)) {
|
||||
parameters = parameters.concat(config.parameters);
|
||||
@ -111,7 +120,7 @@ Server.prototype.start = function() {
|
||||
hostname: createServerTitle(this.title),
|
||||
localClient: this.headless ? ["127.0.0.1"] : null,
|
||||
missions: this.missions,
|
||||
mods: this.mods,
|
||||
mods: mods,
|
||||
parameters: parameters,
|
||||
password: this.password,
|
||||
passwordAdmin: this.admin_password,
|
||||
@ -124,11 +133,10 @@ Server.prototype.start = function() {
|
||||
});
|
||||
server.writeServerConfig();
|
||||
var instance = server.start();
|
||||
var self = this;
|
||||
|
||||
var logStream = null;
|
||||
if (this.config.type === 'linux') {
|
||||
logStream = fs.createWriteStream(this.logs.generateLogFilePath(), {
|
||||
logStream = fs.createWriteStream(this.logsManager.generateLogFilePath(), {
|
||||
'flags': 'a'
|
||||
});
|
||||
}
|
||||
@ -172,7 +180,7 @@ Server.prototype.start = function() {
|
||||
var headless = new ArmaServer.Headless({
|
||||
game: config.game,
|
||||
host: "127.0.0.1",
|
||||
mods: this.mods,
|
||||
mods: mods,
|
||||
parameters: parameters,
|
||||
password: this.password,
|
||||
path: this.config.path,
|
||||
|
56
lib/steam_mods.js
Normal file
56
lib/steam_mods.js
Normal file
@ -0,0 +1,56 @@
|
||||
var async = require('async');
|
||||
var events = require('events');
|
||||
var filesize = require('filesize');
|
||||
var fs = require('fs.extra');
|
||||
var _ = require('lodash');
|
||||
var path = require('path');
|
||||
var ArmaSteamWorkshop = require('arma-steam-workshop');
|
||||
|
||||
var SteamMods = function (config) {
|
||||
this.config = config;
|
||||
this.armaSteamWorkshop = new ArmaSteamWorkshop(this.config.steam);
|
||||
this.mods = [];
|
||||
};
|
||||
|
||||
SteamMods.prototype = new events.EventEmitter();
|
||||
|
||||
SteamMods.prototype.delete = function (mod, cb) {
|
||||
cb(new Error('not implemented'));
|
||||
};
|
||||
|
||||
SteamMods.prototype.find = function (id) {
|
||||
return this.mods.find(function (mod) {
|
||||
return mod.id == id;
|
||||
});
|
||||
};
|
||||
|
||||
SteamMods.prototype.download = function (mod, cb) {
|
||||
cb(new Error('not implemented'));
|
||||
};
|
||||
|
||||
SteamMods.prototype.resolveMods = function (mods, cb) {
|
||||
cb(null, mods);
|
||||
};
|
||||
|
||||
SteamMods.prototype.search = function (query, cb) {
|
||||
cb(new Error('not implemented'));
|
||||
};
|
||||
|
||||
SteamMods.prototype.updateMods = function () {
|
||||
var self = this;
|
||||
this.armaSteamWorkshop.mods(function (err, mods) {
|
||||
if (!err) {
|
||||
mods.map(function (mod) {
|
||||
mod.id = mod.id + '';
|
||||
mod.playWithSix = null;
|
||||
mod.progress = null;
|
||||
mod.outdated = false;
|
||||
});
|
||||
|
||||
self.mods = mods;
|
||||
self.emit('mods', mods);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = SteamMods;
|
@ -11,6 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"arma-server": "0.0.5",
|
||||
"arma-steam-workshop": "https://github.com/Dahlgren/node-arma-steam-workshop/tarball/0f31c36ad2fa68e1ca0bf937cfea02c0c30ba9fd",
|
||||
"async": "^0.9.0",
|
||||
"body-parser": "^1.17.1",
|
||||
"express": "^4.15.2",
|
||||
|
@ -8,9 +8,11 @@ define(function (require) {
|
||||
|
||||
return Backbone.Model.extend({
|
||||
defaults: {
|
||||
name: ''
|
||||
id: '',
|
||||
name: '',
|
||||
path: '',
|
||||
},
|
||||
idAttribute: 'name',
|
||||
idAttribute: 'id',
|
||||
urlRoot: '/api/mods/',
|
||||
});
|
||||
|
||||
|
@ -54,5 +54,16 @@ define(function (require) {
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
templateHelpers: function() {
|
||||
var self = this;
|
||||
return {
|
||||
mods: self.options.mods.filter(function (mod) {
|
||||
return self.model.get('mods').indexOf(mod.get('id')) >= 0;
|
||||
}).map(function (mod) {
|
||||
return mod.get('name');
|
||||
}),
|
||||
};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ define(function (require) {
|
||||
|
||||
templateHelpers: function(){
|
||||
return {
|
||||
enabled: this.options.server.get('mods').indexOf(this.model.get('name')) > -1
|
||||
enabled: this.options.server.get('mods').indexOf(this.model.get('id')) > -1
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -42,7 +42,7 @@ define(function (require) {
|
||||
},
|
||||
|
||||
onRender: function() {
|
||||
this.infoView.show(new InfoView({model: this.model}));
|
||||
this.infoView.show(new InfoView({model: this.model, mods: this.mods}));
|
||||
this.missionsView.show(new MissionsView({missions: this.missions, server: this.model}));
|
||||
this.modsView.show(new ModsListView({collection: this.mods, server: this.model}));
|
||||
this.parametersView.show(new ParametersListView({server: this.model}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
<td>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" value="<%-name%>" <% if (enabled) { %>checked<% } %> >
|
||||
<input type="checkbox" value="<%-id%>" <% if (enabled) { %>checked<% } %> >
|
||||
<%-name%>
|
||||
</label>
|
||||
</div>
|
||||
|
@ -5,14 +5,14 @@ var Server = require('../../lib/server.js');
|
||||
describe('Server', function() {
|
||||
describe('generateId()', function() {
|
||||
it('should include title', function() {
|
||||
var server = new Server(null, null, {title: 'title.with.lot.of.dots'});
|
||||
var server = new Server(null, null, null, {title: 'title.with.lot.of.dots'});
|
||||
server.generateId().should.eql('title-with-lot-of-dots');
|
||||
});
|
||||
});
|
||||
|
||||
describe('toJSON()', function() {
|
||||
it('should include title', function() {
|
||||
var server = new Server(null, null, {title: 'test'});
|
||||
var server = new Server(null, null, null, {title: 'test'});
|
||||
server.toJSON().should.have.property('title', 'test');
|
||||
});
|
||||
});
|
||||
|
21
test/lib/steam_mods.js
Normal file
21
test/lib/steam_mods.js
Normal file
@ -0,0 +1,21 @@
|
||||
var should = require('should');
|
||||
|
||||
var SteamMods = require('../../lib/steam_mods.js');
|
||||
|
||||
var dummyMods = [
|
||||
{
|
||||
id: 'test',
|
||||
name: 'test',
|
||||
}
|
||||
];
|
||||
|
||||
describe('SteamMods', function() {
|
||||
describe('find()', function() {
|
||||
it('should find mod', function() {
|
||||
var steamMods = new SteamMods({});
|
||||
steamMods.mods = dummyMods;
|
||||
var mod = steamMods.find('test');
|
||||
mod.should.eql(dummyMods[0]);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user