Update whosniffer to use named channels

This commit is contained in:
2024-11-29 19:23:26 +01:00
parent 4e0cbbb4ac
commit 73b6e7ca09
3 changed files with 20 additions and 40 deletions

View File

@@ -4,7 +4,11 @@
---@type sender string
function(event, msg, sender, ...)
local channelId = select(6, ...)
if channelId ~= aura_env.channelId then
local channelName = aura_env.GetChannelName(channelId)
if not channelName then
return
end
if channelName ~= aura_env.config.channel then
return
end
@@ -13,7 +17,7 @@ function(event, msg, sender, ...)
local msg = aura_env.MakeNotifyMessage(player)
local message = {
channel = "CHANNEL",
data = channelId,
data = aura_env.config.channel,
message = msg
}
table.insert(WeakAurasSaved.Cyka.MessageQueue, message)

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,6 @@ if not WeakAurasSaved.Cyka.WhoSniffer then
end
aura_env.ignored = {"Maritza", "Goodbones"}
local channelId = nil
---@class aura_env
---@field raceMap table<string, string>
@@ -262,13 +261,9 @@ local NotifyAll = function(msg)
end
---@param msg string
local NotifyChannel = function(msg)
if not channelId then
print("cannot notify channel, channelId is nil")
return
end
local message = {
channel = "CHANNEL",
data = channelId,
data = aura_env.channel,
message = msg
}
table.insert(WeakAurasSaved.Cyka.MessageQueue, message)
@@ -310,37 +305,6 @@ aura_env.NotifyGone = function(player)
aura_env.NotifyChannelGone(player)
end
-- CHANNEL fuckery
local channel = aura_env.config.channel or "foobar"
local password = aura_env.config.channelPassword
local function FindOrJoinChannel(channelName, password)
local function GetChannelId(channelName)
local channels = {GetChannelList()}
for i = 1, #channels, 2 do
local id = channels[i]
local name = channels[i + 1]
if name == channelName then
return id
end
end
end
channelId = GetChannelId(channelName)
if not channelId then
print(string.format("channel %s not found, joining", channelName))
if password then
JoinPermanentChannel(channelName, password)
else
JoinPermanentChannel(channelName)
end
end
channelId = GetChannelId(channelName)
return channelId
end
aura_env.channelId = FindOrJoinChannel(channel, password)
print(string.format("channel %s resolved to id %d", channel, channelId))
---@param player Player
---@return nil
aura_env.NotifyChannel = function(player)
@@ -354,4 +318,16 @@ aura_env.NotifyChannelGone = function(player)
local msg = string.format("%s of class %s and guild %s left %s", player.name, player.class, player.guild,
player.zone)
NotifyChannel(msg)
end
aura_env.GetChannelName= function(channelId)
local channels = {GetChannelList()}
for i = 1, #channels, 2 do
local id = channels[i]
local name = channels[i + 1]
if id == channelId then
return name
end
end
return nil
end