コード例 #1
0
ファイル: MapConsole.cs プロジェクト: tbutiu/radegast
        public void DoTeleport()
        {
            if (!Active)
            {
                return;
            }

            if (instance.MonoRuntime && map != null)
            {
                map.Navigate(Path.GetDirectoryName(Application.ExecutablePath) + @"/worldmap.html");
            }

            lblStatus.Text    = "Teleporting to " + txtRegion.Text;
            prgTeleport.Style = ProgressBarStyle.Marquee;

            WorkPool.QueueUserWorkItem((object state) =>
            {
                if (!client.Self.Teleport(txtRegion.Text, new Vector3((int)nudX.Value, (int)nudY.Value, (int)nudZ.Value)))
                {
                    Self_TeleportProgress(this, new TeleportEventArgs(string.Empty, TeleportStatus.Failed, TeleportFlags.Default));
                }
                InTeleport = false;
            }
                                       );
        }
コード例 #2
0
        void Friends_FriendOnline(object sender, FriendInfoEventArgs e)
        {
            if (!instance.GlobalSettings["show_friends_online_notifications"])
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                string name           = instance.Names.Get(e.Friend.UUID, true);
                MethodInvoker display = () =>
                {
                    DisplayNotification(e.Friend.UUID, name + " is online");
                    RefreshFriendsList();
                };

                if (InvokeRequired)
                {
                    BeginInvoke(display);
                }
                else
                {
                    display();
                }
            });
        }
コード例 #3
0
ファイル: MapControl.cs プロジェクト: CasperTech/radegast
 void GetTargetParcel()
 {
     WorkPool.QueueUserWorkItem(sync =>
     {
         UUID parcelID = Client.Parcels.RequestRemoteParcelID(
             new Vector3((float)(targetX % regionSize), (float)(targetY % regionSize), 20f),
             targetRegion.RegionHandle, UUID.Zero);
         if (parcelID != UUID.Zero)
         {
             ManualResetEvent done = new ManualResetEvent(false);
             EventHandler <ParcelInfoReplyEventArgs> handler = (object sender, ParcelInfoReplyEventArgs e) =>
             {
                 if (e.Parcel.ID == parcelID)
                 {
                     targetParcelName = e.Parcel.Name;
                     done.Set();
                     needRepaint = true;
                 }
             };
             Client.Parcels.ParcelInfoReply += handler;
             Client.Parcels.RequestParcelInfo(parcelID);
             done.WaitOne(30 * 1000, false);
             Client.Parcels.ParcelInfoReply -= handler;
         }
     });
 }
コード例 #4
0
ファイル: MapConsole.cs プロジェクト: tbutiu/radegast
        void map_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            map.DocumentCompleted         -= new WebBrowserDocumentCompletedEventHandler(map_DocumentCompleted);
            map.AllowWebBrowserDrop        = false;
            map.WebBrowserShortcutsEnabled = false;
            map.ScriptErrorsSuppressed     = true;
            map.ObjectForScripting         = this;
            map.AllowNavigation            = false;

            if (instance.MonoRuntime)
            {
                map.Navigating += new WebBrowserNavigatingEventHandler(map_Navigating);
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(1000);
                if (InvokeRequired && (!instance.MonoRuntime || IsHandleCreated))
                {
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        if (savedRegion != null)
                        {
                            gotoRegion(savedRegion, savedX, savedY);
                        }
                        else if (Active)
                        {
                            gotoRegion(client.Network.CurrentSim.Name, 128, 128);
                        }
                    }
                                                  ));
                }
            }
                                       );
        }
コード例 #5
0
        public void GetFolders(string folder)
        {
            var f = FindFolder(folder, Client.Inventory.Store.LibraryRootNode);

            if (f == null)
            {
                return;
            }

            UUID dest = Client.Inventory.FindFolderForType(AssetType.Clothing);

            if (dest == UUID.Zero)
            {
                return;
            }

            var destFolder = (InventoryFolder)Client.Inventory.Store[dest];

            WorkPool.QueueUserWorkItem(sync =>
            {
                Instance.TabConsole.DisplayNotificationInChat("Starting copy operation...");
                foreach (var node in f.Nodes.Values)
                {
                    if (node.Data is InventoryFolder)
                    {
                        var s = (InventoryFolder)node.Data;
                        Instance.TabConsole.DisplayNotificationInChat(string.Format("  Copying {0} to {1}", s.Name, destFolder.Name));
                        CopyFolder(destFolder, s);
                    }
                }
                Instance.TabConsole.DisplayNotificationInChat("Done.");
            });
        }
コード例 #6
0
ファイル: NameManager.cs プロジェクト: CasperTech/radegast
        void SaveCache(object sync)
        {
            WorkPool.QueueUserWorkItem(syncx =>
            {
                OSDArray namesOSD = new OSDArray(names.Count);
                lock (names)
                {
                    foreach (var name in names)
                    {
                        namesOSD.Add(name.Value.GetOSD());
                    }
                }

                OSDMap cache   = new OSDMap(1);
                cache["names"] = namesOSD;
                byte[] data    = OSDParser.SerializeLLSDBinary(cache, false);
                Logger.DebugLog(string.Format("Caching {0} avatar names to {1}", namesOSD.Count, cacheFileName));

                try
                {
                    File.WriteAllBytes(cacheFileName, data);
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed to save avatar name cache: ", Helpers.LogLevel.Error, client, ex);
                }
            });
        }
コード例 #7
0
ファイル: NameManager.cs プロジェクト: CasperTech/radegast
        void LoadCachedNames()
        {
            WorkPool.QueueUserWorkItem(syncx =>
            {
                try
                {
                    byte[] data       = File.ReadAllBytes(cacheFileName);
                    OSDMap cache      = (OSDMap)OSDParser.DeserializeLLSDBinary(data);
                    OSDArray namesOSD = (OSDArray)cache["names"];
                    DateTime now      = DateTime.Now;
                    TimeSpan maxAge   = new TimeSpan(48, 0, 0);
                    NameMode mode     = (NameMode)(int)instance.GlobalSettings["display_name_mode"];

                    lock (names)
                    {
                        for (int i = 0; i < namesOSD.Count; i++)
                        {
                            AgentDisplayName name = AgentDisplayName.FromOSD(namesOSD[i]);
                            if (mode == NameMode.Standard || ((now - name.Updated) < maxAge))
                            {
                                names[name.ID] = name;
                            }
                        }
                    }

                    Logger.DebugLog(string.Format("Restored {0} names from the avatar name cache", names.Count));
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed loading cached avatar names: ", Helpers.LogLevel.Warning, client, ex);
                }
            });
        }
コード例 #8
0
ファイル: WornAttachments.cs プロジェクト: rcoscali/METAbolt
        private void button1_Click(object sender, EventArgs e)
        {
            int iDx = lbxPrims.SelectedIndex;

            if (iDx != -1)
            {
                AttachmentsListItem item = (AttachmentsListItem)lbxPrims.Items[iDx];

                if (item == null)
                {
                    return;
                }

                UUID itmid = GetItemID(item.Prim);

                if (itmid == UUID.Zero)
                {
                    return;
                }

                InventoryItem attid = client.Inventory.Store[itmid] as InventoryItem;

                //client.Appearance.Detach(attid);

                //List<UUID> remclothing = new List<UUID>();
                //remclothing.Add(attid.UUID);

                List <InventoryBase> contents    = client.Inventory.Store.GetContents(instance.CoF.UUID);
                List <UUID>          remclothing = new List <UUID>();

                foreach (InventoryItem ritem in contents)
                {
                    if (ritem.AssetUUID == attid.UUID)
                    {
                        remclothing.Add(ritem.UUID);
                    }
                }

                client.Inventory.Remove(remclothing, null);
                client.Appearance.Detach(attid);

                lock (listItems)
                {
                    listItems.Clear();
                }

                pBar3.Visible = true;
                lbxPrims.Items.Clear();
                lbxPrimGroup.Items.Clear();

                WorkPool.QueueUserWorkItem(delegate(object sync)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    Thread.Sleep(2000);
                    ReLoadItems();
                    //GetAttachments();
                    Cursor.Current = Cursors.Default;
                });
            }
        }
コード例 #9
0
ファイル: WornAttachments.cs プロジェクト: rcoscali/METAbolt
        private void SIM_OnSimChanged(object sender, SimChangedEventArgs e)
        {
            if (!this.IsHandleCreated)
            {
                return;
            }

            lock (listItems)
            {
                listItems.Clear();
            }

            BeginInvoke(new MethodInvoker(delegate()
            {
                pBar3.Visible = true;
                lbxPrims.Items.Clear();
                lbxPrimGroup.Items.Clear();

                WorkPool.QueueUserWorkItem(delegate(object sync)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    Thread.Sleep(5000);
                    ReLoadItems();
                    //GetAttachments();
                    Cursor.Current = Cursors.Default;
                });
            }));
        }
コード例 #10
0
ファイル: MapConsole.cs プロジェクト: tbutiu/radegast
        void gotoRegion(string regionName, int simX, int simY)
        {
            savedRegion = regionName;
            savedX      = simX;
            savedY      = simY;

            if (!Visible)
            {
                return;
            }

            if (mmap != null)
            {
                if (!regionHandles.ContainsKey(regionName))
                {
                    WorkPool.QueueUserWorkItem(sync =>
                    {
                        ManualResetEvent done = new ManualResetEvent(false);
                        EventHandler <GridRegionEventArgs> handler = (object sender, GridRegionEventArgs e) =>
                        {
                            regionHandles[e.Region.Name] = Utils.UIntsToLong((uint)e.Region.X, (uint)e.Region.Y);
                            if (e.Region.Name == regionName)
                            {
                                done.Set();
                            }
                        };
                        client.Grid.GridRegion += handler;
                        client.Grid.RequestMapRegion(regionName, GridLayerType.Objects);
                        if (done.WaitOne(30 * 1000, false))
                        {
                            if (!instance.MonoRuntime || IsHandleCreated)
                            {
                                BeginInvoke(new MethodInvoker(() => gotoRegion(regionName, simX, simY)));
                            }
                        }
                        client.Grid.GridRegion -= handler;
                    }
                                               );
                    return;
                }
                mmap.CenterMap(regionHandles[regionName], (uint)simX, (uint)simY, true);
                return;
            }

            if (map == null || map.Document == null)
            {
                return;
            }

            if (instance.MonoRuntime)
            {
                map.Document.InvokeScript(string.Format("gReg = \"{0}\"; gSimX = {1}; gSimY = {2}; monosucks", regionName, simX, simY));
            }
            else
            {
                map.Document.InvokeScript("gotoRegion", new object[] { regionName, simX, simY });
            }
        }
コード例 #11
0
 void Network_SimChanged(object sender, SimChangedEventArgs e)
 {
     WorkPool.QueueUserWorkItem(sync =>
     {
         Thread.Sleep(15 * 1000);
         AutoSit.TrySit();
         PseudoHome.ETGoHome();
     });
     client.Self.Movement.SetFOVVerticalAngle(FOVVerticalAngle);
 }
コード例 #12
0
ファイル: RenderTerrain.cs プロジェクト: somsomsomi/radegast
        private void UpdateTerrain()
        {
            if (sim == null || sim.Terrain == null)
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                int step = 1;

                for (int x = 0; x < 256; x += step)
                {
                    for (int y = 0; y < 256; y += step)
                    {
                        float z     = 0;
                        int patchNr = ((int)x / 16) * 16 + (int)y / 16;
                        if (sim.Terrain[patchNr] != null &&
                            sim.Terrain[patchNr].Data != null)
                        {
                            float[] data = sim.Terrain[patchNr].Data;
                            z            = data[(int)x % 16 * 16 + (int)y % 16];
                        }
                        heightTable[x, y] = z;
                    }
                }

                terrainFace     = renderer.TerrainMesh(heightTable, 0f, 255f, 0f, 255f);
                terrainVertices = new ColorVertex[terrainFace.Vertices.Count];
                for (int i = 0; i < terrainFace.Vertices.Count; i++)
                {
                    byte[] part        = Utils.IntToBytes(i);
                    terrainVertices[i] = new ColorVertex()
                    {
                        Vertex = terrainFace.Vertices[i],
                        Color  = new Color4b()
                        {
                            R = part[0],
                            G = part[1],
                            B = part[2],
                            A = 253 // terrain picking
                        }
                    };
                }
                terrainIndices = new uint[terrainFace.Indices.Count];
                for (int i = 0; i < terrainIndices.Length; i++)
                {
                    terrainIndices[i] = terrainFace.Indices[i];
                }
                terrainInProgress         = false;
                Modified                  = false;
                terrainTextureNeedsUpdate = true;
                terrainTimeSinceUpdate    = 0f;
            });
        }
コード例 #13
0
        private void btnIM_Click(object sender, EventArgs e)
        {
            if (listFriends.SelectedItems.Count == 1)
            {
                selectedFriend = (FriendInfo)listFriends.SelectedItems[0];
                instance.TabConsole.ShowIMTab(selectedFriend.UUID, selectedFriend.Name, true);
            }
            else if (listFriends.SelectedItems.Count > 1)
            {
                List <UUID> participants = new List <UUID>();
                foreach (var item in listFriends.SelectedItems)
                {
                    participants.Add(((FriendInfo)item).UUID);
                }
                UUID tmpID = UUID.Random();
                lblFriendName.Text = "Startings friends conference...";
                instance.TabConsole.DisplayNotificationInChat(lblFriendName.Text, ChatBufferTextStyle.Invisible);
                btnIM.Enabled = false;

                WorkPool.QueueUserWorkItem(sync =>
                {
                    using (ManualResetEvent started = new ManualResetEvent(false))
                    {
                        UUID sessionID     = UUID.Zero;
                        string sessionName = string.Empty;

                        EventHandler <GroupChatJoinedEventArgs> handler = (object isender, GroupChatJoinedEventArgs ie) =>
                        {
                            if (ie.TmpSessionID == tmpID)
                            {
                                sessionID   = ie.SessionID;
                                sessionName = ie.SessionName;
                                started.Set();
                            }
                        };

                        client.Self.GroupChatJoined += handler;
                        client.Self.StartIMConference(participants, tmpID);
                        if (started.WaitOne(30 * 1000, false))
                        {
                            instance.TabConsole.BeginInvoke(new MethodInvoker(() =>
                            {
                                instance.TabConsole.AddConferenceIMTab(sessionID, sessionName);
                                instance.TabConsole.SelectTab(sessionID.ToString());
                            }
                                                                              ));
                        }
                        client.Self.GroupChatJoined -= handler;
                        BeginInvoke(new MethodInvoker(() => RefreshFriendsList()));
                    }
                }
                                           );
            }
        }
コード例 #14
0
ファイル: MapControl.cs プロジェクト: CasperTech/radegast
 public void ClearTarget()
 {
     targetRegion = nullRegion;
     targetX      = targetY = -5000000000d;
     WorkPool.QueueUserWorkItem(sync =>
     {
         Thread.Sleep(500);
         needRepaint = true;
     }
                                );
 }
コード例 #15
0
        /// <summary>
        /// Add items to current outfit
        /// </summary>
        /// <param name="items">List of items to add</param>
        /// <param name="replace">Should existing wearable of the same type be removed</param>
        public void AddToOutfit(List <InventoryItem> items, bool replace)
        {
            List <InventoryItem> current  = ContentLinks();
            List <UUID>          toRemove = new List <UUID>();

            // Resolve inventory links and remove wearables of the same type from COF
            List <InventoryItem> outfit = new List <InventoryItem>();

            foreach (var item in items)
            {
                InventoryItem realItem = RealInventoryItem(item);
                if (realItem is InventoryWearable)
                {
                    foreach (var link in current)
                    {
                        var currentItem = RealInventoryItem(link);
                        if (link.AssetUUID == item.UUID)
                        {
                            toRemove.Add(link.UUID);
                        }
                        else if (currentItem is InventoryWearable)
                        {
                            var w = (InventoryWearable)currentItem;
                            if (w.WearableType == ((InventoryWearable)realItem).WearableType)
                            {
                                toRemove.Add(link.UUID);
                            }
                        }
                    }
                }

                outfit.Add(realItem);
            }
            Client.Inventory.Remove(toRemove, null);

            // Add links to new items
            List <InventoryItem> newItems = outfit.FindAll(item => CanBeWorn(item));

            foreach (var item in newItems)
            {
                AddLink(item);
            }

            Client.Appearance.AddToOutfit(outfit, replace);
            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(2000);
                Client.Appearance.RequestSetAppearance(true);
            });
        }
コード例 #16
0
        public void StartCheck()
        {
            if (client == null)
            {
                client = new WebClient();
                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnDownloadStringCompleted);
            }

            WorkPool.QueueUserWorkItem((object state) =>
            {
                client.DownloadStringAsync(new Uri(Properties.Resources.UpdateCheckUri));
            }
                                       );
        }
コード例 #17
0
        /// <summary>
        /// Replaces the current outfit and updates COF links accordingly
        /// </summary>
        /// <param name="outfit">List of new wearables and attachments that comprise the new outfit</param>
        public void ReplaceOutfit(List <InventoryItem> newOutfit)
        {
            // Resolve inventory links
            List <InventoryItem> outfit = new List <InventoryItem>();

            foreach (var item in newOutfit)
            {
                outfit.Add(RealInventoryItem(item));
            }

            // Remove links to all exiting items
            List <UUID> toRemove = new List <UUID>();

            ContentLinks().ForEach(item =>
            {
                if (IsBodyPart(item))
                {
                    WearableType linkType = ((InventoryWearable)RealInventoryItem(item)).WearableType;
                    bool hasBodyPart      = newOutfit.Select(RealInventoryItem).Where(IsBodyPart).Any(newItem =>
                                                                                                      ((InventoryWearable)newItem).WearableType == linkType);

                    if (hasBodyPart)
                    {
                        toRemove.Add(item.UUID);
                    }
                }
                else
                {
                    toRemove.Add(item.UUID);
                }
            });

            Client.Inventory.Remove(toRemove, null);

            // Add links to new items
            List <InventoryItem> newItems = outfit.FindAll(CanBeWorn);

            foreach (var item in newItems)
            {
                AddLink(item);
            }

            Client.Appearance.ReplaceOutfit(outfit, false);
            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(2000);
                Client.Appearance.RequestSetAppearance(true);
            });
        }
コード例 #18
0
ファイル: PrimWorkshop.cs プロジェクト: CasperTech/radegast
        private void frmPrimWorkshop_Shown(object sender, EventArgs e)
        {
            SetupGLControl();

            WorkPool.QueueUserWorkItem(sync =>
            {
                if (Client.Network.CurrentSim.ObjectsPrimitives.ContainsKey(RootPrimLocalID))
                {
                    UpdatePrimBlocking(Client.Network.CurrentSim.ObjectsPrimitives[RootPrimLocalID]);
                    var children = Client.Network.CurrentSim.ObjectsPrimitives.FindAll((Primitive p) => { return(p.ParentID == RootPrimLocalID); });
                    children.ForEach(p => UpdatePrimBlocking(p));
                }
            }
                                       );
        }
コード例 #19
0
ファイル: Notification.cs プロジェクト: somsomsomi/radegast
 protected void FireNotificationCallback(NotificationEventArgs e)
 {
     if (OnNotificationDisplayed == null)
     {
         return;
     }
     try
     {
         e.Type = this.Type;
         WorkPool.QueueUserWorkItem((object o) => Notificaton_Displayed(this, e));
     }
     catch (Exception ex)
     {
         Console.WriteLine("" + ex);
         OpenMetaverse.Logger.Log("Error executing notification callback", OpenMetaverse.Helpers.LogLevel.Warning, ex);
     }
 }
コード例 #20
0
ファイル: RenderTerrain.cs プロジェクト: somsomsomi/radegast
        void UpdateTerrainTexture()
        {
            if (!fetchingTerrainTexture)
            {
                fetchingTerrainTexture = true;
                WorkPool.QueueUserWorkItem(sync =>
                {
                    Simulator sim = Client.Network.CurrentSim;
                    terrainImage  = TerrainSplat.Splat(Instance, heightTable,
                                                       new UUID[] { sim.TerrainDetail0, sim.TerrainDetail1, sim.TerrainDetail2, sim.TerrainDetail3 },
                                                       new float[] { sim.TerrainStartHeight00, sim.TerrainStartHeight01, sim.TerrainStartHeight10, sim.TerrainStartHeight11 },
                                                       new float[] { sim.TerrainHeightRange00, sim.TerrainHeightRange01, sim.TerrainHeightRange10, sim.TerrainHeightRange11 });

                    fetchingTerrainTexture    = false;
                    terrainTextureNeedsUpdate = false;
                });
            }
        }
コード例 #21
0
        void Friends_FriendshipTerminated(object sender, FriendshipTerminatedEventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                string name           = instance.Names.Get(e.AgentID, true);
                MethodInvoker display = () =>
                {
                    DisplayNotification(e.AgentID, name + " is no longer on your friend list");
                    RefreshFriendsList();
                };

                if (InvokeRequired)
                {
                    BeginInvoke(display);
                }
                else
                {
                    display();
                }
            });
        }
コード例 #22
0
ファイル: Profile.cs プロジェクト: CasperTech/radegast
        private void btnNewPick_Click(object sender, EventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                UUID parcelID = client.Parcels.RequestRemoteParcelID(client.Self.SimPosition, client.Network.CurrentSim.Handle, client.Network.CurrentSim.ID);
                newPickID     = UUID.Random();

                client.Self.PickInfoUpdate(
                    newPickID,
                    false,
                    parcelID,
                    Instance.State.Parcel.Name,
                    client.Self.GlobalPosition,
                    Instance.State.Parcel.SnapshotID,
                    Instance.State.Parcel.Desc
                    );

                Invoke(new MethodInvoker(() => ClearPicks()));
                client.Avatars.RequestAvatarPicks(agentID);
            });
        }
コード例 #23
0
ファイル: DisplayNameChange.cs プロジェクト: TsengSR/Radegast
 private void StartDisplayNameChage(string name)
 {
     WorkPool.QueueUserWorkItem(sync =>
     {
         Client.Avatars.GetDisplayNames(new List <UUID>()
         {
             Client.Self.AgentID
         },
                                        (success, names, badIDs) =>
         {
             if (!success || names.Length < 1)
             {
                 UpdateStatus("Failed to get curret name");
             }
             else
             {
                 Client.Self.SetDisplayName(names[0].DisplayName, name);
             }
         }
                                        );
     }
                                );
 }
コード例 #24
0
        void Self_IM(object sender, InstantMessageEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }
            // Every event coming from a different thread (almost all of them, most certanly those
            // from libomv) needs to be executed on the GUI thread. This code can be basically
            // copy-pasted on the begining of each libomv event handler that results in update
            // of any GUI element
            //
            // In this case the IM we sent back as a reply is also displayed in the corresponding IM tab
            if (Instance.MainForm.InvokeRequired)
            {
                Instance.MainForm.BeginInvoke(
                    new MethodInvoker(
                        delegate()
                {
                    Self_IM(sender, e);
                }
                        ));
                return;
            }

            // We need to filter out all sorts of things that come in as a instante message
            if (e.IM.Dialog == InstantMessageDialog.MessageFromAgent && // Message is not notice, inv. offer, etc etc
                !Instance.Groups.ContainsKey(e.IM.IMSessionID) &&  // Message is not group IM (sessionID == groupID)
                e.IM.BinaryBucket.Length < 2 &&                  // Session is not ad-hoc friends conference
                e.IM.FromAgentName != "Second Life" &&           // Not a system message
                Alice.isAcceptingUserInput                       // Alice bot loaded successfully
                )
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.IM.FromAgentName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.IM.FromAgentName];
                        }
                        else
                        {
                            user = new User(e.IM.FromAgentName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.IM.FromAgentName));
                            AliceUsers[e.IM.FromAgentName] = user;
                        }
                        AIMLbot.Request req = new Request(e.IM.Message, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string msg          = res.Output;
                        if (msg.Length > 1000)
                        {
                            msg = msg.Substring(0, 1000);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(3));
                        }
                        Instance.Netcom.SendIMStartTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.Netcom.SendIMStopTyping(e.IM.FromAgentID, e.IM.IMSessionID);
                        if (Instance.MainForm.InvokeRequired)
                        {
                            Instance.MainForm.BeginInvoke(new MethodInvoker(() => Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID)));
                        }
                        else
                        {
                            Instance.Netcom.SendInstantMessage(msg, e.IM.FromAgentID, e.IM.IMSessionID);
                        }
                    }
                });
            }
        }
コード例 #25
0
ファイル: LSLHelper.cs プロジェクト: TsengSR/Radegast
        /// <summary>
        /// Dispatcher for incoming IM automation
        /// </summary>
        /// <param name="e">Incoming message</param>
        /// <returns>If message processed correctly, should GUI processing be halted</returns>
        public bool ProcessIM(InstantMessageEventArgs e)
        {
            LoadSettings();

            if (!Enabled)
            {
                return(false);
            }

            switch (e.IM.Dialog)
            {
            case InstantMessageDialog.MessageFromObject:
            {
                if (!AllowedOwners.Contains(e.IM.FromAgentID.ToString()))
                {
                    return(true);
                }
                string[] args = e.IM.Message.Trim().Split('^');
                if (args.Length < 1)
                {
                    return(false);
                }

                switch (args[0].Trim())
                {
                case "group_invite":
                {
                    if (args.Length < 4)
                    {
                        return(false);
                    }
                    ProcessInvite(args);
                    return(true);
                }

                case "send_im":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    string msg = args[2].Trim();
                    client.Self.InstantMessage(sendTo, msg);
                    return(true);
                }

                case "give_inventory":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo    = UUID.Zero;
                    UUID invItemID = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    if (!UUID.TryParse(args[2].Trim(), out invItemID))
                    {
                        return(false);
                    }
                    if (!client.Inventory.Store.Contains(invItemID))
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Tried to offer {0} but could not find it in my inventory", invItemID),
                            ChatBufferTextStyle.Error);
                        return(false);
                    }
                    InventoryItem item = client.Inventory.Store[invItemID] as InventoryItem;
                    if (item == null)
                    {
                        return(false);
                    }
                    client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, sendTo, true);
                    WorkPool.QueueUserWorkItem(sync =>
                                               instance.TabConsole.DisplayNotificationInChat(
                                                   string.Format("Gave {0} to {1}", item.Name, instance.Names.Get(sendTo, true)),
                                                   ChatBufferTextStyle.ObjectChat)
                                               );
                    return(true);
                }

                case "say":             /* This one doesn't work yet. I don't know why. TODO. - Nico */
                {
                    if (args.Length < 2)
                    {
                        return(true);
                    }
                    ChatType ct   = ChatType.Normal;
                    int      chan = 0;
                    if (args.Length > 2 && int.TryParse(args[2].Trim(), out chan) && chan < 0)
                    {
                        chan = 0;
                    }
                    if (args.Length > 3)
                    {
                        switch (args[3].Trim().ToLower())
                        {
                        case "whisper":
                        {
                            ct = ChatType.Whisper;
                            break;
                        }

                        case "shout":
                        {
                            ct = ChatType.Shout;
                        }
                        break;
                        }
                    }
                    client.Self.Chat(args[1].Trim(), chan, ct);
                    return(true);
                }
                }
            }
            break;
            }

            return(false);
        }
コード例 #26
0
        /// <summary>
        /// Dispatcher for incoming IM automation
        /// </summary>
        /// <param name="e">Incoming message</param>
        /// <returns>If message processed correctly, should GUI processing be halted</returns>
        public bool ProcessIM(InstantMessageEventArgs e)
        {
            LoadSettings();

            if (!Enabled)
            {
                return(false);
            }

            switch (e.IM.Dialog)
            {
            case InstantMessageDialog.MessageFromObject:
            {
                if (e.IM.FromAgentID != AllowedOwner)
                {
                    return(true);
                }
                string[] args = e.IM.Message.Trim().Split('^');
                if (args.Length < 1)
                {
                    return(false);
                }

                switch (args[0].Trim())
                {
                case "group_invite":
                {
                    if (args.Length < 4)
                    {
                        return(false);
                    }
                    ProcessInvite(args);
                    return(true);
                }

                case "send_im":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    string msg = args[2].Trim();
                    client.Self.InstantMessage(sendTo, msg);
                    return(true);
                }

                case "give_inventory":
                {
                    if (args.Length < 3)
                    {
                        return(false);
                    }
                    UUID sendTo    = UUID.Zero;
                    UUID invItemID = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out sendTo))
                    {
                        return(false);
                    }
                    if (!UUID.TryParse(args[2].Trim(), out invItemID))
                    {
                        return(false);
                    }
                    if (!client.Inventory.Store.Contains(invItemID))
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Tried to offer {0} but could not find it in my inventory", invItemID),
                            ChatBufferTextStyle.Error);
                        return(false);
                    }
                    InventoryItem item = client.Inventory.Store[invItemID] as InventoryItem;
                    if (item == null)
                    {
                        return(false);
                    }
                    client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, sendTo, true);
                    WorkPool.QueueUserWorkItem(sync =>
                                               instance.TabConsole.DisplayNotificationInChat(
                                                   string.Format("Gave {0} to {1}", item.Name, instance.Names.Get(sendTo, true)),
                                                   ChatBufferTextStyle.ObjectChat)
                                               );
                    return(true);
                }
                }
            }
            break;
            }

            return(false);
        }
コード例 #27
0
        private void ProcessInvite(string[] args)
        {
            if (args == null || args.Length < 4)
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                try
                {
                    UUID invitee = UUID.Zero;
                    UUID groupID = UUID.Zero;
                    UUID roleID  = UUID.Zero;
                    if (!UUID.TryParse(args[1].Trim(), out invitee))
                    {
                        return;
                    }
                    if (!UUID.TryParse(args[2].Trim(), out groupID))
                    {
                        return;
                    }
                    if (!UUID.TryParse(args[3].Trim(), out roleID))
                    {
                        return;
                    }

                    if (instance.Groups.ContainsKey(groupID))
                    {
                        AutoResetEvent gotMembers = new AutoResetEvent(false);
                        Dictionary <UUID, GroupMember> Members            = null;
                        EventHandler <GroupMembersReplyEventArgs> handler = (sender, e) =>
                        {
                            if (e.GroupID != groupID)
                            {
                                return;
                            }
                            Members = e.Members;
                            gotMembers.Set();
                        };

                        client.Groups.GroupMembersReply += handler;
                        client.Groups.RequestGroupMembers(groupID);
                        bool success = gotMembers.WaitOne(30 * 1000, false);
                        client.Groups.GroupMembersReply -= handler;

                        if (Members != null && Members.ContainsKey(invitee))
                        {
                            instance.TabConsole.DisplayNotificationInChat(
                                string.Format("Not inviting {0} ({1}) to {2} ({3}), already member", instance.Names.Get(invitee, true), invitee, instance.Groups[groupID].Name, groupID),
                                ChatBufferTextStyle.ObjectChat);
                        }
                        else
                        {
                            instance.TabConsole.DisplayNotificationInChat(
                                string.Format("Inviting {0} ({1}) to {2} ({3})", instance.Names.Get(invitee, true), invitee, instance.Groups[groupID].Name, groupID),
                                ChatBufferTextStyle.ObjectChat);
                            client.Groups.Invite(groupID, new List <UUID>(1)
                            {
                                roleID
                            }, invitee);
                        }
                    }
                    else
                    {
                        instance.TabConsole.DisplayNotificationInChat(
                            string.Format("Cannot invite to group {0}, I don't appear to be in it.", groupID),
                            ChatBufferTextStyle.Error);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("Failed proccessing automation IM: " + ex.ToString(), Helpers.LogLevel.Warning);
                }
            });
        }
コード例 #28
0
        /// <summary>
        /// Handle Instant Messages
        /// </summary>
        /// <param name="im"></param>
        /// <param name="simulator"></param>
        void OnInstantMessage(object sender, InstantMessageEventArgs e)
        {
            WorkPool.QueueUserWorkItem(sync =>
            {
                Thread.Sleep(100);     // Give tab a chance to show up
                IMSession sess = null;
                string groupName;

                // All sorts of things come in as a instant messages. For actual messages
                // we need to match them up with an existing Conversation.  IM Conversations
                // are keyed by the name of the group or individual involved.
                switch (e.IM.Dialog)
                {
                case InstantMessageDialog.MessageFromAgent:
                    if (control.instance.Groups.ContainsKey(e.IM.IMSessionID))
                    {
                        // Message from a group member
                        groupName = control.instance.Groups[e.IM.IMSessionID].Name;
                        sess      = (IMSession)control.converse.GetConversation(groupName);
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    else if (e.IM.BinaryBucket.Length >= 2)
                    {
                        // Ad-hoc friend conference
                        sess = (IMSession)control.converse.GetConversation(Utils.BytesToString(e.IM.BinaryBucket));
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    else if (e.IM.FromAgentName == "Second Life")
                    {
                        Talker.Say("Second Life says " + e.IM.Message);
                    }
                    else
                    {
                        // Message from an individual
                        sess = (IMSession)control.converse.GetConversation(e.IM.FromAgentName);
                        if (sess != null)
                        {
                            sess.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                        }
                        else
                        {
                            Talker.Say(e.IM.FromAgentName + ", " + e.IM.Message);
                        }
                    }
                    break;

                case InstantMessageDialog.SessionSend:
                    if (control.instance.Groups.ContainsKey(e.IM.IMSessionID))
                    {
                        // Message from a group member
                        groupName = control.instance.Groups[e.IM.IMSessionID].Name;
                        sess      = (IMSession)control.converse.GetConversation(groupName);
                    }
                    else if (e.IM.BinaryBucket.Length >= 2)         // ad hoc friends conference
                    {
                        sess = (IMSession)control.converse.GetConversation(Utils.BytesToString(e.IM.BinaryBucket));
                    }

                    sess?.OnMessage(e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                    break;

                case InstantMessageDialog.FriendshipOffered:
                    Talker.Say(e.IM.FromAgentName + " is offering friendship.");
                    break;

                default:
                    break;
                }
            }
                                       );
        }
コード例 #29
0
        void Self_ChatFromSimulator(object sender, ChatEventArgs e)
        {
            // We ignore everything except normal chat from other avatars
            if (!Enabled || e.SourceType != ChatSourceType.Agent || e.FromName == Client.Self.Name || e.Message.Trim().Length == 0)
            {
                return;
            }

            bool parseForResponse = Alice != null && Alice.isAcceptingUserInput && Enabled;

            if (parseForResponse && respondRange >= 0)
            {
                parseForResponse = Vector3.Distance(Client.Self.SimPosition, e.Position) <= respondRange;
            }
            if (parseForResponse)
            {
                parseForResponse = respondWithoutName || e.Message.ToLower().Contains(FirstName(Client.Self.Name).ToLower());
            }


            if (parseForResponse)
            {
                WorkPool.QueueUserWorkItem(sync =>
                {
                    lock (syncChat)
                    {
                        Alice.GlobalSettings.updateSetting("location", "region " + Client.Network.CurrentSim.Name);
                        string msg = e.Message.ToLower();
                        msg        = msg.Replace(FirstName(Client.Self.Name).ToLower(), "");
                        AIMLbot.User user;
                        if (AliceUsers.ContainsKey(e.FromName))
                        {
                            user = (AIMLbot.User)AliceUsers[e.FromName];
                        }
                        else
                        {
                            user = new User(e.FromName, Alice);
                            user.Predicates.removeSetting("name");
                            user.Predicates.addSetting("name", FirstName(e.FromName));
                            AliceUsers[e.FromName] = user;
                        }

                        Client.Self.Movement.TurnToward(e.Position);
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(1000 + 1000 * rand.Next(2));
                        }
                        if (!Instance.State.IsTyping)
                        {
                            Instance.State.SetTyping(true);
                        }
                        if (EnableRandomDelay)
                        {
                            System.Threading.Thread.Sleep(2000 + 1000 * rand.Next(5));
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        Instance.State.SetTyping(false);
                        AIMLbot.Request req = new Request(msg, user, Alice);
                        AIMLbot.Result res  = Alice.Chat(req);
                        string outp         = res.Output;
                        if (outp.Length > 1000)
                        {
                            outp = outp.Substring(0, 1000);
                        }

                        ChatType useChatType = ChatType.Normal;
                        if (shout2shout && e.Type == ChatType.Shout)
                        {
                            useChatType = ChatType.Shout;
                        }
                        else if (whisper2whisper && e.Type == ChatType.Whisper)
                        {
                            useChatType = ChatType.Whisper;
                        }
                        Client.Self.Chat(outp, 0, useChatType);
                    }
                });
            }
        }
コード例 #30
0
        public void Export(string Filename)
        {
            FileName = Filename;

            MeshedPrims.Clear();

            if (string.IsNullOrEmpty(FileName))
            {
                return;
            }

            WorkPool.QueueUserWorkItem(sync =>
            {
                if (ExportTextures)
                {
                    SaveTextures();
                }
                for (int i = 0; i < Prims.Count; i++)
                {
                    if (!CanExport(Prims[i]))
                    {
                        continue;
                    }

                    FacetedMesh mesh = MeshPrim(Prims[i]);
                    if (mesh == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < mesh.Faces.Count; j++)
                    {
                        Face face = mesh.Faces[j];

                        Primitive.TextureEntryFace teFace = mesh.Faces[j].TextureFace;
                        if (teFace == null)
                        {
                            continue;
                        }


                        // Sculpt UV vertically flipped compared to prims. Flip back
                        if (Prims[i].Sculpt != null && Prims[i].Sculpt.SculptTexture != UUID.Zero && Prims[i].Sculpt.Type != SculptType.Mesh)
                        {
                            teFace          = (Primitive.TextureEntryFace)teFace.Clone();
                            teFace.RepeatV *= -1;
                        }

                        // Texture transform for this face
                        Mesher.TransformTexCoords(face.Vertices, face.Center, teFace, Prims[i].Scale);
                    }
                    MeshedPrims.Add(mesh);
                }

                string msg;
                if (MeshedPrims.Count == 0)
                {
                    msg = string.Format("Can export 0 out of {0} prims.{1}{1}Skipping.", Prims.Count, Environment.NewLine);
                }
                else
                {
                    msg = string.Format("Exported {0} out of {1} objects to{2}{2}{3}", MeshedPrims.Count, Prims.Count, Environment.NewLine, FileName);
                }
                GenerateCollada();
                File.WriteAllText(FileName, DocToString(Doc));
                OnProgress(msg);
            });
        }