コード例 #1
0
 public static void RemoveMobile(Mobile m)
 {
     Mobiles.Remove(m.Serial);
 }
コード例 #2
0
        public static Mobile FindMobile(Serial serial)
        {
            Mobiles.TryGetValue(serial, out Mobile mob);

            return(mob);
        }
コード例 #3
0
        public ActionResult AddToCart(Mobiles mobileDetails)
        {
            using (IfxConnection Con = new IfxConnection(connString))
            {
                Con.Open();
                int selectedQuantity = mobileDetails.Quantity;

                Mobiles   mobile      = new Mobiles();
                DataTable mobileTable = new DataTable();

                string         query = "SELECT * FROM Mobiles Where SLNo = ?";
                IfxDataAdapter ifx   = new IfxDataAdapter(query, Con);
                ifx.SelectCommand.Parameters.Add("SLNo", IfxType.Serial).Value = mobileDetails.SLNo;
                ifx.Fill(mobileTable);

                if (mobileTable.Rows.Count == 1)
                {
                    mobile.SLNo        = Convert.ToInt32(mobileTable.Rows[0][0].ToString());
                    mobile.MobileName  = mobileTable.Rows[0][1].ToString();
                    mobile.Price       = Convert.ToDecimal(mobileTable.Rows[0][2].ToString());
                    mobile.Quantity    = Convert.ToInt32(mobileTable.Rows[0][3].ToString());
                    mobile.Description = mobileTable.Rows[0][4].ToString();
                    mobile.PicURL      = mobileTable.Rows[0][5].ToString();
                    mobile.Model       = mobileTable.Rows[0][6].ToString();
                    mobile.Features    = mobileTable.Rows[0][7].ToString();
                    mobile.Color       = mobileTable.Rows[0][8].ToString();
                    mobile.SimType     = mobileTable.Rows[0][9].ToString();
                }
                else
                {
                    Con.Close();
                    mobile.ErrorMessage = "Error : Unable to get mobile details";
                }

                if (selectedQuantity > mobile.Quantity)
                {
                    Con.Close();
                    mobile.ErrorMessage = "Cannot purchase " + selectedQuantity + " quantities, available quantities are : " + mobile.Quantity;
                }
                else
                {
                    try
                    {
                        searchSLNoInCartTable(Con, mobileDetails.SLNo, mobile, selectedQuantity);
                    }
                    catch (Exception ex)
                    {
                        string createCartTable = "Create table cart (cartid serial PRIMARY KEY, SLNo int, MobileName nvarchar(100) NULL, " +
                                                 " Description nvarchar(250) NULL, PicURL nvarchar(250) NULL, Model nvarchar(50) NULL, Features nvarchar(200) NULL, " +
                                                 "Color nvarchar(20) NULL, SimType nvarchar(10) NULL, Price decimal(18, 2), Quantity int NULL, TotalAmount decimal(18,2))";

                        IfxCommand cmd2 = new IfxCommand(createCartTable, Con);
                        cmd2.ExecuteNonQuery();

                        searchSLNoInCartTable(Con, mobileDetails.SLNo, mobile, selectedQuantity);
                    }
                    finally
                    {
                        Con.Close();
                        mobile.ErrorMessage = "Added to cart successfully";
                    }
                }
                // return View(mobile);
                return(RedirectToAction("Index", "Home"));
            }
        }
コード例 #4
0
 private static Mobile GetOrCreateMobile(Serial serial)
 {
     return(Mobiles.Get(serial) ?? new Mobile(serial));
 }
コード例 #5
0
        private static void OnMobileStatus(Packet p)//0x11
        {
            Mobile mobile = Mobiles.Get(p.ReadUInt());

            if (mobile == null)
            {
                return;
            }

            mobile.Name      = p.ReadASCII(30);
            mobile.Hits      = p.ReadUShort();
            mobile.HitsMax   = p.ReadUShort();
            mobile.Renamable = p.ReadBool();

            byte type = p.ReadByte();

            if (type > 0)
            {
                Player.Female         = p.ReadBool();
                Player.Strength       = p.ReadUShort();
                Player.Dexterity      = p.ReadUShort();
                Player.Intelligence   = p.ReadUShort();
                Player.Stamina        = p.ReadUShort();
                Player.StaminaMax     = p.ReadUShort();
                Player.Mana           = p.ReadUShort();
                Player.ManaMax        = p.ReadUShort();
                Player.Gold           = p.ReadUInt();
                Player.ResistPhysical = p.ReadUShort();
                Player.Weight         = p.ReadUShort();
            }

            if (type >= 5)//ML
            {
                Player.WeightMax = p.ReadUShort();
                p.Skip(1);
            }

            if (type >= 2)//T2A
            {
                p.Skip(2);
            }

            if (type >= 3)//Renaissance
            {
                Player.Followers    = p.ReadByte();
                Player.FollowersMax = p.ReadByte();
            }

            if (type >= 4)//AOS
            {
                Player.ResistFire    = p.ReadUShort();
                Player.ResistCold    = p.ReadUShort();
                Player.ResistPoison  = p.ReadUShort();
                Player.ResistEnergy  = p.ReadUShort();
                Player.Luck          = p.ReadUShort();
                Player.DamageMin     = p.ReadUShort();
                Player.DamageMax     = p.ReadUShort();
                Player.TithingPoints = p.ReadUInt();
            }

            mobile.ProcessDelta();
        }
コード例 #6
0
ファイル: Account.cs プロジェクト: zerodowned/UO-Forever
        public Account(XmlElement node)
        {
            Username = Utility.GetText(node["username"], "empty");

            string plainPassword       = Utility.GetText(node["password"], null);
            string cryptPassword       = Utility.GetText(node["cryptPassword"], null);
            string newCryptPassword    = Utility.GetText(node["newCryptPassword"], null);
            string saltedCryptPassword = Utility.GetText(node["saltedCryptPassword"], null);

            switch (AccountHandler.ProtectPasswords)
            {
            case PasswordProtection.None:
            {
                if (plainPassword != null)
                {
                    SetPassword(plainPassword);
                }
                else if (cryptPassword != null)
                {
                    CryptPassword = cryptPassword;
                }
                else if (newCryptPassword != null)
                {
                    NewCryptPassword = newCryptPassword;
                }
                else if (saltedCryptPassword != null)
                {
                    SaltedCryptPassword = saltedCryptPassword;
                }
                else
                {
                    SetPassword("empty");
                }
            }
            break;

            case PasswordProtection.Crypt:
            {
                if (cryptPassword != null)
                {
                    CryptPassword = cryptPassword;
                }
                else if (plainPassword != null)
                {
                    SetPassword(plainPassword);
                }
                else if (newCryptPassword != null)
                {
                    NewCryptPassword = newCryptPassword;
                }
                else if (saltedCryptPassword != null)
                {
                    SaltedCryptPassword = saltedCryptPassword;
                }
                else
                {
                    SetPassword("empty");
                }
            }
            break;

            case PasswordProtection.NewCrypt:
            {
                if (newCryptPassword != null)
                {
                    NewCryptPassword = newCryptPassword;
                }
                else if (plainPassword != null)
                {
                    SetPassword(plainPassword);
                }
                else if (cryptPassword != null)
                {
                    CryptPassword = cryptPassword;
                }
                else if (saltedCryptPassword != null)
                {
                    SaltedCryptPassword = saltedCryptPassword;
                }
                else
                {
                    SetPassword("empty");
                }
            }
            break;

            default:
            {
                if (saltedCryptPassword != null)
                {
                    SaltedCryptPassword = saltedCryptPassword;
                }
                else if (plainPassword != null)
                {
                    SetPassword(plainPassword);
                }
                else if (cryptPassword != null)
                {
                    CryptPassword = cryptPassword;
                }
                else if (newCryptPassword != null)
                {
                    NewCryptPassword = newCryptPassword;
                }
                else
                {
                    SetPassword("empty");
                }
            }
            break;
            }

            AccessLevel al;

            if (Enum.TryParse(Utility.GetText(node["accessLevel"], "Player"), true, out al))
            {
                AccessLevel = al;
            }

            Flags     = Utility.GetXMLInt32(Utility.GetText(node["flags"], "0"), 0);
            Created   = Utility.GetXMLDateTime(Utility.GetText(node["created"], null), DateTime.UtcNow);
            LastLogin = Utility.GetXMLDateTime(Utility.GetText(node["lastLogin"], null), DateTime.UtcNow);

            Email            = Utility.GetText(node["email"], String.Empty);
            Language         = Utility.GetText(node["language"], String.Empty);
            SecurityQuestion = Utility.GetText(node["secquest"], String.Empty);
            SecurityAnswer   = Utility.GetText(node["secanswer"], String.Empty);

            Mobiles        = LoadMobiles(node);
            Comments       = LoadComments(node);
            Tags           = LoadTags(node);
            LoginIPs       = LoadAddressList(node);
            IPRestrictions = LoadAccessCheck(node);

            foreach (Mobile t in Mobiles.Where(m => m != null))
            {
                t.Account = this;
            }

            TimeSpan totalGameTime = Utility.GetXMLTimeSpan(Utility.GetText(node["totalGameTime"], null), TimeSpan.Zero);

            if (totalGameTime == TimeSpan.Zero)
            {
                totalGameTime = Mobiles.OfType <PlayerMobile>().Aggregate(totalGameTime, (current, m) => current + m.GameTime);
            }

            TotalAcctGameTime = totalGameTime;

            if (Young)
            {
                CheckYoung();
            }

            Accounts.Add(this);
        }
コード例 #7
0
        public ActionResult Create(Mobiles mobilesModel)
        {
            // To create a Unique file name and URL everytime when User upload a new picture
            string ImageFileName      = Path.GetFileNameWithoutExtension(mobilesModel.ImageFile.FileName);
            string ImageFileExtension = Path.GetExtension(mobilesModel.ImageFile.FileName);
            string FinalImageName     = ImageFileName + DateTime.Now.ToString("yymmssfff") + ImageFileExtension;

            mobilesModel.PicURL = FinalImageName;
            // To save that newly uploaded image to Disk location inside wwwroot/Images folder
            var uploads   = Path.Combine(hostingEnvironment.WebRootPath, "Images");
            var imagePath = Path.Combine(uploads, FinalImageName);

            FileStream fileStream = new FileStream(imagePath, FileMode.Create);

            mobilesModel.ImageFile.CopyTo(fileStream);
            fileStream.Close();


            //string fileByteArray = null;
            //var fileBytes = 0;

            /*
             * if (mobilesModel.ImageFile.Length > 0)
             * {
             *  using (var ms = new MemoryStream())
             *  {
             *      //mobilesModel.ImageFile.CopyTo(ms);
             *      //var fileBytes = ms.ToArray();
             *      //fileByteArray = Convert.ToBase64String();
             *      // act on the Base64 data
             *
             *      // To save the newly added Mobile and the Image disk imagePath to Database table (Mobiles)
             */
            using (IfxConnection Con = new IfxConnection(connString))
            {
                Con.Open();

                // Insert the form data into mobiles table but not the picture
                string     query = "INSERT INTO Mobiles (MobileName, Price, Quantity, Description, PicURL, Model, Features, Color, SimType) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
                IfxCommand cmd   = new IfxCommand(query, Con);
                cmd.Parameters.Add("mobilename", IfxType.VarChar).Value  = mobilesModel.MobileName;
                cmd.Parameters.Add("price", IfxType.Decimal).Value       = mobilesModel.Price;
                cmd.Parameters.Add("quantity", IfxType.Int).Value        = mobilesModel.Quantity;
                cmd.Parameters.Add("description", IfxType.VarChar).Value = mobilesModel.Description;
                cmd.Parameters.Add("picurl", IfxType.VarChar).Value      = mobilesModel.PicURL;
                cmd.Parameters.Add("model", IfxType.VarChar).Value       = mobilesModel.Model;
                cmd.Parameters.Add("features", IfxType.VarChar).Value    = mobilesModel.Features;
                cmd.Parameters.Add("color", IfxType.VarChar).Value       = mobilesModel.Color;
                cmd.Parameters.Add("simtype", IfxType.VarChar).Value     = mobilesModel.SimType;
                cmd.ExecuteNonQuery();
                cmd.Dispose();

                // Getting the latest inserted row's slno to insert the picture in the same row
                string     selQuery     = "Select max(slno) from Mobiles";
                IfxCommand selcmd       = new IfxCommand(selQuery, Con);
                int        serialnumber = -1;
                try
                {
                    IfxDataReader rows = selcmd.ExecuteReader();
                    while (rows.Read())
                    {
                        serialnumber = Convert.ToInt32(rows[0]);
                    }
                    rows.Close();
                    selcmd.Dispose();

                    string     updatePicQuery = "update mobiles set(imagefile) = (Filetoblob(" + "'" + imagePath + "'" + ", 'client', 'mobiles', 'imagefile')) where slno = ?";
                    IfxCommand insertPiccmd   = new IfxCommand(updatePicQuery, Con);
                    insertPiccmd.Parameters.Add("slno", IfxType.Int).Value = serialnumber;
                    insertPiccmd.ExecuteNonQuery();
                    insertPiccmd.Dispose();

                    // Delete the temprary created image file from Disk

                    FileInfo file = new FileInfo(imagePath);
                    if (file.Exists)
                    {
                        file.Delete();
                    }
                }
                catch (IfxException ex)
                {
                }
                finally
                {
                    Con.Close();
                }
            }
            return(RedirectToAction("Index"));
        }