@@ -17,6 +17,11 @@ define([ | |||
this.blockedList = blueprint.blockedList; | |||
events.emit('onGetBlockedPlayers', this.blockedPlayers); | |||
} | |||
if (blueprint.actions) { | |||
this.actions = blueprint.actions; | |||
events.emit('onGetSocialActions', this.actions); | |||
} | |||
} | |||
}; | |||
}); |
@@ -23,6 +23,8 @@ define([ | |||
modal: true, | |||
hasClose: true, | |||
actions: [], | |||
postRender: function () { | |||
globals.onlineList = this.onlineList; | |||
@@ -30,11 +32,16 @@ define([ | |||
this.onEvent('onGetDisconnectedPlayer', this.onGetDisconnectedPlayer.bind(this)); | |||
this.onEvent('onGetBlockedPlayers', this.onGetBlockedPlayers.bind(this)); | |||
this.onEvent('onGetSocialActions', this.onGetSocialActions.bind(this)); | |||
this.onEvent('onKeyDown', this.onKeyDown.bind(this)); | |||
this.onEvent('onShowOnline', this.toggle.bind(this)); | |||
}, | |||
onGetSocialActions: function (actions) { | |||
this.actions = actions; | |||
}, | |||
onGetBlockedPlayers: function (list) { | |||
this.blockedPlayers = list; | |||
}, | |||
@@ -117,8 +124,14 @@ define([ | |||
showContext: function (char, e) { | |||
if (char.name !== window.player.name) { | |||
let isBlocked = this.blockedPlayers.includes(char.name); | |||
events.emit('onContextMenu', [{ | |||
const extraActions = this.actions.map(({ command, text }) => { | |||
return { | |||
text, | |||
callback: this.performAction.bind(this, command, char.name) | |||
}; | |||
}); | |||
const actions = [{ | |||
text: 'invite to party', | |||
callback: this.invite.bind(this, char.id) | |||
}, { | |||
@@ -127,26 +140,33 @@ define([ | |||
}, { | |||
text: isBlocked ? 'unblock' : 'block', | |||
callback: this.block.bind(this, char.name) | |||
}], e); | |||
}, ...extraActions]; | |||
const isBlocked = this.blockedPlayers.includes(char.name); | |||
events.emit('onContextMenu', actions, e); | |||
} | |||
e.preventDefault(); | |||
return false; | |||
}, | |||
block: function (charName) { | |||
let isBlocked = this.blockedPlayers.includes(charName); | |||
let method = isBlocked ? 'unblock' : 'block'; | |||
performAction: function (command, charName) { | |||
client.request({ | |||
cpn: 'social', | |||
method: 'chat', | |||
data: { | |||
message: `/${method} ${charName}` | |||
message: `/${command} ${charName}` | |||
} | |||
}); | |||
}, | |||
block: function (charName) { | |||
let isBlocked = this.blockedPlayers.includes(charName); | |||
let method = isBlocked ? 'unblock' : 'block'; | |||
this.performAction(method, charName); | |||
}, | |||
invite: function (charId) { | |||
this.hide(); | |||
@@ -39,7 +39,8 @@ let commandRoles = { | |||
getMaterials: 10 | |||
}; | |||
let localCommands = [ | |||
//Commands that should be run on the main thread (not the zone thread) | |||
const localCommands = [ | |||
'join', | |||
'leave', | |||
'mute', | |||
@@ -53,6 +54,18 @@ let localCommands = [ | |||
'saveAll' | |||
]; | |||
//Actions that should appear when a player is right clicked | |||
const contextActions = [ | |||
{ | |||
command: 'mute', | |||
text: 'mute' | |||
}, | |||
{ | |||
command: 'unmute', | |||
text: 'unmute' | |||
} | |||
]; | |||
module.exports = { | |||
customChannels: [], | |||
roleLevel: null, | |||
@@ -64,6 +77,12 @@ module.exports = { | |||
} | |||
this.roleLevel = roles.getRoleLevel(this.obj); | |||
this.calculateActions(); | |||
}, | |||
calculateActions: function () { | |||
this.actions = contextActions | |||
.filter(c => this.roleLevel >= commandRoles[c.action]); | |||
}, | |||
onBeforeChat: function (msg) { | |||
@@ -1,6 +1,4 @@ | |||
let roles = require('../config/roles'); | |||
let events = require('../misc/events'); | |||
const profanities = require('../misc/profanities'); | |||
const chat = require('./social/chat'); | |||
module.exports = { | |||
type: 'social', | |||
@@ -12,6 +10,8 @@ module.exports = { | |||
customChannels: null, | |||
blockedPlayers: [], | |||
actions: null, | |||
messageHistory: [], | |||
maxChatLength: 255, | |||
@@ -24,13 +24,23 @@ module.exports = { | |||
}, | |||
simplify: function (self) { | |||
return { | |||
const { party, customChannels, blockedPlayers, actions, muted } = this; | |||
const res = { | |||
type: 'social', | |||
party: this.party, | |||
customChannels: self ? this.customChannels : null, | |||
blockedPlayers: self ? this.blockedPlayers : null, | |||
muted: this.muted | |||
party, | |||
muted | |||
}; | |||
if (self) { | |||
Object.assign(res, { | |||
actions, | |||
customChannels, | |||
blockedPlayers | |||
}); | |||
} | |||
return res; | |||
}, | |||
save: function () { | |||
@@ -181,91 +191,7 @@ module.exports = { | |||
}, | |||
chat: function (msg) { | |||
if (!msg.data.message) | |||
return; | |||
msg.data.message = msg.data.message | |||
.split('<') | |||
.join('<') | |||
.split('>') | |||
.join('>'); | |||
if (!msg.data.message) | |||
return; | |||
if (msg.data.message.trim() === '') | |||
return; | |||
if (this.muted) { | |||
this.sendMessage('You have been muted from talking', 'color-redA'); | |||
return; | |||
} | |||
let messageString = msg.data.message; | |||
if (messageString.length > this.maxChatLength) | |||
return; | |||
let history = this.messageHistory; | |||
let time = +new Date(); | |||
history.spliceWhere(h => ((time - h.time) > 5000)); | |||
if (history.length > 0) { | |||
if (history[history.length - 1].msg === messageString) { | |||
this.sendMessage('You have already sent that message', 'color-redA'); | |||
return; | |||
} else if (history.length >= 3) { | |||
this.sendMessage('You are sending too many messages', 'color-redA'); | |||
return; | |||
} | |||
} | |||
this.onBeforeChat(msg.data); | |||
if (msg.data.ignore) | |||
return; | |||
if (!msg.data.item && !profanities.isClean(messageString)) { | |||
this.sendMessage('Profanities detected in message. Blocked.', 'color-redA'); | |||
return; | |||
} | |||
history.push({ | |||
msg: messageString, | |||
time: time | |||
}); | |||
let charname = this.obj.auth.charname; | |||
let msgStyle = roles.getRoleMessageStyle(this.obj) || ('color-grayB'); | |||
let msgEvent = { | |||
source: charname, | |||
msg: messageString | |||
}; | |||
events.emit('onBeforeSendMessage', msgEvent); | |||
messageString = msgEvent.msg; | |||
if (messageString[0] === '@') | |||
this.sendPrivateMessage(messageString); | |||
else if (messageString[0] === '$') | |||
this.sendCustomChannelMessage(msg); | |||
else if (messageString[0] === '%') | |||
this.sendPartyMessage(msg); | |||
else { | |||
let prefix = roles.getRoleMessagePrefix(this.obj) || ''; | |||
cons.emit('event', { | |||
event: 'onGetMessages', | |||
data: { | |||
messages: [{ | |||
class: msgStyle, | |||
message: prefix + charname + ': ' + msg.data.message, | |||
item: msg.data.item, | |||
type: 'chat', | |||
source: this.obj.name | |||
}] | |||
} | |||
}); | |||
} | |||
chat(this, msg); | |||
}, | |||
dc: function () { | |||
@@ -0,0 +1,91 @@ | |||
let roles = require('../../config/roles'); | |||
let events = require('../../misc/events'); | |||
const profanities = require('../../misc/profanities'); | |||
module.exports = (cpnSocial, msg) => { | |||
if (!msg.data.message) | |||
return; | |||
msg.data.message = msg.data.message | |||
.split('<') | |||
.join('<') | |||
.split('>') | |||
.join('>'); | |||
if (!msg.data.message) | |||
return; | |||
if (msg.data.message.trim() === '') | |||
return; | |||
if (cpnSocial.muted) { | |||
cpnSocial.sendMessage('You have been muted from talking', 'color-redA'); | |||
return; | |||
} | |||
let messageString = msg.data.message; | |||
if (messageString.length > cpnSocial.maxChatLength) | |||
return; | |||
let history = cpnSocial.messageHistory; | |||
let time = +new Date(); | |||
history.spliceWhere(h => ((time - h.time) > 5000)); | |||
if (history.length > 0) { | |||
if (history[history.length - 1].msg === messageString) { | |||
cpnSocial.sendMessage('You have already sent that message', 'color-redA'); | |||
return; | |||
} else if (history.length >= 3) { | |||
cpnSocial.sendMessage('You are sending too many messages', 'color-redA'); | |||
return; | |||
} | |||
} | |||
cpnSocial.onBeforeChat(msg.data); | |||
if (msg.data.ignore) | |||
return; | |||
if (!msg.data.item && !profanities.isClean(messageString)) { | |||
cpnSocial.sendMessage('Profanities detected in message. Blocked.', 'color-redA'); | |||
return; | |||
} | |||
history.push({ | |||
msg: messageString, | |||
time: time | |||
}); | |||
let charname = cpnSocial.obj.auth.charname; | |||
let msgStyle = roles.getRoleMessageStyle(cpnSocial.obj) || ('color-grayB'); | |||
let msgEvent = { | |||
source: charname, | |||
msg: messageString | |||
}; | |||
events.emit('onBeforeSendMessage', msgEvent); | |||
messageString = msgEvent.msg; | |||
if (messageString[0] === '@') | |||
cpnSocial.sendPrivateMessage(messageString); | |||
else if (messageString[0] === '$') | |||
cpnSocial.sendCustomChannelMessage(msg); | |||
else if (messageString[0] === '%') | |||
cpnSocial.sendPartyMessage(msg); | |||
else { | |||
let prefix = roles.getRoleMessagePrefix(cpnSocial.obj) || ''; | |||
cons.emit('event', { | |||
event: 'onGetMessages', | |||
data: { | |||
messages: [{ | |||
class: msgStyle, | |||
message: prefix + charname + ': ' + msg.data.message, | |||
item: msg.data.item, | |||
type: 'chat', | |||
source: cpnSocial.obj.name | |||
}] | |||
} | |||
}); | |||
} | |||
}; |