Esempio n. 1
0
        public static MessageMovedIn AddMessageMovedInEventHandler <T>(this RoomWatcher <T> rw, Action <Chat.User, Chat.Message> callback) where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new MessageMovedIn();

            eventProcessor.OnEvent += mm =>
            {
                Chat.User    movedBy = null;
                Chat.Message message = null;

                var tasks = new[]
                {
                    Task.Run(() =>
                    {
                        movedBy = new Chat.User(rw.Host, mm.MovedBy, rw.Auth);
                    }),
                    Task.Run(() =>
                    {
                        message = new Chat.Message(rw.Host, mm.MessageId, rw.Auth);
                    })
                };

                Task.WaitAll(tasks);

                callback(movedBy, message);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
Esempio n. 2
0
    void ForwardMessage(string channel, string messageChannel, Chat.Message message)
    {
        if (m_Channels.ContainsKey(channel) == false)
        {
            return;
        }

        Listeners listeners = new Listeners();

        listeners.AddRange(m_Channels[channel]);

        bool cleanup = false;

        foreach (var listener in listeners)
        {
            if (listener != null)
            {
                listener.ReceiveMessage(messageChannel, message);
            }
            else
            {
                cleanup = true;
            }
        }

        if (cleanup == true)
        {
            m_Channels[channel].RemoveAll((obj) => { return(obj == null ? true : false); });
        }
    }
Esempio n. 3
0
    // HANDLERS

    void OnMessageReceived(Chat.Message message)
    {
        if (IsVisible == false)
        {
            m_UnreadMessages++;
        }
    }
Esempio n. 4
0
        public static UserMentioned AddUserMentionedEventHandler <T>(
            this RoomWatcher <T> rw,
            Action <Chat.Message, Chat.User> callback)
            where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new UserMentioned();

            eventProcessor.OnEvent += um =>
            {
                Chat.Message msg    = null;
                Chat.User    pinger = null;

                var tasks = new[]
                {
                    Task.Run(() =>
                    {
                        msg = new Chat.Message(rw.Host, um.MessageId, rw.Auth);
                    }),
                    Task.Run(() =>
                    {
                        pinger = new Chat.User(rw.Host, um.PingerId, rw.Auth);
                    })
                };

                Task.WaitAll(tasks);

                callback(msg, pinger);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                //Make sure a recipient is selected to chat with
                if (lstUsers.SelectedItems.Count < 1)
                {
                    MessageBox.Show("You must select who to chat with.");
                    return;
                }

                Chat.Message MSG = new Chat.Message();
                MSG.Sender = Client;
                MSG.MSG    = txtMessage.Text;

                switch (cmbAction.SelectedIndex)
                {
                case 0:
                    MSG.Type = Chat.MGSType.Chat;
                    break;

                case 1:
                    MSG.Type = Chat.MGSType.PowerShell;
                    break;

                case 2:
                    MSG.Type = Chat.MGSType.ComputerInfo;
                    break;
                }


                //Add the selected recipients to the table
                foreach (string user in lstUsers.SelectedItems)
                {
                    Chat.Client c = new Chat.Client();
                    c.Name = user;
                    MSG.Reciptients.Add(c);
                }

                //Update the sender's message history
                txtMessageHistory.Text += Client.Name + " - " + txtMessage.Text + Environment.NewLine;

                byte[] msg = Chat.Serialize(Chat.Action.Message, MSG);

                if (Session.SendMessage(msg) == false)
                {
                    // Show the exception
                    MessageBox.Show(Session.Exception);
                    return;
                }

                //Clear the message box
                txtMessage.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 6
0
        public void Update(Chat.Message message)
        {
            Id = message.Id;

            if (m_Name != null)
            {
                m_Name.SetNewText(GuiBaseUtils.FixNameForGui(message.Nickname));
            }

            if (m_Text != null)
            {
                m_Text.SetNewText(m_Name == null ? string.Format("{0}: {1}", GuiBaseUtils.FixNameForGui(message.Nickname), message.Text) : message.Text);

                Transform trans = m_Text.transform;
                Vector3   scale = trans.localScale;
                m_Rect.width  = Mathf.RoundToInt(m_Text.textSize.x * scale.x);
                m_Rect.height = Mathf.RoundToInt(m_Text.textSize.y * scale.y);
            }

            if (m_RankIcon != null)
            {
                m_RankIcon.State = string.Format("Rank_{0}", Mathf.Min(message.Rank, m_RankIcon.Count - 1).ToString("D2"));
            }

            if (m_RankText != null)
            {
                m_RankText.SetNewText(message.Rank.ToString());
            }

            if (m_HighlightBkg != null)
            {
                Vector2   pos    = m_HighlightBkg.GetOrigPos();
                Transform trans  = m_HighlightBkg.transform;
                Vector3   scale  = trans.lossyScale;
                int       offset = Mathf.RoundToInt(pos.y - m_Root.GetOrigPos().y);
                int       width  = Mathf.RoundToInt(m_HighlightBkg.GetWidth());
                int       height = (int)m_Rect.height + 4;

                offset -= offset - Mathf.RoundToInt(m_HighlightBkg.GetHeight() * 0.5f * scale.y);
                pos.y   = pos.y - offset + height * 0.5f * scale.y;

                m_HighlightBkg.UpdateSpritePosAndSize(0, pos.x, pos.y, width, height);

                m_Rect.width = Mathf.RoundToInt(width * scale.x);
                //m_Rect.height = Mathf.RoundToInt(height * scale.y);
            }

            foreach (var button in m_Buttons)
            {
                Transform trans = button.transform;
                Vector3   pos   = trans.localPosition;

                pos.y = m_Rect.height * 0.5f;
                trans.localPosition = pos;
            }

            m_HoverButton = null;
        }
Esempio n. 7
0
 void OnMessageAction(Chat.Message message, GUIBase_Widget instigator)
 {
     if (instigator.name == "AddFriend_Button")
     {
         NewFriendDialog popup =
             (NewFriendDialog)Owner.ShowPopup("NewFriend", string.Empty, string.Empty, (inPopup, inResult) => { m_Chat.Refresh(); });
         popup.Nickname   = message.Nickname;
         popup.Username   = string.Empty;
         popup.PrimaryKey = message.PrimaryKey;
     }
 }
        internal void receivedData(Chat.Packet packet)
        {
            Chat.Clients recipients = new Chat.Clients();

            if (packet != null)
            {
                switch (packet.ID)
                {
                case Chat.Action.Join:

                    // Deserialize the content
                    Chat.Client usr = Chat.Client.Deserialize(packet.Content);
                    ClientName = usr.Name;

                    // Add the user set to receive a full list of user
                    recipients.List.Add(usr);

                    Chat.Clients usrs = new Chat.Clients();
                    foreach (DictionaryEntry c in IPList)
                    {
                        Chat.Client u = new Chat.Client();
                        u.Name = ((Server)c.Value).ClientName;
                        usrs.List.Add(u);
                    }

                    byte[] msg = Chat.Serialize(Chat.Action.ClientList, usrs);

                    //Send the full user list to the user that just signed on
                    Broadcast(msg, recipients);

                    //Rebroadcast the original message to everyone that this user is online
                    Broadcast(Data, null);

                    break;

                case Chat.Action.Message:
                    Chat.Message message = Chat.Message.Deserialize(packet.Content);

                    foreach (Chat.Client recipient in message.Reciptients)
                    {
                        recipients.List.Add(recipient);
                    }

                    //Send the message to the recipients
                    Broadcast(Data, recipients);
                    break;

                default:

                    break;
                }
            }
        }
Esempio n. 9
0
    void Chat.IListener.ReceiveMessage(string channel, Chat.Message message)
    {
        FriendInfo info = m_Friends.Find(obj => obj.Channel == channel);

        if (info == null)
        {
            Chat.Unregister(channel, this);
        }
        else
        {
            AddChatMessage(info, message);
        }
    }
Esempio n. 10
0
    void AddSystemMessage(FriendInfo info, string text)
    {
        Chat.Message message = Chat.Message.Create("", "System", -1, text);

        bool active = m_Friends.FindIndex(obj => obj.PrimaryKey == info.PrimaryKey) == m_ActiveFriend;

        if (active == true)
        {
            m_Chat.AddMessage(message);
        }

        AddMessage(info, active, message);
    }
Esempio n. 11
0
    void AddMessage(FriendInfo info, bool active, Chat.Message message)
    {
        info.Messages.Enqueue(message);

        if (active == false || IsVisible == false)
        {
            info.UnreadMessages++;
        }

        if (IsVisible == true)
        {
            m_FriendList.Widget.SetModify();
        }
    }
        private void AddMessage(Chat.Message msg)
        {
            AppendText($"{msg.Nick} ({msg.QQ}) {DateTime.FromBinary(msg.Time).ToShortTimeString()}", MemberInfoBursh);
            switch (msg.Type)
            {
            case Chat.Message.Normal: AppendText(msg.Text, NormalTextBursh, 20); break;

            case Chat.Message.Command: AppendText(msg.Text, CommandTextBursh, 20); break;

            case Chat.Message.Reply: AppendText(msg.Text, ReplyTextBursh, 20); break;

            case Chat.Message.Image: AppendSubImage(msg.Text); AppendSub(20); break;
            }
        }
Esempio n. 13
0
    // HANDLERS

    void OnRowButtonDelegate(string rowId, GUIBase_Widget widget, object evt)
    {
        if (OnMessageAction == null)
        {
            return;
        }

        Chat.Message[] messages = m_Messages.ToArray();
        Chat.Message   message  = System.Array.Find(messages, obj => obj.Id == rowId);

        if (message.Id == rowId)
        {
            OnMessageAction(message, widget);
        }
    }
Esempio n. 14
0
    // PUBLIC METHODS

    public void AddMessage(Chat.Message message)
    {
        m_Messages.Enqueue(message);

        if (m_ScrollingTable != null && m_ScrollingOffset != 0)  //if the list is scrolled, this will prevent from another movement,
        {
            m_ScrollingTable.ChildButtonPressed(-1);             //so the user can read old messages
        }
        m_UnseenMessages++;

        if (OnMessageReceived != null)
        {
            OnMessageReceived(message);
        }
    }
Esempio n. 15
0
    bool OnIsMessageSelectable(Chat.Message message)
    {
        // filter out friends
        FriendList.FriendInfo friend = GameCloudManager.friendList.friends.Find(obj => obj.PrimaryKey == message.PrimaryKey);
        if (friend != null)
        {
            return(false);
        }

        // filter out pending friends
        FriendList.PendingFriendInfo pending = GameCloudManager.friendList.pendingFriends.Find(obj => obj.PrimaryKey == message.PrimaryKey);
        if (pending != null)
        {
            return(false);
        }

        // done
        return(true);
    }
Esempio n. 16
0
        public static MessageCreated AddMessageCreatedEventHandler <T>(
            this RoomWatcher <T> rw,
            Action <Chat.Message> callback)
            where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new MessageCreated();

            eventProcessor.OnEvent += id =>
            {
                var message = new Chat.Message(rw.Host, id, rw.Auth);

                callback(message);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
Esempio n. 17
0
        public static UserMentioned AddUserMentionedEventHandler <T>(
            this RoomWatcher <T> rw,
            Action <Chat.Message> callback)
            where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new UserMentioned();

            eventProcessor.OnEvent += um =>
            {
                var msg = new Chat.Message(rw.Host, um.MessageId, rw.Auth);

                callback(msg);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
Esempio n. 18
0
    internal void ReceiveMessage(string channel, string json)
    {
        try
        {
            Chat.Message message = JsonMapper.ToObject <Chat.Message>(json);
            message.Text = SwearWords.Filter(message.Text, true);

            ForwardMessage(channel, channel, message);
            ForwardMessage(CHANNEL_ALL, channel, message);
        }
        catch
        {
            if (Debug.isDebugBuild == true)
            {
                Debug.LogWarning("Chat.ReceiveMessage() :: json of invalid format received!");
                Debug.LogWarning("  channel = " + channel);
                Debug.LogWarning("  json = " + json);
            }
        }
    }
        public static MessageReplyCreated AddMessageReplyCreatedEventHandler <T>(
            this RoomWatcher <T> rw,
            Action <Chat.User, Chat.Message, Chat.Message> callback)
            where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new MessageReplyCreated();

            eventProcessor.OnEvent += mr =>
            {
                Chat.User    author    = null;
                Chat.Message message   = null;
                Chat.Message targetMsg = null;

                var tasks = new[]
                {
                    Task.Run(() =>
                    {
                        author = new Chat.User(rw.Host, mr.AuthorId, rw.Auth);
                    }),
                    Task.Run(() =>
                    {
                        message = new Chat.Message(rw.Host, mr.MessageId, rw.Auth);
                    }),
                    Task.Run(() =>
                    {
                        targetMsg = new Chat.Message(rw.Host, mr.TargetMessageId, rw.Auth);
                    })
                };

                Task.WaitAll(tasks);

                callback(author, message, targetMsg);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
Esempio n. 20
0
    bool IsRowSelectable(Chat.Message message)
    {
        // filter out local user
        if (message.PrimaryKey == CloudUser.instance.primaryKey)
        {
            return(false);
        }

        // filter out system messages
        // system messages has no primaryKey specified, just nickname
        if (string.IsNullOrEmpty(message.PrimaryKey) == true)
        {
            return(false);
        }

        // let someone else decide
        if (OnIsMessageSelectable != null)
        {
            return(OnIsMessageSelectable(message));
        }

        return(false);
    }
Esempio n. 21
0
        public static MessageEdited AddMessageEditedEventHandler <T>(
            this RoomWatcher <T> rw,
            Action <Chat.Message,
                    Chat.User> callback)
            where T : IWebSocket
        {
            callback.ThrowIfNull(nameof(callback));

            var eventProcessor = new MessageEdited();

            eventProcessor.OnEvent += me =>
            {
                Chat.Message message = null;
                Chat.User    user    = null;

                var tasks = new[]
                {
                    Task.Run(() =>
                    {
                        message = new Chat.Message(rw.Host, me.Message, rw.Auth);
                    }),
                    Task.Run(() =>
                    {
                        user = new Chat.User(rw.Host, me.EditedBy, rw.Auth);
                    })
                };

                Task.WaitAll(tasks);

                callback(message, user);
            };

            rw.EventRouter.AddProcessor(eventProcessor);

            return(eventProcessor);
        }
Esempio n. 22
0
        public static Task <bool> EditMessageAsync(this ActionScheduler actionScheduler, Chat.Message message, string newText)
        {
            message.ThrowIfNull(nameof(message));
            newText.ThrowIfNullOrEmpty(nameof(newText));

            return(EditMessageAsync(actionScheduler, message.Id, newText));
        }
Esempio n. 23
0
        public static Task <bool> DeleteMessageAsync(this ActionScheduler actionScheduler, Chat.Message message)
        {
            message.ThrowIfNull(nameof(message));

            return(DeleteMessageAsync(actionScheduler, message.Id));
        }
Esempio n. 24
0
        void OnResponseReceived(Response response)
        {
            if (response.Target == "/chat-logout") {
                if (OnChatLoggedOut != null)
                    OnChatLoggedOut();
            } else if (response.Target == "/chat-login") {
                Console.WriteLine("Logged into chat");
                chatSessionId = (string)response["chatSessionId"];

                if (OnChatLoggedIn != null)
                    OnChatLoggedIn();
            } else  if (response.Target == "/chat") {
                var chatType = (string)response["chatType"];
                if (chatType == "message_ack") {
                    Console.WriteLine("received ack");
                    return;
                }
                var from = (Dictionary<string, object>)response["from"];
                if (chatType == "wow_message") {
                    var message = new Chat.Message(response);

                    if (message.Type == Chat.Message.CHAT_MSG_TYPE_GUILD_MOTD) {
                        if (OnMessageMOTD != null)
                            OnMessageMOTD(this, message);
                    } else if (message.Type == Chat.Message.CHAT_MSG_TYPE_GUILD_CHAT) {
                        if (OnMessageGuildChat != null)
                            OnMessageGuildChat(this, message);
                    } else if (message.Type == Chat.Message.CHAT_MSG_TYPE_WHISPER) {
                        if (OnMessageWhisper != null)
                            OnMessageWhisper(this, message);
                    } else if (message.Type == Chat.Message.CHAT_MSG_TYPE_OFFICER_CHAT) {
                        if (OnMessageOfficerChat != null)
                            OnMessageOfficerChat(this, message);
                    } else {
                        Console.WriteLine("unhandled message type: " + message.Type);
                    }
                } else if (chatType == "wow_presence") {
                    var presence = new Chat.Presence(response);

                    if (OnPresenceChange != null)
                        OnPresenceChange(this, presence);
                } else {
                    Console.WriteLine("unhandled chat type: " + chatType);
                }
            }
        }
        public void ReceiveMessage(IAsyncResult ar)
        {
            //Read from client
            int bytesRead = 0;

            try
            {
                if (_client.Connected == true)
                {
                    lock (_client.GetStream())
                    {
                        bytesRead = _client.GetStream().EndRead(ar);
                    }

                    //Client disconnected
                    if (bytesRead < 1)
                    {
                        sessionEnded(_clientIP);
                        return;
                    }
                    else
                    {
                        //The message received from the remote client
                        string messageReceived = System.Text.Encoding.ASCII.GetString(data, 0, bytesRead);

                        // Deserialize the packet
                        Chat.Packet packet = new Chat.Packet();
                        packet = (Chat.Packet)Chat.Deserialize(messageReceived, packet.GetType());

                        Chat.Users recipients = new Chat.Users();
                        switch (packet.ID)
                        {
                        case Chat.MSGType.Join:


                            Chat.User usr = (Chat.User)packet.Content;
                            _clientName = usr.Name;

                            // Add the user set to receive a full list of user
                            recipients.List.Add(usr);

                            Chat.Users usrs = new Chat.Users();
                            foreach (DictionaryEntry c in AllClients)
                            {
                                Chat.User u = new Chat.User();
                                u.Name = ((Server)c.Value)._clientName;
                                usrs.List.Add(u);
                            }

                            Chat.Packet usersListPacket = new Chat.Packet();
                            usersListPacket.ID      = Chat.MSGType.ClientList;
                            usersListPacket.Content = usrs;


                            //Send the full user list to the user that just signed on
                            Broadcast(usersListPacket, recipients);

                            //Rebroadcast the original message to everyone that this user is online
                            Broadcast(packet, null);

                            break;

                        case Chat.MSGType.Message:
                            Chat.Message message = (Chat.Message)packet.Content;

                            foreach (string recipient in message.Reciptients)
                            {
                                Chat.User u = new Chat.User();
                                u.Name = recipient;
                                recipients.List.Add(u);
                            }

                            //Send the message to the recipients
                            Broadcast(packet, recipients);
                            break;

                        default:

                            break;
                        }
                    }

                    //Continue reading from the client
                    lock (_client.GetStream()) {
                        _client.GetStream().BeginRead(data, 0, Convert.ToInt32(_client.ReceiveBufferSize), ReceiveMessage, null);
                    }
                }
            } catch (Exception ex) {
                sessionEnded(_clientIP);
            }
        }
Esempio n. 26
0
 private async Task OnMessageReadyForDelivery(Chat.Message messageToDelivery, string senderId, string receiverId)
 {
     await Clients.Users(new[] { senderId, receiverId }).SendAsync("MessageReceived", messageToDelivery);
 }
Esempio n. 27
0
    void RefreshRows()
    {
        if (IsVisible == false)
        {
            return;
        }
        if (Parent == null)
        {
            return;
        }

        Transform trans = m_RowsContainer.transform;
        Vector3   pos   = trans.position;
        Vector3   scale = trans.lossyScale;

        float chatHeight = scale.y * m_RowsContainer.GetHeight();

        pos.y += chatHeight / 2;            //bottom row

        float rowMinY = pos.y - chatHeight; //upper row

        // get messages from buffer
        Chat.Message[] messages = m_Messages.ToArray();
        System.Array.Reverse(messages);

        int visibleRows = 0;

        for (int idx = 0; idx < m_MaxRows; ++idx)
        {
            int  idxScrolled = idx + m_ScrollingOffset;
            bool isVisible   = idxScrolled < messages.Length && pos.y >= rowMinY ? IsVisible : false;

            Row row = m_Rows[idx];

            if (isVisible == true)
            {
                Chat.Message message = messages[idxScrolled];

                row.IsSelectable = IsRowSelectable(message);
                row.IsVisible    = isVisible;
                row.Update(message);

                pos.y         -= 5.0f;
                pos.y         -= row.Height * scale.y;
                pos.y          = Mathf.RoundToInt(pos.y);
                row.Position   = pos;
                row.IsSelected = m_SelectedMessageId != null && row.Id == m_SelectedMessageId;

                if (pos.y < rowMinY)
                {
                    isVisible = false;
                }
                else
                {
                    visibleRows++;
                }
            }

            if (isVisible == false)
            {
                row.IsSelectable = false;
                row.IsSelected   = false;
                row.IsVisible    = false;
            }
        }

        m_UnseenMessages = 0;

        if (m_ScrollingTable != null)
        {
            if (visibleRows <= 0)
            {
                visibleRows = m_MaxRows;
            }

            m_ScrollingTable.numOfLines = visibleRows;
            m_ScrollingTable.MaxItems   = messages.Length;
            m_ScrollingTable.Widget.SetModify();
        }
    }
Esempio n. 28
0
    // PRIVATE METHODS

    void AddChatMessage(FriendInfo info, Chat.Message message)
    {
        bool active = m_Friends.FindIndex(obj => obj.PrimaryKey == info.PrimaryKey) == m_ActiveFriend;

        AddMessage(info, active, message);
    }
Esempio n. 29
0
        public static Task <int> CreateReplyAsync(this ActionScheduler actionScheduler, string message, Chat.Message messageToReplyTo)
        {
            message.ThrowIfNullOrEmpty(nameof(message));
            messageToReplyTo.ThrowIfNull(nameof(messageToReplyTo));

            return(CreateReplyAsync(actionScheduler, message, messageToReplyTo.Id));
        }
Esempio n. 30
0
 public static void SendMessage(string channel, Chat.Message message)
 {
     // Chat does not work in this version. The required underlying technology was released.
 }
        //Delegate and subroutine to update the textBox control
        //Friend Delegate Sub delUpdateHistory(ByVal str As String)
        internal void receivedData(Chat.Packet packet)
        {
            switch (packet.ID)
            {
            case Chat.Action.Join:

                Chat.Client usr = Chat.Client.Deserialize(packet.Content);
                lstUsers.Items.Add(usr.Name);

                break;

            case Chat.Action.ClientList:
                lstUsers.Items.Clear();

                Chat.Clients usrs = Chat.Clients.Deserialize(packet.Content);
                foreach (Chat.Client u in usrs.List)
                {
                    if (Client.Name != u.Name)
                    {
                        lstUsers.Items.Add(u.Name);
                    }
                }

                break;

            case Chat.Action.Message:
                //Read the message
                Chat.Message msg = Chat.Message.Deserialize(packet.Content);

                switch (msg.Type)
                {
                case Chat.MGSType.Chat:

                    break;

                case Chat.MGSType.PowerShell:

                    break;

                case Chat.MGSType.ComputerInfo:

                    break;
                }

                //Read the recipients...

                //Update the recipient's message history
                txtMessageHistory.Text += msg.Sender.Name + " - " + msg.MSG + Environment.NewLine;
                break;

            case Chat.Action.Disconnect:
                Chat.Client user = Chat.Client.Deserialize(packet.Content);

                //Remove the user from the listbox
                lstUsers.Items.Remove(user.Name);

                break;

            default:
                break;
            }
        }