From a4dcb643bd0a9c4b1e07275434b3034c83d6a07b Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Fri, 17 Feb 2023 15:41:33 +0100 Subject: [PATCH] #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