Skip to content

Commit

Permalink
Enforce stricter name length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerkrewson committed Jul 26, 2016
1 parent 352a96d commit a804b4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions routes/socketio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -21,7 +21,7 @@ module.exports = function(app){
} else {
socket.emit('joinGameRes', {
success: false,
error: 'Failed to join game'
error: 'Name too short/long'
})
}
});
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a804b4a

Please sign in to comment.