Exemple #1
0
        public async Task <RegisterEvent> Register(Client client, string login_, string pass_, string email_, string promo_)
        {
            try
            {
                if (Main.Accounts.ContainsKey(client))
                {
                    Main.Accounts.Remove(client);
                }

                if (Main.SocialClubs.Contains(client.SocialClubName) || Main.SocialClubs.Contains(client.GetData("RealSocialClub")))
                {
                    return(RegisterEvent.SocialReg);
                }

                if (login_.Length < 1 || pass_.Length < 1 || email_.Length < 1)
                {
                    return(RegisterEvent.DataError);
                }
                if (Main.Usernames.Contains(login_))
                {
                    return(RegisterEvent.UserReg);
                }

                if (Main.Emails.ContainsKey(email_))
                {
                    return(RegisterEvent.EmailReg);
                }

                Password   = GetSha256(pass_);
                Login      = login_;
                Email      = email_;
                VipLvl     = 0;
                PromoCodes = new List <string>();
                promo_     = promo_.ToLower();
                if (!promo_.Equals("reborn"))
                {
                    if (string.IsNullOrEmpty(promo_) || !Main.PromoCodes.ContainsKey(promo_))
                    {
                        promo_ = "noref";
                    }
                    else
                    {
                        await MySQL.QueryAsync($"UPDATE promocodes SET count=count+1 WHERE name='{promo_}'");
                    }
                }
                PromoCodes.Add(promo_);

                Characters = new List <int>()
                {
                    -1, -1, -2
                };                                           // -1 - empty slot, -2 - non-purchased slot

                HWID = client.GetData("RealHWID");
                if (client.Address.Equals("80.235.53.64"))
                {
                    IP = "31.13.190.88";
                }
                else
                {
                    IP = client.Address;
                }
                SocialClub = client.GetData("RealSocialClub");
                await MySQL.QueryAsync($"INSERT INTO `accounts` (`login`,`email`,`password`,`hwid`,`ip`,`socialclub`,`redbucks`,`viplvl`,`vipdate`,`promocodes`,`character1`,`character2`,`character3`) " +
                                       $"VALUES ('{Login}','{Email}','{Password}','{HWID}','{IP}','{SocialClub}',0,{VipLvl},'{MySQL.ConvertTime(VipDate)}','{JsonConvert.SerializeObject(PromoCodes)}',-1,-1,-2)");

                Main.SocialClubs.Add(SocialClub);
                Main.Usernames.Add(Login);
                Main.Emails.Add(Email, Login);
                Main.Accounts.Add(client, this);

                MoneySystem.Donations.newNames.Enqueue(Login);
                LoadSlots(client);
                if (!Main.LoggedIn.ContainsKey(login_))
                {
                    Main.LoggedIn.Add(login_, client);
                }
                return(RegisterEvent.Registered);
            }
            catch (Exception ex)
            {
                await Log.WriteAsync(ex.ToString(), nLog.Type.Error);

                return(RegisterEvent.Error);
            }
        }
Exemple #2
0
        public static async Task changeName(string oldName)
        {
            try
            {
                if (!toChange.ContainsKey(oldName))
                {
                    return;
                }

                string newName = toChange[oldName];

                //int UUID = Main.PlayerNames.FirstOrDefault(u => u.Value == oldName).Key;
                int Uuid = Main.PlayerUUIDs.GetValueOrDefault(oldName);
                if (Uuid <= 0)
                {
                    await Log.WriteAsync($"Cant'find UUID of player [{oldName}]", nLog.Type.Warn);

                    return;
                }

                string[] split = newName.Split("_");

                Main.PlayerNames[Uuid] = newName;
                Main.PlayerUUIDs.Remove(oldName);
                Main.PlayerUUIDs.Add(newName, Uuid);
                try {
                    if (Main.PlayerBankAccs.ContainsKey(oldName))
                    {
                        int bank = Main.PlayerBankAccs[oldName];
                        Main.PlayerBankAccs.Add(newName, bank);
                        Main.PlayerBankAccs.Remove(oldName);
                    }
                } catch { }

                MySqlCommand cmd = nameCommand;
                cmd.Parameters.AddWithValue("@fn", split[0]);
                cmd.Parameters.AddWithValue("@ln", split[1]);
                cmd.Parameters.AddWithValue("@uuid", Uuid);
                await MySQL.QueryAsync(cmd);

                NAPI.Task.Run(() =>
                {
                    try
                    {
                        VehicleManager.changeOwner(oldName, newName);
                        BusinessManager.changeOwner(oldName, newName);
                        MoneySystem.Bank.changeHolder(oldName, newName);
                        Houses.HouseManager.ChangeOwner(oldName, newName);
                    }
                    catch { }
                });

                await Log.DebugAsync("Nickname has been changed!", nLog.Type.Success);

                toChange.Remove(oldName);
                MoneySystem.Donations.Rename(oldName, newName);
                GameLog.Name(Uuid, oldName, newName);
            }
            catch (Exception e)
            {
                Log.Write("EXCEPTION AT \"CHANGENAME\":\n" + e.ToString(), nLog.Type.Error);
            }
        }