internal async static void XmppConnection_OnPresence(object sender, Presence pres) { /* Log("Received pres (Bare): " + pres.From.Bare); Log("From user: "******"Pres Type: " + pres.Type); Log("Other stuff: " + pres.InnerXml); //*/ if (pres.From.User.Contains(LoginPacket.AllSummonerData.Summoner.AcctId.ToString())) return; if (pres.From.Bare.Contains("@sec.pvp.net") || pres.From.Bare.Contains("@lvl.pvp.net") || pres.From.Bare.Contains("@conference.pvp.net")) return; SetChatHover(); switch (pres.Type) { case PresenceType.subscribe: case PresenceType.subscribed: MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { FriendInvite pop = new FriendInvite(ChatSubjects.XMPP_SUBSCRIBE, pres); pop.Height = 230; pop.HorizontalAlignment = HorizontalAlignment.Right; pop.VerticalAlignment = VerticalAlignment.Bottom; NotificationGrid.Children.Add(pop); try { AllPlayers.Add(pres.From.User, new ChatPlayerItem()); } catch { } })); break; case PresenceType.unsubscribe: case PresenceType.unsubscribed: await MainWin.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { NotifyPlayerPopup notify = new NotifyPlayerPopup("Friends", string.Format("{0} is no longer your friend", pres.From.User)); })); AllPlayers.Remove(pres.From.User); break; case PresenceType.available: if (!AllPlayers.ContainsKey(pres.From.User)) { if (pres.InnerXml.Contains("profileIcon")) { AllPlayers.Add(pres.From.User, new ChatPlayerItem()); } } ChatPlayerItem Player = AllPlayers[pres.From.User]; Player.IsOnline = false; UpdatePlayers = true; string Presence = pres.Status; if (Presence == null) return; Player.RawPresence = Presence; //For debugging Player.IsOnline = true; using (XmlReader reader = XmlReader.Create(new StringReader(Presence))) { try { while (reader.Read()) { if (!reader.IsStartElement() || reader.IsEmptyElement) continue; #region Parse Presence switch (reader.Name) { case "profileIcon": reader.Read(); Player.ProfileIcon = Convert.ToInt32(reader.Value); break; case "level": reader.Read(); Player.Level = Convert.ToInt32(reader.Value); break; case "wins": reader.Read(); Player.Wins = Convert.ToInt32(reader.Value); break; case "leaves": reader.Read(); Player.Leaves = Convert.ToInt32(reader.Value); break; case "rankedWins": reader.Read(); Player.RankedWins = Convert.ToInt32(reader.Value); break; case "timeStamp": reader.Read(); Player.Timestamp = Convert.ToInt64(reader.Value); break; case "statusMsg": reader.Read(); Player.Status = reader.Value; break; case "dev": reader.Read(); Player.UsingLegendary = true; if (reader.Value == "true") Player.IsLegendaryDev = true; break; case "gameStatus": reader.Read(); Player.GameStatus = reader.Value; break; case "skinname": reader.Read(); Player.Champion = reader.Value; break; case "rankedLeagueName": reader.Read(); Player.LeagueName = reader.Value; break; case "rankedLeagueTier": reader.Read(); Player.LeagueTier = reader.Value; break; case "rankedLeagueDivision": reader.Read(); Player.LeagueDivision = reader.Value; break; } #endregion Parse Presence } } catch (Exception e) { Log(e.Message + " - remember to fix this later instead of avoiding the problem."); } } if (string.IsNullOrWhiteSpace(Player.Status)) Player.Status = "Online"; break; case PresenceType.unavailable: case PresenceType.invisible: if (pres.From.User.Contains(LoginPacket.AllSummonerData.Summoner.AcctId.ToString())) return; try { ChatPlayerItem x = AllPlayers[pres.From.User]; x.IsOnline = false; UpdatePlayers = true; } catch { } break; } }
private async void LocalRuneComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!QuickLoad) //Make loading quicker return; int i = 0; string[] runeIds = Client.LocalRunePages[LocalRuneComboBox.SelectedItem.ToString()].Split(','); var failsafe = Client.LoginPacket.AllSummonerData.SpellBook; try { foreach (string item in runeIds) { Client.LoginPacket.AllSummonerData.SpellBook.BookPages[RuneComboBox.SelectedIndex].SlotEntries[i].RuneId = Convert.ToInt32(item); i++; } if ((await RiotCalls.SaveSpellBook(Client.LoginPacket.AllSummonerData.SpellBook)).DefaultPage == null) { Client.LoginPacket.AllSummonerData.SpellBook = failsafe; var pop = new NotifyPlayerPopup("Save failed", "Failed to use local rune page.") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Client.NotificationGrid.Children.Add(pop); } } catch { Client.LoginPacket.AllSummonerData.SpellBook = failsafe; var pop = new NotifyPlayerPopup("Save failed", "Failed to use local rune page.") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Client.NotificationGrid.Children.Add(pop); } }
/// <summary> /// Main logic behind Champion Select /// </summary> /// <param name="sender"></param> /// <param name="message"></param> private void Select_OnMessageReceived(object sender, object message) { if (message is GameDTO) { #region In Champion Select var champDto = message as GameDTO; //Sometimes chat doesn't work so spam this until it does LatestDto = champDto; Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () => { //Allow all champions to be selected (reset our modifications) var championArray = new ListViewItem[ChampionSelectListView.Items.Count]; ChampionSelectListView.Items.CopyTo(championArray, 0); foreach (ListViewItem y in championArray) { y.IsHitTestVisible = true; y.Opacity = 1; } //Push all teams into one array to save a foreach call (looks messy) if (champDto == null) return; var allParticipants = new List<Participant>(champDto.TeamOne.ToArray()); allParticipants.AddRange(champDto.TeamTwo); int t = 1; if (LatestDto.QueueTypeName == "COUNTER_PICK") //fix for nemesis draft, get your champ from GameDTO { var selectedChamp = champDto.PlayerChampionSelections.Find(item => item.SummonerInternalName == Client.LoginPacket.AllSummonerData.Summoner.InternalName); ChangeSelectedChampionSkins(selectedChamp.ChampionId); } foreach (PlayerParticipant participant in allParticipants.Select(p => p as PlayerParticipant)) { if (participant != null) { PlayerParticipant play = participant; //If it is our turn to pick if (play.PickTurn == champDto.PickTurn) { if (play.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId) { if (Settings.Default.PickBanFocus) Client.MainWin.Focus(); if (Settings.Default.PickBanFlash) Client.MainWin.FlashWindow(); //Allows us to instapick any champ we own. if (Client.usingInstaPick) { bool champbanned = false; //disallow picking banned champs try { foreach ( BannedChampion x in champDto.BannedChampions.Where( x => x.ChampionId == Client.SelectChamp)) champbanned = true; //disallow picking picked champs foreach ( PlayerChampionSelectionDTO selection in champDto.PlayerChampionSelections.Where( selection => selection.ChampionId == Client.SelectChamp)) champbanned = true; var temp = new ListViewItem { Tag = Client.SelectChamp }; if (!champbanned) ListViewItem_PreviewMouseDown(temp, null); Client.usingInstaPick = false; } catch { Client.Log("Something went weird insta-picking a champ", "Error"); } } ChampionSelectListView.IsHitTestVisible = true; ChampionSelectListView.Opacity = 1; GameStatusLabel.Content = "Your turn to pick!"; break; } } if (string.IsNullOrEmpty(participant.SummonerName)) { participant.SummonerName = "Summoner " + t; t++; } } //Otherwise block selection of champions unless in dev mode if (!Client.Dev) { ChampionSelectListView.IsHitTestVisible = false; ChampionSelectListView.Opacity = 0.5; } GameStatusLabel.Content = "Waiting for others to pick..."; } allParticipants = allParticipants.Distinct().ToList(); //Champion select was cancelled if (champDto.GameState == "TEAM_SELECT") { if (CountdownTimer != null) CountdownTimer.Stop(); Client.FixChampSelect(); return; } if (champDto.GameState == "PRE_CHAMP_SELECT") { //Banning phase. Enable banning phase and this will render only champions for ban BanningPhase = true; PurpleBansLabel.Visibility = Visibility.Visible; BlueBansLabel.Visibility = Visibility.Visible; BlueBanListView.Visibility = Visibility.Visible; PurpleBanListView.Visibility = Visibility.Visible; GameStatusLabel.Content = "Bans are on-going"; counter = configType.BanTimerDuration - 3; #region Render Bans BlueBanListView.Items.Clear(); PurpleBanListView.Items.Clear(); foreach (BannedChampion x in champDto.BannedChampions) { var champImage = new Image { Height = 58, Width = 58, Source = champions.GetChampion(x.ChampionId).icon }; if (x.TeamId == 100) BlueBanListView.Items.Add(champImage); else PurpleBanListView.Items.Add(champImage); foreach (var y in championArray.Where(y => (int)y.Tag == x.ChampionId)) { ChampionSelectListView.Items.Remove(y); //Remove from arrays foreach ( ChampionDTO playerChamps in ChampList.ToArray() .Where(playerChamps => x.ChampionId == playerChamps.ChampionId)) { ChampList.Remove(playerChamps); break; } foreach ( ChampionBanInfoDTO banChamps in ChampionsForBan.ToArray() .Where(banChamps => x.ChampionId == banChamps.ChampionId)) { ChampionsForBan.Remove(banChamps); break; } } } #endregion Render Bans } else if (champDto.GameState == "CHAMP_SELECT") { //Picking has started. If pickturn has changed reset timer LastPickTurn = champDto.PickTurn; BanningPhase = false; } else if (champDto.GameState == "POST_CHAMP_SELECT") { //Post game has started. Allow trading CanTradeWith = await RiotCalls.GetPotentialTraders(); HasLockedIn = true; GameStatusLabel.Content = "All players have picked!"; if (configType != null) counter = configType.PostPickTimerDuration - 2; else counter = 10; } else if (champDto.GameState == "START_REQUESTED") { GameStatusLabel.Content = "The game is about to start!"; DodgeButton.IsEnabled = false; //Cannot dodge past this point! counter = 1; } else if (champDto.GameState == "TERMINATED") { var pop = new NotifyPlayerPopup("Player Dodged", "Player has Dodged Queue.") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Client.CurrentPage = previousPage; Client.HasPopped = false; Client.ReturnButton.Content = "Return to Lobby Page"; Client.ReturnButton.Visibility = Visibility.Visible; Client.inQueueTimer.Visibility = Visibility.Visible; Client.NotificationGrid.Children.Add(pop); Client.RiotConnection.MessageReceived -= ChampSelect_OnMessageReceived; //Client.OnFixChampSelect -= ChampSelect_OnMessageReceived; Client.GameStatus = "inQueue"; Client.SetChatHover(); Client.SwitchPage(previousPage); Client.ClearPage(typeof(ChampSelectPage)); } #region Display players BlueListView.Items.Clear(); PurpleListView.Items.Clear(); BlueListView.Items.Refresh(); PurpleListView.Items.Refresh(); int i = 0; bool purpleSide = false; //Aram hack, view other players champions & names (thanks to Andrew) var otherPlayers = new List<PlayerChampionSelectionDTO>(champDto.PlayerChampionSelections.ToArray()); AreWePurpleSide = false; foreach (Participant participant in allParticipants) { Participant tempParticipant = participant; i++; var control = new ChampSelectPlayer(); //Cast AramPlayers as PlayerParticipants. This removes reroll data if (tempParticipant is AramPlayerParticipant) { tempParticipant = (PlayerParticipant)tempParticipant; } if (tempParticipant is PlayerParticipant) { var player = tempParticipant as PlayerParticipant; if (!string.IsNullOrEmpty(player.SummonerName)) { control.PlayerName.Content = player.SummonerName; control.sumName = player.SummonerName; } else { try { AllPublicSummonerDataDTO summoner = await RiotCalls.GetAllPublicSummonerDataByAccount(player.SummonerId); if (summoner.Summoner != null && !string.IsNullOrEmpty(summoner.Summoner.Name)) control.PlayerName.Content = summoner.Summoner.Name; else control.PlayerName.Content = "Unknown Player"; } catch { control.PlayerName.Content = "Unknown Player"; } } foreach (PlayerChampionSelectionDTO selection in champDto.PlayerChampionSelections) { #region Disable picking selected champs PlayerChampionSelectionDTO selection1 = selection; foreach (ListViewItem y in championArray.Where(y => (int)y.Tag == selection1.ChampionId)) { y.IsHitTestVisible = true; y.Opacity = 0.5; if (configType == null) continue; if (!configType.DuplicatePick) continue; y.IsHitTestVisible = false; y.Opacity = 1; } foreach (ListViewItem y in championArray.Where(y => disabledCharacters.Contains((int)y.Tag))) { y.Opacity = .7; y.IsHitTestVisible = false; } #endregion Disable picking selected champs if (selection.SummonerInternalName != player.SummonerInternalName) continue; //Clear our teams champion selection for aram hack otherPlayers.Remove(selection); control = RenderPlayer(selection, player); //If we have locked in render skin select if (!HasLockedIn || selection.SummonerInternalName != Client.LoginPacket.AllSummonerData.Summoner.InternalName || (Client.Dev && champDto.MapId != 12)) continue; if (purpleSide) AreWePurpleSide = true; RenderLockInGrid(selection); if (player.PointSummary == null) continue; LockInButton.Content = string.Format("Reroll ({0}/{1})", player.PointSummary.CurrentPoints, player.PointSummary.PointsCostToRoll); LockInButton.IsEnabled = player.PointSummary.NumberOfRolls > 0; } } else if (tempParticipant is ObfuscatedParticipant) { control.PlayerName.Content = "Summoner " + ((tempParticipant as ObfuscatedParticipant).GameUniqueId - ((tempParticipant as ObfuscatedParticipant).GameUniqueId > 5 ? 5 : 0)); } else if (tempParticipant is BotParticipant) { var bot = tempParticipant as BotParticipant; if (bot.SummonerInternalName.Contains('_')) { string botChamp = bot.SummonerInternalName.Split('_')[1]; //Why is this internal name rito? champions botSelectedChamp = champions.GetChampion(botChamp); var part = new PlayerParticipant(); var selection = new PlayerChampionSelectionDTO { ChampionId = botSelectedChamp.id }; part.SummonerName = botSelectedChamp.displayName + " bot"; control = RenderPlayer(selection, part); } else { control.PlayerName.Content = "Bot"; control.sumName = "Bot"; } } else control.PlayerName.Content = "Unknown Summoner"; //Display purple side if we have gone through our team if (i > champDto.TeamOne.Count) { i = 0; purpleSide = true; } if (!purpleSide) BlueListView.Items.Add(control); else PurpleListView.Items.Add(control); } //Do aram hack! if (otherPlayers.Count <= 0) return; if (AreWePurpleSide) BlueListView.Items.Clear(); else PurpleListView.Items.Clear(); foreach (PlayerChampionSelectionDTO hackSelection in otherPlayers) { var player = new PlayerParticipant { SummonerName = hackSelection.SummonerInternalName }; ChampSelectPlayer control = RenderPlayer(hackSelection, player); if (AreWePurpleSide) BlueListView.Items.Add(control); else PurpleListView.Items.Add(control); } #endregion Display players })); #endregion In Champion Select } else if (message is PlayerCredentialsDto) { Client.RiotConnection.MessageReceived -= ChampSelect_OnMessageReceived; #region Launching Game var dto = message as PlayerCredentialsDto; Client.CurrentGame = dto; if (HasLaunchedGame) return; HasLaunchedGame = true; if (Settings.Default.AutoRecordGames) { Dispatcher.InvokeAsync(async () => { PlatformGameLifecycleDTO n = await RiotCalls.RetrieveInProgressSpectatorGameInfo( Client.LoginPacket.AllSummonerData.Summoner.Name); if (n.GameName != null) { string ip = n.PlayerCredentials.ObserverServerIp + ":" + n.PlayerCredentials.ObserverServerPort; string key = n.PlayerCredentials.ObserverEncryptionKey; var gameId = (int)n.PlayerCredentials.GameId; new ReplayRecorder(ip, gameId, Client.Region.InternalName, key); } }); } Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { if (CountdownTimer != null) CountdownTimer.Stop(); InGame(); Client.ReturnButton.Visibility = Visibility.Hidden; if (!Settings.Default.DisableClientSound) { Client.AmbientSoundPlayer.Stop(); } })); #endregion Launching Game } else if (message is TradeContractDTO) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { var tradeDto = message as TradeContractDTO; if (tradeDto == null) return; switch (tradeDto.State) { case "PENDING": { PlayerTradeControl.Visibility = Visibility.Visible; PlayerTradeControl.Tag = tradeDto; PlayerTradeControl.AcceptButton.Visibility = Visibility.Visible; PlayerTradeControl.DeclineButton.Content = "Decline"; champions myChampion = champions.GetChampion((int)tradeDto.ResponderChampionId); PlayerTradeControl.MyChampImage.Source = myChampion.icon; PlayerTradeControl.MyChampLabel.Content = myChampion.displayName; champions theirChampion = champions.GetChampion((int)tradeDto.RequesterChampionId); PlayerTradeControl.TheirChampImage.Source = theirChampion.icon; PlayerTradeControl.TheirChampLabel.Content = theirChampion.displayName; PlayerTradeControl.RequestLabel.Content = string.Format("{0} wants to trade!", tradeDto.RequesterInternalSummonerName); } break; case "BUSY": case "DECLINED": case "CANCELED": { PlayerTradeControl.Visibility = Visibility.Hidden; TextInfo text = new CultureInfo("en-US", false).TextInfo; var pop = new NotificationPopup(ChatSubjects.INVITE_STATUS_CHANGED, string.Format("{0} has {1} this trade", tradeDto.RequesterInternalSummonerName, text.ToTitleCase(tradeDto.State))); if (tradeDto.State == "BUSY") pop.NotificationTextBox.Text = string.Format("{0} is currently busy", tradeDto.RequesterInternalSummonerName); pop.Height = 200; pop.OkButton.Visibility = Visibility.Visible; pop.HorizontalAlignment = HorizontalAlignment.Right; pop.VerticalAlignment = VerticalAlignment.Bottom; Client.NotificationGrid.Children.Add(pop); //*/ } break; } })); } }
private void LocalSaveButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(LocalName.Text)) { var pop = new NotifyPlayerPopup("Error", "Local rune page name can't be empty.") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Client.NotificationGrid.Children.Add(pop); return; } List<string> local = GetCurrentSlotEntries().Select(id => id.RuneId.ToString()).ToList(); if (Client.LocalRunePages.ContainsKey(LocalName.Text)) Client.LocalRunePages.Remove(LocalName.Text); //Client.LocalRunePages.Add(LocalName.Text, string.Join(",", local)); //Make to League setting like string List<string> saveString = Client.LocalRunePages.Select(item => item.Key + "=" + item.Value).ToList(); try { File.WriteAllLines(Path.Combine(Client.ExecutingDirectory,"RunePages",Client.LoginPacket.AllSummonerData.Summoner.Name, LocalName.Text), saveString); } catch { Client.LocalRunePages.Remove(LocalName.Text); var pop = new NotifyPlayerPopup("Error", "Unable to save local rune pages.") { HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom }; Client.NotificationGrid.Children.Add(pop); } }