From 6b59f6de17361fbdbee35cc7e93bb34e1af8bf60 Mon Sep 17 00:00:00 2001 From: Thibault Coupin Date: Thu, 19 Mar 2020 23:20:05 +0100 Subject: [PATCH 1/2] Connect to 20Minutes, web socket on same port --- conf.json | 12 ++---- game_files/gridManager.js | 62 +++++++++++++++++++++------- game_files/motsFleches.js | 10 ++++- public/javascripts/game/UITools.js | 23 +---------- public/javascripts/game/grid.js | 9 +++- public/javascripts/game/mflEngine.js | 2 +- public/stylesheets/mfl.css | 26 ++++++++++-- server.js | 27 ++++-------- views/mfl.jade | 3 +- 9 files changed, 100 insertions(+), 74 deletions(-) diff --git a/conf.json b/conf.json index 46688e3..09b2457 100644 --- a/conf.json +++ b/conf.json @@ -1,14 +1,10 @@ { "SERVER_PORT": 2121, - "SOCKET_ADDR": "http://127.0.0.1", - "SOCKET_PORT": 1337, - "GRID_PROVIDER": { - "PROVIDER_NAME": "Metro", - "PROVIDER_ADDR": "https://www.rci-jeux.com/ope/metro/mfleches/data/mfl", - "PROVIDER_EXTENSION": ".mfl", - "PROVIDER_DEFAULT_GRID": 1215, - "PROVIDER_DEFAULT_GRID_DATE": 1400277600000 + "PROVIDER_NAME": "20 Minutes", + "PROVIDER_ADDR": "https://rcijeux.fr/drupal_game/20minutes/grids/", + "PROVIDER_EXTENSION": ".mfj", + "PROVIDER_LIST_GAMES": "https://rcijeux.fr/drupal_game/20minutes/menu/js/jeux_mfleches.js" } } diff --git a/game_files/gridManager.js b/game_files/gridManager.js index 1f0b728..f1100c8 100644 --- a/game_files/gridManager.js +++ b/game_files/gridManager.js @@ -104,8 +104,50 @@ function parseGrid(callback, serverText) { nbWords: 0, cases: [] }; + + eval(serverText); // Parse and evaluate js, generate variable gamedata + + grid.level = gamedata.force; + _gridInfos.level = gamedata.force; + + grid.nbWords = gamedata.definitions.length; + _gridInfos.nbWords = gamedata.definitions.length; + + grid.nbLines = gamedata.nbcaseshauteur; + grid.nbColumns = gamedata.nbcaseslargeur; + + // Load letters + for (i in gamedata.grille){ + for (j in gamedata.grille[i]){ + type = getCaseType(gamedata.grille[i][j]); + if (type == enums.CaseType.Letter) { + grid.cases.push(new Case.LetterCase(currentCase++, gamedata.grille[i][j])); + _nbLetters++; + } else if (type == enums.CaseType.Description) { + grid.cases.push(new Case.DescriptionCase(currentCase++, gamedata.grille[i][j])); + } else { + grid.cases.push(new Case.EmptyCase(currentCase++)); + } + } + } - // Initial sort. Isolate each "line" by spliting on '&' char + // Add descriptions + for (var i in gamedata.definitions){ + insertDescription(grid, gamedata.definitions[i].join('\n')); + } + + // Add dotted + for (var i in gamedata.spountzV){ + var nb = (gamedata.spountzV[i][0]-1)*grid.nbColumns + gamedata.spountzV[i][1]; + grid.cases[nb - 1].dashed = 2; + } + for (var i in gamedata.spountzV){ + var nb = (gamedata.spountzV[i][0]-1)*grid.nbColumns + gamedata.spountzV[i][1]; + grid.cases[nb - 1].dashed = 1; + } + /* + /////////////////////OLD//////////////////////////////////// + // Initial sort. Isolate each "line" by spliting on '\n' char stArray = serverText.split('&'); // Then parse each line @@ -179,7 +221,7 @@ function parseGrid(callback, serverText) { } } }; - + */ // Once the entire grid is retreived, place arrows placeArrows(grid); @@ -219,6 +261,7 @@ function placeArrows(grid) { case 'k': case 'l': case 'm': + case 'n': grid.cases[i].arrow[0] = enumArrow.RightBottom; grid.cases[i].arrow[1] = enumArrow.Bottom; break; @@ -244,26 +287,15 @@ function placeArrows(grid) { function getGridAddress(commandArgv) { var gridNumber, today, - gridDefaultDay, dayDiff; switch (commandArgv) { // No number given, load day grid case 0: + case -1: console.info('\n\t[GRIDMANAGER] Load day grid'); - // Compare the default date with today. Add this difference to the default grid number. Assume that we have one grid per day ! - gridDefaultDay = new Date(config.PROVIDER_DEFAULT_GRID_DATE); today = new Date(); - dayDiff = Math.abs(today.getTime() - gridDefaultDay.getTime()); - dayDiff = Math.floor(dayDiff / (1000 * 3600 * 24)); - // gridNumber = config.PROVIDER_DEFAULT_GRID + dayDiff; - gridNumber = config.PROVIDER_DEFAULT_GRID; - break; - - // Retreive the default grid - case -1: - console.info('\n\t[GRIDMANAGER] Load default grid'); - gridNumber = config.PROVIDER_DEFAULT_GRID; + gridNumber = ("0"+today.getDate()).substr(-2) + ("0"+(today.getMonth()+1)).substr(-2) + (""+today.getFullYear()).substr(-2) break; // Load the specified grid diff --git a/game_files/motsFleches.js b/game_files/motsFleches.js index 3700081..76134cc 100644 --- a/game_files/motsFleches.js +++ b/game_files/motsFleches.js @@ -170,6 +170,12 @@ function checkServerCommand(message) { return (true); } + // Check the change grid command + if (message.indexOf('!stop') >= 0) { + resetGame(0); + return (true); + } + return (false); } @@ -190,9 +196,9 @@ function sendPlayerMessage(socket, Message) { /** * Start mfl server. */ -exports.startMflServer = function (desiredGrid) { +exports.startMflServer = function (server, desiredGrid) { // Instanciiate io module with proper parameters - _io = require('socket.io').listen(config.SOCKET_PORT); + _io = require('socket.io').listen(server); _io.configure(function(){ _io.set('log level', 2); }); diff --git a/public/javascripts/game/UITools.js b/public/javascripts/game/UITools.js index 098fe64..a996feb 100644 --- a/public/javascripts/game/UITools.js +++ b/public/javascripts/game/UITools.js @@ -12,27 +12,6 @@ define(function () { } - function injectInGameInfoPanel() { - var emptyNodes = document.querySelectorAll('.empty'), - square = { - x: 0, - y: 0, - width: 0, - height: 0, - }; - - // Find an available space within empty spaces (fuck the ads !!!) - if (emptyNodes) { - square.x = emptyNodes[0].offsetLeft; - square.y = emptyNodes[0].offsetTop; - square.width = emptyNodes[emptyNodes.length - 1].offsetLeft + emptyNodes[emptyNodes.length - 1].offsetWidth - square.x; - square.height = emptyNodes[emptyNodes.length - 1].offsetTop + emptyNodes[emptyNodes.length - 1].offsetHeight - square.y; - - // Now put the info panel on the grid - document.getElementById('gs-grid-container').innerHTML += '
'; - } - } - function formatTime(ellapsedTime) { var m = Math.floor(ellapsedTime / 60), s = ellapsedTime % 60, @@ -155,7 +134,7 @@ define(function () { time = 0; // First inject the game info panel - injectInGameInfoPanel(); + //injectInGameInfoPanel(); // Retreive time node and inject timer timeNode = document.querySelector('#ig-infos > time'); diff --git a/public/javascripts/game/grid.js b/public/javascripts/game/grid.js index e164e52..d8cbb3b 100644 --- a/public/javascripts/game/grid.js +++ b/public/javascripts/game/grid.js @@ -74,6 +74,11 @@ define(['cursor'], function (Cursor) { fontSize = Math.round(lineHeight / 1.5); break; + case 5: + lineHeight = Math.floor(size / info.nbLines); + fontSize = Math.round(lineHeight / 1.2); + break; + default: console.log('[ERROR][grid.js] Don\'t know how to display ' + info.nbLines + ' lines frame !!!'); } @@ -274,7 +279,7 @@ define(['cursor'], function (Cursor) { line, col, nbFrames = _grid.cases.length, i; - + console.log(_grid) // First we have to retreive the min size to display the grid limit = (container.offsetWidth < container.offsetHeight) ? container.offsetWidth : container.offsetHeight; // console.log('Plus petit cote: ' + limit); @@ -287,7 +292,7 @@ define(['cursor'], function (Cursor) { // For each frame for (i = 0; i < nbFrames; i++) { // Get line and col - line = Math.floor(i / _grid.nbLines); + line = Math.floor(i / _grid.nbColumns); col = i % _grid.nbColumns; // Insert frame diff --git a/public/javascripts/game/mflEngine.js b/public/javascripts/game/mflEngine.js index b751d05..1eb6477 100644 --- a/public/javascripts/game/mflEngine.js +++ b/public/javascripts/game/mflEngine.js @@ -39,7 +39,7 @@ require(['../lib/text!../../conf.json', 'UITools', 'grid', 'chat', 'score'], fun _scoreManager = new Score(); // document.getElementById('gs-loader-text').innerHTML = 'Connecting to the server...'; - _socket = io.connect((Conf.SOCKET_ADDR + ':' + Conf.SOCKET_PORT), { reconnect: false }); + _socket = io.connect(location.protocol + "//" + location.hostname, { reconnect: false }); _socket.on('connect', function() { console.log('Connection established :)'); diff --git a/public/stylesheets/mfl.css b/public/stylesheets/mfl.css index 4cb49bc..7e3f95a 100644 --- a/public/stylesheets/mfl.css +++ b/public/stylesheets/mfl.css @@ -339,7 +339,7 @@ html, body { width: -webkit-calc(100% - 1200px); width: -moz-calc(100% - 1200px); width: calc(100% - 1200px); - height: 100%; + height: 90%; background-image: url('../images/green-bg.png'); } @@ -369,7 +369,17 @@ html, body { width: -webkit-calc(100% - 900px); width: -moz-calc(100% - 900px); width: calc(100% - 900px); - height: 70%; + height: 60%; + } + #ig-infos { + position: relative; + + float: left; + + width: -webkit-calc(100% - 900px) !important; + width: -moz-calc(100% - 900px) !important; + width: calc(100% - 900px) !important; + height: 10%; } } @@ -474,6 +484,7 @@ html, body { .empty { border: none; + background-color: gray; } .focusCell { @@ -634,14 +645,21 @@ html, body { | | \*=====================*/ #ig-infos { - position: absolute; color: #ecf0f1; text-shadow: 2px 2px 5px #2c3e50; text-align: center; - background-image: url('../images/green-bg.png'); overflow: hidden; + + float: left; + + width: -webkit-calc(100% - 1200px); + width: -moz-calc(100% - 1200px); + width: calc(100% - 1200px); + height: 10%; + + background-image: url('../images/green-bg.png'); } #ig-infos > header { position: relative; diff --git a/server.js b/server.js index 4d2a431..777f0c9 100644 --- a/server.js +++ b/server.js @@ -38,7 +38,9 @@ app.get('/conf.json', function(req, res) { }); // Start server -http.createServer(app).listen(app.get('port'), onServerReady); +var server = http.createServer(app); + + // Retreive command line arguments if (process.argv[2]) { @@ -50,32 +52,19 @@ if (process.argv[2]) { _gridNumber = process.argv[2]; } +mfl.startMflServer(server, _gridNumber); + +server.listen(app.get('port'), onServerReady); + /** Call when the express server has started */ async function onServerReady() { console.log('Express server listening on port ' + app.get('port')); - var addresses = getLocalIpAddresses(); - - if (addresses.length > 1) { - var response = await prompts({ - type: 'select', - name: 'value', - message: 'Choose the IP address to use', - choices: addresses, - }); - - // Update socket address with the choosen one - config.SOCKET_ADDR = `http://${addresses[response.value]}`; - } - else { - config.SOCKET_ADDR = `http://${addresses[0]}`; - } - console.log(`\n\n\tWaiting for players at ${config.SOCKET_ADDR}:${config.SERVER_PORT}\n\n`); // Load desired grid in parameter. // -1 to retreive the day grid, 0 for the default one or any number for a special one - mfl.startMflServer(_gridNumber); + } /** Get local ip addresses */ diff --git a/views/mfl.jade b/views/mfl.jade index f76e7f4..626785f 100644 --- a/views/mfl.jade +++ b/views/mfl.jade @@ -1,7 +1,7 @@ doctype html html head - script(type='text/javascript', src=wsAddress + '/socket.io/socket.io.js'). + script(type='text/javascript', src='/socket.io/socket.io.js'). @@ -49,6 +49,7 @@ html
+
From a7eacbdc139ded5f72bec379ba0dca9e9edbd55a Mon Sep 17 00:00:00 2001 From: Thibault Coupin Date: Thu, 19 Mar 2020 23:42:31 +0100 Subject: [PATCH 2/2] fix dash --- game_files/gridManager.js | 6 +++--- public/stylesheets/mfl.css | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/game_files/gridManager.js b/game_files/gridManager.js index f1100c8..c2e5f04 100644 --- a/game_files/gridManager.js +++ b/game_files/gridManager.js @@ -138,11 +138,11 @@ function parseGrid(callback, serverText) { // Add dotted for (var i in gamedata.spountzV){ - var nb = (gamedata.spountzV[i][0]-1)*grid.nbColumns + gamedata.spountzV[i][1]; + var nb = gamedata.spountzV[i][0] + (gamedata.spountzV[i][1]-1)*grid.nbColumns; grid.cases[nb - 1].dashed = 2; } - for (var i in gamedata.spountzV){ - var nb = (gamedata.spountzV[i][0]-1)*grid.nbColumns + gamedata.spountzV[i][1]; + for (var i in gamedata.spountzH){ + var nb = gamedata.spountzH[i][0] + (gamedata.spountzH[i][1]-1)*grid.nbColumns; grid.cases[nb - 1].dashed = 1; } /* diff --git a/public/stylesheets/mfl.css b/public/stylesheets/mfl.css index 7e3f95a..0bb581a 100644 --- a/public/stylesheets/mfl.css +++ b/public/stylesheets/mfl.css @@ -479,8 +479,8 @@ html, body { line-height: 21px; } -.dash1 { border-bottom: 1px dashed rgba(127, 140, 141, 0.2); } -.dash2 { border-right: 1px dashed rgba(127, 140, 141, 0.2); } +.dash1 { border-bottom: 1.5px dashed rgba(127, 140, 141, 0.7); } +.dash2 { border-right: 1.5px dashed rgba(127, 140, 141, 0.7); } .empty { border: none;