Skip to content
Open
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
16 changes: 14 additions & 2 deletions modinfo.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "battle royale/大逃杀"
name = ChooseTranslationTable({"Battle Royale", zh = "大逃杀"})
description = [[
修改自mod制作者 月 的毒圈mod
已取得原作者允许]]
Expand Down Expand Up @@ -30,4 +30,16 @@ server_filter_tags = {


-- mod设置选项
configuration_options = {}
configuration_options = {
{
name = "whitelisted",
label = ChooseTranslationTable({"Whitelist", zh = "白名单"}),
hover = ChooseTranslationTable({"Use a whitelist, needs to be added manually.", zh = "启用白名单(需要手动添加)"}),
options =
{
{description = ChooseTranslationTable({"Yes", zh = "是"}), data = true},
{description = ChooseTranslationTable({"No", zh = "否"}), data = false},
},
default = true,
},
}
151 changes: 71 additions & 80 deletions modmain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,9 @@ GLOBAL.GetGameModeProperty = function(setting, ...)
if setting == "lobbywaitforallplayers" then
return true
end
return _GetGameModeProperty(gamemode, ...)
return _GetGameModeProperty(setting, ...)
end

local TheNet_idx = getmetatable(TheNet).__index
if TheNet_idx then
local old_GetClientTable = TheNet_idx.GetClientTable
TheNet_idx.GetClientTable = function(self)
local data = old_GetClientTable(self)
for k, client in ipairs(data) do
if client --[[and client.performance == nil]] then
client.name = STRINGS.NAMES[string.upper(client.prefab)] or "未知人物"
client.equip = {}
end
end
return data
end
local old_GetClientTableForUser = TheNet_idx.GetClientTableForUser
TheNet_idx.GetClientTableForUser = function(self, userid)
local client = old_GetClientTableForUser(self, userid)
if client then
client.name = STRINGS.NAMES[string.upper(client.prefab)] or "未知人物"
client.equip = {}
end
return client
end
end


PrefabFiles = {"poison_miasma_cloud_fx"}
Assets = {
Asset("SHADER", "shaders/ui_round.ksh"),
Expand Down Expand Up @@ -65,6 +40,9 @@ AddPrefabPostInit("world", function(inst)
if not inst.ismastersim then
return
end
if GetModConfigData("whitelisted") then
inst:AddComponent("whitelisted")
end
end)
AddPrefabPostInit("forest_network", function(inst)
inst:AddComponent("worldcharacterselectlobby")
Expand Down Expand Up @@ -161,7 +139,7 @@ if TheNet:GetServerIsClientHosted() or TheNet:GetIsClient() then
end

-- 重新设置安全区了 手动更新一下
TheWorld:ListenForEvent("onminimapshrink", function()
TheWorld:ListenForEvent("onminimapshrink", function()
self:setBig()
self:setSmall()
end)
Expand All @@ -172,63 +150,76 @@ local Grid = require "widgets/grid"
local Widget = require "widgets/widget"

AddClassPostConstruct( "widgets/waitingforplayers", function(self)
-- Dynamically scales the player portraits in the waiting lobby to fit the number of connected players.
self.UpdatePlayerListing = function()
local screen_width = 900--520--560--639.32--750--812 -- This was found through testing
local screen_height = 450
local widget_scalar = 0.43
local widget_width = widget_scalar*324--125
local widget_height = widget_scalar*511--250
local offset_width = 110.68--250--125
local offset_height = 30 + 20
local col = 0
local row = 1
local scalar = 3
local scalar_percent_increment = 0.005

local player_count = TheNet:GetDefaultMaxPlayers()
while col*row < player_count do
col = col + 1
-- Find the next scalar
local next_scalar = scalar
local count = 0
while (col * (widget_width + offset_width) - offset_width) * next_scalar > screen_width or ((widget_height + offset_height) * row - offset_height)*next_scalar > screen_height do
count = count + 1
next_scalar = scalar*(1 - scalar_percent_increment*count)
end
scalar = next_scalar
-- If the current player badge is smaller than the size it would be if another row is added then add another row instead of a column.
if ((widget_height + offset_height) * (row + 1) - offset_height)*scalar < screen_height then
row = row + 1
col = col - 1
scalar = 2 / row
end
end
-- Remove any leftover column space from recent new rows.
while (col - 1)*row >= player_count do
col = col - 1
end
-- Scale each widget based on number of max players
for i,widget in pairs(self.player_listing) do
if i <= player_count then
widget:SetScale(scalar)
widget:Show()
else
widget:Hide()
end
end
-- Clear and Update grid based on amount of players
local old_grid = self.list_root
self.list_root = self.proot:AddChild(Grid())
self.list_root:FillGrid(col, (widget_width + offset_width) * scalar, (widget_height + offset_height) * scalar, self.player_listing)
self.list_root:SetPosition(-(widget_width + offset_width) * scalar * (col - 1)/2, (widget_height + offset_height)*scalar*(row - 1)/2 + 20)
old_grid:Kill()
end
self:UpdatePlayerListing()
-- Dynamically scales the player portraits in the waiting lobby to fit the number of connected players.
self.UpdatePlayerListing = function()
local screen_width = 900--520--560--639.32--750--812 -- This was found through testing
local screen_height = 450
local widget_scalar = 0.43
local widget_width = widget_scalar*324--125
local widget_height = widget_scalar*511--250
local offset_width = 110.68--250--125
local offset_height = 30 + 20
local col = 0
local row = 1
local scalar = 3
local scalar_percent_increment = 0.005

local player_count = TheNet:GetDefaultMaxPlayers()
while col*row < player_count do
col = col + 1
-- Find the next scalar
local next_scalar = scalar
local count = 0
while (col * (widget_width + offset_width) - offset_width) * next_scalar > screen_width or ((widget_height + offset_height) * row - offset_height)*next_scalar > screen_height do
count = count + 1
next_scalar = scalar*(1 - scalar_percent_increment*count)
end
scalar = next_scalar
-- If the current player badge is smaller than the size it would be if another row is added then add another row instead of a column.
if ((widget_height + offset_height) * (row + 1) - offset_height)*scalar < screen_height then
row = row + 1
col = col - 1
scalar = 2 / row
end
end
-- Remove any leftover column space from recent new rows.
while (col - 1)*row >= player_count do
col = col - 1
end
-- Scale each widget based on number of max players
for i,widget in pairs(self.player_listing) do
if i <= player_count then
widget:SetScale(scalar)
widget:Show()
else
widget:Hide()
end
end
-- Clear and Update grid based on amount of players
local old_grid = self.list_root
self.list_root = self.proot:AddChild(Grid())
self.list_root:FillGrid(col, (widget_width + offset_width) * scalar, (widget_height + offset_height) * scalar, self.player_listing)
self.list_root:SetPosition(-(widget_width + offset_width) * scalar * (col - 1)/2, (widget_height + offset_height)*scalar*(row - 1)/2 + 20)
old_grid:Kill()
end
self:UpdatePlayerListing()
end)



local _modimport = modimport
---@param path string
function modimport(path)
if not path:find(".lua") then
return _modimport(path .. ".lua")
else
return _modimport(path)
end
end

modimport("postinit/screens/playerstatusscreen")
modimport("postinit/widgets/playeravatarpopup")
modimport("postinit/networkproxy")
modimport("postinit/chathistory")

return
10 changes: 10 additions & 0 deletions postinit/chathistory.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GLOBAL.setfenv(1, GLOBAL)

local _GenerateChatMessage = ChatHistory.GenerateChatMessage
function ChatHistory:GenerateChatMessage(type, sender_userid, sender_netid, sender_name, message, colour, icondata, whisper, localonly, text_filter_context)
if sender_userid then -- sender_userid can be nil
sender_name = TheNet:GetClientTableForUser(sender_userid).name
end

return _GenerateChatMessage(self, type, sender_userid, sender_netid, sender_name, message, WHITE, icondata, whisper, localonly, text_filter_context)
end
48 changes: 48 additions & 0 deletions postinit/networkproxy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
GLOBAL.setfenv(1, GLOBAL)

-- ziwbi: 查看玩家主頁的接口
function NetworkProxy.ViewNetProfile()
-- do nothing
end

-- ziwbi: 加入服务器宣告,改为匿名,统一颜色
function Networking_JoinAnnouncement(name, colour)
Networking_Announcement(string.format(STRINGS.UI.NOTIFICATION.JOINEDGAME, STRINGS.UI.SERVERADMINSCREEN.UNKNOWN_USER_NAME), nil, "join_game")
end

-- 离开,改动同上
function Networking_LeaveAnnouncement(name, colour)
Networking_Announcement(string.format(STRINGS.UI.NOTIFICATION.LEFTGAME, STRINGS.UI.SERVERADMINSCREEN.UNKNOWN_USER_NAME), nil, "leave_game")
end

local function anonymise_data(client)
if not client then
return
end

local base_skin = client.base_skin -- NetworkProxy
local display_name = STRINGS.SKIN_NAMES[base_skin]
if base_skin and not base_skin:find("_none") then -- 有 _none 代表无皮肤,角色名等于皮肤名
display_name = display_name .. " " .. (STRINGS.NAMES[string.upper(client.prefab)] or STRINGS.CHARACTER_NAMES.unknown) -- 加上角色名
end

client._actual_name = client.name
client.name = display_name
client.equip = {}
end

local _GetClientTable = NetworkProxy.GetClientTable
function NetworkProxy:GetClientTable()
local data = _GetClientTable(self)
for k, client in ipairs(data) do
anonymise_data(client)
end
return data
end

local _GetClientTableForUser = NetworkProxy.GetClientTableForUser
function NetworkProxy:GetClientTableForUser(userid)
local client = _GetClientTableForUser(self, userid)
anonymise_data(client)
return client
end
18 changes: 18 additions & 0 deletions postinit/screens/playerstatusscreen.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
GLOBAL.setfenv(1, GLOBAL)

local PlayerStatusScreen = require("screens/playerstatusscreen")

-- 游戏内看到的玩家列表
local _DoInit = PlayerStatusScreen.DoInit
function PlayerStatusScreen:DoInit(...)
_DoInit(self, ...)

local _UpdatePlayerListing = self.scroll_list.updatefn
self.scroll_list.updatefn = function(playerListing, client, i)
_UpdatePlayerListing(playerListing, client, i)
if not TheNet:GetIsServerAdmin() then -- 非管理员
playerListing.adminBadge:Hide() -- 隐藏管理员图标
end
end
self.scroll_list:RefreshView(false) -- 刷新图标
end
9 changes: 9 additions & 0 deletions postinit/widgets/playeravatarpopup.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
GLOBAL.setfenv(1, GLOBAL)

local PlayerAvatarPopup = require("widgets/playeravatarpopup")

local _Layout = PlayerAvatarPopup.Layout
-- 审视自我界面,第二个参数为真时,会显示玩家Steam主页按钮,反之隐藏
function PlayerAvatarPopup:Layout(data, show_net_profile)
return _Layout(self, data, TheNet:GetIsServerAdmin()) -- show Steam profile only for admins
end
50 changes: 50 additions & 0 deletions scripts/components/whitelisted.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--------------------------------------------------------------------------
--[[ Dependencies ]]
--------------------------------------------------------------------------

require("whitelist")

--------------------------------------------------------------------------
--[[ WhiteListed class definition ]]
--------------------------------------------------------------------------
return Class(function(self, inst)

assert(TheWorld.ismastersim, "WhiteListed should not exist on client")

--------------------------------------------------------------------------
--[[ Public Member Variables ]]
--------------------------------------------------------------------------

self.inst = inst

--------------------------------------------------------------------------
--[[ Private member functions ]]
--------------------------------------------------------------------------

local function OnPlayerJoined(player)
if IsPlayerWhitelisted(player) then
return
end

local user_table = TheNet:GetClientTableForUser(player.userid)
c_announce(string.format("%s(%s) 不在白名单上, 踢出", user_table._actual_name, user_table.userid))
print("角色:", STRINGS.NAMES[string.upper(user_table.prefab)],"Steam用户名:", user_table._actual_name,
"Steam ID:", user_table.netid, "KUID:", user_table.userid)
TheNet:Ban(player.userid)
end

--------------------------------------------------------------------------
--[[ Initialization ]]
--------------------------------------------------------------------------
for _, player in pairs(AllPlayers) do
OnPlayerJoined(player)
end

local mt = {
__newindex = function(t, k, v)
OnPlayerJoined(v) -- __newindex 元方法会在列表添加元素时调用
end
}

setmetatable(AllPlayers, mt)
end)
8 changes: 8 additions & 0 deletions scripts/whitelist.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local white_list = {
KU_zPOwY2DT = true, -- ziwbi
}

-- 放到函数里避免直接修改
function IsPlayerWhitelisted(player)
return white_list[player.userid]
end