Exemplo n.º 1
0
        public void Session_Update(RudpSession session)
        {
            if (!ActiveUsers.Contains(session.UserID))
            {
                return;
            }

            IMStatus status = null;

            if (!IMMap.SafeTryGetValue(session.UserID, out status))
            {
                return;
            }


            if (session.Status == SessionStatus.Active)
            {
                // needs to be set here as well be cause we don't receive a keep alive from remote host on connect
                status.SetTTL(session.ClientID, SessionTimeout * 2);

                session.SendData(ServiceID, 0, new IMKeepAlive());
            }

            Update(status);
        }
Exemplo n.º 2
0
        void Session_Data(RudpSession session, byte[] data)
        {
            IMStatus status = OpenStatus(session.UserID);


            G2Header root = new G2Header(data);

            if (G2Protocol.ReadPacket(root))
            {
                if (root.Name == IMPacket.Message)
                {
                    MessageData message = MessageData.Decode(root);

                    if (message.TargetID != 0)
                    {
                        Debug.Assert(session.UserID == Core.UserID);
                        if (session.UserID != Core.UserID)
                        {
                            return;
                        }

                        status = OpenStatus(message.TargetID);
                    }

                    ProcessMessage(status, new InstantMessage(Core, session, message));
                }

                if (root.Name == IMPacket.Alive)
                {
                    status.SetTTL(session.ClientID, SessionTimeout * 2);
                }
            }
        }
Exemplo n.º 3
0
        private IMStatus OpenStatus(ulong user)
        {
            IMStatus status;

            if (!IMMap.SafeTryGetValue(user, out status))
            {
                status = new IMStatus(user);
                IMMap.SafeAdd(user, status);
            }

            return(status);
        }
Exemplo n.º 4
0
        public void Trust_Update(OpTrust trust)
        {
            if (!ActiveUsers.Contains(trust.UserID))
            {
                return;
            }

            IMStatus status = null;

            if (IMMap.SafeTryGetValue(trust.UserID, out status))
            {
                Update(status);
            }
        }
Exemplo n.º 5
0
        /*crit not thread locked/protected
         * private List<IM_View> GetViews()
         * {
         *  List<IM_View> views = new List<IM_View>();
         *
         *  if (MessageUpdate != null)
         *      foreach (Delegate func in MessageUpdate.GetInvocationList())
         *          if (func.Target is IM_View)
         *              views.Add((IM_View)func.Target);
         *
         *  return views;
         * }*/

        public void Connect(ulong user)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(() => Connect(user));
                return;
            }

            IMStatus status = OpenStatus(user);

            foreach (ClientInfo loc in Core.Locations.GetClients(user))
            {
                Network.RudpControl.Connect(loc.Data);
            }

            Update(status);
        }
Exemplo n.º 6
0
        void Core_SecondTimer()
        {
            // need keep alives because someone else might have IM window open while we have it closed

            // send keep alives every x secs
            if (Core.TimeNow.Second % SessionTimeout == 0)
            {
                foreach (var userID in ActiveUsers)
                {
                    IMStatus status = null;

                    if (IMMap.SafeTryGetValue(userID, out status))
                    {
                        foreach (ushort client in status.TTL.Keys)
                        {
                            if (status.TTL[client].Value > 0)
                            {
                                RudpSession session = Network.RudpControl.GetActiveSession(userID, client);

                                if (session != null)
                                {
                                    status.TTL[client].Value = SessionTimeout * 2;
                                    session.SendData(ServiceID, 0, new IMKeepAlive());
                                }
                            }
                        }
                    }
                }
            }

            // timeout sessions
            IMMap.LockReading(delegate()
            {
                foreach (IMStatus status in IMMap.Values)
                {
                    foreach (BoxInt ttl in status.TTL.Values)
                    {
                        if (ttl.Value > 0)
                        {
                            ttl.Value--;
                        }
                    }
                }
            });
        }
Exemplo n.º 7
0
        void IM_StatusUpdate(ulong id)
        {
            if (id != UserID)
            {
                return;
            }

            CheckBackColor();

            IMStatus status = null;

            if (!IM.IMMap.SafeTryGetValue(id, out status))
            {
                return;
            }

            // connected to jonn smith @home, @work
            // connecting to john smith
            // disconnected from john smith

            StatusLabel.Text = status.Text;

            if (status.Away)
            {
                StatusImage.Image = IMRes.yellowled;
            }
            if (status.Connected)
            {
                StatusImage.Image = IMRes.greenled;
            }
            else if (status.Connecting)
            {
                StatusImage.Image = IMRes.yellowled;
            }
            else
            {
                StatusImage.Image = IMRes.redled;
            }

            if (RemoteName != Core.GetName(id))
            {
                UpdateName();
                DisplayLog();
            }
        }
Exemplo n.º 8
0
        public void Location_Update(LocationData location)
        {
            if (!ActiveUsers.Contains(location.UserID))
            {
                return;
            }

            IMStatus status = null;

            if (!IMMap.SafeTryGetValue(location.UserID, out status))
            {
                return;
            }

            Network.RudpControl.Connect(location);

            Update(status);
        }
Exemplo n.º 9
0
        public void SendMessage(ulong key, string text, TextFormat format)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { SendMessage(key, text, format); });
                return;
            }

            if (text == "***debug***")
            {
                Core.DebugWindowsActive = true;
                text = "activated";
            }

            IMStatus status = null;

            if (!IMMap.SafeTryGetValue(key, out status))
            {
                return;
            }


            bool        sent    = false;
            MessageData message = new MessageData(text, format);

            foreach (RudpSession session in Network.RudpControl.GetActiveSessions(key))
            {
                sent = true; // only sent if target receies
                session.SendData(ServiceID, 0, message);
            }

            // send copies to other selves running
            message.TargetID = key;
            foreach (RudpSession session in Network.RudpControl.GetActiveSessions(Core.UserID))
            {
                session.SendData(ServiceID, 0, message);
            }

            ProcessMessage(status, new InstantMessage(Core, text, format)
            {
                Sent = sent
            });
        }
Exemplo n.º 10
0
        private void DisplayLog()
        {
            MessageTextBox.Clear();

            IMStatus status = null;

            if (!IM.IMMap.SafeTryGetValue(UserID, out status))
            {
                return;
            }

            status.MessageLog.LockReading(delegate()
            {
                foreach (InstantMessage message in status.MessageLog)
                {
                    IM_MessageUpdate(UserID, message);
                }
            });
        }
Exemplo n.º 11
0
        public void ProcessMessage(IMStatus status, InstantMessage message)
        {
            if (Core.Buddies.IgnoreList.SafeContainsKey(message.UserID))
            {
                return;
            }

            // log message - locks both dictionary and embedded list form reading
            status.MessageLog.SafeAdd(message);

            if (ActiveUsers.Contains(status.UserID))
            {
                Core.RunInGuiThread(MessageUpdate, status.UserID, message);
            }
            else
            {
                Core.RunInGuiThread(CreateView, status.UserID);
            }

            Update(status);
        }
Exemplo n.º 12
0
        private void Update(IMStatus status)
        {
            ulong key = status.UserID;

            // connected to jonn smith @home, @work
            // connecting to john smith
            // disconnected from john smith

            string places = "";

            status.Connected = false;
            status.Connecting = false;
            status.Away = false;
            string awayMessage = "";
            int activeCount = 0;

            foreach(RudpSession session in Network.RudpControl.SessionMap.Values.Where(s => s.UserID == key))
            {
                if (session.Status == SessionStatus.Closed)
                    continue;

                status.Connecting = true;

                if (session.Status == SessionStatus.Active)
                {
                    status.Connected = true;

                    ClientInfo info = Locations.GetLocationInfo(key, session.ClientID);

                    awayMessage = "";
                    if (info != null)
                        if (info.Data.Away)
                        {
                            status.Away = true;
                            awayMessage = " " + info.Data.AwayMessage;
                        }

                    activeCount++;
                    places += " @" + Locations.GetLocationName(key, session.ClientID) + awayMessage + ",";
                }
            }

            if (status.Away)
            {
                status.Text = Core.GetName(key) + " is Away ";

                if (activeCount > 1)
                    status.Text += places.TrimEnd(',');
                else
                    status.Text += awayMessage;
            }

            else if (status.Connected)
            {
                status.Text = "Connected to " + Core.GetName(key);

                if (activeCount > 1)
                    status.Text += places.TrimEnd(',');
            }

            else if(status.Connecting)
                status.Text = "Connecting to " + Core.GetName(key);

            else
                status.Text = "Disconnected from " + Core.GetName(key);

            Core.RunInGuiThread(StatusUpdate, status.UserID);
        }
Exemplo n.º 13
0
        private IMStatus OpenStatus(ulong user)
        {
            IMStatus status;

            if (!IMMap.SafeTryGetValue(user, out status))
            {
                status = new IMStatus(user);
                IMMap.SafeAdd(user, status);
            }

            return status;
        }
Exemplo n.º 14
0
        public void ProcessMessage(IMStatus status, InstantMessage message)
        {
            if (Core.Buddies.IgnoreList.SafeContainsKey(message.UserID))
                return;

            // log message - locks both dictionary and embedded list form reading
            status.MessageLog.SafeAdd(message);

            if(ActiveUsers.Contains(status.UserID))
                Core.RunInGuiThread(MessageUpdate, status.UserID, message);
            else
                Core.RunInGuiThread(CreateView, status.UserID);

            Update(status);
        }
Exemplo n.º 15
0
        private void Update(IMStatus status)
        {
            ulong key = status.UserID;

            // connected to jonn smith @home, @work
            // connecting to john smith
            // disconnected from john smith

            string places = "";


            status.Connected  = false;
            status.Connecting = false;
            status.Away       = false;
            string awayMessage = "";
            int    activeCount = 0;

            foreach (RudpSession session in Network.RudpControl.SessionMap.Values.Where(s => s.UserID == key))
            {
                if (session.Status == SessionStatus.Closed)
                {
                    continue;
                }

                status.Connecting = true;

                if (session.Status == SessionStatus.Active)
                {
                    status.Connected = true;

                    ClientInfo info = Locations.GetLocationInfo(key, session.ClientID);

                    awayMessage = "";
                    if (info != null)
                    {
                        if (info.Data.Away)
                        {
                            status.Away = true;
                            awayMessage = " " + info.Data.AwayMessage;
                        }
                    }

                    activeCount++;
                    places += " @" + Locations.GetLocationName(key, session.ClientID) + awayMessage + ",";
                }
            }

            if (status.Away)
            {
                status.Text = Core.GetName(key) + " is Away ";

                if (activeCount > 1)
                {
                    status.Text += places.TrimEnd(',');
                }
                else
                {
                    status.Text += awayMessage;
                }
            }

            else if (status.Connected)
            {
                status.Text = "Connected to " + Core.GetName(key);

                if (activeCount > 1)
                {
                    status.Text += places.TrimEnd(',');
                }
            }

            else if (status.Connecting)
            {
                status.Text = "Connecting to " + Core.GetName(key);
            }

            else
            {
                status.Text = "Disconnected from " + Core.GetName(key);
            }


            Core.RunInGuiThread(StatusUpdate, status.UserID);
        }