Browse Source

No longer allowing serverActions to be initiated by keys that are blacklisted

tags/v0.11.0
Shaun 2 years ago
parent
commit
9666f2a397
2 changed files with 23 additions and 14 deletions
  1. +14
    -10
      src/client/js/input.js
  2. +9
    -4
      src/server/clientComponents/serverActions.js

+ 14
- 10
src/client/js/input.js View File

@@ -159,6 +159,19 @@ define([
return result;
},

isKeyAllowed: function (key) {
const result = (
key.length > 1 ||
this.whitelistedKeys.includes(key) ||
(
!this.blacklistedKeys.includes(key) &&
!this.blacklistedKeys.includes('*')
)
);

return result;
},

events: {
keyboard: {
/* eslint-disable-next-line max-lines-per-function */
@@ -176,16 +189,7 @@ define([
if ((e.keyCode === 9) || (e.keyCode === 8) || (e.keyCode === 122))
e.preventDefault();

const allowKey = (
key.length > 1 ||
this.whitelistedKeys.includes(key) ||
(
!this.blacklistedKeys.includes(key) &&
!this.blacklistedKeys.includes('*')
)
);

if (!allowKey)
if (!this.isKeyAllowed(key))
return;

if (this.keys.has(key))


+ 9
- 4
src/server/clientComponents/serverActions.js View File

@@ -1,9 +1,11 @@
define([
'js/system/events',
'js/system/client'
'js/system/client',
'js/input'
], function (
events,
client
client,
input
) {
return {
type: 'serverActions',
@@ -19,7 +21,10 @@ define([
},

onKeyUp: function (key) {
this.actions.forEach(function (a) {
if (!input.isKeyAllowed(key))
return;
this.actions.forEach(a => {
if (a.key !== key)
return;

@@ -28,7 +33,7 @@ define([
method: 'performAction',
data: a.action
});
}, this);
});
},

extend: function (blueprint) {


Loading…
Cancel
Save