Browse Source

* Update on fake users to impersonate more than one

master
vvandenb 2 years ago
parent
commit
101315dbd2
  1. 5
      back/volume/src/pong/game/Games.ts
  2. 3
      back/volume/src/pong/pong.gateway.ts
  3. 6
      front/volume/src/App.svelte
  4. 2
      front/volume/src/FakeLogin.svelte
  5. 3
      front/volume/src/components/Pong/Pong.svelte

5
back/volume/src/pong/game/Games.ts

@ -111,13 +111,16 @@ export class Games {
socket: WebSocket,
uuid: string,
name: string
): void {
): boolean {
let succeeded: boolean = false
const gameIndex: number | undefined =
this.playerNameToGameIndex.get(nameToSpectate)
if (gameIndex !== undefined) {
this.playerNameToGameIndex.set(name, gameIndex)
this.games[gameIndex].addSpectator(socket, uuid, name)
succeeded = true
}
return succeeded
}
async leaveGame (name: string): Promise<void> {

3
back/volume/src/pong/pong.gateway.ts

@ -190,8 +190,7 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect {
let succeeded: boolean = false
const name: string | undefined = this.socketToPlayerName.get(client)
if (name !== undefined) {
this.games.spectateGame(playerToSpectate.value, client, client.id, name)
succeeded = true
succeeded = this.games.spectateGame(playerToSpectate.value, client, client.id, name)
}
return { event: GAME_EVENTS.SPECTATE, data: succeeded }
}

6
front/volume/src/App.svelte

@ -184,8 +184,8 @@
let fakeUser = false;
function impersonate() {
const user = {
username: "test",
socketKey: "42",
username: usernameFake,
socketKey: ftIdFake,
};
store.set(user);
fakeUser = true;
@ -269,7 +269,7 @@
{/if}
{#if fakemenu}
<FakeLogin username={usernameFake} ftId={ftIdFake} />
<FakeLogin bind:username={usernameFake} bind:ftId={ftIdFake} />
<button on:click={impersonate}>Impersonate</button>
<button on:click={() => (fakemenu = false)}>No impersonate</button>
{:else}

2
front/volume/src/FakeLogin.svelte

@ -15,7 +15,7 @@
body: JSON.stringify({
ftId,
username,
socketKey: "42",
socketKey: ftId,
avatar: "no avatar",
}),
});

3
front/volume/src/components/Pong/Pong.svelte

@ -95,9 +95,6 @@
} else if (event == GAME_EVENTS.SPECTATE) {
if (data) {
gamePlaying = true;
setInterval(() => {
updateGameInfo();
}, 1000);
}
} else if (event == GAME_EVENTS.READY) {
game.youAreReady = true;

Loading…
Cancel
Save