Skip to content

Commit 7bf7eba

Browse files
committed
feat(client/main): add more mumble debugging
- move debug -> logger (we don't want to overwrite Lua native functions) - add connection/disconnection logs
1 parent 2c08629 commit 7bf7eba

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

client/main.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ local submixFunctions = {
6060
---@param enabled boolean if the players voice is getting activated or deactivated
6161
---@param submixType string what submix to use for the players voice, currently only supports 'radio'
6262
function toggleVoice(plySource, enabled, submixType)
63-
debug.verbose(('[main] Updating %s to talking: %s with submix %s'):format(plySource, enabled, submixType))
63+
logger.verbose(('[main] Updating %s to talking: %s with submix %s'):format(plySource, enabled, submixType))
6464
MumbleSetVolumeOverrideByServerId(plySource, enabled and volume or -1.0)
6565
if GetConvarInt('voice_enableRadioSubmix', 0) == 1 then
6666
if enabled and submixType then
@@ -85,11 +85,11 @@ function playerTargets(...)
8585
for id, _ in pairs(targets[i]) do
8686
-- we don't want to log ourself, or listen to ourself
8787
if addedPlayers[id] and id ~= playerServerId then
88-
debug.verbose(('[main] %s is already target don\'t re-add'):format(id))
88+
logger.verbose(('[main] %s is already target don\'t re-add'):format(id))
8989
goto skip_loop
9090
end
9191
if not addedPlayers[id] then
92-
debug.verbose(('[main] Adding %s as a voice target'):format(id))
92+
logger.verbose(('[main] Adding %s as a voice target'):format(id))
9393
addedPlayers[id] = true
9494
MumbleAddVoiceTargetPlayerByServerId(1, id)
9595
end
@@ -185,7 +185,7 @@ end
185185
local function updateZone(forced)
186186
local newGrid = getGridZone()
187187
if newGrid ~= currentGrid or forced then
188-
debug.log(('Updating zone from %s to %s and adding nearby grids.'):format(currentGrid, newGrid))
188+
logger.info(('Updating zone from %s to %s and adding nearby grids.'):format(currentGrid, newGrid))
189189
currentGrid = newGrid
190190
MumbleClearVoiceTargetChannels(1)
191191
NetworkSetVoiceChannel(currentGrid)
@@ -221,7 +221,7 @@ Citizen.CreateThread(function()
221221
})
222222
end
223223
end
224-
Wait(50)
224+
Wait(100)
225225
end
226226
end)
227227

@@ -308,3 +308,11 @@ end)
308308
RegisterCommand("grid", function()
309309
print(('Players current grid is %s'):format(currentGrid))
310310
end)
311+
312+
AddEventHandler('mumbleConnected', function(address, shouldReconnect)
313+
logger.log('Connected to mumble server with address of %s, should reconnect on disconnect is set to %s', GetConvarInt('voice_hideEndpoints', 1) == 1 and 'HIDDEN' or address, shouldReconnect)
314+
end)
315+
316+
AddEventHandler('mumbleDisconnected', function(address)
317+
logger.log('Disconnected from mumble server with address of %s', GetConvarInt('voice_hideEndpoints', 1) == 1 and 'HIDDEN' or address)
318+
end)

client/module/phone.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ RegisterNetEvent('pma-voice:removePlayerFromCall', function(plySource)
5252
else
5353
callData[plySource] = nil
5454
toggleVoice(plySource, false, 'phone')
55-
MumbleClearVoiceTargetPlayers(1)
56-
playerTargets(radioPressed and radioData or {}, callData)
55+
if NetworkIsPlayerTalking(PlayerId()) then
56+
MumbleClearVoiceTargetPlayers(1)
57+
playerTargets(radioPressed and radioData or {}, callData)
58+
end
5759
end
5860
end)
5961

client/module/radio.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---@param radioTable table the table of the current players on the radio
44
function syncRadioData(radioTable)
55
radioData = radioTable
6-
debug.log(('[radio] Syncing radio table.'))
6+
logger.info(('[radio] Syncing radio table.'))
77
if GetConvarInt('voice_debugMode', 0) >= 4 then
88
print('-------- RADIO TABLE --------')
99
tPrint(radioData)
@@ -34,10 +34,10 @@ RegisterNetEvent('pma-voice:setTalkingOnRadio', setTalkingOnRadio)
3434
function addPlayerToRadio(plySource)
3535
radioData[plySource] = false
3636
if radioPressed then
37-
debug.log(('[radio] %s joined radio %s while we were talking, adding them to targets'):format(plySource, radioChannel))
37+
logger.info(('[radio] %s joined radio %s while we were talking, adding them to targets'):format(plySource, radioChannel))
3838
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
3939
else
40-
debug.log(('[radio] %s joined radio %s'):format(plySource, radioChannel))
40+
logger.info(('[radio] %s joined radio %s'):format(plySource, radioChannel))
4141
end
4242
end
4343
RegisterNetEvent('pma-voice:addPlayerToRadio', addPlayerToRadio)
@@ -47,24 +47,23 @@ RegisterNetEvent('pma-voice:addPlayerToRadio', addPlayerToRadio)
4747
---@param plySource number the players server id to remove from the radio.
4848
function removePlayerFromRadio(plySource)
4949
if plySource == playerServerId then
50-
debug.log(('[radio] Left radio %s, cleaning up.'):format(radioChannel))
50+
logger.info(('[radio] Left radio %s, cleaning up.'):format(radioChannel))
5151
for tgt, enabled in pairs(radioData) do
5252
if tgt ~= playerServerId then
5353
toggleVoice(tgt, false)
5454
end
5555
end
5656
radioData = {}
57-
playerTargets({}, NetworkIsPlayerTalking(PlayerId()) and callData or {})
57+
playerTargets(NetworkIsPlayerTalking(PlayerId()) and callData or {})
5858
else
5959
radioData[plySource] = nil
6060
toggleVoice(plySource, false)
6161
if radioPressed then
62-
debug.log(('[radio] %s left radio %s while we were talking, updating targets.'):format(plySource, radioChannel))
62+
logger.info(('[radio] %s left radio %s while we were talking, updating targets.'):format(plySource, radioChannel))
6363
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
6464
else
65-
debug.log(('[radio] %s has left radio %s'):format(plySource, radioChannel))
65+
logger.info(('[radio] %s has left radio %s'):format(plySource, radioChannel))
6666
end
67-
6867
end
6968
end
7069
RegisterNetEvent('pma-voice:removePlayerFromRadio', removePlayerFromRadio)
@@ -126,7 +125,7 @@ RegisterCommand('+radiotalk', function()
126125

127126
if not radioPressed and radioEnabled then
128127
if radioChannel > 0 then
129-
debug.log(('[radio] Start broadcasting, update targets and notify server.'))
128+
logger.info(('[radio] Start broadcasting, update targets and notify server.'))
130129
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
131130
TriggerServerEvent('pma-voice:setTalkingOnRadio', true)
132131
radioPressed = true
@@ -148,6 +147,7 @@ RegisterCommand('-radiotalk', function()
148147
if radioChannel > 0 or radioEnabled then
149148
radioPressed = false
150149
MumbleClearVoiceTargetPlayers(1)
150+
playerTargets(NetworkIsPlayerTalking(PlayerId()) and callData or {})
151151
TriggerEvent("pma-voice:radioActive", false)
152152
playMicClicks(false)
153153
TriggerServerEvent('pma-voice:setTalkingOnRadio', false)
@@ -160,7 +160,7 @@ RegisterKeyMapping('+radiotalk', 'Talk over Radio', 'keyboard', GetConvar('voice
160160
---@param _radioChannel number the radio channel to set the player to.
161161
function syncRadio(_radioChannel)
162162
if GetConvarInt('voice_enableRadios', 1) ~= 1 then return end
163-
debug.log(('[radio] radio set serverside update to radio %s'):format(radioChannel))
163+
logger.info(('[radio] radio set serverside update to radio %s'):format(radioChannel))
164164
radioChannel = _radioChannel
165165
end
166166
RegisterNetEvent('pma-voice:clSetPlayerRadio', syncRadio)

server/module/phone.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---@param source number the player to remove from the call
33
---@param callChannel number the call channel to remove them from
44
function removePlayerFromCall(source, callChannel)
5-
debug.log(('[phone] Removed %s from call %s'):format(source, callChannel))
5+
logger.info(('[phone] Removed %s from call %s'):format(source, callChannel))
66

77
callData[callChannel] = callData[callChannel] or {}
88
for player, _ in pairs(callData[callChannel]) do
@@ -17,7 +17,7 @@ end
1717
---@param source number the player to add to the call
1818
---@param callChannel number the call channel to add them to
1919
function addPlayerToCall(source, callChannel)
20-
debug.log(('[phone] Added %s to call %s'):format(source, callChannel))
20+
logger.info(('[phone] Added %s to call %s'):format(source, callChannel))
2121
-- check if the channel exists, if it does set the varaible to it
2222
-- if not create it (basically if not callData make callData)
2323
callData[callChannel] = callData[callChannel] or {}
@@ -70,15 +70,15 @@ function setTalkingOnCall(talking)
7070
local plyVoice = voiceData[source]
7171
local callTbl = callData[plyVoice.call]
7272
if callTbl then
73-
debug.log(('[phone] %s started talking in call %s'):format(source, plyVoice.call))
73+
logger.info(('[phone] %s started talking in call %s'):format(source, plyVoice.call))
7474
for player, _ in pairs(callTbl) do
7575
if player ~= source then
76-
debug.verbose(('[call] Sending event to %s to tell them that %s is talking'):format(player, source))
76+
logger.verbose(('[call] Sending event to %s to tell them that %s is talking'):format(player, source))
7777
TriggerClientEvent('pma-voice:setTalkingOnCall', player, source, talking)
7878
end
7979
end
8080
else
81-
debug.log(('[phone] %s tried to talk in call %s, but it doesnt exist.'):format(source, plyVoice.call))
81+
logger.info(('[phone] %s tried to talk in call %s, but it doesnt exist.'):format(source, plyVoice.call))
8282
end
8383
end
8484
RegisterNetEvent('pma-voice:setTalkingOnCall', setTalkingOnCall)

server/module/radio.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---@param source number the player to remove
33
---@param radioChannel number the current channel to remove them from
44
function removePlayerFromRadio(source, radioChannel)
5-
debug.log(('[radio] Removed %s from radio %s'):format(source, radioChannel))
5+
logger.info(('[radio] Removed %s from radio %s'):format(source, radioChannel))
66
radioData[radioChannel] = radioData[radioChannel] or {}
77
for player, _ in pairs(radioData[radioChannel]) do
88
TriggerClientEvent('pma-voice:removePlayerFromRadio', player, source)
@@ -16,7 +16,7 @@ end
1616
---@param source number the player to add to the channel
1717
---@param radioChannel number the channel to set them to
1818
function addPlayerToRadio(source, radioChannel)
19-
debug.log(('[radio] Added %s to radio %s'):format(source, radioChannel))
19+
logger.info(('[radio] Added %s to radio %s'):format(source, radioChannel))
2020

2121
-- check if the channel exists, if it does set the varaible to it
2222
-- if not create it (basically if not radiodata make radiodata)
@@ -69,11 +69,11 @@ function setTalkingOnRadio(talking)
6969
local plyVoice = voiceData[source]
7070
local radioTbl = radioData[plyVoice.radio]
7171
if radioTbl then
72-
debug.log(('[radio] Set %s to talking: %s on radio %s'):format(source, talking, plyVoice.radio))
72+
logger.info(('[radio] Set %s to talking: %s on radio %s'):format(source, talking, plyVoice.radio))
7373
for player, _ in pairs(radioTbl) do
7474
if player ~= source then
7575
TriggerClientEvent('pma-voice:setTalkingOnRadio', player, source, talking)
76-
debug.verbose(('[radio] Sync %s to let them know %s is %s'):format(player, source, talking and 'talking' or 'not talking'))
76+
logger.verbose(('[radio] Sync %s to let them know %s is %s'):format(player, source, talking and 'talking' or 'not talking'))
7777
end
7878
end
7979
end

shared.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ else
1515
}
1616
end
1717

18-
debug = {
19-
['log'] = function(message)
18+
logger = {
19+
['log'] = function(message, ...)
20+
print((message):format(...))
21+
end,
22+
['info'] = function(message)
2023
if GetConvarInt('voice_debugMode', 0) >= 1 then
21-
print(('%s'):format(message))
24+
print(('[info] %s'):format(message))
2225
end
2326
end,
2427
['verbose'] = function(message)

0 commit comments

Comments
 (0)