You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const express = require('express');
|
|
|
|
const database = require('./database');
|
|
const rooms = require('./rooms');
|
|
|
|
const app = express();
|
|
const http = require('http').Server(app);
|
|
const port = process.env.PORT || 3000;
|
|
const io = require('socket.io')(http);
|
|
|
|
// util is what nodejs uses for console.log, but has a depth of 2 set
|
|
// so console.logs show [Array]/[Object] instead of useful info.
|
|
// This can be overridden console.log(util.inspect(LOGDATA, true, 4, true))
|
|
// 4 being new depth, true (last one) is to show colours
|
|
const util = require('util')
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
http.listen(port, () => console.log('listening on port ' + port));
|
|
database.connect();
|
|
|
|
io.on('connection', onConnection);
|
|
|
|
function onConnection(socket){
|
|
|
|
console.log('+ User connected');
|
|
console.log('');
|
|
|
|
// Rooms (joining, creating, etc)
|
|
socket.on('requestRooms', function(filter) {
|
|
rooms.requestRooms(socket, io, filter);
|
|
});
|
|
|
|
socket.on('requestJoinRoom', function(playerName, roomId) {
|
|
rooms.requestJoinRoom(socket, io, playerName, roomId);
|
|
});
|
|
|
|
socket.on('requestCreateRoom', function(playerName) {
|
|
rooms.requestCreateRoom(socket, io, playerName);
|
|
});
|
|
|
|
// Game (actual things relating to the game)
|
|
|
|
}
|
|
|