private void PSNLogin_FormClosing(object sender, FormClosingEventArgs e) { if (IniModel.GetPSNRefreshToken() == null) { Environment.Exit(-1); } }
private void PsnPlatformComboBox_SelectedIndexChanged(object sender, EventArgs e) { IniModel.SetPSNPlatform(PsnPlatformComboBox.SelectedItem.ToString()); /*if(OnPS.timer1.Enabled == false) * { * OnPS.timer1.Stop(); * } * try * { * if (OnPS.backgroundWorker1.IsBusy == true) * { * OnPS.backgroundWorker1.CancelAsync(); * } * } * catch(Exception) * { * * } * * try * { * OnPS.backgroundWorker1.RunWorkerAsync(); * } * catch (Exception) * { * * } * OnPS.timer1.Start(); * initGameTypes();*/ }
private void GameStatistic_Load(object sender, EventArgs e) { ArrayList availablePlatforms = GameStatisticModel.GetAvailablePlatforms(onlineId); try { platform = availablePlatforms[0].ToString(); } catch (Exception) { //Platform not found! return; } string defaultPlatform = IniModel.GetPSNPlatform(); /*if (availablePlatforms.IndexOf(defaultPlatform) > -1) * { * availablePlatforms * }*/ foreach (String platform in availablePlatforms) { if (defaultPlatform == platform) { toolStripComboBox1.Items.Insert(0, platform); } else { toolStripComboBox1.Items.Add(platform); } } toolStripComboBox1.SelectedIndex = 0; }
private void SteamTest_Load(object sender, EventArgs e) { if (IniModel.GetSteamUsername() != null) { username.Text = IniModel.GetSteamUsername(); } Program.steam = new Platforms.Steam(); }
private void OnLoginKey(SteamUser.LoginKeyCallback callback) { if (string.IsNullOrEmpty(callback.LoginKey)) { return; } IniModel.SetSteamLoginKey(callback.LoginKey); steamUser.AcceptNewLoginKey(callback); }
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { if (webBrowser1.Url.ToString().Contains("/mobile-success.jsp")) { Uri uri = new Uri(webBrowser1.Url.ToString()); //Convert url to Uri class. string queryString = uri.Query; //Get uri query. NameValueCollection name = HttpUtility.ParseQueryString(queryString); //Some computers may not respond here. code = name["targetUrl"]; //Get Target URL. code = code.Replace("com.playstation.remoteplay.sceappcall://redirect?code=", ""); //Replace target url and get code. PSNAuthData AuthData = Platforms.PSN.AuthWithCode(code); //Authentication with code. IniModel.SetPSNRefreshToken(AuthData.refresh_token); //Get refresh token and save config file. this.Close(); //Close Form } }
private void steamButton2_Click(object sender, EventArgs e) { String username = IniModel.GetSteamUsername(); if (username == null) { Program.Restart(); } this.Cursor = Cursors.WaitCursor; Program.steam = new Platforms.Steam(); Program.steam.manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); Program.steam.manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); Program.steam.Connect(username, ""); this.Cursor = Cursors.Default; }
private void timer1_Tick(object sender, EventArgs e) { Console.WriteLine("Steam.isConnected(): " + Program.steam.isConnected()); Console.WriteLine("Steam.isRunning: " + Program.steam.isRunning); Network.SessionCall(); if (IniModel.GetSteamLoginKey() != null && Program.steam.isConnected() == false && settings == null) { timer1.Stop(); SteamConnErr steamConnErr = new SteamConnErr(); steamConnErr.ShowDialog(); OnGameChangedEvent(this, null); timer1.Start(); } tasks.RunPsnTask(UpdateActivityModel); }
public void RunPsnTask(Func <ArrayList, bool> callback) { if (PsnTask == null || PsnTask.Status == TaskStatus.RanToCompletion) { InitializePsnTask(); } else if (PsnTask.Status == TaskStatus.Running) { return; } PsnTask.ContinueWith((task) => { if (task.IsCanceled || task.IsFaulted) { PsnTaskTokenSource.Cancel(); return; } if (errorCount >= 3) { if (Network.CheckForInternetConnection()) { String[] TokenData = Platforms.PSN.AuthWithRefreshToken(IniModel.GetPSNRefreshToken()); if (TokenData[0] == null) { PsnTaskTokenSource.Cancel(); MessageBox.Show("An unknown error has occurred. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return; } Program.AccessToken = TokenData[0]; errorCount = 0; } else { PsnTaskTokenSource.Cancel(); MessageBox.Show("An unknown error has occurred. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } } callback(lastActivityData); }); //PsnTaskTokenSource.Cancel(); PsnTask.Start(); }
private void Loader_Shown(object sender, EventArgs e) { this.Visible = false; updater.run(); String AccessToken = null; String PSNRefreshToken = IniModel.GetPSNRefreshToken(); if (PSNRefreshToken == null) { this.Hide(); PSN login = new PSN(); login.ShowDialog(); PSNRefreshToken = IniModel.GetPSNRefreshToken(); } try { AccessToken = Platforms.PSN.AuthWithRefreshToken(PSNRefreshToken)[0]; } catch (Exception) { MessageBox.Show("Unable to connect PlayStation Network.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(-1); } if (IniModel.GetSteamUsername() != null && IniModel.GetSteamLoginKey() != null) { Program.steam.manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn); Program.steam.manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnected); Program.steam.Connect(IniModel.GetSteamUsername(), null); } /*else * { * this.Hide(); * SteamLogin steamLogin = new SteamLogin(); * steamLogin.ShowDialog(); * }*/ Program.AccessToken = AccessToken; this.Hide(); OnPS OnPSClient = new OnPS(); OnPSClient.ShowDialog(); }
private void SteamLogoutButton_Click(object sender, EventArgs e) { if (Program.steamAvailable) { IniModel.DeleteSteamLoginKey(); Program.steam.Disconnect(); Program.steam = new Platforms.Steam(); Program.steamAvailable = false; } else { Steam steamLogin = new Steam(); steamLogin.ShowDialog(); steamLogin.Dispose(); steamLogin = null; Program.steamAvailable = Program.steam.isConnected(); } this.Close(); }
private void Settings_Load(object sender, EventArgs e) { if (Program.steamAvailable) { SteamLogButton.Text = "Logout"; } else { SteamLogButton.Text = "Login"; } checkBox1.Checked = Utils.StartupEnabled(); PsnUsernameLabel.Text = OnPS.activityModel.onlineId; SteamUsernameLabel.Text = IniModel.GetSteamUsername(); PsnPlatformComboBox.Text = IniModel.GetPSNPlatform(); initGameTypes(); GameType.SelectedIndex = int.Parse(IniModel.GetGameView()); PsnPlatformComboBox.SelectedIndexChanged += new System.EventHandler(this.PsnPlatformComboBox_SelectedIndexChanged); GameType.SelectedIndexChanged += new System.EventHandler(this.GameType_SelectedIndexChanged); checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged); }
private void OnLoggedOn(SteamUser.LoggedOnCallback callback) { bool isSteamGuard = callback.Result == EResult.AccountLogonDenied; bool is2FA = callback.Result == EResult.AccountLoginDeniedNeedTwoFactor; if (isSteamGuard || is2FA) { Console.WriteLine("This account is SteamGuard protected!"); if (is2FA) { twoFactorAuth = Microsoft.VisualBasic.Interaction.InputBox("Please enter your 2 factor auth code from your authenticator app.", "2 Factor Authentication", "", 0, 0); } else { authCode = Microsoft.VisualBasic.Interaction.InputBox("Please enter the auth code sent to the email at " + callback.EmailDomain, "Authentication", "", 0, 0); } return; } if (callback.Result != EResult.OK) { isRunning = false; return; } Console.WriteLine("Successfully logged on!"); IniModel.SetSteamUsername(username); steamFriends.SetPersonaState(EPersonaState.Online); // at this point, we'd be able to perform actions on Steam }
private void PsnLogoutButton_Click(object sender, EventArgs e) { IniModel.DeletePSNRefreshToken(); Program.Restart(); }
private void GameType_SelectedIndexChanged(object sender, EventArgs e) { Console.WriteLine(GameType.SelectedValue.ToString()); IniModel.SetGameView(GameType.SelectedValue.ToString()); //OnPS.OnGameChangedEvent(OnPS, null); }
public static ActivityModel GetUserActivity(String oauth, bool isMain = false) { JObject o; try { o = JObject.Parse(Network.HTTP_GET("https://us-prof.np.community.playstation.net/userProfile/v1/users/me/profile2?fields=npId,onlineId,avatarUrls,plus,primaryOnlineStatus,presences(@titleInfo,hasBroadcastData)&avatarSizes=m,xl&profilePictureSizes=m,xl&languagesUsedLanguageSet=set3&psVitaTitleIcon=circled&titleIconSize=s", null, "Bearer " + oauth)); } catch (Exception) { return(null); } ActivityModel activityModel = new ActivityModel(isMain); activityModel.onlineId = o.GetValue("profile")["onlineId"].ToString(); activityModel.npId = o.GetValue("profile")["npId"].ToString(); activityModel.plus = Convert.ToInt16(o.GetValue("profile")["plus"]); activityModel.primaryOnlineStatus = o.GetValue("profile")["primaryOnlineStatus"].ToString(); activityModel.avatarUrl = o.GetValue("profile")["avatarUrls"][0]["avatarUrl"].ToString(); activityModel.onlineStatus = OnlineStatusModel.OFFLINE; activityModel.platform = IniModel.GetPSNPlatform(); var presences = o.GetValue("profile")["presences"]; bool SelectedPlatformAvailable = false; foreach (var data in presences) { if (data["platform"] == null) { continue; } if (data["platform"].ToString() == activityModel.platform) { SelectedPlatformAvailable = true; try { activityModel.npTitleIconUrl = data["npTitleIconUrl"].ToString(); } catch (Exception) { activityModel.npTitleIconUrl = null; } try { activityModel.onlineStatus = data["onlineStatus"].ToString(); } catch (Exception) { activityModel.onlineStatus = OnlineStatusModel.OFFLINE; } try { activityModel.titleName = data["titleName"].ToString(); activityModel.npTitleId = data["npTitleId"].ToString(); } catch (Exception) { activityModel.titleName = null; activityModel.npTitleId = null; } try { activityModel.gameStatus = data["gameStatus"].ToString(); } catch (Exception) { activityModel.gameStatus = null; } } if (data["platform"] != null && data["titleName"] != null && data["npTitleId"] != null) { GameData gameData = new GameData(); gameData.platform = data["platform"].ToString(); gameData.titleName = data["titleName"].ToString(); gameData.npTitleId = data["npTitleId"].ToString(); try { gameData.npTitleIconUrl = data["npTitleIconUrl"].ToString(); } catch (Exception) { gameData.npTitleIconUrl = ""; } activityModel.RunningGames.Add(gameData); } } if (SelectedPlatformAvailable == false) { activityModel.onlineStatus = OnlineStatusModel.OFFLINE; } return(activityModel); }