From f217bc5dd06b225269ab6b8247f77650dd42cebd Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 24 Sep 2018 21:14:36 +0200 Subject: [PATCH] Added server passwords --- ChangeLog.md | 3 +++ js/client.ts | 23 ++++++++++++++++++++--- js/connection.ts | 16 +++++++++++++++- js/ui/modal/ModalConnect.ts | 7 ++++++- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c92c87b0..b6c69803 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ # Changelog: +* **24.09.18**: + - Added server passwords within login modal + * **0.0.1-Alpha**: - First public upload of the Web client All TeaSpeak premium & alpha testers have access diff --git a/js/client.ts b/js/client.ts index fa8e0ee4..c4cc837b 100644 --- a/js/client.ts +++ b/js/client.ts @@ -19,6 +19,7 @@ enum DisconnectReason { CLIENT_KICKED, CLIENT_BANNED, SERVER_CLOSED, + SERVER_REQUIRES_PASSWORD, UNKNOWN } @@ -75,7 +76,7 @@ class TSClient { this.controlBar.initialise(); } - startConnection(addr: string, identity: Identity, name?: string) { + startConnection(addr: string, identity: Identity, name?: string, password?: {password: string, hashed: boolean}) { if(this.serverConnection) this.handleDisconnect(DisconnectReason.REQUESTED); @@ -92,7 +93,15 @@ class TSClient { } console.log("Start connection to " + host + ":" + port); this.channelTree.initialiseHead(addr, {host, port}); - this.serverConnection.startConnection({host, port}, new HandshakeHandler(identity, name)); + + if(password && !password.hashed) { + helpers.hashPassword(password.password).then(password => { + this.serverConnection.startConnection({host, port}, new HandshakeHandler(identity, name, password)); + }).catch(error => { + createErrorModal("Error while hasing password", "Faield to hash server password!").open(); + }) + } else + this.serverConnection.startConnection({host, port}, new HandshakeHandler(identity, name, password ? password.password : undefined)); } @@ -158,7 +167,6 @@ class TSClient { console.error("Could not connect to remote host! Exception"); console.error(data); - //TODO test for status 1006 createErrorModal( "Could not connect", "Could not connect to remote host (Connection refused)
" + @@ -188,6 +196,15 @@ class TSClient { "Reason: " + data.reasonmsg ).open(); break; + case DisconnectReason.SERVER_REQUIRES_PASSWORD: + chat.serverChat().appendError("Server requires password"); + createInputModal("Server password", "Enter server password:", password => password.length != 0, password => { + if(!(typeof password === "string")) return; + this.startConnection(this.serverConnection._remote_address.host + ":" + this.serverConnection._remote_address.port, + this.serverConnection._handshakeHandler.identity, + this.serverConnection._handshakeHandler.name, + {password: password as string, hashed: false}); + }).open(); default: console.error("Got uncaught disconnect!"); console.error("Type: " + type + " Data:"); diff --git a/js/connection.ts b/js/connection.ts index 383a28d0..e4d39bfb 100644 --- a/js/connection.ts +++ b/js/connection.ts @@ -273,9 +273,11 @@ class HandshakeHandler { readonly identity: Identity; readonly name?: string; private connection: ServerConnection; + server_password: string; - constructor(identity: Identity, name?: string) { + constructor(identity: Identity, name?: string, password?: string) { this.identity = identity; + this.server_password = password; this.name = name; } @@ -330,7 +332,19 @@ class HandshakeHandler { client_nickname: this.name ? this.name : this.identity.name(), client_platform: navigator.platform, client_version: navigator.userAgent, + + client_server_password: this.server_password //client_browser_engine: navigator.product + }).catch(error => { + this.connection.disconnect(); + if(error instanceof CommandResult) { + if(error.id == 1028) { + this.connection._client.handleDisconnect(DisconnectReason.SERVER_REQUIRES_PASSWORD); + } else { + + this.connection._client.handleDisconnect(DisconnectReason.CLIENT_KICKED, error); + } + } }); } } diff --git a/js/ui/modal/ModalConnect.ts b/js/ui/modal/ModalConnect.ts index 0fd89df6..536759d5 100644 --- a/js/ui/modal/ModalConnect.ts +++ b/js/ui/modal/ModalConnect.ts @@ -143,7 +143,12 @@ namespace Modals { let field_address = tag.parents(".modal-content").find(".connect_address"); let address = field_address.val().toString(); - globalClient.startConnection(address, connectIdentity, tag.parents(".modal-content").find(".connect_nickname").val().toString()); + globalClient.startConnection( + address, + connectIdentity, + tag.parents(".modal-content").find(".connect_nickname").val().toString(), + {password: tag.parents(".modal-content").find(".connect_password").val().toString(), hashed: false} + ); }); tag.append(button); return tag;