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.
 
 
 

99 lines
2.2 KiB

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