server.js.map 20 KB

1
  1. {"version":3,"sources":["../src/server.js"],"names":["Server","console","log","io","require","server","listen","mariadbConn","MariadbConnector","gamesManager","GamesManager","authorizedPlayers","Map","connectedPlayers","authorizedPlayersNames","Set","on","socket","id","reason","username","get","player","removeAllGamesCreatedByPlayer","then","res","affectedRows","forceClientsReloadGames","catch","err","message","isPlayingGameId","playerLeft","delete","setConnected","setSocket","playerName","callback","updatePlayersFromDb","response","kickout","has","isConnected","getSocket","connected","disconnect","set","setTimeout","getJoinableGames","games","game","addGameDb","addPlayerInGame","deck","advRules","gameDetails","result","joinCreatedGame","getUsernames","usernames","forEach","name","PlayerId","Error","getCurrentListAuthorizedPlayers","addPlayerDb","addPlayer","add","JSON","stringify","removePlayerDb","removePlayer","addNewGame","removeGameDb","method","removeGameById","removeGamesByPlayer1","removeGamesByPlayerAny","removeGamesByStatus","removeGamesByDays","removeFinishedGamesByDays","getJoinableGamesForPlayer","removeCreatedGamesByPlayer1","emit","serverToolListner","ServerToolListner"],"mappings":"AAAA;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;AAEA,SAASA,MAAT,GAAkB;AAChBC,EAAAA,OAAO,CAACC,GAAR,CAAY,2BAAZ;;AAEA,MAAMC,EAAE,GAAGC,OAAO,CAAC,WAAD,CAAlB;;AACA,MAAMC,MAAM,GAAGF,EAAE,CAACG,MAAH,CAAU,IAAV,CAAf;AAEA,MAAIC,WAAW,GAAG,IAAIC,yBAAJ,EAAlB;AACA,MAAIC,YAAY,GAAG,IAAIC,qBAAJ,CAAiBL,MAAjB,EAAyBE,WAAzB,CAAnB;AAEA,MAAII,iBAAiB,GAAG,IAAIC,GAAJ,EAAxB;AACA,MAAIC,gBAAgB,GAAG,IAAID,GAAJ,EAAvB;AACA,MAAIE,sBAAsB,GAAG,IAAIC,GAAJ,EAA7B;AAEAV,EAAAA,MAAM,CAACW,EAAP,CAAU,YAAV,EAAwB,UAASC,MAAT,EAAiB;AACvChB,IAAAA,OAAO,CAACC,GAAR,CAA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HY;;AAAA;AAAA;AAAA;AAKnBhD,cAAAA,OAAO,CAACC,GAAR,CAAY,+CAAZ;AALmB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAH;;AAAA,oBAAhB8C,gBAAgB;AAAA;AAAA;AAAA,KAApB;;AAUA,MAAIzB,6BAA6B;AAAA,yFAAG,mBAAea,UAAf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBACf7B,WAAW,CAAC2E,2BAAZ,CAAwC9C,UAAxC,CADe;;AAAA;AAC9BoB,cAAAA,MAD8B;AAAA,iDAE3BA,MAF2B;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAAH;;AAAA,oBAA7BjC,6BAA6B;AAAA;AAAA;AAAA,KAAjC;;AAKA,MAAII,uBAAuB,GAAG,SAA1BA,uBAA0B,GAAW;AACvCtB,IAAAA,MAAM,CAAC8E,IAAP,CAAY,mBAAZ;AACD,GAFD;;AAIA,SAAO;AACL7C,IAAAA,mBAAmB,EAAnBA,mBADK;AAEL0B,IAAAA,+BAA+B,EAA/BA,+BAFK;AAGLC,IAAAA,WAAW,EAAXA,WAHK;AAILK,IAAAA,cAAc,EAAdA,cAJK;AAKLnB,IAAAA,SAAS,EAATA,SALK;AAMLsB,IAAAA,YAAY,EAAZA,YANK;AAOLzB,IAAAA,gBAAgB,EAAhBA;AAPK,GAAP;AASD;;AAED,IAAI3C,MAAM,GAAG,IAAIL,MAAJ,EAAb;AAEA,IAAIoF,iBAAiB,GAAG,IAAIC,2BAAJ,CAAsBhF,MAAtB,CAAxB;AACA+E,iBAAiB,CAAC9E,MAAlB,CAAyB,IAAzB","sourcesContent":["'use strict';\nimport PlayerId from './players/player-id';\nimport GamesManager from './game-server/games-manager';\nimport MariadbConnector from './db/mariadb-connector';\nimport ServerToolListner from './tools/server-tool-listener';\n\nfunction Server() {\n console.log('Starting 12 heroes server');\n\n const io = require('socket.io');\n const server = io.listen(2610);\n\n let mariadbConn = new MariadbConnector();\n let gamesManager = new GamesManager(server, mariadbConn);\n\n let authorizedPlayers = new Map();\n let connectedPlayers = new Map();\n let authorizedPlayersNames = new Set();\n\n server.on('connection', function(socket) {\n console.log('A player connected with id : ' + socket.id);\n\n socket.on('disconnect', reason => {\n console.log('A player disconnected, reason : ' + reason);\n if (\n reason === 'client namespace disconnect' ||\n reason === 'server namespace disconnect' ||\n reason === 'transport close'\n ) {\n let username = connectedPlayers.get(socket.id);\n if (username) {\n let player = authorizedPlayers.get(username);\n\n // If player had created a game, remove it\n removeAllGamesCreatedByPlayer(username)\n .then(res => {\n if (res.affectedRows > 0) {\n // Tell other clients to reload their games if there were\n forceClientsReloadGames();\n }\n })\n .catch(err => console.log('Error removing game :>> ', err.message));\n // Tell game manager a player left, if he was playing\n if (player.isPlayingGameId >= 0) {\n gamesManager.playerLeft(player, true);\n }\n connectedPlayers.delete(socket.id);\n player.setConnected(false);\n player.setSocket(null);\n console.log(username + ' disconnected');\n }\n }\n });\n socket.on('connect', () => {\n console.log('Connected to server');\n });\n socket.on('auth', async (playerName, callback) => {\n console.log(' Received auth message, player name : ' + playerName);\n await updatePlayersFromDb();\n\n let response = {};\n let kickout = false;\n if (!authorizedPlayersNames.has(playerName)) {\n response = {\n res: 'ko',\n message: playerName + ' Not found'\n };\n kickout = true;\n }\n // If the player is already connected and active\n else if (\n authorizedPlayers.get(playerName).isConnected() &&\n authorizedPlayers.get(playerName).getSocket().connected\n ) {\n response = {\n res: 'ko',\n message: playerName + ' already connected'\n };\n kickout = true;\n } else {\n // Player marked as connected but socket is down, clean it\n if (authorizedPlayers.get(playerName).isConnected()) {\n authorizedPlayers\n .get(playerName)\n .getSocket()\n .disconnect(true);\n } else {\n // In case server did not detect disconnection and did not clean the pending created games\n try {\n await removeAllGamesCreatedByPlayer(playerName);\n } catch (err) {\n console.log('Error removing games : ' + err.message);\n }\n }\n response = {\n res: 'ok',\n message: playerName + ' connected'\n };\n authorizedPlayers.get(playerName).setConnected(true);\n authorizedPlayers.get(playerName).setSocket(socket);\n connectedPlayers.set(socket.id, playerName);\n }\n\n callback(response);\n if (kickout === true) {\n setTimeout(() => {\n socket.disconnect(true);\n }, 600);\n }\n });\n\n socket.on('games-list', async (playerName, callback) => {\n console.log(' Received games-list message, player name : ' + playerName);\n let response = {};\n try {\n let games = await getJoinableGames(playerName);\n response = {\n res: 'ok',\n message: games\n };\n } catch (error) {\n response = {\n res: 'ko',\n message: 'Error from server'\n };\n }\n callback(response);\n });\n\n socket.on('create-game', async (game, callback) => {\n let response = {};\n try {\n let id = await addGameDb(game);\n response = {\n res: 'ok',\n message: id\n };\n gamesManager.addPlayerInGame(\n authorizedPlayers.get(connectedPlayers.get(socket.id)),\n id,\n false,\n true,\n { deck: game.deck, advRules: game.advRules }\n );\n console.log('Force all clients to reload their games');\n forceClientsReloadGames();\n } catch (error) {\n console.log('error in create-game:>> ', error);\n response = {\n res: 'ko',\n message: 'Error from server'\n };\n }\n callback(response);\n });\n\n socket.on('join-game', async (gameDetails, callback) => {\n let result = gamesManager.addPlayerInGame(\n authorizedPlayers.get(connectedPlayers.get(socket.id)),\n gameDetails.id,\n gameDetails.joinCreatedGame\n );\n let response = {};\n if (result === true) {\n response.res = 'ok';\n response.message = 'Game joined';\n } else {\n response.res = 'ko';\n response.message = 'Unable to join game';\n }\n callback(response);\n });\n\n socket.on('leave-game', async (username, callback) => {\n // Remove player from game he is playing\n try {\n let res = removeAllGamesCreatedByPlayer(username);\n if (res.affectedRows > 0) {\n forceClientsReloadGames();\n }\n } catch (err) {\n console.log('Error removing games : ' + err.message);\n }\n gamesManager.playerLeft(authorizedPlayers.get(username), false);\n callback(true);\n });\n });\n\n let updatePlayersFromDb = async function() {\n try {\n let usernames = await mariadbConn.getUsernames();\n authorizedPlayersNames = new Set(usernames);\n console.log('authorizedPlayersNames update : ', authorizedPlayersNames);\n authorizedPlayersNames.forEach(name => {\n if (!authorizedPlayers.has(name)) {\n console.log('New username authorized :', name);\n authorizedPlayers.set(name, new PlayerId(name));\n }\n });\n return 'ok';\n } catch (error) {\n console.log('Error getting usernames from DB : ', error);\n return error.Error;\n }\n };\n\n let getCurrentListAuthorizedPlayers = function() {\n return [...authorizedPlayersNames];\n };\n let addPlayerDb = async function(username) {\n console.log('add player in db : ' + username);\n try {\n let response = await mariadbConn.addPlayer(username);\n authorizedPlayersNames.add(username);\n authorizedPlayers.set(username, new PlayerId(username));\n return 'OK ' + JSON.stringify(response);\n } catch (err) {\n return 'KO ' + err.message;\n }\n };\n let removePlayerDb = async function(username) {\n console.log('remove player in db : ' + username);\n try {\n let response = await mariadbConn.removePlayer(username);\n authorizedPlayersNames.delete(username);\n authorizedPlayers.delete(username);\n return 'OK ' + JSON.stringify(response);\n } catch (err) {\n return 'KO ' + err.message;\n }\n };\n\n let addGameDb = async function(game) {\n try {\n let response = await mariadbConn.addNewGame(game);\n return response;\n } catch (err) {\n console.log('KO ' + err.message);\n throw err;\n }\n };\n\n let removeGameDb = async function(method, ...args) {\n try {\n let response;\n switch (method) {\n case 'byId':\n response = await mariadbConn.removeGameById(args[0]);\n break;\n case 'byPlayer1':\n response = await mariadbConn.removeGamesByPlayer1(args[0]);\n break;\n case 'byPlayerAny':\n response = await mariadbConn.removeGamesByPlayerAny(args[0]);\n break;\n case 'byStatus':\n response = await mariadbConn.removeGamesByStatus(args[0]);\n break;\n case 'byDays':\n response = await mariadbConn.removeGamesByDays(args[0]);\n break;\n case 'finishedByDays':\n response = await mariadbConn.removeFinishedGamesByDays(args[0]);\n break;\n\n default:\n return 'KO : Unknown method to remove game from DB : ' + method;\n }\n return 'OK ' + JSON.stringify(response);\n } catch (err) {\n return 'KO ' + err.message;\n }\n };\n\n let getJoinableGames = async function(username) {\n try {\n let games = await mariadbConn.getJoinableGamesForPlayer(username);\n return games;\n } catch (err) {\n console.log('KO : not able to get games : ' + err);\n throw err;\n }\n };\n\n let removeAllGamesCreatedByPlayer = async function(playerName) {\n let result = await mariadbConn.removeCreatedGamesByPlayer1(playerName);\n return result;\n };\n\n let forceClientsReloadGames = function() {\n server.emit('reload-games-list');\n };\n\n return {\n updatePlayersFromDb,\n getCurrentListAuthorizedPlayers,\n addPlayerDb,\n removePlayerDb,\n addGameDb,\n removeGameDb,\n getJoinableGames\n };\n}\n\nlet server = new Server();\n\nlet serverToolListner = new ServerToolListner(server);\nserverToolListner.listen(1664);\n"],"file":"server.js"}