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.
 
 
 

100 line
2.3 KiB

  1. global.extend = require('../misc/clone');
  2. global.io = require('../db/io');
  3. global._ = require('../misc/helpers');
  4. global.consts = require('../config/consts');
  5. global.instancer = require('./instancer');
  6. global.eventManager = require('../events/events');
  7. let components = require('../components/components');
  8. let mods = require('../misc/mods');
  9. let mtx = require('../mtx/mtx');
  10. let animations = require('../config/animations');
  11. let skins = require('../config/skins');
  12. let factions = require('../config/factions');
  13. let classes = require('../config/spirits');
  14. let spellsConfig = require('../config/spellsConfig');
  15. let spells = require('../config/spells');
  16. let itemTypes = require('../items/config/types');
  17. let mapList = require('../config/maps/mapList');
  18. let sheets = require('../security/sheets');
  19. let itemEffects = require('../items/itemEffects');
  20. let onCpnsReady = function () {
  21. factions.init();
  22. skins.init();
  23. mtx.init();
  24. animations.init();
  25. classes.init();
  26. spellsConfig.init();
  27. spells.init();
  28. itemTypes.init();
  29. mapList.init();
  30. sheets.init();
  31. itemEffects.init();
  32. process.send({
  33. method: 'onReady'
  34. });
  35. };
  36. let onModsReady = function () {
  37. components.init(onCpnsReady);
  38. };
  39. const onCrash = async e => {
  40. if (e.toString().indexOf('ERR_IPC_CHANNEL_CLOSED') > -1)
  41. return;
  42. _.log('Error Logged: ' + e.toString());
  43. _.log(e.stack);
  44. await io.setAsync({
  45. key: new Date(),
  46. table: 'error',
  47. value: e.toString() + ' | ' + e.stack.toString()
  48. });
  49. process.send({
  50. event: 'onCrashed'
  51. });
  52. };
  53. let onDbReady = function () {
  54. require('../misc/random');
  55. mods.init(onModsReady);
  56. process.on('uncaughtException', onCrash);
  57. process.on('unhandledRejection', onCrash);
  58. };
  59. io.init(onDbReady);
  60. process.on('message', m => {
  61. if (m.module) {
  62. let instances = instancer.instances;
  63. let iLen = instances.length;
  64. for (let i = 0; i < iLen; i++) {
  65. let objects = instances[i].objects.objects;
  66. let oLen = objects.length;
  67. let found = false;
  68. for (let j = 0; j < oLen; j++) {
  69. let object = objects[j];
  70. if (object.name === m.args[0]) {
  71. let mod = object.instance[m.module];
  72. mod[m.method].apply(mod, m.args);
  73. found = true;
  74. break;
  75. }
  76. }
  77. if (found)
  78. break;
  79. }
  80. } else if (m.threadModule)
  81. global[m.threadModule][m.method](m.data);
  82. else if (m.method)
  83. instancer[m.method](m.args);
  84. });