From 83866c3dd3080a45c84ac9824f3e9d11d6e05811 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 15:02:11 +0100 Subject: [PATCH 1/3] #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 2/3] #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 3/3] 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