Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect to 20Minutes, web socket on same port #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions conf.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"SERVER_PORT": 2121,

"SOCKET_ADDR": "http://127.0.0.1",
"SOCKET_PORT": 1337,
Comment on lines -4 to -5
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu commentes ça, les autres joueurs ne pourront plus se connecter non ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ils pourront car la socket.io utilise le même port que le web "standard" cf https://github.com/tcoupin/mots/blob/master/game_files/motsFleches.js#L201


"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"
}
}
62 changes: 47 additions & 15 deletions game_files/gridManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,50 @@ function parseGrid(callback, serverText) {
nbWords: 0,
cases: []
};

eval(serverText); // Parse and evaluate js, generate variable gamedata
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce qui me dérange un peu avec cette approche, c'est qu'on enlève complètement la possibilité d'avoir les grilles du Metro pour le remplacer par celles du 20mn.

Plutôt que de perdre tout un provider, penses-tu que tu pourrais extraire les 2 logique dans 2 fichiers séparés ? Ainsi le gridManager irait lire quel est le provider dans le fichier de config et chargerait le bon loader de grille selon qu'on veuille jouer Metro ou 20mn !

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'avais compris que Metro ne fonctionnait plus...
On pourrait effectivement garder les 2 formats, je viens d'ailleurs de voir que NotreTemps utilisait aussi ce format : https://rcijeux.fr/drupal_game/notretemps/mfleches/grids/mfleches_1_1730.mfj

Potentiellement beaucoup de grille :)


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] + (gamedata.spountzV[i][1]-1)*grid.nbColumns;
grid.cases[nb - 1].dashed = 2;
}
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;
}
/*
/////////////////////OLD////////////////////////////////////
// Initial sort. Isolate each "line" by spliting on '\n' char
stArray = serverText.split('&');

// Then parse each line
Expand Down Expand Up @@ -179,7 +221,7 @@ function parseGrid(callback, serverText) {
}
}
};

*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Donc toute cette "logique Metro" se trouverait dans un autre fichier aussi...

// Once the entire grid is retreived, place arrows
placeArrows(grid);

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions game_files/motsFleches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
});
Expand Down
23 changes: 1 addition & 22 deletions public/javascripts/game/UITools.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@ define(function () {
}


function injectInGameInfoPanel() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Donc y a pas d'infos du jeu avec 20mn (j'ai pas encore pu tester 😃) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le soucis c'est que 20minutes a 2 panneaux dans ses grilles et que la div créée recouvre l'ensemble donc cache des cases. J'ai passé du temps à essayer de détecter des groupes de cases pour faire 2 div mais je n'ai pas réussi. Du coups j'ai préféré mettre les cases en gris et déplacé le panneau d'info sous les scores

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 += '<div id="ig-infos" style="left: ' + square.x + 'px; top: ' + square.y + 'px; width: ' + square.width + 'px; height: ' + square.height + 'px;"><header></header><time></time><footer></footer></div>';
}
}

function formatTime(ellapsedTime) {
var m = Math.floor(ellapsedTime / 60),
s = ellapsedTime % 60,
Expand Down Expand Up @@ -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');
Expand Down
9 changes: 7 additions & 2 deletions public/javascripts/game/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 !!!');
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/game/mflEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 :)');
Expand Down
30 changes: 24 additions & 6 deletions public/stylesheets/mfl.css
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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%;
}
}

Expand Down Expand Up @@ -469,11 +479,12 @@ 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;
background-color: gray;
}

.focusCell {
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 8 additions & 19 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi enlever cette feature ? Est ce que t'héberges le jeu quelque part ? Si oui je veux l'adresse 😄 !!

Mais sinon d'un point de vue fonctionnalités, faut laisser aux gens la possibilité de le lancer en local. Je te proposerai plutôt encore une fois de laisser une option dans le fichier de configuration qui force une adresse et bypass ce choix par défaut.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parce que je travaille avec Docker qui isole le processus et la partie réseau. De toute façon cette fonction n'était utile que pour la websocket qui est fusionée avec l'app expressjs. Et l'app expressjs écoutait déjà sur toutes les ips


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 */
Expand Down
3 changes: 2 additions & 1 deletion views/mfl.jade
Original file line number Diff line number Diff line change
@@ -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').

<link href="/images/favicon.ico" rel="icon" type="image/ico" />
<meta charset='utf-8'>
Expand Down Expand Up @@ -49,6 +49,7 @@ html
<section id="gs-grid-container"></section>

<section id="gs-scores"></section>
<div id="ig-infos" ><header></header><time></time><footer></footer></div>

</div>

Expand Down