Skip to content

Commit

Permalink
feat(client/main): add more mumble debugging
Browse files Browse the repository at this point in the history
- move debug -> logger (we don't want to overwrite Lua native functions)
- add connection/disconnection logs
  • Loading branch information
AvarianKnight committed Apr 9, 2021
1 parent 2c08629 commit 7bf7eba
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 29 deletions.
18 changes: 13 additions & 5 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ local submixFunctions = {
---@param enabled boolean if the players voice is getting activated or deactivated
---@param submixType string what submix to use for the players voice, currently only supports 'radio'
function toggleVoice(plySource, enabled, submixType)
debug.verbose(('[main] Updating %s to talking: %s with submix %s'):format(plySource, enabled, submixType))
logger.verbose(('[main] Updating %s to talking: %s with submix %s'):format(plySource, enabled, submixType))
MumbleSetVolumeOverrideByServerId(plySource, enabled and volume or -1.0)
if GetConvarInt('voice_enableRadioSubmix', 0) == 1 then
if enabled and submixType then
Expand All @@ -85,11 +85,11 @@ function playerTargets(...)
for id, _ in pairs(targets[i]) do
-- we don't want to log ourself, or listen to ourself
if addedPlayers[id] and id ~= playerServerId then
debug.verbose(('[main] %s is already target don\'t re-add'):format(id))
logger.verbose(('[main] %s is already target don\'t re-add'):format(id))
goto skip_loop
end
if not addedPlayers[id] then
debug.verbose(('[main] Adding %s as a voice target'):format(id))
logger.verbose(('[main] Adding %s as a voice target'):format(id))
addedPlayers[id] = true
MumbleAddVoiceTargetPlayerByServerId(1, id)
end
Expand Down Expand Up @@ -185,7 +185,7 @@ end
local function updateZone(forced)
local newGrid = getGridZone()
if newGrid ~= currentGrid or forced then
debug.log(('Updating zone from %s to %s and adding nearby grids.'):format(currentGrid, newGrid))
logger.info(('Updating zone from %s to %s and adding nearby grids.'):format(currentGrid, newGrid))
currentGrid = newGrid
MumbleClearVoiceTargetChannels(1)
NetworkSetVoiceChannel(currentGrid)
Expand Down Expand Up @@ -221,7 +221,7 @@ Citizen.CreateThread(function()
})
end
end
Wait(50)
Wait(100)
end
end)

Expand Down Expand Up @@ -308,3 +308,11 @@ end)
RegisterCommand("grid", function()
print(('Players current grid is %s'):format(currentGrid))
end)

AddEventHandler('mumbleConnected', function(address, shouldReconnect)
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)
end)

AddEventHandler('mumbleDisconnected', function(address)
logger.log('Disconnected from mumble server with address of %s', GetConvarInt('voice_hideEndpoints', 1) == 1 and 'HIDDEN' or address)
end)
6 changes: 4 additions & 2 deletions client/module/phone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ RegisterNetEvent('pma-voice:removePlayerFromCall', function(plySource)
else
callData[plySource] = nil
toggleVoice(plySource, false, 'phone')
MumbleClearVoiceTargetPlayers(1)
playerTargets(radioPressed and radioData or {}, callData)
if NetworkIsPlayerTalking(PlayerId()) then
MumbleClearVoiceTargetPlayers(1)
playerTargets(radioPressed and radioData or {}, callData)
end
end
end)

Expand Down
20 changes: 10 additions & 10 deletions client/module/radio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---@param radioTable table the table of the current players on the radio
function syncRadioData(radioTable)
radioData = radioTable
debug.log(('[radio] Syncing radio table.'))
logger.info(('[radio] Syncing radio table.'))
if GetConvarInt('voice_debugMode', 0) >= 4 then
print('-------- RADIO TABLE --------')
tPrint(radioData)
Expand Down Expand Up @@ -34,10 +34,10 @@ RegisterNetEvent('pma-voice:setTalkingOnRadio', setTalkingOnRadio)
function addPlayerToRadio(plySource)
radioData[plySource] = false
if radioPressed then
debug.log(('[radio] %s joined radio %s while we were talking, adding them to targets'):format(plySource, radioChannel))
logger.info(('[radio] %s joined radio %s while we were talking, adding them to targets'):format(plySource, radioChannel))
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
else
debug.log(('[radio] %s joined radio %s'):format(plySource, radioChannel))
logger.info(('[radio] %s joined radio %s'):format(plySource, radioChannel))
end
end
RegisterNetEvent('pma-voice:addPlayerToRadio', addPlayerToRadio)
Expand All @@ -47,24 +47,23 @@ RegisterNetEvent('pma-voice:addPlayerToRadio', addPlayerToRadio)
---@param plySource number the players server id to remove from the radio.
function removePlayerFromRadio(plySource)
if plySource == playerServerId then
debug.log(('[radio] Left radio %s, cleaning up.'):format(radioChannel))
logger.info(('[radio] Left radio %s, cleaning up.'):format(radioChannel))
for tgt, enabled in pairs(radioData) do
if tgt ~= playerServerId then
toggleVoice(tgt, false)
end
end
radioData = {}
playerTargets({}, NetworkIsPlayerTalking(PlayerId()) and callData or {})
playerTargets(NetworkIsPlayerTalking(PlayerId()) and callData or {})
else
radioData[plySource] = nil
toggleVoice(plySource, false)
if radioPressed then
debug.log(('[radio] %s left radio %s while we were talking, updating targets.'):format(plySource, radioChannel))
logger.info(('[radio] %s left radio %s while we were talking, updating targets.'):format(plySource, radioChannel))
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
else
debug.log(('[radio] %s has left radio %s'):format(plySource, radioChannel))
logger.info(('[radio] %s has left radio %s'):format(plySource, radioChannel))
end

end
end
RegisterNetEvent('pma-voice:removePlayerFromRadio', removePlayerFromRadio)
Expand Down Expand Up @@ -126,7 +125,7 @@ RegisterCommand('+radiotalk', function()

if not radioPressed and radioEnabled then
if radioChannel > 0 then
debug.log(('[radio] Start broadcasting, update targets and notify server.'))
logger.info(('[radio] Start broadcasting, update targets and notify server.'))
playerTargets(radioData, NetworkIsPlayerTalking(PlayerId()) and callData or {})
TriggerServerEvent('pma-voice:setTalkingOnRadio', true)
radioPressed = true
Expand All @@ -148,6 +147,7 @@ RegisterCommand('-radiotalk', function()
if radioChannel > 0 or radioEnabled then
radioPressed = false
MumbleClearVoiceTargetPlayers(1)
playerTargets(NetworkIsPlayerTalking(PlayerId()) and callData or {})
TriggerEvent("pma-voice:radioActive", false)
playMicClicks(false)
TriggerServerEvent('pma-voice:setTalkingOnRadio', false)
Expand All @@ -160,7 +160,7 @@ RegisterKeyMapping('+radiotalk', 'Talk over Radio', 'keyboard', GetConvar('voice
---@param _radioChannel number the radio channel to set the player to.
function syncRadio(_radioChannel)
if GetConvarInt('voice_enableRadios', 1) ~= 1 then return end
debug.log(('[radio] radio set serverside update to radio %s'):format(radioChannel))
logger.info(('[radio] radio set serverside update to radio %s'):format(radioChannel))
radioChannel = _radioChannel
end
RegisterNetEvent('pma-voice:clSetPlayerRadio', syncRadio)
10 changes: 5 additions & 5 deletions server/module/phone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---@param source number the player to remove from the call
---@param callChannel number the call channel to remove them from
function removePlayerFromCall(source, callChannel)
debug.log(('[phone] Removed %s from call %s'):format(source, callChannel))
logger.info(('[phone] Removed %s from call %s'):format(source, callChannel))

callData[callChannel] = callData[callChannel] or {}
for player, _ in pairs(callData[callChannel]) do
Expand All @@ -17,7 +17,7 @@ end
---@param source number the player to add to the call
---@param callChannel number the call channel to add them to
function addPlayerToCall(source, callChannel)
debug.log(('[phone] Added %s to call %s'):format(source, callChannel))
logger.info(('[phone] Added %s to call %s'):format(source, callChannel))
-- check if the channel exists, if it does set the varaible to it
-- if not create it (basically if not callData make callData)
callData[callChannel] = callData[callChannel] or {}
Expand Down Expand Up @@ -70,15 +70,15 @@ function setTalkingOnCall(talking)
local plyVoice = voiceData[source]
local callTbl = callData[plyVoice.call]
if callTbl then
debug.log(('[phone] %s started talking in call %s'):format(source, plyVoice.call))
logger.info(('[phone] %s started talking in call %s'):format(source, plyVoice.call))
for player, _ in pairs(callTbl) do
if player ~= source then
debug.verbose(('[call] Sending event to %s to tell them that %s is talking'):format(player, source))
logger.verbose(('[call] Sending event to %s to tell them that %s is talking'):format(player, source))
TriggerClientEvent('pma-voice:setTalkingOnCall', player, source, talking)
end
end
else
debug.log(('[phone] %s tried to talk in call %s, but it doesnt exist.'):format(source, plyVoice.call))
logger.info(('[phone] %s tried to talk in call %s, but it doesnt exist.'):format(source, plyVoice.call))
end
end
RegisterNetEvent('pma-voice:setTalkingOnCall', setTalkingOnCall)
8 changes: 4 additions & 4 deletions server/module/radio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---@param source number the player to remove
---@param radioChannel number the current channel to remove them from
function removePlayerFromRadio(source, radioChannel)
debug.log(('[radio] Removed %s from radio %s'):format(source, radioChannel))
logger.info(('[radio] Removed %s from radio %s'):format(source, radioChannel))
radioData[radioChannel] = radioData[radioChannel] or {}
for player, _ in pairs(radioData[radioChannel]) do
TriggerClientEvent('pma-voice:removePlayerFromRadio', player, source)
Expand All @@ -16,7 +16,7 @@ end
---@param source number the player to add to the channel
---@param radioChannel number the channel to set them to
function addPlayerToRadio(source, radioChannel)
debug.log(('[radio] Added %s to radio %s'):format(source, radioChannel))
logger.info(('[radio] Added %s to radio %s'):format(source, radioChannel))

-- check if the channel exists, if it does set the varaible to it
-- if not create it (basically if not radiodata make radiodata)
Expand Down Expand Up @@ -69,11 +69,11 @@ function setTalkingOnRadio(talking)
local plyVoice = voiceData[source]
local radioTbl = radioData[plyVoice.radio]
if radioTbl then
debug.log(('[radio] Set %s to talking: %s on radio %s'):format(source, talking, plyVoice.radio))
logger.info(('[radio] Set %s to talking: %s on radio %s'):format(source, talking, plyVoice.radio))
for player, _ in pairs(radioTbl) do
if player ~= source then
TriggerClientEvent('pma-voice:setTalkingOnRadio', player, source, talking)
debug.verbose(('[radio] Sync %s to let them know %s is %s'):format(player, source, talking and 'talking' or 'not talking'))
logger.verbose(('[radio] Sync %s to let them know %s is %s'):format(player, source, talking and 'talking' or 'not talking'))
end
end
end
Expand Down
9 changes: 6 additions & 3 deletions shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ else
}
end

debug = {
['log'] = function(message)
logger = {
['log'] = function(message, ...)
print((message):format(...))
end,
['info'] = function(message)
if GetConvarInt('voice_debugMode', 0) >= 1 then
print(('%s'):format(message))
print(('[info] %s'):format(message))
end
end,
['verbose'] = function(message)
Expand Down

0 comments on commit 7bf7eba

Please sign in to comment.