diff --git a/backend.js b/backend.js index dc8dd90..8a92bd6 100644 --- a/backend.js +++ b/backend.js @@ -11,7 +11,7 @@ const io = new Server(server, { pingTimeout:5000 }) -var Filter = require('bad-words') +var Filter = require('./bad-words-hacked'); filter = new Filter(); // app.use(requireHTTPS); // Set 'SET NODE_ENV=development' in local computer before use @@ -46,6 +46,7 @@ io.on('connection', (socket)=>{ roomId:1, message:'', username:"Visitor", + skin:"Green", timeoutId:0 } //create player object with new socket id property @@ -73,11 +74,16 @@ io.on('connection', (socket)=>{ console.log("updated username for: "+bPlayers[socket.id].username) }) + socket.on('skin',(skin)=>{ + bPlayers[socket.id].skin = skin + console.log("updated skin for: "+bPlayers[socket.id].username) + }) + socket.on('message',(message)=>{ let timeoutId; clearTimeout(bPlayers[socket.id].timeoutId); - // bPlayers[socket.id].message = filter.clean(message) - bPlayers[socket.id].message = message + bPlayers[socket.id].message = filter.cleanHacked(message) + // bPlayers[socket.id].message = message function startTimer() { timeoutId = setTimeout(() => { diff --git a/bad-words-hacked.js b/bad-words-hacked.js new file mode 100644 index 0000000..4a8e5bc --- /dev/null +++ b/bad-words-hacked.js @@ -0,0 +1,19 @@ +// Emoji error fix from: https://github.com/web-mech/badwords/issues/93 + +const Filter = require('bad-words') + +class FilterHacked extends Filter { + cleanHacked(string) { + try { + return this.clean(string); + } catch { + const joinMatch = this.splitRegex.exec(string); + const joinString = (joinMatch && joinMatch[0]) || ''; + return string.split(this.splitRegex).map((word) => { + return this.isProfane(word) ? this.replaceWord(word) : word; + }).join(joinString); + } + } +} + +module.exports = FilterHacked \ No newline at end of file diff --git a/public/characterSprites/Red/Down.png b/public/characterSprites/Red/Down.png new file mode 100644 index 0000000..1193e10 Binary files /dev/null and b/public/characterSprites/Red/Down.png differ diff --git a/public/characterSprites/Red/Left.png b/public/characterSprites/Red/Left.png new file mode 100644 index 0000000..1193e10 Binary files /dev/null and b/public/characterSprites/Red/Left.png differ diff --git a/public/characterSprites/Red/Right.png b/public/characterSprites/Red/Right.png new file mode 100644 index 0000000..871eeef Binary files /dev/null and b/public/characterSprites/Red/Right.png differ diff --git a/public/characterSprites/Red/Up.png b/public/characterSprites/Red/Up.png new file mode 100644 index 0000000..871eeef Binary files /dev/null and b/public/characterSprites/Red/Up.png differ diff --git a/public/classes/Player.js b/public/classes/Player.js index 3bacfcf..f920bdf 100644 --- a/public/classes/Player.js +++ b/public/classes/Player.js @@ -1,7 +1,7 @@ class Player extends Sprite { - constructor({position,clickX,clickY,incrementX,incrementY,userId,username,message,atPosition,animationColumn,imageSrc,frames,center,sprites}){ - super({position,imageSrc,frames,center,atPosition,sprites}) + constructor({position,clickX,clickY,incrementX,incrementY,userId,username,skin,message,atPosition,animationColumn,imageSrc,frames,center,sprites}){ + super({position,imageSrc,frames,center,atPosition,sprites,skin}) // super({imageSrc}) this.clickX = clickX this.clickY = clickY diff --git a/public/classes/Sprite.js b/public/classes/Sprite.js index cb0f8d6..44fd5ab 100644 --- a/public/classes/Sprite.js +++ b/public/classes/Sprite.js @@ -21,7 +21,7 @@ class Sprite{ this.Left = new Image() this.Right = new Image() this.Up.src = sprites.up - this.Down.src = sprites.down + this.Down.src = sprites.down this.Left.src = sprites.left this.Right.src = sprites.right } diff --git a/public/index.js b/public/index.js index c23f4f6..2191dbc 100644 --- a/public/index.js +++ b/public/index.js @@ -78,17 +78,18 @@ socket.on('updatePlayers', (bPlayers) =>{ clickY:bPlayer.clickY, userId:id, username:'', + skin:bPlayer.skin, message:'', atPosition:true, animationColumn:0, - imageSrc:'characterSprites/Green/Down.png', + imageSrc:'characterSprites/' + bPlayer.skin + '/Down.png', frames: 7, center:true, sprites:{ - down:'characterSprites/Green/Down.png', - up:'characterSprites/Green/Up.png', - right:'characterSprites/Green/Right.png', - left:'characterSprites/Green/Left.png' + down:'characterSprites/' + bPlayer.skin + '/Down.png', + up:'characterSprites/' + bPlayer.skin + '/Up.png', + right:'characterSprites/' + bPlayer.skin + '/Right.png', + left:'characterSprites/' + bPlayer.skin + '/Left.png' } }) @@ -101,6 +102,7 @@ socket.on('updatePlayers', (bPlayers) =>{ fPlayers[id].clickY = bPlayer.clickY fPlayers[id].message = bPlayer.message fPlayers[id].username = bPlayer.username + fPlayers[id].skin = bPlayer.skin //update player position without animation if tab is inactive if (document.hidden) { @@ -205,6 +207,9 @@ document.querySelector('#textInput').addEventListener('submit',(event)=>{ }else if(inputValue==='/debug'){ if(debugMode) {debugMode=false;}else{debugMode=true;} + }else if(inputValue==='/red'){ + fPlayers[socket.id].skin = "Red"; + socket.emit('skin',fPlayers[socket.id].skin); }else{ fPlayers[socket.id].message=document.querySelector('#input').value