From 09bb6223d0da54ebd1d6363a3beee7322fd85ade Mon Sep 17 00:00:00 2001 From: kostya-main Date: Thu, 26 Sep 2024 22:54:28 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20Grpc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.ts | 2 +- package.json | 6 +-- public.pem | 24 ++++++------ src/main/api/APIManager.ts | 39 +++++++------------ src/main/core/Launcher.ts | 4 +- src/main/game/Starter.ts | 10 ++--- src/main/game/Updater.ts | 2 +- src/main/scenes/ServersList.ts | 6 +-- src/preload/components/ServersListScene.ts | 3 +- .../runtime/components/ServerButton/index.tsx | 2 +- .../runtime/scenes/ServerPanel/index.tsx | 2 +- .../runtime/scenes/ServersList/index.tsx | 4 +- upload-release.ts | 9 +++-- 13 files changed, 53 insertions(+), 60 deletions(-) diff --git a/config.ts b/config.ts index b7443072..8d4e4b61 100644 --- a/config.ts +++ b/config.ts @@ -11,7 +11,7 @@ export const window = { }; export const api = { - ws: 'ws://127.0.0.1:1370/ws', + ws: 'http://127.0.0.1:1371', web: 'http://127.0.0.1:1370', publicKey, }; diff --git a/package.json b/package.json index 26d17a97..51d0e5c0 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@types/semver": "^7.5.8", - "@types/ws": "^8.5.11", "@typescript-eslint/eslint-plugin": "^7.17.0", "@typescript-eslint/parser": "^7.17.0", "cross-env": "^7.0.3", @@ -58,8 +57,8 @@ "yaml": "^2.5.0" }, "dependencies": { - "@aurora-launcher/api": "^0.4.0", - "@aurora-launcher/core": "^0.23.0", + "@aurora-launcher/proto": "^0.1.0", + "@aurora-launcher/core": "^0.24.0", "@freshgum/typedi": "^0.7.2", "@xhayper/discord-rpc": "^1.1.4", "bytenode": "^1.5.6", @@ -67,6 +66,7 @@ "electron-store": "^10.0.0", "electron-updater": "^6.3.1", "minestat-es": "^1.1.7", + "nice-grpc": "^2.1.9", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.25.1", diff --git a/public.pem b/public.pem index 9a74c7dd..b7ce9cda 100644 --- a/public.pem +++ b/public.pem @@ -1,14 +1,14 @@ -----BEGIN PUBLIC KEY----- -MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA419gbQ3vU7GUwpmfwKVS -zN74Im+PlCzQHpxv5DXti1mZzyIxX/v8O3CcOMf9H/wFJY7PTT1AwDUOni7IBOob -W6hd4uqSe9t3gtlbxeIwG7OvyxKuoFbE/MzvhqFXjwHH/ktQ90x7GgFJuIvVZm62 -aLodDL+4uLblsA02WnS3jLa7qMxA/HyKscEUhCell7xkaWBHmhN8mO4OjC/RYxNm -QfpbZXfJQ1QyTnN3ADEv3yVba1n5I3jKXpSNajvvQYxLNmAJ2IcRgbYrIQUywsyB -nzpn0OXBOGtWSFsszzSZC3jPegIGSTytGT+8VAPCsXRX44iIxFTTq7C3bfscAthK -I9O97ZNmITIJjIYWjj8g7j/rmdbm4v/uSGUoIwOphZUVcB5oRRyVQkuGs46ewJUU -fJTQpmI0m0o+0ciCfcwVbD9AF0y9kNoGLnEVsF4EZC9vOMZwSTbKJ9gInyfW38CW -zbISitGvF8jAFln4czsn6XA0dW6D058dPnS3jre0b9bySWSIxNJvGA5rYzoMSCKm -tLpCBzWi6m0Y0wZcPf7CxzPxcMu+rMz2Sv3ipgbpc/3qNde4QQV8/ahPGfQt0Y9t -g0xbZJdE/Fuurys2ENUU6Mn7D0HsopW1PlOmX19RGTOjlUh5sAsoIvF190iJ1AvJ -0sM2T80SWgTVJos2BGzQd6cCAwEAAQ== +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvSAz+5fnRI5T33QskbLn +PKI8N4WO8Go++VrIilP623jspLZh1ewnGtjRQAN2/5Dw0zZ7649zobQxwwq4lWoV +tYPK8i/Oi8JTJKa/Nr0ClJQjKx1vbQa7CyeV/yZY33ng7X6hSwgw2uxBHiosun/v +EJizF57f6z63ACWHEOJ25ANMZ4/IX0ge8Gv3Ij1qPHif4j/5zYuFkIoaxPW8brEO ++grIkMA7vn91R9jW7bifQROKmuo7cgURt6sM5F/2H9cT+QWxjb0Twqb4dkHa7XHn +A53RZNM+EXpwAfNW+Dl91NLyhLdwzldFGLfCw3cVFxJVdyF6MurQMmsRyL30tnly +BKC1ItZ9KrLC1ga5Jv1Q81d3bIr6lwJ0iBiuyKiua0ob6EUy7bl02xaYqAsVx6qL +JBYqy9BNzE5iqomp3hL9lgy2MkvnqEACvGFs+R7vz5KAoPMutieP1fWR1hX2swam +Ye68qRKiOW32nJ6qJiXmlUXMG030rUkZc8Q8Vxlbl3vtJ1EvtIG3NuBYGEa08ck9 +3Q9eTk4/UgFSY4Qefuui8Ee/TUFnoPr9ZygExZLNuTJBJpxv52ER43H1LqdMbZyo +etaZW1ERxAJEiuu7NkSU0ZOZT28FA7uV/t7vnoQLnKW7IxfYq1fMRmbnTH/0ctpG +99LxVYxGtKWSLUU+DCJlFEECAwEAAQ== -----END PUBLIC KEY----- diff --git a/src/main/api/APIManager.ts b/src/main/api/APIManager.ts index bcc9ad93..41684de6 100644 --- a/src/main/api/APIManager.ts +++ b/src/main/api/APIManager.ts @@ -1,46 +1,37 @@ -import { AuroraAPI } from '@aurora-launcher/api'; +import * as proto from "@aurora-launcher/proto"; +import { createChannel, createClient } from 'nice-grpc'; import { api as apiConfig } from '@config'; import { Service } from '@freshgum/typedi'; -import { LogHelper } from '../helpers/LogHelper'; - @Service([]) export class APIManager { - private api = new AuroraAPI(apiConfig.ws || 'ws://localhost:1370', { - onClose: () => setTimeout(() => this.initConnection(), 2000), - }); + private client = createClient( + proto.AuroraLauncherServiceDefinition, + createChannel(apiConfig.ws), + ); async initConnection() { - try { - await this.api.connect(); - this.#onConnectListeners.forEach((listener) => listener()); - } catch (error) { - LogHelper.error(error); - } - } + const channel = createChannel(apiConfig.ws); - #onConnectListeners: (() => void)[] = []; - onConnect(listener: () => void) { - this.#onConnectListeners.push(listener); + this.client = createClient( + proto.AuroraLauncherServiceDefinition, + channel, + ); } public auth(login: string, password: string) { - return this.api.auth(login, password); + return this.client.auth({login, password}); } public getServers() { - return this.api.getServers(); + return this.client.getServers({}); } public getProfile(uuid: string) { - return this.api.getProfile(uuid); + return this.client.getProfile({uuid}); } public getUpdates(dir: string) { - return this.api.getUpdates(dir); - } - - public verify(stage: number, token?: string) { - return this.api.verify(stage, token); + return this.client.getUpdates({dir}); } } diff --git a/src/main/core/Launcher.ts b/src/main/core/Launcher.ts index 55c54e55..3f7cb26d 100644 --- a/src/main/core/Launcher.ts +++ b/src/main/core/Launcher.ts @@ -32,7 +32,7 @@ export class Launcher { async init() { StorageHelper.createMissing(); - await this.apiManager.initConnection(); + //await this.apiManager.initConnection(); this.loginScene.initHandlers(); this.settingsScene.initHandlers(); @@ -40,7 +40,7 @@ export class Launcher { this.serverPanelScene.initHandlers(); this.discordRPC.initHandlers(); - this.verifyService.init(); + //this.verifyService.init(); this.window.createWindow(); LogHelper.info('Launcher started'); this.discordRPC.start(); diff --git a/src/main/game/Starter.ts b/src/main/game/Starter.ts index e1979086..3dbe64b7 100644 --- a/src/main/game/Starter.ts +++ b/src/main/game/Starter.ts @@ -155,13 +155,13 @@ export class Starter { if (settings.autoConnect) { if (gte(clientVersion, '1.20.0')) { - if ('hostname' in server) gameArgs.push('--quickPlayMultiplayer', server.hostname); - else gameArgs.push('--quickPlayMultiplayer', server.ip + ':' + server.port); + if ('hostname' in server.serverInfo) gameArgs.push('--quickPlayMultiplayer', server.serverInfo?.hostname); + else gameArgs.push('--quickPlayMultiplayer', server.serverInfo?.ip + ':' + server.serverInfo?.port.toString()); } else { - if ('hostname' in server) gameArgs.push('--server', server.hostname); + if ('hostname' in server.serverInfo) gameArgs.push('--server', server.serverInfo?.hostname); else { - gameArgs.push('--server', server.ip); - gameArgs.push('--port', server.port.toString()); + gameArgs.push('--server', server.serverInfo?.ip); + gameArgs.push('--port', server.serverInfo?.port.toString()); } } } diff --git a/src/main/game/Updater.ts b/src/main/game/Updater.ts index f9b203bc..aa85c7b2 100644 --- a/src/main/game/Updater.ts +++ b/src/main/game/Updater.ts @@ -113,7 +113,7 @@ export class Updater { async validateGameFiles(clientArgs: Profile): Promise { this.gameWindow.sendToConsole('Load client files'); - const hashes = await this.api.getUpdates(clientArgs.clientDir); + const hashes = (await this.api.getUpdates(clientArgs.clientDir)).hashedFile; if (!hashes) throw new Error('Client not found'); hashes.sort((a, b) => b.size - a.size); diff --git a/src/main/scenes/ServersList.ts b/src/main/scenes/ServersList.ts index fd97ee45..4a6e61b8 100644 --- a/src/main/scenes/ServersList.ts +++ b/src/main/scenes/ServersList.ts @@ -30,11 +30,11 @@ export class ServersListScene implements IHandleable { } async pingServer(server: Server) { - if ('hostname' in server) { + if (server.serverInfo?.hostname) { return fetchServerInfo({ - hostname: `_minecraft._tcp.${server.hostname}`, + hostname: `_minecraft._tcp.${server.serverInfo.hostname}`, }); } - return fetchServerInfo({ address: server.ip, port: server.port }); + return fetchServerInfo({ address: server.serverInfo.ip, port: server.serverInfo.port }); } } diff --git a/src/preload/components/ServersListScene.ts b/src/preload/components/ServersListScene.ts index b57f56dd..485c6071 100644 --- a/src/preload/components/ServersListScene.ts +++ b/src/preload/components/ServersListScene.ts @@ -1,11 +1,12 @@ import { Server } from '@aurora-launcher/core'; +import { ServersResponse } from '@aurora-launcher/proto'; import { ipcRenderer } from 'electron'; import { ServerInfo } from 'minestat-es'; import { EVENTS } from '../../common/channels'; export default class ServersListScene { - static getServers(): Promise { + static getServers(): Promise { return ipcRenderer.invoke(EVENTS.SCENES.SERVERS_LIST.GET_SERVERS); } diff --git a/src/renderer/runtime/components/ServerButton/index.tsx b/src/renderer/runtime/components/ServerButton/index.tsx index 1de15432..3a070c48 100644 --- a/src/renderer/runtime/components/ServerButton/index.tsx +++ b/src/renderer/runtime/components/ServerButton/index.tsx @@ -13,7 +13,7 @@ export function ServerButton({ onClick, server }: ServerButtonProps) { return (