From 26b51b99c9daae1999f862d7c5e1edbf91a70ae4 Mon Sep 17 00:00:00 2001 From: in0finite Date: Sun, 28 Feb 2021 23:38:34 +0100 Subject: [PATCH] move all logic from ChatSync to ChatManager --- Assets/Scripts/Chat/ChatManager.cs | 8 ++++++++ Assets/Scripts/Chat/ChatSync.cs | 26 ++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/Chat/ChatManager.cs b/Assets/Scripts/Chat/ChatManager.cs index 6c8d40fa..e9481791 100644 --- a/Assets/Scripts/Chat/ChatManager.cs +++ b/Assets/Scripts/Chat/ChatManager.cs @@ -65,6 +65,10 @@ namespace SanAndreasUnity.Chat internal void OnChatMessageReceivedOnServer(Player player, string msg) { + msg = ChatManager.ProcessChatMessage(msg, false); + if (string.IsNullOrEmpty(msg)) + return; + if (!FilterWithPreprocessors(player, ref msg)) return; @@ -73,6 +77,10 @@ namespace SanAndreasUnity.Chat internal void OnChatMessageReceivedOnLocalPlayer(ChatMessage chatMsg) { + chatMsg.msg = ChatManager.ProcessChatMessage(chatMsg.msg, true); + if (string.IsNullOrEmpty(chatMsg.msg)) + return; + F.InvokeEventExceptionSafe(onChatMessage, chatMsg); } diff --git a/Assets/Scripts/Chat/ChatSync.cs b/Assets/Scripts/Chat/ChatSync.cs index b58e1fd0..a94efa64 100644 --- a/Assets/Scripts/Chat/ChatSync.cs +++ b/Assets/Scripts/Chat/ChatSync.cs @@ -8,7 +8,6 @@ namespace SanAndreasUnity.Chat public class ChatSync : NetworkBehaviour { - Player m_player; @@ -18,16 +17,9 @@ namespace SanAndreasUnity.Chat } [Command] - void CmdChatMsg( string msg ) { - - Player p = m_player; - - msg = ChatManager.ProcessChatMessage(msg, false); - if (string.IsNullOrEmpty(msg)) - return; - - F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnServer(p, msg)); - + void CmdChatMsg( string msg ) + { + F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnServer(m_player, msg)); } internal void SendChatMsgToServer( string msg ) @@ -36,18 +28,12 @@ namespace SanAndreasUnity.Chat } [TargetRpc] - void TargetChatMsg( NetworkConnection conn, string msg, string sender ) { - - if (!this.isLocalPlayer) { - return; - } - - msg = ChatManager.ProcessChatMessage(msg, true); - if (string.IsNullOrEmpty(msg)) + void TargetChatMsg( NetworkConnection conn, string msg, string sender ) + { + if (!this.isLocalPlayer) return; F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnLocalPlayer(new ChatMessage (msg, sender))); - } internal void SendChatMsgToClient( NetworkConnection conn, string msg, string sender )