TeaWeb/shared/js/ui/server.ts

259 lines
10 KiB
TypeScript
Raw Normal View History

2018-02-27 17:20:49 +01:00
/// <reference path="channel.ts" />
2018-08-11 15:02:11 +02:00
/// <reference path="modal/ModalServerEdit.ts" />
2018-02-27 17:20:49 +01:00
class ServerProperties {
2018-08-11 15:02:11 +02:00
virtualserver_host: string = "";
virtualserver_port: number = 0;
virtualserver_name: string = "";
2018-08-13 13:06:42 +02:00
virtualserver_name_phonetic: string = "";
virtualserver_icon_id: number = 0;
virtualserver_version: string = "unknown";
virtualserver_platform: string = "unknown";
virtualserver_unique_identifier: string = "";
virtualserver_clientsonline: number = 0;
virtualserver_queryclientsonline: number = 0;
virtualserver_channelsonline: number = 0;
virtualserver_uptime: number = 0;
2018-08-11 15:02:11 +02:00
virtualserver_maxclients: number = 0;
virtualserver_reserved_slots: number = 0;
virtualserver_password: string = "";
virtualserver_flag_password: boolean = false;
virtualserver_welcomemessage: string = "";
virtualserver_hostmessage: string = "";
virtualserver_hostmessage_mode: number = 0;
virtualserver_hostbanner_url: string = "";
virtualserver_hostbanner_gfx_url: string = "";
virtualserver_hostbanner_gfx_interval: number = 0;
virtualserver_hostbanner_mode: number = 0;
virtualserver_hostbutton_tooltip: string = "";
virtualserver_hostbutton_url: string = "";
virtualserver_hostbutton_gfx_url: string = "";
2018-08-13 13:06:42 +02:00
virtualserver_codec_encryption_mode: number = 0;
virtualserver_default_music_group: number = 0;
2018-08-13 13:06:42 +02:00
virtualserver_default_server_group: number = 0;
virtualserver_default_channel_group: number = 0;
virtualserver_default_channel_admin_group: number = 0;
//Special requested properties
virtualserver_default_client_description: string = "";
virtualserver_default_channel_description: string = "";
virtualserver_default_channel_topic: string = "";
virtualserver_antiflood_points_tick_reduce: number = 0;
virtualserver_antiflood_points_needed_command_block: number = 0;
virtualserver_antiflood_points_needed_ip_block: number = 0;
2018-08-13 13:06:42 +02:00
virtualserver_complain_autoban_count: number = 0;
virtualserver_complain_autoban_time: number = 0;
virtualserver_complain_remove_time: number = 0;
virtualserver_needed_identity_security_level: number = 8;
virtualserver_weblist_enabled: boolean = false;
virtualserver_min_clients_in_channel_before_forced_silence: number = 0;
2018-11-04 14:20:38 +01:00
virtualserver_max_upload_total_bandwidth: number = 0;
virtualserver_upload_quota: number = 0;
virtualserver_max_download_total_bandwidth: number = 0;
virtualserver_download_quota: number = 0;
}
interface ServerAddress {
host: string;
port: number;
}
2018-02-27 17:20:49 +01:00
class ServerEntry {
remote_address: ServerAddress;
2018-02-27 17:20:49 +01:00
channelTree: ChannelTree;
properties: ServerProperties;
2018-02-27 17:20:49 +01:00
private info_request_promise: Promise<void> = undefined;
private info_request_promise_resolve: any = undefined;
private info_request_promise_reject: any = undefined;
2018-02-27 17:20:49 +01:00
lastInfoRequest: number = 0;
nextInfoRequest: number = 0;
private _htmlTag: JQuery<HTMLElement>;
constructor(tree, name, address: ServerAddress) {
this.properties = new ServerProperties();
2018-02-27 17:20:49 +01:00
this.channelTree = tree;
this.remote_address = address;
2018-02-27 17:20:49 +01:00
this.properties.virtualserver_name = name;
}
get htmlTag() {
if(this._htmlTag) return this._htmlTag;
Implemented the Material Design and fixed some bugs (#33) * cleaned up some files * Fundamental style update * Redesigned some style * fixed hostbanner popup * Removed old identity stuff * fixed close listener * Fixed changelog date * fixed release chat icons * fixed url * Fixed hostbanner * Uploaded missing images * Improved update handling * Improved script files * Fixed loading error and icon error * fixed Yes/No modal * Fixed loader issues with MS Edge * fixed modal style bug * Fixed control bar overflow for small devices * Improved error handling on identity creation * Logging generate error to terminal * fixed possible php error * fixed some possible loading errors when other files have'nt been already loaded. * removed debug message * Changed emsrcypten flags * Improved codec error handling * removed webassembly as required dependency * Improved and fixed channel tree issues * Improved the sliders * Removed unneeded files * fixed loader versions cache * second slight performance improved (dont animate elements anymore if they are not shown) * Fixed query visibility setting * not showing useless client infos for query clients * Added an auto reconnect system * Added a canceled message and increased reconnect interval * removed implemented todo * fixed repetitive channel names * Reworked the channel tree selected lines * Fixed channel tree names * Fixed name alignment * fixed the native client * added min width to the server select groups to avoid a disappearing effect on shrink * fixed bugged downloaded icons
2019-02-17 16:08:10 +01:00
let tag = $.spawn("div").addClass("tree-entry server");
tag.append(
$.spawn("div")
.addClass("server_type icon client-server_green")
);
tag.append(
$.spawn("div")
.addClass("name")
.text(this.properties.virtualserver_name)
);
tag.append(
$.spawn("div")
.addClass("icon_property icon_empty")
);
2018-02-27 17:20:49 +01:00
return this._htmlTag = tag;
}
initializeListener(){
this._htmlTag.click(() => {
this.channelTree.onSelect(this);
2018-02-27 17:20:49 +01:00
});
2018-04-16 20:38:35 +02:00
if(!settings.static(Settings.KEY_DISABLE_CONTEXT_MENU, false)) {
this.htmlTag.on("contextmenu", (event) => {
2018-04-16 20:38:35 +02:00
event.preventDefault();
if($.isArray(this.channelTree.currently_selected)) { //Multiselect
(this.channelTree.currently_selected_context_callback || ((_) => null))(event);
return;
}
this.channelTree.onSelect(this, true);
this.spawnContextMenu(event.pageX, event.pageY, () => { this.channelTree.onSelect(undefined, true); });
2018-04-16 20:38:35 +02:00
});
}
2018-02-27 17:20:49 +01:00
}
2018-04-16 20:38:35 +02:00
spawnContextMenu(x: number, y: number, on_close: () => void = () => {}) {
2019-03-07 15:30:53 +01:00
let trigger_close = true;
2018-09-30 21:50:59 +02:00
spawn_context_menu(x, y, {
2019-03-07 15:30:53 +01:00
type: MenuEntryType.ENTRY,
name: tr("Show server info"),
callback: () => {
trigger_close = false;
2019-04-04 21:47:52 +02:00
this.channelTree.client.select_info.open_popover()
2019-03-07 15:30:53 +01:00
},
icon: "client-about",
2019-04-04 21:47:52 +02:00
visible: this.channelTree.client.select_info.is_popover()
2019-03-07 15:30:53 +01:00
}, {
type: MenuEntryType.HR,
2019-04-04 21:47:52 +02:00
visible: this.channelTree.client.select_info.is_popover(),
2019-03-07 15:30:53 +01:00
name: ''
}, {
2018-02-27 17:20:49 +01:00
type: MenuEntryType.ENTRY,
2018-08-13 13:16:10 +02:00
icon: "client-virtualserver_edit",
name: tr("Edit"),
2018-08-11 15:02:11 +02:00
callback: () => {
Modals.createServerModal(this, properties => {
log.info(LogCategory.SERVER, tr("Changing server properties %o"), properties);
console.log(tr("Changed properties: %o"), properties);
2018-08-11 15:02:11 +02:00
if (properties)
2019-02-23 14:15:22 +01:00
this.channelTree.client.serverConnection.send_command("serveredit", properties).then(() => {
2019-04-04 21:47:52 +02:00
this.channelTree.client.sound.play(Sound.SERVER_EDITED_SELF);
2018-11-04 00:39:29 +01:00
});
2018-08-11 15:02:11 +02:00
});
}
2019-03-25 20:04:04 +01:00
}, {
type: MenuEntryType.ENTRY,
icon: "client-iconviewer",
name: tr("View icons"),
callback: () => Modals.spawnIconSelect(this.channelTree.client)
}, {
type: MenuEntryType.ENTRY,
icon: 'client-iconsview',
name: tr("View avatars"),
callback: () => Modals.spawnAvatarList(this.channelTree.client)
2019-01-20 18:43:14 +01:00
}, {
type: MenuEntryType.ENTRY,
icon: "client-invite_buddy",
name: tr("Invite buddy"),
callback: () => {
2019-04-15 15:33:51 +02:00
const address = this.channelTree.client.serverConnection.remote_address().host + ":" + this.channelTree.client.serverConnection.remote_address().port;
2019-01-20 18:43:14 +01:00
const parameter = "connect_default=1&connect_address=" + encodeURIComponent(address);
const url = document.location.origin + document.location.pathname + "?" + parameter;
copy_to_clipboard(url);
createInfoModal(tr("Buddy invite URL"), tr("Your buddy invite URL:<br>") + url + tr("<bt>This has been copied to your clipboard.")).open();
}
2018-02-27 17:20:49 +01:00
},
2019-03-07 15:30:53 +01:00
MenuEntry.CLOSE(() => (trigger_close ? on_close : () => {})())
2018-02-27 17:20:49 +01:00
);
}
updateVariables(is_self_notify: boolean, ...variables: {key: string, value: string}[]) {
let group = log.group(log.LogType.DEBUG, LogCategory.SERVER, tr("Update properties (%i)"), variables.length);
2019-03-25 20:04:04 +01:00
{
const entries = [];
for(const variable of variables)
entries.push({
key: variable.key,
value: variable.value,
type: typeof (this.properties[variable.key])
});
log.table("Server update properties", entries);
}
let update_bannner = false;
for(let variable of variables) {
2018-08-10 21:30:58 +02:00
JSON.map_field_to(this.properties, variable.value, variable.key);
if(variable.key == "virtualserver_name") {
this.htmlTag.find(".name").text(variable.value);
2019-04-04 21:47:52 +02:00
this.channelTree.client.tag_connection_handler.find(".server-name").text(variable.value);
server_connections.update_ui();
} else if(variable.key == "virtualserver_icon_id") {
if(this.channelTree.client.fileManager && this.channelTree.client.fileManager.icons)
this.htmlTag.find(".icon_property").replaceWith(this.channelTree.client.fileManager.icons.generateTag(this.properties.virtualserver_icon_id).addClass("icon_property"));
} else if(variable.key.indexOf('hostbanner') != -1) {
update_bannner = true;
}
2018-02-27 17:20:49 +01:00
}
if(update_bannner)
2019-04-04 21:47:52 +02:00
this.channelTree.client.select_info.update_banner();
group.end();
if(is_self_notify && this.info_request_promise_resolve) {
this.info_request_promise_resolve();
this.info_request_promise = undefined;
this.info_request_promise_reject = undefined;
this.info_request_promise_resolve = undefined;
}
2018-02-27 17:20:49 +01:00
}
updateProperties() : Promise<void> {
if(this.info_request_promise && Date.now() - this.lastInfoRequest < 1000) return this.info_request_promise;
this.lastInfoRequest = Date.now();
2018-02-27 17:20:49 +01:00
this.nextInfoRequest = this.lastInfoRequest + 10 * 1000;
2019-02-23 14:15:22 +01:00
this.channelTree.client.serverConnection.send_command("servergetvariables").catch(error => {
this.info_request_promise_reject(error);
this.info_request_promise = undefined;
this.info_request_promise_reject = undefined;
this.info_request_promise_resolve = undefined;
});
return this.info_request_promise = new Promise<void>((resolve, reject) => {
this.info_request_promise_reject = reject;
this.info_request_promise_resolve = resolve;
});
2018-02-27 17:20:49 +01:00
}
shouldUpdateProperties() : boolean {
2018-04-30 23:57:21 +02:00
return this.nextInfoRequest < Date.now();
2018-02-27 17:20:49 +01:00
}
calculateUptime() : number {
if(this.properties.virtualserver_uptime == 0 || this.lastInfoRequest == 0) return this.properties.virtualserver_uptime;
return this.properties.virtualserver_uptime + (new Date().getTime() - this.lastInfoRequest) / 1000;
2018-02-27 17:20:49 +01:00
}
}