示例#1
0
        public override void OnDeath(PlayerEventArgs e)
        {
            base.OnDeath(e);

            ServerDbContext dbContext = ((GameMode)GameMode.Instance).DbContext;

            Data.Dammages = 300;

            if (!Data.Temporary)
            {
                dbContext.SaveChanges();
            }
            else
            {
                this.Dispose();
            }
        }
示例#2
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            this.DisableInteriorEnterExits();
            this.EnableStuntBonusForAll(false);
            this.AllowInteriorWeapons(true);
            this.ManualVehicleEngineAndLights();
            this.ShowPlayerMarkers(SampSharp.GameMode.Definitions.PlayerMarkersMode.Off);
            this.ShowNameTags(false);

            dbContext = new ServerDbContext();

            Console.WriteLine("\n--------------------------------------------");
            Console.WriteLine(" SemiRP originally made by VickeS and Papawy");
            Console.WriteLine("---------------------------------------------\n");

            Console.WriteLine("[Perms] Checking and adding missing permissions...");
            List <Permission> dbPerms = dbContext.Permissions.ToList();

            foreach (string permPath in PermissionList.Perms)
            {
                var perms = permPath.Split('.');

                Permission prevPerm = null;
                string     tmpPath  = "";

                for (uint i = 0; i < perms.Length; i++)
                {
                    if (tmpPath == "")
                    {
                        tmpPath += perms[i];
                    }
                    else
                    {
                        tmpPath += "." + perms[i];
                    }

                    Permission perm = null;
                    ;                   if (!dbPerms.Any(p => p.Name == tmpPath))
                    {
                        perm = new Permission(tmpPath);
                        if (prevPerm != null)
                        {
                            perm.ParentPermission = prevPerm;
                        }

                        dbContext.Permissions.Add(perm);
                        dbPerms.Add(perm);
                        Console.WriteLine("Added " + tmpPath);
                    }
                    else
                    {
                        perm = dbPerms.Single(p => p.Name == tmpPath);
                        if (prevPerm != null && perm.ParentPermission != prevPerm)
                        {
                            perm.ParentPermission       = prevPerm;
                            dbContext.Entry(perm).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        }
                    }
                    dbContext.SaveChanges();
                    prevPerm = perm;
                }
            }
            Console.WriteLine("[Perms] Done.");

            Console.WriteLine("[VehicleModels] Begining checking...");
            InitializeVehicleModel();
            Console.WriteLine("[VehicleModels] Done.");

            Console.WriteLine("[Vehicles] Begining loading...");
            List <VehicleData> vehList = dbContext.Vehicles.ToList();

            foreach (VehicleData vData in vehList)
            {
                try
                {
                    Utils.Vehicles.Helper.CreateFromData(vData);
                }
                catch (Exception)
                {
                    Console.WriteLine("Can't spawn vehicle id " + vData.Id + ".");
                }
            }

            Console.WriteLine("[Vehicles] Done.");

            Console.WriteLine("[Timers] Setup timers...");
            vehicleTimer       = new Timer(Constants.Vehicle.MS500_TIMER, true);
            vehicleTimer.Tick += Vehicle.GlobalTimer;
            Console.WriteLine("Vehicle timer");
            saveTimer       = new Timer(Constants.Timer.SAVE, true);
            saveTimer.Tick += this.SaveTimer;
            Console.WriteLine("Save timer");

            Console.WriteLine("[Timers] Done.");
            Console.WriteLine("[Objects] Begining loading...");
            InitializeObjectOnMap();
            Console.WriteLine("[Objects] Done.");

            Console.WriteLine("-------------Loading finish------------");
        }
示例#3
0
        public override void OnConnected(EventArgs e)
        {
            base.OnConnected(e);

            this.SetSkillLevel(WeaponSkill.Pistol, 998);
            this.SetSkillLevel(WeaponSkill.MicroUzi, 998);
            this.SetSkillLevel(WeaponSkill.SawnoffShotgun, 998);

            AcceptMP = true;

            dbContext = ((GameMode)GameMode.Instance).DbContext;

            bool userExist = false;

            userExist = dbContext.Accounts.Any(a => a.Username == this.Name);

            if (userExist)
            {
                AccountData = dbContext.Accounts
                              .Single(a => a.Username == this.Name);
            }
            else
            {
                Character charactere = dbContext.Characters.Select(x => x).Where(a => a.Name == this.Name).FirstOrDefault();
                if (charactere != null)
                {
                    this.Name   = charactere.Account.Username;
                    AccountData = dbContext.Accounts
                                  .Single(a => a.Username == this.Name);
                    userExist = true;
                }
            }


            this.ToggleSpectating(true);

            if (userExist)
            {
                PlayerLogin login = new PlayerLogin(this, SemiRP.Constants.PASSWORD_MAX_ATTEMPTS);
                login.DialogEnded += (sender, e) =>
                {
                    dbContext.Accounts.Attach(this.AccountData);

                    this.AccountData.LastConnectionIP   = this.IP;
                    this.AccountData.LastConnectionTime = DateTime.Now;

                    dbContext.SaveChanges();

                    PlayerCharacterChoice chrChoiceMenu = new PlayerCharacterChoice(this);
                    chrChoiceMenu.Show();
                };

                login.Begin();
            }
            else
            {
                PlayerRegistration regMenu = new PlayerRegistration();

                regMenu.GetMenu().Ended += (sender, e) =>
                {
                    if (!(e.Data.ContainsKey("password") && e.Data.ContainsKey("email")))
                    {
                        regMenu.Show(this);
                        return;
                    }


                    Account acc = new Account
                    {
                        Email              = (string)e.Data["email"],
                        Username           = this.Name,
                        Nickname           = this.Name,
                        Password           = (string)e.Data["password"],
                        LastConnectionIP   = this.IP,
                        LastConnectionTime = DateTime.Now,
                        PermsSet           = new PermissionSet()
                    };

                    dbContext.Add(acc);
                    dbContext.SaveChanges();

                    this.AccountData = dbContext.Accounts.Single(a => a.Username == this.Name);

                    PlayerCharacterChoice chrChoiceMenu = new PlayerCharacterChoice(this);
                    chrChoiceMenu.Show();
                };

                var regex = new Regex(@"[A-Z][a-z]+_[A-Z][a-z]+([A-Z][a-z]+)*");
                if (regex.IsMatch(this.Name))
                {
                    InputDialog nameChangerDialog = new InputDialog("Changement de nom",
                                                                    "Bienvenue sur le serveur.\nCe compte n'existe pas, cependant, nous avons détecté que vous utilisez un nom Roleplay.\n" +
                                                                    "Ce serveur utilise un système de compte avec personnage, vous créerez votre personnage par la suite.\n" +
                                                                    "Il est donc inutile de garder un nom de compte respectant le format roleplay Prénom_Nom.\n" +
                                                                    "Nous vous proposons donc de le changer ou non suivant votre souhait. Vous pouvez très bien garder le format Prénom_Nom mais il ne correspondera\n" +
                                                                    "pas au nom de votre personnage.\n" +
                                                                    "Veuillez écrire le nom du compte que vous souhaitez utiliser (max 24 charactères) :",
                                                                    false, "Confirmer", "Retour");
                    nameChangerDialog.Response += (sender, eventArg) =>
                    {
                        if (eventArg.DialogButton == DialogButton.Right)
                        {
                            nameChangerDialog.Show(this);
                            return;
                        }
                        if (eventArg.InputText.Length > 24)
                        {
                            nameChangerDialog.Show(this);
                            return;
                        }
                        if (dbContext.Accounts.Where(x => x.Username == eventArg.InputText).Any() || dbContext.Characters.Where(x => x.Name == eventArg.InputText).Any())
                        {
                            nameChangerDialog.Show(this);
                            return;
                        }
                        this.Name = eventArg.InputText;
                        regMenu.Show(this);
                    };
                    nameChangerDialog.Show(this);
                    return;
                }

                regMenu.Show(this);
            }
        }