mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-27 06:20:17 +00:00
48 lines
944 B
C#
48 lines
944 B
C#
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]
|
|
void CmdChatMsg( string msg )
|
|
{
|
|
F.RunExceptionSafe(() => ChatManager.singleton.OnChatMessageReceivedOnServer(m_player, msg));
|
|
}
|
|
|
|
internal void SendChatMsgToServer( string msg )
|
|
{
|
|
this.CmdChatMsg(msg);
|
|
}
|
|
|
|
[TargetRpc]
|
|
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 )
|
|
{
|
|
NetStatus.ThrowIfNotOnServer();
|
|
|
|
this.TargetChatMsg(conn, msg, sender);
|
|
}
|
|
|
|
}
|
|
|
|
}
|