2018-03-07 19:06:52 +01:00
|
|
|
/// <reference path="../../utils/modal.ts" />
|
2018-10-07 18:21:28 +02:00
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
namespace Modals {
|
2018-05-05 14:58:30 +02:00
|
|
|
export function spawnConnectModal(defaultHost: string = "ts.TeaSpeak.de", def_connect_type?: IdentitifyType) {
|
2018-04-11 17:56:09 +02:00
|
|
|
let connectIdentity: Identity;
|
2018-03-07 19:06:52 +01:00
|
|
|
const connectModal = createModal({
|
|
|
|
header: function() {
|
|
|
|
let header = $.spawn("div");
|
|
|
|
header.text("Create a new connection");
|
|
|
|
return header;
|
|
|
|
},
|
|
|
|
body: function () {
|
2018-09-25 17:39:38 +02:00
|
|
|
let tag = $("#tmpl_connect").renderTag({
|
2018-10-07 18:21:28 +02:00
|
|
|
client: native_client,
|
2018-09-25 17:39:38 +02:00
|
|
|
forum_path: settings.static("forum_path"),
|
|
|
|
forum_valid: !!forumIdentity
|
|
|
|
});
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
let updateFields = function () {
|
2018-04-11 17:56:09 +02:00
|
|
|
if(connectIdentity) tag.find(".connect_nickname").attr("placeholder", connectIdentity.name());
|
|
|
|
else tag.find(".connect_nickname").attr("");
|
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
let button = tag.parents(".modal-content").find(".connect_connect_button");
|
|
|
|
|
|
|
|
let field_address = tag.find(".connect_address");
|
|
|
|
let address = field_address.val().toString();
|
2018-09-25 12:57:47 +02:00
|
|
|
settings.changeGlobal("connect_address", address);
|
2018-03-07 19:06:52 +01:00
|
|
|
let flag_address = !!address.match(Regex.IP_V4) || !!address.match(Regex.DOMAIN);
|
|
|
|
|
|
|
|
let field_nickname = tag.find(".connect_nickname");
|
|
|
|
let nickname = field_nickname.val().toString();
|
2018-09-25 12:57:47 +02:00
|
|
|
settings.changeGlobal("connect_name", nickname);
|
2018-09-21 23:25:03 +02:00
|
|
|
let flag_nickname = (nickname.length == 0 && connectIdentity && connectIdentity.name().length > 0) || nickname.length >= 3 && nickname.length <= 32;
|
2018-03-07 19:06:52 +01:00
|
|
|
|
|
|
|
if(flag_address) {
|
|
|
|
if(field_address.hasClass("invalid_input"))
|
|
|
|
field_address.removeClass("invalid_input");
|
|
|
|
} else {
|
|
|
|
if(!field_address.hasClass("invalid_input"))
|
|
|
|
field_address.addClass("invalid_input");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(flag_nickname) {
|
|
|
|
if(field_nickname.hasClass("invalid_input"))
|
|
|
|
field_nickname.removeClass("invalid_input");
|
|
|
|
} else {
|
|
|
|
if(!field_nickname.hasClass("invalid_input"))
|
|
|
|
field_nickname.addClass("invalid_input");
|
|
|
|
}
|
|
|
|
|
2018-04-11 17:56:09 +02:00
|
|
|
if(!flag_nickname || !flag_address || !connectIdentity) {
|
2018-05-05 14:58:30 +02:00
|
|
|
button.prop("disabled", true);
|
2018-03-07 19:06:52 +01:00
|
|
|
} else {
|
2018-05-05 14:58:30 +02:00
|
|
|
button.prop("disabled", false);
|
2018-03-07 19:06:52 +01:00
|
|
|
}
|
2018-03-24 23:38:01 +01:00
|
|
|
};
|
|
|
|
|
2018-09-25 12:57:47 +02:00
|
|
|
tag.find(".connect_nickname").val(settings.static_global("connect_name", undefined));
|
|
|
|
tag.find(".connect_address").val(settings.static_global("connect_address", defaultHost));
|
2018-12-02 20:58:29 +01:00
|
|
|
tag.find(".connect_address")
|
|
|
|
.on("keyup", () => updateFields())
|
|
|
|
.on('keydown', event => {
|
|
|
|
if(event.keyCode == JQuery.Key.Enter && !event.shiftKey)
|
|
|
|
tag.parents(".modal-content").find(".connect_connect_button").trigger('click');
|
|
|
|
});
|
2018-03-07 19:06:52 +01:00
|
|
|
tag.find(".connect_nickname").on("keyup", () => updateFields());
|
2018-04-11 17:56:09 +02:00
|
|
|
|
|
|
|
tag.find(".identity_select").on('change', function (this: HTMLSelectElement) {
|
2018-05-05 14:58:30 +02:00
|
|
|
settings.changeGlobal("connect_identity_type", IdentitifyType[this.value]);
|
2018-04-11 17:56:09 +02:00
|
|
|
tag.find(".error_message").hide();
|
|
|
|
tag.find(".identity_config:not(" + ".identity_config_" + this.value + ")").hide();
|
|
|
|
tag.find(".identity_config_" + this.value).show().trigger('shown');
|
|
|
|
});
|
2018-05-05 14:58:30 +02:00
|
|
|
tag.find(".identity_select").val(IdentitifyType[def_connect_type ? def_connect_type : settings.global("connect_identity_type", IdentitifyType.TEAFORO)]);
|
2018-04-11 17:56:09 +02:00
|
|
|
setTimeout(() => tag.find(".identity_select").trigger('change'), 0); //For some reason could not be run instantly
|
|
|
|
|
2018-09-21 23:25:03 +02:00
|
|
|
{
|
|
|
|
tag.find(".identity_file").change(function (this: HTMLInputElement) {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function() {
|
2018-09-22 16:52:26 +02:00
|
|
|
connectIdentity = TSIdentityHelper.loadIdentityFromFileContains(reader.result as string);
|
2018-09-21 23:25:03 +02:00
|
|
|
|
|
|
|
console.log(connectIdentity.uid());
|
|
|
|
if(!connectIdentity) tag.find(".error_message").text("Could not read identity! " + TSIdentityHelper.last_error());
|
|
|
|
else {
|
|
|
|
tag.find(".identity_string").val((connectIdentity as TeamSpeakIdentity).exported());
|
|
|
|
settings.changeGlobal("connect_identity_teamspeak_identity", (connectIdentity as TeamSpeakIdentity).exported());
|
|
|
|
}
|
|
|
|
|
|
|
|
(!!connectIdentity ? tag.hide : tag.show).apply(tag.find(".error_message"));
|
|
|
|
updateFields();
|
|
|
|
};
|
|
|
|
reader.onerror = ev => {
|
|
|
|
tag.find(".error_message").text("Could not read identity file!").show();
|
|
|
|
updateFields();
|
|
|
|
};
|
|
|
|
reader.readAsText(this.files[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
tag.find(".identity_string").on('change', function (this: HTMLInputElement) {
|
|
|
|
if(this.value.length == 0){
|
|
|
|
tag.find(".error_message").text("Please select an identity!");
|
|
|
|
connectIdentity = undefined;
|
|
|
|
} else {
|
|
|
|
connectIdentity = TSIdentityHelper.loadIdentity(this.value);
|
|
|
|
if(!connectIdentity) tag.find(".error_message").text("Could not parse identity! " + TSIdentityHelper.last_error());
|
|
|
|
else settings.changeGlobal("connect_identity_teamspeak_identity", this.value);
|
2018-04-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
(!!connectIdentity ? tag.hide : tag.show).apply(tag.find(".error_message"));
|
2018-09-21 23:25:03 +02:00
|
|
|
tag.find(".identity_file").val("");
|
2018-04-11 17:56:09 +02:00
|
|
|
updateFields();
|
2018-09-21 23:25:03 +02:00
|
|
|
});
|
|
|
|
tag.find(".identity_string").val(settings.global("connect_identity_teamspeak_identity", ""));
|
|
|
|
tag.find(".identity_config_" + IdentitifyType[IdentitifyType.TEAMSPEAK]).on('shown', ev => {
|
|
|
|
tag.find(".identity_string").trigger('change');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-10-07 18:21:28 +02:00
|
|
|
const element = tag.find(".identity_config_" + IdentitifyType[IdentitifyType.TEAFORO]);
|
|
|
|
element.on('shown', ev => {
|
|
|
|
console.log("Updating via shown");
|
2018-09-21 23:25:03 +02:00
|
|
|
connectIdentity = forumIdentity;
|
2018-10-07 18:21:28 +02:00
|
|
|
|
|
|
|
if(connectIdentity) {
|
|
|
|
element.find(".connected").show();
|
|
|
|
element.find(".disconnected").hide();
|
|
|
|
} else {
|
|
|
|
element.find(".connected").hide();
|
|
|
|
element.find(".disconnected").show();
|
|
|
|
}
|
2018-04-11 17:56:09 +02:00
|
|
|
updateFields();
|
2018-09-21 23:25:03 +02:00
|
|
|
});
|
2018-10-07 18:21:28 +02:00
|
|
|
|
|
|
|
if(native_client) {
|
|
|
|
tag.find(".native-teaforo-login").on('click', event => {
|
|
|
|
setTimeout(() => {
|
|
|
|
const forum = require("teaforo.js");
|
|
|
|
const call = () => {
|
|
|
|
try {
|
|
|
|
console.log("Trigger update!");
|
|
|
|
element.trigger('shown');
|
|
|
|
} catch ($) { console.log($); }
|
|
|
|
if(connectModal.shown)
|
|
|
|
forum.register_callback(call);
|
|
|
|
};
|
|
|
|
forum.register_callback(call);
|
|
|
|
forum.open();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
}
|
2018-09-21 23:25:03 +02:00
|
|
|
}
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2018-09-21 23:25:03 +02:00
|
|
|
{
|
|
|
|
tag.find(".identity_config_" + IdentitifyType[IdentitifyType.NICKNAME]).on('shown', ev => {
|
|
|
|
connectIdentity = new NameIdentity(tag.find(".connect_nickname").val() as string);
|
|
|
|
updateFields();
|
|
|
|
});
|
|
|
|
tag.find(".connect_nickname").on("keyup", () => {
|
|
|
|
if(connectIdentity instanceof NameIdentity)
|
|
|
|
connectIdentity.set_name(tag.find(".connect_nickname").val() as string);
|
|
|
|
});
|
2018-10-07 18:21:28 +02:00
|
|
|
|
|
|
|
if(!settings.static("localhost_debug", false)) {
|
|
|
|
console.trace("Removing debug connect option");
|
2018-09-21 23:25:03 +02:00
|
|
|
tag.find(".identity_select option[value=" + IdentitifyType[IdentitifyType.NICKNAME] + "]").remove();
|
2018-10-07 18:21:28 +02:00
|
|
|
}
|
2018-09-21 23:25:03 +02:00
|
|
|
}
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2018-03-07 19:06:52 +01:00
|
|
|
//connect_address
|
|
|
|
return tag;
|
|
|
|
},
|
|
|
|
footer: function () {
|
|
|
|
let tag = $.spawn("div");
|
|
|
|
tag.css("text-align", "right");
|
|
|
|
tag.css("margin-top", "3px");
|
|
|
|
tag.css("margin-bottom", "6px");
|
|
|
|
tag.addClass("modal-button-group");
|
|
|
|
|
|
|
|
let button = $.spawn("button");
|
|
|
|
button.addClass("connect_connect_button");
|
|
|
|
button.text("Connect");
|
|
|
|
button.on("click", function () {
|
|
|
|
connectModal.close();
|
|
|
|
|
|
|
|
let field_address = tag.parents(".modal-content").find(".connect_address");
|
|
|
|
let address = field_address.val().toString();
|
2018-09-24 21:14:36 +02:00
|
|
|
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}
|
|
|
|
);
|
2018-03-07 19:06:52 +01:00
|
|
|
});
|
|
|
|
tag.append(button);
|
|
|
|
return tag;
|
|
|
|
},
|
|
|
|
|
2018-12-02 19:27:03 +01:00
|
|
|
width: '70%',
|
2018-03-07 19:06:52 +01:00
|
|
|
//closeable: false
|
|
|
|
});
|
|
|
|
connectModal.open();
|
|
|
|
}
|
|
|
|
|
2018-03-24 23:38:01 +01:00
|
|
|
let Regex = {
|
|
|
|
//DOMAIN<:port>
|
|
|
|
DOMAIN: /^(localhost|((([a-zA-Z0-9_-]{0,63}\.){0,253})?[a-zA-Z0-9_-]{0,63}\.[a-zA-Z]{2,5}))(|:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[0-5]?[0-9]{1,4}))$/,
|
|
|
|
//IP<:port>
|
|
|
|
IP_V4: /(^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(|:(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[0-5]?[0-9]{1,4}))$/,
|
|
|
|
IP_V6: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((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0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,
|
|
|
|
};
|
2018-04-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
<div style="display: flex; justify-content: space-between;">
|
|
|
|
<div style="text-align: right;">Identity Settings</div>
|
|
|
|
<select class="identity_select">
|
|
|
|
<option name="identity_type" value="identity_type_forum">Forum Account</option>
|
|
|
|
<option name="identity_type" value="identity_type_teamspeak">TeamSpeak</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<div class="identity_config_teamspeak">
|
|
|
|
Please enter your exported TS3 Identity string bellow or select your exported Identity<br>
|
|
|
|
<div style="width: 100%; display: flex; flex-direction: row">
|
|
|
|
<input placeholder="Identity string" style="width: 70%; margin: 5px;" class="identity_string">
|
|
|
|
<div style="width: 30%; margin: 5px"><input name="identity_file" type="file"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="identity_config_forum">
|
|
|
|
You're using your forum account as verification
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div style="background-color: red; border-radius: 1px; display: none" class="error_message">
|
|
|
|
Identity isnt valid!
|
|
|
|
</div>
|
|
|
|
*/
|