Merge branch 'master' into hugo

This commit is contained in:
simplonco
2023-01-15 02:12:50 +01:00
8 changed files with 97 additions and 28 deletions

View File

@@ -200,8 +200,10 @@ export class GameService {
async declineInvitation(user : User, token : string, @Res() res : Response) async declineInvitation(user : User, token : string, @Res() res : Response)
{ {
if (user.status !== STATUS.CONNECTED) /* Luke: le check de user.status n'est pas fonctionnel avec l'implémentation des invitations dans le front.
return res.status(HttpStatus.FORBIDDEN).json({message : "You must not be in game to decline an invitation"}); Ça me semble dispensable, je désactive donc pour le moment plutôt que de refaire l'implémentation front. */
// if (user.status !== STATUS.CONNECTED)
// return res.status(HttpStatus.FORBIDDEN).json({message : "You must not be in game to decline an invitation"});
console.log("On décline l'invitation") console.log("On décline l'invitation")
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame') const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username}) .andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
@@ -236,8 +238,10 @@ export class GameService {
async acceptInvitation(user : User, token : string, @Res() res : Response) async acceptInvitation(user : User, token : string, @Res() res : Response)
{ {
if (user.status !== STATUS.CONNECTED) /* Luke: le check de user.status n'est pas fonctionnel avec l'implémentation des invitations dans le front.
return res.status(HttpStatus.FORBIDDEN).send("") Ça me semble dispensable, je désactive donc pour le moment plutôt que de refaire l'implémentation front. */
// if (user.status !== STATUS.CONNECTED)
// return res.status(HttpStatus.FORBIDDEN).send("")
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame') const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
.andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username}) .andWhere('tokenGame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
.andWhere('tokenGame.token = :token', {token : token}) .andWhere('tokenGame.token = :token', {token : token})

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 69 KiB

View File

@@ -4,11 +4,13 @@
import { fade, fly } from 'svelte/transition'; import { fade, fly } from 'svelte/transition';
import Header from '../../pieces/Header.svelte'; import Header from '../../pieces/Header.svelte';
import { fetchAvatar } from "../../pieces/utils"; import { fetchUser, fetchAllUsers, fetchAvatar } from "../../pieces/utils";
import * as pong from "./client/pong"; import * as pong from "./client/pong";
import { gameState } from "./client/ws"; import { gameState } from "./client/ws";
import { invited_username } from '../../pieces/store_invitation';
//user's stuff //user's stuff
let user; let user;
let allUsers; let allUsers;
@@ -36,11 +38,21 @@
const watchMatchStartIntervalRate = 111; const watchMatchStartIntervalRate = 111;
onMount( async() => { onMount( async() => {
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`) user = await fetchUser();
.then( x => x.json() ); allUsers = await fetchAllUsers();
allUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
.then( x => x.json() ); if (!user) {
showError = true;
errorMessage = "User load failed";
return;
}
options.playerOneUsername = user.username; options.playerOneUsername = user.username;
if ($invited_username) {
options.isSomeoneIsInvited = true;
options.playerTwoUsername = $invited_username;
invited_username.set("");
}
}) })
onDestroy( async() => { onDestroy( async() => {
@@ -298,8 +310,8 @@
{#if options.isSomeoneIsInvited} {#if options.isSomeoneIsInvited}
<select bind:value={options.playerTwoUsername}> <select bind:value={options.playerTwoUsername}>
{#each allUsers as user } {#each allUsers as invitedUser }
<option value={user.username}>{user.username}</option> <option value={invitedUser.username}>{invitedUser.username}</option>
{/each} {/each}
</select> </select>
{/if} {/if}

View File

@@ -6,15 +6,11 @@
import Header from '../../pieces/Header.svelte'; import Header from '../../pieces/Header.svelte';
import MatchListElem from "../../pieces/MatchListElem.svelte"; import MatchListElem from "../../pieces/MatchListElem.svelte";
import type { Match } from "../../pieces/Match"; import type { Match } from "../../pieces/Match";
import { fetchAvatar } from "../../pieces/utils"; import { fetchUser, fetchAllUsers, fetchAvatar } from "../../pieces/utils";
import * as pongSpectator from "./client/pongSpectator"; import * as pongSpectator from "./client/pongSpectator";
import { gameState } from "./client/ws"; import { gameState } from "./client/ws";
//user's stuff
let user;
let allUsers;
let playerOneAvatar; let playerOneAvatar;
let playerTwoAvatar; let playerTwoAvatar;
@@ -30,13 +26,7 @@
const watchGameStateIntervalRate = 142; const watchGameStateIntervalRate = 142;
onMount( async() => { onMount( async() => {
user = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`) matchList = await fetchMatchList();
.then( x => x.json() );
allUsers = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
.then( x => x.json() );
const responseForMatchList = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
const jsonForMatchList = await responseForMatchList.json();
matchList = jsonForMatchList;
}) })
onDestroy( async() => { onDestroy( async() => {
@@ -82,12 +72,25 @@
async function resetPage() { async function resetPage() {
hiddenGame = true; hiddenGame = true;
pongSpectator.destroy(); pongSpectator.destroy();
fetchMatchList(); matchList = await fetchMatchList();
}; };
async function fetchMatchList() { async function fetchMatchList()
matchList = await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`) {
.then( x => x.json() ); return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/game/match/all`)
.then((response) => {
if (!response.ok) {
throw new Error("All matchs not retrieved");
}
return response.json();
})
.then((body) => {
return body;
})
.catch((error) => {
console.log("catch fetchMatchList: ", error);
return [];
});
}; };
</script> </script>

View File

@@ -8,6 +8,15 @@
let mute = "mute"; let mute = "mute";
let block = "block"; let block = "block";
import { push } from "svelte-spa-router";
import { invited_username } from '../store_invitation';
function game_invitation()
{
const usernamePLACEHOLDER = "hulamy";
invited_username.set(usernamePLACEHOLDER);
push("/game");
}
</script> </script>
<div class="grid_box"> <div class="grid_box">
@@ -40,7 +49,7 @@
<Button> <Button>
view profile view profile
</Button> </Button>
<Button> <Button on_click={() => game_invitation()}>
game invitation game invitation
</Button> </Button>
<Button> <Button>

View File

@@ -0,0 +1,4 @@
import { writable } from 'svelte/store';
export const invited_username = writable("");

View File

@@ -13,5 +13,42 @@ export async function fetchAvatar(username: string)
}) })
.catch((error) => { .catch((error) => {
console.log("catch fetchAvatar: ", error); console.log("catch fetchAvatar: ", error);
return `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/img/default.png`;
});
}
export async function fetchUser()
{
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`)
.then((response) => {
if (!response.ok) {
throw new Error("User not retrieved");
}
return response.json();
})
.then((body) => {
return body;
})
.catch((error) => {
console.log("catch fetchUser: ", error);
return null;
});
}
export async function fetchAllUsers()
{
return fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/all`)
.then((response) => {
if (!response.ok) {
throw new Error("All Users not retrieved");
}
return response.json();
})
.then((body) => {
return body;
})
.catch((error) => {
console.log("catch fetchAllUsers: ", error);
return [];
}); });
} }