Skip to content

Commit

Permalink
Merge pull request #175 from TeaSpeak/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
WolverinDEV committed Feb 26, 2021
2 parents f4dfd86 + d8ecb01 commit ddf099e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 227 deletions.
10 changes: 9 additions & 1 deletion shared/js/clientservice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import * as loader from "tc-loader";
import {Stage} from "tc-loader";
import {config} from "tc-shared/i18n/localize";
import {getBackend} from "tc-shared/backend";
import {ClientServiceConfig, ClientServiceInvite, ClientServices, ClientSessionType, LocalAgent} from "tc-services";
import {
ClientServiceConfig,
ClientServiceInvite,
ClientServices,
ClientSessionType,
initializeClientServices,
LocalAgent
} from "tc-services";

import translation_config = config.translation_config;

Expand All @@ -12,6 +19,7 @@ export let clientServiceInvite: ClientServiceInvite;
loader.register_task(Stage.JAVASCRIPT_INITIALIZING, {
priority: 30,
function: async () => {
initializeClientServices();
clientServices = new ClientServices(new class implements ClientServiceConfig {
getServiceHost(): string {
//return "localhost:1244";
Expand Down
2 changes: 2 additions & 0 deletions shared/js/connection/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export enum ErrorCode {
SERVER_CONNECT_BANNED = 0xD01,
BAN_FLOODING = 0xD03,
TOKEN_INVALID_ID = 0xF00,
TOKEN_EXPIRED = 0xf10,
TOKEN_USE_LIMIT_EXCEEDED = 0xf11,
WEB_HANDSHAKE_INVALID = 0x1000,
WEB_HANDSHAKE_UNSUPPORTED = 0x1001,
WEB_HANDSHAKE_IDENTITY_UNSUPPORTED = 0x1002,
Expand Down
36 changes: 30 additions & 6 deletions shared/js/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import "./clientservice";
import "./text/bbcode/InviteController";
import {clientServiceInvite} from "tc-shared/clientservice";
import {ActionResult} from "tc-services";
import {CommandResult} from "tc-shared/connection/ServerConnectionDeclaration";
import {ErrorCode} from "tc-shared/connection/ErrorCode";

assertMainApplication();

Expand Down Expand Up @@ -218,6 +220,8 @@ async function doHandleConnectRequest(serverAddress: string, serverUniqueId: str
const channel = parameters.getValue(AppParameters.KEY_CONNECT_CHANNEL, undefined);
const channelPassword = parameters.getValue(AppParameters.KEY_CONNECT_CHANNEL_PASSWORD, undefined);

const connectToken = parameters.getValue(AppParameters.KEY_CONNECT_TOKEN, undefined);

if(!targetServerConnection) {
targetServerConnection = server_connections.getActiveConnectionHandler();
if(targetServerConnection.connected) {
Expand All @@ -229,12 +233,29 @@ async function doHandleConnectRequest(serverAddress: string, serverUniqueId: str
if(targetServerConnection.getCurrentServerUniqueId() === serverUniqueId) {
/* Just join the new channel and may use the token (before) */

/* TODO: Use the token! */
let containsToken = false;
if(connectToken) {
try {
await targetServerConnection.serverConnection.send_command("tokenuse", { token: connectToken }, { process_result: false });
} catch (error) {
if(error instanceof CommandResult) {
if(error.id === ErrorCode.TOKEN_INVALID_ID) {
targetServerConnection.log.log("error.custom", { message: tr("Try to use invite key token but the token is invalid.")});
} else if(error.id == ErrorCode.TOKEN_EXPIRED) {
targetServerConnection.log.log("error.custom", { message: tr("Try to use invite key token but the token is expired.")});
} else if(error.id === ErrorCode.TOKEN_USE_LIMIT_EXCEEDED) {
targetServerConnection.log.log("error.custom", { message: tr("Try to use invite key token but the token has been used too many times.")});
} else {
targetServerConnection.log.log("error.custom", { message: tra("Try to use invite key token but an error occurred: {}", error.formattedMessage())});
}
} else {
logError(LogCategory.GENERAL, tr("Failed to use token: {}"), error);
}
}
}

if(!channel) {
/* No need to join any channel */
if(!containsToken) {
if(!connectToken) {
createInfoModal(tr("Already connected"), tr("You're already connected to the target server.")).open();
} else {
/* Don't show a message since a token has been used */
Expand Down Expand Up @@ -263,7 +284,8 @@ async function doHandleConnectRequest(serverAddress: string, serverUniqueId: str
}

targetChannel.setCachedHashedPassword(channelPassword);
if(await targetChannel.joinChannel()) {
/* Force join the channel. Either we have the password, can ignore the password or we don't want to join. */
if(await targetChannel.joinChannel(true)) {
return { status: "success" };
} else {
/* TODO: More detail? */
Expand All @@ -277,7 +299,7 @@ async function doHandleConnectRequest(serverAddress: string, serverUniqueId: str
nicknameSpecified: false,

profile: profile,
token: undefined,
token: connectToken,

serverPassword: serverPassword,
serverPasswordHashed: passwordsHashed,
Expand Down Expand Up @@ -467,7 +489,9 @@ const task_connect_handler: loader.Task = {
preventWelcomeUI = true;
loader.register_task(loader.Stage.LOADED, {
priority: 0,
function: async () => handleConnectRequest(address, undefined, AppParameters.Instance),
function: async () => {
handleConnectRequest(address, undefined, AppParameters.Instance).then(undefined);
},
name: tr("default url connect")
});
loader.register_task(loader.Stage.LOADED, task_teaweb_starter);
Expand Down
1 change: 0 additions & 1 deletion shared/js/text/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as log from "../log";
import {LogCategory, logDebug, logTrace, logWarn} from "../log";
import {
CodeToken,
Expand Down
8 changes: 7 additions & 1 deletion shared/js/tree/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,9 @@ export class ChannelEntry extends ChannelTreeEntry<ChannelEvents> {

}

let passwordPrompted = false;
if(this.properties.channel_flag_password === true && !this.cachedPasswordHash && !ignorePasswordFlag) {
passwordPrompted = true;
const password = await this.requestChannelPassword(PermissionType.B_CHANNEL_JOIN_IGNORE_PASSWORD);
if(typeof password === "undefined") {
/* aborted */
Expand All @@ -717,8 +719,12 @@ export class ChannelEntry extends ChannelTreeEntry<ChannelEvents> {
return true;
} catch (error) {
if(error instanceof CommandResult) {
if(error.id == ErrorCode.CHANNEL_INVALID_PASSWORD) { //Invalid password
if(error.id == ErrorCode.CHANNEL_INVALID_PASSWORD) {
this.invalidateCachedPassword();
if(!passwordPrompted) {
/* It seems like our cached password isn't valid any more */
return await this.joinChannel(false);
}
}
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions shared/js/tree/ChannelTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ export class ChannelTree {
spawnCreateChannel(parent?: ChannelEntry) {
spawnChannelEditNew(this.client, undefined, parent, (properties, permissions) => {
properties["cpid"] = parent ? parent.channelId : 0;

logDebug(LogCategory.CHANNEL, tr("Creating a new channel.\nProperties: %o\nPermissions: %o"), properties);
this.client.serverConnection.send_command("channelcreate", properties).then(() => {
let channel = this.find_channel_by_name(properties.channel_name, parent, true);
Expand All @@ -910,6 +911,7 @@ export class ChannelTree {
return;
}

channel.setCachedHashedPassword(properties.channel_password);
if(permissions && permissions.length > 0) {
let perms = [];
for(let perm of permissions) {
Expand Down
1 change: 0 additions & 1 deletion shared/js/tree/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as log from "../log";
import {LogCategory, logInfo, LogType} from "../log";
import {Sound} from "../sound/Sounds";
import * as bookmarks from "../bookmarks";
import {spawnInviteEditor} from "../ui/modal/ModalInvite";
import {openServerInfo} from "../ui/modal/ModalServerInfo";
import {createServerModal} from "../ui/modal/ModalServerEdit";
import {spawnIconSelect} from "../ui/modal/ModalIconSelect";
Expand Down
217 changes: 0 additions & 217 deletions shared/js/ui/modal/ModalInvite.ts

This file was deleted.

0 comments on commit ddf099e

Please sign in to comment.