-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (35 loc) · 1.2 KB
/
server.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
/**
* @author Will Taylor
* The main file to start up and handle the web server, connections, etc.
*/
// Require the needed Nodejs modules
var express = require('express');
var app = express();
var http = require('http').Server(app);
var GameServer = require('./server/js/gameserver.js');
var io = require('socket.io')(http);
var uuidV1 = require('uuid/v1');
// Declare which port the server will listen on
const PORT = 2000;
// When user loads default URL, send them the index
app.get('/', function(req, res){
res.sendFile(__dirname + '/client/index.html');
});
app.use('/client', express.static(__dirname + '/client'));
// Begin listening on given port
http.listen(PORT);
console.log(':: EXPRESS :: Now listening on port', PORT + '...');
console.log('-------------------------------------------')
// Start the game server
var gameserver = new GameServer();
// Initialize the list of connections
global.SOCKET_LIST = {}
// Handle connection from a new client
io.sockets.on('connection', function(socket){
// Generate a unique ID for this connection
socket.id = uuidV1();
global.SOCKET_LIST[socket.id] = socket;
socket.on('signin', function(username){
gameserver.onConnection(socket, username);
})
});