Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
implmented multithreading in a few places
Browse files Browse the repository at this point in the history
  • Loading branch information
Soneliem committed Aug 15, 2021
1 parent 42c915d commit 834fe8a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 61 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ To get the app up and running follow these simple steps.
Please ensure you are in a match when you try to use it. I swear if you complain about it not working and you're not in a match...

If Valorant is already running:
1. Press the big "WAIUA" button and wait about 20-30 seconds
1. Press the big "WAIUA" button and wait about 10 seconds
2. Profit

If Valorant is not running:
1. Press the account button in the top left
2. Use your Riot Account details to log in. Remember to select your region from the bottom left.
3. Open Valorant LMAO
3. Press the big "WAIUA" button and wait about 20-30 seconds
3. Press the big "WAIUA" button and wait about 10 seconds
4. Profit slightly less

Appologies about the long wait to load the information. I have to individually query each player's information from different APIs and then query another API to display images.

## Roadmap and Known Bugs

See the [project board](https://github.com/Soneliem/WAIUA/projects/1) for a list of proposed features (and known verified bugs). Please check the [issues tab](https://github.com/Soneliem/WAIUA/issues) before making a new issue.
See the [project board](https://github.com/Soneliem/WAIUA/projects/1) for a list of proposed features (and known verified bugs). Please check the [issues tab](https://github.com/Soneliem/WAIUA/issues) before making a new issue.

## Why I Made This

Expand Down
61 changes: 16 additions & 45 deletions WAIUA/Commands/APIConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace WAIUA.Commands
{
Expand Down Expand Up @@ -43,6 +44,7 @@ public static class APIConnection
public static string[] PGList { get; set; } = new string[10];
public static string[] PPGList { get; set; } = new string[10];
public static string[] PPPGList { get; set; } = new string[10];

public static void Login(CookieContainer cookie, string username, string password)
{
try
Expand Down Expand Up @@ -116,39 +118,6 @@ public static string Authenticate(CookieContainer cookie, string user, string pa
return client.Execute(request).Content;
}

//My attempt at re-authentication
//public static void Reauth(CookieContainer jar)
//{
// RestClient client = new RestClient(new Uri("https://auth.riotgames.com/authorize?redirect_uri=https%3A%2F%2Fplayvalorant.com%2Fopt_in&client_id=play-valorant-web-prod&response_type=token%20id_token"));
// client.CookieContainer = jar;

// RestRequest request = new RestRequest();

// var response = client.Get(request);
// Uri responseUri = response.ResponseUri;
// var errorMessage = response.ErrorMessage;
// System.Diagnostics.Debug.WriteLine($"Response: {responseUri}");
// System.Diagnostics.Debug.WriteLine($"errorCode: {errorMessage}");

// AccessToken = responseUri.ToString();
// string[] parts = AccessToken.Split(new char[] { '=', '&' });
// AccessToken = parts[1];

// RestClient client2 = new RestClient(new Uri("https://entitlements.auth.riotgames.com/api/token/v1"));
// client2.CookieContainer = jar;
// RestRequest request2 = new RestRequest();

// request2.AddHeader("Authorization", $"Bearer {AccessToken}");
// request2.AddJsonBody("{}");

// var response2 = client2.Post(request2);
// string content = client2.Execute(request2).Content;
// var errorMessage2 = content;
// System.Diagnostics.Debug.WriteLine($"errorCode2: {errorMessage2}");
// var entitlement_token = JsonConvert.DeserializeObject(content);
// JToken entitlement_tokenObj = JObject.FromObject(entitlement_token);
// EntitlementToken = entitlement_tokenObj["entitlements_token"].Value<string>();
//}
public static Boolean CheckLocal()
{
var lockfileLocation = $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Riot Games\Riot Client\Config\lockfile";
Expand Down Expand Up @@ -295,8 +264,9 @@ public static void LiveMatchSetup()
}
if (LiveMatchID(cookie))
{
GetSeasons();
GetLatestVersion();
Parallel.Invoke(
() => GetSeasons(),
() => GetLatestVersion());
string url = $"https://glz-{Region}-1.{Region}.a.pvp.net/core-game/v1/matches/{Matchid}";
RestClient client = new RestClient(url);
RestRequest request = new RestRequest(Method.GET);
Expand Down Expand Up @@ -334,11 +304,12 @@ public static void LiveMatchSetup()
public static string[] LiveMatchOutput(int playerno)
{
CookieContainer cookie = new CookieContainer();
PlayerList[playerno] = GetIGUsername(cookie, PUUIDList[playerno]);
GetAgentInfo(AgentList[playerno], playerno);
GetCardInfo(CardList[playerno], playerno);
GetCompHistory(PUUIDList[playerno], playerno);
GetPlayerHistory(PUUIDList[playerno], playerno);
Parallel.Invoke(
() => PlayerList[playerno] = GetIGUsername(cookie, PUUIDList[playerno]),
() => GetAgentInfo(AgentList[playerno], playerno),
() => GetCardInfo(CardList[playerno], playerno),
() => GetCompHistory(PUUIDList[playerno], playerno),
() => GetPlayerHistory(PUUIDList[playerno], playerno));

string[] output = new string[]{
PlayerList[playerno],
Expand Down Expand Up @@ -457,14 +428,14 @@ public static void GetPlayerHistory(string puuid, int playerno)
string content = client.Execute(request).Content;
dynamic contentobj = JObject.Parse(content);

try
{
rank = contentobj.QueueSkills.competitive.SeasonalInfoBySeasonID[$"{CurrentSeason}"].CompetitiveTier;
}
/*try
{*/
rank = contentobj.QueueSkills.competitive.SeasonalInfoBySeasonID[$"{CurrentSeason}"].CompetitiveTier;
/*}
catch (Exception)
{
rank = "0";
}
}*/
RankList[playerno] = GetLRankIcon(rank);
try
{
Expand Down
2 changes: 1 addition & 1 deletion WAIUA/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
FontSize="20"
Foreground="White"
Opacity="0.7"
Text="Loads live match data if available. This takes 20-30 seconds to load."
Text="Loads live match data if available. This takes around 10 seconds to load."
TextAlignment="Center"
TextWrapping="Wrap" />
</StackPanel>
Expand Down
1 change: 0 additions & 1 deletion WAIUA/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Windows;
using WAIUA.Commands;
using WAIUA.ViewModels;

namespace WAIUA
Expand Down
65 changes: 54 additions & 11 deletions WAIUA/Views/Home.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using WAIUA.Commands;
Expand All @@ -23,22 +24,65 @@ public class HomeInfo
public static string[] Player8 { get; set; }
public static string[] Player9 { get; set; }

private static void SetPlayer(int number)
{
switch (number)
{
case 0:
Player0 = APIConnection.LiveMatchOutput(0);
break;

case 1:
Player1 = APIConnection.LiveMatchOutput(1);
break;

case 2:
Player2 = APIConnection.LiveMatchOutput(2);
break;

case 3:
Player3 = APIConnection.LiveMatchOutput(3);
break;

case 4:
Player4 = APIConnection.LiveMatchOutput(4);
break;

case 5:
Player5 = APIConnection.LiveMatchOutput(5);
break;

case 6:
Player6 = APIConnection.LiveMatchOutput(6);
break;

case 7:
Player7 = APIConnection.LiveMatchOutput(7);
break;

case 8:
Player8 = APIConnection.LiveMatchOutput(8);
break;

case 9:
Player9 = APIConnection.LiveMatchOutput(9);
break;

default:
break;
}
}

public static HomeInfo GetHomeInfo()
{
var output = new HomeInfo() { };
try
{
APIConnection.LiveMatchSetup();
Player0 = APIConnection.LiveMatchOutput(0);
Player1 = APIConnection.LiveMatchOutput(1);
Player2 = APIConnection.LiveMatchOutput(2);
Player3 = APIConnection.LiveMatchOutput(3);
Player4 = APIConnection.LiveMatchOutput(4);
Player5 = APIConnection.LiveMatchOutput(5);
Player6 = APIConnection.LiveMatchOutput(6);
Player7 = APIConnection.LiveMatchOutput(7);
Player8 = APIConnection.LiveMatchOutput(8);
Player9 = APIConnection.LiveMatchOutput(9);
Parallel.For(0, 10, i =>
{
SetPlayer(i);
});
}
catch (System.Exception)
{
Expand All @@ -52,7 +96,6 @@ public Home()
InitializeComponent();
CookieContainer cookie = new CookieContainer();
DataContext = HomeInfo.GetHomeInfo();

}

public void Window_Loaded(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 834fe8a

Please sign in to comment.