Ejemplo n.º 1
0
        private static void WaitForTurnAsync(object stateInfo)
        {
            var timeStart   = DateTime.Now;
            int lastSeconds = -1;

            while (AppVars.AutoRefresh)
            {
                var timeDiff = DateTime.Now.Subtract(timeStart);
                if ((timeDiff.Seconds % 30) == 0 && (lastSeconds != timeDiff.Seconds))
                {
                    lastSeconds = timeDiff.Seconds;
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.WriteChatMsgSafe(
                            $"Ожидаем хода противника... <b>{timeDiff.Minutes}:{timeDiff.Seconds:00}</b>");
                    }
                }

                var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.neverlands.ru/main.php");
                httpWebRequest.Method = "GET";
                httpWebRequest.Proxy  = AppVars.LocalProxy;
                var cookies = CookiesManager.Obtain("www.neverlands.ru");
                httpWebRequest.Headers.Add("Cookie", cookies);
                string html = null;
                try
                {
                    IdleManager.AddActivity();
                    var resp      = httpWebRequest.GetResponse();
                    var webstream = resp.GetResponseStream();
                    if (webstream != null)
                    {
                        var reader = new StreamReader(webstream, AppVars.Codepage);
                        html = reader.ReadToEnd();
                    }
                }
                catch
                {
                    html = null;
                }
                finally
                {
                    IdleManager.RemoveActivity();
                }

                if (string.IsNullOrEmpty(html))
                {
                    break;
                }

                if (!AreWaitingForTurn(html))
                {
                    break;
                }
            }

            if (AppVars.AutoRefresh && (AppVars.MainForm != null))
            {
                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.BeginInvoke(
                            new ReloadMainPhpInvokeDelegate(AppVars.MainForm.ReloadMainPhpInvoke),
                            new object[] { });
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }

            AppVars.ThreadWaitForTurn = null;
        }
Ejemplo n.º 2
0
        private static void CompasAsync(object stateInfo)
        {
            var nick = stateInfo as string;

            if (nick == null)
            {
                return;
            }

            //var wc = new WebClient { Proxy = AppVars.LocalProxy };
            var html = NeverInfo.GetPInfo(nick);

            if (string.IsNullOrEmpty(html))
            {
                return;
            }

            var params0 = HelperStrings.SubString(html, "var params = [[", "],");

            if (string.IsNullOrEmpty(params0))
            {
                return;
            }

            var spar0 = HelperStrings.ParseArguments(params0);

            if (spar0.Length < 9)
            {
                return;
            }

            var firstNick = spar0[0].Trim();
            var firstSign = spar0[2];
            var firstClan = spar0[8];

            var listClanNicks = new List <string> {
                firstNick
            };

            if (!string.IsNullOrEmpty(firstClan))
            {
                byte[] buffer;
                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri("http://neverstat.ru/clan_players.php?type=all"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
                        AppVars.VipFormCompas.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormCompas.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var linkClan = HelperStrings.SubString(html, firstSign + @"""><a href=""clan_players.php?clantype=", @"""");
                if (string.IsNullOrEmpty(linkClan))
                {
                    return;
                }

                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri($"http://neverstat.ru/clan_players.php?clantype={linkClan}"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                var p1 = 0;
                while (p1 != -1)
                {
                    const string pat1 = @" target=""_blank"">";
                    p1 = html.IndexOf(pat1, p1, StringComparison.OrdinalIgnoreCase);
                    if (p1 == -1)
                    {
                        break;
                    }

                    p1 += pat1.Length;
                    var p2 = html.IndexOf(@"[", p1, StringComparison.OrdinalIgnoreCase);
                    if (p2 == -1)
                    {
                        continue;
                    }

                    var statnick = html.Substring(p1, p2 - p1);
                    if (statnick.Length < 64)
                    {
                        listClanNicks.Add(statnick);
                    }
                }
            }

            foreach (var vipNick in listClanNicks)
            {
                var firstMessage = $"Анализируем [{vipNick}]";
                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        AppVars.VipFormCompas.BeginInvoke(
                            new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus), firstMessage);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                html = NeverInfo.GetPInfo(vipNick);
                if (string.IsNullOrEmpty(html))
                {
                    continue;
                }

                params0 = HelperStrings.SubString(html, "var params = [[", "],");
                if (string.IsNullOrEmpty(params0))
                {
                    continue;
                }

                spar0 = HelperStrings.ParseArguments(params0);
                if (spar0.Length < 9)
                {
                    continue;
                }

                var infNick     = spar0[0].Trim();
                var infAlign    = spar0[1];
                var infSign     = spar0[2];
                var infClan     = spar0[8];
                var infLevel    = spar0[3];
                var orgLocation = spar0[5];
                var infLocation = spar0[5];
                if (infLocation.IndexOf('[') != -1)
                {
                    infLocation = HelperStrings.SubString(infLocation, "[", "]");
                }

                var infIsOnline = !string.IsNullOrEmpty(infLocation);

                if (!infClan.Equals(firstClan))
                {
                    continue;
                }

                var isLightWound    = false;
                var isMediumWound   = false;
                var isHeavyWound    = false;
                var isUltimateWound = false;

                var effects = HelperStrings.SubString(html, "var effects = [", "];");
                var sbeff   = new StringBuilder();
                if (!string.IsNullOrEmpty(effects))
                {
                    var seffects = effects.Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
                    for (var k = 0; k < seffects.Length; k++)
                    {
                        var effk  = seffects[k].Trim(new[] { '[', ']' });
                        var seffk = effk.Split(',');
                        if (seffk.Length <= 1)
                        {
                            continue;
                        }

                        var effcode = seffk[0];
                        var effname = seffk[1].Replace("<b>", String.Empty).Replace("</b>", String.Empty);
                        sbeff.AppendFormat(
                            @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle title=""{1}"">",
                            effcode,
                            effname);
                        switch (effcode)
                        {
                        case "1":
                            isUltimateWound = true;
                            break;

                        case "2":
                            isHeavyWound = true;
                            break;

                        case "3":
                            isMediumWound = true;
                            break;

                        case "4":
                            isLightWound = true;
                            break;
                        }
                    }
                }

                var travma = string.Empty;
                if (isUltimateWound)
                {
                    travma = "боевая";
                }
                else
                {
                    if (isHeavyWound)
                    {
                        travma = "тяжелая";
                    }
                    else
                    {
                        if (isMediumWound)
                        {
                            travma = "средняя";
                        }
                        else
                        {
                            if (isLightWound)
                            {
                                travma = "легкая";
                            }
                        }
                    }
                }

                var colorNick = infNick;
                if (!infIsOnline)
                {
                    colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
                }
                else
                {
                    if (!string.IsNullOrEmpty(travma))
                    {
                        switch (travma)
                        {
                        case "боевая":
                            colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
                            break;

                        case "тяжелая":
                            colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
                            break;

                        case "средняя":
                            colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
                            break;

                        case "легкая":
                            colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
                            break;
                        }
                    }
                }

                var align = string.Empty;
                var ali1  = string.Empty;
                var ali2  = string.Empty;
                switch (infAlign)
                {
                case "1":
                    ali1 = "darks.gif";
                    ali2 = "Дети Тьмы";
                    break;

                case "2":
                    ali1 = "lights.gif";
                    ali2 = "Дети Света";
                    break;

                case "3":
                    ali1 = "sumers.gif";
                    ali2 = "Дети Сумерек";
                    break;

                case "4":
                    ali1 = "chaoss.gif";
                    ali2 = "Дети Хаоса";
                    break;

                case "5":
                    ali1 = "light.gif";
                    ali2 = "Истинный Свет";
                    break;

                case "6":
                    ali1 = "dark.gif";
                    ali2 = "Истинная Тьма";
                    break;

                case "7":
                    ali1 = "sumer.gif";
                    ali2 = "Нейтральные Сумерки";
                    break;

                case "8":
                    ali1 = "chaos.gif";
                    ali2 = "Абсолютный Хаос";
                    break;

                case "9":
                    ali1 = "angel.gif";
                    ali2 = "Ангел";
                    break;
                }

                if (!string.IsNullOrEmpty(ali1))
                {
                    align =
                        "<img src=http://image.neverlands.ru/signs/" +
                        ali1 +
                        @" width=15 height=12 align=absmiddle border=0 title=""" +
                        ali2 +
                        @""">&nbsp";
                }

                var ss = string.Empty;
                if (!string.IsNullOrEmpty(infClan))
                {
                    ss =
                        "<img src=http://image.neverlands.ru/signs/" +
                        infSign +
                        @" width=15 height=12 align=absmiddle title=""" +
                        infClan +
                        @""">&nbsp;";
                }

                var location = string.Empty;
                if (infIsOnline)
                {
                    // Окрестности Форпоста [Окрестность Форпоста, Биржа]"

                    if (!orgLocation.StartsWith("Форпост", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Октал", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Деревня", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Тюрьма", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Окрестности Форпоста [Окрестность Форпоста, Биржа]", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Окрестность Форпоста [Сырьевая Биржа]", StringComparison.OrdinalIgnoreCase))
                    {
                        //var matrixNick = string.Format(":{0}:", vipNick);
                        var arrayPossibleLocations = new List <string>();
                        var cellCount = 0;
                        foreach (var cellKey in Map.Cells.Keys)
                        {
                            var cell = Map.Cells[cellKey];
                            if (!cell.Tooltip.Equals(infLocation, StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            cellCount++;
                        }

                        if (cellCount > 0)
                        {
                            var cellIndex = 0;
                            foreach (var cellKey in Map.Cells.Keys)
                            {
                                var cell = Map.Cells[cellKey];
                                if (!cell.Tooltip.Equals(infLocation, StringComparison.OrdinalIgnoreCase))
                                {
                                    continue;
                                }

                                var progress = (cellIndex * 100) / cellCount;
                                var status   = $"{firstMessage}... {progress}%";
                                try
                                {
                                    if (AppVars.VipFormCompas != null)
                                    {
                                        AppVars.VipFormCompas.BeginInvoke(
                                            new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus),
                                            new object[] { status });
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                                catch (InvalidOperationException)
                                {
                                }

                                cellIndex++;

                                arrayPossibleLocations.Add(cellKey);

                                /*
                                 * var position = Map.InvPosition[cellKey];
                                 * var cm = Convert.ToChar(38);
                                 * var url = string.Format("http://www.neverlands.ru/ch.php?lo=1&r={0}_{1}_{2}", cm, position.X, position.Y);
                                 * try
                                 * {
                                 *  var httpWebRequest = (HttpWebRequest) WebRequest.Create(url);
                                 *  httpWebRequest.Method = "GET";
                                 *  httpWebRequest.Proxy = AppVars.LocalProxy;
                                 *  var cookies = CookiesManager.Obtain("www.neverlands.ru");
                                 *  httpWebRequest.Headers.Add("Cookie", cookies);
                                 *  var resp = httpWebRequest.GetResponse();
                                 *  var webstream = resp.GetResponseStream();
                                 *  var reader = new StreamReader(webstream, AppVars.Codepage);
                                 *  var responseFromServer = reader.ReadToEnd();
                                 *  if (responseFromServer.IndexOf(matrixNick, StringComparison.OrdinalIgnoreCase) != -1)
                                 *  {
                                 *      arrayPossibleLocations.Clear();
                                 *      arrayPossibleLocations.Add(cellKey);
                                 *      break;
                                 *  }
                                 * }
                                 * catch
                                 * {
                                 * }
                                 */
                            }
                        }

                        if (arrayPossibleLocations.Count > 0)
                        {
                            var possibleLocations = arrayPossibleLocations.Count;
                            var path = new MapPath(AppVars.LocationReal, arrayPossibleLocations.ToArray());
                            if (possibleLocations == 1)
                            {
                                location =
                                    $"Точное положение: <a style='text-decoration:none' href='http://{arrayPossibleLocations[0]}'><b>{arrayPossibleLocations[0]}</b></a> (шагов: <b>{path.Jumps}</b>). {infLocation}.";
                            }
                            else
                            {
                                location =
                                    $"{infLocation}. Возможных клеток: <b>{possibleLocations}</b>, ближайшая <a style='text-decoration:none' href='http://{path.Destination ?? AppVars.LocationReal}'><b>{path.Destination ?? AppVars.LocationReal}</b></a> (шагов: <b>{path.Jumps}</b>).";
                            }
                        }
                        else
                        {
                            location = @"<font color=""#cc0000"">" + "Неизвестная клетка!" + "</font>";
                        }
                    }
                    else
                    {
                        string[] dest = null;
                        if (orgLocation.StartsWith("Форпост") || orgLocation.StartsWith("Тюрьма"))
                        {
                            dest = new[] { "8-259", "8-294" };
                        }

                        if (orgLocation.StartsWith("Октал"))
                        {
                            dest = new[] { "12-428", "12-494", "12-521" };
                        }

                        if (orgLocation.StartsWith("Деревня"))
                        {
                            dest = new[] { "8-197", "8-228", "8-229" };
                        }

                        if (orgLocation.StartsWith("Окрестности Форпоста [Окрестность Форпоста, Биржа]"))
                        {
                            dest = new[] { "8-227" };
                        }

                        if (orgLocation.StartsWith("Окрестность Форпоста [Сырьевая Биржа]"))
                        {
                            dest = new[] { "8-227" };
                        }

                        if (dest != null)
                        {
                            var path = new MapPath(AppVars.LocationReal, dest);
                            location = $"Точное положение: <a style='text-decoration:none' href='http://{path.Destination}'><b>{path.Destination}</b></a> (шагов: <b>{path.Jumps}</b>). {infLocation}.";
                        }
                    }
                }
                else
                {
                    location = @"<font color=""#cccccc"">" + "В оффлайне или невиде." + "</font>";
                }

                location = @"<span style=""font-size:10px;"">" + location + "</span>";
                var result =
                    @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
                    align +
                    ss +
                    @"<b>" +
                    colorNick +
                    "</b></a>[" +
                    infLevel +
                    @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
                    sbeff +
                    "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
                    location +
                    "</span><br>";

                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        AppVars.VipFormCompas.BeginInvoke(
                            new AddCharacterDelegate(AppVars.VipFormCompas.AddCharacter), result);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }

            try
            {
                if (AppVars.VipFormCompas != null)
                {
                    AppVars.VipFormCompas.BeginInvoke(
                        new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus), "Сканирование завешено.");
                }
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 3
0
        /* in44.nl
         * private static void AddClanAsync(object stateInfo)
         * {
         *  var nick = stateInfo as string;
         *  if (nick == null)
         *  {
         *      return;
         *  }
         *
         *  var html = NeverInfo.GetPInfo(nick);
         *  if (string.IsNullOrEmpty(html))
         *      return;
         *
         *  var params0 = HelperStrings.SubString(html, "var params = [[", "],");
         *  if (string.IsNullOrEmpty(params0))
         *  {
         *      return;
         *  }
         *
         *  var spar0 = HelperStrings.ParseArguments(params0);
         *  if (spar0.Length < 9)
         *  {
         *      return;
         *  }
         *
         *  var firstNick = spar0[0].Trim();
         *  var firstSign = spar0[2];
         *  var firstClan = spar0[8];
         *
         *  var listClanNicks = new List<string> {firstNick};
         *  if (!string.IsNullOrEmpty(firstSign))
         *  {
         *      byte[] buffer;
         *      using (var wc = new WebClient {Proxy = AppVars.LocalProxy})
         *      {
         *          try
         *          {
         *              var suff = firstSign;
         *              var posp = suff.IndexOf('.');
         *              if (posp != -1)
         *                  suff = suff.Substring(0, posp);
         *
         *              buffer = wc.DownloadData(new Uri("http://in44.nl/clanstruct/c_" + suff + "/"));
         *          }
         *          catch (WebException)
         *          {
         *              return;
         *          }
         *      }
         *
         *      html = AppVars.Codepage.GetString(buffer);
         *      var p1 = 0;
         *      while (p1 != -1)
         *      {
         *          p1 = html.IndexOf("pinfo.cgi?", p1, StringComparison.OrdinalIgnoreCase);
         *          if (p1 == -1)
         *              break;
         *
         *          p1 += "pinfo.cgi?".Length;
         *          var p2 = html.IndexOf(@"""", p1, StringComparison.OrdinalIgnoreCase);
         *          if (p2 == -1)
         *              continue;
         *
         *          var statnick = html.Substring(p1, p2 - p1);
         *          listClanNicks.Add(statnick);
         *      }
         *  }
         *
         *  foreach (var vipNick in listClanNicks)
         *  {
         *      try
         *      {
         *          if (AppVars.VipFormAddClan != null)
         *          {
         *              var message = string.Format("Анализируем [{0}]...", vipNick);
         *              AppVars.VipFormAddClan.BeginInvoke(
         *                  new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
         *                  new object[] { message });
         *          }
         *          else
         *          {
         *              return;
         *          }
         *      }
         *      catch (InvalidOperationException)
         *      {
         *      }
         *
         *      html = NeverInfo.GetPInfo(vipNick);
         *      if (string.IsNullOrEmpty(html))
         *          continue;
         *
         *      params0 = HelperStrings.SubString(html, "var params = [[", "],");
         *      if (string.IsNullOrEmpty(params0))
         *      {
         *          continue;
         *      }
         *
         *      spar0 = HelperStrings.ParseArguments(params0);
         *      if (spar0.Length < 9)
         *      {
         *          continue;
         *      }
         *
         *      var infNick = spar0[0].Trim();
         *      var infAlign = spar0[1];
         *      var infSign = spar0[2];
         *      var infClan = spar0[8];
         *
         *      if (!infClan.Equals(firstClan))
         *      {
         *          continue;
         *      }
         *
         *      var infLevel = spar0[3];
         *      var infLocation = spar0[5];
         *      if (infLocation.IndexOf('[') != -1)
         *      {
         *          infLocation = HelperStrings.SubString(infLocation, "[", "]");
         *      }
         *
         *      var infIsOnline = !string.IsNullOrEmpty(infLocation);
         *
         *      var isLightWound = false;
         *      var isMediumWound = false;
         *      var isHeavyWound = false;
         *      var isUltimateWound = false;
         *
         *      var effects = HelperStrings.SubString(html, "var effects = [", "];");
         *      var sbeff = new StringBuilder();
         *      if (!string.IsNullOrEmpty(effects))
         *      {
         *          var seffects = effects.Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
         *          for (var k = 0; k < seffects.Length; k++)
         *          {
         *              var effk = seffects[k].Trim(new[] { '[', ']' });
         *              var seffk = effk.Split(',');
         *              if (seffk.Length <= 1)
         *              {
         *                  continue;
         *              }
         *
         *              var effcode = seffk[0];
         *              var effname = seffk[1].Replace("<b>", String.Empty).Replace("</b>", String.Empty);
         *              sbeff.AppendFormat(
         *                  @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle alt=""{1}"">",
         *                  effcode,
         *                  effname);
         *              switch (effcode)
         *              {
         *                  case "1":
         *                      isUltimateWound = true;
         *                      break;
         *
         *                  case "2":
         *                      isHeavyWound = true;
         *                      break;
         *
         *                  case "3":
         *                      isMediumWound = true;
         *                      break;
         *
         *                  case "4":
         *                      isLightWound = true;
         *                      break;
         *              }
         *          }
         *      }
         *
         *      var travma = string.Empty;
         *      if (isUltimateWound)
         *      {
         *          travma = "боевая";
         *      }
         *      else
         *      {
         *          if (isHeavyWound)
         *          {
         *              travma = "тяжелая";
         *          }
         *          else
         *          {
         *              if (isMediumWound)
         *              {
         *                  travma = "средняя";
         *              }
         *              else
         *              {
         *                  if (isLightWound)
         *                  {
         *                      travma = "легкая";
         *                  }
         *              }
         *          }
         *      }
         *
         *      var colorNick = infNick;
         *      if (!infIsOnline)
         *      {
         *          colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
         *      }
         *      else
         *      {
         *          if (!string.IsNullOrEmpty(travma))
         *          {
         *              switch (travma)
         *              {
         *                  case "боевая":
         *                      colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
         *                      break;
         *                  case "тяжелая":
         *                      colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
         *                      break;
         *                  case "средняя":
         *                      colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
         *                      break;
         *                  case "легкая":
         *                      colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
         *                      break;
         *              }
         *          }
         *      }
         *
         *      var align = string.Empty;
         *      var ali1 = string.Empty;
         *      var ali2 = string.Empty;
         *      switch (infAlign)
         *      {
         *          case "1":
         *              ali1 = "darks.gif";
         *              ali2 = "Дети Тьмы";
         *              break;
         *          case "2":
         *              ali1 = "lights.gif";
         *              ali2 = "Дети Света";
         *              break;
         *          case "3":
         *              ali1 = "sumers.gif";
         *              ali2 = "Дети Сумерек";
         *              break;
         *          case "4":
         *              ali1 = "chaoss.gif";
         *              ali2 = "Дети Хаоса";
         *              break;
         *          case "5":
         *              ali1 = "light.gif";
         *              ali2 = "Истинный Свет";
         *              break;
         *          case "6":
         *              ali1 = "dark.gif";
         *              ali2 = "Истинная Тьма";
         *              break;
         *          case "7":
         *              ali1 = "sumer.gif";
         *              ali2 = "Нейтральные Сумерки";
         *              break;
         *          case "8":
         *              ali1 = "chaos.gif";
         *              ali2 = "Абсолютный Хаос";
         *              break;
         *          case "9":
         *              ali1 = "angel.gif";
         *              ali2 = "Ангел";
         *              break;
         *      }
         *
         *      if (!string.IsNullOrEmpty(ali1))
         *      {
         *          align =
         *              "<img src=http://image.neverlands.ru/signs/" +
         *              ali1 +
         *              @" width=15 height=12 align=absmiddle border=0 alt=""" +
         *              ali2 +
         *              @""">&nbsp";
         *      }
         *
         *      var ss = string.Empty;
         *      if (!string.IsNullOrEmpty(infClan))
         *      {
         *          ss =
         *              "<img src=http://image.neverlands.ru/signs/" +
         *              infSign +
         *              @" width=15 height=12 align=absmiddle alt=""" +
         *              infClan +
         *              @""">&nbsp;";
         *      }
         *
         *      var result =
         *          @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
         *          align +
         *          ss +
         *          @"<b>" +
         *          colorNick +
         *          "</b></a>[" +
         *          infLevel +
         *          @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
         *          sbeff +
         *          "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
         *          @"<span style=""font-size:10px;"">" + "добавлен в контакты" + "</span>" +
         *          "</span><br>";
         *
         *      try
         *      {
         *          if (AppVars.VipFormAddClan != null)
         *          {
         *              AppVars.VipFormAddClan.BeginInvoke(
         *                  new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.AddCharacter),
         *                  new object[] { result });
         *          }
         *          else
         *          {
         *              return;
         *          }
         *      }
         *      catch (InvalidOperationException)
         *      {
         *      }
         *
         *      var nickContact = infNick;
         *
         *      if (AppVars.MainForm != null)
         *      {
         *          AppVars.MainForm.BeginInvoke(
         *              new AddContactFromBulkDelegate(AppVars.MainForm.AddContactFromBulk),
         *              new object[] { nickContact });
         *      }
         *      else
         *      {
         *          return;
         *      }
         *  }
         *
         *  try
         *  {
         *      if (AppVars.VipFormAddClan != null)
         *      {
         *          AppVars.VipFormAddClan.BeginInvoke(
         *              new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
         *              new object[] { "Добавление в контакты завешено." });
         *      }
         *      else
         *      {
         *          return;
         *      }
         *  }
         *  catch (InvalidOperationException)
         *  {
         *  }
         *
         *  AppVars.Profile.Save();
         * }
         */

        private static void AddClanAsync(object stateInfo)
        {
            var nick = stateInfo as string;

            if (nick == null)
            {
                return;
            }

            var html = NeverInfo.GetPInfo(nick);

            if (string.IsNullOrEmpty(html))
            {
                return;
            }

            // 2/11/2017 - params -> parameters
            // var params0 = HelperStrings.SubString(html, "var params = [[", "],");
            var params0 = HelperStrings.SubString(html, "var parameters = [[", "],");

            if (string.IsNullOrEmpty(params0))
            {
                return;
            }

            var spar0 = HelperStrings.ParseArguments(params0);

            if (spar0.Length < 9)
            {
                return;
            }

            var firstNick = spar0[0].Trim();
            var firstSign = spar0[2];
            var firstClan = spar0[8];

            var listClanNicks = new List <string> {
                firstNick
            };

            if (!string.IsNullOrEmpty(firstSign))
            {
                byte[] buffer;
                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri("http://neverok.ru/clan_players.php?type=all"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                var linkClan = HelperStrings.SubString(html, firstSign + @"""><a href=""clan_players.php?clantype=", @"""");
                if (string.IsNullOrEmpty(linkClan))
                {
                    return;
                }

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri($"http://neverok.ru/clan_players.php?clantype={linkClan}"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                var p1 = 0;
                while (p1 != -1)
                {
                    const string pat1 = @" target=""_blank"">";
                    p1 = html.IndexOf(pat1, p1, StringComparison.OrdinalIgnoreCase);
                    if (p1 == -1)
                    {
                        break;
                    }

                    p1 += pat1.Length;
                    var p2 = html.IndexOf(@"[", p1, StringComparison.OrdinalIgnoreCase);
                    if (p2 == -1)
                    {
                        continue;
                    }

                    var statnick = html.Substring(p1, p2 - p1);
                    if (statnick.Length < 64)
                    {
                        listClanNicks.Add(statnick);
                    }
                }
            }

            foreach (var vipNick in listClanNicks)
            {
                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = $"Анализируем [{vipNick}]...";
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                html = NeverInfo.GetPInfo(vipNick);
                if (string.IsNullOrEmpty(html))
                {
                    continue;
                }

                // 2/11/2017 - params -> parameters
                // var params0 = HelperStrings.SubString(html, "var params = [[", "],");
                params0 = HelperStrings.SubString(html, "var parameters = [[", "],");
                if (string.IsNullOrEmpty(params0))
                {
                    continue;
                }

                spar0 = HelperStrings.ParseArguments(params0);
                if (spar0.Length < 9)
                {
                    continue;
                }

                var infNick  = spar0[0].Trim();
                var infAlign = spar0[1];
                var infSign  = spar0[2];
                var infClan  = spar0[8];

                if (!infClan.Equals(firstClan))
                {
                    continue;
                }

                var infLevel    = spar0[3];
                var infLocation = spar0[5];
                if (infLocation.IndexOf('[') != -1)
                {
                    infLocation = HelperStrings.SubString(infLocation, "[", "]");
                }

                var infIsOnline = !string.IsNullOrEmpty(infLocation);

                var isLightWound    = false;
                var isMediumWound   = false;
                var isHeavyWound    = false;
                var isUltimateWound = false;

                var effects = HelperStrings.SubString(html, "var effects = [", "];");
                var sbeff   = new StringBuilder();
                if (!string.IsNullOrEmpty(effects))
                {
                    var seffects = effects.Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
                    for (var k = 0; k < seffects.Length; k++)
                    {
                        var effk  = seffects[k].Trim(new[] { '[', ']' });
                        var seffk = effk.Split(',');
                        if (seffk.Length <= 1)
                        {
                            continue;
                        }

                        var effcode = seffk[0];
                        var effname = seffk[1].Replace("<b>", String.Empty).Replace("</b>", String.Empty);
                        sbeff.AppendFormat(
                            @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle title=""{1}"">",
                            effcode,
                            effname);
                        switch (effcode)
                        {
                        case "1":
                            isUltimateWound = true;
                            break;

                        case "2":
                            isHeavyWound = true;
                            break;

                        case "3":
                            isMediumWound = true;
                            break;

                        case "4":
                            isLightWound = true;
                            break;
                        }
                    }
                }

                var travma = string.Empty;
                if (isUltimateWound)
                {
                    travma = "боевая";
                }
                else
                {
                    if (isHeavyWound)
                    {
                        travma = "тяжелая";
                    }
                    else
                    {
                        if (isMediumWound)
                        {
                            travma = "средняя";
                        }
                        else
                        {
                            if (isLightWound)
                            {
                                travma = "легкая";
                            }
                        }
                    }
                }

                var colorNick = infNick;
                if (!infIsOnline)
                {
                    colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
                }
                else
                {
                    if (!string.IsNullOrEmpty(travma))
                    {
                        switch (travma)
                        {
                        case "боевая":
                            colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
                            break;

                        case "тяжелая":
                            colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
                            break;

                        case "средняя":
                            colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
                            break;

                        case "легкая":
                            colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
                            break;
                        }
                    }
                }

                var align = string.Empty;
                var ali1  = string.Empty;
                var ali2  = string.Empty;
                switch (infAlign)
                {
                case "1":
                    ali1 = "darks.gif";
                    ali2 = "Дети Тьмы";
                    break;

                case "2":
                    ali1 = "lights.gif";
                    ali2 = "Дети Света";
                    break;

                case "3":
                    ali1 = "sumers.gif";
                    ali2 = "Дети Сумерек";
                    break;

                case "4":
                    ali1 = "chaoss.gif";
                    ali2 = "Дети Хаоса";
                    break;

                case "5":
                    ali1 = "light.gif";
                    ali2 = "Истинный Свет";
                    break;

                case "6":
                    ali1 = "dark.gif";
                    ali2 = "Истинная Тьма";
                    break;

                case "7":
                    ali1 = "sumer.gif";
                    ali2 = "Нейтральные Сумерки";
                    break;

                case "8":
                    ali1 = "chaos.gif";
                    ali2 = "Абсолютный Хаос";
                    break;

                case "9":
                    ali1 = "angel.gif";
                    ali2 = "Ангел";
                    break;
                }

                if (!string.IsNullOrEmpty(ali1))
                {
                    align =
                        "<img src=http://image.neverlands.ru/signs/" +
                        ali1 +
                        @" width=15 height=12 align=absmiddle border=0 title=""" +
                        ali2 +
                        @""">&nbsp";
                }

                var ss = string.Empty;
                if (!string.IsNullOrEmpty(infClan))
                {
                    ss =
                        "<img src=http://image.neverlands.ru/signs/" +
                        infSign +
                        @" width=15 height=12 align=absmiddle title=""" +
                        infClan +
                        @""">&nbsp;";
                }

                var result =
                    @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
                    align +
                    ss +
                    @"<b>" +
                    colorNick +
                    "</b></a>[" +
                    infLevel +
                    @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
                    sbeff +
                    "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
                    @"<span style=""font-size:10px;"">" + "добавлен в контакты" + "</span>" +
                    "</span><br>";

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.AddCharacter),
                            new object[] { result });
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var nickContact = infNick;

                if (AppVars.MainForm != null)
                {
                    AppVars.MainForm.BeginInvoke(
                        new AddContactFromBulkDelegate(AppVars.MainForm.AddContactFromBulk),
                        new object[] { nickContact });
                }
                else
                {
                    return;
                }
            }

            try
            {
                if (AppVars.VipFormAddClan != null)
                {
                    AppVars.VipFormAddClan.BeginInvoke(
                        new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
                        new object[] { "Добавление в контакты завешено." });
                }
                else
                {
                    return;
                }
            }
            catch (InvalidOperationException)
            {
            }

            AppVars.Profile.Save();
        }
Ejemplo n.º 4
0
        private static void CompasAsync(object stateInfo)
        {
            var nick = stateInfo as string;

            if (nick == null)
            {
                return;
            }

            var mainUserInfo = NeverApi.GetAll(nick);

            if (mainUserInfo == null)
            {
                return;
            }

            var firstNick = mainUserInfo.Nick;
            var firstSign = mainUserInfo.ClanSign;
            var firstClan = mainUserInfo.ClanName;

            var listClanNicks = new List <string> {
                firstNick
            };

            if (!string.IsNullOrEmpty(firstClan))
            {
                byte[] buffer;
                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri("http://allnl.ru/clan-players/all"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                var html = Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
                        AppVars.VipFormCompas.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormCompas.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var linkClan = HelperStrings.SubString(
                    html,
                    $"<img src=\"http://image.neverlands.ru/signs/{firstSign}\"> <a href=\"/clan-players/",
                    $"\">{firstClan}</a>");

                if (string.IsNullOrEmpty(linkClan))
                {
                    return;
                }

                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri($"http://allnl.ru/clan-players/{linkClan}"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                var p1 = 0;
                while (p1 != -1)
                {
                    string pat1 = $"<img src=\"http://image.neverlands.ru/signs/{firstSign}\">";
                    p1 = html.IndexOf(pat1, p1, StringComparison.OrdinalIgnoreCase);
                    if (p1 == -1)
                    {
                        break;
                    }

                    p1 += pat1.Length;
                    var p2 = html.IndexOf(@"[", p1, StringComparison.OrdinalIgnoreCase);
                    if (p2 == -1)
                    {
                        continue;
                    }

                    var statnick = html.Substring(p1, p2 - p1).Trim();
                    if (statnick.Length < 64)
                    {
                        listClanNicks.Add(statnick);
                    }
                }
            }

            foreach (var vipNick in listClanNicks)
            {
                var firstMessage = $"Анализируем [{vipNick}]";
                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        AppVars.VipFormCompas.BeginInvoke(
                            new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus), firstMessage);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var userInfo = NeverApi.GetAll(vipNick);
                if (userInfo == null)
                {
                    continue;
                }

                var infNick  = userInfo.Nick;
                var infAlign = userInfo.Align;
                var infSign  = userInfo.ClanSign;
                var infClan  = userInfo.ClanName;

                if (!infClan.Equals(firstClan))
                {
                    continue;
                }

                var infLevel    = userInfo.Level;
                var infLocation = userInfo.Location;
                if (infLocation.IndexOf('[') != -1)
                {
                    infLocation = HelperStrings.SubString(infLocation, "[", "]");
                }

                var infIsOnline = !string.IsNullOrEmpty(infLocation);

                var isLightWound    = false;
                var isMediumWound   = false;
                var isHeavyWound    = false;
                var isUltimateWound = false;

                var sbeff = new StringBuilder();
                if (userInfo.EffectsCodes.Length > 0)
                {
                    for (var i = 0; i < userInfo.EffectsCodes.Length; i++)
                    {
                        sbeff.AppendFormat(
                            @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle title=""{1}"">",
                            userInfo.EffectsCodes[i],
                            userInfo.EffectsNames[i]);

                        switch (userInfo.EffectsCodes[i])
                        {
                        case "2":
                            isHeavyWound = true;     // тяжелые
                            break;

                        case "3":
                            isMediumWound = true;     // средние
                            break;

                        case "4":
                            isLightWound = true;     // легкие
                            break;

                        case "24":
                            isUltimateWound = true;
                            break;

                        default:
                            break;
                        }
                    }
                }

                var travma = string.Empty;
                if (isUltimateWound)
                {
                    travma = "боевая";
                }
                else
                {
                    if (isHeavyWound)
                    {
                        travma = "тяжелая";
                    }
                    else
                    {
                        if (isMediumWound)
                        {
                            travma = "средняя";
                        }
                        else
                        {
                            if (isLightWound)
                            {
                                travma = "легкая";
                            }
                        }
                    }
                }

                var colorNick = infNick;
                if (!infIsOnline)
                {
                    colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
                }
                else
                {
                    if (!string.IsNullOrEmpty(travma))
                    {
                        switch (travma)
                        {
                        case "боевая":
                            colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
                            break;

                        case "тяжелая":
                            colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
                            break;

                        case "средняя":
                            colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
                            break;

                        case "легкая":
                            colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
                            break;
                        }
                    }
                }

                var align = string.Empty;
                var ali1  = string.Empty;
                var ali2  = string.Empty;
                switch (infAlign)
                {
                case "1":
                    ali1 = "darks.gif";
                    ali2 = "Дети Тьмы";
                    break;

                case "2":
                    ali1 = "lights.gif";
                    ali2 = "Дети Света";
                    break;

                case "3":
                    ali1 = "sumers.gif";
                    ali2 = "Дети Сумерек";
                    break;

                case "4":
                    ali1 = "chaoss.gif";
                    ali2 = "Дети Хаоса";
                    break;

                case "5":
                    ali1 = "light.gif";
                    ali2 = "Истинный Свет";
                    break;

                case "6":
                    ali1 = "dark.gif";
                    ali2 = "Истинная Тьма";
                    break;

                case "7":
                    ali1 = "sumer.gif";
                    ali2 = "Нейтральные Сумерки";
                    break;

                case "8":
                    ali1 = "chaos.gif";
                    ali2 = "Абсолютный Хаос";
                    break;

                case "9":
                    ali1 = "angel.gif";
                    ali2 = "Ангел";
                    break;
                }

                if (!string.IsNullOrEmpty(ali1))
                {
                    align =
                        "<img src=http://image.neverlands.ru/signs/" +
                        ali1 +
                        @" width=15 height=12 align=absmiddle border=0 title=""" +
                        ali2 +
                        @""">&nbsp";
                }

                var ss = string.Empty;
                if (!string.IsNullOrEmpty(infClan))
                {
                    ss =
                        "<img src=http://image.neverlands.ru/signs/" +
                        infSign +
                        @" width=15 height=12 align=absmiddle title=""" +
                        infClan +
                        @""">&nbsp;";
                }

                var location = string.Empty;
                if (infIsOnline)
                {
                    // Окрестности Форпоста [Окрестность Форпоста, Биржа]"
                    var orgLocation = userInfo.Location;
                    if (!orgLocation.StartsWith("Форпост", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Октал", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Деревня", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Тюрьма", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Окрестности Форпоста [Окрестность Форпоста, Биржа]", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Окрестность Форпоста [Сырьевая Биржа]", StringComparison.OrdinalIgnoreCase) &&
                        !orgLocation.StartsWith("Окрестности Форпоста [Плавильная мастерская]", StringComparison.OrdinalIgnoreCase))
                    {
                        //var matrixNick = string.Format(":{0}:", vipNick);
                        var arrayPossibleLocations = new List <string>();
                        var cellCount = 0;
                        foreach (var cellKey in Map.Cells.Keys)
                        {
                            var cell = Map.Cells[cellKey];
                            if (!cell.Tooltip.Equals(infLocation, StringComparison.OrdinalIgnoreCase))
                            {
                                continue;
                            }

                            cellCount++;
                        }

                        if (cellCount > 0)
                        {
                            var cellIndex = 0;
                            foreach (var cellKey in Map.Cells.Keys)
                            {
                                var cell = Map.Cells[cellKey];
                                if (!cell.Tooltip.Equals(infLocation, StringComparison.OrdinalIgnoreCase))
                                {
                                    continue;
                                }

                                var progress = (cellIndex * 100) / cellCount;
                                var status   = $"{firstMessage}... {progress}%";
                                try
                                {
                                    if (AppVars.VipFormCompas != null)
                                    {
                                        AppVars.VipFormCompas.BeginInvoke(
                                            new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus),
                                            new object[] { status });
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                                catch (InvalidOperationException)
                                {
                                }

                                cellIndex++;

                                arrayPossibleLocations.Add(cellKey);
                            }
                        }

                        if (arrayPossibleLocations.Count > 0)
                        {
                            var possibleLocations = arrayPossibleLocations.Count;
                            var path = new MapPath(AppVars.LocationReal, arrayPossibleLocations.ToArray());
                            if (possibleLocations == 1)
                            {
                                location =
                                    $"Точное положение: <a style='text-decoration:none' href='http://{arrayPossibleLocations[0]}'><b>{arrayPossibleLocations[0]}</b></a> (шагов: <b>{path.Jumps}</b>). {infLocation}.";
                            }
                            else
                            {
                                location =
                                    $"{infLocation}. Возможных клеток: <b>{possibleLocations}</b>, ближайшая <a style='text-decoration:none' href='http://{path.Destination ?? AppVars.LocationReal}'><b>{path.Destination ?? AppVars.LocationReal}</b></a> (шагов: <b>{path.Jumps}</b>).";
                            }
                        }
                        else
                        {
                            location = @"<font color=""#cc0000"">" + "Неизвестная клетка!" + "</font>";
                        }
                    }
                    else
                    {
                        string[] dest = null;
                        if (orgLocation.StartsWith("Форпост") || orgLocation.StartsWith("Тюрьма"))
                        {
                            dest = new[] { "8-259", "8-294" };
                        }

                        if (orgLocation.StartsWith("Октал"))
                        {
                            dest = new[] { "12-428", "12-494", "12-521" };
                        }

                        if (orgLocation.StartsWith("Деревня"))
                        {
                            dest = new[] { "8-197", "8-228", "8-229" };
                        }

                        if (orgLocation.StartsWith("Окрестности Форпоста [Окрестность Форпоста, Биржа]"))
                        {
                            dest = new[] { "8-227" };
                        }

                        if (orgLocation.StartsWith("Окрестность Форпоста [Сырьевая Биржа]"))
                        {
                            dest = new[] { "8-227" };
                        }

                        if (dest != null)
                        {
                            var path = new MapPath(AppVars.LocationReal, dest);
                            location = $"Точное положение: <a style='text-decoration:none' href='http://{path.Destination}'><b>{path.Destination}</b></a> (шагов: <b>{path.Jumps}</b>). {infLocation}.";
                        }
                    }
                }
                else
                {
                    location = @"<font color=""#cccccc"">" + "В оффлайне или невиде." + "</font>";
                }

                location = @"<span style=""font-size:10px;"">" + location + "</span>";
                var result =
                    @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
                    align +
                    ss +
                    @"<b>" +
                    colorNick +
                    "</b></a>[" +
                    infLevel +
                    @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
                    sbeff +
                    "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
                    location +
                    "</span><br>";

                try
                {
                    if (AppVars.VipFormCompas != null)
                    {
                        AppVars.VipFormCompas.BeginInvoke(
                            new AddCharacterDelegate(AppVars.VipFormCompas.AddCharacter), result);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }

            try
            {
                if (AppVars.VipFormCompas != null)
                {
                    AppVars.VipFormCompas.BeginInvoke(
                        new UpdateStatusDelegate(AppVars.VipFormCompas.UpdateStatus), "Сканирование завешено.");
                }
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 5
0
        /* in44.nl
         * private static void AddClanAsync(object stateInfo)
         * {
         *  var nick = stateInfo as string;
         *  if (nick == null)
         *  {
         *      return;
         *  }
         *
         *  var html = NeverInfo.GetPInfo(nick);
         *  if (string.IsNullOrEmpty(html))
         *      return;
         *
         *  var params0 = HelperStrings.SubString(html, "var params = [[", "],");
         *  if (string.IsNullOrEmpty(params0))
         *  {
         *      return;
         *  }
         *
         *  var spar0 = HelperStrings.ParseArguments(params0);
         *  if (spar0.Length < 9)
         *  {
         *      return;
         *  }
         *
         *  var firstNick = spar0[0].Trim();
         *  var firstSign = spar0[2];
         *  var firstClan = spar0[8];
         *
         *  var listClanNicks = new List<string> {firstNick};
         *  if (!string.IsNullOrEmpty(firstSign))
         *  {
         *      byte[] buffer;
         *      using (var wc = new WebClient {Proxy = AppVars.LocalProxy})
         *      {
         *          try
         *          {
         *              var suff = firstSign;
         *              var posp = suff.IndexOf('.');
         *              if (posp != -1)
         *                  suff = suff.Substring(0, posp);
         *
         *              buffer = wc.DownloadData(new Uri("http://in44.nl/clanstruct/c_" + suff + "/"));
         *          }
         *          catch (WebException)
         *          {
         *              return;
         *          }
         *      }
         *
         *      html = AppVars.Codepage.GetString(buffer);
         *      var p1 = 0;
         *      while (p1 != -1)
         *      {
         *          p1 = html.IndexOf("pinfo.cgi?", p1, StringComparison.OrdinalIgnoreCase);
         *          if (p1 == -1)
         *              break;
         *
         *          p1 += "pinfo.cgi?".Length;
         *          var p2 = html.IndexOf(@"""", p1, StringComparison.OrdinalIgnoreCase);
         *          if (p2 == -1)
         *              continue;
         *
         *          var statnick = html.Substring(p1, p2 - p1);
         *          listClanNicks.Add(statnick);
         *      }
         *  }
         *
         *  foreach (var vipNick in listClanNicks)
         *  {
         *      try
         *      {
         *          if (AppVars.VipFormAddClan != null)
         *          {
         *              var message = string.Format("Анализируем [{0}]...", vipNick);
         *              AppVars.VipFormAddClan.BeginInvoke(
         *                  new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
         *                  new object[] { message });
         *          }
         *          else
         *          {
         *              return;
         *          }
         *      }
         *      catch (InvalidOperationException)
         *      {
         *      }
         *
         *      html = NeverInfo.GetPInfo(vipNick);
         *      if (string.IsNullOrEmpty(html))
         *          continue;
         *
         *      params0 = HelperStrings.SubString(html, "var params = [[", "],");
         *      if (string.IsNullOrEmpty(params0))
         *      {
         *          continue;
         *      }
         *
         *      spar0 = HelperStrings.ParseArguments(params0);
         *      if (spar0.Length < 9)
         *      {
         *          continue;
         *      }
         *
         *      var infNick = spar0[0].Trim();
         *      var infAlign = spar0[1];
         *      var infSign = spar0[2];
         *      var infClan = spar0[8];
         *
         *      if (!infClan.Equals(firstClan))
         *      {
         *          continue;
         *      }
         *
         *      var infLevel = spar0[3];
         *      var infLocation = spar0[5];
         *      if (infLocation.IndexOf('[') != -1)
         *      {
         *          infLocation = HelperStrings.SubString(infLocation, "[", "]");
         *      }
         *
         *      var infIsOnline = !string.IsNullOrEmpty(infLocation);
         *
         *      var isLightWound = false;
         *      var isMediumWound = false;
         *      var isHeavyWound = false;
         *      var isUltimateWound = false;
         *
         *      var effects = HelperStrings.SubString(html, "var effects = [", "];");
         *      var sbeff = new StringBuilder();
         *      if (!string.IsNullOrEmpty(effects))
         *      {
         *          var seffects = effects.Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
         *          for (var k = 0; k < seffects.Length; k++)
         *          {
         *              var effk = seffects[k].Trim(new[] { '[', ']' });
         *              var seffk = effk.Split(',');
         *              if (seffk.Length <= 1)
         *              {
         *                  continue;
         *              }
         *
         *              var effcode = seffk[0];
         *              var effname = seffk[1].Replace("<b>", String.Empty).Replace("</b>", String.Empty);
         *              sbeff.AppendFormat(
         *                  @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle alt=""{1}"">",
         *                  effcode,
         *                  effname);
         *              switch (effcode)
         *              {
         *                  case "1":
         *                      isUltimateWound = true;
         *                      break;
         *
         *                  case "2":
         *                      isHeavyWound = true;
         *                      break;
         *
         *                  case "3":
         *                      isMediumWound = true;
         *                      break;
         *
         *                  case "4":
         *                      isLightWound = true;
         *                      break;
         *              }
         *          }
         *      }
         *
         *      var travma = string.Empty;
         *      if (isUltimateWound)
         *      {
         *          travma = "боевая";
         *      }
         *      else
         *      {
         *          if (isHeavyWound)
         *          {
         *              travma = "тяжелая";
         *          }
         *          else
         *          {
         *              if (isMediumWound)
         *              {
         *                  travma = "средняя";
         *              }
         *              else
         *              {
         *                  if (isLightWound)
         *                  {
         *                      travma = "легкая";
         *                  }
         *              }
         *          }
         *      }
         *
         *      var colorNick = infNick;
         *      if (!infIsOnline)
         *      {
         *          colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
         *      }
         *      else
         *      {
         *          if (!string.IsNullOrEmpty(travma))
         *          {
         *              switch (travma)
         *              {
         *                  case "боевая":
         *                      colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
         *                      break;
         *                  case "тяжелая":
         *                      colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
         *                      break;
         *                  case "средняя":
         *                      colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
         *                      break;
         *                  case "легкая":
         *                      colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
         *                      break;
         *              }
         *          }
         *      }
         *
         *      var align = string.Empty;
         *      var ali1 = string.Empty;
         *      var ali2 = string.Empty;
         *      switch (infAlign)
         *      {
         *          case "1":
         *              ali1 = "darks.gif";
         *              ali2 = "Дети Тьмы";
         *              break;
         *          case "2":
         *              ali1 = "lights.gif";
         *              ali2 = "Дети Света";
         *              break;
         *          case "3":
         *              ali1 = "sumers.gif";
         *              ali2 = "Дети Сумерек";
         *              break;
         *          case "4":
         *              ali1 = "chaoss.gif";
         *              ali2 = "Дети Хаоса";
         *              break;
         *          case "5":
         *              ali1 = "light.gif";
         *              ali2 = "Истинный Свет";
         *              break;
         *          case "6":
         *              ali1 = "dark.gif";
         *              ali2 = "Истинная Тьма";
         *              break;
         *          case "7":
         *              ali1 = "sumer.gif";
         *              ali2 = "Нейтральные Сумерки";
         *              break;
         *          case "8":
         *              ali1 = "chaos.gif";
         *              ali2 = "Абсолютный Хаос";
         *              break;
         *          case "9":
         *              ali1 = "angel.gif";
         *              ali2 = "Ангел";
         *              break;
         *      }
         *
         *      if (!string.IsNullOrEmpty(ali1))
         *      {
         *          align =
         *              "<img src=http://image.neverlands.ru/signs/" +
         *              ali1 +
         *              @" width=15 height=12 align=absmiddle border=0 alt=""" +
         *              ali2 +
         *              @""">&nbsp";
         *      }
         *
         *      var ss = string.Empty;
         *      if (!string.IsNullOrEmpty(infClan))
         *      {
         *          ss =
         *              "<img src=http://image.neverlands.ru/signs/" +
         *              infSign +
         *              @" width=15 height=12 align=absmiddle alt=""" +
         *              infClan +
         *              @""">&nbsp;";
         *      }
         *
         *      var result =
         *          @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
         *          align +
         *          ss +
         *          @"<b>" +
         *          colorNick +
         *          "</b></a>[" +
         *          infLevel +
         *          @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
         *          sbeff +
         *          "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
         *          @"<span style=""font-size:10px;"">" + "добавлен в контакты" + "</span>" +
         *          "</span><br>";
         *
         *      try
         *      {
         *          if (AppVars.VipFormAddClan != null)
         *          {
         *              AppVars.VipFormAddClan.BeginInvoke(
         *                  new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.AddCharacter),
         *                  new object[] { result });
         *          }
         *          else
         *          {
         *              return;
         *          }
         *      }
         *      catch (InvalidOperationException)
         *      {
         *      }
         *
         *      var nickContact = infNick;
         *
         *      if (AppVars.MainForm != null)
         *      {
         *          AppVars.MainForm.BeginInvoke(
         *              new AddContactFromBulkDelegate(AppVars.MainForm.AddContactFromBulk),
         *              new object[] { nickContact });
         *      }
         *      else
         *      {
         *          return;
         *      }
         *  }
         *
         *  try
         *  {
         *      if (AppVars.VipFormAddClan != null)
         *      {
         *          AppVars.VipFormAddClan.BeginInvoke(
         *              new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
         *              new object[] { "Добавление в контакты завешено." });
         *      }
         *      else
         *      {
         *          return;
         *      }
         *  }
         *  catch (InvalidOperationException)
         *  {
         *  }
         *
         *  AppVars.Profile.Save();
         * }
         */

        private static void AddClanAsync(object stateInfo)
        {
            var nick = stateInfo as string;

            if (nick == null)
            {
                return;
            }

            var mainUserInfo = NeverApi.GetAll(nick);

            if (mainUserInfo == null)
            {
                return;
            }

            var firstNick = mainUserInfo.Nick;
            var firstSign = mainUserInfo.ClanSign;
            var firstClan = mainUserInfo.ClanName;

            var listClanNicks = new List <string> {
                firstNick
            };

            if (!string.IsNullOrEmpty(firstSign))
            {
                byte[] buffer;
                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri("http://allnl.ru/clan-players/all"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                var html = Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                // <img src="http://image.neverlands.ru/signs/c207.gif"> <a href="/clan-players/79">Dao Shen</a>
                // <img src="http://image.neverlands.ru/signs/c257.gif"> <a href="/clan-players/82">Reign of Winds</a>

                var linkClan = HelperStrings.SubString(
                    html,
                    $"<img src=\"http://image.neverlands.ru/signs/{firstSign}\"> <a href=\"/clan-players/",
                    $"\">");

                if (string.IsNullOrEmpty(linkClan))
                {
                    return;
                }

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                using (var wc = new WebClient {
                    Proxy = AppVars.LocalProxy
                })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri($"http://allnl.ru/clan-players/{linkClan}"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = Encoding.UTF8.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                {
                    return;
                }

                var p1 = 0;
                while (p1 != -1)
                {
                    // <img src="http://image.neverlands.ru/signs/c237.gif"> Susya JE[18]

                    string pat1 = $"<img src=\"http://image.neverlands.ru/signs/{firstSign}\">";
                    p1 = html.IndexOf(pat1, p1, StringComparison.OrdinalIgnoreCase);
                    if (p1 == -1)
                    {
                        break;
                    }

                    p1 += pat1.Length;
                    var p2 = html.IndexOf(@"[", p1, StringComparison.OrdinalIgnoreCase);
                    if (p2 == -1)
                    {
                        continue;
                    }

                    var statnick = html.Substring(p1, p2 - p1).Trim();
                    if (statnick.Length < 64)
                    {
                        listClanNicks.Add(statnick);
                    }
                }
            }

            foreach (var vipNick in listClanNicks)
            {
                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = $"Анализируем [{vipNick}]...";
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var userInfo = NeverApi.GetAll(vipNick);
                if (userInfo == null)
                {
                    continue;
                }

                var infNick  = userInfo.Nick;
                var infAlign = userInfo.Align;
                var infSign  = userInfo.ClanSign;
                var infClan  = userInfo.ClanName;

                if (!infClan.Equals(firstClan))
                {
                    continue;
                }

                var infLevel    = userInfo.Level;
                var infLocation = userInfo.Location;
                if (infLocation.IndexOf('[') != -1)
                {
                    infLocation = HelperStrings.SubString(infLocation, "[", "]");
                }

                var infIsOnline = !string.IsNullOrEmpty(infLocation);

                var isLightWound    = false;
                var isMediumWound   = false;
                var isHeavyWound    = false;
                var isUltimateWound = false;

                if (userInfo.EffectsCodes.Length > 0)
                {
                    foreach (var elem in userInfo.EffectsCodes)
                    {
                        switch (elem)
                        {
                        case "2":
                            isHeavyWound = true;     // тяжелые
                            break;

                        case "3":
                            isMediumWound = true;     // средние
                            break;

                        case "4":
                            isLightWound = true;     // легкие
                            break;

                        case "24":
                            isUltimateWound = true;
                            break;

                        default:
                            break;
                        }
                    }
                }

                var travma = string.Empty;
                if (isUltimateWound)
                {
                    travma = "боевая";
                }
                else
                {
                    if (isHeavyWound)
                    {
                        travma = "тяжелая";
                    }
                    else
                    {
                        if (isMediumWound)
                        {
                            travma = "средняя";
                        }
                        else
                        {
                            if (isLightWound)
                            {
                                travma = "легкая";
                            }
                        }
                    }
                }

                var colorNick = infNick;
                if (!infIsOnline)
                {
                    colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
                }
                else
                {
                    if (!string.IsNullOrEmpty(travma))
                    {
                        switch (travma)
                        {
                        case "боевая":
                            colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
                            break;

                        case "тяжелая":
                            colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
                            break;

                        case "средняя":
                            colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
                            break;

                        case "легкая":
                            colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
                            break;
                        }
                    }
                }

                var align = string.Empty;
                var ali1  = string.Empty;
                var ali2  = string.Empty;
                switch (infAlign)
                {
                case "1":
                    ali1 = "darks.gif";
                    ali2 = "Дети Тьмы";
                    break;

                case "2":
                    ali1 = "lights.gif";
                    ali2 = "Дети Света";
                    break;

                case "3":
                    ali1 = "sumers.gif";
                    ali2 = "Дети Сумерек";
                    break;

                case "4":
                    ali1 = "chaoss.gif";
                    ali2 = "Дети Хаоса";
                    break;

                case "5":
                    ali1 = "light.gif";
                    ali2 = "Истинный Свет";
                    break;

                case "6":
                    ali1 = "dark.gif";
                    ali2 = "Истинная Тьма";
                    break;

                case "7":
                    ali1 = "sumer.gif";
                    ali2 = "Нейтральные Сумерки";
                    break;

                case "8":
                    ali1 = "chaos.gif";
                    ali2 = "Абсолютный Хаос";
                    break;

                case "9":
                    ali1 = "angel.gif";
                    ali2 = "Ангел";
                    break;
                }

                if (!string.IsNullOrEmpty(ali1))
                {
                    align =
                        "<img src=http://image.neverlands.ru/signs/" +
                        ali1 +
                        @" width=15 height=12 align=absmiddle border=0 title=""" +
                        ali2 +
                        @""">&nbsp";
                }

                var ss = string.Empty;
                if (!string.IsNullOrEmpty(infClan))
                {
                    ss =
                        "<img src=http://image.neverlands.ru/signs/" +
                        infSign +
                        @" width=15 height=12 align=absmiddle title=""" +
                        infClan +
                        @""">&nbsp;";
                }

                var result =
                    @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
                    align +
                    ss +
                    @"<b>" +
                    colorNick +
                    "</b></a>[" +
                    infLevel +
                    @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
                    "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
                    @"<span style=""font-size:10px;"">" + "добавлен в контакты" + "</span>" +
                    "</span><br>";

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.AddCharacter), result);
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var nickContact = infNick;

                if (AppVars.MainForm != null)
                {
                    AppVars.MainForm.BeginInvoke(
                        new AddContactFromBulkDelegate(AppVars.MainForm.AddContactFromBulk), nickContact);
                }
                else
                {
                    return;
                }
            }

            try
            {
                if (AppVars.VipFormAddClan != null)
                {
                    AppVars.VipFormAddClan.BeginInvoke(
                        new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), "Добавление в контакты завешено.");
                }
                else
                {
                    return;
                }
            }
            catch (InvalidOperationException)
            {
            }

            AppVars.Profile.Save();
        }
Ejemplo n.º 6
0
        /* in44.nl
        private static void AddClanAsync(object stateInfo)
        {
            var nick = stateInfo as string;
            if (nick == null)
            {
                return;
            }

            var html = NeverInfo.GetPInfo(nick);
            if (string.IsNullOrEmpty(html))
                return;

            var params0 = HelperStrings.SubString(html, "var params = [[", "],");
            if (string.IsNullOrEmpty(params0))
            {
                return;
            }

            var spar0 = HelperStrings.ParseArguments(params0);
            if (spar0.Length < 9)
            {
                return;
            }

            var firstNick = spar0[0].Trim();
            var firstSign = spar0[2];
            var firstClan = spar0[8];

            var listClanNicks = new List<string> {firstNick};
            if (!string.IsNullOrEmpty(firstSign))
            {
                byte[] buffer;
                using (var wc = new WebClient {Proxy = AppVars.LocalProxy})
                {
                    try
                    {
                        var suff = firstSign;
                        var posp = suff.IndexOf('.');
                        if (posp != -1)
                            suff = suff.Substring(0, posp);

                        buffer = wc.DownloadData(new Uri("http://in44.nl/clanstruct/c_" + suff + "/"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                var p1 = 0;
                while (p1 != -1)
                {
                    p1 = html.IndexOf("pinfo.cgi?", p1, StringComparison.OrdinalIgnoreCase);
                    if (p1 == -1)
                        break;

                    p1 += "pinfo.cgi?".Length;
                    var p2 = html.IndexOf(@"""", p1, StringComparison.OrdinalIgnoreCase);
                    if (p2 == -1)
                        continue;

                    var statnick = html.Substring(p1, p2 - p1);
                    listClanNicks.Add(statnick);
                }
            }

            foreach (var vipNick in listClanNicks)
            {
                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = string.Format("Анализируем [{0}]...", vipNick);
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
                            new object[] { message });
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                html = NeverInfo.GetPInfo(vipNick);
                if (string.IsNullOrEmpty(html))
                    continue;

                params0 = HelperStrings.SubString(html, "var params = [[", "],");
                if (string.IsNullOrEmpty(params0))
                {
                    continue;
                }

                spar0 = HelperStrings.ParseArguments(params0);
                if (spar0.Length < 9)
                {
                    continue;
                }

                var infNick = spar0[0].Trim();
                var infAlign = spar0[1];
                var infSign = spar0[2];
                var infClan = spar0[8];

                if (!infClan.Equals(firstClan))
                {
                    continue;
                }

                var infLevel = spar0[3];
                var infLocation = spar0[5];
                if (infLocation.IndexOf('[') != -1)
                {
                    infLocation = HelperStrings.SubString(infLocation, "[", "]");
                }

                var infIsOnline = !string.IsNullOrEmpty(infLocation);

                var isLightWound = false;
                var isMediumWound = false;
                var isHeavyWound = false;
                var isUltimateWound = false;

                var effects = HelperStrings.SubString(html, "var effects = [", "];");
                var sbeff = new StringBuilder();
                if (!string.IsNullOrEmpty(effects))
                {
                    var seffects = effects.Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries);
                    for (var k = 0; k < seffects.Length; k++)
                    {
                        var effk = seffects[k].Trim(new[] { '[', ']' });
                        var seffk = effk.Split(',');
                        if (seffk.Length <= 1)
                        {
                            continue;
                        }

                        var effcode = seffk[0];
                        var effname = seffk[1].Replace("<b>", String.Empty).Replace("</b>", String.Empty);
                        sbeff.AppendFormat(
                            @"&nbsp;<img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle alt=""{1}"">",
                            effcode,
                            effname);
                        switch (effcode)
                        {
                            case "1":
                                isUltimateWound = true;
                                break;

                            case "2":
                                isHeavyWound = true;
                                break;

                            case "3":
                                isMediumWound = true;
                                break;

                            case "4":
                                isLightWound = true;
                                break;
                        }
                    }
                }

                var travma = string.Empty;
                if (isUltimateWound)
                {
                    travma = "боевая";
                }
                else
                {
                    if (isHeavyWound)
                    {
                        travma = "тяжелая";
                    }
                    else
                    {
                        if (isMediumWound)
                        {
                            travma = "средняя";
                        }
                        else
                        {
                            if (isLightWound)
                            {
                                travma = "легкая";
                            }
                        }
                    }
                }

                var colorNick = infNick;
                if (!infIsOnline)
                {
                    colorNick = @"<font color=""#cccccc"">" + colorNick + "</font>";
                }
                else
                {
                    if (!string.IsNullOrEmpty(travma))
                    {
                        switch (travma)
                        {
                            case "боевая":
                                colorNick = @"<font color=""#666600"">" + colorNick + "</font>";
                                break;
                            case "тяжелая":
                                colorNick = @"<font color=""#c10000"">" + colorNick + "</font>";
                                break;
                            case "средняя":
                                colorNick = @"<font color=""#e94c69"">" + colorNick + "</font>";
                                break;
                            case "легкая":
                                colorNick = @"<font color=""#ef7f94"">" + colorNick + "</font>";
                                break;
                        }
                    }
                }

                var align = string.Empty;
                var ali1 = string.Empty;
                var ali2 = string.Empty;
                switch (infAlign)
                {
                    case "1":
                        ali1 = "darks.gif";
                        ali2 = "Дети Тьмы";
                        break;
                    case "2":
                        ali1 = "lights.gif";
                        ali2 = "Дети Света";
                        break;
                    case "3":
                        ali1 = "sumers.gif";
                        ali2 = "Дети Сумерек";
                        break;
                    case "4":
                        ali1 = "chaoss.gif";
                        ali2 = "Дети Хаоса";
                        break;
                    case "5":
                        ali1 = "light.gif";
                        ali2 = "Истинный Свет";
                        break;
                    case "6":
                        ali1 = "dark.gif";
                        ali2 = "Истинная Тьма";
                        break;
                    case "7":
                        ali1 = "sumer.gif";
                        ali2 = "Нейтральные Сумерки";
                        break;
                    case "8":
                        ali1 = "chaos.gif";
                        ali2 = "Абсолютный Хаос";
                        break;
                    case "9":
                        ali1 = "angel.gif";
                        ali2 = "Ангел";
                        break;
                }

                if (!string.IsNullOrEmpty(ali1))
                {
                    align =
                        "<img src=http://image.neverlands.ru/signs/" +
                        ali1 +
                        @" width=15 height=12 align=absmiddle border=0 alt=""" +
                        ali2 +
                        @""">&nbsp";
                }

                var ss = string.Empty;
                if (!string.IsNullOrEmpty(infClan))
                {
                    ss =
                        "<img src=http://image.neverlands.ru/signs/" +
                        infSign +
                        @" width=15 height=12 align=absmiddle alt=""" +
                        infClan +
                        @""">&nbsp;";
                }

                var result =
                    @"<span style=""font-family:Verdana,Arial,sans-serif; font-size:12px; text-decoration:none;	color:#222222;"">" +
                    align +
                    ss +
                    @"<b>" +
                    colorNick +
                    "</b></a>[" +
                    infLevel +
                    @"]<a href='http://www.neverlands.ru/pinfo.cgi?" + infNick + "'><img src=http://image.neverlands.ru/chat/info.gif width=11 height=12 border=0 align=absmiddle></a>" +
                    sbeff +
                    "<img src=http://image.neverlands.ru/1x1.gif width=8 height=1>" +
                    @"<span style=""font-size:10px;"">" + "добавлен в контакты" + "</span>" +
                    "</span><br>";

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.AddCharacter),
                            new object[] { result });
                    }
                    else
                    {
                        return;
                    }
                }
                catch (InvalidOperationException)
                {
                }

                var nickContact = infNick;

                if (AppVars.MainForm != null)
                {
                    AppVars.MainForm.BeginInvoke(
                        new AddContactFromBulkDelegate(AppVars.MainForm.AddContactFromBulk),
                        new object[] { nickContact });
                }
                else
                {
                    return;
                }
            }

            try
            {
                if (AppVars.VipFormAddClan != null)
                {
                    AppVars.VipFormAddClan.BeginInvoke(
                        new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus),
                        new object[] { "Добавление в контакты завешено." });
                }
                else
                {
                    return;
                }
            }
            catch (InvalidOperationException)
            {
            }

            AppVars.Profile.Save();
        }
        */

        private static void AddClanAsync(object stateInfo)
        {
            var nick = stateInfo as string;
            if (nick == null)
            {
                return;
            }

            var html = NeverInfo.GetPInfo(nick);
            if (string.IsNullOrEmpty(html))
                return;

            var params0 = HelperStrings.SubString(html, "var params = [[", "],");
            if (string.IsNullOrEmpty(params0))
            {
                return;
            }

            var spar0 = HelperStrings.ParseArguments(params0);
            if (spar0.Length < 9)
            {
                return;
            }

            var firstNick = spar0[0].Trim();
            var firstSign = spar0[2];
            var firstClan = spar0[8];

            var listClanNicks = new List<string> { firstNick };
            if (!string.IsNullOrEmpty(firstSign))
            {
                byte[] buffer;
                using (var wc = new WebClient { Proxy = AppVars.LocalProxy })
                {
                    try
                    {
                        IdleManager.AddActivity();
                        buffer = wc.DownloadData(new Uri("http://neverok.ru//clan_players.php?type=all"));
                    }
                    catch (WebException)
                    {
                        return;
                    }
                    finally
                    {
                        IdleManager.RemoveActivity();
                    }
                }

                html = AppVars.Codepage.GetString(buffer);
                if (string.IsNullOrEmpty(html))
                    return;

                var linkClan = HelperStrings.SubString(html, firstSign + @"""><a href=""clan_players.php?clantype=", @"""");
                if (string.IsNullOrEmpty(linkClan))
                    return;

                try
                {
                    if (AppVars.VipFormAddClan != null)
                    {
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
                        AppVars.VipFormAddClan.BeginInvoke(
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
                    }
                    else
                    {
                        return;
465
                return;
466
            }
467
​
468
            var spar0 = HelperStrings.ParseArguments(params0);
469
            if (spar0.Length < 9)
470
            {
471
                return;
472
            }
473
​
474
            var firstNick = spar0[0].Trim();
475
            var firstSign = spar0[2];
476
            var firstClan = spar0[8];
477
​
478
            var listClanNicks = new List<string> { firstNick };
479
            if (!string.IsNullOrEmpty(firstSign))
480
            {
481
                byte[] buffer;
482
                using (var wc = new WebClient { Proxy = AppVars.LocalProxy })
483
                {
484
                    try
485
                    {
486
                        IdleManager.AddActivity();
487
                        buffer = wc.DownloadData(new Uri("http://neverok.ru//clan_players.php?type=all"));
488
                    }
489
                    catch (WebException)
490
                    {
491
                        return;
492
                    }
493
                    finally
494
                    {
495
                        IdleManager.RemoveActivity();
496
                    }
497
                }
498
​
499
                html = AppVars.Codepage.GetString(buffer);
500
                if (string.IsNullOrEmpty(html))
501
                    return;
502
​
503
                var linkClan = HelperStrings.SubString(html, firstSign + @"""><a href=""clan_players.php?clantype=", @"""");
504
                if (string.IsNullOrEmpty(linkClan))
505
                    return;
506
​
507
                try
508
                {
509
                    if (AppVars.VipFormAddClan != null)
510
                    {
511
                        var message = string.Format($"Получаем список клана [{firstClan}]...");
512
                        AppVars.VipFormAddClan.BeginInvoke(
513
                            new UpdateStatusFormAddClanDelegate(AppVars.VipFormAddClan.UpdateStatus), message);
514
                    }
515
                    else
516
                    {
517
                        return;
518
                    }
519
                }
Ejemplo n.º 7
0
        private void Execute(object objThreadstate)
        {
            var flag            = false;
            var flag2           = false;
            var flagsavedtrafic = false;

            if ((Request != null) && (Response != null))
            {
                if (!Request.ReadRequest())
                {
                    CloseSessionPipes();
                    return;
                }

                RequestBodyBytes = Request.TakeEntity();
                ExecuteBasicRequestManipulations();

                RequestBodyBytes = Filter.PreProcess("http://" + Url, RequestBodyBytes);

                if (Url.StartsWith("www.neverlands.ru/cgi-bin/go.cgi?uid=", StringComparison.OrdinalIgnoreCase))
                {
                    flag     = true;
                    Response = new ServerChatter(this, "HTTP/1.1 304 Not Modified\r\nServer: Cache\r\n\r\n");
                    goto afterresponse;
                }

                if (Url.Contains("top.list.ru") || Url.Contains("counter.yadro.ru"))
                {
                    flag     = true;
                    Response = new ServerChatter(this, "HTTP/1.1 304 Not Modified\r\nServer: Cache\r\n\r\n");
                    goto afterresponse;
                }

                if (!string.IsNullOrEmpty(Proxy.BasicAuth))
                {
                    Request.Headers.Add("Proxy-Authorization", Proxy.BasicAuth);
                }

                if (_isCustomFilter)
                {
                    if (Request.Headers.Exists("If-Modified-Since"))
                    {
                        Request.Headers.Remove("If-Modified-Since");
                    }

                    if (Request.Headers.Exists("If-None-Match"))
                    {
                        Request.Headers.Remove("If-None-Match");
                    }
                }
                else
                {
                    if (Request.Headers.Exists("If-Modified-Since") || Request.Headers.Exists("If-None-Match"))
                    {
                        flag     = true;
                        Response = new ServerChatter(this, "HTTP/1.1 304 Not Modified\r\nServer: Cache\r\n\r\n");
                        goto afterresponse;
                    }

                    flagsavedtrafic = true;
                }

                Request.Headers.Remove("Cookie");

                var cookiedata = CookiesManager.Obtain(Host);
                if (!string.IsNullOrEmpty(cookiedata))
                {
                    Request.Headers.Add("Cookie", cookiedata);
                }

                if (_isCache)
                {
                    var data = Cache.Get(Url, AppVars.CacheRefresh);
                    if (data != null)
                    {
                        if (flagsavedtrafic)
                        {
                            try
                            {
                                if (AppVars.MainForm != null)
                                {
                                    AppVars.MainForm.UpdateSavedTrafficSafe(data.Length);
                                }
                            }
                            catch (InvalidOperationException)
                            {
                            }
                        }

                        flag     = true;
                        Response = new ServerChatter(this, "HTTP/1.1 200 OK\r\nServer: Cache\r\n\r\n");
                        if (_isCustomFilter)
                        {
                            _isCustomFilter = false;
                            var pdata = Filter.Process("http://" + Url, data);
                            Response.AssignData(pdata);
                        }
                        else
                        {
                            Response.AssignData(data);
                        }

                        _isCache = false;
                        goto afterresponse;
                    }
                }

                // Begin of request

                IdleManager.AddActivity();

                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.AddAddressToStatusString(Url);
                    }
                }
                catch (InvalidOperationException)
                {
                }

                flag = Response.ResendRequest(0);
                if (flag)
                {
                    flag = Response.ReadResponse();
                }

                if (!flag)
                {
                    CloseSessionPipes();
                }
                else
                {
                    ResponseBodyBytes = Response.TakeEntity();
                }

                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.RemoveAddressFromStatusString(Url);
                    }
                }
                catch (InvalidOperationException)
                {
                }

                // End of request

                IdleManager.RemoveActivity();
            }

afterresponse:
            ExecuteBasicResponseManipulations();

            if (Response != null)
            {
                if (Url.StartsWith("www.neverlands.ru/main.php", StringComparison.OrdinalIgnoreCase))
                {
                    if (Response.Headers.Exists("Date"))
                    {
                        var      stringDateTime = Response.Headers["Date"];
                        DateTime serverDateTime;
                        if (DateTime.TryParse(stringDateTime, AppVars.EnUsCulture, DateTimeStyles.None, out serverDateTime))
                        {
                            try
                            {
                                if (AppVars.MainForm != null)
                                {
                                    AppVars.MainForm.BeginInvoke(
                                        new UpdateServerTimeDelegate(AppVars.MainForm.UpdateServerTime),
                                        new object[] { serverDateTime });
                                }
                            }
                            catch (InvalidOperationException)
                            {
                            }
                        }
                    }
                }

                for (var i = 0; i < Response.Headers.Count(); i++)
                {
                    if (Response.Headers[i].Name.Equals("Set-Cookie", StringComparison.OrdinalIgnoreCase))
                    {
                        CookiesManager.Assign(Host, Response.Headers[i].Value);
                    }
                }

                Response.Headers.Remove("Set-Cookie");
                if (Response != null && Response.Headers != null && Response.Headers.HttpResponseCode == 200)
                {
                    if (Url.StartsWith("www.neverlands.ru/modules/code/code.php?", StringComparison.OrdinalIgnoreCase))
                    {
                        AppVars.CodePng = ResponseBodyBytes;
                    }
                    else
                    {
                        if (_isCache)
                        {
                            Cache.Store(Url, ResponseBodyBytes, _isGameHost);
                        }

                        if (_isCustomFilter && ResponseBodyBytes != null)
                        {
                            var pdata = Filter.Process("http://" + Url, ResponseBodyBytes);
                            Response.AssignData(pdata);
                        }
                    }
                }
                else
                {
                    if (Response != null && Response.Headers != null && Response.Headers.HttpResponseCode >= 400 & Response.Headers.HttpResponseCode != 404 && _isCustomFilter)
                    {
                        var sb = new StringBuilder(
                            HelperErrors.Head() +
                            "Отказ сервера <br>" +
                            @"<br><span class=""gray"">");
                        sb.AppendLine(Response.Headers.HttpResponseStatus);
                        sb.Append(
                            "</span>" +
                            "</body>" +
                            "</html>");

                        Response.AssignData(Encoding.UTF8.GetBytes(sb.ToString()));
                        Response.Headers = new HttpResponseHeaders
                        {
                            HttpResponseCode   = 200,
                            HttpResponseStatus = "OK"
                        };
                    }
                }
            }

            var flag3 = false;

            if (!BufferResponse)
            {
                flag3 = true;
            }

            if (Response != null && Response.Headers != null)
            {
                if (((Response.Headers.HttpResponseCode == 0x191) &&
                     (string.Compare(Response.Headers["WWW-Authenticate"], 0, "N", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)) ||
                    ((Response.Headers.HttpResponseCode == 0x197) &&
                     (string.Compare(Response.Headers["Proxy-Authenticate"], 0, "N", 0, 1, StringComparison.OrdinalIgnoreCase) == 0)))
                {
                    flag2 = DoNTLM(0x197 == Response.Headers.HttpResponseCode);
                }
                else if (Response.ServerSocket != null)
                {
                    if (Response.Headers.ExistsAndEquals("Connection", "close") ||
                        (!Response.ServerSocket.Connected || (Response.Headers.HttpVersion != "HTTP/1.1")))
                    {
                        if (Response.ServerSocket.Connected)
                        {
                            try
                            {
                                if (Response.ServerSocket != null)
                                {
                                    Response.ServerSocket.Shutdown(SocketShutdown.Both);
                                    Response.ServerSocket.Close();
                                }
                            }
                            catch (Exception)
                            {
                            }

                            Response.ServerSocket = null;
                        }
                    }

                    Response.ServerSocket = null;
                }
            }

            if (!flag3)
            {
                if (flag)
                {
                    ReturnResponse(flag2);
                }

                /*
                 * if (!flag)
                 * {
                 *  if (Request != null)
                 *      if (Response != null)
                 *          Request.FailSession(400, "Bad Response", "Reading response failed. Response was:\n" + Response);
                 * }
                 */
            }

            if (Request != null && ((Request.ClientSocket != null) && flag3))
            {
                if (Response != null && Response.Headers != null)
                {
                    if (flag2 ||
                        (((!Response.Headers.ExistsAndEquals("Connection", "close")) &&
                          !Request.Headers.ExistsAndEquals("Connection", "close")) &&
                         ((Response.Headers.HttpVersion == "HTTP/1.1") ||
                          Response.Headers.ExistsAndContains("Connection", "Keep-Alive"))))
                    {
                        if (!flag2)
                        {
                            Thread.Sleep(0x19);
                        }

                        if (flag2 || (0 < Request.ClientSocket.Available))
                        {
                            _nextSession = flag2 ?
                                           new Session(Request.ClientSocket, Response.ServerSocket, Response.WasForwarded) :
                                           new Session(Request.ClientSocket, null, false);

                            Request.ClientSocket = null;
                            goto next;
                        }
                    }
                }

                try
                {
                    if (Request.ClientSocket != null)
                    {
                        Request.ClientSocket.Shutdown(SocketShutdown.Both);
                        Request.ClientSocket.Close();
                    }
                }
                catch (Exception)
                {
                }

                Request.ClientSocket = null;
            }

next:
            if (_nextSession != null)
            {
                _nextSession.Execute(null);
            }
        }