-fiz emoji issue

-last change before skin functionality is added
This commit is contained in:
gocivici 2024-02-25 12:31:29 +03:00
parent cf3b794195
commit f6496327fe
9 changed files with 41 additions and 11 deletions

View File

@ -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(() => {

19
bad-words-hacked.js Normal file
View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -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

View File

@ -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