From 3950963277fd14c1c61f4816b0587357318fa90f Mon Sep 17 00:00:00 2001 From: Itokoyamato Date: Sat, 5 Dec 2020 22:23:06 +0100 Subject: [PATCH 01/13] feat(plugin): add manual connect option --- ts3_plugin/src/tokovoip.cpp | 45 ++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/ts3_plugin/src/tokovoip.cpp b/ts3_plugin/src/tokovoip.cpp index f31f446a..63f77f78 100644 --- a/ts3_plugin/src/tokovoip.cpp +++ b/ts3_plugin/src/tokovoip.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include "plugin.h" //pluginID #include "ts3_functions.h" @@ -34,6 +36,7 @@ HANDLE threadWebSocket = INVALID_HANDLE_VALUE; bool exitWebSocketThread = FALSE; shared_ptr wsConnection; +string currentEndpoint = ""; bool isTalking = false; char* originalName = ""; time_t lastNameSetTick = 0; @@ -50,6 +53,8 @@ int disconnectButtonId; int unmuteButtonId; int supportButtonId; int projectButtonId; +int manualConnectButtonId; + bool isPTT = true; float defaultMicClicksVolume = -15; @@ -315,7 +320,12 @@ void tokovoipProcess() { Sleep(1000); } - string endpoint = getWebSocketEndpoint(); + string endpoint; + if (currentEndpoint != "") endpoint = currentEndpoint; + else { + getWebSocketEndpoint(); + currentEndpoint = endpoint; + } if (endpoint == "") { outputLog("WebsocketServer: Failed to retrieve the websocket endpoint."); return; @@ -634,6 +644,7 @@ void onButtonClicked(uint64 serverConnectionHandlerID, PluginMenuType type, int { if (type == PLUGIN_MENU_TYPE_GLOBAL) { if (menuItemID == connectButtonId) { + currentEndpoint = ""; initWebSocket(); } else if (menuItemID == disconnectButtonId) { killWebsocketThread(); @@ -644,6 +655,33 @@ void onButtonClicked(uint64 serverConnectionHandlerID, PluginMenuType type, int } else if (menuItemID == projectButtonId) { QDesktopServices::openUrl(QUrl("https://github.com/Itokoyamato/TokoVOIP_TS3")); } + else if (menuItemID == manualConnectButtonId) { + QSettings cfg(TSHelpers::GetFullConfigPath(), QSettings::IniFormat); + cfg.beginGroup("TokoVOIP"); + { + currentEndpoint = cfg.value("currentEndpoint", "").toString().toStdString(); + } + cfg.endGroup(); + bool ok; + QString text = QInputDialog::getText(0, + "Manual connect", + "\nEnter the ws_server address below\n\nYou can find it on the in-game blocking screen\nOr ask the server owner/support\n\n", + QLineEdit::Normal, + QString::fromStdString(currentEndpoint), + &ok, + Qt::WindowCloseButtonHint + ); + if (!ok || text.isEmpty()) return; + outputLog("Setting currentEndpoint to: " + text.toStdString()); + currentEndpoint = text.toStdString(); + cfg.beginGroup("TokoVOIP"); + { + cfg.setValue("currentEndpoint", QString::fromStdString(currentEndpoint)); + } + cfg.endGroup(); + killWebsocketThread(); + initWebSocket(); + } } } @@ -653,10 +691,11 @@ int Tokovoip::initialize(char *id, QObject* parent) { plugin = qobject_cast(parent); auto& context_menu = plugin->context_menu(); - connectButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Connect", ""); + supportButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Support the project on Patreon", "logo.png"); + connectButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Connect (Auto Discover)", ""); + manualConnectButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Connect (Manual)", ""); disconnectButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Disconnect", ""); unmuteButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Unmute All", ""); - supportButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Support on Patreon", ""); projectButtonId = context_menu.Register(plugin, PLUGIN_MENU_TYPE_GLOBAL, "Project page", ""); ts3Functions.setPluginMenuEnabled(plugin->id().c_str(), disconnectButtonId, false); parent->connect(&context_menu, &TSContextMenu::FireContextMenuEvent, parent, &onButtonClicked); From 953e77b2ad0773a254b0679ad45d792b3feb8e9d Mon Sep 17 00:00:00 2001 From: Itokoyamato Date: Mon, 7 Dec 2020 10:27:33 +0100 Subject: [PATCH 02/13] chore(deps): update cpp-httplib --- ts3_plugin/deps/cpp-httplib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts3_plugin/deps/cpp-httplib b/ts3_plugin/deps/cpp-httplib index 42f9f910..88c961f3 160000 --- a/ts3_plugin/deps/cpp-httplib +++ b/ts3_plugin/deps/cpp-httplib @@ -1 +1 @@ -Subproject commit 42f9f9107f87ad2ee04be117dbbadd621c449552 +Subproject commit 88c961f37efb0205aae418a35b354935be3ff3ff From ff273b6b060d3c6ed8eb6cdbddf7550430ddc17d Mon Sep 17 00:00:00 2001 From: Itokoyamato Date: Mon, 7 Dec 2020 10:28:13 +0100 Subject: [PATCH 03/13] feat(fivem-script): add displayWSInfo option --- fivem_script/tokovoip_script/c_config.lua | 1 + fivem_script/tokovoip_script/nui/index.html | 4 +++- fivem_script/tokovoip_script/nui/script.js | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fivem_script/tokovoip_script/c_config.lua b/fivem_script/tokovoip_script/c_config.lua index b05799e5..629e8112 100644 --- a/fivem_script/tokovoip_script/c_config.lua +++ b/fivem_script/tokovoip_script/c_config.lua @@ -19,6 +19,7 @@ TokoVoipConfig = { radioAnim = true, -- Enable or disable the radio animation radioEnabled = true, -- Enable or disable using the radio wsServer = "ip:port", -- Address of the websocket server + displayWSInfo = true, -- Enable or disable the WS info on the blocking screen, used to manually connect in TeamSpeak plugin_data = { -- TeamSpeak channel name used by the voip diff --git a/fivem_script/tokovoip_script/nui/index.html b/fivem_script/tokovoip_script/nui/index.html index fb47feff..d1e8f285 100644 --- a/fivem_script/tokovoip_script/nui/index.html +++ b/fivem_script/tokovoip_script/nui/index.html @@ -107,6 +107,8 @@ TeamSpeak channel:
+
+
Status:
  • Plugin status: OFFLINE @@ -115,7 +117,7 @@
  • Ts3 websocket: Not connected
  • -
    +
  • Plugin version: Not found (Required: 1.5.0)
diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index d06c7600..1d4711f8 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -330,6 +330,8 @@ function updateConfig (payload) { document.getElementById('TSChannel').innerHTML = `TeamSpeak channel: ${(voip.plugin_data.TSChannelWait) ? voip.plugin_data.TSChannelWait.replace(/\[[a-z]spacer(.*?)\]/, '') : voip.plugin_data.TSChannel.replace(/\[[a-z]spacer(.*?)\]/, '')}`; document.getElementById('TSDownload').innerHTML = voip.plugin_data.TSDownload; document.getElementById('pluginVersion').innerHTML = `Plugin version: Not found (Minimal version: ${voip.minVersion})`; + document.getElementById('wsInfo').style.display = voip.displayWSInfo ? 'block' : 'none'; + document.getElementById('wsInfo').innerHTML = `WS Server address: ${voip.wsServer}
(Use this to manually connect on TeamSpeak, plugins->TokoVOIP->Connect (Manual))`; } function updatePlugin () { From e4bcce729c462d7271e775ec52840e025a58221e Mon Sep 17 00:00:00 2001 From: Itokoyamato Date: Mon, 7 Dec 2020 10:29:25 +0100 Subject: [PATCH 04/13] chore(ws-server): update config.js comments --- ws_server/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ws_server/config.js b/ws_server/config.js index f5c1951d..8a38ff71 100644 --- a/ws_server/config.js +++ b/ws_server/config.js @@ -7,9 +7,9 @@ module.exports = { //-- Please use a port above 30k as some networks block those below it WSServerPort: 33250, - //-- [OPTIONAL] IPv4 Address of the ws_server + //-- [OPTIONAL] IPv4 Address or domain name of the ws_server //-- Set by autoconfig - // WSServerIP: "127.0.0.1", + // WSServerIP: "127.0.0.1 or mydomain.com", //-- [OPTIONAL] Enable connection/disconnection logs enableLogs: false, From efbb4c5d9c77901bfb3e3633e63154099a1f80f4 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Wed, 10 Mar 2021 11:02:21 +0100 Subject: [PATCH 05/13] fix(ws-server): delete handshake on clientIP update --- ws_server/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ws_server/index.js b/ws_server/index.js index 8e408fd3..c419285a 100644 --- a/ws_server/index.js +++ b/ws_server/index.js @@ -154,7 +154,10 @@ io.on('connection', async socket => { socketHeartbeat(socket); socket.on('updateClientIP', data => { if (!data || !data.ip || !IPv4Regex.test(data.ip) || !clients[socket.uuid]) return; - if (lodash.get(clients, `[${socket.uuid}].fivem.socket`)) clients[socket.uuid].fivem.socket.clientIp = data.ip; + if (lodash.get(clients, `[${socket.uuid}].fivem.socket`)) { + delete handshakes[clients[socket.uuid].fivem.socket.clientIp]; + clients[socket.uuid].fivem.socket.clientIp = data.ip; + } if (lodash.get(clients, `[${socket.uuid}].ts3.socket`)) clients[socket.uuid].ts3.socket.clientIp = data.ip; }); await registerHandshake(socket); From adedb661599724696cd27b0bf16ded54f19b0021 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 21:53:17 +0200 Subject: [PATCH 06/13] fix(plugin): set endpoint properly --- ts3_plugin/src/tokovoip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts3_plugin/src/tokovoip.cpp b/ts3_plugin/src/tokovoip.cpp index 63f77f78..a0ec926f 100644 --- a/ts3_plugin/src/tokovoip.cpp +++ b/ts3_plugin/src/tokovoip.cpp @@ -323,7 +323,7 @@ void tokovoipProcess() { string endpoint; if (currentEndpoint != "") endpoint = currentEndpoint; else { - getWebSocketEndpoint(); + endpoint = getWebSocketEndpoint(); currentEndpoint = endpoint; } if (endpoint == "") { From 0cccbeb48e946b94a7c09b079253ed91da67833a Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:00:34 +0200 Subject: [PATCH 07/13] fix(ws-server): avoid sending non-json data to ts3 --- ws_server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ws_server/index.js b/ws_server/index.js index c419285a..bd9c76f8 100644 --- a/ws_server/index.js +++ b/ws_server/index.js @@ -209,7 +209,7 @@ function setTS3Data(socket, data) { function onIncomingData(socket, data) { const client = clients[socket.uuid]; - if (!socket.uuid || !client || !client.ts3.socket) return; + if (!socket.uuid || !client || !client.ts3.socket || typeof data !== 'object') return; socket.tokoData = data; client.fivem.data = socket.tokoData; client.fivem.updatedAt = (new Date()).toISOString(); From b955ee52a86587ede6b498d173629705fad9ce18 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:04:42 +0200 Subject: [PATCH 08/13] fix(plugin): secure invalid json object --- ts3_plugin/src/tokovoip.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ts3_plugin/src/tokovoip.cpp b/ts3_plugin/src/tokovoip.cpp index a0ec926f..bb0244f9 100644 --- a/ts3_plugin/src/tokovoip.cpp +++ b/ts3_plugin/src/tokovoip.cpp @@ -88,8 +88,9 @@ int handleMessage(shared_ptr connection, string message_st // Load the json // json json_data = json::parse(message_str.c_str(), nullptr, false); - if (json_data.is_discarded()) { - ts3Functions.logMessage("Invalid JSON data", LogLevel_INFO, "TokoVOIP", 0); + if (json_data.is_discarded() || !json_data.is_object()) { + if (json_data.is_discarded()) outputLog("Invalid JSON data"); + else outputLog("Invalid JSON data, expected object"); tokovoip->setProcessingState(false, currentPluginStatus); return (0); } From af0c58ba8a09917fb247d06f69612088de7e7959 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:13:41 +0200 Subject: [PATCH 09/13] improv(ws-server): increase http buffer size which might help with unwanted disconnects --- ws_server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ws_server/index.js b/ws_server/index.js index bd9c76f8..61234304 100644 --- a/ws_server/index.js +++ b/ws_server/index.js @@ -3,7 +3,7 @@ const bootTime = new Date(); const express = require('express'); const app = express(); const http = require('http').createServer(app); -const io = require('socket.io')(http); +const io = require('socket.io')(http, { maxHttpBufferSize: 1e8 }); const axios = require('axios'); const lodash = require('lodash'); const chalk = require('chalk'); From bb1685d37fa0e0183689634e4dfef7a8786aace0 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:14:19 +0200 Subject: [PATCH 10/13] improv(fivem-script): adjust sytling of wsInfo --- fivem_script/tokovoip_script/nui/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index 1d4711f8..050d94a2 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -331,7 +331,7 @@ function updateConfig (payload) { document.getElementById('TSDownload').innerHTML = voip.plugin_data.TSDownload; document.getElementById('pluginVersion').innerHTML = `Plugin version: Not found (Minimal version: ${voip.minVersion})`; document.getElementById('wsInfo').style.display = voip.displayWSInfo ? 'block' : 'none'; - document.getElementById('wsInfo').innerHTML = `WS Server address: ${voip.wsServer}
(Use this to manually connect on TeamSpeak, plugins->TokoVOIP->Connect (Manual))`; + document.getElementById('wsInfo').innerHTML = `WS Server address: ${voip.wsServer}
Use this to manually connect on TeamSpeak
TS3->Plugins->TokoVOIP->Connect (Manual)
`; } function updatePlugin () { From 7857ca0357752113051f79036acf6b33769c29e2 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:18:01 +0200 Subject: [PATCH 11/13] fix(fivem-script): clear ip update timeout on creating new one --- fivem_script/tokovoip_script/nui/script.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index 050d94a2..2abdf98c 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -60,6 +60,7 @@ function disconnect (src) { } } +let clientIPTimeout; async function updateClientIP(endpoint) { if (!endpoint) { console.error('updateClientIP: endpoint missing'); @@ -72,11 +73,12 @@ async function updateClientIP(endpoint) { if (res) { const ip = await res.text(); clientIp = ip; - console.log('TokoVOIP: updated client IP'); if (websocket && websocket.readyState === websocket.OPEN) websocket.send(`42${JSON.stringify(['updateClientIP', { ip: clientIp }])}`); } } - setTimeout(_ => updateClientIP(endpoint), 10000); + + if (clientIPTimeout) clearTimeout(clientIPTimeout); + clientIPTimeout = setTimeout(_ => updateClientIP(endpoint), 10000); } async function init(address, serverId) { From 2b5901434d8ed178b87deaee1fb1cc55bef7e3ac Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:19:29 +0200 Subject: [PATCH 12/13] fix(fivem-script): trying to send socket data on websocket close --- fivem_script/tokovoip_script/nui/script.js | 1 - 1 file changed, 1 deletion(-) diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index 2abdf98c..0466a5dd 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -128,7 +128,6 @@ async function init(address, serverId) { }; websocket.onclose = () => { - sendData('disconnect'); disconnect('FiveM') console.log('FiveM Disconnected') From b05c633f214fcf603627d4a223b1b0b375e40fd7 Mon Sep 17 00:00:00 2001 From: Dylan THUILLIER Date: Thu, 8 Apr 2021 22:38:49 +0200 Subject: [PATCH 13/13] fix(fivem-script): handle clientIP update error --- fivem_script/tokovoip_script/nui/script.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index 0466a5dd..dabd173a 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -67,10 +67,9 @@ async function updateClientIP(endpoint) { return; } if (voipStatus !== OK) { - const res = await fetch(`http://${endpoint}/getmyip`) - .catch(e => console.error('TokoVOIP: failed to update cient IP', e)); - - if (res) { + const res = await fetch(`http://${endpoint}/getmyip`); + if (!res.ok) console.error(`TokoVOIP: failed to update cient IP (error: ${res.status})`); + else { const ip = await res.text(); clientIp = ip; if (websocket && websocket.readyState === websocket.OPEN) websocket.send(`42${JSON.stringify(['updateClientIP', { ip: clientIp }])}`);