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

Resolve initialization problems for some players #203

Merged
merged 5 commits into from
Oct 10, 2020
Merged
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
3 changes: 1 addition & 2 deletions fivem_script/tokovoip_script/nui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,13 @@ function receivedClientCall (event) {

// Start with a status OK by default, and change the status if issues are encountered
voipStatus = OK;

if (eventName == 'updateConfig') {
updateConfig(payload);

} else if (voip) {
if (eventName == 'initializeSocket') {
$.post(`http://${scriptName}/nuiLoaded`)
init(payload);

} else if (eventName == 'updateTokovoipInfo') {
if (connected)
updateTokovoipInfo(payload, 1);
Expand Down
12 changes: 11 additions & 1 deletion fivem_script/tokovoip_script/src/c_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local animStates = {}
local displayingPluginScreen = false;
local HeadBone = 0x796e;
local radioVolume = 0;
local nuiLoaded = false

--------------------------------------------------------------------------------
-- Plugin functions
Expand Down Expand Up @@ -256,7 +257,10 @@ AddEventHandler("initializeVoip", function()
print("TokoVoip: FiveM Server ID is " .. voip.fivemServerId);

voip.processFunction = clientProcessing; -- Link the processing function that will be looped
voip:initialize(); -- Initialize the websocket and controls
while not nuiLoaded do
voip:initialize(); -- Initialize the websocket and controls
Citizen.Wait(5000)
end
voip:loop(); -- Start TokoVoip's loop
end);

Expand Down Expand Up @@ -406,6 +410,12 @@ AddEventHandler("updateVoipTargetPed", function(newTargetPed, useLocal)
useLocalPed = useLocal
end)

-- Used to prevent bad nui loading
RegisterNUICallback("nuiLoaded", function(data, cb)
nuiLoaded = true
cb("ok")
end)

-- Make exports available on first tick
exports("addPlayerToRadio", addPlayerToRadio);
exports("removePlayerFromRadio", removePlayerFromRadio);
Expand Down
4 changes: 2 additions & 2 deletions ws_server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ app.get('/playerbyip', (req, res) => {
return res.status(204).send();
});

app.get('getmyip', (req, res) => {
app.get('/getmyip', (req, res) => {
const ip = (lodash.get(req, `headers.['x-forwarded-for']`) || lodash.get(req, `headers.['x-real-ip']`) || lodash.get(req, 'connection.remoteAddress')).replace('::ffff:', '');
res.send(ip);
});

http.on('upgrade', (req, socket) => {
http.on('/upgrade', (req, socket) => {
if (!req._query || !req._query.from) return socket.destroy();
if (req._query.from === 'ts3' && !req._query.uuid) return socket.destroy();
});
Expand Down