Browse Source

Merge remote-tracking branch 'upstream/master' into 1832-buffs

tags/v0.10.6^2
kckckc 2 years ago
parent
commit
269534b6cd
23 changed files with 358 additions and 825 deletions
  1. +2
    -2
      .gitlab-ci.yml
  2. +2
    -0
      README.md
  3. +41
    -53
      src/client/js/components/components.js
  4. +2
    -1
      src/client/js/rendering/particles.js
  5. +23
    -8
      src/client/js/rendering/renderer.js
  6. +35
    -0
      src/client/js/sound/sound.js
  7. +4
    -3
      src/client/package.json
  8. +2
    -2
      src/client/ui/templates/login/template.html
  9. +2
    -2
      src/client/ui/templates/tooltipInfo/template.html
  10. +1
    -1
      src/server/.eslintrc
  11. +18
    -3
      src/server/clientComponents/sound.js
  12. +29
    -1
      src/server/components/auth.js
  13. +5
    -0
      src/server/components/door.js
  14. +16
    -0
      src/server/components/particles.js
  15. +1
    -1
      src/server/config/recipes/enchanting.js
  16. +1
    -1
      src/server/config/serverConfig.js
  17. +122
    -729
      src/server/package-lock.json
  18. +5
    -6
      src/server/package.json
  19. +15
    -5
      src/server/security/router.js
  20. +9
    -0
      src/server/security/routerConfig.js
  21. +6
    -0
      src/server/server/onConnection.js
  22. +12
    -6
      src/server/world/map.js
  23. +5
    -1
      src/server/world/syncer.js

+ 2
- 2
.gitlab-ci.yml View File

@@ -16,7 +16,7 @@ audit:
lint-server:
stage: test
script:
- npm install eslint eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
- npm install eslint@7.32.0 eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
- cd src/server
- ../../node_modules/.bin/eslint .
only:
@@ -26,7 +26,7 @@ lint-server:
lint-client:
stage: test
script:
- npm install eslint eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
- npm install eslint@7.32.0 eslint-plugin-prettier prettier babel-eslint eslint-plugin-requirejs
- cd src/client
- ../../node_modules/.bin/eslint .
only:


+ 2
- 0
README.md View File

@@ -10,6 +10,8 @@ Built with NodeJS, JS, HTML and CSS.

### Installation and Usage

**IMPORTANT**: The sqlite3 package has been removed for the time being due to multiple `npm audit` issues arrising. While installing this module will not cause you any security issues (due to the nature of the vulnerabilities and how Isleward actually uses the module), we have removed it to make the build process simpler for us. As a result of this, after performing an `npm install` in the `server` folder, please also run `npm i sqlite3`.

* [Windows](https://gitlab.com/Isleward/isleward/wikis/installation-and-usage-(windows))
* [Linux](https://gitlab.com/Isleward/isleward/wikis/installation-and-usage-(linux))
* [MacOS](https://gitlab.com/Isleward/isleward/wikis/installation-and-usage-(macos))


+ 41
- 53
src/client/js/components/components.js View File

@@ -5,6 +5,11 @@ define([
events,
globals
) {
//Store templates here after loading them
const templates = [];
const extenders = [];

//Bound Methods
const hookEvent = function (e, cb) {
if (!this.eventList[e])
this.eventList[e] = [];
@@ -19,71 +24,54 @@ define([
});
};

let cpns = [];

return {
templates: {},

init: function () {
cpns = globals.clientConfig.clientComponents;

cpns = cpns.map(c => ({
...c,
promise: this.getComponent(c)
}));
//Helpers
const loadComponent = cpn => {
return new Promise(res => {
require([cpn.path], tpl => {
if (cpn.type)
templates.push(tpl);
if (cpn.extends)
extenders.push(tpl);
res();
});
});
};

return Promise.all(cpns.map(c => c.promise));
},
//Init Methods
const loadComponents = paths => {
return Promise.all(
paths.map(p => loadComponent(p))
);
};
const buildComponents = () => {
templates.forEach(t => {
const extensions = extenders.filter(e => e.extends === t.type);

getComponent: function (cpn) {
return new Promise(resolve => {
require([cpn.path], this.onGetComponent.bind(this, resolve, cpn));
});
},
extensions.forEach(e => $.extend(true, t, e));

onGetComponent: function (resolve, cpn, template) {
if (cpn.type) {
template.eventList = {};
template.hookEvent = hookEvent;
template.unhookEvents = unhookEvents;
t.eventList = {};
t.hookEvent = hookEvent;
t.unhookEvents = unhookEvents;
});
};

this.templates[cpn.type] = template;
//Export
return {
init: async function () {
const paths = globals.clientConfig.clientComponents;

resolve();
} else if (cpn.extends) {
let target = cpn.extends;
await loadComponents(paths);

if (!this.templates[target]) {
let waitFor = cpns.find(c => c.type === target);
if (waitFor) {
waitFor.promise.then(() => {
this.templates[target] = $.extend(true, this.templates[target], template);
resolve();
});
} else {
// There's no file for that component type for us to extend
resolve();
}
} else {
this.templates[target] = $.extend(true, this.templates[target], template);
resolve();
}
} else {
// This shouldn't get reached
resolve();
}
buildComponents();
},

getTemplate: function (type) {
if (type === 'lightpatch')
type = 'lightPatch';

let template = this.templates[type] || {
type: type
};

return template;
return templates.find(t => t.type === type) || { type: type };
}
};
});

+ 2
- 1
src/client/js/rendering/particles.js View File

@@ -28,9 +28,10 @@ define([

let options = $.extend(true, {}, particleDefaults, config);

let emitter = new PIXI.particles.Emitter(this.r.layers.particles, ['images/particles.png'], options);
let emitter = new PIXI.particles.Emitter(this.stage, ['images/particles.png'], options);
emitter.obj = obj;
emitter.emit = true;
emitter.particleEngine = this;

this.emitters.push(emitter);



+ 23
- 8
src/client/js/rendering/renderer.js View File

@@ -21,11 +21,15 @@ define([
globals,
renderLoginBackground
) {
let mRandom = Math.random.bind(Math);
const mRandom = Math.random.bind(Math);

const particleLayers = ['particlesUnder', 'particles'];
const particleEngines = {};

return {
stage: null,
layers: {
particlesUnder: null,
objects: null,
mobs: null,
characters: null,
@@ -115,10 +119,15 @@ define([
this.textures[t].scaleMode = PIXI.SCALE_MODES.NEAREST;
});

particles.init({
r: this,
renderer: this.renderer,
stage: this.layers.particles
particleLayers.forEach(p => {
const engine = $.extend({}, particles);
engine.init({
r: this,
renderer: this.renderer,
stage: this.layers[p]
});

particleEngines[p] = engine;
});

this.buildSpritesTexture();
@@ -769,11 +778,16 @@ define([
},

buildEmitter: function (config) {
return particles.buildEmitter(config);
const { layerName = 'particles' } = config;
const particleEngine = particleEngines[layerName];

return particleEngine.buildEmitter(config);
},

destroyEmitter: function (emitter) {
particles.destroyEmitter(emitter);
const particleEngine = emitter.particleEngine;

particleEngine.destroyEmitter(emitter);
},

setSprite: function (obj) {
@@ -887,7 +901,8 @@ define([
return;

effects.render();
particles.update();

particleLayers.forEach(p => particleEngines[p].update());

this.renderer.render(this.stage);
}


+ 35
- 0
src/client/js/sound/sound.js View File

@@ -32,6 +32,7 @@ define([
init: function () {
events.on('onToggleAudio', this.onToggleAudio.bind(this));
events.on('onPlaySound', this.playSound.bind(this));
events.on('onPlaySoundAtPosition', this.onPlaySoundAtPosition.bind(this));
events.on('onManipulateVolume', this.onManipulateVolume.bind(this));

const { clientConfig: { sounds: loadSounds } } = globals;
@@ -67,6 +68,24 @@ define([
}
},

onPlaySoundAtPosition: function ({ position: { x, y }, file, volume }) {
const { player: { x: playerX, y: playerY } } = window;
const dx = Math.abs(x - playerX);
const dy = Math.abs(y - playerY);
const distance = Math.max(dx, dy);

const useVolume = volume * (1 - (Math.pow(distance, 2) / Math.pow(minDistance, 2)));

//eslint-disable-next-line no-undef, no-unused-vars
const sound = new Howl({
src: [file],
volume: useVolume,
loop: false,
autoplay: true,
html5: false
});
},

playSound: function (soundName) {
const soundEntry = this.sounds.find(s => s.name === soundName);
if (!soundEntry)
@@ -211,6 +230,13 @@ define([
addSound: function (
{ name: soundName, scope, file, volume = 1, x, y, w, h, area, music, defaultMusic, autoLoad, loop }
) {
if (this.sounds.some(s => s.file === file)) {
if (window.player?.x !== undefined)
this.update(window.player.x, window.player.y);

return;
}

if (!area && w) {
area = [
[x, y],
@@ -243,6 +269,11 @@ define([
};

this.sounds.push(soundEntry);

if (window.player?.x !== undefined)
this.update(window.player.x, window.player.y);

return soundEntry;
},

loadSound: function (file, loop = false, autoplay = false, volume = 1) {
@@ -290,6 +321,10 @@ define([

const { player: { x, y } } = window;
this.update(x, y);
},

destroySoundEntry: function (soundEntry) {
this.sounds.spliceWhere(s => s === soundEntry);
}
};
});

+ 4
- 3
src/client/package.json View File

@@ -1,11 +1,12 @@
{
"name": "isleward_client",
"version": "0.10.1",
"version": "0.10.5",
"description": "isleward",
"dependencies": {},
"dependencies": {
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"babel-eslint": "^10.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-requirejs": "^4.0.1"
}


+ 2
- 2
src/client/ui/templates/login/template.html View File

@@ -11,11 +11,11 @@
</div>
<div class="message"></div>
</div>
<div class="news" location="https://gitlab.com/Isleward/play.isleward.com/-/wikis/v0.10.1-Release-Notes">[ Latest Release Notes ]</div>
<div class="news" location="https://gitlab.com/Isleward/play.isleward.com/-/wikis/v0.10.5-Release-Notes">[ Latest Release Notes ]</div>
<div class="extra">
<div class="el btn btnPatreon monetization" location="https://patreon.com/bigbadwaffle">Pledge on Patreon</div>
<div class="el btn btnPaypal monetization" location="https://www.paypal.com/donate?hosted_button_id=NEQAV3NG9PWXA">Donate on Paypal</div>
<div class="el btn btnWiki" location="http://wiki.isleward.com/Main_Page">Access the Wiki</div>
</div>
<div class="version" location="https://gitlab.com/Isleward/play.isleward.com/-/wikis/v0.10.1-Release-Notes">v0.10.1</div>
<div class="version" location="https://gitlab.com/Isleward/play.isleward.com/-/wikis/v0.10.5-Release-Notes">v0.10.5</div>
</div>

+ 2
- 2
src/client/ui/templates/tooltipInfo/template.html View File

@@ -1,3 +1,3 @@
<div class="uiTooltipInfo">
<div class="uiTooltipInfo hasBorderShadow">
</div>

+ 1
- 1
src/server/.eslintrc View File

@@ -1,4 +1,4 @@
{
{
"root": true,

"parser": "babel-eslint",


+ 18
- 3
src/server/clientComponents/sound.js View File

@@ -9,9 +9,11 @@ define([
sound: null,
volume: 0,

soundEntry: null,

init: function () {
const {
sound, volume, music, defaultMusic,
sound, volume, music, defaultMusic, loop = true,
obj: { zoneId, x, y, width, height, area }
} = this;

@@ -26,10 +28,23 @@ define([
area,
music,
defaultMusic,
loop: true
loop
};

soundManager.addSound(config);
this.soundEntry = soundManager.addSound(config);
},

extend: function (bpt) {
Object.assign(this, bpt);

Object.assign(this.soundEntry, bpt);
},

destroy: function () {
if (this.soundEntry?.sound)
this.soundEntry?.sound.stop();

soundManager.destroySoundEntry(this.soundEntry);
}
};
});

+ 29
- 1
src/server/components/auth.js View File

@@ -204,7 +204,7 @@ module.exports = {

fixes.fixStash(this.stash);

eventEmitter.emit('onAfterGetStash', {
await eventEmitter.emit('onAfterGetStash', {
obj: this.obj,
stash: this.stash
});
@@ -260,6 +260,7 @@ module.exports = {

if (credentials.username === '' || credentials.password === '') {
msg.callback(messages.login.allFields);

return;
}

@@ -279,6 +280,18 @@ module.exports = {
msg.callback(messages.login.incorrect);
return;
}

const emBeforeLogin = {
obj: this.obj,
success: true,
msg: null
};
await eventEmitter.emit('onBeforeLogin', emBeforeLogin);
if (!emBeforeLogin.success) {
msg.callback(emBeforeLogin.msg);

return;
}
this.username = username;
await cons.logOut(this.obj);
@@ -340,6 +353,20 @@ module.exports = {
}
}

const emBeforeRegisterAccount = {
obj: this.obj,
success: true,
msg: null
};

await eventEmitter.emit('onBeforeRegisterAccount', emBeforeRegisterAccount);

if (!emBeforeRegisterAccount.success) {
msg.callback(emBeforeRegisterAccount.msg);

return;
}

let exists = await io.getAsync({
key: credentials.username,
ignoreCase: true,
@@ -350,6 +377,7 @@ module.exports = {

if (exists) {
msg.callback(messages.login.exists);

return;
}



+ 5
- 0
src/server/components/door.js View File

@@ -20,6 +20,11 @@ module.exports = {
this.destroyKey = blueprint.destroyKey;
this.autoClose = blueprint.autoClose;

if (blueprint.openSprite)
this.openSprite = blueprint.openSprite;
if (blueprint.closedSprite)
this.closedSprite = blueprint.closedSprite;

if (this.closed) {
this.obj.instance.physics.setCollision(this.obj.x, this.obj.y, true);
this.obj.instance.objects.notifyCollisionChange(this.obj.x, this.obj.y, true);


+ 16
- 0
src/server/components/particles.js View File

@@ -0,0 +1,16 @@
module.exports = {
type: 'particles',

blueprint: null,

simplify: function (self) {
const { blueprint } = this;

const result = {
type: 'particles',
blueprint
};

return result;
}
};

+ 1
- 1
src/server/config/recipes/enchanting.js View File

@@ -45,7 +45,7 @@ module.exports = [{
withProps: ['slot'],
withoutProps: ['noAugment'],
checks: [
item => item.level && item.level < consts.maxLevel
item => item.level && (item.originalLevel || item.level) < consts.maxLevel
]
}],
craftAction: relevel


+ 1
- 1
src/server/config/serverConfig.js View File

@@ -1,5 +1,5 @@
module.exports = {
version: '0.10.1',
version: '0.10.5',
port: 4000,
startupMessage: 'Server: ready',
defaultZone: 'fjolarok',


+ 122
- 729
src/server/package-lock.json
File diff suppressed because it is too large
View File


+ 5
- 6
src/server/package.json View File

@@ -1,23 +1,22 @@
{
"name": "isleward_server",
"version": "0.10.1",
"version": "0.10.5",
"description": "isleward",
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.22.0",
"bcrypt-nodejs": "0.0.3",
"compression": "^1.7.4",
"express": "^4.17.1",
"express-minify": "^1.0.0",
"image-size": "^1.0.0",
"rethinkdbdash": "^2.3.31",
"socket.io": "^4.1.3",
"socket.io": "^4.2.0",
"universal-analytics": "^0.4.23"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-requirejs": "^4.0.1",
"sqlite3": "^4.2.0"
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-requirejs": "^4.0.1"
}
}

+ 15
- 5
src/server/security/router.js View File

@@ -1,17 +1,27 @@
const { routerConfig: { allowed, secondaryAllowed, globalAllowed } } = require('./routerConfig');
const { routerConfig: { allowed, secondaryAllowed, globalAllowed, allowTargetId } } = require('./routerConfig');

module.exports = {
allowedCpn: function (msg) {
let valid = allowed[msg.cpn] && allowed[msg.cpn].includes(msg.method);
const { cpn, method, data: { cpn: secondaryCpn, method: secondaryMethod, targetId } } = msg;

const valid = allowed[cpn] && allowed[cpn].includes(method);
if (!valid)
return false;

if (!msg.data.cpn)
if (!secondaryCpn)
return true;

const result = secondaryAllowed[msg.data.cpn] && secondaryAllowed[msg.data.cpn].includes(msg.data.method);
const secondaryValid = secondaryAllowed?.[secondaryCpn]?.includes(secondaryMethod);
if (!secondaryValid)
return false;

if (targetId !== undefined) {
const canHaveTargetId = allowTargetId?.[secondaryCpn]?.includes(secondaryMethod);
if (!canHaveTargetId)
return false;
}

return result;
return true;
},

allowedGlobal: function (msg) {


+ 9
- 0
src/server/security/routerConfig.js View File

@@ -25,6 +25,15 @@ const routerConfig = {
clientConfig: ['getClientConfig'],
leaderboard: ['requestList'],
cons: ['unzone']
},
allowTargetId: {
door: ['lock', 'unlock'],
gatherer: ['gather'],
equipment: ['inspect'],
stash: ['open'],
social: ['declineInvite'],
wardrobe: ['open', 'apply'],
workbench: ['open', 'craft', 'getRecipe']
}
};



+ 6
- 0
src/server/server/onConnection.js View File

@@ -20,11 +20,17 @@ const onRequest = (socket, msg, callback) => {
if (!router.allowedCpn(msg))
return;

delete msg.threadModule;
delete msg.module;

cons.route(socket, msg);
} else if (msg.threadModule) {
if (!router.allowedGlobalCall(msg.threadModule, msg.method))
return;

delete msg.cpn;
delete msg.module;

cons.route(socket, msg);
} else {
if (!router.allowedGlobal(msg))


+ 12
- 6
src/server/world/map.js View File

@@ -259,12 +259,18 @@ module.exports = {
const layers = [...mapFile.layers.filter(l => l.objects), ...mapFile.layers.filter(l => !l.objects)];

//Rooms need to be ahead of exits
layers.rooms = (layers.rooms || [])
.sort(function (a, b) {
if ((a.exit) && (!b.exit))
return 1;
return 0;
});
const layerRooms = layers.find(l => l.name === 'rooms') || {};
layerRooms.objects.sort((a, b) => {
const isExitA = a?.properties?.some(p => p.name === 'exit');
const isExitB = b?.properties?.some(p => p.name === 'exit');

if (isExitA && !isExitB)
return 1;
else if (!isExitA && isExitB)
return -1;

return 0;
});

for (let i = 0; i < layers.length; i++) {
let layer = layers[i];


+ 5
- 1
src/server/world/syncer.js View File

@@ -172,7 +172,11 @@ module.exports = {
for (let p in buffer) {
const list = buffer[p];

list.spliceWhere(l => l.to === targetServerId);
list.forEach(l => l.to.splice(f => f === targetServerId));
list.spliceWhere(l => !l.to.length);

if (!list.length)
delete buffer[p];
}
},



Loading…
Cancel
Save