Added CLIENT:FindByPlayerName(Name)

NET - slot blocker comments in log removed
This commit is contained in:
Applevangelist 2023-02-19 12:31:08 +01:00
parent 3e8413c6b7
commit 7dc239f506
2 changed files with 178 additions and 155 deletions

View File

@ -95,6 +95,22 @@ function CLIENT:Find(DCSUnit, Error)
end
end
--- Finds a CLIENT from the _DATABASE using the relevant player name.
-- @param #CLIENT self
-- @param #string Name Name of the player
-- @return #CLIENT or nil if not found
function CLIENT:FindByPlayerName(Name)
local foundclient = nil
_DATABASE:ForEachClient(
function(client)
if client:GetPlayerName() == Name then
foundclient = client
end
end
)
return foundclient
end
--- Finds a CLIENT from the _DATABASE using the relevant Client Unit Name.
-- As an optional parameter, a briefing text can be given also.

View File

@ -31,7 +31,7 @@ do
-- @field #NET
NET = {
ClassName = "NET",
Version = "0.0.6",
Version = "0.0.7",
BlockTime = 600,
BlockedPilots = {},
BlockedUCIDs = {},
@ -154,17 +154,18 @@ function NET:_EventHandler(EventData)
local name = data.IniPlayerName and data.IniPlayerName or data.IniUnit:GetPlayerName()
local ucid = self:GetPlayerUCID(nil,name)
local PlayerID = self:GetPlayerIDByName(name) or "none"
local PlayerSide, PlayerSlot = self:GetSlot(data.IniUnit)
local TNow = timer.getTime()
self:I(self.lid.."Event for: "..name.." | UCID: "..ucid)
self:T(self.lid.."Event for: "..name.." | UCID: "..ucid)
if self.BlockedPilots[name] then
self:I(self.lid.."Pilot "..name.." ID "..PlayerID.." Blocked for another "..self.BlockedPilots[name]-timer.getTime().." seconds!")
self:T(self.lid.."Pilot "..name.." ID "..PlayerID.." Blocked for another "..self.BlockedPilots[name]-timer.getTime().." seconds!")
end
if self.BlockedUCIDs[ucid] then
self:I(self.lid.."Pilot "..name.." ID "..PlayerID.." Blocked for another "..self.BlockedUCIDs[ucid]-timer.getTime().." seconds!")
self:T(self.lid.."Pilot "..name.." ID "..PlayerID.." Blocked for another "..self.BlockedUCIDs[ucid]-timer.getTime().." seconds!")
end
-- Joining
if data.id == EVENTS.PlayerEnterUnit or data.id == EVENTS.PlayerEnterAircraft then
self:I(self.lid.."Pilot Joining: "..name.." | UCID: "..ucid)
self:T(self.lid.."Pilot Joining: "..name.." | UCID: "..ucid)
-- Check for known pilots
if self.BlockedPilots[name] and TNow < self.BlockedPilots[name] then
-- block pilot by name
@ -177,7 +178,13 @@ function NET:_EventHandler(EventData)
local outcome = net.force_player_slot(tonumber(PlayerID), 0, '' )
end
else
self.KnownPilots[name] = true
self.KnownPilots[name] = {
name = name,
ucid = ucid,
id = PlayerID,
side = PlayerSide,
slot = PlayerSlot,
}
if (self.BlockedUCIDs[ucid] and TNow >= self.BlockedUCIDs[ucid]) or (self.BlockedPilots[name] and TNow >= self.BlockedPilots[name]) then
self.BlockedPilots[name] = nil
self.BlockedUCIDs[ucid] = nil
@ -188,21 +195,21 @@ function NET:_EventHandler(EventData)
end
-- Leaving
if data.id == EVENTS.PlayerLeaveUnit and self.KnownPilots[name] then
self:I(self.lid.."Pilot Leaving: "..name.." | UCID: "..ucid)
self:T(self.lid.."Pilot Leaving: "..name.." | UCID: "..ucid)
self:__PlayerLeft(1,data.IniUnit,name)
self.KnownPilots[name] = false
return self
end
-- Ejected
if data.id == EVENTS.Ejection and self.KnownPilots[name] then
self:I(self.lid.."Pilot Ejecting: "..name.." | UCID: "..ucid)
self:T(self.lid.."Pilot Ejecting: "..name.." | UCID: "..ucid)
self:__PlayerEjected(1,data.IniUnit,name)
self.KnownPilots[name] = false
return self
end
-- Dead, Crash, Suicide
if (data.id == EVENTS.PilotDead or data.id == EVENTS.SelfKillPilot or data.id == EVENTS.Crash) and self.KnownPilots[name] then
self:I(self.lid.."Pilot Dead: "..name.." | UCID: "..ucid)
self:T(self.lid.."Pilot Dead: "..name.." | UCID: "..ucid)
self:__PlayerDied(1,data.IniUnit,name)
self.KnownPilots[name] = false
return self
@ -219,7 +226,7 @@ end
-- @param #string Message (optional) Message to be sent via chat.
-- @return #NET self
function NET:BlockPlayer(Client,PlayerName,Seconds,Message)
self:I({PlayerName,Seconds,Message})
self:T({PlayerName,Seconds,Message})
local name = PlayerName
if Client and (not PlayerName) then
name = Client:GetPlayerName()
@ -322,10 +329,10 @@ end
function NET:GetPlayerIDByName(Name)
if not Name then return nil end
local playerList = self:GetPlayerList()
self:I({playerList})
self:T({playerList})
for i=1,#playerList do
local playerName = net.get_name(i)
self:I({playerName})
self:T({playerName})
if playerName == Name then
return playerList[i]
end