private async void BtnKey_Click(object sender, RoutedEventArgs e) { HttpRequest req = new HttpRequest(); var KeyRoomSelected = selectRoom.Name.Split('_'); FeedsJson.FeedProprety feedProprety = await getDataJson(KeyRoomSelected[2]); if (MqttConnection.ChatRoomNameKey == feedProprety.key) { var valuedata = feedProprety.license.Split('*'); string NewKey = downloadData.DownloadString("https://passwordsgenerator.net/calc.php?Length=50&Symbols=0&Lowercase=1&Uppercase=1&Numbers=1&Nosimilar=1&Last=1"); NewKey = NewKey.Substring(0, 50); if (await req.UpdateFeed(feedProprety.name, feedProprety.key, feedProprety.description, NewKey, valuedata[1], valuedata[2])) { MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_KEY_" + NewKey); DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnKey); ShowSnackBar("Key update successfully!"); } else { DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnKey); ShowSnackBar("Error updating Key!"); } } else { DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnKey); ShowSnackBar("At first, you must be joined to the room!"); } }
private async void BtnTrash_Click(object sender, RoutedEventArgs e) { HttpRequest req = new HttpRequest(); var KeyRoomSelected = selectRoom.Name.Split('_'); FeedsJson.FeedProprety feedProprety = await getDataJson(KeyRoomSelected[2]); MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_CLOSEROOM_" + feedProprety.key); if (await req.DeleteFeed(feedProprety.key)) { DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnKey); ShowSnackBar("Room delete successfully!"); RoomProgressCircle.IsIndeterminate = true; refreshRoom(""); } else { DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnKey); ShowSnackBar("Error deleting Key!"); } }
private async void BtnJoin_Click(object sender, RoutedEventArgs e) { var KeyRoomSelected = selectRoom.Name.Split('_'); FeedsJson.FeedProprety feedProprety = await getDataJson(KeyRoomSelected[2]); if (MqttConnection.ChatRoomNameKey != feedProprety.key) { MqttConnection.MqttUnsubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); var valuedata = feedProprety.license.Split('*'); MqttConnection.ChatRoomNameKey = feedProprety.key; MqttConnection.Key_EndToEnd = valuedata[0]; MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_JOINGROUP_" + feedProprety.name + "_" + valuedata[1]); DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnJoin); ShowSnackBar("Joined successfully!"); } else { DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnJoin); ShowSnackBar("You are already joined!"); } }
private async void GenerateBtn_Click(object sender, RoutedEventArgs e) { if (NameRoom.Text != "" && !string.IsNullOrWhiteSpace(UsernameTxt.Text) && !string.IsNullOrWhiteSpace(AioKeyTxt.Password) && !string.IsNullOrWhiteSpace(Key_EndToEnd.Text) && !Key_EndToEnd.Text.Contains("GENERATE")) { HttpRequest req = new HttpRequest(); string KeyRoomDec = req.getCorretName(NameRoom.Text) + "|" + UsernameTxt.Text + "|" + AioKeyTxt.Password + "|" + Key_EndToEnd.Text + "|" + MqttConnection.NickName + "|" + UrlTxt.Text + "|" + CheckControll.IsChecked + "|" + MqttConnection.MqttServer + "|" + MqttConnection.MqttPort.ToString(); string KeyRoomEnc = StringCipher.Encrypt(KeyRoomDec, ""); if (CheckCurrentData.IsChecked == true) { if (getNumFeed(req.getAllFeeds()) != 10) { MqttConnection.MqttUnsubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString())) { MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text); Clipboard.SetText(KeyRoomEnc); MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\""); Close(); } else { MqttConnection.setKeyEndToEnd(""); MqttConnection.setChatRoomNameKey("chat"); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); ShowSnackBar("Error creating room!"); } } else { ShowSnackBar("Max number of group created, delete one!"); } } else { string tempUser = MqttConnection.UserName; string tempAioKey = MqttConnection.AioKey; MqttConnection.MqttDisconnect(); MqttConnection.setUser(UsernameTxt.Text); MqttConnection.setAioKey(AioKeyTxt.Password); if (!(await MqttConnection.MqttFastConnect())) { MqttConnection.setUser(tempUser); MqttConnection.setAioKey(tempAioKey); ShowSnackBar("Erron to connect with new data!"); UsernameTxt.Focus(); return; } if (getNumFeed(req.getAllFeeds()) != 10) { if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString())) { MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients"); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text); Clipboard.SetText(KeyRoomEnc); MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\""); Close(); } else { MqttConnection.setKeyEndToEnd(""); MqttConnection.setChatRoomNameKey("chat"); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients"); MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey); ShowSnackBar("Error creating room!"); } } else { ShowSnackBar("Max number of group created, delete one!"); } } } else { ShowSnackBar("Complete the box please"); } }