@rpgjs/server 4.2.2 → 5.0.0-alpha.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 → dist}/Gui/DialogGui.d.ts +1 -2
- package/{lib → dist}/Gui/Gui.d.ts +1 -2
- package/dist/Player/BattleManager.d.ts +22 -0
- package/dist/Player/ClassManager.d.ts +18 -0
- package/dist/Player/Event.d.ts +0 -0
- package/dist/Player/ItemManager.d.ts +17 -0
- package/dist/Player/MoveManager.d.ts +177 -0
- package/dist/Player/ParameterManager.d.ts +42 -0
- package/dist/Player/Player.d.ts +73 -0
- package/dist/Player/SkillManager.d.ts +23 -0
- package/dist/Player/StateManager.d.ts +39 -0
- package/{lib → dist}/RpgServer.d.ts +34 -17
- package/dist/RpgServerEngine.d.ts +5 -0
- package/dist/core/context.d.ts +2 -0
- package/dist/core/inject.d.ts +5 -0
- package/dist/core/setup.d.ts +6 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +29673 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +2 -0
- package/dist/rooms/lobby.d.ts +6 -0
- package/dist/rooms/map.d.ts +110 -0
- package/package.json +16 -38
- package/src/Gui/DialogGui.ts +3 -4
- package/src/Gui/Gui.ts +4 -6
- package/src/Player/BattleManager.ts +108 -99
- package/src/Player/ClassManager.ts +47 -46
- package/src/Player/ComponentManager.ts +26 -535
- package/src/Player/EffectManager.ts +44 -59
- package/src/Player/ElementManager.ts +70 -72
- package/src/Player/Event.ts +0 -0
- package/src/Player/GoldManager.ts +24 -6
- package/src/Player/GuiManager.ts +106 -97
- package/src/Player/ItemFixture.ts +22 -17
- package/src/Player/ItemManager.ts +234 -225
- package/src/Player/MoveManager.ts +1047 -457
- package/src/Player/ParameterManager.ts +59 -37
- package/src/Player/Player.ts +272 -1058
- package/src/Player/SkillManager.ts +146 -137
- package/src/Player/StateManager.ts +124 -98
- package/src/Player/VariableManager.ts +23 -3
- package/src/RpgServer.ts +38 -14
- package/src/RpgServerEngine.ts +7 -0
- package/src/core/context.ts +3 -0
- package/src/core/inject.ts +17 -0
- package/src/core/setup.ts +20 -0
- package/src/index.ts +9 -31
- package/src/module.ts +32 -0
- package/src/presets/index.ts +1 -3
- package/src/rooms/lobby.ts +24 -0
- package/src/rooms/map.ts +311 -0
- package/tsconfig.json +26 -23
- package/vite.config.ts +21 -0
- package/CHANGELOG.md +0 -163
- package/LICENSE +0 -19
- package/browser/manifest.json +0 -7
- package/browser/rpg.server.js +0 -22372
- package/browser/rpg.server.umd.cjs +0 -22403
- package/lib/Game/EventManager.d.ts +0 -54
- package/lib/Game/EventManager.js +0 -107
- package/lib/Game/EventManager.js.map +0 -1
- package/lib/Game/Map.d.ts +0 -191
- package/lib/Game/Map.js +0 -414
- package/lib/Game/Map.js.map +0 -1
- package/lib/Game/WorldMaps.d.ts +0 -17
- package/lib/Game/WorldMaps.js +0 -28
- package/lib/Game/WorldMaps.js.map +0 -1
- package/lib/Gui/DialogGui.js +0 -57
- package/lib/Gui/DialogGui.js.map +0 -1
- package/lib/Gui/Gui.js +0 -37
- package/lib/Gui/Gui.js.map +0 -1
- package/lib/Gui/MenuGui.js +0 -23
- package/lib/Gui/MenuGui.js.map +0 -1
- package/lib/Gui/NotificationGui.js +0 -8
- package/lib/Gui/NotificationGui.js.map +0 -1
- package/lib/Gui/ShopGui.js +0 -40
- package/lib/Gui/ShopGui.js.map +0 -1
- package/lib/Gui/index.js +0 -7
- package/lib/Gui/index.js.map +0 -1
- package/lib/Interfaces/Gui.d.ts +0 -4
- package/lib/Interfaces/Gui.js +0 -2
- package/lib/Interfaces/Gui.js.map +0 -1
- package/lib/Interfaces/StateStore.d.ts +0 -5
- package/lib/Interfaces/StateStore.js +0 -2
- package/lib/Interfaces/StateStore.js.map +0 -1
- package/lib/MatchMaker.d.ts +0 -24
- package/lib/MatchMaker.js +0 -42
- package/lib/MatchMaker.js.map +0 -1
- package/lib/Monitor/index.d.ts +0 -17
- package/lib/Monitor/index.js +0 -72
- package/lib/Monitor/index.js.map +0 -1
- package/lib/Player/BattleManager.d.ts +0 -36
- package/lib/Player/BattleManager.js +0 -101
- package/lib/Player/BattleManager.js.map +0 -1
- package/lib/Player/ClassManager.d.ts +0 -47
- package/lib/Player/ClassManager.js +0 -65
- package/lib/Player/ClassManager.js.map +0 -1
- package/lib/Player/ComponentManager.d.ts +0 -397
- package/lib/Player/ComponentManager.js +0 -505
- package/lib/Player/ComponentManager.js.map +0 -1
- package/lib/Player/EffectManager.d.ts +0 -46
- package/lib/Player/EffectManager.js +0 -75
- package/lib/Player/EffectManager.js.map +0 -1
- package/lib/Player/ElementManager.d.ts +0 -108
- package/lib/Player/ElementManager.js +0 -120
- package/lib/Player/ElementManager.js.map +0 -1
- package/lib/Player/GoldManager.d.ts +0 -17
- package/lib/Player/GoldManager.js +0 -27
- package/lib/Player/GoldManager.js.map +0 -1
- package/lib/Player/GuiManager.d.ts +0 -247
- package/lib/Player/GuiManager.js +0 -291
- package/lib/Player/GuiManager.js.map +0 -1
- package/lib/Player/ItemFixture.d.ts +0 -7
- package/lib/Player/ItemFixture.js +0 -19
- package/lib/Player/ItemFixture.js.map +0 -1
- package/lib/Player/ItemManager.d.ts +0 -331
- package/lib/Player/ItemManager.js +0 -475
- package/lib/Player/ItemManager.js.map +0 -1
- package/lib/Player/MoveManager.d.ts +0 -333
- package/lib/Player/MoveManager.js +0 -450
- package/lib/Player/MoveManager.js.map +0 -1
- package/lib/Player/ParameterManager.d.ts +0 -316
- package/lib/Player/ParameterManager.js +0 -408
- package/lib/Player/ParameterManager.js.map +0 -1
- package/lib/Player/Player.d.ts +0 -828
- package/lib/Player/Player.js +0 -927
- package/lib/Player/Player.js.map +0 -1
- package/lib/Player/SkillManager.d.ts +0 -163
- package/lib/Player/SkillManager.js +0 -223
- package/lib/Player/SkillManager.js.map +0 -1
- package/lib/Player/StateManager.d.ts +0 -185
- package/lib/Player/StateManager.js +0 -228
- package/lib/Player/StateManager.js.map +0 -1
- package/lib/Player/VariableManager.d.ts +0 -46
- package/lib/Player/VariableManager.js +0 -52
- package/lib/Player/VariableManager.js.map +0 -1
- package/lib/Query.d.ts +0 -127
- package/lib/Query.js +0 -159
- package/lib/Query.js.map +0 -1
- package/lib/RpgServer.js +0 -2
- package/lib/RpgServer.js.map +0 -1
- package/lib/Scenes/Map.d.ts +0 -136
- package/lib/Scenes/Map.js +0 -273
- package/lib/Scenes/Map.js.map +0 -1
- package/lib/decorators/event.d.ts +0 -43
- package/lib/decorators/event.js +0 -13
- package/lib/decorators/event.js.map +0 -1
- package/lib/decorators/map.d.ts +0 -178
- package/lib/decorators/map.js +0 -43
- package/lib/decorators/map.js.map +0 -1
- package/lib/entry-point.d.ts +0 -34
- package/lib/entry-point.js +0 -70
- package/lib/entry-point.js.map +0 -1
- package/lib/express/api.d.ts +0 -3
- package/lib/express/api.js +0 -105
- package/lib/express/api.js.map +0 -1
- package/lib/express/errors/NotAuthorized.d.ts +0 -4
- package/lib/express/errors/NotAuthorized.js +0 -7
- package/lib/express/errors/NotAuthorized.js.map +0 -1
- package/lib/express/errors/NotFound.d.ts +0 -4
- package/lib/express/errors/NotFound.js +0 -7
- package/lib/express/errors/NotFound.js.map +0 -1
- package/lib/express/server.d.ts +0 -16
- package/lib/express/server.js +0 -65
- package/lib/express/server.js.map +0 -1
- package/lib/index.d.ts +0 -20
- package/lib/index.js +0 -19
- package/lib/index.js.map +0 -1
- package/lib/inject.d.ts +0 -22
- package/lib/inject.js +0 -29
- package/lib/inject.js.map +0 -1
- package/lib/logs/index.js +0 -6
- package/lib/logs/index.js.map +0 -1
- package/lib/logs/item.js +0 -34
- package/lib/logs/item.js.map +0 -1
- package/lib/logs/log.js +0 -7
- package/lib/logs/log.js.map +0 -1
- package/lib/logs/skill.js +0 -19
- package/lib/logs/skill.js.map +0 -1
- package/lib/logs/state.js +0 -13
- package/lib/logs/state.js.map +0 -1
- package/lib/models/Item.d.ts +0 -10
- package/lib/models/Item.js +0 -2
- package/lib/models/Item.js.map +0 -1
- package/lib/presets/index.js +0 -65
- package/lib/presets/index.js.map +0 -1
- package/lib/server.d.ts +0 -137
- package/lib/server.js +0 -443
- package/lib/server.js.map +0 -1
- package/rpg.toml +0 -14
- package/src/Game/EventManager.ts +0 -125
- package/src/Game/Map.ts +0 -495
- package/src/Game/WorldMaps.ts +0 -45
- package/src/Interfaces/Gui.ts +0 -4
- package/src/Interfaces/StateStore.ts +0 -5
- package/src/MatchMaker.ts +0 -65
- package/src/Monitor/index.ts +0 -78
- package/src/Query.ts +0 -172
- package/src/Scenes/Map.ts +0 -310
- package/src/decorators/event.ts +0 -58
- package/src/decorators/map.ts +0 -226
- package/src/entry-point.ts +0 -111
- package/src/express/api.ts +0 -118
- package/src/express/errors/NotAuthorized.ts +0 -6
- package/src/express/errors/NotFound.ts +0 -6
- package/src/express/server.ts +0 -87
- package/src/inject.ts +0 -33
- package/src/models/Item.ts +0 -11
- package/src/server.ts +0 -459
- /package/{lib → dist}/Gui/MenuGui.d.ts +0 -0
- /package/{lib → dist}/Gui/NotificationGui.d.ts +0 -0
- /package/{lib → dist}/Gui/ShopGui.d.ts +0 -0
- /package/{lib → dist}/Gui/index.d.ts +0 -0
- /package/{lib → dist}/logs/index.d.ts +0 -0
- /package/{lib → dist}/logs/item.d.ts +0 -0
- /package/{lib → dist}/logs/log.d.ts +0 -0
- /package/{lib → dist}/logs/skill.d.ts +0 -0
- /package/{lib → dist}/logs/state.d.ts +0 -0
- /package/{lib → dist}/presets/index.d.ts +0 -0
package/src/decorators/map.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { TiledMap } from '@rpgjs/tiled'
|
|
2
|
-
import { componentSchema, RpgPlayer } from '../Player/Player'
|
|
3
|
-
|
|
4
|
-
export interface MapOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Map identifier. Allows to go to the map (for example with player.changeMap())
|
|
7
|
-
*
|
|
8
|
-
* @prop {string} [id]
|
|
9
|
-
* @memberof MapData
|
|
10
|
-
* */
|
|
11
|
-
id?: string,
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* the path to the .tmx file (Tiled Map Editor)
|
|
15
|
-
*
|
|
16
|
-
* Remember to use `require()` function
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { MapData, RpgMap } from '@rpgjs/server'
|
|
20
|
-
*
|
|
21
|
-
* @MapData({
|
|
22
|
-
* id: 'town',
|
|
23
|
-
* file: require('./tmx/town.tmx')
|
|
24
|
-
* })
|
|
25
|
-
* class TownMap extends RpgMap { }
|
|
26
|
-
* ```
|
|
27
|
-
* @prop {string} file
|
|
28
|
-
* @memberof MapData
|
|
29
|
-
* */
|
|
30
|
-
file: string | TiledMap,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The name of the map.
|
|
34
|
-
* @prop {string} [name]
|
|
35
|
-
* @memberof MapData
|
|
36
|
-
* */
|
|
37
|
-
name?: string,
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Map events. This is an array containing `RpgEvent` classes.
|
|
41
|
-
* You can also give an object that will indicate the positions of the event on the map.
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* import { MapData, RpgMap, EventData, RpgEvent } from '@rpgjs/server'
|
|
45
|
-
*
|
|
46
|
-
* @EventData({
|
|
47
|
-
* name: 'Ev-1'
|
|
48
|
-
* })
|
|
49
|
-
* class NpcEvent extends RpgEvent { }
|
|
50
|
-
*
|
|
51
|
-
* @MapData({
|
|
52
|
-
* id: 'medieval',
|
|
53
|
-
* file: require('./tmx/town.tmx'),
|
|
54
|
-
* events: [NpcEvent]
|
|
55
|
-
* })
|
|
56
|
-
* class TownMap extends RpgMap {}
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* If the positions are not defined, the event will be placed on a Tiled Map Editor shape ([/guide/create-event.html#position-the-event-on-the-map](Guide)). Otherwise, it will be placed at `{x:0, y:0 }`
|
|
60
|
-
*
|
|
61
|
-
* You can give positions:
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* events: [{ event: NpcEvent, x: 10, y: 30 }]
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @prop {Class of RpgEvent[] | { event: Class RpgEvent, x: number, y: number }} [events]
|
|
68
|
-
* @memberof MapData
|
|
69
|
-
* */
|
|
70
|
-
events?: { event: any, x: number, y: number }[] | any[],
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The sounds that will be played when the map is open. Sounds must be defined on the client side. Then, put the name of the sound identifier
|
|
74
|
-
*
|
|
75
|
-
* So, it is possible to play several sounds (in loop or not) on the card. You can put a background music (BGM) and a background noise (BGS) for example
|
|
76
|
-
*
|
|
77
|
-
* ```ts
|
|
78
|
-
* sounds: ['my-bgm', 'my-bgs']
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* And client side:
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* import { Sound } from '@rpgjs/client'
|
|
85
|
-
*
|
|
86
|
-
* @Sound({
|
|
87
|
-
* sounds: {
|
|
88
|
-
* 'my-bgm': require('./assets/bgm.ogg'),
|
|
89
|
-
* 'my-bgs': require('./assets/bgs.ogg')
|
|
90
|
-
* },
|
|
91
|
-
* loop: true
|
|
92
|
-
* })
|
|
93
|
-
* export class Sounds {}
|
|
94
|
-
* ```
|
|
95
|
-
*
|
|
96
|
-
* See [https://docs.rpgjs.dev/classes/sound.html#properties](RpgSound Decorator)
|
|
97
|
-
*
|
|
98
|
-
* @prop {Array<string>} [sounds]
|
|
99
|
-
* @memberof MapData
|
|
100
|
-
* */
|
|
101
|
-
sounds?: string[]
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Specify which properties will be synchronized with the client. On the client side, you can retrieve the values synchronized with the valueChanges property on the scene
|
|
105
|
-
*
|
|
106
|
-
* You must create the schema:
|
|
107
|
-
*
|
|
108
|
-
* ```ts
|
|
109
|
-
* import { MapData, RpgMap } from '@rpgjs/server'
|
|
110
|
-
*
|
|
111
|
-
* @MapData({
|
|
112
|
-
* id: 'medieval',
|
|
113
|
-
* file: require('./tmx/town.tmx'),
|
|
114
|
-
* syncSchema: {
|
|
115
|
-
* count: Number
|
|
116
|
-
* }
|
|
117
|
-
* })
|
|
118
|
-
* export class TownMap extends RpgMap {
|
|
119
|
-
* count: number = 0
|
|
120
|
-
*
|
|
121
|
-
* onLoad() {}
|
|
122
|
-
*
|
|
123
|
-
* onJoin() {
|
|
124
|
-
* this.count++
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* onLeave(player) {
|
|
128
|
-
* super.onLeave(player)
|
|
129
|
-
* this.count--
|
|
130
|
-
* }
|
|
131
|
-
* }
|
|
132
|
-
*
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* If you want to change the scheme of players and events, consider overwriting the existing scheme
|
|
136
|
-
*
|
|
137
|
-
* ```ts
|
|
138
|
-
* import { MapData, RpgMap, RpgPlayer } from '@rpgjs/server'
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* declare module '@rpgjs/server' {
|
|
142
|
-
* export interface RpgPlayer {
|
|
143
|
-
* customProp: string
|
|
144
|
-
* }
|
|
145
|
-
* }
|
|
146
|
-
*
|
|
147
|
-
* @MapData({
|
|
148
|
-
* id: 'medieval',
|
|
149
|
-
* file: require('./tmx/town.tmx'),
|
|
150
|
-
* syncSchema: {
|
|
151
|
-
* users: [
|
|
152
|
-
* {
|
|
153
|
-
* customProp: String,
|
|
154
|
-
* ...RpgPlayer.schemas
|
|
155
|
-
* }
|
|
156
|
-
* ]
|
|
157
|
-
* }
|
|
158
|
-
* })
|
|
159
|
-
* export class TownMap extends RpgMap {}
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* The properties are called `users` and `events`. Their scheme is identical and defined in `RpgPlayer.schemas`. To write schematics, refer to the [documentation of the simple-room](https://github.com/RSamaium/simple-room) module
|
|
163
|
-
*
|
|
164
|
-
* @prop {object} [syncSchema]
|
|
165
|
-
* @memberof MapData
|
|
166
|
-
* */
|
|
167
|
-
syncSchema?: any
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Decreases the RAM of the map. In this case, some instructions will be different.
|
|
171
|
-
*
|
|
172
|
-
* `map.getTileByIndex()` will not return all tiles of an index but only the tile of the highest layer
|
|
173
|
-
*
|
|
174
|
-
* > You can also use the `low-memory` property in Tiled maps
|
|
175
|
-
*
|
|
176
|
-
* @prop {boolean} [lowMemory=false]
|
|
177
|
-
* @since 3.1.0
|
|
178
|
-
* @memberof MapData
|
|
179
|
-
* */
|
|
180
|
-
lowMemory?: boolean
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function MapData(options: MapOptions) {
|
|
184
|
-
return (target) => {
|
|
185
|
-
target.file = options.file
|
|
186
|
-
target.id = options.id
|
|
187
|
-
target.type = 'map'
|
|
188
|
-
target.prototype.name = options.name
|
|
189
|
-
target.prototype.file = options.file
|
|
190
|
-
target.prototype.id = options.id
|
|
191
|
-
target.prototype.sounds = options.sounds
|
|
192
|
-
target.prototype.lowMemory = options.lowMemory
|
|
193
|
-
|
|
194
|
-
target.prototype.$schema = {}
|
|
195
|
-
|
|
196
|
-
if (options.syncSchema) {
|
|
197
|
-
target.prototype.$schema = options.syncSchema
|
|
198
|
-
}
|
|
199
|
-
if (!target.prototype.$schema.shapes) {
|
|
200
|
-
target.prototype.$schema.shapes = [
|
|
201
|
-
{
|
|
202
|
-
type: String,
|
|
203
|
-
name: String,
|
|
204
|
-
x: Number,
|
|
205
|
-
y: Number,
|
|
206
|
-
width: Number,
|
|
207
|
-
height: Number,
|
|
208
|
-
properties: {
|
|
209
|
-
collision: Boolean
|
|
210
|
-
},
|
|
211
|
-
polygon: [{ x: Number, y: Number }],
|
|
212
|
-
rotation: Number,
|
|
213
|
-
components: [componentSchema]
|
|
214
|
-
}
|
|
215
|
-
]
|
|
216
|
-
}
|
|
217
|
-
if (!target.prototype.$schema.users) {
|
|
218
|
-
target.prototype.$schema.users = [RpgPlayer.schemas]
|
|
219
|
-
}
|
|
220
|
-
if (!target.prototype.$schema.events) {
|
|
221
|
-
target.prototype.$schema.events = [RpgPlayer.schemas]
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
target.prototype._events = options.events
|
|
225
|
-
}
|
|
226
|
-
}
|
package/src/entry-point.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { RpgCommonGame, HookServer, loadModules, ModuleType, GameSide, RpgPlugin, InjectContext } from '@rpgjs/common'
|
|
2
|
-
import { RpgServerEngine } from './server'
|
|
3
|
-
import { RpgPlayer } from './Player/Player'
|
|
4
|
-
import { RpgMatchMaker } from './MatchMaker'
|
|
5
|
-
import { inject, setInject } from './inject'
|
|
6
|
-
|
|
7
|
-
interface RpgServerEntryPointOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Represents socket io but you can put something else (which is of the same scheme as socket io)
|
|
10
|
-
*
|
|
11
|
-
* @prop {SocketIO or other} io
|
|
12
|
-
* @memberof RpgServerEntryPoint
|
|
13
|
-
* */
|
|
14
|
-
io: any,
|
|
15
|
-
/**
|
|
16
|
-
* It allows you to know where the maps are located. Usually put `__dirname` for the current directory.
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* basePath: __dirname
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @prop {string} basePath
|
|
23
|
-
* @memberof RpgServerEntryPoint
|
|
24
|
-
* */
|
|
25
|
-
basePath: string
|
|
26
|
-
|
|
27
|
-
standalone?: boolean
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* The general configurations of the game.
|
|
31
|
-
*
|
|
32
|
-
* @prop {object} [globalConfig]
|
|
33
|
-
* @memberof RpgServerEntryPoint
|
|
34
|
-
* */
|
|
35
|
-
globalConfig?: any
|
|
36
|
-
|
|
37
|
-
workers?: any
|
|
38
|
-
|
|
39
|
-
envs?: object
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export default async function (modules: ModuleType[], options: RpgServerEntryPointOptions): Promise<RpgServerEngine> {
|
|
43
|
-
const context = new InjectContext()
|
|
44
|
-
setInject(context)
|
|
45
|
-
|
|
46
|
-
inject(RpgCommonGame, [GameSide.Server])
|
|
47
|
-
|
|
48
|
-
if (!options.globalConfig) options.globalConfig = {}
|
|
49
|
-
|
|
50
|
-
const relations = {
|
|
51
|
-
onConnected: HookServer.PlayerConnected,
|
|
52
|
-
onInput: HookServer.PlayerInput,
|
|
53
|
-
onJoinMap: HookServer.PlayerJoinMap,
|
|
54
|
-
onLeaveMap: HookServer.PlayerLeaveMap,
|
|
55
|
-
onLevelUp: HookServer.PlayerLevelUp,
|
|
56
|
-
onDead: HookServer.PlayerDead,
|
|
57
|
-
onDisconnected: HookServer.PlayerDisconnected,
|
|
58
|
-
onInShape: HookServer.PlayerInShape,
|
|
59
|
-
onOutShape: HookServer.PlayerOutShape,
|
|
60
|
-
onMove: HookServer.PlayerMove,
|
|
61
|
-
canChangeMap: HookServer.PlayerCanChangeMap
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const relationsEngine = {
|
|
65
|
-
onStart: HookServer.Start,
|
|
66
|
-
onStep: HookServer.Step,
|
|
67
|
-
auth: HookServer.Auth
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const { playerProps } = await loadModules(modules, {
|
|
71
|
-
side: 'server',
|
|
72
|
-
relations: {
|
|
73
|
-
player: relations,
|
|
74
|
-
engine: relationsEngine,
|
|
75
|
-
scalability: {
|
|
76
|
-
onConnected: HookServer.ScalabilityPlayerConnected,
|
|
77
|
-
doChangeServer: HookServer.ScalabilityChangeServer
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, (mod) => {
|
|
81
|
-
const { scalability } = mod
|
|
82
|
-
if (scalability) {
|
|
83
|
-
const { hooks, stateStore, matchMaker } = scalability
|
|
84
|
-
const matchMakerInstance = new RpgMatchMaker(matchMaker)
|
|
85
|
-
RpgPlugin.on(HookServer.Start, () => {
|
|
86
|
-
return stateStore.connect()
|
|
87
|
-
})
|
|
88
|
-
mod.scalability._hooks = {}
|
|
89
|
-
for (let hookName in hooks) {
|
|
90
|
-
let originalHook = mod.scalability.hooks[hookName]
|
|
91
|
-
mod.scalability._hooks[hookName] = function (player: RpgPlayer) {
|
|
92
|
-
return originalHook(stateStore, matchMakerInstance, player)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return mod
|
|
97
|
-
})
|
|
98
|
-
|
|
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
|
-
])
|
|
110
|
-
return serverEngine
|
|
111
|
-
}
|
package/src/express/api.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express'
|
|
2
|
-
import { RpgServerEngine } from '../server'
|
|
3
|
-
import { Query } from '../Query'
|
|
4
|
-
import { RpgMap } from '../Game/Map'
|
|
5
|
-
import { NotAuthorized } from './errors/NotAuthorized'
|
|
6
|
-
import { NotFound } from './errors/NotFound'
|
|
7
|
-
|
|
8
|
-
type ApiConfig = {
|
|
9
|
-
enabled?: boolean,
|
|
10
|
-
authSecret?: string,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function api(rpgServer: RpgServerEngine): Router {
|
|
14
|
-
const router = new Router()
|
|
15
|
-
|
|
16
|
-
router.use((req, res, next) => {
|
|
17
|
-
try {
|
|
18
|
-
const apiConfig: ApiConfig = rpgServer.globalConfig.api || {}
|
|
19
|
-
const enabled = apiConfig.enabled === undefined ? false : apiConfig.enabled
|
|
20
|
-
const { dev } = req.query
|
|
21
|
-
if (process.env.NODE_ENV === 'development' && dev) {
|
|
22
|
-
return next()
|
|
23
|
-
}
|
|
24
|
-
if (!enabled) {
|
|
25
|
-
throw new NotAuthorized('API disabled')
|
|
26
|
-
}
|
|
27
|
-
const authSecret = apiConfig.authSecret
|
|
28
|
-
if (!authSecret) {
|
|
29
|
-
throw new NotAuthorized('API secret not defined')
|
|
30
|
-
}
|
|
31
|
-
// headers
|
|
32
|
-
const authHeader = req.headers.authorization
|
|
33
|
-
if (!authHeader) {
|
|
34
|
-
throw new NotAuthorized('Authorization header not defined')
|
|
35
|
-
}
|
|
36
|
-
const [type, token] = authHeader.split(' ')
|
|
37
|
-
if (type !== 'Bearer') {
|
|
38
|
-
throw new NotAuthorized('Authorization type not supported')
|
|
39
|
-
}
|
|
40
|
-
if (token !== authSecret) {
|
|
41
|
-
throw new NotAuthorized('Authorization token not valid')
|
|
42
|
-
}
|
|
43
|
-
next()
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
next(err)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
router.get('/players', (req, res) => {
|
|
51
|
-
const players = Query.getPlayers()
|
|
52
|
-
res.json(players)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
router.put('/maps', (req, res, next) => {
|
|
56
|
-
try {
|
|
57
|
-
const { mapId, data, mapFile } = req.body
|
|
58
|
-
const maps = rpgServer.sceneMap.getMaps()
|
|
59
|
-
const findMap = maps.find(map => {
|
|
60
|
-
if (mapId) {
|
|
61
|
-
return map.id === mapId
|
|
62
|
-
}
|
|
63
|
-
else if (mapFile) {
|
|
64
|
-
return map.file === mapFile
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
if (findMap) {
|
|
68
|
-
const map = Query.getRoom<RpgMap>(findMap.id as string)
|
|
69
|
-
map.update(data)
|
|
70
|
-
res.json({ success: true })
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw new NotFound('Map not found')
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
next(err)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
router.put('/tilesets', async (req, res, next) => {
|
|
82
|
-
try {
|
|
83
|
-
const { data, tilesetId } = req.body
|
|
84
|
-
const maps = Query.getRooms<RpgMap>()
|
|
85
|
-
for (let [id, map] of maps) {
|
|
86
|
-
const findTileset = map.tilesets.find(tileset => tileset.name === tilesetId)
|
|
87
|
-
if (findTileset) {
|
|
88
|
-
await map.updateTileset(data)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
res.json({ success: true })
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
next(err)
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
router.put('/worlds', (req, res, next) => {
|
|
99
|
-
try {
|
|
100
|
-
const { worldId, data } = req.body
|
|
101
|
-
const sceneMap = rpgServer.sceneMap
|
|
102
|
-
const world = sceneMap.getWorldMaps(worldId)
|
|
103
|
-
if (world) {
|
|
104
|
-
sceneMap.deleteWorldMaps(worldId)
|
|
105
|
-
sceneMap.createDynamicWorldMaps(data)
|
|
106
|
-
res.json({ success: true })
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
throw new NotFound('World not found')
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
next(err)
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
return router
|
|
118
|
-
}
|
package/src/express/server.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import http from 'http'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import express from 'express'
|
|
4
|
-
import cors from 'cors'
|
|
5
|
-
import { Server } from 'socket.io'
|
|
6
|
-
import entryPoint from '../entry-point'
|
|
7
|
-
import PrettyError from 'pretty-error'
|
|
8
|
-
import { ModuleType } from '@rpgjs/common'
|
|
9
|
-
import { RpgServerEngine } from '../server'
|
|
10
|
-
import { api } from './api'
|
|
11
|
-
import { Query } from '../Query'
|
|
12
|
-
|
|
13
|
-
type ExpressServerOptions = {
|
|
14
|
-
basePath: string,
|
|
15
|
-
globalConfig?: any,
|
|
16
|
-
envs?: object
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function expressServer(modules: ModuleType[], options: ExpressServerOptions): Promise<{
|
|
20
|
-
app: express.Express,
|
|
21
|
-
server: http.Server,
|
|
22
|
-
game: RpgServerEngine
|
|
23
|
-
}> {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
const envs = options.envs || {}
|
|
26
|
-
const { express: expressConfig = {} } = options.globalConfig || {}
|
|
27
|
-
const dirname = options.basePath
|
|
28
|
-
const PORT = process.env.PORT || expressConfig.port || 3000
|
|
29
|
-
const pe = new PrettyError()
|
|
30
|
-
const app = express()
|
|
31
|
-
const server = http.createServer(app)
|
|
32
|
-
const io = new Server(server, {
|
|
33
|
-
maxHttpBufferSize: 1e10,
|
|
34
|
-
cors: {
|
|
35
|
-
origin: "*",
|
|
36
|
-
methods: ["GET", "POST"]
|
|
37
|
-
},
|
|
38
|
-
...(expressConfig.socketIo || {})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
const isBuilt = !!envs.VITE_BUILT
|
|
43
|
-
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
const hasStatic = process.env.STATIC_DIRECTORY_ENABLED
|
|
46
|
-
const staticDirectory = isBuilt ? expressConfig.static ?? '' : 'dist'
|
|
47
|
-
// @ts-ignore
|
|
48
|
-
const staticEnabled = (isBuilt && hasStatic === undefined) || hasStatic === 'true'
|
|
49
|
-
|
|
50
|
-
app.use(express.json(expressConfig.json))
|
|
51
|
-
app.use(cors(expressConfig.cors))
|
|
52
|
-
|
|
53
|
-
if (staticEnabled || expressConfig.static) {
|
|
54
|
-
app.use('/', express.static(path.join(dirname, '..', staticDirectory, 'client')))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let rpgGame: RpgServerEngine
|
|
58
|
-
|
|
59
|
-
async function start() {
|
|
60
|
-
rpgGame = await entryPoint(modules, { io, ...options })
|
|
61
|
-
rpgGame.app = app
|
|
62
|
-
rpgGame.start()
|
|
63
|
-
app.use('/api', api(rpgGame))
|
|
64
|
-
app.use((err: any, req: any, res: any, next: any) => {
|
|
65
|
-
const status = err.status || 500
|
|
66
|
-
res.status(status).json({ error: err.message })
|
|
67
|
-
})
|
|
68
|
-
resolve({
|
|
69
|
-
app,
|
|
70
|
-
server,
|
|
71
|
-
game: rpgGame
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
const serverPort = !isBuilt ? (envs.VITE_SERVER_URL || '').split(':')[1] || PORT : PORT
|
|
77
|
-
server.listen(serverPort, start)
|
|
78
|
-
|
|
79
|
-
process.on('uncaughtException', function (error) {
|
|
80
|
-
console.log(pe.render(error))
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
process.on('unhandledRejection', function (reason: any) {
|
|
84
|
-
console.log(pe.render(reason))
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
}
|
package/src/inject.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { InjectContext } from "@rpgjs/common";
|
|
2
|
-
|
|
3
|
-
let instanceContext: InjectContext | null = null
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Dependency injection function for RPGJS server side.
|
|
7
|
-
*
|
|
8
|
-
* The server-side `inject` function is designed for retrieving instances of server-related classes in the RPGJS framework.
|
|
9
|
-
* This function is crucial for accessing singleton instances of classes like `RpgServerEngine` on the server. It facilitates
|
|
10
|
-
* a clean and efficient approach to handling dependencies within server modules, contributing to a more organized codebase.
|
|
11
|
-
*
|
|
12
|
-
* @template T The class type that you want to retrieve an instance of, specific to server-side modules.
|
|
13
|
-
* @returns {T} Returns the singleton instance of the specified class, ensuring consistent server-side behavior and state management.
|
|
14
|
-
* @since 4.2.0
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* // Example of injecting the RpgServerEngine
|
|
19
|
-
* import { inject, RpgServerEngine } from '@rpgjs/server'
|
|
20
|
-
* const server = inject(RpgServerEngine)
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function inject<T>(service: new (...args: any[]) => T, args: any[] = []): T {
|
|
24
|
-
return instanceContext!.inject(service, args);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function setInject(context: InjectContext) {
|
|
28
|
-
instanceContext = context;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function clearInject() {
|
|
32
|
-
instanceContext = null
|
|
33
|
-
}
|
package/src/models/Item.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ItemOptions } from '@rpgjs/database'
|
|
2
|
-
import { RpgPlayer } from '../Player/Player';
|
|
3
|
-
|
|
4
|
-
export interface ItemModel extends ItemOptions {
|
|
5
|
-
id?: string
|
|
6
|
-
equipped?: boolean
|
|
7
|
-
onUseFailed?: (player: RpgPlayer) => {}
|
|
8
|
-
onUse?: (player: RpgPlayer) => {}
|
|
9
|
-
onAdd?: (player: RpgPlayer) => {}
|
|
10
|
-
onRemove?: (player: RpgPlayer) => {}
|
|
11
|
-
}
|