@takaro/modules 0.0.15 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/dist/BuiltinModule.d.ts +13 -8
  2. package/dist/BuiltinModule.d.ts.map +1 -0
  3. package/dist/BuiltinModule.js +48 -31
  4. package/dist/BuiltinModule.js.map +1 -1
  5. package/dist/dto/base.d.ts +1 -0
  6. package/dist/dto/base.d.ts.map +1 -0
  7. package/dist/dto/discordEvents.d.ts +1 -0
  8. package/dist/dto/discordEvents.d.ts.map +1 -0
  9. package/dist/dto/gameEvents.d.ts +1 -0
  10. package/dist/dto/gameEvents.d.ts.map +1 -0
  11. package/dist/dto/index.d.ts +4 -0
  12. package/dist/dto/index.d.ts.map +1 -0
  13. package/dist/dto/takaroEvents.d.ts +16 -0
  14. package/dist/dto/takaroEvents.d.ts.map +1 -0
  15. package/dist/dto/takaroEvents.js +36 -0
  16. package/dist/dto/takaroEvents.js.map +1 -1
  17. package/dist/main.d.ts +4 -3
  18. package/dist/main.d.ts.map +1 -0
  19. package/dist/main.js +1 -1
  20. package/dist/main.js.map +1 -1
  21. package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts +1 -0
  22. package/dist/modules/chatBridge/hooks/DiscordToGame.d.ts.map +1 -0
  23. package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts +1 -0
  24. package/dist/modules/chatBridge/hooks/GameToDiscord.d.ts.map +1 -0
  25. package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts +1 -0
  26. package/dist/modules/chatBridge/hooks/PlayerConnected.d.ts.map +1 -0
  27. package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts +1 -0
  28. package/dist/modules/chatBridge/hooks/PlayerDisconnected.d.ts.map +1 -0
  29. package/dist/modules/chatBridge/index.d.ts +3 -2
  30. package/dist/modules/chatBridge/index.d.ts.map +1 -0
  31. package/dist/modules/chatBridge/index.js +55 -47
  32. package/dist/modules/chatBridge/index.js.map +1 -1
  33. package/dist/modules/dailyRewards/commands/daily.d.ts +1 -0
  34. package/dist/modules/dailyRewards/commands/daily.d.ts.map +1 -0
  35. package/dist/modules/dailyRewards/commands/streak.d.ts +1 -0
  36. package/dist/modules/dailyRewards/commands/streak.d.ts.map +1 -0
  37. package/dist/modules/dailyRewards/commands/topstreak.d.ts +1 -0
  38. package/dist/modules/dailyRewards/commands/topstreak.d.ts.map +1 -0
  39. package/dist/modules/dailyRewards/functions/utils.d.ts +1 -0
  40. package/dist/modules/dailyRewards/functions/utils.d.ts.map +1 -0
  41. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.d.ts +1 -0
  42. package/dist/modules/dailyRewards/hooks/dailyLoginCheck.d.ts.map +1 -0
  43. package/dist/modules/dailyRewards/index.d.ts +3 -2
  44. package/dist/modules/dailyRewards/index.d.ts.map +1 -0
  45. package/dist/modules/dailyRewards/index.js +114 -106
  46. package/dist/modules/dailyRewards/index.js.map +1 -1
  47. package/dist/modules/economyUtils/commands/balance.d.ts +1 -0
  48. package/dist/modules/economyUtils/commands/balance.d.ts.map +1 -0
  49. package/dist/modules/economyUtils/commands/claim.d.ts +1 -0
  50. package/dist/modules/economyUtils/commands/claim.d.ts.map +1 -0
  51. package/dist/modules/economyUtils/commands/confirmTransfer.d.ts +1 -0
  52. package/dist/modules/economyUtils/commands/confirmTransfer.d.ts.map +1 -0
  53. package/dist/modules/economyUtils/commands/grantCurrency.d.ts +1 -0
  54. package/dist/modules/economyUtils/commands/grantCurrency.d.ts.map +1 -0
  55. package/dist/modules/economyUtils/commands/revokeCurrency.d.ts +1 -0
  56. package/dist/modules/economyUtils/commands/revokeCurrency.d.ts.map +1 -0
  57. package/dist/modules/economyUtils/commands/shop.d.ts +1 -0
  58. package/dist/modules/economyUtils/commands/shop.d.ts.map +1 -0
  59. package/dist/modules/economyUtils/commands/topCurrency.d.ts +1 -0
  60. package/dist/modules/economyUtils/commands/topCurrency.d.ts.map +1 -0
  61. package/dist/modules/economyUtils/commands/transfer.d.ts +1 -0
  62. package/dist/modules/economyUtils/commands/transfer.d.ts.map +1 -0
  63. package/dist/modules/economyUtils/cronJobs/zombieKillReward.d.ts +1 -0
  64. package/dist/modules/economyUtils/cronJobs/zombieKillReward.d.ts.map +1 -0
  65. package/dist/modules/economyUtils/index.d.ts +3 -2
  66. package/dist/modules/economyUtils/index.d.ts.map +1 -0
  67. package/dist/modules/economyUtils/index.js +178 -170
  68. package/dist/modules/economyUtils/index.js.map +1 -1
  69. package/dist/modules/geoBlock/hooks/IPDetected.d.ts +1 -0
  70. package/dist/modules/geoBlock/hooks/IPDetected.d.ts.map +1 -0
  71. package/dist/modules/geoBlock/index.d.ts +3 -2
  72. package/dist/modules/geoBlock/index.d.ts.map +1 -0
  73. package/dist/modules/geoBlock/index.js +71 -63
  74. package/dist/modules/geoBlock/index.js.map +1 -1
  75. package/dist/modules/gimme/commands/gimme.d.ts +1 -0
  76. package/dist/modules/gimme/commands/gimme.d.ts.map +1 -0
  77. package/dist/modules/gimme/index.d.ts +3 -2
  78. package/dist/modules/gimme/index.d.ts.map +1 -0
  79. package/dist/modules/gimme/index.js +59 -50
  80. package/dist/modules/gimme/index.js.map +1 -1
  81. package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts +1 -0
  82. package/dist/modules/highPingKicker/cronJobs/Ping check.d.ts.map +1 -0
  83. package/dist/modules/highPingKicker/index.d.ts +3 -2
  84. package/dist/modules/highPingKicker/index.d.ts.map +1 -0
  85. package/dist/modules/highPingKicker/index.js +36 -28
  86. package/dist/modules/highPingKicker/index.js.map +1 -1
  87. package/dist/modules/lottery/commands/buyTicket.d.ts +1 -0
  88. package/dist/modules/lottery/commands/buyTicket.d.ts.map +1 -0
  89. package/dist/modules/lottery/commands/nextDraw.d.ts +1 -0
  90. package/dist/modules/lottery/commands/nextDraw.d.ts.map +1 -0
  91. package/dist/modules/lottery/commands/viewTickets.d.ts +1 -0
  92. package/dist/modules/lottery/commands/viewTickets.d.ts.map +1 -0
  93. package/dist/modules/lottery/cronJobs/drawLottery.d.ts +1 -0
  94. package/dist/modules/lottery/cronJobs/drawLottery.d.ts.map +1 -0
  95. package/dist/modules/lottery/index.d.ts +3 -2
  96. package/dist/modules/lottery/index.d.ts.map +1 -0
  97. package/dist/modules/lottery/index.js +73 -65
  98. package/dist/modules/lottery/index.js.map +1 -1
  99. package/dist/modules/playerOnboarding/commands/starterkit.d.ts +1 -0
  100. package/dist/modules/playerOnboarding/commands/starterkit.d.ts.map +1 -0
  101. package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts +1 -0
  102. package/dist/modules/playerOnboarding/hooks/playerConnected.d.ts.map +1 -0
  103. package/dist/modules/playerOnboarding/index.d.ts +3 -2
  104. package/dist/modules/playerOnboarding/index.d.ts.map +1 -0
  105. package/dist/modules/playerOnboarding/index.js +69 -60
  106. package/dist/modules/playerOnboarding/index.js.map +1 -1
  107. package/dist/modules/serverMessages/cronJobs/Automated message.d.ts +1 -0
  108. package/dist/modules/serverMessages/cronJobs/Automated message.d.ts.map +1 -0
  109. package/dist/modules/serverMessages/index.d.ts +3 -2
  110. package/dist/modules/serverMessages/index.d.ts.map +1 -0
  111. package/dist/modules/serverMessages/index.js +36 -28
  112. package/dist/modules/serverMessages/index.js.map +1 -1
  113. package/dist/modules/teleports/commands/deletetp.d.ts +1 -0
  114. package/dist/modules/teleports/commands/deletetp.d.ts.map +1 -0
  115. package/dist/modules/teleports/commands/deletewaypoint.d.ts +1 -0
  116. package/dist/modules/teleports/commands/deletewaypoint.d.ts.map +1 -0
  117. package/dist/modules/teleports/commands/deletewaypoint.js +4 -35
  118. package/dist/modules/teleports/commands/deletewaypoint.js.map +1 -1
  119. package/dist/modules/teleports/commands/listwaypoints.d.ts +1 -0
  120. package/dist/modules/teleports/commands/listwaypoints.d.ts.map +1 -0
  121. package/dist/modules/teleports/commands/listwaypoints.js +3 -22
  122. package/dist/modules/teleports/commands/listwaypoints.js.map +1 -1
  123. package/dist/modules/teleports/commands/setprivate.d.ts +1 -0
  124. package/dist/modules/teleports/commands/setprivate.d.ts.map +1 -0
  125. package/dist/modules/teleports/commands/setpublic.d.ts +1 -0
  126. package/dist/modules/teleports/commands/setpublic.d.ts.map +1 -0
  127. package/dist/modules/teleports/commands/settp.d.ts +1 -0
  128. package/dist/modules/teleports/commands/settp.d.ts.map +1 -0
  129. package/dist/modules/teleports/commands/setwaypoint.d.ts +1 -0
  130. package/dist/modules/teleports/commands/setwaypoint.d.ts.map +1 -0
  131. package/dist/modules/teleports/commands/setwaypoint.js +5 -63
  132. package/dist/modules/teleports/commands/setwaypoint.js.map +1 -1
  133. package/dist/modules/teleports/commands/teleport.d.ts +1 -0
  134. package/dist/modules/teleports/commands/teleport.d.ts.map +1 -0
  135. package/dist/modules/teleports/commands/teleportwaypoint.d.ts +1 -0
  136. package/dist/modules/teleports/commands/teleportwaypoint.d.ts.map +1 -0
  137. package/dist/modules/teleports/commands/teleportwaypoint.js +7 -23
  138. package/dist/modules/teleports/commands/teleportwaypoint.js.map +1 -1
  139. package/dist/modules/teleports/commands/tplist.d.ts +1 -0
  140. package/dist/modules/teleports/commands/tplist.d.ts.map +1 -0
  141. package/dist/modules/teleports/cronJobs/Waypoint reconciler.d.ts +2 -0
  142. package/dist/modules/teleports/cronJobs/Waypoint reconciler.d.ts.map +1 -0
  143. package/dist/modules/teleports/cronJobs/Waypoint reconciler.js +6 -0
  144. package/dist/modules/teleports/cronJobs/Waypoint reconciler.js.map +1 -0
  145. package/dist/modules/teleports/functions/utils.d.ts +12 -0
  146. package/dist/modules/teleports/functions/utils.d.ts.map +1 -0
  147. package/dist/modules/teleports/functions/utils.js +117 -0
  148. package/dist/modules/teleports/functions/utils.js.map +1 -1
  149. package/dist/modules/teleports/index.d.ts +3 -2
  150. package/dist/modules/teleports/index.d.ts.map +1 -0
  151. package/dist/modules/teleports/index.js +188 -172
  152. package/dist/modules/teleports/index.js.map +1 -1
  153. package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts +1 -0
  154. package/dist/modules/timedShutdown/cronJobs/Shutdown.d.ts.map +1 -0
  155. package/dist/modules/timedShutdown/cronJobs/warning.d.ts +1 -0
  156. package/dist/modules/timedShutdown/cronJobs/warning.d.ts.map +1 -0
  157. package/dist/modules/timedShutdown/index.d.ts +3 -2
  158. package/dist/modules/timedShutdown/index.d.ts.map +1 -0
  159. package/dist/modules/timedShutdown/index.js +35 -27
  160. package/dist/modules/timedShutdown/index.js.map +1 -1
  161. package/dist/modules/utils/commands/help.d.ts +1 -0
  162. package/dist/modules/utils/commands/help.d.ts.map +1 -0
  163. package/dist/modules/utils/commands/help.js +10 -9
  164. package/dist/modules/utils/commands/help.js.map +1 -1
  165. package/dist/modules/utils/commands/ping.d.ts +1 -0
  166. package/dist/modules/utils/commands/ping.d.ts.map +1 -0
  167. package/dist/modules/utils/index.d.ts +3 -2
  168. package/dist/modules/utils/index.d.ts.map +1 -0
  169. package/dist/modules/utils/index.js +36 -28
  170. package/dist/modules/utils/index.js.map +1 -1
  171. package/dist/modules.json +600 -570
  172. package/package.json +3 -8
  173. package/scripts/buildBuiltinJson.ts +12 -8
  174. package/src/BuiltinModule.ts +25 -17
  175. package/src/__tests__/aliases.integration.test.ts +23 -26
  176. package/src/__tests__/bugRepros.integration.test.ts +261 -10
  177. package/src/__tests__/builtinmodule.unit.test.ts +3 -1
  178. package/src/__tests__/commandArgs.integration.test.ts +13 -6
  179. package/src/__tests__/economy/claim.integration.test.ts +1 -0
  180. package/src/__tests__/economy/economyUtils.integration.test.ts +43 -46
  181. package/src/__tests__/economy/shop.integration.test.ts +5 -4
  182. package/src/__tests__/economy/zombieKillReward.integration.test.ts +28 -31
  183. package/src/__tests__/geoblock.integration.test.ts +76 -91
  184. package/src/__tests__/gimme.integration.test.ts +22 -25
  185. package/src/__tests__/help.integration.test.ts +21 -20
  186. package/src/__tests__/lottery.integration.test.ts +15 -11
  187. package/src/__tests__/modulePermission.integration.test.ts +17 -13
  188. package/src/__tests__/onboarding.integration.test.ts +31 -34
  189. package/src/__tests__/ping.integration.test.ts +5 -4
  190. package/src/__tests__/roleExpiry.integration.test.ts +5 -4
  191. package/src/__tests__/serverMessages.integration.test.ts +24 -27
  192. package/src/__tests__/systemConfigCooldown.integration.test.ts +5 -1
  193. package/src/__tests__/systemConfigCost.integration.test.ts +16 -17
  194. package/src/__tests__/teleports/listtp.integration.test.ts +20 -21
  195. package/src/__tests__/teleports/publicteleports.integration.test.ts +58 -70
  196. package/src/__tests__/teleports/teleport.integration.test.ts +16 -17
  197. package/src/__tests__/teleports/tpManagement.integration.test.ts +21 -20
  198. package/src/__tests__/teleports/waypoints.integration.test.ts +52 -6
  199. package/src/dto/takaroEvents.ts +21 -0
  200. package/src/main.ts +12 -4
  201. package/src/modules/chatBridge/index.ts +54 -51
  202. package/src/modules/dailyRewards/index.ts +121 -111
  203. package/src/modules/economyUtils/index.ts +182 -179
  204. package/src/modules/geoBlock/index.ts +72 -70
  205. package/src/modules/gimme/index.ts +59 -55
  206. package/src/modules/highPingKicker/index.ts +35 -32
  207. package/src/modules/lottery/index.ts +73 -71
  208. package/src/modules/playerOnboarding/index.ts +71 -67
  209. package/src/modules/serverMessages/index.ts +36 -32
  210. package/src/modules/teleports/commands/deletewaypoint.js +4 -53
  211. package/src/modules/teleports/commands/listwaypoints.js +3 -35
  212. package/src/modules/teleports/commands/setwaypoint.js +5 -83
  213. package/src/modules/teleports/commands/teleportwaypoint.js +9 -36
  214. package/src/modules/teleports/cronJobs/Waypoint reconciler.js +7 -0
  215. package/src/modules/teleports/functions/utils.js +150 -0
  216. package/src/modules/teleports/index.ts +196 -180
  217. package/src/modules/timedShutdown/index.ts +35 -30
  218. package/src/modules/utils/commands/help.js +14 -14
  219. package/src/modules/utils/index.ts +36 -32
  220. package/tsconfig.json +1 -1
@@ -1,39 +1,43 @@
1
- import { BuiltinModule, ICronJob } from '../../BuiltinModule.js';
1
+ import { ModuleTransferDTO, ICronJob, ModuleTransferVersionDTO } from '../../BuiltinModule.js';
2
2
 
3
- export class ServerMessages extends BuiltinModule<ServerMessages> {
3
+ export class ServerMessages extends ModuleTransferDTO<ServerMessages> {
4
4
  constructor() {
5
- super(
6
- 'serverMessages',
7
- 'Send automated, rotated, configurable messages to players on the server.',
8
- JSON.stringify({
9
- $schema: 'http://json-schema.org/draft-07/schema#',
10
- type: 'object',
11
- properties: {
12
- messages: {
13
- type: 'array',
14
- title: 'Messages',
15
- description: 'List of messages that will be sent to players on the server.',
16
- default: [
17
- // prettier-ignore
18
- 'This is an automated message, don\'t forget to read the server rules!',
19
- ],
20
- items: {
21
- type: 'string',
22
- minLength: 5,
23
- maxLength: 1024,
5
+ super();
6
+
7
+ this.name = 'serverMessages';
8
+ this.versions = [
9
+ new ModuleTransferVersionDTO({
10
+ tag: '0.0.1',
11
+ description: 'Send automated, rotated, configurable messages to players on the server.',
12
+ configSchema: JSON.stringify({
13
+ $schema: 'http://json-schema.org/draft-07/schema#',
14
+ type: 'object',
15
+ properties: {
16
+ messages: {
17
+ type: 'array',
18
+ title: 'Messages',
19
+ description: 'List of messages that will be sent to players on the server.',
20
+ default: [
21
+ // prettier-ignore
22
+ 'This is an automated message, don\'t forget to read the server rules!',
23
+ ],
24
+ items: {
25
+ type: 'string',
26
+ minLength: 5,
27
+ maxLength: 1024,
28
+ },
29
+ minItems: 1,
24
30
  },
25
- minItems: 1,
26
31
  },
27
- },
28
- required: ['messages'],
29
- }),
30
- );
31
-
32
- this.cronJobs = [
33
- new ICronJob({
34
- name: 'Automated message',
35
- temporalValue: '*/30 * * * *',
36
- function: this.loadFn('cronJobs', 'Automated message'),
32
+ required: ['messages'],
33
+ }),
34
+ cronJobs: [
35
+ new ICronJob({
36
+ name: 'Automated message',
37
+ temporalValue: '*/30 * * * *',
38
+ function: this.loadFn('cronJobs', 'Automated message'),
39
+ }),
40
+ ],
37
41
  }),
38
42
  ];
39
43
  }
@@ -1,56 +1,18 @@
1
1
  import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';
2
-
3
- function getWaypointName(name) {
4
- return `waypoint ${name}`;
5
- }
2
+ import { getWaypointName, waypointReconciler } from './utils.js';
6
3
 
7
4
  async function main() {
8
- const { pog, gameServerId, arguments: args } = data;
5
+ const { pog, gameServerId, arguments: args, module: mod } = data;
9
6
 
10
7
  if (!checkPermission(pog, 'TELEPORTS_MANAGE_WAYPOINTS')) {
11
8
  throw new TakaroUserError('You do not have permission to manage waypoints.');
12
9
  }
13
10
 
14
- async function ensureWaypointsModule() {
15
- let waypointsDefinition = (
16
- await takaro.module.moduleControllerSearch({
17
- filters: {
18
- name: ['Waypoints'],
19
- },
20
- })
21
- ).data.data[0];
22
-
23
- if (!waypointsDefinition) {
24
- console.log('Waypoints module definition not found, creating it.');
25
- waypointsDefinition = (
26
- await takaro.module.moduleControllerCreate({
27
- name: 'Waypoints',
28
- description: 'Waypoints module for the teleport system.',
29
- })
30
- ).data.data;
31
- }
32
-
33
- let waypointsInstallation = (
34
- await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
35
- ).data.data.find((module) => module.name === 'Waypoints');
36
-
37
- if (!waypointsInstallation) {
38
- console.log('Waypoints module not found, installing it.');
39
- waypointsInstallation = (
40
- await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
41
- ).data.data;
42
- }
43
-
44
- return { waypointsInstallation, waypointsDefinition };
45
- }
46
-
47
- const { waypointsInstallation } = await ensureWaypointsModule();
48
-
49
11
  const variable = await takaro.variable.variableControllerSearch({
50
12
  filters: {
51
13
  key: [getWaypointName(args.waypoint)],
52
14
  gameServerId: [gameServerId],
53
- moduleId: [waypointsInstallation.moduleId],
15
+ moduleId: [mod.moduleId],
54
16
  },
55
17
  });
56
18
 
@@ -59,18 +21,7 @@ async function main() {
59
21
  }
60
22
 
61
23
  await takaro.variable.variableControllerDelete(variable.data.data[0].id);
62
-
63
- const teleportCommand = await takaro.command.commandControllerSearch({
64
- filters: {
65
- moduleId: [waypointsInstallation.moduleId],
66
- name: [`waypoint ${args.waypoint} server ${gameServerId}`],
67
- },
68
- });
69
-
70
- if (teleportCommand.data.data.length) {
71
- await takaro.command.commandControllerRemove(teleportCommand.data.data[0].id);
72
- }
73
-
24
+ await waypointReconciler();
74
25
  await pog.pm(`Waypoint ${args.waypoint} deleted.`);
75
26
  }
76
27
 
@@ -1,44 +1,12 @@
1
- import { takaro, data, checkPermission } from '@takaro/helpers';
1
+ import { data, checkPermission } from '@takaro/helpers';
2
+ import { ensureWaypointsModule } from './utils.js';
2
3
 
3
4
  async function main() {
4
5
  const { pog, gameServerId } = data;
5
6
 
6
- async function ensureWaypointsModule() {
7
- let waypointsDefinition = (
8
- await takaro.module.moduleControllerSearch({
9
- filters: {
10
- name: ['Waypoints'],
11
- },
12
- })
13
- ).data.data[0];
14
-
15
- if (!waypointsDefinition) {
16
- console.log('Waypoints module definition not found, creating it.');
17
- waypointsDefinition = (
18
- await takaro.module.moduleControllerCreate({
19
- name: 'Waypoints',
20
- description: 'Waypoints module for the teleport system.',
21
- })
22
- ).data.data;
23
- }
24
-
25
- let waypointsInstallation = (
26
- await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
27
- ).data.data.find((module) => module.name === 'Waypoints');
28
-
29
- if (!waypointsInstallation) {
30
- console.log('Waypoints module not found, installing it.');
31
- waypointsInstallation = (
32
- await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
33
- ).data.data;
34
- }
35
-
36
- return { waypointsInstallation, waypointsDefinition };
37
- }
38
-
39
7
  const { waypointsDefinition } = await ensureWaypointsModule();
40
8
 
41
- const allWaypoints = waypointsDefinition.commands;
9
+ const allWaypoints = waypointsDefinition.latestVersion.commands;
42
10
 
43
11
  const waypointsWithPermission = allWaypoints
44
12
  .filter((waypoint) => checkPermission(pog, `WAYPOINTS_USE_${waypoint.trigger.toUpperCase()}_${gameServerId}`))
@@ -1,54 +1,16 @@
1
1
  import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';
2
-
3
- function getWaypointName(name) {
4
- return `waypoint ${name}`;
5
- }
2
+ import { getWaypointName, waypointReconciler } from './utils.js';
6
3
 
7
4
  async function main() {
8
- const { pog, gameServerId, module: mod, arguments: args } = data;
5
+ const { pog, gameServerId, arguments: args, module: mod } = data;
9
6
 
10
7
  if (!checkPermission(pog, 'TELEPORTS_MANAGE_WAYPOINTS')) {
11
8
  throw new TakaroUserError('You do not have permission to manage waypoints.');
12
9
  }
13
10
 
14
- async function ensureWaypointsModule() {
15
- let waypointsDefinition = (
16
- await takaro.module.moduleControllerSearch({
17
- filters: {
18
- name: ['Waypoints'],
19
- },
20
- })
21
- ).data.data[0];
22
-
23
- if (!waypointsDefinition) {
24
- console.log('Waypoints module definition not found, creating it.');
25
- waypointsDefinition = (
26
- await takaro.module.moduleControllerCreate({
27
- name: 'Waypoints',
28
- description: 'Waypoints module for the teleport system.',
29
- })
30
- ).data.data;
31
- }
32
-
33
- let waypointsInstallation = (
34
- await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
35
- ).data.data.find((module) => module.name === 'Waypoints');
36
-
37
- if (!waypointsInstallation) {
38
- console.log('Waypoints module not found, installing it.');
39
- waypointsInstallation = (
40
- await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
41
- ).data.data;
42
- }
43
-
44
- return { waypointsInstallation, waypointsDefinition };
45
- }
46
-
47
- const { waypointsInstallation, waypointsDefinition } = await ensureWaypointsModule();
48
-
49
11
  try {
50
12
  await takaro.variable.variableControllerCreate({
51
- moduleId: waypointsInstallation.moduleId,
13
+ moduleId: mod.moduleId,
52
14
  gameServerId,
53
15
  key: getWaypointName(args.waypoint),
54
16
  value: JSON.stringify({
@@ -61,50 +23,10 @@ async function main() {
61
23
  if (error.message === 'Request failed with status code 409') {
62
24
  throw new TakaroUserError(`Waypoint ${args.waypoint} already exists.`);
63
25
  }
26
+ throw error;
64
27
  }
65
28
 
66
- const teleportCommand = await takaro.command.commandControllerSearch({
67
- filters: {
68
- moduleId: [mod.moduleId],
69
- name: ['teleportwaypoint'],
70
- },
71
- });
72
-
73
- await takaro.command.commandControllerCreate({
74
- moduleId: waypointsInstallation.moduleId,
75
- name: `waypoint ${args.waypoint} server ${gameServerId}`,
76
- trigger: args.waypoint,
77
- helpText: `Teleport to waypoint ${args.waypoint}.`,
78
- function: teleportCommand.data.data[0].function.code,
79
- });
80
-
81
- const existingPermissions = waypointsDefinition.permissions || [];
82
- const permissionInputDTOs = existingPermissions.map((permission) => ({
83
- permission: permission.permission,
84
- description: permission.description,
85
- friendlyName: permission.friendlyName,
86
- canHaveCount: permission.canHaveCount,
87
- }));
88
-
89
- const gameServer = (await takaro.gameserver.gameServerControllerGetOne(gameServerId)).data.data;
90
-
91
- await takaro.module.moduleControllerUpdate(waypointsInstallation.moduleId, {
92
- permissions: [
93
- {
94
- permission: `WAYPOINTS_USE_${args.waypoint.toUpperCase()}_${gameServerId}`,
95
- description: `Use the waypoint ${args.waypoint} on ${gameServer.name}.`,
96
- friendlyName: `Use waypoint ${args.waypoint} on ${gameServer.name}`,
97
- canHaveCount: false,
98
- },
99
- ...permissionInputDTOs,
100
- ],
101
- });
102
-
103
- // Need to reinstall the module to ensure the new commands systemconfig and permissions are properly in place
104
- await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsInstallation.moduleId, {
105
- systemConfig: JSON.stringify(waypointsInstallation.systemConfig),
106
- userConfig: JSON.stringify(waypointsInstallation.userConfig),
107
- });
29
+ await waypointReconciler();
108
30
 
109
31
  await pog.pm(`Waypoint ${args.waypoint} set.`);
110
32
  }
@@ -7,7 +7,7 @@ function getWaypointName(name) {
7
7
  async function main() {
8
8
  const { pog, gameServerId, trigger, module, itemId } = data;
9
9
 
10
- const triggeredCommand = module.module.commands.find((command) => command.id === itemId);
10
+ const triggeredCommand = module.version.commands.find((command) => command.id === itemId);
11
11
 
12
12
  if (!triggeredCommand) {
13
13
  throw new Error('Waypoint not found.');
@@ -22,46 +22,19 @@ async function main() {
22
22
  throw new TakaroUserError(`You are not allowed to use the waypoint ${trigger}.`);
23
23
  }
24
24
 
25
- async function ensureWaypointsModule() {
26
- let waypointsDefinition = (
27
- await takaro.module.moduleControllerSearch({
28
- filters: {
29
- name: ['Waypoints'],
30
- },
31
- })
32
- ).data.data[0];
33
-
34
- if (!waypointsDefinition) {
35
- console.log('Waypoints module definition not found, creating it.');
36
- waypointsDefinition = (
37
- await takaro.module.moduleControllerCreate({
38
- name: 'Waypoints',
39
- description: 'Waypoints module for the teleport system.',
40
- })
41
- ).data.data;
42
- }
43
-
44
- let waypointsInstallation = (
45
- await takaro.gameserver.gameServerControllerGetInstalledModules(gameServerId)
46
- ).data.data.find((module) => module.name === 'Waypoints');
47
-
48
- if (!waypointsInstallation) {
49
- console.log('Waypoints module not found, installing it.');
50
- waypointsInstallation = (
51
- await takaro.gameserver.gameServerControllerInstallModule(gameServerId, waypointsDefinition.id)
52
- ).data.data;
53
- }
54
-
55
- return { waypointsInstallation, waypointsDefinition };
56
- }
57
-
58
- const { waypointsInstallation } = await ensureWaypointsModule();
25
+ const teleportsModule = (
26
+ await takaro.module.moduleControllerSearch({
27
+ filters: {
28
+ builtin: ['teleports'],
29
+ },
30
+ })
31
+ ).data.data[0];
59
32
 
60
33
  const variable = await takaro.variable.variableControllerSearch({
61
34
  filters: {
62
35
  key: [getWaypointName(trigger)],
63
36
  gameServerId: [gameServerId],
64
- moduleId: [waypointsInstallation.moduleId],
37
+ moduleId: [teleportsModule.id],
65
38
  },
66
39
  });
67
40
 
@@ -0,0 +1,7 @@
1
+ import { waypointReconciler } from './utils.js';
2
+
3
+ async function main() {
4
+ await waypointReconciler();
5
+ }
6
+
7
+ await main();
@@ -34,3 +34,153 @@ export async function findTp(tpName, playerId, pub = false) {
34
34
  sortDirection: 'asc',
35
35
  });
36
36
  }
37
+
38
+ export async function ensureWaypointsModule() {
39
+ const { gameServerId } = data;
40
+ let waypointsDefinition = (
41
+ await takaro.module.moduleControllerSearch({
42
+ filters: {
43
+ name: ['Waypoints'],
44
+ },
45
+ })
46
+ ).data.data[0];
47
+
48
+ if (!waypointsDefinition) {
49
+ console.log('Waypoints module definition not found, creating it.');
50
+ waypointsDefinition = (
51
+ await takaro.module.moduleControllerCreate({
52
+ name: 'Waypoints',
53
+ })
54
+ ).data.data;
55
+ }
56
+
57
+ let waypointsInstallation = (
58
+ await takaro.module.moduleInstallationsControllerGetInstalledModules({
59
+ filters: { gameserverId: [gameServerId] },
60
+ })
61
+ ).data.data.find((module) => module.module.name === 'Waypoints');
62
+
63
+ if (!waypointsInstallation) {
64
+ console.log('Waypoints installation not found, installing it.');
65
+ waypointsInstallation = (
66
+ await takaro.module.moduleInstallationsControllerInstallModule({
67
+ gameServerId,
68
+ versionId: waypointsDefinition.latestVersion.id,
69
+ })
70
+ ).data.data;
71
+ }
72
+
73
+ return { waypointsInstallation, waypointsDefinition };
74
+ }
75
+
76
+ export function getWaypointName(name) {
77
+ return `waypoint ${name}`;
78
+ }
79
+
80
+ export function getWaypointId(varName) {
81
+ const split = varName.split(' ')[1];
82
+ if (split) return split;
83
+ return varName;
84
+ }
85
+
86
+ /**
87
+ * This function is responsible to read all the configured waypoints (vars)
88
+ * and then ensuring that the waypoints module has the correct config
89
+ */
90
+ export async function waypointReconciler() {
91
+ console.log('Reconciling waypoints');
92
+ const { waypointsInstallation, waypointsDefinition } = await ensureWaypointsModule();
93
+ const { gameServerId, module: mod } = data;
94
+
95
+ // Get all the installed waypoints
96
+ const waypointVars = (
97
+ await takaro.variable.variableControllerSearch({
98
+ filters: {
99
+ moduleId: [mod.moduleId],
100
+ gameServerId: [gameServerId],
101
+ },
102
+ })
103
+ ).data.data;
104
+
105
+ const waypointsInModule = waypointsDefinition.latestVersion.commands;
106
+
107
+ // Check if any waypoints are missing in module
108
+ const missingWaypoints = waypointVars.filter((waypointVar) => {
109
+ const existingWaypointsForServer = waypointsInModule.filter((waypoint) => waypoint.name.includes(gameServerId));
110
+ return !existingWaypointsForServer.some((waypoint) => waypoint.trigger === getWaypointId(waypointVar.key));
111
+ });
112
+
113
+ // Check if there are waypoints too many in module compared to our vars
114
+ const toDeleteWaypoints = waypointsInModule.filter((waypoint) => {
115
+ // We ignore any commands that are not for this game server
116
+ if (!waypoint.name.includes(gameServerId)) return false;
117
+ return !waypointVars.some((waypointVar) => getWaypointId(waypointVar.key) === waypoint.trigger);
118
+ });
119
+
120
+ if (!missingWaypoints.length && !toDeleteWaypoints.length) {
121
+ // No changes in waypoints, exit
122
+ return;
123
+ }
124
+
125
+ console.log(
126
+ 'Missing waypoints:',
127
+ missingWaypoints.map((waypoint) => waypoint.key),
128
+ );
129
+ console.log(
130
+ 'To delete waypoints:',
131
+ toDeleteWaypoints.map((waypoint) => waypoint.trigger),
132
+ );
133
+
134
+ // Fetch the teleporting code template
135
+ const teleportCommand = await takaro.command.commandControllerSearch({
136
+ filters: {
137
+ moduleId: [mod.moduleId],
138
+ name: ['teleportwaypoint'],
139
+ },
140
+ });
141
+
142
+ // Edit the module accordingly
143
+ await Promise.all([
144
+ ...missingWaypoints.map((waypoint) => {
145
+ return takaro.command.commandControllerCreate({
146
+ name: `waypoint ${getWaypointId(waypoint.key)} server ${gameServerId}`,
147
+ trigger: getWaypointId(waypoint.key),
148
+ helpText: `Teleport to waypoint ${getWaypointId(waypoint.key)}.`,
149
+ function: teleportCommand.data.data[0].function.code,
150
+ versionId: waypointsInstallation.versionId,
151
+ });
152
+ }),
153
+ ...toDeleteWaypoints.map((waypointVar) => {
154
+ return takaro.command.commandControllerRemove(waypointVar.id);
155
+ }),
156
+ ]);
157
+
158
+ // Update permissions
159
+ const existingPermissions = waypointsDefinition.latestVersion.permissions || [];
160
+ const permissionInputDTOs = existingPermissions.map((permission) => ({
161
+ permission: permission.permission,
162
+ description: permission.description,
163
+ friendlyName: permission.friendlyName,
164
+ canHaveCount: permission.canHaveCount,
165
+ }));
166
+ // We need to filter out the permissions we deleted in the above lines
167
+ const filteredPermissionsInputs = permissionInputDTOs.filter((permission) => {
168
+ return !toDeleteWaypoints.some(
169
+ (waypoint) => permission.permission === `WAYPOINTS_USE_${waypoint.trigger.toUpperCase()}_${gameServerId}`,
170
+ );
171
+ });
172
+ const gameServer = (await takaro.gameserver.gameServerControllerGetOne(gameServerId)).data.data;
173
+ await takaro.module.moduleControllerUpdate(waypointsInstallation.moduleId, {
174
+ latestVersion: {
175
+ permissions: [
176
+ ...filteredPermissionsInputs,
177
+ ...missingWaypoints.map((waypoint) => ({
178
+ permission: `WAYPOINTS_USE_${getWaypointId(waypoint.key).toUpperCase()}_${gameServerId}`,
179
+ description: `Use the waypoint ${getWaypointId(waypoint.key)} on ${gameServer.name}.`,
180
+ friendlyName: `Use waypoint ${getWaypointId(waypoint.key)} on ${gameServer.name}`,
181
+ canHaveCount: false,
182
+ })),
183
+ ],
184
+ },
185
+ });
186
+ }