Ejemplo n.º 1
0
        public RadegastInstance(GridClient client0)
        {
            // incase something else calls GlobalInstance while we are loading
            globalInstance = this;

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException += HandleThreadException;
            }

            client = client0;

            // Initialize current time zone, and mark when we started
            GetWorldTimeZone();
            StartupTimeUTC = DateTime.UtcNow;

            // Are we running mono?
            monoRuntime = Type.GetType("Mono.Runtime") != null;

            netcom = new RadegastNetcom(this);
            state = new StateManager(this);
            mediaManager = new MediaManager(this);
            commandsManager = new CommandsManager(this);
            ContextActionManager = new ContextActionsManager(this);
            movement = new RadegastMovement(this);

            InitializeLoggingAndConfig();
            InitializeClient(client);

            rlv = new RLVManager(this);
            gridManager = new GridManager(this);
            gridManager.LoadGrids();

            names = new NameManager(this);

            mainForm = new frmMain(this);
            mainForm.InitializeControls();

            mainForm.Load += new EventHandler(mainForm_Load);
            pluginManager = new PluginManager(this);
            pluginManager.ScanAndLoadPlugins();
        }
Ejemplo n.º 2
0
        public void CleanUp()
        {
            if (names != null)
            {
                names.Dispose();
                names = null;
            }

            if (gridManager != null)
            {
                gridManager.Dispose();
                gridManager = null;
            }

            if (rlv != null)
            {
                rlv.Dispose();
                rlv = null;
            }

            if (client != null)
            {
                UnregisterClientEvents(client);
            }

            if (pluginManager != null)
            {
                pluginManager.Dispose();
                pluginManager = null;
            }

            if (movement != null)
            {
                movement.Dispose();
                movement = null;
            }
            if (commandsManager != null)
            {
                commandsManager.Dispose();
                commandsManager = null;
            }
            if (ContextActionManager != null)
            {
                ContextActionManager.Dispose();
                ContextActionManager = null;
            }
            if (mediaManager != null)
            {
                mediaManager.Dispose();
                mediaManager = null;
            }
            if (state != null)
            {
                state.Dispose();
                state = null;
            }
            if (netcom != null)
            {
                netcom.Dispose();
                netcom = null;
            }
            if (mainForm != null)
            {
                mainForm.Load -= new EventHandler(mainForm_Load);
            }
            Logger.Log("RadegastInstance finished cleaning up.", Helpers.LogLevel.Debug);
        }
Ejemplo n.º 3
0
        void UpdateRadar(CoarseLocationUpdateEventArgs e)
        {
            if (client.Network.CurrentSim == null /*|| client.Network.CurrentSim.Handle != sim.Handle*/)
            {
                return;
            }

            if (InvokeRequired)
            {
                if (!instance.MonoRuntime || IsHandleCreated)
                {
                    BeginInvoke(new MethodInvoker(() => UpdateRadar(e)));
                }
                return;
            }

            // later on we can set this with something from the GUI
            const double MAX_DISTANCE = 362.0; // one sim a corner to corner distance

            lock (agentSimHandle)
                try
                {
                    lvwObjects.BeginUpdate();
                    Vector3d mypos = e.Simulator.AvatarPositions.ContainsKey(client.Self.AgentID)
                                        ? StateManager.ToVector3D(e.Simulator.Handle, e.Simulator.AvatarPositions[client.Self.AgentID])
                                        : client.Self.GlobalPosition;

                    // CoarseLocationUpdate gives us hight of 0 when actual height is
                    // between 1024-4096m.
                    if (mypos.Z < 0.1)
                    {
                        mypos.Z = client.Self.GlobalPosition.Z;
                    }

                    List <UUID> existing = new List <UUID>();
                    List <UUID> removed  = new List <UUID>(e.RemovedEntries);

                    e.Simulator.AvatarPositions.ForEach(delegate(KeyValuePair <UUID, Vector3> avi)
                    {
                        existing.Add(avi.Key);
                        if (!lvwObjects.Items.ContainsKey(avi.Key.ToString()))
                        {
                            string name       = instance.Names.Get(avi.Key);
                            ListViewItem item = lvwObjects.Items.Add(avi.Key.ToString(), name, string.Empty);
                            if (avi.Key == client.Self.AgentID)
                            {
                                // Stops our name saying "Loading..."
                                item.Text = instance.Names.Get(avi.Key, client.Self.Name);
                                item.Font = new Font(item.Font, FontStyle.Bold);
                            }
                            item.Tag = avi.Key;
                            agentSimHandle[avi.Key] = e.Simulator.Handle;
                        }
                    });

                    foreach (ListViewItem item in lvwObjects.Items)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        UUID key = (UUID)item.Tag;

                        if (agentSimHandle[key] != e.Simulator.Handle)
                        {
                            // not for this sim
                            continue;
                        }

                        if (key == client.Self.AgentID)
                        {
                            if (instance.Names.Mode != NameMode.Standard)
                            {
                                item.Text = instance.Names.Get(key);
                            }
                            continue;
                        }

                        //the AvatarPostions is checked once more because it changes wildly on its own
                        //even though the !existing should have been adequate
                        Vector3 pos;
                        if (!existing.Contains(key) || !e.Simulator.AvatarPositions.TryGetValue(key, out pos))
                        {
                            // not here anymore
                            removed.Add(key);
                            continue;
                        }

                        Avatar foundAvi = e.Simulator.ObjectsAvatars.Find(av => { return(av.ID == key); });

                        // CoarseLocationUpdate gives us hight of 0 when actual height is
                        // between 1024-4096m on OpenSim grids. 1020 on SL
                        bool unkownAltitude = instance.Netcom.LoginOptions.Grid.Platform == "SecondLife" ? pos.Z == 1020f : pos.Z == 0f;
                        if (unkownAltitude)
                        {
                            if (foundAvi != null)
                            {
                                if (foundAvi.ParentID == 0)
                                {
                                    pos.Z = foundAvi.Position.Z;
                                }
                                else
                                {
                                    if (e.Simulator.ObjectsPrimitives.ContainsKey(foundAvi.ParentID))
                                    {
                                        pos.Z = e.Simulator.ObjectsPrimitives[foundAvi.ParentID].Position.Z;
                                    }
                                }
                            }
                        }

                        int d = (int)Vector3d.Distance(StateManager.ToVector3D(e.Simulator.Handle, pos), mypos);

                        if (e.Simulator != client.Network.CurrentSim && d > MAX_DISTANCE)
                        {
                            removed.Add(key);
                            continue;
                        }

                        if (unkownAltitude)
                        {
                            item.Text = instance.Names.Get(key) + " (?m)";
                        }
                        else
                        {
                            item.Text = instance.Names.Get(key) + " (" + d + "m)";
                        }

                        if (foundAvi != null)
                        {
                            item.Text += "*";
                        }
                    }

                    foreach (UUID key in removed)
                    {
                        lvwObjects.Items.RemoveByKey(key.ToString());
                        agentSimHandle.Remove(key);
                    }

                    lvwObjects.Sort();
                }
                catch (Exception ex)
                {
                    Logger.Log("Grid_OnCoarseLocationUpdate: " + ex, Helpers.LogLevel.Error, client);
                }
            finally
            {
                lvwObjects.EndUpdate();
            }
        }