Пример #1
0
        public async Task <string> Initialize(string server, string characterId, int level, bool useToken = false)
        {
            using (HttpClientHandler handler = new HttpClientHandler {
                CookieContainer = AcapulcoBot.GetInstance.GetCookies()
            })
            {
                using (HttpClient client = new HttpClient(handler))
                {
                    client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 8.0.0; Samsung Galaxy S8 - 8.0 - API 26 - 1440x2960 Build/OPR6.170623.017)");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("X-Unity-Version", "5.6.2p4");

                    Uri url = new Uri(string.Concat(new string[]
                    {
                        $"http://{server}",
                        ".margonem.pl/engine?t=init&initlvl=",
                        $"{level}",
                        $"&mucka={Mucka.GenerateMucka()}",
                        "&mobile=1",
                        useToken ? $"&mobile_token={_characterToken}" : ""
                    }));

                    AcapulcoBot.GetInstance.GetCookies().Add(url, new Cookie("mchar_id", characterId));
                    string response = await client.GetStringAsync(url);

                    if (level == 1)
                    {
                        Match m = Regex.Match(response, "\"mobile_token\": \"(.*?)\",");
                        if (m.Success)
                        {
                            _characterToken = MD5.Hash(m.Groups[1].Value);
                        }
                        else
                        {
                            MessageBox.Show("Ta postać jest zarejestrowana na innym świecie.", "Acapulco Bot", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Environment.Exit(0);
                        }
                    }
                    else if (level == 4)
                    {
                        Match m = Regex.Match(response, "\"ev\": (.*?),");
                        if (m.Success)
                        {
                            _characterEvent = m.Groups[1].Value;
                        }

                        _server = server;
                        _id     = characterId;
                    }

                    return(response);
                }
            }
        }
        private async Task ClientInit(Character player)
        {
            for (int level = 1; level < 5; level++)
            {
                var request = new HttpRequestMessage()
                {
                    RequestUri = new Uri(string
                        .Concat(new string[] {
                                    $"http://{player.World}",
                                    ".margonem.pl/engine?t=init&initlvl=",
                                    $"{level}",
                                    $"&clientTs={new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()}",
                                    $"&mucka={Mucka.GenerateMucka()}",
                                    player.BrowserToken == null ? "" : $"&browser_token={player.BrowserToken}"
                                    })),
                };
                request.Headers.Referrer = new Uri($"http://{player.World}.margonem.pl/");

                var result = await _apiClient.SendAsync(request);

                string response = await result.Content.ReadAsStringAsync(); 

                if (response.Contains("Nie jesteś zalogowany"))
                {
                    Environment.Exit(1);
                }

                if (response.Contains("Przerwa techniczna - aktualizacja silnika."))
                {
                    player.StatusInfo = "Przerwa techniczna";
                    await Wait(60 * 1000, 60 * 2000);
                    await ClientInit(player);
                    return;
                }

                if (response.Contains("wait_for"))
                {
                    await Task.Delay(5000);
                    await ClientInit(player);
                    return;
                }

                var BrowserToken = new
                {
                    browser_token = ""
                };

                BrowserToken = JsonConvert.DeserializeAnonymousType(response, BrowserToken);

                if (level == 1)
                {
                    player.BrowserToken = BrowserToken.browser_token;
                }
                if (level == 3)
                {
                    var Items = new
                    {
                        item = new Dictionary<string, Item>()
                    };

                    Items = JsonConvert.DeserializeAnonymousType(response, Items);
                    player.Items = Items.item;
                }
            }
        }