diff --git a/node/source/classes/controller/GameController.ts b/node/source/classes/controller/GameController.ts index 5248db6..6269221 100644 --- a/node/source/classes/controller/GameController.ts +++ b/node/source/classes/controller/GameController.ts @@ -116,7 +116,6 @@ export class GameController { let gameKeyInterpretation = message.getMessageGameKey(); if (gameKeyInterpretation !== false) { this.getUserStorage().getUser(user.getUserId()).then((storageUser) => { - console.log(storageUser); if (storageUser === undefined) { this.getUserStorage().createUser(parseInt(user.getUserId()), FREE_GAME_INPUT_MOVES); this.chatHandlerForGameInteraction(message, user); @@ -127,16 +126,26 @@ export class GameController { if(hasBalance) { // Subtract the credit from the user when the user is not a developer if(!this.getDeveloperUserIds().includes(parseInt(user.getUserId()))) { - this.getUserStorage().updateUserCredits(user.getUserId(), storageUser.credits - 1); + this.getUserStorage().updateUserCredits(user.getUserId(), storageUser.credits - 1).then(() => { + // Send the button tap to the mGBA API + this.mgbaHttpClient + .buttonTapCreate({ + key: gameKeyInterpretation.toString(), + }) + .then(() => { + Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "ChatInteraction"); + }); + }); + } else { + // Send the button tap to the mGBA API + this.mgbaHttpClient + .buttonTapCreate({ + key: gameKeyInterpretation.toString(), + }) + .then(() => { + Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "ChatInteraction"); + }); } - // Send the button tap to the mGBA API - this.mgbaHttpClient - .buttonTapCreate({ - key: gameKeyInterpretation.toString(), - }) - .then(() => { - Logger.logMessage(`Button tap for ${gameKeyInterpretation} created by ${user.getDisplayName()}`, "GameInput"); - }); } }); } @@ -159,6 +168,7 @@ export class GameController { private giftHandler(data: any): void { let giftObject = this.availableGifts.get(data.giftId); if(giftObject) { + Logger.logMessage(`Gift received: ${giftObject.getName()} from ${data.userId} with value ${giftObject.getCostDiamonds()}`, "ChatInteraction", LogLevel.INFO); let giftValue = giftObject.getCostDiamonds(); this.getUserStorage().getUser(data.userId).then((storageUser) => { if(storageUser === undefined) { diff --git a/node/source/classes/modules/database/Storage.ts b/node/source/classes/modules/database/Storage.ts index 1d1ced0..1dedb93 100644 --- a/node/source/classes/modules/database/Storage.ts +++ b/node/source/classes/modules/database/Storage.ts @@ -21,6 +21,19 @@ export class UserStorage { }); } + public async intervalUserCredits(amountOfCredits: number): Promise { + Logger.logMessage(`Increasing credits for all users by ${amountOfCredits}`, "Database", LogLevel.INFO); + return new Promise((resolve, reject) => { + this.database.run('UPDATE users SET credits = credits + ?', [amountOfCredits], (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + /** * Update the credits for a user in the database * @param userId {string} @@ -28,6 +41,7 @@ export class UserStorage { * @returns */ public async updateUserCredits(userId: string, credits: number): Promise { + Logger.logMessage(`Updating credits for user ${userId} to ${credits}`, "Database", LogLevel.INFO); return new Promise((resolve, reject) => { this.database.run('UPDATE users SET credits = ? WHERE id = ?', [credits, userId], (err) => { if (err) { @@ -45,8 +59,9 @@ export class UserStorage { * @returns {Promise} */ public async getUser(userId: string): Promise { + Logger.logMessage(`Getting user ${userId} from the database`, "Database", LogLevel.INFO); return new Promise((resolve, reject) => { - this.database.get('SELECT * FROM users WHERE id = ?', [userId], (err, row: IUser) => { + this.database.get('SELECT * FROM users WHERE id = ?', [parseInt(userId)], (err, row: IUser) => { if (err) { reject(err); } else { diff --git a/node/source/index.ts b/node/source/index.ts index 575db97..fd2e807 100644 --- a/node/source/index.ts +++ b/node/source/index.ts @@ -1,6 +1,3 @@ import { GameController } from "./classes/controller/GameController"; -import { UserStorage } from "./classes/modules/database/Storage"; -new GameController("mr.vadim_"); - -new UserStorage(); \ No newline at end of file +new GameController("Hoodienie"); \ No newline at end of file diff --git a/roms/pokemon_red.gb b/roms/pokemon_red.gb new file mode 100644 index 0000000..c602e6c Binary files /dev/null and b/roms/pokemon_red.gb differ diff --git a/roms/pokemon_red.sav b/roms/pokemon_red.sav new file mode 100644 index 0000000..b040531 Binary files /dev/null and b/roms/pokemon_red.sav differ diff --git a/start.bat b/start.bat new file mode 100644 index 0000000..eac54fc --- /dev/null +++ b/start.bat @@ -0,0 +1,3 @@ +start ./http/server/mGBA-http-server.exe +cd node +pnpm start \ No newline at end of file diff --git a/stream/graphics/gba_pokemon.jpg b/stream/graphics/gba_pokemon.jpg new file mode 100644 index 0000000..ffb7984 Binary files /dev/null and b/stream/graphics/gba_pokemon.jpg differ diff --git a/stream/graphics/gba_pokemon.png b/stream/graphics/gba_pokemon.png new file mode 100644 index 0000000..855dd21 Binary files /dev/null and b/stream/graphics/gba_pokemon.png differ