private async Task <bool> RefreshPlayersAsync(List <IClient> connectedClients) { if (isRefreshing) { return(false); } isRefreshing = true; clients.Clear(); infos.Clear(); playerIds.Clear(); playerList.Items.Clear(); foreach (var client in connectedClients) { var packet = await client.RefreshLegionAsync(); if (packet == null) { continue; } Debug.Assert(packet.CommandId == "32101"); var token = JToken.Parse(packet.Message); var info = LegionInfo.Parse(token); if (info == null) { continue; } if (info.officername.Equals("Bang chủ")) { hostInput.Text = client.PlayerName; } packet = await client.RefreshCollectAsync(); if (packet == null) { continue; } Debug.Assert(packet.CommandId == "30100"); token = JToken.Parse(packet.Message); var swapInfo = SwapInfo.Parse(token, (int)numericUpDown1.Value); if (swapInfo == null || swapInfo.imposenum == 0) { continue; } var playerId = client.PlayerId; playerIds.Add(playerId); clients.Add(playerId, client); infos.Add(playerId, swapInfo); playerList.SetObjects(playerIds); } isRefreshing = false; return(true); }
private async Task <bool> RefreshPlayerAsync(long playerId) { if (isRefreshing) { return(false); } isRefreshing = true; try { var client = clients[playerId]; var packet = await client.RefreshLegionAsync(); if (packet == null) { return(false); } Debug.Assert(packet.CommandId == "32101"); var token = JToken.Parse(packet.Message); var info = LegionInfo.Parse(token); if (info == null) { return(false); } if (info.officername.Equals("Bang chủ")) { hostInput.Text = client.PlayerName; } packet = await client.RefreshCollectAsync(); if (packet == null) { return(false); } Debug.Assert(packet.CommandId == "30100"); token = JToken.Parse(packet.Message); infos[playerId] = SwapInfo.Parse(token, (int)numericUpDown1.Value); playerList.RefreshObject(playerId); } finally { isRefreshing = false; } return(true); }