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.
 
 
 

94 lines
2.0 KiB

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