Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit 4df0a4a

Browse files
authored
Merge pull request #266 from MUD-Game/dev
Final Release
2 parents c4d168d + 66da9ce commit 4df0a4a

File tree

130 files changed

+5468
-19765
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+5468
-19765
lines changed

backend/data/src/databaseAdapter.ts

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function mapToArray(map: any): any[] {
3737
*/
3838
export class DatabaseAdapter {
3939

40+
4041
public database: string;
4142

4243
connection: mongoose.Connection;
@@ -73,6 +74,7 @@ export class DatabaseAdapter {
7374
return this.dungeon.create({
7475
name: dungeonToStore.name,
7576
description: dungeonToStore.description,
77+
password: dungeonToStore.password,
7678
creatorId: dungeonToStore.creatorId,
7779
masterId: dungeonToStore.masterId,
7880
maxPlayers: dungeonToStore.maxPlayers,
@@ -101,6 +103,13 @@ export class DatabaseAdapter {
101103
return this.user.updateOne({ email: email }, { password: password });
102104
}
103105

106+
async checkIfCharacterExists(name: string, dungeonID: string) {
107+
const foundCharacter = await this.character.findOne({ name: name, dungeonID: dungeonID });
108+
if (foundCharacter) {
109+
return true;
110+
}
111+
return false;
112+
}
104113

105114

106115
/**
@@ -116,6 +125,7 @@ export class DatabaseAdapter {
116125
return {
117126
name: foundDungeon.name,
118127
description: foundDungeon.description,
128+
password: foundDungeon.password,
119129
creatorId: foundDungeon.creatorId,
120130
masterId: foundDungeon.masterId,
121131
maxPlayers: foundDungeon.maxPlayers,
@@ -162,7 +172,7 @@ export class DatabaseAdapter {
162172
await this.room.findByIdAndDelete(r)
163173
})
164174
foundDungeon.items.forEach(async (it: any) => {
165-
await this.item.findByIdAndDelete(it.item)
175+
await this.item.findByIdAndDelete(it)
166176
})
167177
foundDungeon.npcs.forEach(async (npc: any) => {
168178
await this.npc.findByIdAndDelete(npc)
@@ -187,7 +197,7 @@ export class DatabaseAdapter {
187197
await this.room.findByIdAndDelete(r)
188198
})
189199
oldDungeon.items.forEach(async (it: any) => {
190-
await this.item.findByIdAndDelete(it.item)
200+
await this.item.findByIdAndDelete(it)
191201
})
192202
oldDungeon.npcs.forEach(async (npc: any) => {
193203
await this.npc.findByIdAndDelete(npc)
@@ -210,10 +220,11 @@ export class DatabaseAdapter {
210220
_id: oldDungeon._id,
211221
name: newDungeon.name,
212222
description: newDungeon.description,
223+
password: newDungeon.password,
213224
creatorId: oldDungeon.creatorId,
214225
masterId: oldDungeon.creatorId,
215226
maxPlayers: newDungeon.maxPlayers,
216-
blacklist: newDungeon.blacklist,
227+
blacklist: oldDungeon.blacklist,
217228
globalActions: newDungeon.globalActions,
218229
characters: oldDungeon.characters,
219230
characterClasses: await this.characterClass.insertMany(newDungeon.characterClasses),
@@ -229,14 +240,17 @@ export class DatabaseAdapter {
229240
/**
230241
* get the needed dungeon information for the supervisor
231242
* @param id the id of the dungeon to get the information from
232-
* @returns the dungeon information (id, name, description, creatorId, masterId, maxPlayers, currentPlayers)
243+
* @returns the dungeon information (id, name, description, creatorId, password, masterId, maxPlayers, currentPlayers)
233244
*/
234245
async getDungeonInfo(id: string) {
235246
return (this.dungeon.findOne({ id: id },
236-
'id name description creatorId masterId maxPlayers currentPlayers'))
247+
'id name description password creatorId masterId maxPlayers currentPlayers'))
237248
}
238249

239250
async getUserId(user: string): Promise<string | undefined> {
251+
if (user === "root") {
252+
return "root";
253+
}
240254
const foundUser = await this.user.findOne({ username: user }, '_id');
241255
if (foundUser) {
242256
return foundUser._id.toString();
@@ -248,11 +262,11 @@ export class DatabaseAdapter {
248262

249263
/**
250264
* get the dungeon information for the supervisor from all existing dungeons
251-
* @returns an array of the dungeon information (id, name, description, creatorId, masterId, maxPlayers, currentPlayers)
265+
* @returns an array of the dungeon information (id, name, description, password, creatorId, masterId, maxPlayers, currentPlayers)
252266
*/
253267
async getAllDungeonInfos() {
254268
return (this.dungeon.find({},
255-
'id name description creatorId masterId maxPlayers currentPlayers'))
269+
'id name description password creatorId masterId maxPlayers currentPlayers'))
256270
}
257271

258272
/**
@@ -272,7 +286,7 @@ export class DatabaseAdapter {
272286
* @returns true if the character could be found inside the dungeon, false if not
273287
*/
274288
async characterExistsInDungeon(characterName: string, dungeonId: string) {
275-
return this.getCharacterFromDungeon(characterName, dungeonId) !== null;
289+
return await this.getCharacterFromDungeon(characterName, dungeonId) !== null;
276290
}
277291

278292
/**
@@ -317,6 +331,26 @@ export class DatabaseAdapter {
317331
}
318332
}
319333

334+
async updateBlacklistInDungeon(updatedBlacklist: string[], dungeonId: string) {
335+
let dungeonToUpdate = await this.dungeon.findOne({ _id: new mongoose.Types.ObjectId(dungeonId) })
336+
if (dungeonToUpdate?.blacklist != undefined) {
337+
dungeonToUpdate.blacklist = updatedBlacklist;
338+
}
339+
dungeonToUpdate?.save();
340+
}
341+
342+
async isBanned(userId: string, dungeonId: string): Promise<boolean> {
343+
console.log(userId);
344+
let dungeon = await this.dungeon.findOne({ _id: new mongoose.Types.ObjectId(dungeonId) }, { blacklist: { $elemMatch: { $eq: userId } } });
345+
console.log(dungeon);
346+
if (dungeon) {
347+
if (dungeon.blacklist.includes(userId)) {
348+
return true;
349+
}
350+
}
351+
return false;
352+
}
353+
320354
/**
321355
* updates a room inside from the rooms collection inside the database
322356
* @param room the updated room (has to have the same custom id as the room that should be updated)
@@ -326,10 +360,10 @@ export class DatabaseAdapter {
326360
let dungeonRoomIds: RoomDataset[] | undefined = (await this.dungeon.findOne({ _id: new mongoose.Types.ObjectId(dungeonId) }, 'rooms'))?.rooms
327361
console.log(dungeonRoomIds)
328362
if (dungeonRoomIds != undefined) {
329-
dungeonRoomIds.forEach(async id => {
363+
await Promise.all(dungeonRoomIds.map(async id => {
330364
let foundRoom = (await this.room.findOne({ _id: id })) as RoomDataset
331365
await this.room.updateOne(foundRoom, rooms.find(room => room.id == foundRoom.id));
332-
});
366+
}));
333367
}
334368
}
335369

backend/data/src/datasets/dungeonDataset.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { RoomDataset } from "./roomDataset";
1111
export interface DungeonDataset {
1212
name: string;
1313
description: string;
14+
password: string;
1415
creatorId: string;
1516
masterId: string;
1617
maxPlayers: number;
@@ -29,6 +30,7 @@ export interface DungeonDataset {
2930
export const dungeonSchema = new Schema<DungeonDataset>({
3031
name: { type: String, maxLength: 50 },
3132
description: { type: String },
33+
password: {type: String },
3234
creatorId: { type: String },
3335
masterId: { type: String },
3436
maxPlayers: { type: Number },

backend/data/src/interfaces/character.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface Character {
2020
isDead(): boolean
2121
getCharakterStats(): CharacterStats
2222
getMaxStats(): CharacterStats
23+
getUserId(): string
2324
}
2425

2526
export class CharacterImpl implements Character {
@@ -91,4 +92,8 @@ export class CharacterImpl implements Character {
9192
getMaxStats(): CharacterStats {
9293
return this.maxStats
9394
}
95+
96+
getUserId(): string {
97+
return this.userId
98+
}
9499
}

backend/data/src/interfaces/dungeon.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export interface Dungeon {
1414
id: string;
1515
name: string;
1616
description: string;
17+
password: string;
1718
creatorId: string;
1819
globalActions: string[];
1920
masterId: string;
21+
isMasterless: boolean;
2022
maxPlayers: number;
21-
currentPlayers: number;
2223
characterSpecies: { [id: string]: CharacterSpecies };
2324
characterClasses: { [id: string]: CharacterClass };
2425
characterGenders: { [id: string]: CharacterGender };
@@ -43,6 +44,7 @@ export interface Dungeon {
4344
getCharacter(characterName: string): Character
4445
getRoom(roomId: string): Room
4546
getRoomByCoordinates(x: number, y: number): Room
47+
getRoomByName(roomName: string): Room
4648
getNorthernRoom(initialRoom: Room): Room
4749
getEasternRoom(initialRoom: Room): Room
4850
getSouthernRoom(initialRoom: Room): Room
@@ -53,18 +55,21 @@ export interface Dungeon {
5355
getItem(itemId: string): Item
5456
getItemByName(itemName: string): Item
5557
getNpc(npcId: string): Npc
58+
setMasterId(masterId: string): void
59+
getIsMasterless(): boolean
60+
setIsMasterless(isMasterless: boolean): void
5661

5762
}
5863

5964
export class DungeonImpl implements Dungeon {
6065
id: string;
6166
name: string;
6267
description: string;
68+
password: string;
6369
creatorId: string;
6470
masterId: string;
6571
maxPlayers: number;
6672
globalActions: string[];
67-
currentPlayers: number;
6873
characterSpecies: { [id: string]: CharacterSpecies };
6974
characterClasses: { [id: string]: CharacterClass };
7075
characterGenders: { [id: string]: CharacterGender };
@@ -74,7 +79,15 @@ export class DungeonImpl implements Dungeon {
7479
actions: { [id: string]: ActionElement };
7580
items: { [id: string]: Item };
7681
npcs: { [id: string]: Npc };
82+
isMasterless: boolean;
7783

84+
setIsMasterless(isMasterless: boolean): void {
85+
this.isMasterless = isMasterless;
86+
}
87+
88+
getIsMasterless(): boolean {
89+
return this.isMasterless;
90+
}
7891
getId(): string {
7992
return this.id;
8093
}
@@ -87,6 +100,10 @@ export class DungeonImpl implements Dungeon {
87100
return this.description;
88101
}
89102

103+
getPassword(): string {
104+
return this.password;
105+
}
106+
90107
getCreatorId(): string {
91108
return this.creatorId;
92109
}
@@ -100,7 +117,7 @@ export class DungeonImpl implements Dungeon {
100117
}
101118

102119
getCurrentPlayers(): number {
103-
return this.currentPlayers;
120+
return Object.keys(this.characters).length;
104121
}
105122

106123
getSpecies(speciesId: string): CharacterSpecies {
@@ -111,6 +128,9 @@ export class DungeonImpl implements Dungeon {
111128
return species;
112129
}
113130
}
131+
setMasterId(masterId: string): void {
132+
this.masterId = masterId;
133+
}
114134

115135
getClass(classId: string): CharacterClass {
116136
let characterClass: CharacterClass = this.characterClasses[classId]
@@ -157,6 +177,15 @@ export class DungeonImpl implements Dungeon {
157177
}
158178
}
159179

180+
getRoomByName(roomName: string): Room {
181+
let room: Room | undefined = Object.values(this.rooms).find(room => room.name === roomName)
182+
if (room === undefined) {
183+
throw new Error("Room does not exist");
184+
} else {
185+
return room;
186+
}
187+
}
188+
160189
getGlobalActions(): string[] {
161190
return this.globalActions;
162191
}
@@ -237,10 +266,10 @@ export class DungeonImpl implements Dungeon {
237266
id: string,
238267
name: string,
239268
description: string,
269+
password: string,
240270
creatorId: string,
241271
masterId: string,
242272
maxPlayers: number,
243-
currentPlayers: number,
244273
species: CharacterSpecies[],
245274
classes: CharacterClass[],
246275
genders: CharacterGender[],
@@ -255,11 +284,11 @@ export class DungeonImpl implements Dungeon {
255284
this.id = id;
256285
this.name = name;
257286
this.description = description;
287+
this.password = password;
258288
this.creatorId = creatorId;
259289
this.masterId = masterId;
260290
this.maxPlayers = maxPlayers;
261291
this.globalActions = globalActions;
262-
this.currentPlayers = currentPlayers;
263292
this.characterSpecies = arrayToMap(species);
264293
this.characterClasses = arrayToMap(classes);
265294
this.characterGenders = arrayToMap(genders);
@@ -269,6 +298,7 @@ export class DungeonImpl implements Dungeon {
269298
this.actions = arrayToMap(actions);
270299
this.items = arrayToMap(items)
271300
this.npcs = arrayToMap(npcs)
301+
this.isMasterless = false;
272302
}
273303
}
274304

backend/game/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
FROM node:16.14.2
2+
ARG HOM_HOST_NAME
3+
ENV HOM_HOST_NAME ${HOM_HOST_NAME}
24
WORKDIR /app
35
COPY package.json ./
46
COPY package-lock.json ./
57
COPY ./ ./
68
RUN rm -r ./test
79
RUN npm i
810
RUN npm run build
9-
CMD [ "npm", "start" ]
11+
CMD [ "npm", "start" , "$HOM_HOST_NAME"]

backend/game/default-config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ supervisorLink:
88
authKey: SuperSecretKey
99

1010
amqpAdapter:
11-
url: mud-ga.me
11+
url: ...
1212
port: 5672
1313
user: guest
1414
password: guest
@@ -19,4 +19,5 @@ mongodb:
1919
host: 127.0.0.1
2020
port: 27017
2121
user: root
22-
password: root
22+
password: root
23+
database: app

0 commit comments

Comments
 (0)