This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (44 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var MobileDetect = require('mobile-detect');
var session = require('express-session');
var FileStore = require('session-file-store')(session);
// Initialize the session
app.use(session({
store: new FileStore(),
secret: 'martijniscool123456',
resave: false,
saveUninitialized: true,
cookie: {
// in miliseconds, this is one hour
maxAge: 3600000,
}
}));
// Routing for the game
app.get('/', function(req, res) {
// Use this to check if the browser is a mobile one
md = new MobileDetect(req.headers['user-agent']);
// If the browser is not a mobile one, don't allow to play the game
if (!md.mobile()) {
res.sendFile(`${__dirname}/not-mobile.html`);
} else {
res.sendFile(`${__dirname}/dotsmash.html`);
}
});
// Socket code for each connected client
io.on('connection', function(socket){
// Log that a client is connected, for debug purposes
console.log(`user connected: ${socket.id}`);
// Log if a client disconnects, for debug purposes
socket.on('disconnect', function(){
console.log(`user disconnected: ${socket.id}`);
});
});
// Normal HTTP
// Listen on port 80
http.listen(80, function(){
// Log that we're actually active, for debug purposes
console.log('listening on *:80');
});