123456789101112131415161718192021222324252627282930313233 |
- 'use strict';
- import PlayerId from './players/player-id';
- import DuelController from './game-server/duel-controller';
- const io = require('socket.io'); //(http)
- const server = io.listen(4000);
- let players = [];
- let addNewPlayer = function (playerSocket, playerName) {
- console.log('players length : ' + players.length + ' : ' + players);
- if (players.length < 2) {
- let newPlayer = new PlayerId(playerSocket,playerName);
- console.log('push player : ' + newPlayer);
- players.push(newPlayer);
- }
- if (players.length === 2) {
- let duelController = new DuelController(players[0], players[1]);
- }
- }
- server.on('connection', function (socket) {
- console.log("A player connected with id : " + socket.id);
- socket.on ('disconnect', () => {
- console.log("A player disconnected with id : " + socket.id);
- });
- socket.on('auth', (playerName) => {
- console.log(' Received auth message, player name : ' + playerName);
- addNewPlayer(socket, playerName);
- });
- })
|