2019-11-15 11:37:37 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Mirror;
|
|
|
|
|
using SanAndreasUnity.Net;
|
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Chat
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class ChatSync : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Player m_player;
|
|
|
|
|
|
|
|
|
|
public static event System.Action<Player, string> onChatMessageReceivedOnServer = delegate {};
|
|
|
|
|
public static event System.Action<ChatMessage> onChatMessageReceivedOnLocalPlayer = delegate {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
m_player = this.GetComponentOrThrow<Player>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command]
|
|
|
|
|
void CmdChatMsg( string msg ) {
|
|
|
|
|
|
|
|
|
|
Player p = m_player;
|
|
|
|
|
|
2021-02-28 21:53:16 +00:00
|
|
|
|
msg = ChatManager.ProcessChatMessage(msg, false);
|
2021-02-27 22:15:29 +00:00
|
|
|
|
if (string.IsNullOrEmpty(msg))
|
|
|
|
|
return;
|
2019-11-15 11:37:37 +00:00
|
|
|
|
|
2021-01-02 16:35:46 +00:00
|
|
|
|
F.InvokeEventExceptionSafe(onChatMessageReceivedOnServer, p, msg);
|
2019-11-15 11:37:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendChatMsgToServer( string msg )
|
|
|
|
|
{
|
|
|
|
|
this.CmdChatMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TargetRpc]
|
|
|
|
|
void TargetChatMsg( NetworkConnection conn, string msg, string sender ) {
|
|
|
|
|
|
|
|
|
|
if (!this.isLocalPlayer) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 21:53:16 +00:00
|
|
|
|
msg = ChatManager.ProcessChatMessage(msg, true);
|
2021-02-27 22:15:29 +00:00
|
|
|
|
if (string.IsNullOrEmpty(msg))
|
|
|
|
|
return;
|
2021-02-20 20:57:52 +00:00
|
|
|
|
|
2021-02-27 22:25:07 +00:00
|
|
|
|
F.InvokeEventExceptionSafe(onChatMessageReceivedOnLocalPlayer, new ChatMessage (msg, sender));
|
2019-11-15 11:37:37 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendChatMsgToClient( NetworkConnection conn, string msg, string sender )
|
|
|
|
|
{
|
|
|
|
|
this.TargetChatMsg(conn, msg, sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|