mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Simple gamespy status
This commit is contained in:
parent
f203ad4a11
commit
39bbe2e0c9
5
main.js
5
main.js
@ -15,9 +15,12 @@ var servers = require('./routes/servers');
|
||||
|
||||
app.resource('api/missions', require('./routes/missions'));
|
||||
app.resource('api/mods', require('./routes/mods'));
|
||||
app.resource('api/servers', servers);
|
||||
var serversResource = app.resource('api/servers', servers);
|
||||
app.resource('api/settings', require('./routes/settings'));
|
||||
|
||||
var gamespyResource = app.resource('gamespy', require('./routes/servers/gamespy'));
|
||||
serversResource.add(gamespyResource);
|
||||
|
||||
app.get('/api/servers/:server/start', servers.start);
|
||||
app.get('/api/servers/:server/stop', servers.stop);
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
"express": "3.x",
|
||||
"slug": "~0.4.0",
|
||||
"express-resource": "~1.0.0",
|
||||
"when": "~3.1.0"
|
||||
"when": "~3.1.0",
|
||||
"gamedig": "^0.2.4",
|
||||
"ip": "^0.3.0"
|
||||
}
|
||||
}
|
||||
|
19
public/js/app/models/gamespy.js
Normal file
19
public/js/app/models/gamespy.js
Normal file
@ -0,0 +1,19 @@
|
||||
define(function (require) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone');
|
||||
|
||||
return Backbone.Model.extend({
|
||||
initialize: function(attributes, options) {
|
||||
this.server = options.server;
|
||||
},
|
||||
|
||||
url : function(){
|
||||
return this.server.url() + '/gamespy';
|
||||
}
|
||||
});
|
||||
|
||||
});
|
54
public/js/app/views/servers/gamespy.js
Normal file
54
public/js/app/views/servers/gamespy.js
Normal file
@ -0,0 +1,54 @@
|
||||
define(function (require) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var $ = require('jquery'),
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
Gamespy = require('app/models/gamespy'),
|
||||
tpl = require('text!tpl/servers/gamespy.html');
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
template: _.template(tpl),
|
||||
|
||||
initialize: function (options) {
|
||||
this.model = new Gamespy({running: false}, {server: options.server});
|
||||
|
||||
this.clockInterval = this.startUpdating();
|
||||
this.refresh();
|
||||
},
|
||||
|
||||
onBeforeClose: function(){
|
||||
this.stopUpdating();
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
refresh: function () {
|
||||
if (this.options.server.get("pid")) {
|
||||
var self = this;
|
||||
this.model.fetch({
|
||||
success: function() {
|
||||
self.model.set("running", true);
|
||||
self.render();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.model.set("running", false)
|
||||
}
|
||||
},
|
||||
|
||||
startUpdating: function(){
|
||||
return setInterval(
|
||||
this.refresh.bind(this),
|
||||
5000
|
||||
)
|
||||
},
|
||||
|
||||
stopUpdating: function(){
|
||||
clearInterval(this.clockInterval);
|
||||
},
|
||||
});
|
||||
|
||||
});
|
@ -6,16 +6,25 @@ define(function (require) {
|
||||
_ = require('underscore'),
|
||||
Backbone = require('backbone'),
|
||||
Marionette = require('marionette'),
|
||||
GamespyView = require('app/views/servers/gamespy'),
|
||||
tpl = require('text!tpl/servers/info.html');
|
||||
|
||||
return Marionette.ItemView.extend({
|
||||
return Marionette.Layout.extend({
|
||||
template: _.template(tpl),
|
||||
|
||||
regions: {
|
||||
gamespyView: "#gamespy",
|
||||
},
|
||||
|
||||
events: {
|
||||
"click #start": "start",
|
||||
"click #stop": "stop",
|
||||
},
|
||||
|
||||
onRender: function() {
|
||||
this.gamespyView.show(new GamespyView({server: this.model}));
|
||||
},
|
||||
|
||||
start: function (event) {
|
||||
var self = this;
|
||||
event.preventDefault();
|
||||
|
27
public/js/tpl/servers/gamespy.html
Normal file
27
public/js/tpl/servers/gamespy.html
Normal file
@ -0,0 +1,27 @@
|
||||
<h3>Server Status from Gamespy</h3>
|
||||
|
||||
<% if (typeof(error) != "undefined") { %>
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Error</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static"><%= error %></p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<% } else if (typeof(running) != "undefined" && running) { %>
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Players</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static"><%= numplayers %> / <%= maxplayers %></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">Mission</label>
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control-static"><%= mission %></p>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<% } %>
|
@ -5,3 +5,5 @@
|
||||
<% } else { %>
|
||||
<a class="btn btn-primary" href="#" id="start">Start</a>
|
||||
<% } %>
|
||||
|
||||
<div id="gamespy"></div>
|
||||
|
17
routes/servers/gamespy.js
Normal file
17
routes/servers/gamespy.js
Normal file
@ -0,0 +1,17 @@
|
||||
var Gamedig = require('gamedig');
|
||||
var ip = require('ip');
|
||||
|
||||
exports.index = function (req, res){
|
||||
Gamedig.query({
|
||||
type: 'arma3',
|
||||
host: ip.address()
|
||||
},
|
||||
function(state) {
|
||||
if(state.error) {
|
||||
res.send({error: state.error});
|
||||
} else {
|
||||
res.send(state.raw);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
Loading…
Reference in New Issue
Block a user