From a804b4acd23055e2b260829a416b1cb90d60e4e9 Mon Sep 17 00:00:00 2001 From: tannerkrewson Date: Tue, 26 Jul 2016 02:05:43 -0500 Subject: [PATCH] Enforce stricter name length limit --- public/js/client.js | 6 ++++++ routes/socketio.js | 8 ++++---- views/index.jade | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/js/client.js b/public/js/client.js index d4055fbd..40713673 100644 --- a/public/js/client.js +++ b/public/js/client.js @@ -217,6 +217,7 @@ function JoinMenu(onBack) { this.id = '#joinmenu'; this.backButton = $('#joinmenu-back'); this.goButton = $('#joinmenu-go'); + this.codeInput = $('#joinincode'); this.onBack = onBack; Screen.prototype.setDefaultTitles.call(this); @@ -236,6 +237,11 @@ JoinMenu.prototype.initialize = function() { }); }); + var self = this; + this.codeInput.on('keyup', function(e) { + self.codeInput.val(self.codeInput.val().toLowerCase()); + }); + Screen.prototype.setDefaultTitles.call(this); } diff --git a/routes/socketio.js b/routes/socketio.js index 2a96be1e..f6669f0f 100644 --- a/routes/socketio.js +++ b/routes/socketio.js @@ -10,7 +10,7 @@ module.exports = function(app){ socket.on('joinGame', onJoinGame); socket.on('newGame', function(data) { - if (data.name.length > 1) { + if (data.name.length > 2 && data.name.length <= 16) { thisGame = dp.newGame(); thisUser = thisGame.addPlayer(data.name, socket); socket.emit('joinGameRes', { @@ -21,7 +21,7 @@ module.exports = function(app){ } else { socket.emit('joinGameRes', { success: false, - error: 'Failed to join game' + error: 'Name too short/long' }) } }); @@ -59,10 +59,10 @@ module.exports = function(app){ success: false, error: 'Game not found' }); - } else if (data.name.length < 1) { + } else if (data.name.length <= 2 || data.name.length > 16) { socket.emit('joinGameRes', { success: false, - error: 'Name too short' + error: 'Name too short/long' }); } else { if (!thisGame.inProgress) { diff --git a/views/index.jade b/views/index.jade index 22ac87f7..12b9245e 100644 --- a/views/index.jade +++ b/views/index.jade @@ -16,16 +16,16 @@ block content div#joinmenu.hidden form .form-group - input#joinincode.form-control(type='text', placeholder='Enter the game code', maxlength=4) + input#joinincode.form-control(type='text', placeholder='Enter the game code', maxlength=4, autocomplete='off') .form-group - input#joininname.form-control(type='text', placeholder='Enter your name') + input#joininname.form-control(type='text', placeholder='Enter your name', maxlength=16) .btn-toolbar button#joinmenu-back.btn.btn-default.btn-lg(type='button') Back button#joinmenu-go.btn.btn-default.btn-lg(type='submit') Join div#newmenu.hidden form .form-group - input#newinname.form-control(type='text', placeholder='Enter your name') + input#newinname.form-control(type='text', placeholder='Enter your name', maxlength=16) .btn-toolbar button#newmenu-back.btn.btn-default.btn-lg(type='button') Back button#newmenu-go.btn.btn-default.btn-lg(type='submit') Start