Exemple #1
0
        public static void FindMobile_OnCommand(CommandEventArgs e)
        {
            if (e.Length > 1)
            {
                LogHelper Logger = new LogHelper("findMobile.log", e.Mobile, false);

                // Extract property & value from command parameters

                string sProp = e.GetString(0);
                string sVal  = "";

                if (e.Length > 2)
                {
                    sVal = e.GetString(1);

                    // Concatenate the strings
                    for (int argi = 2; argi < e.Length; argi++)
                    {
                        sVal += " " + e.GetString(argi);
                    }
                }
                else
                {
                    sVal = e.GetString(1);
                }

                Regex PattMatch = new Regex("= \"*" + sVal, RegexOptions.IgnoreCase);

                // Loop through assemblies and add type if has property

                Type[]     types;
                Assembly[] asms = ScriptCompiler.Assemblies;

                ArrayList MatchTypes = new ArrayList();

                for (int i = 0; i < asms.Length; ++i)
                {
                    types = ScriptCompiler.GetTypeCache(asms[i]).Types;

                    foreach (Type t in types)
                    {
                        if (typeof(Mobile).IsAssignableFrom(t))
                        {
                            // Reflect type
                            PropertyInfo[] allProps = t.GetProperties(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);

                            foreach (PropertyInfo prop in allProps)
                            {
                                if (prop.Name.ToLower() == sProp.ToLower())
                                {
                                    MatchTypes.Add(t);
                                }
                            }
                        }
                    }
                }

                // Loop items and check vs. types

                foreach (Mobile m in World.Mobiles.Values)
                {
                    Type t     = m.GetType();
                    bool match = false;

                    foreach (Type MatchType in MatchTypes)
                    {
                        if (t == MatchType)
                        {
                            match = true;
                            break;
                        }
                    }

                    if (match == false)
                    {
                        continue;
                    }

                    // Reflect instance of type (matched)

                    if (PattMatch.IsMatch(Properties.GetValue(e.Mobile, m, sProp)))
                    {
                        Logger.Log(LogType.Mobile, m);
                    }
                }

                Logger.Finish();
            }
            else
            {
                // Badly formatted
                e.Mobile.SendMessage("Format: FindMobile <property> <value>");
            }
        }
Exemple #2
0
        public static void Announcement_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            // check arguments
            if (e.Length != 3)
            {
                Usage(from);
                return;
            }

            // can only be run on Test Center
            if (TestCenter.Enabled == false)
            {
                from.SendMessage("This command may only be executed on Test Center.");
                return;
            }

            int iChecked  = 0;
            int Reminders = 0;

            try
            {
                // loop through the accouints looking for current users
                ArrayList results = new ArrayList();

                int days = 0;
                try { days = Convert.ToInt32(e.GetString(0)); }
                catch { Usage(from); return; }

                foreach (Account acct in Accounts.Table.Values)
                {
                    iChecked++;
                    // logged in the last n days.
                    if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true)
                    {
                        Reminders++;
                        results.Add(acct.EmailAddress);
                    }
                }

                if (Reminders > 0)
                {
                    from.SendMessage("Sending {0} email announcement(s).", Reminders);

                    string subject = String.Format(e.GetString(1));
                    string body    = null;

                    try
                    {
                        // create reader & open file
                        TextReader tr = new StreamReader(String.Format("Msgs/{0}", e.GetString(2)));

                        // read it
                        body = tr.ReadToEnd();

                        // close the stream
                        tr.Close();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogException(ex);
                        from.SendMessage(ex.Message);
                        Usage(from);
                        return;
                    }

                    // okay, now hand the list of users off to our mailer daemon
                    new Emailer().SendEmail(results, subject, body, false);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message);
                System.Console.WriteLine(ex.StackTrace);
            }

            return;
        }
        private static bool Global_OnCommand(CommandEventArgs e)
        {
            if (e.Length == 0)
            {
                e.SendMessage("Need some parametrs");
                return(false);
            }
            int CorrectCount = 0;
            int AllCount     = 0;

            PropsChecker prop        = new PropsChecker();
            int          i           = -1;
            int          startSumbol = 0;

            if (e.GetString(0) == "if")
            {
                startSumbol = 8;
                for (i = 1; (i + 2) < e.Length; i += 3)
                {
                    if (e.GetString(i) == "then")
                    {
                        break;
                    }
                    if (!Server.Scripts.Properties.CharacterProperties.HasProperty(e.GetString(i)) && !Server.Scripts.Properties.MobileProperties.HasProperty(e.GetString(i)))
                    {
                        e.SendMessage("Wrong property \"{0}\" in if_then block", e.GetString(i));
                    }

                    if (!prop.AddProperty(e.GetString(i), e.GetString(i + 1), e.GetString(i + 2)))
                    {
                        e.SendMessage("Wrong sumbol(s) \"{0}\" in if_then block or incorrect type of value \"{1}\"", e.GetString(i + 1), e.GetString(i + 2));
                        return(false);
                    }
                    startSumbol += e.GetString(i).Length + e.GetString(i + 1).Length + e.GetString(i + 2).Length + 3;
                }
            }

            int startNum = i + 1;

            string str = ".";

            for (i = startNum; i < e.Length; i++)
            {
                if (HaveSpaces(e.GetString(i)))
                {
                    str += "\"";
                    str += e.GetString(i);
                    str += "\"";
                }
                else
                {
                    str += e.GetString(i);
                }
                if (i != e.Length - 1)
                {
                    str += " ";
                }
            }
            if (!Commands.HasCommand(e.GetString(startNum)))
            {
                e.SendMessage("Command \"{0}\" dont exist.", e.GetString(startNum));
                return(false);
            }
            if (Commands.TargetType(e.GetString(startNum)) == TargetType.None)
            {
                e.SendMessage("Command \"{0}\" dont have target variable.", e.GetString(startNum));
                return(false);
            }


            MobileList.MobileEnumerator enumerator = World.allMobiles.GetEnumerator();
            {
                try
                {
                    while (enumerator.MoveNext())
                    {
                        Mobile targ = (Mobile)enumerator.Current;
                        if (prop.Check(targ))
                        {
                            if (Commands.Handle(e.Player, targ, str, true))
                            {
                                CorrectCount++;
                            }
                            AllCount++;
                        }
                    }
                }
                finally
                {
                }
            }
            e.SendMessage(String.Format("Command correctly used on {0} of {1} Mobiles in the world", CorrectCount, AllCount));
            return(true);
        }
Exemple #4
0
        public static void AddressDump_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            // check arguments
            if (e.Length < 1)
            {
                Usage(from);
                return;
            }

            int iChecked  = 0;
            int Reminders = 0;

            try
            {
                // loop through the accouints looking for current users
                ArrayList results = new ArrayList();

                // assume DaysActive
                if (e.Length == 1 && LooksLikeInt(e.GetString(0)))
                {
                    int days = 0;
                    try { days = Convert.ToInt32(e.GetString(0)); }
                    catch { Usage(from); return; }
                    foreach (Account acct in Accounts.Table.Values)
                    {
                        iChecked++;
                        // logged in the last n days.
                        if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true)
                        {
                            if (ValidEmail(acct.EmailAddress))
                            {
                                Reminders++;
                                results.Add(acct.EmailAddress);
                            }
                        }
                    }
                }
                // assume activations since date
                else
                {
                    string buff = null;
                    for (int ix = 0; ix < e.Length; ix++)
                    {
                        buff += e.GetString(ix) + " ";
                    }

                    DateTime Since;
                    try { Since = DateTime.Parse(buff); }
                    catch { Usage(from); return; }

                    foreach (Account acct in Accounts.Table.Values)
                    {
                        iChecked++;
                        // account created since...
                        if (acct.Created >= Since && acct.EmailAddress != null)
                        {
                            if (ValidEmail(acct.EmailAddress))
                            {
                                Reminders++;
                                results.Add(acct.EmailAddress);
                            }
                        }
                    }
                }

                if (Reminders > 0)
                {
                    from.SendMessage("Logging {0} email address(es).", Reminders);
                    LogHelper Logger = new LogHelper("accountEmails.log", true);

                    foreach (object ox in results)
                    {
                        string address = ox as string;
                        if (address == null)
                        {
                            continue;
                        }
                        Logger.Log(LogType.Text, address);
                    }
                    Logger.Finish();
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogException(ex);
                System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message);
                System.Console.WriteLine(ex.StackTrace);
            }

            return;
        }
 private static bool Bring_OnCommand(CommandEventArgs e)
 {
     if (e.Length == 1)
     {
         foreach (Account acct in World.allAccounts)
         {
             foreach (Mobile m in acct.characteres)
             {
                 Character ch = m as Character;
                 if (ch.Name.ToLower() == e.GetString(0).ToLower())
                 {
                     if (World.allConnectedChars.Contains(ch))
                     {
                         ch.Teleport(e.Player.X, e.Player.Y, e.Player.Z, e.Player.MapId);
                         return(true);
                     }
                     else
                     {
                         Console.WriteLine("Player is not online.");
                         ch.X     = e.Player.X;
                         ch.Y     = e.Player.Y;
                         ch.Z     = e.Player.Z;
                         ch.MapId = e.Player.MapId;
                         return(true);
                     }
                 }
             }
         }
         e.Player.SendMessage(String.Format("Character with name {0} not found.", e.GetString(0)));
         return(false);
     }
     else if (e.Length == 2 && e.GetString(0).ToLower() == "account")
     {
         foreach (Account acct in World.allAccounts)
         {
             if (acct.Username.ToLower() == e.GetString(1).ToLower())
             {
                 if (acct.SelectedChar != null)
                 {
                     Character m = acct.SelectedChar;
                     m.Teleport(e.Player.X, e.Player.Y, e.Player.Z, e.Player.MapId);
                     return(true);
                 }
                 else
                 {
                     e.Player.SendMessage(String.Format("Account with name '{0}' is not online.", e.GetString(1)));
                     return(false);
                 }
             }
         }
         e.Player.SendMessage(String.Format("Account with name '{0}' not found.", e.GetString(1)));
         return(false);
     }
     else if (e.Length == 0)
     {
         if (e.Target != null)
         {
             if (e.Target is Character)
             {
                 Character ch = e.Target as Character;
                 ch.Teleport(e.Player.X, e.Player.Y, e.Player.Z, e.Player.MapId);
                 return(true);
             }
         }
         e.Player.SendMessage("Select player first.");
     }
     e.Player.SendMessage("Usage : .Bring");
     e.Player.SendMessage("Usage : .Bring <Character Name>");
     e.Player.SendMessage("Usage : .Bring Account <Account Name>");
     return(false);
 }
Exemple #6
0
        private static void Go_OnCommand(CommandEventArgs e)
        {
            Mobile from = e.Mobile;

            if (e.Length == 0)
            {
                GoGump.DisplayTo(from);
            }
            else if (e.Length == 1)
            {
                try
                {
                    int ser = e.GetInt32(0);

                    IEntity ent = World.Instance.FindEntity(ser);

                    if (ent is Item)
                    {
                        Item item = (Item)ent;

                        Map     map = item.Map;
                        Point3D loc = item.GetWorldLocation();

                        Mobile owner = item.RootParent as Mobile;

                        if (owner != null && (owner.Map != null && owner.Map != Map.Internal) && !from.CanSee(owner))
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (!FixMap(ref map, ref loc, item))
                        {
                            from.SendMessage("That is an internal item and you cannot go to it.");
                            return;
                        }

                        from.MoveToWorld(loc, map);

                        return;
                    }
                    else if (ent is Mobile)
                    {
                        Mobile m = (Mobile)ent;

                        Map     map = m.Map;
                        Point3D loc = m.Location;

                        Mobile owner = m;

                        if (owner != null && (owner.Map != null && owner.Map != Map.Internal) && !from.CanSee(owner))
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (owner != null && (owner.Map == null || owner.Map == Map.Internal) && owner.Hidden && owner.AccessLevel >= from.AccessLevel)
                        {
                            from.SendMessage("You can not go to what you can not see.");
                            return;
                        }
                        else if (!FixMap(ref map, ref loc, m))
                        {
                            from.SendMessage("That is an internal mobile and you cannot go to it.");
                            return;
                        }

                        from.MoveToWorld(loc, map);

                        return;
                    }
                    else
                    {
                        string name = e.GetString(0);
                        Map    map;

                        for (int i = 0; i < Map.AllMaps.Count; ++i)
                        {
                            map = Map.AllMaps[i];

                            if (map.MapIndex == 0x7F || map.MapIndex == 0xFF)
                            {
                                continue;
                            }

                            if (Insensitive.Equals(name, map.Name))
                            {
                                from.Map = map;
                                return;
                            }
                        }

                        Dictionary <string, Region> list = from.Map.Regions;

                        foreach (KeyValuePair <string, Region> kvp in list)
                        {
                            Region r = kvp.Value;

                            if (Insensitive.Equals(r.Name, name))
                            {
                                from.Location = new Point3D(r.GoLocation);
                                return;
                            }
                        }

                        for (int i = 0; i < Map.AllMaps.Count; ++i)
                        {
                            Map m = Map.AllMaps[i];

                            if (m.MapIndex == 0x7F || m.MapIndex == 0xFF || from.Map == m)
                            {
                                continue;
                            }

                            foreach (Region r in m.Regions.Values)
                            {
                                if (Insensitive.Equals(r.Name, name))
                                {
                                    from.MoveToWorld(r.GoLocation, m);
                                    return;
                                }
                            }
                        }

                        if (ser != 0)
                        {
                            from.SendMessage("No object with that serial was found.");
                        }
                        else
                        {
                            from.SendMessage("No region with that name was found.");
                        }

                        return;
                    }
                }
                catch
                {
                }

                from.SendMessage("Region name not found");
            }
            else if (e.Length == 2)
            {
                Map map = from.Map;

                if (map != null)
                {
                    int x = e.GetInt32(0), y = e.GetInt32(1);
                    int z = map.GetAverageZ(x, y);

                    from.Location = new Point3D(x, y, z);
                }
            }
            else if (e.Length == 3)
            {
                from.Location = new Point3D(e.GetInt32(0), e.GetInt32(1), e.GetInt32(2));
            }
            else if (e.Length == 6)
            {
                Map map = from.Map;

                if (map != null)
                {
                    Point3D p = Sextant.ReverseLookup(map, e.GetInt32(3), e.GetInt32(0), e.GetInt32(4), e.GetInt32(1), Insensitive.Equals(e.GetString(5), "E"), Insensitive.Equals(e.GetString(2), "S"));

                    if (p != Point3D.Zero)
                    {
                        from.Location = p;
                    }
                    else
                    {
                        from.SendMessage("Sextant reverse lookup failed.");
                    }
                }
            }
            else
            {
                from.SendMessage("Format: Go [name | serial | (x y [z]) | (deg min (N | S) deg min (E | W)]");
            }
        }
        private static bool Dublicate_OnCommand(CommandEventArgs e)
        {
            string    name;
            string    toacctname;
            Character from = new Character();

            if (e.Length == 2 && e.Target != null && e.Target is Character)
            {
                name       = e.GetString(1);
                from       = e.Target as Character;
                toacctname = e.GetString(0);
            }
            else if (e.Length == 3)
            {
                bool found = false;
                name       = e.GetString(2);
                toacctname = e.GetString(1);
                foreach (Account acct in World.allAccounts)
                {
                    foreach (Mobile m in acct.characteres)
                    {
                        Character ch = m as Character;
                        if (ch.Name.ToLower() == e.GetString(0).ToLower())
                        {
                            from  = ch;
                            found = true;
                        }
                    }
                }
                if (!found)
                {
                    e.Player.SendMessage(String.Format("Character with name {0} not found.", e.GetString(0)));
                    return(false);
                }
            }
            else
            {
                e.Player.SendMessage("Usage : .Dublicate <To Account> <New Name>");
                e.Player.SendMessage("Usage : .Dublicate <Character Name> <To Account> <New Name>");
                return(false);
            }

            foreach (Account acct in World.allAccounts)
            {
                foreach (Mobile m in acct.characteres)
                {
                    if (m.Name.ToLower() == name.ToLower())
                    {
                        e.Player.SendMessage(String.Format("Name '{0}' is allready exist.", name));
                        return(false);
                    }
                }
            }
            foreach (Account toacct in World.allAccounts)
            {
                if (toacct.Username.ToLower() == toacctname.ToLower())
                {
                    DublicateCharacter(from, toacct, name);
                    e.Player.SendMessage(String.Format("Character '{0}' successfully dublicated to account '{1}'.", from.Name, toacct.Username));
                    return(true);
                }
            }
            e.Player.SendMessage(String.Format("Account with name '{0}' not found.", toacctname));
            return(false);
        }
Exemple #8
0
        private static void Generate_OnCommand(CommandEventArgs e)
        {
            if (e.Length == 0)
            {
                e.Mobile.SendMessage("You need to provide an action as well as a valid .map name.");
                return;
            }
            else if (e.Length == 1)
            {
                if (e.GetString(0) == "export")
                {
                    try
                    {
                        var baseDir         = Core.BaseDirectory;
                        var export_fileName = Path.Combine(baseDir, string.Format("Data/spawn_export_{0}.map", DateTime.Now.Millisecond));
                        Console.WriteLine(export_fileName);

                        e.Mobile.SendMessage("Now exporting worldspawns to: " + export_fileName);

                        using (var streamWriter = File.AppendText(export_fileName))
                        {
                            var lines      = new List <string>();
                            var spawnCount = 0;
                            foreach (var item in World.Items)
                            {
                                if (item.Value is Spawner)
                                {
                                    var currentSpawn = item.Value as Spawner;
                                    var template     = @"+{0} [{1}]: {2} {3} {4} {5} {6} {7} {8} {9} {10}";
                                    var separator    = string.Empty;

                                    var creaturesToSpawn = string.Empty;
                                    var spawnEntryName   = string.Empty;
                                    // WARNING: this is pre .NET 2.0 code block, later RunUO versions use a true List<string>, not an ArrayList.
                                    if (currentSpawn.CreaturesName != null)
                                    {
                                        // CHECK ALL POSSIBLE CASES
                                        if (currentSpawn.CreaturesName.Count > 1 && currentSpawn.Count > 1)
                                        {
                                            separator = "|";
                                        }
                                        else if (currentSpawn.CreaturesName.Count > 1 && currentSpawn.Count == 1)
                                        {
                                            separator = ",";
                                        }

                                        if (currentSpawn.CreaturesName.Count >= 1)
                                        {
                                            if (currentSpawn.CreaturesName[0] != null)
                                            {
                                                spawnEntryName = currentSpawn.CreaturesName[0].ToString();
                                            }

                                            foreach (var creature in currentSpawn.CreaturesName)
                                            {
                                                creaturesToSpawn += creature.ToString() + separator;
                                            }
                                        }
                                        else if (currentSpawn.CreaturesName.Count == 1)
                                        {
                                            if (currentSpawn.CreaturesName[0] != null)
                                            {
                                                creaturesToSpawn = currentSpawn.CreaturesName[0].ToString();
                                            }


                                            spawnEntryName += "export_" + creaturesToSpawn;
                                        }
                                    }
                                    if (creaturesToSpawn.LastIndexOf(',') > -1)
                                    {
                                        creaturesToSpawn = creaturesToSpawn.Remove(creaturesToSpawn.LastIndexOf(','));
                                    }
                                    if (creaturesToSpawn.LastIndexOf('|') > -1)
                                    {
                                        creaturesToSpawn = creaturesToSpawn.Remove(creaturesToSpawn.LastIndexOf('|'));
                                    }
                                    //
                                    // Basic format
                                    // +name [MobileTypeA, MobileTypeB, etc]: X Y MapID NPCCount HomeRange BringToHome MinTime MaxTime Team Description
                                    // "," can also be "|" depending on spawn being unique or not
                                    var line = string.Format(template, spawnEntryName, creaturesToSpawn, currentSpawn.X.ToString(), currentSpawn.Y.ToString(), currentSpawn.Map.MapID.ToString(),
                                                             currentSpawn.Count.ToString(), currentSpawn.HomeRange.ToString(), false, Math.Round(currentSpawn.MinDelay.TotalMinutes).ToString(),
                                                             Math.Round(currentSpawn.MaxDelay.TotalMinutes).ToString(), currentSpawn.Team.ToString(), string.Empty);

                                    // BringToHome == false because: BringToHome is a Spawn object method telling the spawns to spawn right at the spawn point.
                                    // It's a Prop in the "Spawn" app only because we need to explicitely tell -or not- whether to bring the spawns home or not
                                    // during runtime.

                                    // ATTENTION: CHECK EVERYWHERE THAT UNIQUE SPAWNS HAVE , SEPARATORS (UNIQUE == COUNT @ 1 BUT MULTIPLE AVAILABLE MOBS FROM THE SPAWN POOL)
                                    // CHECK THAT IN THE MAP IMPORTER TOO
                                    // if (UniqueSpawn)
                                    //      separator = ", ";
                                    // else
                                    //      separator = "| ";
                                    lines.Add(line);
                                    spawnCount++;
                                }
                            }
                            foreach (var line in lines)
                            {
                                streamWriter.WriteLine(line);
                            }
                            e.Mobile.SendMessage("Done exporting " + spawnCount.ToString() + " spawns.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            else
            {
                Parse(e.Mobile, e.GetString(0).ToLower(), e.GetString(1).ToLower());
            }
        }