From c66cc421182fae8c4e5a9c46fd903192894f31a3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 28 Jan 2021 17:58:33 +0100 Subject: [PATCH] Updated build config + Drone CI --- .drone.yml | 27 ++++++ .gitignore | 3 +- Dockerfile | 22 ++--- client/src/store/socketPlugin.js | 6 +- docker-compose.yml | 6 +- server/dist/Game.js | 118 ------------------------ server/dist/Game.js.map | 1 - server/dist/app.js | 40 -------- server/dist/app.js.map | 1 - server/dist/models/GameSettings.js | 15 --- server/dist/models/GameSettings.js.map | 1 - server/dist/models/GameWebSocket.js | 3 - server/dist/models/GameWebSocket.js.map | 1 - server/dist/models/Player.js | 75 --------------- server/dist/models/Player.js.map | 1 - server/dist/models/Wall.js | 11 --- server/dist/models/Wall.js.map | 1 - 17 files changed, 46 insertions(+), 286 deletions(-) create mode 100644 .drone.yml delete mode 100644 server/dist/Game.js delete mode 100644 server/dist/Game.js.map delete mode 100644 server/dist/app.js delete mode 100644 server/dist/app.js.map delete mode 100644 server/dist/models/GameSettings.js delete mode 100644 server/dist/models/GameSettings.js.map delete mode 100644 server/dist/models/GameWebSocket.js delete mode 100644 server/dist/models/GameWebSocket.js.map delete mode 100644 server/dist/models/Player.js delete mode 100644 server/dist/models/Player.js.map delete mode 100644 server/dist/models/Wall.js delete mode 100644 server/dist/models/Wall.js.map diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..ef03054 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,27 @@ +kind: pipeline +type: docker +name: default +steps: +- name: build + image: plugins/docker + settings: + username: + from_secret: reg_user + password: + from_secret: reg_password + registry: dockerreg.gltronic.ovh + repo: dockerreg.gltronic.ovh/tronio +- name: deploy + image: appleboy/drone-ssh + settings: + host: + from_secret: deploy_host + username: + from_secret: deploy_user + password: + from_secret: deploy_password + port: 22 + script: + - cd docker/perso + - docker-compose pull tronio + - docker-compose up -d tronio \ No newline at end of file diff --git a/.gitignore b/.gitignore index d8f597d..5f9dad4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ pnpm-debug.log* *.sln *.sw? -tronio.jar \ No newline at end of file +server/dist +client/dist \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5c7a966..7e19d68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,15 @@ -# https://medium.com/bb-tutorials-and-thoughts/packaging-your-vue-js-app-with-nodejs-backend-for-production-83abe213532c - -FROM node:10 AS ui-build +FROM node:latest AS client-build WORKDIR /usr/src/app COPY client/ ./client/ RUN cd client && npm install && npm run build -FROM node:10 AS server-build +FROM node:latest AS server-build +WORKDIR /usr/src/app +COPY server/ ./server/ +RUN cd server && npm install && npm run build + +FROM node:latest AS serve WORKDIR /root/ -COPY --from=ui-build /usr/src/app/client/dist ./server/dist -COPY server/package*.json ./server/ -RUN cd server && npm install -COPY server/src ./server/src - -EXPOSE 8080 - -CMD ["node", "./server/src/server.js"] +COPY --from=server-build /usr/src/app/server/dist ./distServer +COPY --from=client-build /usr/src/app/client/dist ./distClient +CMD ["node", "./distServer/app.js"] diff --git a/client/src/store/socketPlugin.js b/client/src/store/socketPlugin.js index 86315c9..e527a92 100644 --- a/client/src/store/socketPlugin.js +++ b/client/src/store/socketPlugin.js @@ -1,8 +1,8 @@ import { ToastProgrammatic as Toast } from 'buefy' -const server = process.env.SERVER || 'localhost:3000' -const connection = new WebSocket('ws://' + server + '/socket') -// const connection = new WebSocket('wss://tronio.gltronic.ovh/socket') +let connection +if (process.env.SERVER) connection = new WebSocket('wss://' + process.env.SERVER + '/socket') +else connection = new WebSocket('ws://localhost:3000/socket') export default function createSocketPlugin () { return store => { diff --git a/docker-compose.yml b/docker-compose.yml index 951e91c..ca70d28 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,13 @@ -version: '3' +--- +version: "2" services: tronio: - image: gltron/tronio + image: dockerreg.gltronic.ovh/tronio container_name: tronio ports: - 8006:8080 environment: - NODE_ENV=production - PORT=8080 + - SERVER=tronio.gltronic.ovh restart: unless-stopped diff --git a/server/dist/Game.js b/server/dist/Game.js deleted file mode 100644 index 5fd5b07..0000000 --- a/server/dist/Game.js +++ /dev/null @@ -1,118 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Game = void 0; -const uuid_1 = require("uuid"); -const Player_1 = require("./models/Player"); -const GameSettings_1 = require("./models/GameSettings"); -class Game { - constructor() { - this.gameSettings = new GameSettings_1.GameSettings(); - this.players = new Map(); - this.sockets = new Map(); - this.computeUpdates = false; - this.updateInterval = setInterval(() => this.step(), 10000000); - this.lastUpdateTime = Date.now(); - this.doUpdate = true; - clearInterval(this.updateInterval); - } - login(connection, name) { - console.log('[GAME] Player ' + name + ' connected | ' + this.players.size); - const id = uuid_1.v4(); - connection.id = id; - connection.name = name; - this.sockets.set(id, connection); - this.players.set(id, new Player_1.Player(id, name)); - connection.send(JSON.stringify({ - type: 'login', - player: this.players.get(id) - })); - connection.send(JSON.stringify({ - type: 'gameSettings', - gameSettings: this.gameSettings - })); - if (!this.computeUpdates) { - console.log('[GAME] Starting updates'); - this.updateInterval = setInterval(() => this.step(), 1000 / 60); - this.computeUpdates = true; - } - } - logout(connection) { - console.log('[GAME] Player ' + connection.name + ' disconnected | ' + this.players.size); - this.sockets.delete(connection.id); - this.players.delete(connection.id); - if (this.players.size === 0) { - console.log('[GAME] Stoping updates'); - clearInterval(this.updateInterval); - this.computeUpdates = false; - } - } - respawn(connection) { - console.log('[GAME] Player ' + connection.name + ' respawned'); - this.players.get(connection.id)?.reset(); - connection.send(JSON.stringify({ - type: 'gamePlayerSpawn', - player: this.players.get(connection.id) - })); - } - update(connection, player) { - const playerToUpdate = this.players.get(connection.id); - if (playerToUpdate) - playerToUpdate.angle = player.angle; - } - kill(player) { - console.log('[GAME] Player ' + player.name + ' died'); - player.kill(); - this.sockets.get(player.id)?.send(JSON.stringify({ - type: 'gamePlayerDead', - player: player - })); - } - step() { - const currentTime = Date.now(); - const durationSinceLastUpdate = (currentTime - this.lastUpdateTime) / 1000; - const tickToSimulate = (durationSinceLastUpdate * 60) / 1000; - this.lastUpdateTime = currentTime; - // console.log('UPDATE ' + currentTime + ' doUpdate ' + doUpdate) - this.players.forEach((player, id) => { - if (player.isOutOfBorders()) - this.kill(player); - this.players.forEach((player2, id2) => { - if (player.state === 'DEAD') - return; - for (let i = 0; i < player2.walls.length - 2; i++) { - // Prevent self destroy on last wall - if (player === player2 && i >= player2.walls.length - 1) - break; - const wallA = player2.walls[i]; - const wallB = player2.walls[i + 1]; - if (player.isCloseToWall(wallA, wallB)) { - if (player.isCrossingLine(wallA, wallB)) { - if (player !== player2) - player2.score += 300; - this.kill(player); - return; - } - } - } - }); - }); - this.players.forEach((player, id) => { - player.step(tickToSimulate); - }); - if (this.doUpdate) - this.broadcastUpdate(); - this.doUpdate = !this.doUpdate; - } - broadcastUpdate() { - const update = { - type: 'gameUpdate', - players: [...this.players.values()], - time: this.lastUpdateTime - }; - this.sockets.forEach((connection, id) => { - connection.send(JSON.stringify(update)); - }); - } -} -exports.Game = Game; -//# sourceMappingURL=Game.js.map \ No newline at end of file diff --git a/server/dist/Game.js.map b/server/dist/Game.js.map deleted file mode 100644 index efbac4f..0000000 --- a/server/dist/Game.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Game.js","sourceRoot":"","sources":["../src/Game.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAEpC,4CAAyC;AACzC,wDAAqD;AAGrD,MAAa,IAAI;IAUf;QATQ,iBAAY,GAAG,IAAI,2BAAY,EAAE,CAAC;QAClC,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QACpC,YAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;QAEvC,mBAAc,GAAG,KAAK,CAAC;QACvB,mBAAc,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC1D,mBAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;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AE,KAAK,CAAC,EAAE;4BACvC,IAAI,MAAM,KAAK,OAAO;gCAAE,OAAO,CAAC,KAAK,IAAI,GAAG,CAAA;4BAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;4BAClB,OAAM;yBACP;qBACF;iBACF;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE;YAClC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,eAAe,EAAE,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEO,eAAe;QACrB,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,CAAE,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAE;YACrC,IAAI,EAAE,IAAI,CAAC,cAAc;SAC1B,CAAA;QAED,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE;YACtC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9HD,oBA8HC"} \ No newline at end of file diff --git a/server/dist/app.js b/server/dist/app.js deleted file mode 100644 index 7b7fce4..0000000 --- a/server/dist/app.js +++ /dev/null @@ -1,40 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const express_1 = __importDefault(require("express")); -const Game_1 = require("./Game"); -const ws_1 = require("ws"); -const app = express_1.default(); -const WebSocketServer = ws_1.Server; -const port = process.env.PORT || 3000; -app.use(express_1.default.static('../distClient')); -const server = app.listen(port, () => { - console.log(`Tron.io running on port ${port}`); -}); -const wss = new WebSocketServer({ server }); -const game = new Game_1.Game(); -wss.on('connection', function (connection) { - connection.on('close', () => game.logout(connection)); - connection.on('message', (message) => { - try { - const data = JSON.parse(message); - switch (data.type) { - case 'login': - game.login(connection, data.name); - break; - case 'respawn': - game.respawn(connection); - break; - case 'update': - game.update(connection, data.player); - break; - } - } - catch (e) { - return; - } - }); -}); -//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/server/dist/app.js.map b/server/dist/app.js.map deleted file mode 100644 index edef102..0000000 --- a/server/dist/app.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,iCAA8B;AAC9B,2BAAuC;AAGvC,MAAM,GAAG,GAAG,iBAAO,EAAE,CAAC;AACtB,MAAM,eAAe,GAAG,WAAM,CAAC;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;AAEtC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;AAEzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACnC,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC;AAEH,MAAM,GAAG,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAE5C,MAAM,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;AAExB,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,UAAU,UAAqB;IAClD,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,UAA2B,CAAC,CAAC,CAAC;IAEvE,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,CAAE,OAAO,EAAG,EAAE;QACrC,IAAI;YACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAiB,CAAC,CAAC;YAC3C,QAAQ,IAAI,CAAC,IAAI,EAAE;gBACjB,KAAK,OAAO;oBAAE,IAAI,CAAC,KAAK,CAAC,UAA2B,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;oBAAC,MAAM;gBACxE,KAAK,SAAS;oBAAE,IAAI,CAAC,OAAO,CAAC,UAA2B,CAAC,CAAC;oBAAC,MAAM;gBACjE,KAAK,QAAQ;oBAAE,IAAI,CAAC,MAAM,CAAC,UAA2B,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;oBAAC,MAAM;aAC7E;SACF;QAAC,OAAO,CAAC,EAAE;YACV,OAAM;SACP;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/server/dist/models/GameSettings.js b/server/dist/models/GameSettings.js deleted file mode 100644 index 68ee509..0000000 --- a/server/dist/models/GameSettings.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.GameSettings = void 0; -class GameSettings { - constructor() { - this.playerSize = 10; - this.playerSpeed = 5; - this.playerTurnSpeed = 10; - this.wallSize = 8; - this.wallUpdate = 3; - this.arenaSize = 1000; - } -} -exports.GameSettings = GameSettings; -//# sourceMappingURL=GameSettings.js.map \ No newline at end of file diff --git a/server/dist/models/GameSettings.js.map b/server/dist/models/GameSettings.js.map deleted file mode 100644 index 62f848e..0000000 --- a/server/dist/models/GameSettings.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"GameSettings.js","sourceRoot":"","sources":["../../src/models/GameSettings.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAQvB;QAPA,eAAU,GAAG,EAAE,CAAC;QAChB,gBAAW,GAAG,CAAC,CAAC;QAChB,oBAAe,GAAG,EAAE,CAAC;QACrB,aAAQ,GAAG,CAAC,CAAC;QACb,eAAU,GAAG,CAAC,CAAC;QACf,cAAS,GAAG,IAAI,CAAC;IAED,CAAC;CAClB;AATD,oCASC"} \ No newline at end of file diff --git a/server/dist/models/GameWebSocket.js b/server/dist/models/GameWebSocket.js deleted file mode 100644 index 4074f6f..0000000 --- a/server/dist/models/GameWebSocket.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=GameWebSocket.js.map \ No newline at end of file diff --git a/server/dist/models/GameWebSocket.js.map b/server/dist/models/GameWebSocket.js.map deleted file mode 100644 index 3666a99..0000000 --- a/server/dist/models/GameWebSocket.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"GameWebSocket.js","sourceRoot":"","sources":["../../src/models/GameWebSocket.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/server/dist/models/Player.js b/server/dist/models/Player.js deleted file mode 100644 index 7ef2fe4..0000000 --- a/server/dist/models/Player.js +++ /dev/null @@ -1,75 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Player = void 0; -const Wall_1 = require("./Wall"); -const GameSettings_1 = require("./GameSettings"); -class Player { - constructor(id, name) { - this.id = id; - this.name = name; - this.gameSettings = new GameSettings_1.GameSettings(); - this.bestScore = 0; - this.angle = 0; - this.score = 0; - this.color = '#' + (0x1000000 + (Math.random()) * 0xffffff).toString(16).substr(1, 6); - this.x = this.gameSettings.arenaSize * (0.25 + Math.random() * 0.5); - this.y = this.gameSettings.arenaSize * (0.25 + Math.random() * 0.5); - this.walls = []; - this.lastWall = 0; - this.state = 'ALIVE'; - this.reset(); - } - reset() { - this.score = 0; - this.color = '#' + (0x1000000 + (Math.random()) * 0xffffff).toString(16).substr(1, 6); - this.x = this.gameSettings.arenaSize * (0.25 + Math.random() * 0.5); - this.y = this.gameSettings.arenaSize * (0.25 + Math.random() * 0.5); - this.walls = []; - this.lastWall = 0; - this.state = 'ALIVE'; - } - kill() { - this.state = 'DEAD'; - if (this.bestScore < this.score) - this.bestScore = this.score; - } - isOutOfBorders() { - return this.x - this.gameSettings.playerSize < 0 || - this.x + this.gameSettings.playerSize > this.gameSettings.arenaSize || - this.y - this.gameSettings.playerSize < 0 || - this.y + this.gameSettings.playerSize > this.gameSettings.arenaSize; - } - isCloseToWall(wallA, wallB) { - const xar = Math.min(wallA.x, wallB.x) - this.gameSettings.playerSize; - const yar = Math.min(wallA.y, wallB.y) - this.gameSettings.playerSize; - const xbr = Math.min(wallA.x, wallB.x) + this.gameSettings.playerSize; - const ybr = Math.min(wallA.y, wallB.y) + this.gameSettings.playerSize; - return ((this.x >= xar && this.x <= xbr) && (this.y >= yar && this.y <= ybr)); - } - isCrossingLine(wallA, wallB) { - const xa = wallA.x; - const ya = wallA.y; - const xb = wallB.x; - const yb = wallB.y; - const xc = this.x; - const yc = this.y; - const radius = this.gameSettings.playerSize; - return Math.abs((yb - ya) * xc - (xb - xa) * yc + xb * ya - yb * xa) / Math.sqrt(Math.pow(xb - xa, 2) + Math.pow(yb - ya, 2)) < radius; - } - step(tickToSimulate) { - if (this.state === 'DEAD') - return; - for (let i = 0; i < tickToSimulate; i++) { - this.lastWall++; - if (this.lastWall > this.gameSettings.wallUpdate) { - this.walls.push(new Wall_1.Wall(this.x, this.y)); - this.score++; - this.lastWall = 0; - } - this.x = this.x + this.gameSettings.playerSpeed * Math.cos(this.angle); - this.y = this.y + this.gameSettings.playerSpeed * Math.sin(this.angle); - } - } -} -exports.Player = Player; -//# sourceMappingURL=Player.js.map \ No newline at end of file diff --git a/server/dist/models/Player.js.map b/server/dist/models/Player.js.map deleted file mode 100644 index b89e353..0000000 --- a/server/dist/models/Player.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Player.js","sourceRoot":"","sources":["../../src/models/Player.ts"],"names":[],"mappings":";;;AAAA,iCAA8B;AAC9B,iDAA8C;AAE9C,MAAa,MAAM;IAajB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AE;YACvC,IAAI,CAAC,QAAQ,EAAE,CAAA;YAEf,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE;gBAChD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,WAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBACzC,IAAI,CAAC,KAAK,EAAE,CAAA;gBACZ,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;aAClB;YAED,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACtE,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SACvE;IACH,CAAC;CACF;AA5ED,wBA4EC"} \ No newline at end of file diff --git a/server/dist/models/Wall.js b/server/dist/models/Wall.js deleted file mode 100644 index 0cb4855..0000000 --- a/server/dist/models/Wall.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Wall = void 0; -class Wall { - constructor(x, y) { - this.x = x; - this.y = y; - } -} -exports.Wall = Wall; -//# sourceMappingURL=Wall.js.map \ No newline at end of file diff --git a/server/dist/models/Wall.js.map b/server/dist/models/Wall.js.map deleted file mode 100644 index f0ca069..0000000 --- a/server/dist/models/Wall.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Wall.js","sourceRoot":"","sources":["../../src/models/Wall.ts"],"names":[],"mappings":";;;AAAA,MAAa,IAAI;IACf,YAAoB,CAAS,EAAS,CAAS;QAA3B,MAAC,GAAD,CAAC,CAAQ;QAAS,MAAC,GAAD,CAAC,CAAQ;IAAI,CAAC;CACrD;AAFD,oBAEC"} \ No newline at end of file