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, socket: WebSocket,
uuid: string, uuid: string,
name: string name: string
): void { ): boolean {
let succeeded: boolean = false
const gameIndex: number | undefined = const gameIndex: number | undefined =
this.playerNameToGameIndex.get(nameToSpectate) this.playerNameToGameIndex.get(nameToSpectate)
if (gameIndex !== undefined) { if (gameIndex !== undefined) {
this.playerNameToGameIndex.set(name, gameIndex) this.playerNameToGameIndex.set(name, gameIndex)
this.games[gameIndex].addSpectator(socket, uuid, name) this.games[gameIndex].addSpectator(socket, uuid, name)
succeeded = true
} }
return succeeded
} }
async leaveGame (name: string): Promise<void> { 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 let succeeded: boolean = false
const name: string | undefined = this.socketToPlayerName.get(client) const name: string | undefined = this.socketToPlayerName.get(client)
if (name !== undefined) { if (name !== undefined) {
this.games.spectateGame(playerToSpectate.value, client, client.id, name) succeeded = this.games.spectateGame(playerToSpectate.value, client, client.id, name)
succeeded = true
} }
return { event: GAME_EVENTS.SPECTATE, data: succeeded } return { event: GAME_EVENTS.SPECTATE, data: succeeded }
} }

6
front/volume/src/App.svelte

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

2
front/volume/src/FakeLogin.svelte

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

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

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

Loading…
Cancel
Save