Example #1
0
        public RegionSearchResultItem(SleekInstance instance, GridRegion region, ListBox listBox)
        {
            this.instance = instance;
            netcom = this.instance.Netcom;
            client = this.instance.Client;
            this.region = region;
            this.listBox = listBox;

            agentCountWorker = new BackgroundWorker();
            agentCountWorker.DoWork += new DoWorkEventHandler(agentCountWorker_DoWork);
            agentCountWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(agentCountWorker_RunWorkerCompleted);

            AddClientEvents();
        }
Example #2
0
        /// <summary>
        /// Get grid region information using the region name, this function
        /// will block until it can find the region or gives up
        /// </summary>
        /// <param name="name">Name of sim you're looking for</param>
        /// <param name="layer">Layer that you are requesting</param>
        /// <param name="region">Will contain a GridRegion for the sim you're
        /// looking for if successful, otherwise an empty structure</param>
        /// <returns>True if the GridRegion was successfully fetched, otherwise
        /// false</returns>
        public bool GetGridRegion(string name, GridLayerType layer, out GridRegion region)
        {
            if (String.IsNullOrEmpty(name))
            {
                Logger.Log("GetGridRegion called with a null or empty region name", Helpers.LogLevel.Error, Client);
                region = new GridRegion();
                return(false);
            }

            // All lookups are done using lowercase sim names
            name = name.ToLower();

            if (Regions.ContainsKey(name))
            {
                // We already have this GridRegion structure
                region = Regions[name];
                return(true);
            }
            else
            {
                AutoResetEvent     regionEvent = new AutoResetEvent(false);
                GridRegionCallback callback    =
                    delegate(GridRegion gridRegion)
                {
                    if (gridRegion.Name == name)
                    {
                        regionEvent.Set();
                    }
                };
                OnGridRegion += callback;

                RequestMapRegion(name, layer);
                regionEvent.WaitOne(Client.Settings.MAP_REQUEST_TIMEOUT, false);

                OnGridRegion -= callback;

                if (Regions.ContainsKey(name))
                {
                    // The region was found after our request
                    region = Regions[name];
                    return(true);
                }
                else
                {
                    Logger.Log("Couldn't find region " + name, Helpers.LogLevel.Warning, Client);
                    region = new GridRegion();
                    return(false);
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="simName"></param>
        /// <param name="position"></param>
        /// <param name="lookAt"></param>
        /// <returns></returns>
        public bool Teleport(string simName, LLVector3 position, LLVector3 lookAt)
        {
            int attempts = 0;

            TeleportStat = TeleportStatus.None;

            simName = simName.ToLower();

            GridRegion region = Client.Grid.GetGridRegion(simName);

            if (region != null)
            {
                return(Teleport(region.RegionHandle, position, lookAt));
            }
            else
            {
                while (attempts++ < 5)
                {
                    region = Client.Grid.GetGridRegion(simName);

                    if (region != null)
                    {
                        return(Teleport(region.RegionHandle, position, lookAt));
                    }
                    else
                    {
                        // Request the region info again
                        Client.Grid.AddSim(simName);

                        System.Threading.Thread.Sleep(1000);
                    }
                }
            }

            if (OnTeleport != null)
            {
                TeleportMessage = "Unable to resolve name: " + simName;
                TeleportStat    = TeleportStatus.Failed;
                OnTeleport(TeleportMessage, TeleportStat);
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// Populate Grid info based on data from MapBlockReplyPacket
        /// </summary>
        /// <param name="packet">Incoming MapBlockReplyPacket packet</param>
        /// <param name="simulator">Unused</param>
        private void MapBlockReplyHandler(Packet packet, Simulator simulator)
        {
            GridRegion          region;
            MapBlockReplyPacket map = (MapBlockReplyPacket)packet;

            foreach (MapBlockReplyPacket.DataBlock block in map.Data)
            {
                if (block.X != 0 && block.Y != 0)
                {
                    region = new GridRegion();

                    region.X            = block.X;
                    region.Y            = block.Y;
                    region.Name         = Helpers.FieldToString(block.Name);
                    region.RegionFlags  = block.RegionFlags;
                    region.WaterHeight  = block.WaterHeight;
                    region.Agents       = block.Agents;
                    region.Access       = block.Access;
                    region.MapImageID   = block.MapImageID;
                    region.RegionHandle = Helpers.UIntsToLong((uint)region.X * (uint)256, (uint)region.Y * (uint)256);

                    lock (Regions)
                    {
                        Regions[region.Name.ToLower()] = region;
                    }

                    lock (RegionsByHandle)
                    {
                        RegionsByHandle[region.RegionHandle] = region;
                    }

                    if (OnRegionAddInternal != null && BeginGetGridRegionName == region.Name.ToLower())
                    {
                        OnRegionAddInternal(region);
                    }
                    else if (OnRegionAdd != null)
                    {
                        OnRegionAdd(region);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Get grid region information using the region name, this function
        /// will block until it can find the region or gives up
        /// </summary>
        /// <param name="name">Name of sim you're looking for</param>
        /// <param name="layer">Layer that you are requesting</param>
        /// <param name="region">Will contain a GridRegion for the sim you're
        /// looking for if successful, otherwise an empty structure</param>
        /// <returns>True if the GridRegion was successfully fetched, otherwise
        /// false</returns>
        public bool GetGridRegion(string name, GridLayerType layer, out GridRegion region)
        {
            if (String.IsNullOrEmpty(name))
            {
                Client.Log("GetGridRegion called with a null or empty region name", Helpers.LogLevel.Error);
                region = new GridRegion();
                return false;
            }

            // All lookups are done using lowercase sim names
            name = name.ToLower();

            if (Regions.ContainsKey(name))
            {
                // We already have this GridRegion structure
                region = Regions[name];
                return true;
            }
            else
            {
                AutoResetEvent regionEvent = new AutoResetEvent(false);
                GridRegionCallback callback =
                    delegate(GridRegion gridRegion)
                    {
                        if (gridRegion.Name == name)
                            regionEvent.Set();
                    };
                OnGridRegion += callback;

                RequestMapRegion(name, layer);
                regionEvent.WaitOne(Client.Settings.MAP_REQUEST_TIMEOUT, false);

                OnGridRegion -= callback;

                if (Regions.ContainsKey(name))
                {
                    // The region was found after our request
                    region = Regions[name];
                    return true;
                }
                else
                {
                    Client.Log("Couldn't find region " + name, Helpers.LogLevel.Warning);
                    region = new GridRegion();
                    return false;
                }
            }
        }
Example #6
0
 private bool Equals(GridRegion region)
 {
     return (this.X == region.X && this.Y == region.Y);
 }
        /// <summary>
        /// Populate Grid info based on data from MapBlockReplyPacket
        /// </summary>
        /// <param name="packet">Incoming MapBlockReplyPacket packet</param>
        /// <param name="simulator">Unused</param>
        private void MapBlockReplyHandler(Packet packet, Simulator simulator)
        {
            GridRegion region;
            MapBlockReplyPacket map = (MapBlockReplyPacket)packet;

            foreach (MapBlockReplyPacket.DataBlock block in map.Data)
            {
                if (block.X != 0 && block.Y != 0)
                {
                    region = new GridRegion();

                    region.X = block.X;
                    region.Y = block.Y;
                    region.Name = Helpers.FieldToString(block.Name);
                    region.RegionFlags = block.RegionFlags;
                    region.WaterHeight = block.WaterHeight;
                    region.Agents = block.Agents;
                    region.Access = block.Access;
                    region.MapImageID = block.MapImageID;
                    region.RegionHandle = Helpers.UIntsToLong((uint)region.X * (uint)256, (uint)region.Y * (uint)256);

                    lock (Regions)
                    {
                        Regions[region.Name.ToLower()] = region;
                    }

                    lock (RegionsByHandle)
                    {
                        RegionsByHandle[region.RegionHandle] = region;
                    }

                    if (OnRegionAddInternal != null && BeginGetGridRegionName == region.Name.ToLower())
                    {
                        OnRegionAddInternal(region);
                    }
                    else if (OnRegionAdd != null)
                    {
                        OnRegionAdd(region);
                    }
                }
            }
        }
Example #8
0
 private bool Equals(GridRegion region)
 {
     return(this.X == region.X && this.Y == region.Y);
 }
Example #9
0
        /// <summary>
        /// Get grid region information using the region name, this function
        /// will block until it can find the region or gives up
        /// </summary>
        /// <param name="name">Name of sim you're looking for</param>
        /// <param name="layer">Layer that you are requesting</param>
        /// <param name="region">Will contain a GridRegion for the sim you're
        /// looking for if successful, otherwise an empty structure</param>
        /// <returns>True if the GridRegion was successfully fetched, otherwise
        /// false</returns>
        public bool GetGridRegion(string name, GridLayerType layer, out GridRegion region)
        {
            name = name.ToLower();

            if (Regions.ContainsKey(name))
            {
                // We already have this GridRegion structure
                region = Regions[name];
                return true;
            }
            else
            {
                ManualResetEvent requestEvent = new ManualResetEvent(false);

                if (RequestingRegions.ContainsKey(name))
                {
                    Client.Log("GetGridRegion called for " + name + " multiple times, ignoring", 
                        Helpers.LogLevel.Warning);
                    region = new GridRegion();
                    return false;
                }
                else
                {
                    // Add this region request to the list of requests we are tracking
                    lock (RequestingRegions) RequestingRegions.Add(name, requestEvent);
                }

                // Make the request
                RequestMapRegion(name, layer);

                // Wait until an answer is retrieved
                requestEvent.WaitOne(Client.Settings.MAP_REQUEST_TIMEOUT, false);

                // Remove the dictionary entry for this lookup
                lock (RequestingRegions) RequestingRegions.Remove(name);

                if (Regions.ContainsKey(name))
                {
                    // The region was found after our request
                    region = Regions[name];
                    return true;
                }
                else
                {
                    Client.Log("Couldn't find region " + name, Helpers.LogLevel.Warning);
                    region = new GridRegion();
                    return false;
                }
            }
        }
 private void GridRegionHandler(GridRegion region)
 {
     if (region.Name.ToLower() == Sim.ToLower())
     {
         RegionHandle = region.RegionHandle;
         Console.WriteLine("Resolved " + Sim + " to region handle " + RegionHandle);
     }
 }
Example #11
0
        /// <summary>
        /// Populate Grid info based on data from MapBlockReplyPacket
        /// </summary>
        /// <param name="packet">Incoming MapBlockReplyPacket packet</param>
        /// <param name="simulator">Unused</param>
		private void MapBlockReplyHandler(Packet packet, Simulator simulator) 
		{
			GridRegion region;
            MapBlockReplyPacket map = (MapBlockReplyPacket)packet;

            foreach (MapBlockReplyPacket.DataBlock block in map.Data)
            {
                if (block.X != 0 && block.Y != 0)
                {
                    region = new GridRegion();

                    region.X = block.X;
                    region.Y = block.Y;
                    region.Name = Helpers.FieldToUTF8String(block.Name);
                    // RegionFlags seems to always be zero here?
                    region.RegionFlags = (Simulator.RegionFlags)block.RegionFlags;
                    region.WaterHeight = block.WaterHeight;
                    region.Agents = block.Agents;
                    region.Access = (Simulator.SimAccess)block.Access;
                    region.MapImageID = block.MapImageID;
                    region.RegionHandle = Helpers.UIntsToLong((uint)(region.X * 256), (uint)(region.Y * 256));

                    lock (Regions) Regions[region.Name.ToLower()] = region;
					lock (RegionsByHandle) RegionsByHandle[region.RegionHandle] = region;
                    lock (RequestingRegions)
                    {
                        if (RequestingRegions.ContainsKey(region.Name.ToLower()))
                            RequestingRegions[region.Name.ToLower()].Set();
                    }

                    if (OnRegionAdd != null)
                    {
                        try { OnRegionAdd(region); }
                        catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                    }
                }
            }
		}
Example #12
0
 //Separate thread
 private void Grid_OnGridRegion(GridRegion region)
 {
     BeginInvoke(new GridManager.GridRegionCallback(RegionSearchResult), new object[] { region });
 }
Example #13
0
 //UI thread
 private void RegionSearchResult(GridRegion region)
 {
     RegionSearchResultItem item = new RegionSearchResultItem(instance, region, lbxRegionSearch);
     int index = lbxRegionSearch.Items.Add(item);
     item.ListIndex = index;
 }