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.
 
 
 

123 lines
2.1 KiB

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