@rpgjs/server 4.1.2 → 4.2.0

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.
package/lib/inject.js ADDED
@@ -0,0 +1,29 @@
1
+ let instanceContext = null;
2
+ /**
3
+ * Dependency injection function for RPGJS server side.
4
+ *
5
+ * The server-side `inject` function is designed for retrieving instances of server-related classes in the RPGJS framework.
6
+ * This function is crucial for accessing singleton instances of classes like `RpgServerEngine` on the server. It facilitates
7
+ * a clean and efficient approach to handling dependencies within server modules, contributing to a more organized codebase.
8
+ *
9
+ * @template T The class type that you want to retrieve an instance of, specific to server-side modules.
10
+ * @returns {T} Returns the singleton instance of the specified class, ensuring consistent server-side behavior and state management.
11
+ * @since 4.2.0
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // Example of injecting the RpgServerEngine
16
+ * import { inject, RpgServerEngine } from '@rpgjs/server'
17
+ * const server = inject(RpgServerEngine)
18
+ * ```
19
+ */
20
+ export function inject(service, args = []) {
21
+ return instanceContext.inject(service, args);
22
+ }
23
+ export function setInject(context) {
24
+ instanceContext = context;
25
+ }
26
+ export function clearInject() {
27
+ instanceContext = null;
28
+ }
29
+ //# sourceMappingURL=inject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAEA,IAAI,eAAe,GAAyB,IAAI,CAAA;AAEhD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAI,OAAkC,EAAE,OAAc,EAAE;IAC1E,OAAO,eAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,OAAsB;IAC5C,eAAe,GAAG,OAAO,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,eAAe,GAAG,IAAI,CAAA;AAC1B,CAAC"}
package/lib/server.d.ts CHANGED
@@ -5,9 +5,6 @@ import { Observable } from 'rxjs';
5
5
  import { Tick } from '@rpgjs/types';
6
6
  import { DatabaseTypes } from '@rpgjs/database';
7
7
  export declare class RpgServerEngine {
8
- io: any;
9
- gameEngine: RpgCommonGame;
10
- inputOptions: any;
11
8
  /**
12
9
  * Express App Instance. If you have assigned this variable before starting the game, you can get the instance of Express
13
10
  *
@@ -42,16 +39,19 @@ export declare class RpgServerEngine {
42
39
  protected totalConnected: number;
43
40
  private scheduler;
44
41
  private playerProps;
42
+ gameEngine: RpgCommonGame;
45
43
  world: WorldClass;
46
44
  workers: any;
47
45
  envs: any;
46
+ io: any;
47
+ inputOptions: any;
48
48
  /**
49
49
  * Combat formulas
50
50
  *
51
51
  * @prop {Socket Io Server} [io]
52
52
  * @memberof RpgServerEngine
53
53
  */
54
- constructor(io: any, gameEngine: RpgCommonGame, inputOptions: any);
54
+ initialize(io: any, inputOptions: any): void;
55
55
  private _init;
56
56
  /**
57
57
  * Adds data to the server's database (in RAM) for later use
@@ -104,6 +104,7 @@ export declare class RpgServerEngine {
104
104
  * @memberof RpgServerEngine
105
105
  */
106
106
  start(inputOptions?: any, scheduler?: boolean): Promise<void>;
107
+ private transport;
107
108
  get tick(): Observable<Tick>;
108
109
  /**
109
110
  * Sends all packages to clients. The sending is done automatically but you can decide to send yourself by calling this method (for example, for unit tests)
@@ -113,7 +114,7 @@ export declare class RpgServerEngine {
113
114
  * @returns {void}
114
115
  * @memberof RpgServerEngine
115
116
  */
116
- send(): void;
117
+ send(): Promise<void>;
117
118
  private updatePlayersMove;
118
119
  nextTick(timestamp: number): void;
119
120
  step(t: number, dt: number): void;
@@ -129,6 +130,7 @@ export declare class RpgServerEngine {
129
130
  get module(): import("@rpgjs/common/lib/Plugin").PluginSystem;
130
131
  get assetsPath(): string;
131
132
  sendToPlayer(currentPlayer: any, eventName: any, data: any): void;
133
+ private getPlayerBySession;
132
134
  private onPlayerConnected;
133
135
  private onPlayerDisconnected;
134
136
  stop(): void;
package/lib/server.js CHANGED
@@ -8,20 +8,12 @@ import { SceneMap } from './Scenes/Map.js';
8
8
  import { RpgPlayer } from './Player/Player.js';
9
9
  import { Query } from './Query.js';
10
10
  import { DAMAGE_SKILL, DAMAGE_PHYSIC, DAMAGE_CRITICAL, COEFFICIENT_ELEMENTS } from './presets/index.js';
11
- import { World } from 'simple-room';
12
- import { Utils, RpgPlugin, Scheduler, HookServer, DefaultInput } from '@rpgjs/common';
11
+ import { World, Transport } from 'simple-room';
12
+ import { Utils, RpgPlugin, Scheduler, HookServer, RpgCommonGame, DefaultInput } from '@rpgjs/common';
13
13
  import { Actor, Armor, Class, Item, Skill, State, Weapon } from '@rpgjs/database';
14
+ import { inject } from './inject.js';
14
15
  export class RpgServerEngine {
15
- /**
16
- * Combat formulas
17
- *
18
- * @prop {Socket Io Server} [io]
19
- * @memberof RpgServerEngine
20
- */
21
- constructor(io, gameEngine, inputOptions) {
22
- this.io = io;
23
- this.gameEngine = gameEngine;
24
- this.inputOptions = inputOptions;
16
+ constructor() {
25
17
  /**
26
18
  * List of the data
27
19
  *
@@ -48,8 +40,20 @@ export class RpgServerEngine {
48
40
  this.scenes = new Map();
49
41
  this.totalConnected = 0;
50
42
  this.scheduler = new Scheduler();
43
+ this.gameEngine = inject(RpgCommonGame);
51
44
  this.world = World;
52
45
  this.envs = {};
46
+ this.inputOptions = {};
47
+ }
48
+ /**
49
+ * Combat formulas
50
+ *
51
+ * @prop {Socket Io Server} [io]
52
+ * @memberof RpgServerEngine
53
+ */
54
+ initialize(io, inputOptions) {
55
+ this.io = io;
56
+ this.inputOptions = inputOptions;
53
57
  this.envs = inputOptions.envs || {};
54
58
  if (this.inputOptions.workers) {
55
59
  console.log('workers enabled');
@@ -91,16 +95,21 @@ export class RpgServerEngine {
91
95
  };
92
96
  if (!this.inputOptions.database)
93
97
  this.inputOptions.database = {};
98
+ /**
99
+ * data is array with object or array
100
+ */
94
101
  const datas = await RpgPlugin.emit(HookServer.AddDatabase, this.inputOptions.database) || [];
95
- for (let plug of datas) {
96
- this.inputOptions.database = {
97
- ...plug,
98
- ...this.inputOptions.database
99
- };
100
- }
101
- for (let key in this.inputOptions.database) {
102
- const data = this.inputOptions.database[key];
103
- this.addInDatabase(data.id, data);
102
+ for (let element of datas) {
103
+ if (Array.isArray(element)) {
104
+ for (let data of element) {
105
+ this.addInDatabase(data.id, data);
106
+ }
107
+ }
108
+ else {
109
+ for (let id in element) {
110
+ this.addInDatabase(element[id].id ?? id, element[id]);
111
+ }
112
+ }
104
113
  }
105
114
  this.loadScenes();
106
115
  }
@@ -242,9 +251,29 @@ export class RpgServerEngine {
242
251
  return Query._getShapesOfMap(map);
243
252
  }
244
253
  });
245
- this.io.on('connection', this.onPlayerConnected.bind(this));
254
+ //this.io.on('connection', this.onPlayerConnected.bind(this))
255
+ this.transport(this.io);
246
256
  await RpgPlugin.emit(HookServer.Start, this);
247
257
  }
258
+ transport(io) {
259
+ const timeoutDisconnect = this.globalConfig.timeoutDisconnect ?? 0;
260
+ const auth = this.globalConfig.disableAuth ? () => Utils.generateUID() :
261
+ async (socket) => {
262
+ const val = await RpgPlugin.emit(HookServer.Auth, [this, socket], true);
263
+ if (val.length == 0) {
264
+ return Utils.generateUID();
265
+ }
266
+ return val[val.length - 1];
267
+ };
268
+ const transport = new Transport(io, {
269
+ timeoutDisconnect,
270
+ auth
271
+ });
272
+ this.world.timeoutDisconnect = timeoutDisconnect;
273
+ transport.onConnected(this.onPlayerConnected.bind(this));
274
+ transport.onDisconnected(this.onPlayerDisconnected.bind(this));
275
+ return transport;
276
+ }
248
277
  get tick() {
249
278
  return this.scheduler.tick;
250
279
  }
@@ -257,7 +286,7 @@ export class RpgServerEngine {
257
286
  * @memberof RpgServerEngine
258
287
  */
259
288
  send() {
260
- this.world.send();
289
+ return this.world.send();
261
290
  }
262
291
  async updatePlayersMove(deltaTimeInt) {
263
292
  const players = this.world.getUsers();
@@ -320,7 +349,7 @@ export class RpgServerEngine {
320
349
  maps: this.inputOptions.maps,
321
350
  events: this.inputOptions.events,
322
351
  worldMaps: this.inputOptions.worldMaps
323
- }, this));
352
+ }));
324
353
  }
325
354
  getScene(name) {
326
355
  return this.scenes.get(name);
@@ -343,11 +372,49 @@ export class RpgServerEngine {
343
372
  sendToPlayer(currentPlayer, eventName, data) {
344
373
  currentPlayer._socket.emit(eventName, data);
345
374
  }
346
- onPlayerConnected(socket) {
347
- const { token } = socket.handshake.auth;
348
- const playerId = Utils.generateUID();
349
- const player = new RpgPlayer(this.gameEngine, playerId);
350
- player.session = token;
375
+ getPlayerBySession(session) {
376
+ const users = this.world.getUsers();
377
+ for (let userId in users) {
378
+ const user = users[userId];
379
+ if (user.session === session) {
380
+ return user;
381
+ }
382
+ }
383
+ return null;
384
+ }
385
+ onPlayerConnected(socket, playerId) {
386
+ const existingUser = this.world.getUser(playerId, false);
387
+ this.world.connectUser(socket, playerId);
388
+ let player;
389
+ if (!existingUser) {
390
+ const { token } = socket.handshake.auth;
391
+ player = new RpgPlayer(playerId);
392
+ player.session = token;
393
+ this.world.setUser(player, socket);
394
+ player._init();
395
+ if (!token) {
396
+ const newToken = Utils.generateUID() + '-' + Utils.generateUID() + '-' + Utils.generateUID();
397
+ player.session = newToken;
398
+ }
399
+ if (!token) {
400
+ player.execMethod('onConnected');
401
+ }
402
+ else {
403
+ RpgPlugin.emit(HookServer.ScalabilityPlayerConnected, player);
404
+ }
405
+ }
406
+ else {
407
+ player = existingUser;
408
+ if (player.map) {
409
+ player.emit('preLoadScene', {
410
+ reconnect: true,
411
+ id: player.map
412
+ });
413
+ player.emitSceneMap();
414
+ this.world.joinRoom(player.map, playerId);
415
+ }
416
+ }
417
+ socket.emit('playerJoined', { playerId, session: player.session });
351
418
  socket.on('move', (data) => {
352
419
  if (!data?.input)
353
420
  return;
@@ -364,23 +431,6 @@ export class RpgServerEngine {
364
431
  });
365
432
  }
366
433
  });
367
- socket.on('disconnect', () => {
368
- this.onPlayerDisconnected(playerId);
369
- });
370
- this.world.setUser(player, socket);
371
- player.server = this;
372
- player._init();
373
- if (!token) {
374
- const newToken = Utils.generateUID() + '-' + Utils.generateUID() + '-' + Utils.generateUID();
375
- player.session = newToken;
376
- }
377
- socket.emit('playerJoined', { playerId, session: player.session });
378
- if (!token) {
379
- player.execMethod('onConnected');
380
- }
381
- else {
382
- RpgPlugin.emit(HookServer.ScalabilityPlayerConnected, player);
383
- }
384
434
  }
385
435
  onPlayerDisconnected(playerId) {
386
436
  const player = World.getUser(playerId);
package/lib/server.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAC9F,OAAO,EAAE,KAAK,EAAc,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAiB,YAAY,EAAE,MAAM,eAAe,CAAA;AAGpG,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAiB,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjG,MAAM,OAAO,eAAe;IA8CxB;;;;;OAKG;IACH,YAAmB,EAAE,EAAS,UAAyB,EAAS,YAAY;QAAzD,OAAE,GAAF,EAAE,CAAA;QAAS,eAAU,GAAV,UAAU,CAAe;QAAS,iBAAY,GAAZ,YAAY,CAAA;QA1C5E;;;;;WAKG;QACI,aAAQ,GAAQ,EAAE,CAAA;QAEzB;;;;;;aAMK;QACE,iBAAY,GAAQ,EAAE,CAAA;QAE7B;;;;;WAKG;QACI,mBAAc,GAAQ,EAAE,CAAA;QAExB,aAAQ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Y,EAAE,CAAA;gBACrB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;aAC5C;SACJ;QAED,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAA;QAElE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAwC,EAAE,EAAE;YAC3D,IAAI,CAAC,IAAI,EAAE,KAAK;gBAAE,OAAM;YACxB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;gBAAE,OAAM;YACtC,MAAM,aAAa,GAAG,MAAM,CAAC,oBAAoB,IAAI,MAAM,CAAA;YAC3D,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE;gBACxB,OAAM;aACT;YACD,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE;gBAC1B,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC;oBAC3B,KAAK;oBACL,KAAK,EAAE,IAAI,CAAC,KAAK;iBACpB,CAAC,CAAA;aACL;QACL,CAAC,CAAC,CAAA;IAEN,CAAC;IAEO,oBAAoB,CAAC,QAAgB;QACzC,MAAM,MAAM,GAAc,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAc,CAAA;QAC9D,MAAM,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAA;QACnC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;IACvC,CAAC;IAED,IAAI;QACA,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAA;IACzB,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/server",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -27,24 +27,23 @@
27
27
  "author": "Samuel Ronce",
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@rpgjs/common": "^4.1.1",
31
- "@rpgjs/database": "^4.1.1",
30
+ "@rpgjs/common": "^4.2.0",
31
+ "@rpgjs/database": "^4.2.0",
32
32
  "@rpgjs/tiled": "^4.0.5",
33
33
  "@rpgjs/types": "^4.0.5",
34
34
  "axios": "^1.3.6",
35
35
  "cors": "^2.8.5",
36
36
  "express": "^4.18.2",
37
37
  "lodash.merge": "^4.6.2",
38
- "pathfinding": "^0.4.18",
39
38
  "pretty-error": "^4.0.0",
40
39
  "rxjs": "7.8.0",
41
40
  "sat": "^0.9.0",
42
- "simple-room": "^2.4.1",
41
+ "simple-room": "^3.1.1",
43
42
  "socket.io": "^4.6.1"
44
43
  },
45
- "gitHead": "9e5c8ba4fcc73e0e156df69f930012c58349c3f5",
44
+ "gitHead": "afba6593c6d060c46a67be465bef2abd401d4c8d",
46
45
  "devDependencies": {
47
- "@rpgjs/compiler": "^4.1.1",
46
+ "@rpgjs/compiler": "^4.2.0",
48
47
  "typescript": "^5.0.4"
49
48
  },
50
49
  "alias": {
@@ -105,7 +105,7 @@ export class EventManager {
105
105
  for (let playerId in map.players) {
106
106
  if (object.id == playerId) continue
107
107
  const otherPlayer = map.players[playerId]
108
- if (otherPlayer.following?.id == object.id) {
108
+ if (otherPlayer.followingId == object.id) {
109
109
  otherPlayer.cameraFollow(otherPlayer)
110
110
  }
111
111
  }
package/src/Game/Map.ts CHANGED
@@ -90,6 +90,21 @@ export class RpgMap extends RpgCommonMap {
90
90
  return Object.keys(this.players).length
91
91
  }
92
92
 
93
+ $additionalEmitProperties(player: RpgPlayer) {
94
+ const lastFramePositions: {
95
+ frame: number
96
+ position: unknown
97
+ } | undefined = player['_lastFramePositions']
98
+ let pos
99
+ let lastFrame
100
+ if (lastFramePositions) {
101
+ pos = lastFramePositions.position
102
+ lastFrame = lastFramePositions.frame
103
+ }
104
+ const data = { frame: lastFrame, pos }
105
+ return data
106
+ }
107
+
93
108
  async load() {
94
109
  if (RpgCommonMap.buffer.has(this.id)) {
95
110
  return
@@ -390,7 +405,6 @@ export class RpgMap extends RpgCommonMap {
390
405
  const ev = this.game.addEvent<RpgEvent>(event)
391
406
  const _shape = shape || this.getEventShape(ev.name)
392
407
  ev.map = this.id
393
- ev.server = this._server
394
408
  ev.width = event.width || this.tileWidth
395
409
  ev.height = event.height || this.tileHeight
396
410
  if (_shape && _shape.properties) ev.properties = _shape.properties
package/src/MatchMaker.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  import axios from 'axios'
3
3
  import { Utils } from '@rpgjs/common'
4
4
  import { RpgPlayer } from './Player/Player'
5
+ import { inject } from './inject'
6
+ import { RpgServerEngine } from './server'
5
7
 
6
8
  interface MatchMakerPayload {
7
9
  playerId: string
@@ -32,7 +34,7 @@ export class RpgMatchMaker {
32
34
  }
33
35
 
34
36
  async getServer(player: RpgPlayer): Promise<MatchMakerResponse | null> {
35
- const currentServerId = player.server.serverId
37
+ const currentServerId = inject(RpgServerEngine).serverId
36
38
  const payload: MatchMakerPayload = {
37
39
  playerId: player.id,
38
40
  mapName: player.map
@@ -37,6 +37,7 @@ import { CameraOptions, PositionXY_OptionalZ, SocketEvents, SocketMethods, Layou
37
37
  import { ComponentManager } from './ComponentManager'
38
38
  import { Subject } from 'rxjs'
39
39
  import { EventManager, EventMode } from '../Game/EventManager'
40
+ import { inject } from '../inject'
40
41
 
41
42
  const {
42
43
  isPromise,
@@ -104,7 +105,7 @@ const playerSchemas = {
104
105
  sp: Number,
105
106
  gold: Number,
106
107
  level: {
107
- $effects: ['$this.expForNextlevel']
108
+ $effects: ['$this.expForNextlevel', '$this.param']
108
109
  },
109
110
  expForNextlevel: {
110
111
  $permanent: false
@@ -200,6 +201,7 @@ export class RpgPlayer extends RpgCommonPlayer {
200
201
  * ```
201
202
  * @title Server Instance
202
203
  * @prop {RpgServerEngine} player.server
204
+ * @deprecated Use `inject(RpgServerEngine)` instead. Will be removed in v5
203
205
  * @memberof Player
204
206
  * */
205
207
  public server: RpgServerEngine
@@ -208,7 +210,7 @@ export class RpgPlayer extends RpgCommonPlayer {
208
210
  /** @internal */
209
211
  public tmpPositions: Position | string | null = null
210
212
  public otherPossessedPlayer: RpgPlayer | RpgEvent | null = null
211
- public following: RpgPlayer | RpgEvent | null = null
213
+ public followingId: string | null = null
212
214
 
213
215
  // Indicates whether to load data with load(). In this case, hooks are not triggered.
214
216
  private _dataLoading: boolean = false
@@ -218,10 +220,10 @@ export class RpgPlayer extends RpgCommonPlayer {
218
220
  position: Position
219
221
  } | undefined
220
222
 
221
- constructor(gameEngine: RpgCommonGame, playerId: string) {
222
- super(gameEngine, playerId)
223
- this.initialize()
224
- }
223
+ /**
224
+ * @deprecated Use `inject(RpgCommonGame)` instead. Will be removed in v5
225
+ */
226
+ public gameEngine: RpgCommonGame = inject(RpgCommonGame)
225
227
 
226
228
  // redefine type (as RpgPlayer)
227
229
  get otherPlayersCollision(): RpgPlayer[] {
@@ -238,8 +240,14 @@ export class RpgPlayer extends RpgCommonPlayer {
238
240
  // a flag that lets the client know if the event is suppressed. The client can, for example, end animations before completely deleting the object (client side).
239
241
  deleted: boolean = false
240
242
 
243
+ constructor(public playerId: string) {
244
+ super(inject(RpgCommonGame), playerId)
245
+ this.initialize()
246
+ }
247
+
241
248
  /** @internal */
242
249
  initialize() {
250
+ this.server = inject(RpgServerEngine)
243
251
  this.expCurve = {
244
252
  basis: 30,
245
253
  extra: 20,
@@ -597,7 +605,7 @@ export class RpgPlayer extends RpgCommonPlayer {
597
605
  }
598
606
 
599
607
  toJSON() {
600
- const { permanentObject } = Room.toDict(this.schema)
608
+ const { permanentObject } = Room.compileSchema(this.schema)
601
609
  const snapshot = Room.extractObjectOfRoom(this, permanentObject)
602
610
  snapshot.variables = [...this.variables]
603
611
  return snapshot
@@ -769,10 +777,10 @@ export class RpgPlayer extends RpgCommonPlayer {
769
777
  */
770
778
  cameraFollow(otherPlayer: RpgPlayer | RpgEvent, options: CameraOptions = {}) {
771
779
  if (otherPlayer.id == this.id) {
772
- this.following = null
780
+ this.followingId = null
773
781
  }
774
782
  else {
775
- this.following = otherPlayer
783
+ this.followingId = otherPlayer.id
776
784
  }
777
785
  this.emit(SocketEvents.CallMethod, {
778
786
  objectId: this.playerId,
@@ -1004,8 +1012,8 @@ export class RpgEvent extends RpgPlayer {
1004
1012
  mode: EventMode
1005
1013
  playerRelated: RpgPlayer | null = null
1006
1014
 
1007
- constructor(gameEngine: RpgCommonGame, playerId: string) {
1008
- super(gameEngine, playerId)
1015
+ constructor(playerId: string) {
1016
+ super(playerId)
1009
1017
  }
1010
1018
 
1011
1019
  async execMethod(methodName: string, methodData = []) {
package/src/RpgServer.ts CHANGED
@@ -25,6 +25,36 @@ export interface RpgServerEngineHooks {
25
25
  * @memberof RpgServerEngineHooks
26
26
  */
27
27
  onStep?: (server: RpgServerEngine) => any
28
+
29
+ /**
30
+ * Flexible authentication function for RPGJS.
31
+ *
32
+ * This `auth` function is an integral part of the connection process in RPGJS, designed to be agnostic
33
+ * and adaptable to various authentication systems. It is not tied to any specific database or third-party
34
+ * authentication service, allowing developers to implement custom logic suited to their game's requirements.
35
+ * This flexibility is particularly useful in MMORPGs where diverse and robust authentication mechanisms may be needed.
36
+ *
37
+ * The function is called during the player connection phase and should handle the verification of player credentials.
38
+ * The implementation can vary widely based on the chosen authentication method (e.g., JWT tokens, OAuth, custom tokens).
39
+ *
40
+ * @param {RpgServerEngine} server - The instance of the game server.
41
+ * @param {SocketIO.Socket} socket - The socket instance for the connecting player. This can be used to access client-sent data, like tokens or other credentials.
42
+ * @returns {Promise<string> | string} The function should return a promise that resolves to a player's unique identifier (e.g., user ID) if authentication is successful, or a string representing the user's ID. Alternatively, it can throw an error if authentication fails.
43
+ * @throws {string} Throwing an error will prevent the player from connecting, signifying a failed authentication attempt.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * // Example of a simple token-based authentication in main/server.ts
48
+ * const server: RpgServerEngineHooks = {
49
+ * auth(server, socket) {
50
+ * const token = socket.handshake.query.token;
51
+ * // Implement your authentication logic here
52
+ * // Return user ID or throw an error if authentication fails
53
+ * }
54
+ * };
55
+ * ```
56
+ */
57
+ auth?: (server: RpgServerEngine, socket: any) => Promise<string> | string | never
28
58
  }
29
59
 
30
60
  export interface RpgPlayerHooks {
@@ -239,7 +269,6 @@ export interface RpgServer {
239
269
  player?: string[],
240
270
  engine?: string[]
241
271
  }
242
-
243
272
  /**
244
273
  * Adding sub-modules
245
274
  *
package/src/Scenes/Map.ts CHANGED
@@ -7,6 +7,7 @@ import { RpgMap } from '../Game/Map'
7
7
  import { RpgWorldMaps, WorldMap } from '../Game/WorldMaps'
8
8
  import { RpgEvent, RpgPlayer } from '../Player/Player'
9
9
  import { RpgServerEngine } from '../server'
10
+ import { inject } from '../inject'
10
11
 
11
12
  export interface RpgClassMap<T> {
12
13
  id?: string
@@ -28,8 +29,9 @@ export class SceneMap {
28
29
  [mapId: string]: RpgClassMap<RpgMap>
29
30
  } = {}
30
31
  private worldMaps: Map<string, RpgWorldMaps> = new Map()
32
+ private server: RpgServerEngine = inject(RpgServerEngine)
31
33
 
32
- constructor(sceneMapObject: SceneMapObject, private server: RpgServerEngine) {
34
+ constructor(sceneMapObject: SceneMapObject) {
33
35
  const { maps, worldMaps, events } = sceneMapObject
34
36
  this.maps = maps
35
37
  this.mapsById = {}
@@ -252,7 +254,9 @@ export class SceneMap {
252
254
  return null
253
255
  }
254
256
 
255
- player.emit('preLoadScene', mapId)
257
+ player.emit('preLoadScene', {
258
+ id: mapId
259
+ })
256
260
 
257
261
  player.prevMap = player.map
258
262
 
@@ -1,7 +1,8 @@
1
- import { RpgCommonGame, HookServer, loadModules, ModuleType, GameSide, RpgPlugin } from '@rpgjs/common'
1
+ import { RpgCommonGame, HookServer, loadModules, ModuleType, GameSide, RpgPlugin, InjectContext } from '@rpgjs/common'
2
2
  import { RpgServerEngine } from './server'
3
3
  import { RpgPlayer } from './Player/Player'
4
4
  import { RpgMatchMaker } from './MatchMaker'
5
+ import { inject, setInject } from './inject'
5
6
 
6
7
  interface RpgServerEntryPointOptions {
7
8
  /**
@@ -39,7 +40,10 @@ interface RpgServerEntryPointOptions {
39
40
  }
40
41
 
41
42
  export default async function (modules: ModuleType[], options: RpgServerEntryPointOptions): Promise<RpgServerEngine> {
42
- const gameEngine = new RpgCommonGame(GameSide.Server)
43
+ const context = new InjectContext()
44
+ setInject(context)
45
+
46
+ inject(RpgCommonGame, [GameSide.Server])
43
47
 
44
48
  if (!options.globalConfig) options.globalConfig = {}
45
49
 
@@ -59,7 +63,8 @@ export default async function (modules: ModuleType[], options: RpgServerEntryPoi
59
63
 
60
64
  const relationsEngine = {
61
65
  onStart: HookServer.Start,
62
- onStep: HookServer.Step
66
+ onStep: HookServer.Step,
67
+ auth: HookServer.Auth
63
68
  }
64
69
 
65
70
  const { playerProps } = await loadModules(modules, {
@@ -91,14 +96,16 @@ export default async function (modules: ModuleType[], options: RpgServerEntryPoi
91
96
  return mod
92
97
  })
93
98
 
94
- const serverEngine = new RpgServerEngine(options.io, gameEngine, {
95
- debug: {},
96
- updateRate: 10,
97
- stepRate: 60,
98
- timeoutInterval: 0,
99
- countConnections: false,
100
- playerProps,
101
- ...options
102
- })
99
+ const serverEngine = inject(RpgServerEngine, [
100
+ options.io, {
101
+ debug: {},
102
+ updateRate: 10,
103
+ stepRate: 60,
104
+ timeoutInterval: 0,
105
+ countConnections: false,
106
+ playerProps,
107
+ ...options
108
+ }
109
+ ])
103
110
  return serverEngine
104
111
  }