Exemplo n.º 1
0
        // -------------------------------------------------------------------------------
        public void OnServerChatReceive(NetworkConnection conn, MsgChatSendFromClient msg)
        {
            ChatChannelData channel = defaultChannel;

            if (ChatUsers.ContainsKey(conn))
            {
                ChatUser user = ChatUsers[conn];
                if (Channels.ContainsKey(msg.channelId))
                {
                    channel = Channels[msg.channelId];
                }
                else
                {
                    Debug.LogWarning("[Warning] Chat channel (" + msg.channelId + ") not found");
                }

                if (channel != null)
                {
                    ClientChatReceive(channel.DoChatLogic(user, msg.chatData));
                }
            }
            else
            {
                Debug.LogError("[Error] Invalid chat user " + conn.connectionId);
            }
        }
Exemplo n.º 2
0
        // -------------------------------------------------------------------------------
        // ClientChatSend
        // -------------------------------------------------------------------------------
        public void ClientChatSend(string channelId, string message)
        {
            if (clientChatUser == null || string.IsNullOrEmpty(message))
            {
                Debug.LogWarning("[Warning] Did not login to server can not send chat message");
                return;
            }

            // -- Profanity Filter (applied client side already)
            message = profanityFilter.FilterText(message);

            ChatChannelData channel = null;

            if (Channels.TryGetValue(channelId, out channel))
            {
                string[] chatData = channel.GetChatData(message);
                if (chatData != null && chatData.Length > 0)
                {
                    NetworkConnection     conn        = NetworkClient.connection;
                    MsgChatSendFromClient chatSendMsg = new MsgChatSendFromClient();
                    chatSendMsg.channelId = channelId;
                    chatSendMsg.chatData  = chatData;
                    conn.Send(chatSendMsg);
                }
                else
                {
                    Debug.LogWarning("[Warning] Invalid chat data");
                }
            }
            else
            {
                Debug.LogWarning("[Warning] Chat channel (" + channelId + ") not found");
            }
        }
 public ChatChannelDataResult(ChatChannelData channel, string message, bool isBroadcast, ChatUser sender, ChatUser receiver = null)
 {
     this.channel     = channel;
     this.message     = message;
     this.isBroadcast = isBroadcast;
     this.sender      = sender;
     this.receiver    = receiver;
 }
Exemplo n.º 4
0
 // -------------------------------------------------------------------------------
 // ChatMessage (Constructor)
 // -------------------------------------------------------------------------------
 public ChatMessage(ChatChannelData channelData, string senderId, string senderName, string message, ChatState chatState)
 {
     this.channelData = channelData;
     this.senderId    = senderId;
     this.senderName  = senderName;
     this.message     = message;
     this.chatState   = chatState;
     this.receiveTime = Time.unscaledTime;
 }
Exemplo n.º 5
0
        // -------------------------------------------------------------------------------
        // LocalChatSend
        // -------------------------------------------------------------------------------
        public void LocalChatSend(string message, string channelId = "info")
        {
            if (clientChatUser == null || string.IsNullOrEmpty(message))
            {
                Debug.LogWarning("[Warning] Did not login to server can not send chat message");
                return;
            }

            ChatChannelData channel = null;

            if (Channels.TryGetValue(channelId, out channel))
            {
                Debug.Log(message);
                ChatMessage chatMessage = new ChatMessage(channel, "", "", message, ChatMessage.ChatState.Send);

                if (UIWindowChat.singleton)
                {
                    UIWindowChat.singleton.OnReceiveChatMessage(chatMessage);
                }
            }
        }
Exemplo n.º 6
0
        // -------------------------------------------------------------------------------
        // OnClientChatReceive
        // -------------------------------------------------------------------------------
        public void OnClientChatReceive(NetworkConnection conn, MsgChatReceiveFromServer msg)
        {
            ChatChannelData channel = defaultChannel;

            if (Channels.ContainsKey(msg.channelId))
            {
                channel = Channels[msg.channelId];
            }
            else
            {
                Debug.LogWarning("[Warning] Chat channel (" + msg.channelId + ") not found");
            }

            if (channel != null)
            {
                ChatMessage.ChatState chatState = ChatMessage.ChatState.Receive;

                if (msg.senderId.Equals(clientChatUser.userId))
                {
                    chatState = ChatMessage.ChatState.Send;
                }

                ChatMessage chatMessage = new ChatMessage(channel, msg.senderId, msg.senderName, msg.message, chatState);
                Messages.Add(chatMessage);

                if (onReceiveMessage != null)
                {
                    onReceiveMessage(this, chatMessage);
                }

                if (UIWindowChat.singleton)
                {
                    UIWindowChat.singleton.OnReceiveChatMessage(chatMessage);
                }
            }
        }