Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to log in and returns the correct packet
        /// </summary>
        /// <returns></returns>
        private ConnectResult TryLogin()
        {
            using (var db = new ExteelContext())
            {
                // Find user
                var user = db.Users.SingleOrDefault(u => u.Username == _userName);

                // If not user?
                if (user == null)
                {
                    return(new ConnectResult(1));
                }

                if (user.Password != _passWord)
                {
                    return(new ConnectResult(2));
                }

                GetClient().UserId = user.Id;
            }

            GetClient().UpdateUserFromDatabase();

            if (string.IsNullOrEmpty(GetClient().User.Callsign))
            {
                return(new ConnectResult(-6, GetClient().User));
            }

            return(new ConnectResult(0, GetClient().User));
        }
Ejemplo n.º 2
0
        public GameServer(IPAddress address, int port) : base(address, port)
        {
            using (var db = new ExteelContext())
            {
//                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
            }

            StartedStamp = DateTime.UtcNow;
        }
Ejemplo n.º 3
0
        protected override void RunImpl()
        {
            // Patch to database
            using (var db = new ExteelContext())
            {
                var unit = db.Units.Single(u => u.Id == _patchUnit.Id);

                // Patch unit
                unit.Name = _patchUnit.Name;

                db.SaveChanges();
            }

            GetClient().UpdateUserFromDatabase();

            GetClient().SendPacket(new ServerPackets.Hangar.NameIsValid(true));
        }
        protected override void RunImpl()
        {
            // Patch to database
            using (var db = new ExteelContext())
            {
                var unit = db.Units.Single(u => u.Id == _patchUnit.Id);

                // Patch unit
                unit.Name = _patchUnit.Name;

                unit.HeadId     = _patchUnit.HeadId;
                unit.ChestId    = _patchUnit.ChestId;
                unit.ArmsId     = _patchUnit.ArmsId;
                unit.LegsId     = _patchUnit.LegsId;
                unit.BackpackId = _patchUnit.BackpackId;

                unit.WeaponSet1LeftId = _patchUnit.WeaponSet1LeftId;
                if (_patchUnit.WeaponSet1RightId != -1)
                {
                    unit.WeaponSet1RightId = _patchUnit.WeaponSet1RightId;
                }
                else
                {
                    unit.WeaponSet1RightId = null;
                }

                unit.WeaponSet2LeftId = _patchUnit.WeaponSet2LeftId;
                if (_patchUnit.WeaponSet2RightId != -1)
                {
                    unit.WeaponSet2RightId = _patchUnit.WeaponSet2RightId;
                }
                else
                {
                    unit.WeaponSet2RightId = null;
                }

                unit.Skill1Id = _patchUnit.Skill1Id;
                unit.Skill2Id = _patchUnit.Skill2Id;
                unit.Skill3Id = _patchUnit.Skill3Id;
                unit.Skill4Id = _patchUnit.Skill4Id;

                db.SaveChanges();
            }

            GetClient().UpdateUserFromDatabase();
        }
Ejemplo n.º 5
0
        protected override void RunImpl()
        {
            // TODO: Actually select operator
            var client = GetClient();

            using (var db = new ExteelContext())
            {
                // Get tracked entity
                var user = db.Users
                           .Single(u => u.Id == client.User.Id);

                // Update operator
                user.OperatorId = _operatorId;

                // Save to DB
                db.SaveChanges();
            }

            // Update user
            GetClient().UpdateUserFromDatabase();

            client.SendPacket(new SelectOperatorInfo(_operatorId));
        }
        public async Task <string> PostData([FormData] NameValueCollection data)
        {
            // Validate some stuff
            var user     = data["username"].Trim();
            var pass     = data["password"].Trim();
            var callsign = data["callsign"].Trim();

            if (string.IsNullOrEmpty(user) || user.Length < 3 || user.Length > 10)
            {
                return("YOUR USERNAME HAS TO BE BETWEEN 3 AND 10 CHARACTERS");
            }

            if (string.IsNullOrEmpty(pass) || pass.Length < 3 || pass.Length > 10)
            {
                return("YOUR PASSWORD HAS TO BE BETWEEN 3 AND 10 CHARACTERS");
            }

            if (string.IsNullOrEmpty(callsign) || callsign.Length < 3 || callsign.Length > 10)
            {
                return("YOUR CALLSIGN HAS TO BE BETWEEN 3 AND 10 CHARACTERS");
            }

            // Now validate against db
            using (var db = new ExteelContext())
            {
                if (db.Users.Any(u => u.Username == user))
                {
                    return("THAT USERNAME IS ALREADY TAKEN");
                }

                if (db.Users.Any(u => u.Callsign == callsign))
                {
                    return("THAT CALLSIGN IS ALREADY TAKEN");
                }

                // If not, make them a new account
                var newUser = new ExteelUser
                {
                    Nickname   = callsign,
                    Username   = user,
                    Callsign   = callsign,
                    Coins      = 999999,
                    Credits    = 10000000,
                    Experience = 0,
                    Level      = 50,
                    Rank       = 23,
                    Password   = pass
                };

                newUser.PilotInfo = new PilotInfo
                {
                    AbilityPointsAvailable = 0,
                    AimLevel       = 0,
                    EnLevel        = 0,
                    HpLevel        = 0,
                    MeleeLevel     = 0,
                    MoveSpeedLevel = 0,
                    RangedLevel    = 0,
                    RocketLevel    = 0,
                    ScanRangeLevel = 0,
                    SiegeLevel     = 0,
                    SpLevel        = 0
                };

                newUser.Stats = new List <UserStats>
                {
                    new UserStats
                    {
                        Type = UserStats.StatType.Training
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.Survival
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.TeamSurvival
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.TeamBattle
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.Ctf
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.ClanBattle
                    },
                    new UserStats
                    {
                        Type = UserStats.StatType.DefensiveBattle
                    }
                };

                newUser.Inventory = new UserInventory
                {
                    InventorySize = 100,
                    UnitSlots     = 1,
                    RepairPoints  = 100
                };

                newUser.Inventory.Parts = new List <PartRecord>
                {
                    new PartRecord
                    {
                        TemplateId = 1110001,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 1
                    },
                    new PartRecord
                    {
                        TemplateId = 2220001,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 2
                    },
                    new PartRecord
                    {
                        TemplateId = 3330001,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 3
                    },
                    new PartRecord
                    {
                        TemplateId = 4440001,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 4
                    },
                    new PartRecord
                    {
                        TemplateId = 5550001,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 5
                    },
                    new PartRecord
                    {
                        TemplateId = 7770016,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 7
                    },
                    new PartRecord
                    {
                        TemplateId = 7770016,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 7
                    },
                    new PartRecord
                    {
                        TemplateId = 7770016,
                        Parameters = 4,
                        Color      = Color.Gray,
                        Type       = 7
                    },
                    new PartRecord
                    {
                        TemplateId = 7770016,
                        Parameters = 1,
                        Color      = Color.Gray,
                        Type       = 7
                    }, new PartRecord
                    {
                        TemplateId = 1002,
                        Parameters = 1,
                        Color      = Color.White,
                        Type       = 9
                    }, new PartRecord
                    {
                        TemplateId = 6001,
                    }
                };

                newUser.Inventory.Units = new List <UnitRecord>
                {
                    new UnitRecord
                    {
                        LaunchOrder     = 0,
                        Name            = "ExteelLives",
                        Head            = newUser.Inventory.Parts[0],
                        Chest           = newUser.Inventory.Parts[1],
                        Arms            = newUser.Inventory.Parts[2],
                        Legs            = newUser.Inventory.Parts[3],
                        Backpack        = newUser.Inventory.Parts[4],
                        WeaponSet1Left  = newUser.Inventory.Parts[5],
                        WeaponSet1Right = newUser.Inventory.Parts[6],
                        WeaponSet2Left  = newUser.Inventory.Parts[7],
                        WeaponSet2Right = newUser.Inventory.Parts[8]
                    }
                };

                newUser.Operator    = newUser.Inventory.Parts[10];
                newUser.DefaultUnit = newUser.Inventory.Units[0];

                db.Users.Add(newUser);

                db.SaveChanges();
            }

            return("OK YOURE SIGNED UP");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Updates user with data from database
        /// </summary>
        public void UpdateUserFromDatabase()
        {
            if (UserId == 0)
            {
                return;
            }

            using (var db = new ExteelContext())
            {
                // Find user
                var user = db.Users.SingleOrDefault(u => u.Id == UserId);

                // TODO: Check for ban state / admin state / user already logged in

                // Successful login from here, so assign user

                // Load user inventory
                user.Inventory = db.Inventories
                                 .Include(i => i.Parts)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.Head)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.Chest)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.Arms)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.Legs)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.Backpack)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.WeaponSet1Left)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.WeaponSet1Right)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.WeaponSet2Left)

                                 .Include(i => i.Units)
                                 .ThenInclude(u => u.WeaponSet2Right)

                                 // .Include(i => i.Units)
                                 //     .ThenInclude(u => u.Skill1)
                                 //
                                 // .Include(i => i.Units)
                                 //     .ThenInclude(u => u.Skill2)
                                 //
                                 // .Include(i => i.Units)
                                 //     .ThenInclude(u => u.Skill3)
                                 //
                                 // .Include(i => i.Units)
                                 //     .ThenInclude(u => u.Skill4)
                                 //
                                 .SingleOrDefault(i => i.Id == user.InventoryId);

                // Assign user units
                // TODO: Maybe we can map this, not sure
                user.Inventory.Units.ForEach(u => u.User = user);


                // Load users stats
                db
                .Entry(user)
                .Collection(u => u.Stats)
                .Load();

                // Assign to client
                User = user;

                // Set session
                User.SessionId = Id;
            }
        }
Ejemplo n.º 8
0
        protected override void RunImpl()
        {
            // Patch to database
            using (var db = new ExteelContext())
            {
                var unit = db.Units.Single(u => u.Id == _patchUnit.Id);

                // Patch unit
                unit.Name = _patchUnit.Name;

                unit.HeadId     = _patchUnit.HeadId;
                unit.ChestId    = _patchUnit.ChestId;
                unit.ArmsId     = _patchUnit.ArmsId;
                unit.LegsId     = _patchUnit.LegsId;
                unit.BackpackId = _patchUnit.BackpackId;

                unit.WeaponSet1LeftId = _patchUnit.WeaponSet1LeftId;
                if (_patchUnit.WeaponSet1RightId != -1)
                {
                    unit.WeaponSet1RightId = _patchUnit.WeaponSet1RightId;
                }
                else
                {
                    unit.WeaponSet1RightId = null;
                }

                unit.WeaponSet2LeftId = _patchUnit.WeaponSet2LeftId;
                if (_patchUnit.WeaponSet2RightId != -1)
                {
                    unit.WeaponSet2RightId = _patchUnit.WeaponSet2RightId;
                }
                else
                {
                    unit.WeaponSet2RightId = null;
                }

                unit.Skill1Id = _patchUnit.Skill1Id;
                unit.Skill2Id = _patchUnit.Skill2Id;
                unit.Skill3Id = _patchUnit.Skill3Id;
                unit.Skill4Id = _patchUnit.Skill4Id;

                // Patch parts
                var head = db.Parts.Single(p => p.Id == _patchUnit.HeadId);
                head.Color = _patchHead.Color;

                var chest = db.Parts.Single(p => p.Id == _patchUnit.ChestId);
                chest.Color = _patchChest.Color;

                var arms = db.Parts.Single(p => p.Id == _patchUnit.ArmsId);
                arms.Color = _patchArms.Color;

                var legs = db.Parts.Single(p => p.Id == _patchUnit.LegsId);
                legs.Color = _patchLegs.Color;

                var backpack = db.Parts.Single(p => p.Id == _patchUnit.BackpackId);
                backpack.Color = _patchBackpack.Color;

                // Weapons

                var weaponSet1Left = db.Parts.Single(p => p.Id == _patchUnit.WeaponSet1LeftId);
                weaponSet1Left.Color = _patchWeaponSet1Left.Color;

                var weaponSet1Right = db.Parts.SingleOrDefault(p => p.Id == _patchUnit.WeaponSet1RightId);
                if (weaponSet1Right != null)
                {
                    weaponSet1Right.Color = _patchWeaponSet1Right.Color;
                }

                var weaponSet2Left = db.Parts.Single(p => p.Id == _patchUnit.WeaponSet2LeftId);
                weaponSet2Left.Color = _patchWeaponSet2Left.Color;

                var weaponSet2Right = db.Parts.SingleOrDefault(p => p.Id == _patchUnit.WeaponSet2RightId);
                if (weaponSet2Right != null)
                {
                    weaponSet2Right.Color = _patchWeaponSet2Right.Color;
                }

                db.SaveChanges();
            }

            GetClient().UpdateUserFromDatabase();
        }
Ejemplo n.º 9
0
        protected override void RunImpl()
        {
            var client = GetClient();

            using (var db = new ExteelContext())
            {
                // Get tracked entity
                var user = db.Users
                           .Include(u => u.Inventory)
                           .ThenInclude(i => i.Parts)
                           .Single(u => u.Id == client.User.Id);

                Console.WriteLine("Found user " + user.Id);

                // Lookup good
                var good = ShopDataReader.GetGoodById(_goodId);

                // Subtract money
                // TODO: Handle Coins
                user.Credits -= good.CreditPrice;

                // Create Parts
                foreach (var templateId in good.Templates)
                {
                    PartRecord partRecord;

                    var partsType = (int)templateId;
                    while (partsType >= 10)
                    {
                        partsType /= 10;
                    }

                    // Check if its a code
                    if (templateId < 300)
                    {
                        partRecord      = new Code();
                        partRecord.Type = (byte)9;
                    }
                    // Check for weapon
                    else if (partsType == 6 || partsType == 7 || partsType == 8)
                    {
                        partRecord      = new Weapon();
                        partRecord.Type = (byte)partsType;
                    }
                    else
                    {
                        partRecord      = new PartRecord();
                        partRecord.Type = (byte)partsType;
                    }

                    // Populate info

                    partRecord.TemplateId = templateId;
                    partRecord.Parameters = 1;
                    partRecord.Color      = Color.White;

                    // Add to inventory
                    user.Inventory.Parts.Add(partRecord);

                    //db.Parts.Add(part);
                }

                // Save to DB
                db.SaveChanges();
            }

            GetClient().UpdateUserFromDatabase();

            // Send result
            GetClient().SendPacket(new BuyListResult(GetClient().User));
        }