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

Better Mumble Channel Mapping #418

Merged
merged 1 commit into from
Jun 2, 2023
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
8 changes: 4 additions & 4 deletions client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ function handleInitialState()
MumbleSetTalkerProximity(voiceModeData[1] + 0.0)
MumbleClearVoiceTarget(voiceTarget)
MumbleSetVoiceTarget(voiceTarget)
MumbleSetVoiceChannel(playerServerId)
MumbleSetVoiceChannel(LocalPlayer.state.assignedChannel)

while MumbleGetVoiceChannelFromServerId(playerServerId) ~= playerServerId do
while MumbleGetVoiceChannelFromServerId(playerServerId) ~= LocalPlayer.state.assignedChannel do
Wait(250)
MumbleSetVoiceChannel(playerServerId)
MumbleSetVoiceChannel(LocalPlayer.state.assignedChannel)
end

MumbleAddVoiceTargetChannel(voiceTarget, playerServerId)
MumbleAddVoiceTargetChannel(voiceTarget, LocalPlayer.state.assignedChannel)

addNearbyPlayers()
end
Expand Down
28 changes: 14 additions & 14 deletions client/init/proximity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function orig_addProximityCheck(ply)
local tgtPed = GetPlayerPed(ply)
local voiceRange = GetConvar('voice_useNativeAudio', 'false') == 'true' and proximity * 3 or proximity
local distance = #(plyCoords - GetEntityCoords(tgtPed))
return distance < voiceRange, distance
return distance < voiceRange, distance
end
local addProximityCheck = orig_addProximityCheck

Expand All @@ -29,14 +29,14 @@ function addNearbyPlayers()
currentTargets = {}
MumbleClearVoiceTargetChannels(voiceTarget)
if LocalPlayer.state.disableProximity then return end
MumbleAddVoiceChannelListen(playerServerId)
MumbleAddVoiceTargetChannel(voiceTarget, playerServerId)
MumbleAddVoiceChannelListen(LocalPlayer.state.assignedChannel)
MumbleAddVoiceTargetChannel(voiceTarget, LocalPlayer.state.assignedChannel)

for source, _ in pairs(callData) do
if source ~= playerServerId then
MumbleAddVoiceTargetChannel(voiceTarget, source)
for source, _ in pairs(callData) do
if source ~= playerServerId then
MumbleAddVoiceTargetChannel(voiceTarget, MumbleGetVoiceChannelFromServerId(source))
end
end
end


local players = GetActivePlayers()
Expand All @@ -48,11 +48,11 @@ function addNearbyPlayers()
-- if distance then
-- currentTargets[serverId] = distance
-- else
-- -- backwards compat, maybe remove in v7
-- -- backwards compat, maybe remove in v7
-- currentTargets[serverId] = 15.0
-- end
-- logger.verbose('Added %s as a voice target', serverId)
MumbleAddVoiceTargetChannel(voiceTarget, serverId)
MumbleAddVoiceTargetChannel(voiceTarget, MumbleGetVoiceChannelFromServerId(serverId))
end
end
end
Expand All @@ -67,7 +67,7 @@ function setSpectatorMode(enabled)
local serverId = GetPlayerServerId(ply)
if serverId == playerServerId then goto skip_loop end
logger.verbose("Adding %s to listen table", serverId)
MumbleAddVoiceChannelListen(serverId)
MumbleAddVoiceChannelListen(MumbleGetVoiceChannelFromServerId(serverId))
::skip_loop::
end
else
Expand All @@ -76,22 +76,22 @@ function setSpectatorMode(enabled)
local serverId = GetPlayerServerId(ply)
if serverId == playerServerId then goto skip_loop end
logger.verbose("Removing %s from listen table", serverId)
MumbleRemoveVoiceChannelListen(serverId)
MumbleRemoveVoiceChannelListen(MumbleGetVoiceChannelFromServerId(serverId))
::skip_loop::
end
end
end

RegisterNetEvent('onPlayerJoining', function(serverId)
if isListenerEnabled then
MumbleAddVoiceChannelListen(serverId)
MumbleAddVoiceChannelListen(MumbleGetVoiceChannelFromServerId(serverId))
logger.verbose("Adding %s to listen table", serverId)
end
end)

RegisterNetEvent('onPlayerDropped', function(serverId)
if isListenerEnabled then
MumbleRemoveVoiceChannelListen(serverId)
MumbleRemoveVoiceChannelListen(MumbleGetVoiceChannelFromServerId(serverId))
logger.verbose("Removing %s from listen table", serverId)
end
end)
Expand All @@ -116,7 +116,7 @@ CreateThread(function()
while not MumbleIsConnected() do
Wait(100)
end
-- Leave the check here as we don't want to do any of this logic
-- Leave the check here as we don't want to do any of this logic
if GetConvarInt('voice_enableUi', 1) == 1 then
local curTalkingStatus = MumbleIsPlayerTalking(PlayerId()) == 1
if lastRadioStatus ~= radioPressed or lastTalkingStatus ~= curTalkingStatus then
Expand Down
35 changes: 33 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ voiceData = {}
radioData = {}
callData = {}

local maxChannels = GetConvarInt('sv_maxclients', 32) + 10
local mappedChannels = {}
function firstFreeChannel()
local newMax = GetConvarInt('sv_maxclients', 32) + 10
if newMax > maxChannels then maxChannels = newMax end

for i = 1, maxChannels do
if not mappedChannels[i] then
return i
end
end

return 0
end

function defaultTable(source)
handleStateBagInitilization(source)
return {
Expand All @@ -14,7 +29,7 @@ end

function handleStateBagInitilization(source)
local plyState = Player(source).state
if not plyState.pmaVoiceInit then
if not plyState.pmaVoiceInit then
plyState:set('radio', GetConvarInt('voice_defaultRadioVolume', 30), true)
plyState:set('call', GetConvarInt('voice_defaultCallVolume', 60), true)
plyState:set('submix', nil, true)
Expand All @@ -25,6 +40,15 @@ function handleStateBagInitilization(source)
-- We want to save voice inits because we'll automatically reinitalize calls and channels
plyState:set('pmaVoiceInit', true, false)
end

local assignedChannel = firstFreeChannel()
plyState:set('assignedChannel', assignedChannel, true)
if assignedChannel ~= 0 then
mappedChannels[assignedChannel] = source
logger.verbose('[reuse] Assigned %s to channel %s', source, assignedChannel)
else
logger.error('[reuse] Failed to find a free channel for %s', source)
end
end

CreateThread(function()
Expand Down Expand Up @@ -55,7 +79,7 @@ CreateThread(function()
logger.info('No convars detected for voice mode, defaulting to \'setr voice_useNativeAudio true\' and \'setr voice_useSendingRangeOnly true\'')
end
elseif sendingRangeOnly == 'false' then
logger.warn('It\'s recommended to have \'voice_useSendingRangeOnly\' set to true you can do that with \'setr voice_useSendingRangeOnly true\', this prevents players who directly join the mumble server from broadcasting to players.')
logger.warn("It's recommended to have 'voice_useSendingRangeOnly' set to true you can do that with 'setr voice_useSendingRangeOnly true', this prevents players who directly join the mumble server from broadcasting to players.")
end

local radioVolume = GetConvarInt("voice_defaultRadioVolume", 30)
Expand Down Expand Up @@ -83,6 +107,8 @@ end)

AddEventHandler("playerDropped", function()
local source = source
local mappedChannel = Player(source).state.assignedChannel

if voiceData[source] then
local plyData = voiceData[source]

Expand All @@ -96,6 +122,11 @@ AddEventHandler("playerDropped", function()

voiceData[source] = nil
end

if mappedChannel then
mappedChannels[mappedChannel] = nil
logger.verbose('[reuse] Unassigned %s from channel %s', source, mappedChannel)
end
end)

if GetConvarInt('voice_externalDisallowJoin', 0) == 1 then
Expand Down