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.
 
 
 

120 lines
2.9 KiB

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