Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static SwapInfo Parse(JToken token, int value)
        {
            var result = new SwapInfo();

            var res = token["res"];

            foreach (var item in res)
            {
                if (item["resid"].ToString().Equals(value + ""))
                {
                    result.imposenum    = (int)item["imposenum"];
                    result.maximposenum = (int)item["maximposenum"];
                    var cd = (int)item["cd"];
                    result.cooldown = new Cooldown(cd);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        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);
        }