-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
|
||
"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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,8 +104,50 @@ function parseGrid(callback, serverText) { | |
nbWords: 0, | ||
cases: [] | ||
}; | ||
|
||
eval(serverText); // Parse and evaluate js, generate variable gamedata | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'avais compris que Metro ne fonctionnait plus... 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 | ||
|
@@ -179,7 +221,7 @@ function parseGrid(callback, serverText) { | |
} | ||
} | ||
}; | ||
|
||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,27 +12,6 @@ define(function () { | |
} | ||
|
||
|
||
function injectInGameInfoPanel() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 😃) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
|
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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