通过给服务器添加 tag 标记,能够向外界传达部分信息
不清楚在此之前有没有其它模组作者使用过这类方法
tag,例如 LEGION@KU_ABCD1234#SteamID&0609-1323Klei Lobby API 扫描,检测这些特殊 tagmodinfo.lua 的 server_filter_tags 加上模组名字或特征,例如 棱镜v.7.6.5List 时检测房间的 tag 列表,锁定有相应 tag 的房间,并解析这些特殊 tagv 字段不属于当前游戏版本的房间Read 房间的详细信息,检查 mods_info 是否包含指定的模组connected 字段等于 0 的房间tag 可以被任意模组修改,不能作为唯一信任来源,建议通过多重检测验真Read 房间详情,检测特殊 tag 的内容与房间内的玩家是否对应tag 的一段时间后删除建议收集的数据
__addr IPhost 主机Klei IDname 房间名session 唯一ID,用来辨别是否为相同存档和去重tags 内容players 连接的玩家列表 包含 netidGLOBAL.setmetatable(env, {
__index = function(t, k)
return GLOBAL.rawget(GLOBAL, k)
end
})
-- 主机环境
if not TheNet:GetIsServer() then return end
-- 注意
-- 服务器重载后 会清理掉所有自定义的tag
-- 需要通过其他手段持久化保存tag
CustomServerTags = CustomServerTags or {} -- 存放自定义tag
local tag_map = {} -- 已有的自定义tag 防止重复
for _, tag in ipairs(CustomServerTags) do
tag_map[tag] = true
end
-- hook构建tag的函数 加上自定义的tag
if GLOBAL.BuildTagsStringCommon and not _CustomServerTagsHooked then
_CustomServerTagsHooked = true
local _BuildTagsStringCommon = GLOBAL.BuildTagsStringCommon
GLOBAL.BuildTagsStringCommon = function(tags_table, ...)
if tags_table then
for _, tag in ipairs(CustomServerTags) do
table.insert(tags_table, tag)
end
end
return _BuildTagsStringCommon(tags_table, ...)
end
end
-- 刷新房间的tag状态
local function RefreshServerTags()
UpdateServerTagsString()
end
-- 添加tag
AddServerTag = function(tag, no_refresh)
if type(tag) ~= "string" or tag == "" then
return
end
if tag_map[tag] then
return
end
tag_map[tag] = true
table.insert(CustomServerTags, tag)
if not no_refresh then
RefreshServerTags()
end
end
-- 删除tag
RemoveServerTag = function(tag)
if not tag_map[tag] then
return
end
tag_map[tag] = nil
for i = #CustomServerTags, 1, -1 do
if CustomServerTags[i] == tag then
table.remove(CustomServerTags, i)
end
end
RefreshServerTags()
end
-- 批量添加tag
AddServerTags = function(tags)
if type(tags) ~= "table" then
return
end
for _, tag in ipairs(tags) do
AddServerTag(tag, true)
end
RefreshServerTags()
end
-- 清除所有自定义tag
ClearServerTags = function()
CustomServerTags = {}
tag_map = {}
RefreshServerTags()
end
-- 查看当前tag
PrintServerTags = function()
print("====== Custom Server Tags ======")
for i, tag in ipairs(CustomServerTags) do
print(i, tag)
end
print("================================")
end