From 2ebbc8f466b2629c4d5033e50cb4ef8b0e08756c Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 08:54:15 +0100 Subject: [PATCH 1/6] #NET - added docu --- Moose Development/Moose/Wrapper/Net.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index d2ac28285..34c7bdbdf 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -91,7 +91,7 @@ function NET:New() -- @param #string From State. -- @param #string Event Trigger. -- @param #string To State. - -- @param Wrapper.Unit#UNIT Client Unit Object. + -- @param Wrapper.Unit#UNIT Client Unit Object, might be nil. -- @param #string Name Name of leaving Pilot. -- @return #NET self @@ -101,7 +101,7 @@ function NET:New() -- @param #string From State. -- @param #string Event Trigger. -- @param #string To State. - -- @param Wrapper.Unit#UNIT Client Unit Object. + -- @param Wrapper.Unit#UNIT Client Unit Object, might be nil. -- @param #string Name Name of leaving Pilot. -- @return #NET self @@ -111,7 +111,7 @@ function NET:New() -- @param #string From State. -- @param #string Event Trigger. -- @param #string To State. - -- @param Wrapper.Unit#UNIT Client Unit Object. + -- @param Wrapper.Unit#UNIT Client Unit Object, might be nil. -- @param #string Name Name of dead Pilot. -- @return #NET self @@ -121,7 +121,7 @@ function NET:New() -- @param #string From State. -- @param #string Event Trigger. -- @param #string To State. - -- @param Wrapper.Client#CLIENT Client Client Object. + -- @param Wrapper.Client#CLIENT Client Client Object, might be nil. -- @param #string Name Name of blocked Pilot. -- @param #number Seconds Blocked for this number of seconds -- @return #NET self @@ -132,7 +132,7 @@ function NET:New() -- @param #string From State. -- @param #string Event Trigger. -- @param #string To State. - -- @param Wrapper.Client#CLIENT Client Client Object. + -- @param Wrapper.Client#CLIENT Client Client Object, might be nil. -- @param #string Name Name of unblocked Pilot. -- @return #NET self From 50f73f1be275bfef4ad6970e1723bb80ebbbdf05 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 13:22:10 +0100 Subject: [PATCH 2/6] #NET extended block to UCID --- Moose Development/Moose/Wrapper/Net.lua | 47 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index 34c7bdbdf..1e3845979 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -1,6 +1,6 @@ --- **Wrapper** - DCS net functions. -- --- Encapsules **multiplayer** environment scripting functions from [net](https://wiki.hoggitworld.com/view/DCS_singleton_net) +-- Encapsules **multiplayer server** environment scripting functions from [net](https://wiki.hoggitworld.com/view/DCS_singleton_net) -- -- === -- @@ -22,6 +22,7 @@ do -- @field #table KnownPilots -- @field #string BlockMessage -- @field #string UnblockMessage +-- @field #table BlockedUCIDs -- @extends Core.Fsm#FSM --- Encapsules multiplayer environment scripting functions from [net](https://wiki.hoggitworld.com/view/DCS_singleton_net) @@ -30,9 +31,10 @@ do -- @field #NET NET = { ClassName = "NET", - Version = "0.0.3", + Version = "0.0.4", BlockTime = 600, BlockedPilots = {}, + BlockedUCIDs = {}, KnownPilots = {}, BlockMessage = nil, UnblockMessage = nil, @@ -150,17 +152,22 @@ function NET:_EventHandler(EventData) if data.id and data.IniUnit and (data.IniPlayerName or data.IniUnit:GetPlayerName()) then -- Get PlayerName local name = data.IniPlayerName and data.IniPlayerName or data.IniUnit:GetPlayerName() - self:T(self.lid.."Event for: "..name) + local ucid = self:GetPlayerUCID(nil,name) + self:T(self.lid.."Event for: "..name.." | UCID: "..ucid) -- Joining if data.id == EVENTS.PlayerEnterUnit or data.id == EVENTS.PlayerEnterAircraft then -- Check for known pilots local TNow = timer.getTime() if self.BlockedPilots[name] and TNow < self.BlockedPilots[name] then - -- block pilot + -- block pilot by name + self:ReturnToSpectators(data.IniUnit) + elseif self.BlockedUCIDs[ucid] and TNow < self.BlockedUCIDs[ucid] then + -- block pilot by ucid self:ReturnToSpectators(data.IniUnit) else self.KnownPilots[name] = true self.BlockedPilots[name] = nil + self.BlockedUCIDs[ucid] = nil self:__PlayerJoined(1,data.IniUnit,name) return self end @@ -204,8 +211,10 @@ function NET:BlockPlayer(Client,PlayerName,Seconds,Message) self:F(self.lid.."Block: No PlayerName given or not found!") return self end + local ucid = self:GetPlayerUCID(Client,name) local addon = Seconds or self.BlockTime self.BlockedPilots[name] = timer.getTime()+addon + self.BlockedUCIDs[ucid] = timer.getTime()+addon local message = Message or self.BlockMessage if Client then self:SendChatToPlayer(message,Client) @@ -233,7 +242,9 @@ function NET:UnblockPlayer(Client,PlayerName,Message) self:F(self.lid.."Unblock: No PlayerName given or not found!") return self end + local ucid = self:GetPlayerUCID(Client,name) self.BlockedPilots[name] = nil + self.BlockedUCIDs[ucid] = nil local message = Message or self.UnblockMessage if Client then self:SendChatToPlayer(message,Client) @@ -244,16 +255,28 @@ function NET:UnblockPlayer(Client,PlayerName,Message) return self end +--- Set block chat message. +-- @param #NET self +-- @param #string Text The message +-- @return #NET self function NET:SetBlockMessage(Text) self.BlockMessage = Text or "You are blocked from joining. Wait time is: "..self.BlockTime.." seconds!" return self end +--- Set block time in seconds. +-- @param #NET self +-- @param #number Seconds Numnber of seconds this block will last. Defaults to 600. +-- @return #NET self function NET:SetBlockTime(Seconds) self.BlockTime = Seconds or 600 return self end +--- Set unblock chat message. +-- @param #NET self +-- @param #string Text The message +-- @return #NET self function NET:SetUnblockMessage(Text) self.UnblockMessage = Text or "You are unblocked now and can join again." return self @@ -275,7 +298,7 @@ end -- @param #NET self -- @param #string Name The player name whose ID to find -- @return #number PlayerID or nil -function NET:GetPlayerIdByName(Name) +function NET:GetPlayerIDByName(Name) local playerList = self:GetPlayerList() for i=1,#playerList do local playerName = net.get_name(i) @@ -292,7 +315,7 @@ end -- @return #number PlayerID or nil function NET:GetPlayerIDFromClient(Client) local name = Client:GetPlayerName() - local id = self:GetPlayerIdByName(name) + local id = self:GetPlayerIDByName(name) return id end @@ -384,6 +407,18 @@ function NET:GetPlayerInfo(Client,Attribute) end end + +--- Get player UCID from player CLIENT object or player name. Provide either one. +-- @param #NET self +-- @param Wrapper.Client#CLIENT Client The client object to be used. +-- @param #string Name Player name to be used. +-- @return #boolean success +function NET:GetPlayerUCID(Client,Name) + local PlayerID = self:GetPlayerIDByName(Name) or self:GetPlayerIDFromClient(Client) + local ucid = net.get_player_info(tonumber(PlayerID), 'ucid') + return ucid +end + --- Kicks a player from the server. Can display a message to the user. -- @param #NET self -- @param Wrapper.Client#CLIENT Client The client From 4797abc2875fdbdf4addc54b7f6cb3f19ec2e5da Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 14:32:48 +0100 Subject: [PATCH 3/6] #NET Bugfix --- Moose Development/Moose/Wrapper/Net.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index 1e3845979..eafa6a640 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -208,7 +208,7 @@ function NET:BlockPlayer(Client,PlayerName,Seconds,Message) elseif PlayerName then name = PlayerName else - self:F(self.lid.."Block: No PlayerName given or not found!") + self:F(self.lid.."Block: No Client or PlayerName given or nothing found!") return self end local ucid = self:GetPlayerUCID(Client,name) @@ -414,7 +414,14 @@ end -- @param #string Name Player name to be used. -- @return #boolean success function NET:GetPlayerUCID(Client,Name) - local PlayerID = self:GetPlayerIDByName(Name) or self:GetPlayerIDFromClient(Client) + local PlayerID = nil + if Client then + PlayerID = self:GetPlayerIDFromClient(Client) + elseif Name then + PlayerID = self:GetPlayerIDByName(Name) + else + self:E(self.lid.."Neither client nor name provided!") + end local ucid = net.get_player_info(tonumber(PlayerID), 'ucid') return ucid end From 83866c3dd3080a45c84ac9824f3e9d11d6e05811 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 15:02:11 +0100 Subject: [PATCH 4/6] #NET Fixes --- Moose Development/Moose/Wrapper/Net.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index eafa6a640..b7c61ed86 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -204,7 +204,7 @@ end function NET:BlockPlayer(Client,PlayerName,Seconds,Message) local name if Client then - name = CLIENT:GetPlayerName() + name = Client:GetPlayerName() elseif PlayerName then name = PlayerName else @@ -235,7 +235,7 @@ end function NET:UnblockPlayer(Client,PlayerName,Message) local name if Client then - name = CLIENT:GetPlayerName() + name = Client:GetPlayerName() elseif PlayerName then name = PlayerName else From 973127aa8cb46ca4b03d13ff227cadc5c1601f51 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 15:42:06 +0100 Subject: [PATCH 5/6] #NET Fixes --- Moose Development/Moose/Wrapper/Net.lua | 39 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index b7c61ed86..87840fd78 100644 --- a/Moose Development/Moose/Wrapper/Net.lua +++ b/Moose Development/Moose/Wrapper/Net.lua @@ -216,8 +216,8 @@ function NET:BlockPlayer(Client,PlayerName,Seconds,Message) self.BlockedPilots[name] = timer.getTime()+addon self.BlockedUCIDs[ucid] = timer.getTime()+addon local message = Message or self.BlockMessage - if Client then - self:SendChatToPlayer(message,Client) + if name then + self:SendChatToPlayer(message,name) else self:SendChat(name..": "..message) end @@ -246,8 +246,8 @@ function NET:UnblockPlayer(Client,PlayerName,Message) self.BlockedPilots[name] = nil self.BlockedUCIDs[ucid] = nil local message = Message or self.UnblockMessage - if Client then - self:SendChatToPlayer(message,Client) + if name then + self:SendChatToPlayer(message,name) else self:SendChat(name..": "..message) end @@ -314,18 +314,22 @@ end -- @param Wrapper.Client#CLIENT Client The client -- @return #number PlayerID or nil function NET:GetPlayerIDFromClient(Client) - local name = Client:GetPlayerName() - local id = self:GetPlayerIDByName(name) - return id + if Client then + local name = Client:GetPlayerName() + local id = self:GetPlayerIDByName(name) + return id + else + return nil + end end ---- Send chat message to a specific player. +--- Send chat message to a specific player using the CLIENT object. -- @param #NET self -- @param #string Message The text message -- @param Wrapper.Client#CLIENT ToClient Client receiving the message -- @param Wrapper.Client#CLIENT FromClient (Optional) Client sending the message -- @return #NET self -function NET:SendChatToPlayer(Message, ToClient, FromClient) +function NET:SendChatToClient(Message, ToClient, FromClient) local PlayerId = self:GetPlayerIDFromClient(ToClient) local FromId = self:GetPlayerIDFromClient(FromClient) if Message and PlayerId and FromId then @@ -336,6 +340,23 @@ function NET:SendChatToPlayer(Message, ToClient, FromClient) return self end +--- Send chat message to a specific player using the player name +-- @param #NET self +-- @param #string Message The text message +-- @param #string ToPlayer Player receiving the message +-- @param #string FromPlayer(Optional) Player sending the message +-- @return #NET self +function NET:SendChatToPlayer(Message, ToPlayer, FromPlayer) + local PlayerId = self:GetPlayerIDByName(ToPlayer) + local FromId = self:GetPlayerIDByName(FromPlayer) + if Message and PlayerId and FromId then + net.send_chat_to(Message, tonumber(PlayerId) , tonumber(FromId)) + elseif Message and PlayerId then + net.send_chat_to(Message, tonumber(PlayerId)) + end + return self +end + --- Load a specific mission. -- @param #NET self -- @param #string Path and Mission From 66494b7b5ac2a98eddb1d623698bd7916f123757 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 16:23:02 +0100 Subject: [PATCH 6/6] NET --- Moose Development/Moose/Wrapper/Net.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Net.lua b/Moose Development/Moose/Wrapper/Net.lua index 87840fd78..f98f1f93f 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.4", + Version = "0.0.5", BlockTime = 600, BlockedPilots = {}, BlockedUCIDs = {}, @@ -202,7 +202,7 @@ end -- @param #string Message (optional) Message to be sent via chat. -- @return #NET self function NET:BlockPlayer(Client,PlayerName,Seconds,Message) - local name + local name = PlayerName if Client then name = Client:GetPlayerName() elseif PlayerName then @@ -222,7 +222,10 @@ function NET:BlockPlayer(Client,PlayerName,Seconds,Message) self:SendChat(name..": "..message) end self:__PlayerBlocked(1,Client,name,Seconds) - self:ReturnToSpectators(Client) + local PlayerID = self:GetPlayerIDByName(name) + if PlayerID and tonumber(PlayerID) ~= 1 then + local outcome = net.force_player_slot(tonumber(PlayerID), 0, '' ) + end return self end @@ -233,7 +236,7 @@ end -- @param #string Message (optional) Message to be sent via chat. -- @return #NET self function NET:UnblockPlayer(Client,PlayerName,Message) - local name + local name = PlayerName if Client then name = Client:GetPlayerName() elseif PlayerName then @@ -299,6 +302,7 @@ end -- @param #string Name The player name whose ID to find -- @return #number PlayerID or nil function NET:GetPlayerIDByName(Name) + if not Name then return nil end local playerList = self:GetPlayerList() for i=1,#playerList do local playerName = net.get_name(i) @@ -526,8 +530,8 @@ end -- @return #boolean Success function NET:ForceSlot(Client,SideID,SlotID) local PlayerID = self:GetPlayerIDFromClient(Client) - if PlayerID then - return net.force_player_slot(tonumber(PlayerID), SideID, SlotID ) + if PlayerID and tonumber(PlayerID) ~= 1 then + return net.force_player_slot(tonumber(PlayerID), SideID, SlotID or '' ) else return false end