Browse Source

* Player names DTO & pipe validation packages

master
vvandenb 2 years ago
parent
commit
f2e61122d5
  1. 88
      back/volume/package-lock.json
  2. 4
      back/volume/package.json
  3. 8
      back/volume/src/pong/dtos/PlayerNamesDto.ts
  4. 15
      back/volume/src/pong/pong.gateway.ts
  5. 1092
      front/volume/package-lock.json

88
back/volume/package-lock.json

@ -9,7 +9,9 @@
"version": "0.0.1",
"license": "UNLICENSED",
"dependencies": {
"@types/ws": "^8.5.3"
"@types/ws": "^8.5.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
@ -2137,6 +2139,11 @@
"@types/superagent": "*"
}
},
"node_modules/@types/validator": {
"version": "13.7.12",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.12.tgz",
"integrity": "sha512-YVtyAPqpefU+Mm/qqnOANW6IkqKpCSrarcyV269C8MA8Ux0dbkEuQwM/4CjL47kVEM2LgBef/ETfkH+c6+moFA=="
},
"node_modules/@types/ws": {
"version": "8.5.3",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
@ -3162,6 +3169,21 @@
"integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==",
"dev": true
},
"node_modules/class-transformer": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
},
"node_modules/class-validator": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.0.tgz",
"integrity": "sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==",
"dependencies": {
"@types/validator": "^13.7.10",
"libphonenumber-js": "^1.10.14",
"validator": "^13.7.0"
}
},
"node_modules/cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@ -4424,20 +4446,6 @@
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"dev": true
},
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@ -5974,6 +5982,11 @@
"node": ">= 0.8.0"
}
},
"node_modules/libphonenumber-js": {
"version": "1.10.20",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.20.tgz",
"integrity": "sha512-kQovlKNdLcVzerbTPmJ+Fx4R+7/pYXmPDIllHjg7IxL4X6MsMG7jaT5opfYrBok0uqkByVif//JUR8e11l/V7w=="
},
"node_modules/lines-and-columns": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@ -8225,6 +8238,14 @@
"node": ">=10.12.0"
}
},
"node_modules/validator": {
"version": "13.9.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz",
"integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
@ -10198,6 +10219,11 @@
"@types/superagent": "*"
}
},
"@types/validator": {
"version": "13.7.12",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.12.tgz",
"integrity": "sha512-YVtyAPqpefU+Mm/qqnOANW6IkqKpCSrarcyV269C8MA8Ux0dbkEuQwM/4CjL47kVEM2LgBef/ETfkH+c6+moFA=="
},
"@types/ws": {
"version": "8.5.3",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
@ -10949,6 +10975,21 @@
"integrity": "sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==",
"dev": true
},
"class-transformer": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw=="
},
"class-validator": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.0.tgz",
"integrity": "sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==",
"requires": {
"@types/validator": "^13.7.10",
"libphonenumber-js": "^1.10.14",
"validator": "^13.7.0"
}
},
"cli-cursor": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@ -11923,13 +11964,6 @@
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"dev": true
},
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"optional": true
},
"function-bind": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
@ -13073,6 +13107,11 @@
"type-check": "~0.4.0"
}
},
"libphonenumber-js": {
"version": "1.10.20",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.20.tgz",
"integrity": "sha512-kQovlKNdLcVzerbTPmJ+Fx4R+7/pYXmPDIllHjg7IxL4X6MsMG7jaT5opfYrBok0uqkByVif//JUR8e11l/V7w=="
},
"lines-and-columns": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@ -14701,6 +14740,11 @@
"convert-source-map": "^1.6.0"
}
},
"validator": {
"version": "13.9.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz",
"integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA=="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

4
back/volume/package.json

@ -70,6 +70,8 @@
"testEnvironment": "node"
},
"dependencies": {
"@types/ws": "^8.5.3"
"@types/ws": "^8.5.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0"
}
}

8
back/volume/src/pong/dtos/PlayerNamesDto.ts

@ -0,0 +1,8 @@
import { ArrayMaxSize, ArrayMinSize, IsString } from 'class-validator';
export class PlayerNamesDto {
@IsString({ each: true })
@ArrayMaxSize(2)
@ArrayMinSize(2)
playerNames: string[];
}

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

@ -11,6 +11,8 @@ import { randomUUID } from 'crypto';
import { Pong } from './pong';
import { formatWebsocketData, Point } from './game/utils';
import { GAME_EVENTS } from './game/constants';
import { PlayerNamesDto } from './dtos/PlayerNamesDto';
import { UsePipes, ValidationPipe } from '@nestjs/common';
interface WebSocketWithId extends WebSocket {
id: string;
@ -63,14 +65,16 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect {
this.pong.movePlayer(client.id, position);
}
@UsePipes(new ValidationPipe({ whitelist: true }))
@SubscribeMessage(GAME_EVENTS.CREATE_GAME)
createGame(
@ConnectedSocket()
client: WebSocketWithId,
@MessageBody('playerNames') playerNames: string[]
@MessageBody() playerNames: PlayerNamesDto
) {
console.log(playerNames);
const allPlayerNames: Array<string> = Array.from(this.socketToPlayerName.values());
if (playerNames && playerNames.length === 2 && allPlayerNames && allPlayerNames.length >= 2) {
if (allPlayerNames && allPlayerNames.length >= 2) {
const player1Socket: WebSocketWithId = Array.from(this.socketToPlayerName.keys()).find(
(key) => this.socketToPlayerName.get(key) === playerNames[0]
);
@ -84,9 +88,14 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect {
(client.id === player1Socket.id || client.id === player2Socket.id) &&
player1Socket.id !== player2Socket.id
) {
this.pong.newGame([player1Socket, player2Socket], [player1Socket.id, player2Socket.id], playerNames);
this.pong.newGame(
[player1Socket, player2Socket],
[player1Socket.id, player2Socket.id],
playerNames.playerNames
);
}
}
return { event: GAME_EVENTS.CREATE_GAME };
}
@SubscribeMessage(GAME_EVENTS.READY)

1092
front/volume/package-lock.json

File diff suppressed because it is too large
Loading…
Cancel
Save