You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.2 KiB

  1. //Imports
  2. const { sendMessageToThread } = require('../../world/threadManager');
  3. //Helpers
  4. const route = function (socket, msg) {
  5. const source = this.players.find(p => p.socket.id === socket.id);
  6. if (!source)
  7. return;
  8. if (!msg.data)
  9. msg.data = {};
  10. msg.data.sourceId = source.id;
  11. if (
  12. (
  13. (source.permadead) &&
  14. (['getCharacterList', 'getCharacter', 'deleteCharacter'].indexOf(msg.method) === -1)
  15. ) ||
  16. (
  17. source.dead &&
  18. !(
  19. (msg.method === 'performAction' && ['respawn'].includes(msg.data.method)) ||
  20. (msg.method === 'clientAck')
  21. )
  22. )
  23. )
  24. return;
  25. if (msg.threadModule) {
  26. if (msg.callback)
  27. msg.data.callbackId = atlas.registerCallback(msg.callback);
  28. sendMessageToThread({
  29. threadId: source.zoneId,
  30. msg
  31. });
  32. return;
  33. }
  34. let target = source;
  35. if (msg.data.targetId !== undefined && msg.data.cpn === undefined) {
  36. target = this.players.find(p => p.id === msg.data.targetId);
  37. if (!target)
  38. return;
  39. }
  40. let cpn = target[msg.cpn];
  41. if (!cpn)
  42. return;
  43. let method = msg.method;
  44. if (cpn[method])
  45. cpn[method](msg);
  46. };
  47. const routeGlobal = function (msg) {
  48. global[msg.module][msg.method](msg);
  49. };
  50. //Exports
  51. module.exports = {
  52. route,
  53. routeGlobal
  54. };