コード例 #1
0
        public static object GetObjectFromString(Type t, string s)
        {
            if (t == typeof(string))
            {
                return(s.Replace("\\r", "\r").Replace("\\n", "\n"));
            }
            else if (t == typeof(bool) || t == typeof(byte) || t == typeof(sbyte) || t == typeof(short) || t == typeof(ushort) || t == typeof(int) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong))
            {
                if (s.StartsWith("0x"))
                {
                    if (t == typeof(ulong) || t == typeof(uint) || t == typeof(ushort) || t == typeof(byte))
                    {
                        return(Convert.ChangeType(Convert.ToUInt64(s.Substring(2), 16), t));
                    }
                    else
                    {
                        return(Convert.ChangeType(Convert.ToInt64(s.Substring(2), 16), t));
                    }
                }
                else
                {
                    return(Convert.ChangeType(s, t));
                }
            }
            else if (t == typeof(double) || t == typeof(float))
            {
                return(Convert.ChangeType(s, t));
            }
            else if (IsType(t, typeof(Mobile)))
            {
                return(FindMobile((Serial)Convert.ToInt32(s)));
            }
            else if (IsType(t, typeof(Item)))
            {
                return(FindItem((Serial)Convert.ToInt32(s)));
            }
            else if (IsType(t, typeof(Account)))
            {
                return(Accounts.GetAccount(s));
            }
            else if (IsType(t, typeof(Enum)))
            {
                return(Enum.Parse(t, s));
            }
            else if (IsType(t, typeof(Server.Body)))
            {
                return(new Server.Body(Convert.ToInt32(s.Substring(2), 16)));
            }
            else
            {
                MethodInfo parseMethod = t.GetMethod("Parse", new Type[] { typeof(string) });

                if (parseMethod != null)
                {
                    return(parseMethod.Invoke(null, new object[] { s }));
                }
            }

            return(null);
        }
コード例 #2
0
        private static void TAFLogin(LoginEventArgs args)
        {
            Mobile  m          = args.Mobile;
            Account ac         = (Account)m.Account;
            bool    toldfriend = ToldAFriend(m);
            bool    gotfriend  = GotAFriend(m);

            if (ac.Created >= age)
            {
                if (!toldfriend)
                {
                    m.SendGump(new TAFGump(m));
                }
            }
            else if (toldfriend)
            {
                string  friend     = ac.GetTag("Referrer");
                Account friendacct = Accounts.GetAccount(friend) as Account;
                if (friendacct == null)
                {
                    ac.RemoveTag("Referrer");
                }
                else
                {
                    if (ac.LastLogin > mindate && friendacct.LastLogin > mindate && ac.TotalGameTime >= RewardTime && friendacct.TotalGameTime >= RewardTime)
                    {
                        m.SendMessage(String.Format("Your friend will receive a reward for referring you to {0} next time (s)he logs in.", TAFShardName));
                        //m.SendMessage( String.Format( "You receive a reward for your loyalty to {0}.", TAFShardName ) );
                        //m.AddToBackpack( new ReferrerReward() );
                        if (Convert.ToBoolean(ac.GetTag("GotAFriend")))
                        {
                            string friends = ac.GetTag("GotFriend") + "," + ac.ToString();
                            friendacct.SetTag("GotFriend", friends);
                        }
                        else
                        {
                            friendacct.SetTag("GotAFriend", "true");
                            friendacct.SetTag("GotFriend", ac.ToString());
                        }
                        ac.RemoveTag("Referrer");
                        ac.RemoveTag("ToldAFriend");
                    }
                }
            }
            else if (gotfriend)
            {
                string   friend  = ac.GetTag("GotFriend");
                string[] friends = friend.Split(',');
                for (int i = 0; i < friends.Length; ++i)
                {
                    m.SendMessage(String.Format("You receive a reward and a referral token for referring one of your friends to {0}.", TAFShardName));
                    m.AddToBackpack(new ReferrerReward());
                    //m.AddToBackpack( new DarkwindReferrerToken() );//reward token if using raelis vendor stone idea
                }
                ac.RemoveTag("GotAFriend");
                ac.RemoveTag("GotFriend");
            }
        }
コード例 #3
0
ファイル: SerializeExt.cs プロジェクト: zerodowned/UO-Forever
        public static IAccount ReadAccount(this GenericReader reader, bool defaultToOwner = false)
        {
            string   username = reader.ReadString();
            IAccount a        = Accounts.GetAccount(username ?? String.Empty);

            if (a == null && defaultToOwner)
            {
                a = Accounts.GetAccounts().FirstOrDefault(ac => ac.AccessLevel == AccessLevel.Owner);
            }

            return(a);
        }
コード例 #4
0
            public override void OnResponse(NetState state, RelayInfo info)
            {
                Mobile    from       = state.Mobile;
                Account   acct       = (Account)from.Account;
                ArrayList ip_List    = new ArrayList(acct.LoginIPs);
                int       id         = info.ButtonID;
                Account   tafacc     = null;
                ArrayList tafip_List = new ArrayList();

                if (id == 1)
                {
                    string input = info.GetTextEntry(2).Text;
                    try
                    {
                        tafacc     = Accounts.GetAccount(input) as Account;
                        tafip_List = new ArrayList(tafacc.LoginIPs);
                    }
                    catch (Exception e) { }

                    string initialText = "";

                    if (tafacc == null)
                    {
                        initialText = String.Format("Account: '{0}' NOT found", input);
                    }
                    else if (input == "")
                    {
                        initialText = "Please enter a valid Account name.";
                    }
                    else if (input.ToLower() == acct.ToString().ToLower())
                    {
                        initialText = "You can't enter you own Account name!";
                    }
                    else
                    {
                        bool uniqueIP = true;

                        if (checkIP)
                        {
                            for (int i = 0; i < ip_List.Count; ++i)
                            {
                                if (tafip_List.Contains(ip_List[i]))
                                {
                                    uniqueIP = false;
                                }
                            }

                            if (uniqueIP)
                            {
                                initialText = String.Format("{0} Marked as Referrer", tafacc);
                                acct.SetTag("ToldAFriend", "true");
                                acct.SetTag("Referrer", tafacc.ToString());
                            }
                            else
                            {
                                initialText = "You can't refer another account you own";
                            }
                        }
                        else
                        {
                            initialText = String.Format("{0} Marked as Referrer", tafacc);
                            acct.SetTag("ToldAFriend", "true");
                            acct.SetTag("Referrer", tafacc.ToString());
                        }
                    }
                    from.SendGump(new TAFGump(from, initialText));
                }
                if (id == 2)
                {
                    from.BeginTarget(10, false, TargetFlags.None, new TargetCallback(TAFTarget));
                    from.SendMessage(String.Format("Please target the character of the person who referred you to {0}", TAFShardName));
                }
            }