Added server passwords
parent
cb6088ec4e
commit
f217bc5dd0
|
@ -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
|
||||
|
|
23
js/client.ts
23
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)<br>" +
|
||||
|
@ -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:");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue