Exemple #1
0
        private void CreateLogDir()
        {
            string logdir = appdir;   // Application.StartupPath.ToString();

            logdir += "\\Logs\\";

            bool direxists = DirExists(logdir);

            if (!direxists)
            {
                // Create the dir
                Directory.CreateDirectory(logdir);
            }
            else
            {
                long   size  = GetDirectorySize(logdir);
                double fsize = ConvertBytesToMegabytes(size);

                if (fsize > 1000)
                {
                    //DialogResult res = MessageBox.Show("Your chat log folder is over 3GB in size.\n\nDo you want to delete log files older than 60 days?", "METAbolt", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                    tabsConsole.DisplayChatScreen("Your chat log folder is over 1GB in size.");

                    //if (res == DialogResult.Yes)
                    //{
                    //    DirectoryInfo dir = new DirectoryInfo(logdir);

                    //    FileInfo[] rgFiles = dir.GetFiles("*.txt");

                    //    foreach (FileInfo fi in rgFiles)
                    //    {
                    //        if (DateTime.Now.AddDays(-60) > fi.CreationTime)
                    //        {
                    //            fi.Delete();
                    //        }
                    //    }
                    //}
                }
            }

            // Create the Extensions dir
            logdir  = appdir;  // Application.StartupPath.ToString();
            logdir += "\\Extensions\\";

            direxists = DirExists(logdir);

            if (!direxists)
            {
                // Create the dir
                Directory.CreateDirectory(logdir);
            }
        }
        public string ProcessCommand(string command, string name, UUID fromid)
        {
            string icmd = command.Replace(this.instance.Config.CurrentConfig.CommandInID, string.Empty);

            if (instance.Config.CurrentConfig.DisplayLSLcommands)
            {
                tconsole.DisplayChatScreen("Recevided LSL (action) command: " + icmd + " >>> from " + name + " (" + fromid + ")");
            }

            char[]   deli = "|".ToCharArray();
            string[] sGrp = command.Split(deli);

            // Check password first and exit if not valid
            string pwd    = sGrp[1].Trim();
            string md5pwd = GetMD5();

            if (pwd != md5pwd)
            {
                return("LSL Command: Command ignored due to incorrect METAbolt password");
            }

            string cmdtype = sGrp[2].Trim();
            string msg     = string.Empty;

            switch (cmdtype)
            {
            case "WEAR":
                // Format: cmd identifier|password|command type|folder UUID
                UUID folder = (UUID)sGrp[3].Trim();

                if (folder == UUID.Zero)
                {
                    return("IM WEAR COMMAND: Folder UUID can't be empty or null. Failed.");
                }

                try
                {
                    List <InventoryBase> contents = client.Inventory.FolderContents(folder, client.Self.AgentID, true, true, InventorySortOrder.ByName, 20 * 1000);
                    List <InventoryItem> items    = new List <InventoryItem>();

                    if (contents == null)
                    {
                        Logger.Log("IM WEAR COMMAND: Failed to get contents of '" + folder.ToString() + "'", Helpers.LogLevel.Warning);
                        return("IM WEAR COMMAND: Could not get folder contents. Failed");
                    }

                    foreach (InventoryBase iitem in contents)
                    {
                        if (iitem is InventoryItem)
                        {
                            items.Add((InventoryItem)iitem);
                        }
                    }

                    client.Appearance.ReplaceOutfit(items);
                }
                catch (Exception ex)
                {
                    Logger.Log("IM WEAR COMMAND: " + ex.Message, Helpers.LogLevel.Error);
                    return("IM WEAR COMMAND: " + ex.Message + ". Failed");
                }

                //msg = "Wearing folder: " + folder.ToString();
                //client.Self.Chat(msg, 0, ChatType.Whisper);

                break;

            case "AWAY":
                instance.State.SetAway(true);
                break;

            case "NOTAWAY":
                instance.State.SetAway(false);
                break;

            case "BUSY":
                instance.State.SetBusy(true);
                break;

            case "NOTBUSY":
                instance.State.SetBusy(false);
                break;

            case "TP":
                // Format: cmd identifier|password|command type|SIM|coord x|coord y|coord z
                string sim = sGrp[3].Trim();
                float  x   = float.Parse(sGrp[4].Trim());
                float  y   = float.Parse(sGrp[5].Trim());
                float  z   = float.Parse(sGrp[6].Trim());

                client.Self.AutoPilotCancel();

                if (!string.IsNullOrEmpty(sim))
                {
                    netcom.Teleport(sim, new Vector3(x, y, z));
                }
                else
                {
                    Logger.Log("TP COMMAND: SIM name can't be empty. Command has been ignored", Helpers.LogLevel.Info);
                    return("IM TP COMMAND: SIM name can't be empty. Command has been ignored");
                }
                break;

            case "SAY":
                // Format: cmd identifier|password|command type|channel|message|message type
                int      channel  = Convert.ToInt32(sGrp[3].Trim());
                string   msgtosay = sGrp[4].Trim();
                string   ctypein  = sGrp[5].Trim().ToLower();
                ChatType ctype    = ChatType.Normal;

                switch (ctypein)
                {
                case "normal":
                    ctype = ChatType.Normal;
                    break;

                case "ownersay":
                    ctype = ChatType.OwnerSay;
                    break;

                case "regionsay":
                    ctype = ChatType.RegionSay;
                    break;

                case "shout":
                    ctype = ChatType.Shout;
                    break;

                case "whisper":
                    ctype = ChatType.Whisper;
                    break;

                default:
                    ctype = ChatType.Normal;
                    break;
                }

                netcom.ChatOut(msgtosay, ctype, channel);
                break;

            case "GIVE":
                // Format: cmd identifier|password|command type|item UUID|avatar UUID
                UUID imitem = (UUID)sGrp[3].Trim();
                UUID avatar = (UUID)sGrp[4].Trim();

                if (imitem == UUID.Zero || avatar == UUID.Zero)
                {
                    return(string.Empty);
                }

                // Find the item in inventory
                InventoryItem item = client.Inventory.FetchItem(imitem, client.Self.AgentID, 15000);

                if (item == null)
                {
                    Logger.Log("IM GIVE COMMAND: Item " + imitem.ToString() + " not found in inventory", Helpers.LogLevel.Error);
                    return("IM GIVE COMMAND: Item " + imitem.ToString() + " not found in inventory");
                }

                try
                {
                    if ((item.Permissions.OwnerMask & PermissionMask.Transfer) == PermissionMask.Transfer)
                    {
                        if ((item.Permissions.OwnerMask & PermissionMask.Copy) != PermissionMask.Copy)
                        {
                            client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, avatar, false);
                            client.Inventory.Store.RemoveNodeFor(item);
                        }
                        else
                        {
                            client.Inventory.GiveItem(item.UUID, item.Name, item.AssetType, avatar, false);
                            instance.TabConsole.DisplayChatScreen("Gave inventory item  " + item.Name + " (" + imitem + ") to " + avatar + " via ActionCommand received");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("IM GIVE COMMAND: " + ex.Message, Helpers.LogLevel.Error);
                    return("IM GIVE COMMAND: " + ex.Message);
                }

                break;

            case "GIVEFOLDER":
                // Format: cmd identifier|password|command type|folder UUID|folder name|avatar UUID
                UUID   imfolder = (UUID)sGrp[3].Trim();
                string fname    = sGrp[4].Trim();
                UUID   imavatar = (UUID)sGrp[5].Trim();

                if (imfolder == UUID.Zero || imavatar == UUID.Zero)
                {
                    return(string.Empty);
                }

                try
                {
                    client.Inventory.GiveFolder(imfolder, fname, AssetType.Folder, imavatar, true);
                    instance.TabConsole.DisplayChatScreen("Gave inventory folder " + fname + " (" + imfolder + ") to " + imavatar + " via ActionCommand received");
                }
                catch (Exception ex)
                {
                    Logger.Log("ERROR IM GIVEFOLDER COMMAND: " + ex.Message, Helpers.LogLevel.Error);
                    return("ERROR IM GIVEFOLDER COMMAND: " + ex.Message);
                }

                break;

            case "EJECTFROMGROUP":
                UUID groupid  = (UUID)sGrp[3].Trim();
                UUID avatarid = (UUID)sGrp[4].Trim();

                if (groupid == UUID.Zero || avatarid == UUID.Zero)
                {
                    return(string.Empty);
                }

                client.Groups.EjectUser(groupid, avatarid);
                break;

            case "TOUCH":
                UUID itemid = (UUID)sGrp[3].Trim();

                if (itemid == UUID.Zero)
                {
                    return(string.Empty);
                }

                Primitive fav = client.Network.Simulators[0].ObjectsPrimitives.Find((Primitive av) => { return(av.ID == itemid); });

                if (fav == null)
                {
                    return(string.Empty);
                }

                client.Self.Touch(fav.LocalID);
                break;

            case "SIT":
                UUID oid = (UUID)sGrp[3].Trim();

                if (oid == UUID.Zero)
                {
                    return(string.Empty);
                }

                client.Self.AutoPilotCancel();
                instance.State.SetSitting(true, oid);
                break;

            case "STAND":
                UUID sid = (UUID)sGrp[3].Trim();

                client.Self.AutoPilotCancel();

                if (sid == UUID.Zero)
                {
                    return(string.Empty);
                }

                instance.State.SetSitting(false, sid);
                break;

            case "MOVETO":
                string typ = sGrp[3].Trim().ToLower();
                float  xx  = Convert.ToSingle(sGrp[4].Trim());
                float  yy  = Convert.ToSingle(sGrp[5].Trim());
                float  zz  = Convert.ToSingle(sGrp[6].Trim());

                client.Self.AutoPilotCancel();

                client.Self.Movement.SendManualUpdate(AgentManager.ControlFlags.AGENT_CONTROL_AT_POS, client.Self.Movement.Camera.Position,
                                                      client.Self.Movement.Camera.AtAxis, client.Self.Movement.Camera.LeftAxis, client.Self.Movement.Camera.UpAxis,
                                                      client.Self.Movement.BodyRotation, client.Self.Movement.HeadRotation, client.Self.Movement.Camera.Far, AgentFlags.None,
                                                      AgentState.None, true);

                if (typ == "walk")
                {
                    client.Self.Movement.Fly = false;
                    client.Self.Fly(false);
                    client.Self.Movement.AlwaysRun = false;
                }

                if (typ == "run")
                {
                    client.Self.Movement.Fly = false;
                    client.Self.Fly(false);
                    client.Self.Movement.AlwaysRun = true;
                }

                if (typ == "fly")
                {
                    client.Self.Movement.Fly = true;
                    client.Self.Fly(true);
                    client.Self.Movement.AlwaysRun = false;
                }

                ulong regionHandle = client.Network.CurrentSim.Handle;

                ulong followRegionX = regionHandle >> 32;
                ulong followRegionY = regionHandle & (ulong)0xFFFFFFFF;
                ulong ux            = (ulong)(xx + followRegionX);
                ulong uy            = (ulong)(yy + followRegionY);
                float uz            = zz - 2f;

                client.Self.AutoPilot(ux, uy, uz);
                break;

            case "STOP":
                client.Self.AutoPilotCancel();
                client.Self.Movement.Stop = true;
                break;

            case "FOLLOW":
                string flname = sGrp[3].Trim();

                //if (instance.State.FollowName != flname)
                //{
                //    instance.State.Follow(name);
                //}
                //else
                //{
                //    instance.State.Follow(string.Empty);
                //}

                if (string.IsNullOrEmpty(flname))
                {
                    instance.State.Follow(string.Empty);
                }
                else
                {
                    if (instance.State.FollowName != flname)
                    {
                        instance.State.Follow(flname);
                    }
                    else
                    {
                        instance.State.Follow(string.Empty);
                    }
                }
                break;

            case "SENDNOTICE":
                string subject = sGrp[3].Trim();
                string mssg    = sGrp[4].Trim();
                UUID   athmnt  = (UUID)sGrp[5].Trim();
                UUID   ngrp    = (UUID)sGrp[6].Trim();

                GroupNotice sgnotice = new GroupNotice();

                if (ngrp == UUID.Zero)
                {
                    return("Send Notice LSL Command: Group UUID cannot be emptry or zero. Notice has been ignored.");
                }

                try
                {
                    sgnotice.Subject = subject;
                    sgnotice.Message = mssg;

                    if (athmnt != UUID.Zero)
                    {
                        sgnotice.AttachmentID = athmnt;
                        sgnotice.OwnerID      = client.Self.AgentID;
                        sgnotice.SerializeAttachment();
                    }

                    client.Groups.SendGroupNotice(ngrp, sgnotice);
                }
                catch (Exception ex)
                {
                    return("Send Notice LSL Command Error: " + ex.Message);
                }

                break;
            }

            return(msg);
        }