//Speicify the player
        private async void getPlayerInformation(RlsPlatform platform, bool Steam2)
        {
            if (!platform_set)
            {
                plat = platform;
            }

            bar.Visible     = true;
            button1.Visible = false;

            bar.Value = 1;

            try
            {
                player = await getPlayerTask();
            }
            catch (Exception e)
            {
                Error(e.Message);
                Close();
                return;
            }

            bar.Value  = 3;
            player_set = true;
            openMain();
            this.Hide();
        }
        private ulong GetPlatformRole(RlsPlatform platform)
        {
            switch (platform)
            {
            case RlsPlatform.Steam:
                return(386067580630073356);

            case RlsPlatform.Xbox:
                return(386067821035126784);

            case RlsPlatform.Ps4:
                return(386067907093856256);
            }

            throw new ArgumentException("Invalid platform.");
        }
        public Player_Name_Platform()
        {
            InitializeComponent();
            bar = progressBar1;
            progressBar1.Maximum = 3;
            try
            {
                TextReader tr = new StreamReader("SavedPlayer.txt");
                savedPlayer = tr.ReadLine();
                int.TryParse(tr.ReadLine(), out platform);
                tr.Close();
            }
            catch (FileNotFoundException e)
            {
                ;
            }
            if (savedPlayer != null)
            {
                player_name.Text = savedPlayer;

                if (platform == 0)
                {
                    plat  = RlsPlatform.Steam;
                    Steam = true;
                }
                if (platform == 1)
                {
                    plat  = RlsPlatform.Ps4;
                    Steam = false;
                }
                if (platform == 2)
                {
                    plat  = RlsPlatform.Xbox;
                    Steam = false;
                }

                platform_set = true;
                name         = player_name.Text;
                getPlayerInformation(plat, Steam);
            }
        }
Пример #4
0
 /// <summary>
 ///     Retrieves player data.
 /// </summary>
 /// <param name="platform">The <see cref="RlsPlatform"/> of the player.</param>
 /// <param name="uniqueId">Steam 64 ID / PSN Username / Xbox Gamertag or XUID.</param>
 /// <returns></returns>
 public async Task <Player> GetPlayerAsync(RlsPlatform platform, string uniqueId)
 {
     return(await _api.Get <Player>($"player?unique_id={Uri.EscapeDataString(uniqueId)}&platform_id={(int)platform}"));
 }
Пример #5
0
 /// <summary>
 ///     Initialize a request for <see cref="RLSClient.GetPlayersAsync"/>.
 /// </summary>
 /// <param name="platform">The <see cref="RlsPlatform"/> of the player.</param>
 /// <param name="uniqueId">Steam 64 ID / PSN Username / Xbox Gamertag or XUID.</param>
 public PlayerBatchRequest(RlsPlatform platform, string uniqueId)
 {
     Platform = platform;
     UniqueId = uniqueId;
 }
        public async Task LinkAsync()
        {
            await Context.Channel.TriggerTypingAsync();

            var user = Context.Message.Author as SocketGuildUser;

            try
            {
                // check if discord id is already in the database
                var userinfo = await Database.GetUserInfoAsync(user.Id);

                if (userinfo == null)
                {
                    await ReplyAsync($"{user.Mention}, no account info provided.");

                    return;
                }

                // check if there are still unlinked playlists
                if (userinfo.Elo1s != -1 && userinfo.Elo2s != -1 && userinfo.Elo3s != -1)
                {
                    await ReplyAsync($"{user.Mention}, you've already linked all your rocket league playlists to your discord.");

                    return;
                }

                // get the platform from the user
                RlsPlatform platform = RlsPlatform.Steam;
                if (user.Roles.Contains(Context.Guild.GetRole(386067580630073356)))
                {
                    platform = RlsPlatform.Steam;
                }
                else if (user.Roles.Contains(Context.Guild.GetRole(386067821035126784)))
                {
                    platform = RlsPlatform.Xbox;
                }
                else if (user.Roles.Contains(Context.Guild.GetRole(386067907093856256)))
                {
                    platform = RlsPlatform.Ps4;
                }
                else
                {
                    await ReplyAsync($"{user.Mention}, couldn't retrieve your platform.");

                    return;
                }

                // try to retrieve the account info and check if previously unranked playlists are now ranked
                var player = await _RLSClient.GetPlayerAsync(platform, userinfo.UniqueID);

                if (player == null)
                {
                    await ReplyAsync($"Failed to retrieve player information!");

                    return;
                }

                if (!player.RankedSeasons.TryGetValue(Enum.GetValues(typeof(RlsSeason)).Cast <RlsSeason>().Max(), out var season))
                {
                    await ReplyAsync($"{user.Mention}, the account was found, but no information could be retrieved for the current season.");

                    return;
                }

                List <IRole> roles = new List <IRole>();
                int          rp1   = userinfo.Elo1s;
                if (rp1 == -1 && season.TryGetValue(RlsPlaylistRanked.Duel, out PlayerRank duel))
                {
                    rp1 = duel.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Duel, duel.RankPoints).RoleID));
                }

                int rp2 = userinfo.Elo2s;
                if (rp2 == -1 && season.TryGetValue(RlsPlaylistRanked.Doubles, out PlayerRank doubles))
                {
                    rp2 = doubles.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Doubles, doubles.RankPoints).RoleID));
                }

                int rp3 = userinfo.Elo3s;
                if (rp3 == -1 && season.TryGetValue(RlsPlaylistRanked.Standard, out PlayerRank standard))
                {
                    rp3 = standard.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Standard, standard.RankPoints).RoleID));
                }

                if (rp1 == userinfo.Elo1s && rp2 == userinfo.Elo2s && rp3 == userinfo.Elo3s)
                {
                    await ReplyAsync($"{user.Mention}, no new playlists have been linked.");

                    return;
                }

                // try to add the user to the database with their current elo
                await Database.UpdateUserInfoAsync(user.Id, (short)rp1, (short)rp2, (short)rp3);

                // give the roles to the user
                await user.AddRolesAsync(roles);

                await ReplyAsync($"{user.Mention}, new playlists have been linked!");
            }
            catch (Exception ex)
            {
                await ReplyAsync($"{user.Mention}, " + ex.Message);
            }
        }
        public async Task LinkAsync([OverrideTypeReader(typeof(RLRegionTypeReader))] RLRegion region, [OverrideTypeReader(typeof(RLPlatformTypeReader))] RlsPlatform platform, [Remainder] string uniqueId)
        {
            await Context.Channel.TriggerTypingAsync();

            var user = Context.Message.Author as SocketGuildUser;

            try
            {
                // check if discord id is already in the database
                if (await Database.GetUserInfoAsync(user.Id) != null)
                {
                    await ReplyAsync($"{user.Mention}, you've already linked your rocket league account to your discord. If not all playlists are linked do `!link`.");

                    return;
                }

                // try to retrieve the account info and show it to the user so he/she can confirm it's them
                var player = await _RLSClient.GetPlayerAsync(platform, uniqueId);

                if (player == null)
                {
                    await ReplyAsync($"Failed to retrieve player information!");

                    return;
                }

                var embedBuilder = new EmbedBuilder()
                                   .WithColor(RLBot.EMBED_COLOR)
                                   .WithTitle($"Rocket League Stats")
                                   .AddField("Username", player.DisplayName)
                                   .WithThumbnailUrl(player.Avatar);

                if (!player.RankedSeasons.TryGetValue(Enum.GetValues(typeof(RlsSeason)).Cast <RlsSeason>().Max(), out var season))
                {
                    await ReplyAsync($"{user.Mention}, the following account was found, but no information could be retrieved for the current season.", false, embedBuilder.Build());

                    return;
                }

                List <IRole> roles = new List <IRole>();
                int          rp1   = -1;
                if (season.TryGetValue(RlsPlaylistRanked.Duel, out PlayerRank duel))
                {
                    embedBuilder.AddField("1V1", GetRankString(duel.Tier) + $" ({duel.RankPoints})", true);
                    rp1 = duel.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Duel, duel.RankPoints).RoleID));
                }
                else
                {
                    embedBuilder.AddField("1V1", "Unranked");
                }

                int rp2 = -1;
                if (season.TryGetValue(RlsPlaylistRanked.Doubles, out PlayerRank doubles))
                {
                    embedBuilder.AddField("2V2", GetRankString(doubles.Tier) + $" ({doubles.RankPoints})", true);
                    rp2 = doubles.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Doubles, doubles.RankPoints).RoleID));
                }
                else
                {
                    embedBuilder.AddField("2V2", "Unranked");
                }

                int rp3 = -1;
                if (season.TryGetValue(RlsPlaylistRanked.Standard, out PlayerRank standard))
                {
                    embedBuilder.AddField("3V3", GetRankString(standard.Tier) + $" ({standard.RankPoints})", true);
                    rp3 = standard.RankPoints;
                    roles.Add(Context.Guild.GetRole(Global.GetRank(RlsPlaylistRanked.Standard, standard.RankPoints).RoleID));
                }
                else
                {
                    embedBuilder.AddField("3V3", "Unranked");
                }

                await ReplyAsync($"{user.Mention}, reply with yes if this is you. (Cannot be undone!)", false, embedBuilder.Build());

                var msg = await NextMessageAsync(timeout : new TimeSpan(0, 0, 30));

                if (msg == null)
                {
                    await ReplyAsync("Message timed out..");

                    return;
                }
                else if (msg.Content.ToLower() != "yes" && msg.Content.ToLower() != "y")
                {
                    await ReplyAsync($"{user.Mention}, account linking cancelled.");

                    return;
                }

                // check if the user has all the required ranks
                if (rp1 == -1 && rp2 == -1 && rp3 == -1)
                {
                    await ReplyAsync($"{user.Mention}, the accounts can't be linked untill you have received a rank in at least 1 playlist.");

                    return;
                }

                // prepare the roles for the user
                roles.Add(Context.Guild.GetRole(GetRegionRole(region)));
                roles.Add(Context.Guild.GetRole(GetPlatformRole(platform)));

                // try to add the user to the database with their current elo
                await Database.InsertUserInfoAsync(user.Id, uniqueId, (short)rp1, (short)rp2, (short)rp3);

                // give the rolse to the user
                await user.AddRolesAsync(roles);

                await ReplyAsync($"Accounts linked succesfull!");
            }
            catch (SqlException ex)
                when(ex.Number == 2627)
                {
                    await ReplyAsync($"{user.Mention}, this account is already linked to someone else.");
                }
            catch (Exception ex)
            {
                await ReplyAsync($"{user.Mention}, " + ex.Message);
            }
        }