//Delete favorited world private void FavoriteMenuStrip1_MouseClick(object sender, MouseEventArgs e) { if (FavoritesListView.SelectedIndices.Count == 1) { var id = FavoritesListView.SelectedItems[0].SubItems[1].Text; ListViewItem lvi = new ListViewItem(); lvi.Text = FavoritesListView.SelectedItems[0].SubItems[0].Text; lvi.SubItems.Add(FavoritesListView.SelectedItems[0].SubItems[1].Text); FavBackupListView.Items.Add(lvi); if (!data.ContainsKey(id)) { data.Add(id, FavoritesListView.SelectedItems[0].SubItems[0].Text); } client_.Multiplayer.CreateJoinRoom(id, id.Substring(0, 2) == "BW" ? $"Beta{client_.BigDB.Load("config", "config")["version"]}" : $"Everybodyedits{client_.BigDB.Load("config", "config")["version"]}", true, null, new Dictionary <string, string>() { { "QuickAction", "unfavorite" } }, (Connection con) => { con.OnMessage += (s, m) => { switch (m.Type) { case "unfavorited": if (FavoritesCountLabel.InvokeRequired) { FavoritesCountLabel.Invoke((MethodInvoker) delegate { int tot = Convert.ToInt32(FavoritesCountLabel.Text); int calc = tot - 1; if (calc <= morethanxFavs) { FavoritesCountLabel.ForeColor = Color.DarkGreen; } else { FavoritesCountLabel.ForeColor = Color.DarkRed; } FavoritesCountLabel.Text = calc.ToString(); }); } con.Disconnect(); break; } }; }, (PlayerIOError error) => { }); FavoritesListView.SelectedItems[0].Remove(); } }
//Read data from lobby connection. private void lobbyConnected(Connection con, Client client) { con_ = con; con.OnMessage += (s, m) => { switch (m.Type) { case "universeOptIn": if (m.GetBoolean(0)) { RT.AppendText(LogRichTextBox, $"Info: EEU: You just signed up for closed Beta.\n", Color.DarkBlue); } else { RT.AppendText(LogRichTextBox, $"Error: EEU: You are already signed up to closed beta.\n", Color.DarkRed); } break; case "LobbyTo": TryLobbyConnect(m.GetString(0), client); break; case "connectioncomplete": RT.AppendText(LogRichTextBox, $"Info: Successfully connected to lobby.\n", Color.DarkBlue); con.Send("getMySimplePlayerObject"); break; case "getMySimplePlayerObject": RT.AppendText(LogRichTextBox, $"Info: Reading your database data.\n", Color.DarkBlue); int total = ExtractPlayerObjectsMessage(m) + 1; string nickname = m[(uint)total].ToString(); signedUniverse = Convert.ToBoolean(m[(uint)total + 30]); nick = nickname; RT.AppendText(LogRichTextBox, $"Info: Connected as: {nickname}.\n", Color.DarkBlue); bool havebeta = false; client.PayVault.Refresh(() => { //if (client.PayVault.Has("pro")) //Beta; if (client.PayVault.Has("pro")) { havebeta = true; } s1.Release(); }); s1.WaitOne(); if (havebeta) { if (BetaPictureBox.InvokeRequired) { BetaPictureBox.Invoke((MethodInvoker) delegate { BetaPictureBox.Image = Properties.Resources.tick; }); } } if (signedUniverse) { if (UniversePictureBox.InvokeRequired) { UniversePictureBox.Invoke((MethodInvoker) delegate { UniversePictureBox.Image = Properties.Resources.tick; }); } } if (!signedUniverse && havebeta) { if (EEUJoinButton.InvokeRequired) { EEUJoinButton.Invoke((MethodInvoker) delegate { EEUJoinButton.Enabled = true; }); } } string[] favsid = m[(uint)total + 27].ToString().Split((char)0x1399); string[] favsname = m[(uint)total + 28].ToString().Split((char)0x1399); int totals = favsid.Count(); if (FavoritesCountLabel.InvokeRequired) { FavoritesCountLabel.Invoke((MethodInvoker) delegate { FavoritesCountLabel.Text = totals.ToString(); if (totals <= morethanxFavs) { FavoritesCountLabel.ForeColor = Color.DarkGreen; } else { FavoritesCountLabel.ForeColor = Color.DarkRed; } }); } for (int i = 0; i < favsid.Count(); i++) { if (FavoritesListView.InvokeRequired) { FavoritesListView.Invoke((MethodInvoker) delegate { ListViewItem lvi = new ListViewItem(); lvi.Text = favsname[i]; lvi.SubItems.Add(favsid[i]); FavoritesListView.Items.Add(lvi); }); } } if (File.Exists($"{Directory.GetCurrentDirectory()}\\favs.json")) { var output = JObject.Parse(File.ReadAllText($"{Directory.GetCurrentDirectory()}\\favs.json")); foreach (var property in output) { if (property.Key == nick) { if (property.Value != null) { data = JsonConvert.DeserializeObject <Dictionary <string, string> >(property.Value["worlds"].ToString()); foreach (KeyValuePair <string, string> kvp in data) { if (FavBackupListView.InvokeRequired) { FavBackupListView.Invoke((MethodInvoker) delegate { ListViewItem lvi1 = new ListViewItem(); lvi1.Text = kvp.Value; lvi1.SubItems.Add(kvp.Key); FavBackupListView.Items.Add(lvi1); }); } } } } } } break; case "linked": client.Multiplayer.CreateJoinRoom("$service-room", "AuthRoom", true, null, new Dictionary <string, string>() { { "type", "Link" } }, (Connection conn) => { conn.OnMessage += (object sender1, PlayerIOClient.Message mm) => { if (mm.Type == "auth") { PlayerIO.Authenticate("everybody-edits-su9rn58o40itdbnw69plyw", "connected", new Dictionary <string, string>() { { "userId", mm.GetString(0) }, { "auth", mm.GetString(1) } }, null, (Client client1) => { con.Disconnect(); TryLobbyConnect(string.Format("{0}_{1}", client1.ConnectUserId, RandomString(5)), client1); }, (PlayerIOError error) => { RT.AppendText(LogRichTextBox, $"Error: Linked Login: {error.Message}\n", Color.DarkRed); }); } }; }, (PlayerIOError error) => { RT.AppendText(LogRichTextBox, $"Error: Linked Create Room: {error.Message}\n", Color.DarkRed); }); break; } }; }