From f6496327febbcb552a97ebcf8ac2552649670025 Mon Sep 17 00:00:00 2001 From: gocivici Date: Sun, 25 Feb 2024 12:31:29 +0300 Subject: [PATCH] -fiz emoji issue -last change before skin functionality is added --- backend.js | 12 +++++++++--- bad-words-hacked.js | 19 +++++++++++++++++++ public/characterSprites/Red/Down.png | Bin 0 -> 1718 bytes public/characterSprites/Red/Left.png | Bin 0 -> 1718 bytes public/characterSprites/Red/Right.png | Bin 0 -> 1723 bytes public/characterSprites/Red/Up.png | Bin 0 -> 1723 bytes public/classes/Player.js | 4 ++-- public/classes/Sprite.js | 2 +- public/index.js | 15 ++++++++++----- 9 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 bad-words-hacked.js create mode 100644 public/characterSprites/Red/Down.png create mode 100644 public/characterSprites/Red/Left.png create mode 100644 public/characterSprites/Red/Right.png create mode 100644 public/characterSprites/Red/Up.png 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 0000000000000000000000000000000000000000..1193e10e6ff3eb12ebf5b376ce2ecc3e42ef8158 GIT binary patch literal 1718 zcmeAS@N?(olHy`uVBq!ia0y~yVEh4OJ8&=q$%7J89|9@H;vjb?hIQv;UNSH+GX(gA zxB>+g4J<4a6^$$uy{zSxD_=R+F7TeE&M@V_@1#8ooL%?$`X8}3{LjEJOJhRE0_XXA ze7F5)_`i1x}*#}jUB@Be>&#sB|6`B5+$0z)qZ^4^^31?CHek|4ieU@{)bfFbxh zyD9?%Q-r6BV@SoEx3dps9X1ef@zrbl@#fe6{Z|Y{1vfp>xRmwu&AK$crBkXtxt(8X zF(K2v?aY^Kh9~BYKOC7qHnTlq=RLwN)gf;pV4tB-cfsM$0*J)2?jP=sReSRC<-B(* z>}xuHNv~u5gN<9VA8B!UPg`x%JSF_(L&I&{j}+tBCPc_3?^av4XvOjPNz-=BtDN^a z)Tr{zo2H76>5M9Kj-Ocw^%<4=rem5^)HPT4i7ZZ z@w)Z6=(gkL56BYna?h(|0#0i6+UzQGv^jE`;nL~F+2O4}jwObk*XpX6@(ygnl0NsB z>)t=&JbcJS_57y#1fxoww-Bpm9>28i$K2iD5`WH3485NC#^xBr7@^b2IoFT#hZx9R zh@Vgz8|xq1=_7Y_w}RZGR0hpQfqS*p_q}Gkns@oo;#Bb?&U<(i-r7W!g?6V)KKnQS zZoLEFKKb+O%Uo^q(&n*0QrySG@rd=^t?KUOyw-Y={~u>$`0HFWI3IlVbA`RNpce!UoEaYmm;^{@I3QJfp|8Sk1zGIA4&3ORMryYOZsSa`2w^jKXd6`)6O^lxq=He@IF$sJI(TOu2P^)l7;^L8EK01x@!bMrG%%e KpUXO@geCwu17Uao literal 0 HcmV?d00001 diff --git a/public/characterSprites/Red/Left.png b/public/characterSprites/Red/Left.png new file mode 100644 index 0000000000000000000000000000000000000000..1193e10e6ff3eb12ebf5b376ce2ecc3e42ef8158 GIT binary patch literal 1718 zcmeAS@N?(olHy`uVBq!ia0y~yVEh4OJ8&=q$%7J89|9@H;vjb?hIQv;UNSH+GX(gA zxB>+g4J<4a6^$$uy{zSxD_=R+F7TeE&M@V_@1#8ooL%?$`X8}3{LjEJOJhRE0_XXA ze7F5)_`i1x}*#}jUB@Be>&#sB|6`B5+$0z)qZ^4^^31?CHek|4ieU@{)bfFbxh zyD9?%Q-r6BV@SoEx3dps9X1ef@zrbl@#fe6{Z|Y{1vfp>xRmwu&AK$crBkXtxt(8X zF(K2v?aY^Kh9~BYKOC7qHnTlq=RLwN)gf;pV4tB-cfsM$0*J)2?jP=sReSRC<-B(* z>}xuHNv~u5gN<9VA8B!UPg`x%JSF_(L&I&{j}+tBCPc_3?^av4XvOjPNz-=BtDN^a z)Tr{zo2H76>5M9Kj-Ocw^%<4=rem5^)HPT4i7ZZ z@w)Z6=(gkL56BYna?h(|0#0i6+UzQGv^jE`;nL~F+2O4}jwObk*XpX6@(ygnl0NsB z>)t=&JbcJS_57y#1fxoww-Bpm9>28i$K2iD5`WH3485NC#^xBr7@^b2IoFT#hZx9R zh@Vgz8|xq1=_7Y_w}RZGR0hpQfqS*p_q}Gkns@oo;#Bb?&U<(i-r7W!g?6V)KKnQS zZoLEFKKb+O%Uo^q(&n*0QrySG@rd=^t?KUOyw-Y={~u>$`0HFWI3IlVbA`RNpce!UoEaYmm;^{@I3QJfp|8Sk1zGIA4&3ORMryYOZsSa`2w^jKXd6`)6O^lxq=He@IF$sJI(TOu2P^)l7;^L8EK01x@!bMrG%%e KpUXO@geCwu17Uao literal 0 HcmV?d00001 diff --git a/public/characterSprites/Red/Right.png b/public/characterSprites/Red/Right.png new file mode 100644 index 0000000000000000000000000000000000000000..871eeefb243cdfa1ed8e132f3f52243c96e33bd3 GIT binary patch literal 1723 zcmeAS@N?(olHy`uVBq!ia0y~yVEh4OJ8&=q$%7J89|9@H;vjb?hIQv;UNSH+GX(gA zxB>+g4J<4a6^$$uy{zSxD_=R+F7TeE&M@V_@1#8ooL%?$`X8}3{LjEJOJhRE0_XXA ze7F5)_`i1x}*#}jUB@Be>&#sB|6`B5+$0z)qZ^4^^31?CHek|4ieU@{)bfFbxh zyD9?%Q>>?pV@SoEw{uTt9d_VxbvA1(d;9DE{wuOp3d`iG<0j>1mTcwF^wj(Q!iS^M zAzu2}(>?R_8Y<_w>&ZO7TULo7+^JQkk>xexZ5j(zq{`saz zL+kJ7d9L1HXEt*`QjBv~{9F6%ft5i0(WYyqyy1sbZ4H+0ik}f8zdJ^N|DzSx%~#3O zS1Zlq6jMKc^K5SSv{%NA;zykK^f{^h@;Okd1GF&p@`j9+cEtsbdxG^k%1@R4Iyv`E z)2Hp)=eZ^W^>RN7ed4fZ7wg$mp@Qex7f;_9d*%24j^^0AAV-7D3HufCT&q@If9rxd z%YQit*ZLGY+8lYUk+PycbKNih^%e<+S}i)KKTSRp476N%>SqO*^&U@G2-^#k%y3AM z64Sk!&Ihub^`qZTt^3D~xsQhH*m7%q$?U&$M$}PZ-(r5CU5R?@Dg+IzYzq&4eVSi& zf87z8SC=`$-U>6V^bcR^#Mkbfa{frrTjq}f^I07KMD$gDR7%Jc5taIp(zWd}>$OYm z=gMuSpPAFhJf-OEJc%>UBewD!asK1Ub;SJH4Don|*Rdu`1*7$arrwlQ;CeD$a`hB0 z@7JZB{;d<&J`7!Mah0W`{f7?IqtlAQUH3P!^6Fc?H<>me{LvgIzuvbj?UifV`2*x` zFmZfr_Ep%omG?;a;w>HOJo}6%PPDS^Zx(rG=FoB7R3Ls8%g3uNukL=Z&zy5kzrQX` UF|6wP9Z*r>>FVdQ&MBb@0EoF-lK=n! literal 0 HcmV?d00001 diff --git a/public/characterSprites/Red/Up.png b/public/characterSprites/Red/Up.png new file mode 100644 index 0000000000000000000000000000000000000000..871eeefb243cdfa1ed8e132f3f52243c96e33bd3 GIT binary patch literal 1723 zcmeAS@N?(olHy`uVBq!ia0y~yVEh4OJ8&=q$%7J89|9@H;vjb?hIQv;UNSH+GX(gA zxB>+g4J<4a6^$$uy{zSxD_=R+F7TeE&M@V_@1#8ooL%?$`X8}3{LjEJOJhRE0_XXA ze7F5)_`i1x}*#}jUB@Be>&#sB|6`B5+$0z)qZ^4^^31?CHek|4ieU@{)bfFbxh zyD9?%Q>>?pV@SoEw{uTt9d_VxbvA1(d;9DE{wuOp3d`iG<0j>1mTcwF^wj(Q!iS^M zAzu2}(>?R_8Y<_w>&ZO7TULo7+^JQkk>xexZ5j(zq{`saz zL+kJ7d9L1HXEt*`QjBv~{9F6%ft5i0(WYyqyy1sbZ4H+0ik}f8zdJ^N|DzSx%~#3O zS1Zlq6jMKc^K5SSv{%NA;zykK^f{^h@;Okd1GF&p@`j9+cEtsbdxG^k%1@R4Iyv`E z)2Hp)=eZ^W^>RN7ed4fZ7wg$mp@Qex7f;_9d*%24j^^0AAV-7D3HufCT&q@If9rxd z%YQit*ZLGY+8lYUk+PycbKNih^%e<+S}i)KKTSRp476N%>SqO*^&U@G2-^#k%y3AM z64Sk!&Ihub^`qZTt^3D~xsQhH*m7%q$?U&$M$}PZ-(r5CU5R?@Dg+IzYzq&4eVSi& zf87z8SC=`$-U>6V^bcR^#Mkbfa{frrTjq}f^I07KMD$gDR7%Jc5taIp(zWd}>$OYm z=gMuSpPAFhJf-OEJc%>UBewD!asK1Ub;SJH4Don|*Rdu`1*7$arrwlQ;CeD$a`hB0 z@7JZB{;d<&J`7!Mah0W`{f7?IqtlAQUH3P!^6Fc?H<>me{LvgIzuvbj?UifV`2*x` zFmZfr_Ep%omG?;a;w>HOJo}6%PPDS^Zx(rG=FoB7R3Ls8%g3uNukL=Z&zy5kzrQX` UF|6wP9Z*r>>FVdQ&MBb@0EoF-lK=n! literal 0 HcmV?d00001 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