void XmppConnection_OnMessage(object sender, Message msg) { if (!roomName.Contains(msg.From.User)) { return; } if (msg.From.Resource == Client.LoginPacket.AllSummonerData.Summoner.Name) { return; } Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { if (msg.Body == "This room is not anonymous") { return; } var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = msg.From.Resource + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Turquoise); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = msg.Body.Replace("<![CDATA[", "").Replace("]]>", string.Empty) + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatText.ScrollToEnd(); })); }
public void Update() { ChatText.Document.Blocks.Clear(); ChatPlayerItem tempItem = null; foreach (KeyValuePair <string, ChatPlayerItem> x in Client.AllPlayers) { if (x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content) { tempItem = x.Value; break; } } foreach (string x in tempItem.Messages.ToArray()) { string[] Message = x.Split('|'); TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); if (Message[0] == tempItem.Username) { tr.Text = tempItem.Username + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gold); } else { tr.Text = Message[0] + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue); } tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = x.Replace(Message[0] + "|", "") + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); } ChatText.ScrollToEnd(); }
public void Update() { ChatText.Document.Blocks.Clear(); ChatPlayerItem tempItem = (from x in Client.AllPlayers where x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content select x.Value).FirstOrDefault(); if (tempItem != null) { foreach (string x in tempItem.Messages.ToArray()) { string[] message = x.Split('|'); var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); if (message[0] == tempItem.Username) { tr.Text = tempItem.Username + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gold); } else { tr.Text = message[0] + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue); } tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = x.Replace(message[0] + "|", "") + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); } } ChatText.ScrollToEnd(); }
private void SendButton_Click(object sender, RoutedEventArgs e) { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = Client.LoginPacket.AllSummonerData.Summoner.Name + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = ChatTextBox.Text + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatPlayerItem tempItem = null; string JID = ""; foreach (KeyValuePair <string, ChatPlayerItem> x in Client.AllPlayers) { if (x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content) { tempItem = x.Value; JID = x.Key + "@pvp.net"; break; } } tempItem.Messages.Add(Client.LoginPacket.AllSummonerData.Summoner.Name + "|" + ChatTextBox.Text); ChatText.ScrollToEnd(); Client.ChatClient.Message(JID, Environment.NewLine + ChatTextBox.Text); ChatTextBox.Text = ""; }
public void Update() { ChatText.Document.Blocks.Clear(); var tempItem = (from x in Client.AllPlayers where x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content select x.Value).FirstOrDefault(); if (tempItem != null) { foreach (var x in tempItem.Messages.ToArray()) { var message = x.Split('|'); var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); if (message[0] == tempItem.Username) { tr.Text = DateTime.Now.ToString("[HH:mm] ") + tempItem.Username + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Turquoise); } else { tr.Text = DateTime.Now.ToString("[HH:mm] ") + message[0] + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); } tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = x.Replace(message[0] + "|", string.Empty) + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); } } ChatText.ScrollToEnd(); }
private void SendButton_Click(object sender, RoutedEventArgs e) { var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = Client.LoginPacket.AllSummonerData.Summoner.Name + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.SteelBlue); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = ChatTextBox.Text + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatPlayerItem tempItem = null; string jid = ""; foreach ( var x in Client.AllPlayers.Where(x => x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content)) { tempItem = x.Value; jid = x.Key + "@pvp.net"; break; } if (tempItem != null) { tempItem.Messages.Add(Client.LoginPacket.AllSummonerData.Summoner.Name + "|" + ChatTextBox.Text); } ChatText.ScrollToEnd(); Client.ChatClient.Message(jid, Environment.NewLine + ChatTextBox.Text); ChatTextBox.Text = ""; }
private void SendButton_Click(object sender, RoutedEventArgs e) { var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = Client.LoginPacket.AllSummonerData.Summoner.Name + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = ChatTextBox.Text + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); if (String.IsNullOrEmpty(ChatTextBox.Text)) { return; } _newRoom.PublicMessage(ChatTextBox.Text); ChatTextBox.Text = ""; ChatText.ScrollToEnd(); }
private void RestoreHistory() { Archive.Read(); ChatText.Text = Archive.IsExists() && !Archive.IsEmpty() ? Archive.GetMessages() : Bob.SayGreetings() + "\n"; ChatText.Focus(); ChatText.CaretIndex = ChatText.Text.Length; ChatText.ScrollToEnd(); }
private void GroupChatClient_OnParticipantLeave(Room room, RoomParticipant participant) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = participant.Nick + " left the room." + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); ChatText.ScrollToEnd(); })); }
private void GroupChatClient_OnParticipantJoin(Room room, RoomParticipant participant) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = participant.Nick + " joined the room." + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); ChatText.ScrollToEnd(); participants.Add(new SmallPlayer(participant)); ParticipantList.Items.Refresh(); })); }
public void GroupChatClient_OnMessage(object sender, jabber.protocol.client.Message msg) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { if (msg.Body != "This room is not anonymous") { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = msg.From.Resource + ": "; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = msg.InnerText.Replace("<![CDATA[", "").Replace("]]>", "") + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatText.ScrollToEnd(); } })); }
private async void GroupChatClient_OnParticipantJoin(Room room, RoomParticipant participant) { await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() => { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = participant.Nick + " joined the room." + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); ChatText.ScrollToEnd(); var x = new GroupChatPlayer(); x.SName.Content = participant.Nick; PublicSummoner summoner = await Client.PVPNet.GetSummonerByName(participant.Nick); var uriSource = System.IO.Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", summoner.ProfileIconId + ".png"); x.sIcon.Source = Client.GetImage(uriSource); ParticipantList.Items.Add(x); ParticipantList.Items.Refresh(); })); }
private void Send_Message(object sender, RoutedEventArgs e) { var UserMessage = $"{Bot.ChatMessageFormat("Me", MessageText.Text)}"; var BotMessage = $"{Bob.Answer(MessageText.Text)}"; MessageText.Clear(); Archive.Add(UserMessage); Archive.Add(BotMessage); ChatText.Text += UserMessage + "\n"; ChatText.Text += BotMessage + "\n"; ChatText.ScrollToEnd(); if (Archive.Count() % 10 == 0) { Archive.Write(); } }
private void GroupChatClient_OnParticipantLeave(Room room, RoomParticipant participant) { Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { TextRange tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd); tr.Text = participant.Nick + " left the room." + Environment.NewLine; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); ChatText.ScrollToEnd(); foreach (GroupChatPlayer x in ParticipantList.Items) { if (participant.Nick == (string)x.SName.Content) { ParticipantList.Items.Remove(x); ParticipantList.Items.Refresh(); break; } } })); }
private void SendButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(ChatTextBox.Text)) { return; } var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = DateTime.Now.ToString("[HH:mm] ") + Client.LoginPacket.AllSummonerData.Summoner.Name + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = ChatTextBox.Text + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); ChatPlayerItem tempItem = null; var Jid = string.Empty; foreach ( var x in Client.AllPlayers.Where(x => x.Value.Username == (string)Client.ChatItem.PlayerLabelName.Content)) { tempItem = x.Value; Jid = x.Key + "@pvp.net"; break; } if (tempItem != null) { tempItem.Messages.Add(Client.LoginPacket.AllSummonerData.Summoner.Name + "|" + ChatTextBox.Text); } ChatText.ScrollToEnd(); Client.XmppConnection.Send(new Message(new Jid(Jid), MessageType.chat, ChatTextBox.Text)); ChatTextBox.Text = string.Empty; }
private void SendButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(ChatTextBox.Text)) { return; } var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = Client.LoginPacket.AllSummonerData.Summoner.Name + ": " }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = ChatTextBox.Text + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White); Client.XmppConnection.Send(new Message(new Jid(roomName), MessageType.groupchat, ChatTextBox.Text)); ChatTextBox.Text = string.Empty; ChatText.ScrollToEnd(); }
async void XmppConnection_OnPresence(object sender, Presence pres) { if (pres.From.Bare != roomName) { return; } if (pres.Type != PresenceType.available) { await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => { using (XmlReader reader = XmlReader.Create(new StringReader(pres.InnerXml))) { try { string jid = string.Empty; while (reader.Read()) { if (!reader.IsStartElement() || reader.IsEmptyElement) { continue; } #region Parse Presence switch (reader.Name) { case "jid": reader.Read(); jid = reader.Value; break; } #endregion Parse Presence } var user = Client.GetUserFromJid(jid); var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = user + " left the room." + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); } catch (Exception e) { Client.Log(e.Message + " - remember to fix this later instead of avoiding the problem."); } } ChatText.ScrollToEnd(); foreach ( var x in from GroupChatPlayer x in ParticipantList.Items where pres.From.User == (string)x.SName.Content select x) { ParticipantList.Items.Remove(x); ParticipantList.Items.Refresh(); break; } })); } else { await Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async() => { //ugly hack var user = pres.From.Resource; int ProfileIcon = 0; var x = new GroupChatPlayer(); bool exists = false; foreach (var m in from GroupChatPlayer m in ParticipantList.Items where (m).SName.Content.ToString() == user select m) { x = m; exists = true; } x.SName.Content = user; if (pres.Status == null) { pres.Status = "<profileIcon>3</profileIcon>"; } ProfileIcon = Regex.Split(pres.Status, "<profileIcon>")[1].Split(new[] { "</profileIcon>" }, StringSplitOptions.None)[0].ToInt(); var UriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", ProfileIcon + ".png"); x.SIcon.Source = Client.GetImage(UriSource); if (!exists) { ParticipantList.Items.Add(x); var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd) { Text = user + " joined the room." + Environment.NewLine }; tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow); } ParticipantList.Items.Refresh(); })); } }