Guest User

Untitled

a guest
Jun 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. var io = require('socket.io')(process.env.PORT || 80);
  2. var shortid = require('shortid');
  3. var fs = require('fs');
  4.  
  5. console.log('Server started');
  6.  
  7. var playerCount = 0;
  8.  
  9. io.on('connection', function(socket) {
  10. var thisClientId = shortid.generate();
  11.  
  12. io.sockets.emit('start');
  13.  
  14. var text = 'Client connected, broadcasting spawn, id:' + thisClientId;
  15. fs.writeFileSync('writeme.txt', text);
  16. console.log('Client connected, broadcasting spawn, id:', thisClientId);
  17.  
  18. socket.emit('new', {uid: thisClientId});
  19. playerCount++;
  20.  
  21. if (playerCount == 2) {
  22. io.sockets.emit('start');
  23. console.log('Started game');
  24. playerCount = 0;
  25. }
  26. });
Add Comment
Please, Sign In to add comment