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.
 
 
 

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