Exemple #1
0
 void Grid_GridItems(object sender, GridItemsEventArgs e)
 {
     foreach (MapItem item in e.Items)
     {
         if (item is MapAgentLocation)
         {
             MapAgentLocation loc = (MapAgentLocation)item;
             lock (regionMapItems)
             {
                 if (!regionMapItems.ContainsKey(item.RegionHandle))
                 {
                     regionMapItems[loc.RegionHandle] = new List <MapItem>();
                 }
                 regionMapItems[loc.RegionHandle].Add(loc);
             }
             if (loc.AvatarCount > 0)
             {
                 needRepaint = true;
             }
         }
     }
 }
Exemple #2
0
        public void MonitorSim(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            string par = additionalArgs[0].Replace('_', ' ');

            OCBSession.Instance.MonitoredRegions.Add(par);

            /*GridRegion rg;
             * if(grid.Grid.GetGridRegion(additionalArgs[0], GridLayerType.Objects, out rg))
             * {
             *
             * }*/
            Thread X = new Thread(() =>
            {
                while (OCBSession.Instance.MonitoredRegions.Count != 0)
                {
                    Thread.Sleep(10000);

                    foreach (string region in OCBSession.Instance.MonitoredRegions)
                    {
                        GridRegion rg;
                        if (BotSession.Instance.grid.Grid.GetGridRegion(region, GridLayerType.Objects, out rg))
                        {
                            List <MapItem> MI = BotSession.Instance.grid.Grid.MapItems(rg.RegionHandle, GridItemType.AgentLocations, GridLayerType.Objects, 60000);
                            int actual        = 0;
                            foreach (MapItem mp in MI)
                            {
                                MapAgentLocation MAL = (MapAgentLocation)mp;
                                actual += MAL.AvatarCount;
                            }
                            MHE(Destinations.DEST_LOCAL, UUID.Zero, $"[{rg.Name}] Number of avatars: {actual}; Map TextureID: {rg.MapImageID.ToString()}");
                        }
                    }
                }
                MHE(Destinations.DEST_LOCAL, UUID.Zero, "No more monitored regions. Closing watchdog");
                return;
            });

            X.Start();
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            ulong regionHandle;

            int       argsUsed;
            Simulator CurSim = TryGetSim(args, out argsUsed) ?? Client.Network.CurrentSim;

            if (args.Length == 0)
            {
                regionHandle = CurSim.Handle;
            }
            else if (!(args.Length == 1 && UInt64.TryParse(args[0], out regionHandle)))
            {
                return(ShowUsage()); // " agentlocations [regionhandle]";
            }
            List <MapItem> items = Client.Grid.MapItems(regionHandle, GridItemType.AgentLocations,
                                                        GridLayerType.Objects, 1000 * 20);

            if (items != null)
            {
                StringBuilder ret = new StringBuilder();
                ret.AppendLine("Agent locations:");

                for (int i = 0; i < items.Count; i++)
                {
                    MapAgentLocation location = (MapAgentLocation)items[i];

                    ret.AppendLine(String.Format("{0} avatar(s) at {1},{2}", location.AvatarCount, location.LocalX,
                                                 location.LocalY));
                }

                return(Success(ret.ToString()));
            }
            else
            {
                return(Failure("failed to fetch agent locations"));
            }
        }
Exemple #4
0
        void Grid_GridItems(object sender, GridItemsEventArgs e)
        {
            lock (regionCacheSync)
            {
                hasRegionDataChanged = true;
            }

            int avatarCount = 0;

            if (e.Items.Count == 0)
            {
                return;
            }

            foreach (var mapItem in e.Items)
            {
                MapAgentLocation agentLocation = mapItem as MapAgentLocation;
                if (agentLocation == null)
                {
                    continue;
                }

                avatarCount += agentLocation.AvatarCount;
            }

            ulong regionHandle = e.Items[0].RegionHandle;

            lock (regionCacheSync)
            {
                if (!regionCacheTemp.ContainsKey(regionHandle))
                {
                    regionCacheTemp.Add(regionHandle, new RegionData());
                }

                regionCacheTemp[regionHandle].AgentCount = avatarCount;
            }
        }
Exemple #5
0
        public override string Execute(string[] args, UUID fromAgentID)
        {
            ulong regionHandle;

            if (args.Length == 0)
            {
                regionHandle = Client.Network.CurrentSim.Handle;
            }
            else if (!(args.Length == 1 && UInt64.TryParse(args[0], out regionHandle)))
            {
                return("Usage: agentlocations [regionhandle]");
            }

            List <MapItem> items = Client.Grid.MapItems(regionHandle, GridItemType.AgentLocations,
                                                        GridLayerType.Objects, 1000 * 20);

            if (items != null)
            {
                StringBuilder ret = new StringBuilder();
                ret.AppendLine("Agent locations:");

                for (int i = 0; i < items.Count; i++)
                {
                    MapAgentLocation location = (MapAgentLocation)items[i];

                    ret.AppendLine(String.Format("{0} avatar(s) at {1},{2}", location.AvatarCount, location.LocalX,
                                                 location.LocalY));
                }

                return(ret.ToString());
            }
            else
            {
                return("Failed to fetch agent locations");
            }
        }
Exemple #6
0
        private void MapControl_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(background);
            if (!centered)
            {
                return;
            }
            int h = Height, w = Width;

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            //Client.Grid.RequestMapLayer(GridLayerType.Objects);


            float localX, localY;
            ulong centerRegion = GlobalPosToRegionHandle(centerX, centerY, out localX, out localY);
            int   pixCenterRegionX = (int)(w / 2 - localX / zoom);
            int   pixCenterRegionY = (int)(h / 2 + localY / zoom);

            uint regX, regY;

            Utils.LongToUInts(centerRegion, out regX, out regY);
            regX /= regionSize;
            regY /= regionSize;

            int regLeft = (int)regX - ((int)(pixCenterRegionX / PixRegS) + 1);

            if (regLeft < 0)
            {
                regLeft = 0;
            }
            int regBottom = (int)regY - ((int)((Height - pixCenterRegionY) / PixRegS) + 1);

            if (regBottom < 0)
            {
                regBottom = 0;
            }
            int regXMax = 0, regYMax = 0;

            bool foundMyPos = false;
            int  myRegX = 0, myRegY = 0;

            for (int ry = regBottom; pixCenterRegionY - (ry - (int)regY) * PixRegS > 0; ry++)
            {
                regYMax = ry;
                for (int rx = regLeft; pixCenterRegionX - ((int)regX - rx) * PixRegS < Width; rx++)
                {
                    regXMax = rx;
                    int   pixX   = pixCenterRegionX - ((int)regX - rx) * PixRegS;
                    int   pixY   = pixCenterRegionY - (ry - (int)regY) * PixRegS;
                    ulong handle = Utils.UIntsToLong((uint)rx * regionSize, (uint)ry * regionSize);

                    lock (requestedLocations)
                    {
                        if (!requestedLocations.Contains(handle))
                        {
                            requestedLocations.Add(handle);
                            Client.Grid.RequestMapItems(handle, OpenMetaverse.GridItemType.AgentLocations, GridLayerType.Objects);
                        }
                    }

                    DrawRegion(g,
                               pixX,
                               pixY,
                               handle);

                    if (Client.Network.CurrentSim.Handle == handle)
                    {
                        foundMyPos = true;
                        myRegX     = pixX;
                        myRegY     = pixY;
                    }
                }
            }

            float ratio = (float)PixRegS / (float)regionSize;

            // Draw agent dots
            for (int ry = regBottom; ry <= regYMax; ry++)
            {
                for (int rx = regLeft; rx <= regXMax; rx++)
                {
                    int   pixX   = pixCenterRegionX - ((int)regX - rx) * PixRegS;
                    int   pixY   = pixCenterRegionY - (ry - (int)regY) * PixRegS;
                    ulong handle = Utils.UIntsToLong((uint)rx * regionSize, (uint)ry * regionSize);

                    lock (regionMapItems)
                    {
                        if (regionMapItems.ContainsKey(handle))
                        {
                            foreach (MapItem i in regionMapItems[handle])
                            {
                                if (i is MapAgentLocation)
                                {
                                    MapAgentLocation loc = (MapAgentLocation)i;
                                    if (loc.AvatarCount == 0)
                                    {
                                        continue;
                                    }
                                    int dotX = pixX + (int)((float)loc.LocalX * ratio);
                                    int dotY = pixY - (int)((float)loc.LocalY * ratio);
                                    for (int j = 0; j < loc.AvatarCount; j++)
                                    {
                                        g.FillEllipse(dotBrush, dotX, dotY - (j * 3), 7, 7);
                                        g.DrawEllipse(blackPen, dotX, dotY - (j * 3), 7, 7);
                                        //g.DrawImageUnscaled(Properties.Resources.map_dot, dotX, dotY - (j * 4));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (foundMyPos)
            {
                int myPosX = (int)(myRegX + Client.Self.SimPosition.X * ratio);
                int myPosY = (int)(myRegY - Client.Self.SimPosition.Y * ratio);

                Bitmap icn = Properties.Resources.my_map_pos;
                g.DrawImageUnscaled(icn,
                                    myPosX - icn.Width / 2,
                                    myPosY - icn.Height / 2
                                    );
            }

            int pixTargetX = (int)(Width / 2 + (targetX - centerX) * ratio);
            int pixTargetY = (int)(Height / 2 - (targetY - centerY) * ratio);

            if (pixTargetX >= 0 && pixTargetY < Width &&
                pixTargetY >= 0 && pixTargetY < Height)
            {
                Bitmap icn = Properties.Resources.target_map_pos;
                g.DrawImageUnscaled(icn,
                                    pixTargetX - icn.Width / 2,
                                    pixTargetY - icn.Height / 2
                                    );
                if (!string.IsNullOrEmpty(targetRegion.Name))
                {
                    string label = string.Format("{0} ({1:0}, {2:0})", targetRegion.Name, targetX % regionSize, targetY % regionSize);
                    if (!string.IsNullOrEmpty(targetParcelName))
                    {
                        label += Environment.NewLine + targetParcelName;
                    }
                    Print(g, pixTargetX - 8, pixTargetY + 14, label, new SolidBrush(Color.White));
                }
            }

            if (!dragging)
            {
                string block = string.Format("{0},{1},{2},{3}", (ushort)regLeft, (ushort)regBottom, (ushort)regXMax, (ushort)regYMax);
                lock (requestedBlocks)
                {
                    if (!requestedBlocks.Contains(block))
                    {
                        requestedBlocks.Add(block);
                        Client.Grid.RequestMapBlocks(GridLayerType.Objects, (ushort)regLeft, (ushort)regBottom, (ushort)regXMax, (ushort)regYMax, true);
                    }
                }
            }
        }