Ejemplo n.º 1
0
        // -------------------------------------------------------------------------------
        public void ClientChatReceive(ChatChannelDataResult result)
        {
            if (result == null)
            {
                Debug.LogWarning("[Warning] Can not receive null chat result");
                return;
            }

            MsgChatReceiveFromServer msg = new MsgChatReceiveFromServer();

            msg.channelId  = result.channel.channelId;
            msg.senderId   = result.sender.userId;
            msg.senderName = result.sender.name;
            msg.message    = result.message;
            if (result.isBroadcast)
            {
                foreach (ChatUser user in ChatUsers.Values)
                {
                    if (user.conn != null)
                    {
                        user.conn.Send(msg);
                    }
                }
            }
            else
            {
                if (result.receiver != null && result.receiver.conn != null)
                {
                    result.receiver.conn.Send(msg);
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }