Преглед на файлове

modding[#1640]: Removed ban, mute and unmute from the codebase and added new modding events to skip sending messages and add new components to players when they log in

tags/v0.8.3^2
Shaun преди 3 години
родител
ревизия
0bb9754b8d
променени са 5 файла, в които са добавени 35 реда и са изтрити 177 реда
  1. +10
    -132
      src/server/components/extensions/socialCommands.js
  2. +5
    -0
      src/server/components/player.js
  3. +3
    -5
      src/server/components/social.js
  4. +0
    -27
      src/server/components/social/ban.js
  5. +17
    -13
      src/server/components/social/chat.js

+ 10
- 132
src/server/components/extensions/socialCommands.js Целия файл

@@ -7,7 +7,6 @@ const connections = require('../../security/connections');
const events = require('../../misc/events');

//Commands
const ban = require('../social/ban');
const rezone = require('../social/rezone');
const canChat = require('../social/canChat');
const startEvent = require('../social/startEvent');
@@ -24,11 +23,6 @@ let commandRoles = {
unblock: 0,
help: 0,

//Mods
ban: 5,
mute: 5,
unmute: 5,

//Super Mods
broadcast: 8,
saveAll: 8,
@@ -56,37 +50,20 @@ let commandRoles = {

//Commands that should be run on the main thread (not the zone thread)
const localCommands = [
'ban',
'join',
'leave',
'mute',
'unmute',
'setPassword',
'roll',
'giveSkin',
'broadcast',
'saveAll',
'ban',
'help',
'startEvent',
'stopEvent'
];

//Actions that should appear when a player is right clicked
const contextActions = [
{
command: 'mute',
text: 'mute'
},
{
command: 'unmute',
text: 'unmute'
},
{
command: 'ban',
text: 'ban'
}
];
const contextActions = [];

const commandActions = {};

@@ -100,6 +77,15 @@ module.exports = {
.filter((c, i) => (this.customChannels.indexOf(c) === i));
}

const chatCommandConfig = {
localCommands,
contextActions,
commandRoles,
commandActions
};

events.emit('onBeforeGetChatCommands', chatCommandConfig);

events.emit('onBeforeGetCommandRoles', commandRoles, commandActions);
Object.entries(commandActions).forEach(a => {
const [ actionName, actionHandler ] = a;
@@ -372,110 +358,6 @@ module.exports = {
});
},

mute: async function (target, reason = null) {
if (typeof (target) === 'object') {
let keys = Object.keys(target);
target = keys[0];
reason = keys[1] || null;
}

if (target === this.obj.name)
return;

let o = connections.players.find(f => (f.name === target));
if (!o)
return;

let role = roles.getRoleLevel(o);
if (role >= this.roleLevel)
return;

let social = o.social;
if (social.muted) {
this.sendMessage('That player has already been muted', 'color-redA');
return;
}

let reasonMsg = '';
if (reason)
reasonMsg = ' (' + reason + ')';

social.muted = true;
this.sendMessage('Successfully muted ' + target, 'color-yellowB');
this.sendMessage('You have been muted' + reasonMsg, 'color-yellowB', o);

atlas.updateObject(o, {
components: [{
type: 'social',
muted: true
}]
});

await io.setAsync({
key: new Date(),
table: 'modLog',
value: {
source: this.obj.name,
command: 'mute',
target: target,
reason: reason
},
serialize: true
});
},

unmute: async function (target, reason = null) {
if (typeof (target) === 'object') {
let keys = Object.keys(target);
target = keys[0];
reason = keys[1] || null;
}

if (target === this.obj.name)
return;

let o = connections.players.find(f => (f.name === target));
if (!o)
return;

let role = roles.getRoleLevel(o);
if (role >= this.roleLevel)
return;

let social = o.social;
if (!social.muted) {
this.sendMessage('That player is not muted', 'color-redA');
return;
}

let reasonMsg = '';
if (reason)
reasonMsg = ' (' + reason + ')';

delete social.muted;
this.sendMessage('Successfully unmuted ' + target, 'color-yellowB');
this.sendMessage('You have been unmuted' + reasonMsg, 'color-yellowB', o);

atlas.updateObject(o, {
components: [{
type: 'social',
muted: null
}]
});

await io.setAsync({
key: new Date(),
table: 'modLog',
value: {
source: this.obj.name,
command: 'unmute',
target: target,
reason: reason
},
serialize: true
});
},

clearInventory: function () {
let inventory = this.obj.inventory;

@@ -741,10 +623,6 @@ module.exports = {
connections.forceSaveAll();
},

ban: function (msg) {
ban(this, msg);
},

rezone: function (msg) {
rezone(this, msg);
},


+ 5
- 0
src/server/components/player.js Целия файл

@@ -1,6 +1,7 @@
let classes = require('../config/spirits');
let roles = require('../config/roles');
let serverConfig = require('../config/serverConfig');
const eventEmitter = require('../misc/events');

module.exports = {
type: 'player',
@@ -100,6 +101,10 @@ module.exports = {
obj.addComponent(c, character.components.find(f => f.type === c));
});

eventEmitter.emit('onAfterBuildPlayerObject', {
obj: this.obj
});

obj.xp = stats.values.xp;
obj.level = stats.values.level;



+ 3
- 5
src/server/components/social.js Целия файл

@@ -24,12 +24,11 @@ module.exports = {
},

simplify: function (self) {
const { party, customChannels, blockedPlayers, actions, muted } = this;
const { party, customChannels, blockedPlayers, actions } = this;

const res = {
type: 'social',
party,
muted
party
};

if (self) {
@@ -47,8 +46,7 @@ module.exports = {
return {
type: 'social',
customChannels: this.customChannels,
blockedPlayers: this.blockedPlayers,
muted: this.muted || null
blockedPlayers: this.blockedPlayers
};
},



+ 0
- 27
src/server/components/social/ban.js Целия файл

@@ -1,27 +0,0 @@
const roles = require('../../config/roles');

module.exports = async (cpnSocial, playerName) => {
let o = cons.players.find(f => (f.name === playerName));
if (!o)
return;

const { username } = o.auth;

let role = roles.getRoleLevel(o);
if (role >= cpnSocial.roleLevel)
return;

await io.setAsync({
key: username,
table: 'login',
value: '{banned}'
});

cons.logOut({
auth: {
username
}
});

cpnSocial.sendMessage('Successfully banned ' + playerName, 'color-yellowB');
};

+ 17
- 13
src/server/components/social/chat.js Целия файл

@@ -147,7 +147,7 @@ module.exports = (cpnSocial, msg) => {
if (!msgData.message)
return;

const { obj, muted, maxChatLength, messageHistory } = cpnSocial;
const { obj, maxChatLength, messageHistory } = cpnSocial;
const sendError = sendErrorMsg.bind(null, cpnSocial);

msgData.message = msgData.message
@@ -162,12 +162,6 @@ module.exports = (cpnSocial, msg) => {
if (msgData.message.trim() === '')
return;

if (muted) {
sendError('You have been muted from talking');

return;
}

let messageString = msgData.message;
if (messageString.length > maxChatLength)
return;
@@ -203,17 +197,27 @@ module.exports = (cpnSocial, msg) => {
return;
}

messageHistory.push({
msg: messageString,
time: time
});

let msgEvent = {
source: obj.auth.charname,
msg: messageString
sourceObj: obj,
msg: messageString,
ignore: false,
error: null
};
events.emit('onBeforeSendMessage', msgEvent);

if (msgEvent.ignore) {
if (msgEvent.error)
sendError(msgEvent.error);

return;
}

messageHistory.push({
msg: msgEvent.messageString,
time: time
});

const messageHandler = {
global: sendRegularMessage,
custom: sendCustomChannelMessage,


Зареждане…
Отказ
Запис