/// <summary> /// Làm mới tất cả các tài khoản. /// </summary> /// <param name="connectedClients">Danh sách tài khoản để làm mới.</param> private async Task <bool> RefreshPlayersAsync(List <IClient> connectedClients) { if (isRefreshing) { LogInfo("Đang làm mới, không thể làm mới!"); return(false); } if (isWeaving) { LogInfo("Đang dệt, không thể làm mới!"); return(false); } LogInfo("Bắt đầu làm mới..."); isRefreshing = true; clients.Clear(); infos.Clear(); playerIds.Clear(); playerList.Items.Clear(); foreach (var client in connectedClients) { var packet = await client.RefreshWeaveAsync(); if (packet == null) { continue; } Debug.Assert(packet.CommandId == "45200"); var token = JToken.Parse(packet.Message); var info = WeaveInfo.Parse(token); if (info == null) { continue; } var playerId = client.PlayerId; playerIds.Add(playerId); clients.Add(playerId, client); infos.Add(playerId, info); playerList.SetObjects(playerIds); } LogInfo("Làm mới hoàn thành!"); isRefreshing = false; return(true); }
private void Parse45200(Packet packet) { var token = JToken.Parse(packet.Message); weaveInfo = WeaveInfo.Parse(token); if (weaveInfo == null) { // Chưa đủ lv 82. return; } spinnerLevelLabel.Text = String.Format("Công nhân: Lv. {0}", weaveInfo.Level); spinnerRateLabel.Text = String.Format("Tỉ lệ: {0} - {1}", weaveInfo.SuccessRate, weaveInfo.CriticalRate); priceLabel.Text = String.Format("Giá bán: {0} {1} {2}", weaveInfo.Price, weaveInfo.PriceWay == WeavePriceWay.Up ? "▲" : "▼", weaveInfo.PriceWay == WeavePriceWay.Up ? "(Lên)" : "(Xuống)"); numLabel.Text = String.Format("Lượt: {0}/{1}", weaveInfo.Turns, weaveInfo.MaxTurns); var oldSelectedIndex = teamList.SelectedIndex; teamList.SetObjects(weaveInfo.Teams, true); teamList.SelectedIndex = oldSelectedIndex; }
/// <summary> /// Làm mới một người chơi. /// </summary> /// <param name="playerId">ID của người chơi cần làm mới.</param> private async Task <bool> RefreshPlayerAsync(long playerId) { if (isRefreshing) { return(false); } isRefreshing = true; try { var client = clients[playerId]; var packet = await client.RefreshWeaveAsync(); if (packet == null) { return(false); } var token = JToken.Parse(packet.Message); infos[playerId] = WeaveInfo.Parse(token); playerList.RefreshObject(playerId); } finally { isRefreshing = false; } return(true); }
private async Task <bool> WeaveAsync(IClient host, WeaveMode mode, params IClient[] members) { // Lập tổ đội. var textileLevel = (int)textileLevelInput.Value; try { host.PacketReceived += OnPacketReceived; var limit = (hostLegionButton.Checked ? WeaveTeamLimit.Legion : WeaveTeamLimit.None); var p = await host.CreateWeaveAsync(textileLevel, limit); if (p == null) { return(false); } if (p.HasError) { LogInfo(String.Format("{0}: {1}", host.PlayerName, p.Message)); return(false); } } finally { host.PacketReceived -= OnPacketReceived; } if (hostingTeamId == NoTeam) { // Host is in parallel login mode. var p = await host.RefreshWeaveAsync(); if (p == null) { return(false); } var info = WeaveInfo.Parse(JToken.Parse(p.Message)); var hostingTeam = info.Teams.Find(team => team.Name == host.PlayerName); hostingTeamId = hostingTeam.Id; } try { Debug.Assert(hostingTeamId != NoTeam); var tasks = new List <Task <Packet> >(); foreach (var member in members) { tasks.Add(member.JoinWeaveAsync(hostingTeamId)); } // Gia nhập tổ đội. var p2s = await Task.WhenAll(tasks); int memberIndex = 0; foreach (var p in p2s) { if (p == null) { // Mất kết nối. // Huỷ tổ đội. await host.DisbandWeaveAsync(hostingTeamId); return(false); } if (p.HasError) { // Lỗi gia nhập. LogInfo(String.Format("{0}: {1}", members[memberIndex].PlayerName, p.ErrorMessage)); // Huỷ tổ đội. await host.DisbandWeaveAsync(hostingTeamId); return(false); } ++memberIndex; } if (mode == WeaveMode.WeaveTogether) { var p3 = await host.MakeWeaveAsync(hostingTeamId); if (p3 == null) { return(false); } } else { var p4 = await host.QuitAndMakeWeaveAsync(hostingTeamId); if (p4 == null) { return(false); } } return(true); } finally { hostingTeamId = NoTeam; } }