This commit is contained in:
Applevangelist 2024-11-17 16:22:32 +01:00
parent 112a0b2a8e
commit cea3ab291e

View File

@ -43,7 +43,7 @@ do
-- @field #NET -- @field #NET
NET = { NET = {
ClassName = "NET", ClassName = "NET",
Version = "0.1.3", Version = "0.1.4",
BlockTime = 600, BlockTime = 600,
BlockedPilots = {}, BlockedPilots = {},
BlockedUCIDs = {}, BlockedUCIDs = {},
@ -67,6 +67,9 @@ function NET:New()
self.KnownPilots = {} self.KnownPilots = {}
self:SetBlockMessage() self:SetBlockMessage()
self:SetUnblockMessage() self:SetUnblockMessage()
self.BlockedSides = {}
self.BlockedSides[1] = false
self.BlockedSides[2] = false
-- Start State. -- Start State.
self:SetStartState("Stopped") self:SetStartState("Stopped")
@ -160,11 +163,12 @@ end
-- @param #string PlayerSlot -- @param #string PlayerSlot
-- @return #boolean IsBlocked -- @return #boolean IsBlocked
function NET:IsAnyBlocked(UCID,Name,PlayerID,PlayerSide,PlayerSlot) function NET:IsAnyBlocked(UCID,Name,PlayerID,PlayerSide,PlayerSlot)
self:T({UCID,Name,PlayerID,PlayerSide,PlayerSlot})
local blocked = false local blocked = false
local TNow = timer.getTime() local TNow = timer.getTime()
-- UCID -- UCID
if UCID and self.BlockedUCIDs[UCID] and TNow < self.BlockedUCIDs[UCID] then if UCID and self.BlockedUCIDs[UCID] and TNow < self.BlockedUCIDs[UCID] then
return true blocked = true
end end
-- ID/Name -- ID/Name
if PlayerID and not Name then if PlayerID and not Name then
@ -172,16 +176,18 @@ function NET:IsAnyBlocked(UCID,Name,PlayerID,PlayerSide,PlayerSlot)
end end
-- Name -- Name
if Name and self.BlockedPilots[Name] and TNow < self.BlockedPilots[Name] then if Name and self.BlockedPilots[Name] and TNow < self.BlockedPilots[Name] then
return true blocked = true
end end
-- Side -- Side
if PlayerSide and self.BlockedSides[PlayerSide] and TNow < self.BlockedSides[PlayerSide] then self:T({time = self.BlockedSides[PlayerSide]})
return true if PlayerSide and type(self.BlockedSides[PlayerSide]) == "number" and TNow < self.BlockedSides[PlayerSide] then
blocked = true
end end
-- Slot -- Slot
if PlayerSlot and self.BlockedSlots[PlayerSlot] and TNow < self.BlockedSlots[PlayerSlot] then if PlayerSlot and self.BlockedSlots[PlayerSlot] and TNow < self.BlockedSlots[PlayerSlot] then
return true blocked = true
end end
self:T("IsAnyBlocke: "..tostring(blocked))
return blocked return blocked
end end
@ -200,6 +206,7 @@ function NET:_EventHandler(EventData)
local ucid = self:GetPlayerUCID(nil,name) or "none" local ucid = self:GetPlayerUCID(nil,name) or "none"
local PlayerID = self:GetPlayerIDByName(name) or "none" local PlayerID = self:GetPlayerIDByName(name) or "none"
local PlayerSide, PlayerSlot = self:GetSlot(data.IniUnit) local PlayerSide, PlayerSlot = self:GetSlot(data.IniUnit)
if not PlayerSide then PlayerSide = EventData.IniCoalition end
local TNow = timer.getTime() local TNow = timer.getTime()
self:T(self.lid.."Event for: "..name.." | UCID: "..ucid) self:T(self.lid.."Event for: "..name.." | UCID: "..ucid)
@ -225,6 +232,7 @@ function NET:_EventHandler(EventData)
slot = PlayerSlot, slot = PlayerSlot,
timestamp = TNow, timestamp = TNow,
} }
UTILS.PrintTableToLog(self.KnownPilots[name])
end end
return self return self
end end
@ -354,7 +362,6 @@ end
-- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining. -- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining.
-- @return #NET self -- @return #NET self
function NET:BlockSide(Side,Seconds) function NET:BlockSide(Side,Seconds)
self:T({Side,Seconds})
local addon = Seconds or self.BlockTime local addon = Seconds or self.BlockTime
if Side == 1 or Side == 2 then if Side == 1 or Side == 2 then
self.BlockedSides[Side] = timer.getTime()+addon self.BlockedSides[Side] = timer.getTime()+addon
@ -367,10 +374,9 @@ end
-- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining. -- @param #number Seconds Seconds (optional) Number of seconds the player has to wait before rejoining.
-- @return #NET self -- @return #NET self
function NET:UnblockSide(Side,Seconds) function NET:UnblockSide(Side,Seconds)
self:T({Side,Seconds})
local addon = Seconds or self.BlockTime local addon = Seconds or self.BlockTime
if Side == 1 or Side == 2 then if Side == 1 or Side == 2 then
self.BlockedSides[Side] = nil self.BlockedSides[Side] = false
end end
return self return self
end end
@ -485,8 +491,11 @@ end
-- @param Wrapper.Client#CLIENT Client The client -- @param Wrapper.Client#CLIENT Client The client
-- @return #number PlayerID or nil -- @return #number PlayerID or nil
function NET:GetPlayerIDFromClient(Client) function NET:GetPlayerIDFromClient(Client)
self:T("GetPlayerIDFromClient")
self:T({Client=Client})
if Client then if Client then
local name = Client:GetPlayerName() local name = Client:GetPlayerName()
self:T({name=name})
local id = self:GetPlayerIDByName(name) local id = self:GetPlayerIDByName(name)
return id return id
else else
@ -682,9 +691,12 @@ end
-- @return #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue -- @return #number SideID i.e. 0 : spectators, 1 : Red, 2 : Blue
-- @return #number SlotID -- @return #number SlotID
function NET:GetSlot(Client) function NET:GetSlot(Client)
self:T("NET.GetSlot")
local PlayerID = self:GetPlayerIDFromClient(Client) local PlayerID = self:GetPlayerIDFromClient(Client)
self:T("NET.GetSlot PlayerID = "..tostring(PlayerID))
if PlayerID then if PlayerID then
local side,slot = net.get_slot(tonumber(PlayerID)) local side,slot = net.get_slot(tonumber(PlayerID))
self:T("NET.GetSlot side, slot = "..tostring(side)..","..tostring(slot))
return side,slot return side,slot
else else
return nil,nil return nil,nil
@ -781,7 +793,7 @@ function NET:onafterStatus(From,Event,To)
local function HouseHold(tavolo) local function HouseHold(tavolo)
local TNow = timer.getTime() local TNow = timer.getTime()
for _,entry in pairs (tavolo) do for _,entry in pairs (tavolo) do
if entry >= TNow then entry = nil end if type(entry) == "number" and entry >= TNow then entry = false end
end end
end end