From 55a055a0472dba1bc0a84e564e8bd89699b972a8 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sat, 18 Feb 2023 15:03:07 +0100 Subject: [PATCH] #NET - further ado --- Moose Development/Moose/Wrapper/Net.lua | 32 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index a12d580ca..300775eb9 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -31,7 +31,7 @@ do -- @field #NET NET = { ClassName = "NET", - Version = "0.0.5", + Version = "0.0.6", BlockTime = 600, BlockedPilots = {}, BlockedUCIDs = {}, @@ -153,45 +153,56 @@ function NET:_EventHandler(EventData) -- Get PlayerName local name = data.IniPlayerName and data.IniPlayerName or data.IniUnit:GetPlayerName() local ucid = self:GetPlayerUCID(nil,name) - self:T(self.lid.."Event for: "..name.." | UCID: "..ucid) + local PlayerID = self:GetPlayerIDByName(name) or "none" + local TNow = timer.getTime() + self:I(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!") + end + if self.BlockedUCIDs[ucid] then + self:I(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) -- Check for known pilots - local TNow = timer.getTime() if self.BlockedPilots[name] and TNow < self.BlockedPilots[name] then - -- block pilot by name - local PlayerID = self:GetPlayerIDByName(name) + -- block pilot by name if PlayerID and tonumber(PlayerID) ~= 1 then local outcome = net.force_player_slot(tonumber(PlayerID), 0, '' ) end elseif self.BlockedUCIDs[ucid] and TNow < self.BlockedUCIDs[ucid] then -- block pilot by ucid - local PlayerID = self:GetPlayerIDByName(name) if PlayerID and tonumber(PlayerID) ~= 1 then local outcome = net.force_player_slot(tonumber(PlayerID), 0, '' ) end else self.KnownPilots[name] = true - self.BlockedPilots[name] = nil - self.BlockedUCIDs[ucid] = nil + 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 + end self:__PlayerJoined(1,data.IniUnit,name) return self end end -- Leaving if data.id == EVENTS.PlayerLeaveUnit and self.KnownPilots[name] then + self:I(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:__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:__PlayerDied(1,data.IniUnit,name) self.KnownPilots[name] = false return self @@ -208,8 +219,9 @@ 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}) local name = PlayerName - if Client then + if Client and (not PlayerName) then name = Client:GetPlayerName() elseif PlayerName then name = PlayerName @@ -310,8 +322,10 @@ end function NET:GetPlayerIDByName(Name) if not Name then return nil end local playerList = self:GetPlayerList() + self:I({playerList}) for i=1,#playerList do local playerName = net.get_name(i) + self:I({playerName}) if playerName == Name then return playerList[i] end