diff --git a/client/main.lua b/client/main.lua index 9a471f4..435e54d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -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 @@ -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 @@ -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) @@ -221,7 +221,7 @@ Citizen.CreateThread(function() }) end end - Wait(50) + Wait(100) end end) @@ -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) \ No newline at end of file diff --git a/client/module/phone.lua b/client/module/phone.lua index 5f72f44..2f09262 100644 --- a/client/module/phone.lua +++ b/client/module/phone.lua @@ -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) diff --git a/client/module/radio.lua b/client/module/radio.lua index 4f66e22..bcf090b 100644 --- a/client/module/radio.lua +++ b/client/module/radio.lua @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/server/module/phone.lua b/server/module/phone.lua index c5294a2..25b31a4 100644 --- a/server/module/phone.lua +++ b/server/module/phone.lua @@ -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 @@ -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 {} @@ -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) \ No newline at end of file diff --git a/server/module/radio.lua b/server/module/radio.lua index 2a4a8f1..e32b545 100644 --- a/server/module/radio.lua +++ b/server/module/radio.lua @@ -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) @@ -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) @@ -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 diff --git a/shared.lua b/shared.lua index b1c4b1f..0096062 100644 --- a/shared.lua +++ b/shared.lua @@ -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)