Przeglądaj źródła

moved custom chat commands to socialCommands

tags/v0.1.7^2
big bad waffle 6 lat temu
rodzic
commit
b435060362
3 zmienionych plików z 111 dodań i 134 usunięć
  1. +1
    -1
      src/client/index.html
  2. +108
    -11
      src/server/components/extensions/socialCommands.js
  3. +2
    -122
      src/server/components/social.js

+ 1
- 1
src/client/index.html Wyświetl plik

@@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<title>isleward</title>
<title>geared</title>
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="js/system/addons.js"></script>
<script src="plugins/require.js" data-main="js/app"></script>


+ 108
- 11
src/server/components/extensions/socialCommands.js Wyświetl plik

@@ -3,14 +3,30 @@ define([
'world/atlas',
'items/generator',
'misc/random',
'items/config/slots'
'items/config/slots',
'security/io'
], function(
roles,
atlas,
generator,
random,
configSlots
configSlots,
io
) {
var commandRoles = {
join: 0,
leave: 0,
getItem: 10,
getGold: 10,
setLevel: 10,
godMode: 10
};

var localCommands = [
'join',
'leave'
];

return {
roleLevel: null,

@@ -19,9 +35,6 @@ define([
},

onBeforeChat: function(msg) {
if (this.roleLevel < 10)
return;

var messageText = msg.message;
if (messageText[0] != '/')
return;
@@ -31,6 +44,10 @@ define([
actionName = Object.keys(this).find(a => (a.toLowerCase() == actionName));
if (!actionName)
return;
else if (this.roleLevel < commandRoles[actionName])
return;

msg.ignore = true;

var config = {};
if ((messageText.length == 1) && (messageText[0].indexOf('=') == -1))
@@ -42,16 +59,91 @@ define([
});
}

msg.ignore = true;
if (localCommands.indexOf(actionName) > -1) {
this[actionName].call(this, config);
} else {
atlas.performAction(this.obj, {
cpn: 'social',
method: actionName,
data: config
});
}
},

//actions
join: function(value) {
var obj = this.obj;

var channels = obj.auth.customChannels;
if (!channels.some(c => (c == value)))
channels.push(value);
else
return;

channels.push(value);

var charname = obj.auth.charname;
io.set({
ent: charname,
field: 'customChannels',
value: JSON.stringify(channels)
});

obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'joined channel: ' + value,
type: 'info'
}]
}]
});

atlas.performAction(this.obj, {
cpn: 'social',
method: actionName,
data: config
obj.socket.emit('event', {
event: 'onJoinChannel',
data: value
});
},

leave: function(value) {
var obj = this.obj;

var channels = obj.auth.customChannels;
if (!channels.some(c => (c == value))) {
obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'you are not currently in that channel',
type: 'info'
}]
}]
});

return;
}

var channels = obj.auth.customChannels;
channels.spliceWhere(c => (c == value));

var charname = obj.auth.charname;
io.set({
ent: charname,
field: 'customChannels',
value: JSON.stringify(channels)
});

this.obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'left channel: ' + value,
type: 'info'
}]
}]
});
},

//actions
getItem: function(config) {
if (config.slot == 'set') {
configSlots.slots.forEach(function(s) {
@@ -170,6 +262,11 @@ define([
}

obj.spellbook.calcDps();
},

//custom channels
isInChannel: function(character, channel) {
return character.auth.customChannels.some(c => (c == channel));
}
};
});

+ 2
- 122
src/server/components/social.js Wyświetl plik

@@ -1,11 +1,9 @@
define([
'world/atlas',
'config/roles',
'security/io'
'config/roles'
], function(
atlas,
roles,
io
roles
) {
return {
type: 'social',
@@ -71,17 +69,6 @@ define([
}, this);
},

isInChannel: function(character, channel) {
if (character.auth.customChannels) {
var cLen = character.auth.customChannels.length;
for (var c = 0; c < cLen; c++) {
if (character.auth.customChannels[c] == channel)
return true;
}
}
return false;
},

sendCustomChannelMessage: function(msg) {
var pList = cons.players;
var pLen = pList.length;
@@ -127,111 +114,6 @@ define([
}
}
}

},

chatCommand: function(msg) {
var origMessage = msg.data.message.substr(1);
var command = origMessage.split(' ')[0];
var value = origMessage.split(' ')[1];

var charCommands = ['join', 'leave'];

if ((!command) || (!value) || (charCommands.indexOf(command) == -1)) {
this.obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'invalid command',
type: 'info'
}]
}]
});
return;
}

switch(command) {
case 'join':
var channels = []
var charname = this.obj.auth.charname;
if (this.obj.auth.customChannels) {
var cLen = this.obj.auth.customChannels.length;
for (i = 0; i < cLen; i++) {
channels.push(this.obj.auth.customChannels[i]);
}
} else {
this.obj.auth.customChannels = [];
}
channels.push(value);
io.set({
ent: charname,
field: 'customChannels',
value: JSON.stringify(channels)
});

this.obj.auth.customChannels.push(value);

this.obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'joined channel: ' + value,
type: 'info'
}]
}]
});
this.obj.socket.emit('event', {
event: 'onJoinChannel',
data: value
});
break;
case "leave":
var targetChannelIndex = this.obj.auth.customChannels.indexOf(value);

if (targetChannelIndex == -1) {
this.obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'you are not currently in that channel',
type: 'info'
}]
}]
});
return;
}

var channels = []
var charname = this.obj.auth.charname;
var cLen = this.obj.auth.customChannels.length;
if (this.obj.auth.customChannels[0]) {
for (i = 0; i < cLen; i++) {
if (this.obj.auth.customChannels[i] != value)
channels.push(this.obj.auth.customChannels[i]);
}
}
io.set({
ent: charname,
field: 'customChannels',
value: JSON.stringify(channels)
});

this.obj.auth.customChannels.splice(targetChannelIndex);

this.obj.socket.emit('events', {
onGetMessages: [{
messages: [{
class: 'q0',
message: 'left channel: ' + value,
type: 'info'
}]
}]
});
break;
}
},

chat: function(msg) {
@@ -294,8 +176,6 @@ define([
this.sendCustomChannelMessage(msg);
} else if (messageString[0] == '%') {
this.sendPartyMessage(msg);
} else if (messageString[0] == '/') {
this.chatCommand(msg);
} else {
var prefix = roles.getRoleMessagePrefix(this.obj) || '';



Ładowanie…
Anuluj
Zapisz