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.
 
 
 

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