Added server passwords

This commit is contained in:
WolverinDEV 2018-09-24 21:14:36 +02:00
parent cb6088ec4e
commit f217bc5dd0
4 changed files with 44 additions and 5 deletions

View file

@ -1,5 +1,8 @@
# Changelog: # Changelog:
* **24.09.18**:
- Added server passwords within login modal
* **0.0.1-Alpha**: * **0.0.1-Alpha**:
- First public upload of the Web client - First public upload of the Web client
All TeaSpeak premium & alpha testers have access All TeaSpeak premium & alpha testers have access

View file

@ -19,6 +19,7 @@ enum DisconnectReason {
CLIENT_KICKED, CLIENT_KICKED,
CLIENT_BANNED, CLIENT_BANNED,
SERVER_CLOSED, SERVER_CLOSED,
SERVER_REQUIRES_PASSWORD,
UNKNOWN UNKNOWN
} }
@ -75,7 +76,7 @@ class TSClient {
this.controlBar.initialise(); 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) if(this.serverConnection)
this.handleDisconnect(DisconnectReason.REQUESTED); this.handleDisconnect(DisconnectReason.REQUESTED);
@ -92,7 +93,15 @@ class TSClient {
} }
console.log("Start connection to " + host + ":" + port); console.log("Start connection to " + host + ":" + port);
this.channelTree.initialiseHead(addr, {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("Could not connect to remote host! Exception");
console.error(data); console.error(data);
//TODO test for status 1006
createErrorModal( createErrorModal(
"Could not connect", "Could not connect",
"Could not connect to remote host (Connection refused)<br>" + "Could not connect to remote host (Connection refused)<br>" +
@ -188,6 +196,15 @@ class TSClient {
"Reason: " + data.reasonmsg "Reason: " + data.reasonmsg
).open(); ).open();
break; 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: default:
console.error("Got uncaught disconnect!"); console.error("Got uncaught disconnect!");
console.error("Type: " + type + " Data:"); console.error("Type: " + type + " Data:");

View file

@ -273,9 +273,11 @@ class HandshakeHandler {
readonly identity: Identity; readonly identity: Identity;
readonly name?: string; readonly name?: string;
private connection: ServerConnection; private connection: ServerConnection;
server_password: string;
constructor(identity: Identity, name?: string) { constructor(identity: Identity, name?: string, password?: string) {
this.identity = identity; this.identity = identity;
this.server_password = password;
this.name = name; this.name = name;
} }
@ -330,7 +332,19 @@ class HandshakeHandler {
client_nickname: this.name ? this.name : this.identity.name(), client_nickname: this.name ? this.name : this.identity.name(),
client_platform: navigator.platform, client_platform: navigator.platform,
client_version: navigator.userAgent, client_version: navigator.userAgent,
client_server_password: this.server_password
//client_browser_engine: navigator.product //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);
}
}
}); });
} }
} }

View file

@ -143,7 +143,12 @@ namespace Modals {
let field_address = tag.parents(".modal-content").find(".connect_address"); let field_address = tag.parents(".modal-content").find(".connect_address");
let address = field_address.val().toString(); 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); tag.append(button);
return tag; return tag;