Ejemplo n.º 1
0
        public void OnServerChatReceive(NetworkMessage netMsg)
        {
            MsgChatSendFromClient msg     = netMsg.ReadMessage <MsgChatSendFromClient>();
            ChatChannelData       channel = defaultChannel;

            if (ChatUsers.ContainsKey(netMsg.conn))
            {
                ChatUser user = ChatUsers[netMsg.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 " + netMsg.conn.connectionId);
            }
        }
Ejemplo n.º 2
0
        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;
            }

            ChatChannelData channel = null;

            if (Channels.TryGetValue(channelId, out channel))
            {
                string[] chatData = channel.GetChatData(message);
                if (chatData != null && chatData.Length > 0)
                {
                    NetworkConnection     conn        = client.connection;
                    MsgChatSendFromClient chatSendMsg = new MsgChatSendFromClient();
                    chatSendMsg.channelId = channelId;
                    chatSendMsg.chatData  = chatData;
                    conn.Send(MsgChatSendFromClient.MsgId, chatSendMsg);
                }
                else
                {
                    Debug.LogWarning("[Warning] Invalid chat data");
                }
            }
            else
            {
                Debug.LogWarning("[Warning] Chat channel (" + channelId + ") not found");
            }
        }