2019-11-15 12:37:37 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Mirror;
|
|
|
|
|
using SanAndreasUnity.Net;
|
|
|
|
|
using SanAndreasUnity.Utilities;
|
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Chat
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public class ChatSync : NetworkBehaviour
|
|
|
|
|
{
|
|
|
|
|
Player m_player;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
m_player = this.GetComponentOrThrow<Player>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Command]
|
2021-02-28 23:38:34 +01:00
|
|
|
|
void CmdChatMsg( string msg )
|
|
|
|
|
{
|
|
|
|
|
F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnServer(m_player, msg));
|
2019-11-15 12:37:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 23:25:49 +01:00
|
|
|
|
internal void SendChatMsgToServer( string msg )
|
2019-11-15 12:37:37 +01:00
|
|
|
|
{
|
|
|
|
|
this.CmdChatMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TargetRpc]
|
2021-02-28 23:38:34 +01:00
|
|
|
|
void TargetChatMsg( NetworkConnection conn, string msg, string sender )
|
|
|
|
|
{
|
|
|
|
|
if (!this.isLocalPlayer)
|
2021-02-27 23:15:29 +01:00
|
|
|
|
return;
|
2021-02-20 21:57:52 +01:00
|
|
|
|
|
2021-02-28 23:25:49 +01:00
|
|
|
|
F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnLocalPlayer(new ChatMessage (msg, sender)));
|
2019-11-15 12:37:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 23:25:49 +01:00
|
|
|
|
internal void SendChatMsgToClient( NetworkConnection conn, string msg, string sender )
|
2019-11-15 12:37:37 +01:00
|
|
|
|
{
|
2021-02-28 23:07:26 +01:00
|
|
|
|
NetStatus.ThrowIfNotOnServer();
|
|
|
|
|
|
2019-11-15 12:37:37 +01:00
|
|
|
|
this.TargetChatMsg(conn, msg, sender);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|