Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependabot/npm and yarn/ws server/axios 0.21.1 #275

Open
wants to merge 15 commits into
base: dependabot/npm_and_yarn/ws_server/axios-0.21.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fivem_script/tokovoip_script/c_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion fivem_script/tokovoip_script/nui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
TeamSpeak channel:
</div>
<br>
<div id="wsInfo"></div>
<br>
Status:
<ul>
<li id="pluginStatus">Plugin status: <font color="red">OFFLINE</font>
Expand All @@ -115,7 +117,7 @@
</li>
<li id="Ts3State">Ts3 websocket: <font color="red">Not connected</font>
</li>
<br />
<br>
<li id="pluginVersion">Plugin version: <font color="red">Not found</font> (Required: 1.5.0)</li>
</ul>
</div>
Expand Down
16 changes: 9 additions & 7 deletions fivem_script/tokovoip_script/nui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,24 @@ function disconnect (src) {
}
}

let clientIPTimeout;
async function updateClientIP(endpoint) {
if (!endpoint) {
console.error('updateClientIP: endpoint missing');
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;
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) {
Expand Down Expand Up @@ -126,7 +127,6 @@ async function init(address, serverId) {
};

websocket.onclose = () => {
sendData('disconnect');
disconnect('FiveM')
console.log('FiveM Disconnected')

Expand Down Expand Up @@ -330,6 +330,8 @@ function updateConfig (payload) {
document.getElementById('TSChannel').innerHTML = `TeamSpeak channel: <font color="#01b0f0">${(voip.plugin_data.TSChannelWait) ? voip.plugin_data.TSChannelWait.replace(/\[[a-z]spacer(.*?)\]/, '') : voip.plugin_data.TSChannel.replace(/\[[a-z]spacer(.*?)\]/, '')}</font>`;
document.getElementById('TSDownload').innerHTML = voip.plugin_data.TSDownload;
document.getElementById('pluginVersion').innerHTML = `Plugin version: <font color="red">Not found</font> (Minimal version: ${voip.minVersion})`;
document.getElementById('wsInfo').style.display = voip.displayWSInfo ? 'block' : 'none';
document.getElementById('wsInfo').innerHTML = `WS Server address: <font color="#01b0f0">${voip.wsServer}</font><br><font color="#a8a8a8" size="1">Use this to manually connect on TeamSpeak <br> TS3->Plugins->TokoVOIP->Connect (Manual)</font>`;
}

function updatePlugin () {
Expand Down
50 changes: 45 additions & 5 deletions ts3_plugin/src/tokovoip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <QDesktopServices>
#include <QUrl>
#include <QInputDialog>
#include <QSettings>

#include "plugin.h" //pluginID
#include "ts3_functions.h"
Expand All @@ -34,6 +36,7 @@ HANDLE threadWebSocket = INVALID_HANDLE_VALUE;
bool exitWebSocketThread = FALSE;
shared_ptr<WsClient::Connection> wsConnection;

string currentEndpoint = "";
bool isTalking = false;
char* originalName = "";
time_t lastNameSetTick = 0;
Expand All @@ -50,6 +53,8 @@ int disconnectButtonId;
int unmuteButtonId;
int supportButtonId;
int projectButtonId;
int manualConnectButtonId;

bool isPTT = true;

float defaultMicClicksVolume = -15;
Expand Down Expand Up @@ -83,8 +88,9 @@ int handleMessage(shared_ptr<WsClient::Connection> 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);
}
Expand Down Expand Up @@ -315,7 +321,12 @@ void tokovoipProcess() {
Sleep(1000);
}

string endpoint = getWebSocketEndpoint();
string endpoint;
if (currentEndpoint != "") endpoint = currentEndpoint;
else {
endpoint = getWebSocketEndpoint();
currentEndpoint = endpoint;
}
if (endpoint == "") {
outputLog("WebsocketServer: Failed to retrieve the websocket endpoint.");
return;
Expand Down Expand Up @@ -634,6 +645,7 @@ void onButtonClicked(uint64 serverConnectionHandlerID, PluginMenuType type, int
{
if (type == PLUGIN_MENU_TYPE_GLOBAL) {
if (menuItemID == connectButtonId) {
currentEndpoint = "";
initWebSocket();
} else if (menuItemID == disconnectButtonId) {
killWebsocketThread();
Expand All @@ -644,6 +656,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();
}
}
}

Expand All @@ -653,10 +692,11 @@ int Tokovoip::initialize(char *id, QObject* parent) {

plugin = qobject_cast<Plugin_Base*>(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);
Expand Down
4 changes: 2 additions & 2 deletions ws_server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions ws_server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -206,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();
Expand Down