Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var io = require('socket.io')(process.env.PORT || 80);
- var shortid = require('shortid');
- var fs = require('fs');
- console.log('Server started');
- var playerCount = 0;
- io.on('connection', function(socket) {
- var thisClientId = shortid.generate();
- io.sockets.emit('start');
- var text = 'Client connected, broadcasting spawn, id:' + thisClientId;
- fs.writeFileSync('writeme.txt', text);
- console.log('Client connected, broadcasting spawn, id:', thisClientId);
- socket.emit('new', {uid: thisClientId});
- playerCount++;
- if (playerCount == 2) {
- io.sockets.emit('start');
- console.log('Started game');
- playerCount = 0;
- }
- });
Add Comment
Please, Sign In to add comment