Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.

Commit 1faa901

Browse files
committed
Display server version on homepage. Fixes #23
1 parent d81e52d commit 1faa901

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ var server = http.createServer(function(req, res) {
1616
var eioServer = eio(server).on('connection', router)
1717

1818
require('log-timestamp')
19-
console.log(`Started up ${CONFIG.VERSION.RELEASE}+${CONFIG.VERSION.LOCAL_BUILD}`)
19+
console.log(`Started up ${CONFIG.VERSION}`)

config.server.js.default

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const execSync = require('child_process').execSync
22

3-
const RELEASE = execSync('git describe').toString().trim()
4-
const LOCAL_BUILD = parseInt(
5-
execSync('git rev-list --count "$(git describe)..HEAD"').toString().trim(),
6-
10)
3+
const VERSION = execSync('git describe')
4+
.toString()
5+
.trim()
6+
.replace('-', '/')
77

88
module.exports = {
99
PORT: 1337,
10-
VERSION: {RELEASE, LOCAL_BUILD},
10+
VERSION,
1111
STRINGS: {
1212
BRANDING: {
1313
DEFAULT_USERNAME: 'ninja',

public/src/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let App = {
1414
id: null,
1515
name: STRINGS.BRANDING.DEFAULT_USERNAME,
1616

17+
serverVersion: null,
1718
numUsers: 0,
1819
numPlayers: 0,
1920
numActiveGames: 0,

public/src/components/lobby.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,7 @@ export default React.createClass({
2222
d.header({},
2323
d.h1({ className: 'lobby-header' },
2424
Spaced(...STRINGS.BRANDING.SITE_NAME))),
25-
26-
d.p({},
27-
Spaced(
28-
`${App.state.numUsers}
29-
${App.state.numUsers === 1 ? 'user' : 'users'}
30-
connected`,
31-
`${App.state.numPlayers}
32-
${App.state.numPlayers === 1 ? 'player' : 'players'}
33-
playing
34-
${App.state.numActiveGames}
35-
${App.state.numActiveGames === 1 ? 'game' : 'games'}`)),
25+
ServerInfo(),
3626
d.p({ className: 'error' }, App.err),
3727
Create(),
3828
Join(),
@@ -98,6 +88,27 @@ function Motd() {
9888
d.div({}, motd))
9989
}
10090

91+
function ServerInfo() {
92+
let numUsers =
93+
`${App.state.numUsers}
94+
${App.state.numUsers === 1 ? 'user' : 'users'}
95+
connected`
96+
97+
let numPlayers =
98+
`${App.state.numPlayers}
99+
${App.state.numPlayers === 1 ? 'player' : 'players'}
100+
playing
101+
${App.state.numActiveGames}
102+
${App.state.numActiveGames === 1 ? 'game' : 'games'}`
103+
104+
let serverVersion =
105+
App.state.serverVersion
106+
? `Running ${App.state.serverVersion}`
107+
: null
108+
109+
return d.p({}, Spaced(...[numUsers, numPlayers, serverVersion]))
110+
}
111+
101112
function Create() {
102113
let seats = _.seq(100, 2).map(x =>
103114
d.option({}, x))

public/src/components/spacer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
let d = React.DOM
22

33
export function Spaced(...elements) {
4+
elements = elements.filter(x => x)
5+
46
let parts = []
57
for (let part of elements) {
68
parts.push(d.span({}, part))

src/router.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {MOTD} = require('../config.server')
1+
const {VERSION} = require('../config.server')
22
var Game = require('./game')
33
var Room = require('./room')
44
var Sock = require('./sock')
@@ -40,5 +40,5 @@ module.exports = function (ws) {
4040
sock.on('create', create)
4141

4242
Game.broadcastGameInfo()
43-
sock.send('set', { motd: MOTD })
43+
sock.send('set', { serverVersion: VERSION })
4444
}

0 commit comments

Comments
 (0)