public LocalChannel(OpenMetaverse.GridClient client, IIdentityMapper mapper)
        {
            this.client = client;
            this.mapper = mapper;
            this.nearby = new Dictionary<string, Dictionary<UUID, ChannelMembership>>();

            var selfmember = new ChannelMembership();
            selfmember.IsOperator = false;
            selfmember.Position = PositionCategory.Whisper;
            selfmember.Subject = mapper.MapUser(client.Self.AgentID, client.Self.Name);

            var thissimlist = new Dictionary<UUID, ChannelMembership>();
            thissimlist.Add(client.Self.AgentID, selfmember);
            nearby.Add(client.Network.CurrentSim.Name, thissimlist);

            client.Grid.CoarseLocationUpdate += OnLocationUpdate;
            client.Self.ChatFromSimulator += OnLocalChat;
        }
Esempio n. 2
0
        public LocalChannel(OpenMetaverse.GridClient client, IIdentityMapper mapper)
        {
            this.client = client;
            this.mapper = mapper;
            this.nearby = new Dictionary <string, Dictionary <UUID, ChannelMembership> >();

            var selfmember = new ChannelMembership();

            selfmember.IsOperator = false;
            selfmember.Position   = PositionCategory.Whisper;
            selfmember.Subject    = mapper.MapUser(client.Self.AgentID, client.Self.Name);

            var thissimlist = new Dictionary <UUID, ChannelMembership>();

            thissimlist.Add(client.Self.AgentID, selfmember);
            nearby.Add(client.Network.CurrentSim.Name, thissimlist);

            client.Grid.CoarseLocationUpdate += OnLocationUpdate;
            client.Self.ChatFromSimulator    += OnLocalChat;
        }
Esempio n. 3
0
        public void OnLocationUpdate(object sender, CoarseLocationUpdateEventArgs e)
        {
            var evt = new ChannelMemberChangeEventArgs();
            Dictionary <UUID, ChannelMembership> nearbyAvatars;

            if (e.Simulator.Name != client.Network.CurrentSim.Name)
            {
                return;
            }

            if (!nearby.TryGetValue(e.Simulator.Name, out nearbyAvatars))
            {
                nearbyAvatars = new Dictionary <UUID, ChannelMembership>();
                nearby.Add(e.Simulator.Name, nearbyAvatars);
            }

            foreach (var i in e.NewEntries)
            {
                if (i == client.Self.AgentID)
                {
                    continue;
                }

                var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                detail.Subject     = mapper.MapUser(i);
                detail.IsOperator  = false;
                detail.WasOperator = false;
                detail.NewPosition = CategorisePosition(i, e);
                detail.OldPosition = PositionCategory.Distant;
                evt.NewMembers.Add(detail);

                var membership = new ChannelMembership();
                membership.Subject    = detail.Subject;
                membership.IsOperator = false;
                membership.Position   = CategorisePosition(i, e);
                if (nearbyAvatars.ContainsKey(i))
                {
                    nearbyAvatars[i] = membership;
                }
                else
                {
                    nearbyAvatars.Add(i, membership);
                }
            }

            foreach (var i in e.RemovedEntries)
            {
                if (i == client.Self.AgentID)
                {
                    continue;
                }

                var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                if (nearbyAvatars.ContainsKey(i))
                {
                    detail.Subject     = nearbyAvatars[i].Subject;
                    detail.IsOperator  = false;
                    detail.WasOperator = false;
                    detail.NewPosition = PositionCategory.Distant;
                    detail.OldPosition = nearbyAvatars[i].Position;
                    evt.RemovedMembers.Add(detail);

                    nearbyAvatars.Remove(i);
                }
            }

            foreach (var i in nearbyAvatars)
            {
                if (i.Key == client.Self.AgentID)
                {
                    continue;
                }

                var newpos = CategorisePosition(i.Key, e);
                if (i.Value.Position != newpos)
                {
                    var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                    detail.Subject     = nearbyAvatars[i.Key].Subject;
                    detail.IsOperator  = false;
                    detail.WasOperator = false;
                    detail.NewPosition = newpos;
                    detail.OldPosition = nearbyAvatars[i.Key].Position;
                    evt.ChangedMembers.Add(detail);
                    nearbyAvatars[i.Key].Position = newpos;
                }
            }

            if (!evt.HasChanges)
            {
                return;
            }

            lock (syncRoot)
            {
                if (state != ChannelState.Connected)
                {
                    state = ChannelState.Connected;
                    joinTask.SetResult(true);
                }
            }

            if (this.MembersChanged != null)
            {
                MembersChanged(this, evt);
            }
        }
        public void OnLocationUpdate(object sender, CoarseLocationUpdateEventArgs e)
        {
            var evt = new ChannelMemberChangeEventArgs();
            Dictionary<UUID, ChannelMembership> nearbyAvatars;

            if (e.Simulator.Name != client.Network.CurrentSim.Name) return;

            if(!nearby.TryGetValue(e.Simulator.Name, out nearbyAvatars))
            {
                nearbyAvatars = new Dictionary<UUID, ChannelMembership>();
                nearby.Add(e.Simulator.Name, nearbyAvatars);
            }

            foreach(var i in e.NewEntries)
            {
                if (i == client.Self.AgentID) { continue; }

                var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                detail.Subject = mapper.MapUser(i);
                detail.IsOperator = false;
                detail.WasOperator = false;
                detail.NewPosition = CategorisePosition(i, e);
                detail.OldPosition = PositionCategory.Distant;
                evt.NewMembers.Add(detail);

                var membership = new ChannelMembership();
                membership.Subject = detail.Subject;
                membership.IsOperator = false;
                membership.Position = CategorisePosition(i, e);
                if (nearbyAvatars.ContainsKey(i))
                {
                    nearbyAvatars[i] = membership;
                }
                else
                {
                    nearbyAvatars.Add(i, membership);
                }
            }

            foreach(var i in e.RemovedEntries)
            {
                if (i == client.Self.AgentID) { continue; }

                var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                if (nearbyAvatars.ContainsKey(i))
                {
                    detail.Subject = nearbyAvatars[i].Subject;
                    detail.IsOperator = false;
                    detail.WasOperator = false;
                    detail.NewPosition = PositionCategory.Distant;
                    detail.OldPosition = nearbyAvatars[i].Position;
                    evt.RemovedMembers.Add(detail);

                    nearbyAvatars.Remove(i);
                }
            }

            foreach(var i in nearbyAvatars)
            {
                if (i.Key == client.Self.AgentID) { continue; }

                var newpos = CategorisePosition(i.Key, e);
                if (i.Value.Position != newpos)
                {
                    var detail = new ChannelMemberChangeEventArgs.ChangeDetails();
                    detail.Subject = nearbyAvatars[i.Key].Subject;
                    detail.IsOperator = false;
                    detail.WasOperator = false;
                    detail.NewPosition = newpos;
                    detail.OldPosition = nearbyAvatars[i.Key].Position;
                    evt.ChangedMembers.Add(detail);
                    nearbyAvatars[i.Key].Position = newpos;
                }
            }

            if (!evt.HasChanges) { return; }

            lock (syncRoot)
            {
                if (state != ChannelState.Connected)
                {
                    state = ChannelState.Connected;
                    joinTask.SetResult(true);
                }
            }

            if(this.MembersChanged != null)
            {
                MembersChanged(this, evt);
            }
        }