Пример #1
0
 public RLVEventArgs(RLVRule rule)
 {
     Rule = rule;
 }
Пример #2
0
        public bool TryProcessCMD(ChatEventArgs e)
        {
            if (!Enabled || !e.Message.StartsWith("@"))
            {
                return(false);
            }

            if (e.Message == "@clear")
            {
                Clear(e.SourceID);
                return(true);
            }

            foreach (var cmd in e.Message.Substring(1).Split(','))
            {
                var m = rlv_regex.Match(cmd);
                if (!m.Success)
                {
                    continue;
                }

                var rule = new RLVRule();
                rule.Behaviour  = m.Groups["behaviour"].ToString().ToLower();;
                rule.Option     = m.Groups["option"].ToString().ToLower();
                rule.Param      = m.Groups["param"].ToString().ToLower();
                rule.Sender     = e.SourceID;
                rule.SenderName = e.FromName;

                Logger.DebugLog(rule.ToString());

                if (rule.Param == "rem")
                {
                    rule.Param = "y";
                }
                if (rule.Param == "add")
                {
                    rule.Param = "n";
                }

                if (rule.Param == "n")
                {
                    lock (rules)
                    {
                        var existing = rules.Find(r =>
                                                  r.Behaviour == rule.Behaviour &&
                                                  r.Sender == rule.Sender &&
                                                  r.Option == rule.Option);

                        if (existing != null)
                        {
                            rules.Remove(existing);
                        }
                        rules.Add(rule);
                        OnRLVRuleChanged(new RLVEventArgs(rule));
                    }
                    continue;
                }

                if (rule.Param == "y")
                {
                    lock (rules)
                    {
                        if (rule.Option == "")
                        {
                            rules.RemoveAll((RLVRule r) =>
                            {
                                return(r.Behaviour == rule.Behaviour && r.Sender == rule.Sender);
                            });
                        }
                        else
                        {
                            rules.RemoveAll((RLVRule r) =>
                            {
                                return(r.Behaviour == rule.Behaviour && r.Sender == rule.Sender && r.Option == rule.Option);
                            });
                        }
                    }

                    OnRLVRuleChanged(new RLVEventArgs(rule));
                    continue;
                }


                switch (rule.Behaviour)
                {
                case "version":
                    int chan = 0;
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        Respond(chan, "RestrainedLife viewer v1.23 (" + Properties.Resources.METAboltTitle + "." + METAboltBuild.CurrentRev + ")");
                    }
                    break;

                case "versionnew":
                    chan = 0;
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        Respond(chan, "RestrainedLove viewer v1.23 (" + Properties.Resources.METAboltTitle + "." + METAboltBuild.CurrentRev + ")");
                    }
                    break;


                case "versionnum":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        Respond(chan, "1230100");
                    }
                    break;

                case "getgroup":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        UUID gid = client.Self.ActiveGroup;
                        if (instance.Groups.ContainsKey(gid))
                        {
                            Respond(chan, instance.Groups[gid].Name);
                        }
                    }
                    break;

                case "setgroup":
                {
                    if (rule.Param == "force")
                    {
                        foreach (var g in instance.Groups.Values)
                        {
                            if (g.Name.ToLower() == rule.Option)
                            {
                                client.Groups.ActivateGroup(g.ID);
                            }
                        }
                    }
                }
                break;

                case "getsitid":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        Avatar me;
                        if (client.Network.CurrentSim.ObjectsAvatars.TryGetValue(client.Self.LocalID, out me))
                        {
                            if (me.ParentID != 0)
                            {
                                Primitive seat;
                                if (client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(me.ParentID, out seat))
                                {
                                    Respond(chan, seat.ID.ToString());
                                    break;
                                }
                            }
                        }
                        Respond(chan, UUID.Zero.ToString());
                    }
                    break;

                case "getstatusall":
                case "getstatus":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        string sep    = "/";
                        string filter = "";

                        if (!string.IsNullOrEmpty(rule.Option))
                        {
                            var parts = rule.Option.Split(';');
                            if (parts.Length > 1 && parts[1].Length > 0)
                            {
                                sep = parts[1].Substring(0, 1);
                            }
                            if (parts.Length > 0 && parts[0].Length > 0)
                            {
                                filter = parts[0].ToLower();
                            }
                        }

                        lock (rules)
                        {
                            string res = "";
                            rules
                            .FindAll(r => (rule.Behaviour == "getstatusall" || r.Sender == rule.Sender) && r.Behaviour.Contains(filter))
                            .ForEach(objRule =>
                            {
                                res += sep + objRule.Behaviour;
                                if (!string.IsNullOrEmpty(objRule.Option))
                                {
                                    res += ":" + objRule.Option;
                                }
                            });
                            Respond(chan, res);
                        }
                    }
                    break;

                case "sit":
                    UUID sitTarget = UUID.Zero;

                    if (rule.Param == "force" && UUID.TryParse(rule.Option, out sitTarget) && sitTarget != UUID.Zero)
                    {
                        instance.State.SetSitting(true, sitTarget);
                    }
                    break;

                case "unsit":
                    if (rule.Param == "force")
                    {
                        instance.State.SetSitting(false, UUID.Zero);
                    }
                    break;

                case "setrot":
                    double rot = 0.0;

                    if (rule.Param == "force" && double.TryParse(rule.Option, System.Globalization.NumberStyles.Float, Utils.EnUsCulture, out rot))
                    {
                        client.Self.Movement.UpdateFromHeading(Math.PI / 2d - rot, true);
                    }
                    break;

                case "tpto":
                    var coord = rule.Option.Split('/');

                    try
                    {
                        float gx = float.Parse(coord[0], Utils.EnUsCulture);
                        float gy = float.Parse(coord[1], Utils.EnUsCulture);
                        float z = float.Parse(coord[2], Utils.EnUsCulture);
                        float x = 0, y = 0;

                        instance.TabConsole.DisplayNotificationInChat("Starting teleport...");
                        ulong h = Helpers.GlobalPosToRegionHandle(gx, gy, out x, out y);
                        client.Self.RequestTeleport(h, new Vector3(x, y, z));
                    }
                    catch (Exception) { }

                    break;

                    #region #RLV folder and outfit manipulation
                case "getoutfit":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        var    wearables = client.Appearance.GetWearables();
                        string res       = "";

                        // Do we have a specific wearable to check, ie @getoutfit:socks=99
                        if (!string.IsNullOrEmpty(rule.Option))
                        {
                            if (wearables.ContainsKey(WearableFromString(rule.Option)))
                            {
                                res = "1";
                            }
                            else
                            {
                                res = "0";
                            }
                        }
                        else
                        {
                            for (int i = 0; i < RLVWearables.Count; i++)
                            {
                                if (wearables.ContainsKey(RLVWearables[i].Type))
                                {
                                    res += "1";
                                }
                                else
                                {
                                    res += "0";
                                }
                            }
                        }
                        Respond(chan, res);
                    }
                    break;

                case "getattach":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        string res         = "";
                        var    attachments = client.Network.CurrentSim.ObjectsPrimitives.FindAll(p => p.ParentID == client.Self.LocalID);
                        if (attachments.Count > 0)
                        {
                            var myPoints = new List <AttachmentPoint>(attachments.Count);
                            for (int i = 0; i < attachments.Count; i++)
                            {
                                if (!myPoints.Contains(attachments[i].PrimData.AttachmentPoint))
                                {
                                    myPoints.Add(attachments[i].PrimData.AttachmentPoint);
                                }
                            }

                            // Do we want to check one single attachment
                            if (!string.IsNullOrEmpty(rule.Option))
                            {
                                if (myPoints.Contains(AttachmentPointFromString(rule.Option)))
                                {
                                    res = "1";
                                }
                                else
                                {
                                    res = "0";
                                }
                            }
                            else
                            {
                                for (int i = 0; i < RLVAttachments.Count; i++)
                                {
                                    if (myPoints.Contains(RLVAttachments[i].Point))
                                    {
                                        res += "1";
                                    }
                                    else
                                    {
                                        res += "0";
                                    }
                                }
                            }
                        }
                        Respond(chan, res);
                    }
                    break;

                case "remattach":
                case "detach":
                    if (rule.Param == "force")
                    {
                        if (!string.IsNullOrEmpty(rule.Option))
                        {
                            var point = RLVAttachments.Find(a => a.Name == rule.Option);
                            if (point.Name == rule.Option)
                            {
                                var attachment = client.Network.CurrentSim.ObjectsPrimitives.Find(p => p.ParentID == client.Self.LocalID && p.PrimData.AttachmentPoint == point.Point);
                                if (attachment != null && client.Inventory.Store.Items.ContainsKey(CurrentOutfitFolder.GetAttachmentItem(attachment)))
                                {
                                    instance.COF.Detach((InventoryItem)client.Inventory.Store.Items[CurrentOutfitFolder.GetAttachmentItem(attachment)].Data);
                                }
                            }
                            else
                            {
                                InventoryNode folder = FindFolder(rule.Option);
                                if (folder != null)
                                {
                                    var outfit = new List <InventoryItem>();
                                    foreach (var item in folder.Nodes.Values)
                                    {
                                        if (CurrentOutfitFolder.CanBeWorn(item.Data))
                                        {
                                            outfit.Add((InventoryItem)(item.Data));
                                        }
                                    }
                                    instance.COF.RemoveFromOutfit(outfit);
                                }
                            }
                        }
                        else
                        {
                            client.Network.CurrentSim.ObjectsPrimitives.FindAll(p => p.ParentID == client.Self.LocalID).ForEach(attachment =>
                            {
                                if (client.Inventory.Store.Items.ContainsKey(CurrentOutfitFolder.GetAttachmentItem(attachment)))
                                {
                                    instance.COF.Detach((InventoryItem)client.Inventory.Store.Items[CurrentOutfitFolder.GetAttachmentItem(attachment)].Data);
                                }
                            });
                        }
                    }
                    break;

                case "remoutfit":
                    if (rule.Param == "force")
                    {
                        if (!string.IsNullOrEmpty(rule.Option))
                        {
                            var w = RLVWearables.Find(a => a.Name == rule.Option);
                            if (w.Name == rule.Option)
                            {
                                var items = instance.COF.GetWornAt(w.Type);
                                instance.COF.RemoveFromOutfit(items);
                            }
                        }
                    }
                    break;

                case "attach":
                case "attachoverorreplace":
                case "attachover":
                    if (rule.Param == "force")
                    {
                        if (!string.IsNullOrEmpty(rule.Option))
                        {
                            InventoryNode folder = FindFolder(rule.Option);
                            if (folder != null)
                            {
                                List <InventoryItem> outfit = new List <InventoryItem>();
                                foreach (var item in folder.Nodes.Values)
                                {
                                    if (CurrentOutfitFolder.CanBeWorn(item.Data))
                                    {
                                        outfit.Add((InventoryItem)item.Data);
                                    }
                                }
                                if (rule.Behaviour == "attachover")
                                {
                                    instance.COF.AddToOutfit(outfit, false);
                                }
                                else
                                {
                                    instance.COF.AddToOutfit(outfit, true);
                                }
                            }
                        }
                    }
                    break;

                case "getinv":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        string        res    = string.Empty;
                        InventoryNode folder = FindFolder(rule.Option);
                        if (folder != null)
                        {
                            foreach (var f in folder.Nodes.Values)
                            {
                                if (f.Data is InventoryFolder && !f.Data.Name.StartsWith("."))
                                {
                                    res += f.Data.Name + ",";
                                }
                            }
                        }

                        Respond(chan, res.TrimEnd(','));
                    }
                    break;

                case "getinvworn":
                    if (int.TryParse(rule.Param, out chan) && chan > 0)
                    {
                        string        res  = string.Empty;
                        InventoryNode root = FindFolder(rule.Option);
                        if (root != null)
                        {
                            res += "|" + GetWornIndicator(root) + ",";
                            foreach (var n in root.Nodes.Values)
                            {
                                if (n.Data is InventoryFolder && !n.Data.Name.StartsWith("."))
                                {
                                    res += n.Data.Name + "|" + GetWornIndicator(n) + ",";
                                }
                            }
                        }

                        Respond(chan, res.TrimEnd(','));
                    }
                    break;

                    #endregion #RLV folder and outfit manipulation
                }
            }


            return(true);
        }