예제 #1
0
        private static void CheckInfoAsync(object state)
        {
            if (string.IsNullOrEmpty(AppVars.Profile.UserNick))
            {
                return;
            }

            var userInfo = NeverApi.GetAll(AppVars.Profile.UserNick);

            if (userInfo == null)
            {
                return;
            }

            var poisonAndWounds = GetPoisonAndWounds(userInfo);

            if (
                (poisonAndWounds[0] > AppVars.PoisonAndWounds[0]) ||
                (poisonAndWounds[1] > AppVars.PoisonAndWounds[1]) ||
                (poisonAndWounds[2] > AppVars.PoisonAndWounds[2]) ||
                (poisonAndWounds[3] > AppVars.PoisonAndWounds[3])
                )
            {
                AppVars.PoisonAndWounds = poisonAndWounds;
                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.BeginInvoke(
                            new ReloadMainPhpInvokeDelegate(AppVars.MainForm.ReloadMainPhpInvoke),
                            new object[] { });
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }
        }
예제 #2
0
        private static void CheckTiedAsync(object state)
        {
            AppVars.LastTied = DateTime.Now;
            var userInfo = NeverApi.GetAll(AppVars.Profile.UserNick);

            if (userInfo == null)
            {
                return;
            }

            // var effects = [[1,'Боевая травма (x9) (еще 23:06:17)'],[2,'Тяжелая травма (x2) (еще 07:01:22)'],[17,'Молчанка (еще 00:00:05)']];
            // var effects = [[24,'<b>Яд</b> (x1) (еще 04:59:46)'],[77,'<b>Новогодний бонус</b> (x1) (еще 352:52:16)']];
            // var effects = [[2,'<b>Тяжелая травма</b> (x1) (еще 12:20:22)'],[4,'<b>Легкая травма</b> (x1) (еще 01:40:48)'],[77,'<b>Новогодний бонус </ b > (x1)(еще 369:35:45)']];

            if (userInfo.EffectsCodes.Length > 0)
            {
                Array.Clear(AppVars.PoisonAndWounds, 0, AppVars.PoisonAndWounds.Length);
                for (var k = 0; k < userInfo.EffectsCodes.Length; k++)
                {
                    var effcode = userInfo.EffectsCodes[k];
                    // "2" - тяжелая
                    // "3" - средняя
                    // "4" - легкая
                    // "24" - яд

                    switch (effcode)
                    {
                    case "2":
                        AppVars.PoisonAndWounds[3]++;     // тяжелые
                        break;

                    case "3":
                        AppVars.PoisonAndWounds[2]++;     // средние
                        break;

                    case "4":
                        AppVars.PoisonAndWounds[1]++;     // легкие
                        break;

                    case "24":
                        AppVars.PoisonAndWounds[0]++;
                        break;

                    default:
                        break;
                    }
                }

                if (AppVars.PoisonAndWounds[0] > 0)
                {
                    if (DateTime.Now.Subtract(AppVars.LastMessageAboutTraumaOrPoison).TotalMinutes > 10.0)
                    {
                        AppVars.LastMessageAboutTraumaOrPoison = DateTime.Now;
                        AppVars.MainForm.WriteChatMsgSafe(
                            "У вас отравление. Почему бы не включить автолечение в настройках?");
                    }
                }
                else
                {
                    if ((AppVars.PoisonAndWounds[1] > 0) || (AppVars.PoisonAndWounds[2] > 0) ||
                        (AppVars.PoisonAndWounds[3] > 0))
                    {
                        if (DateTime.Now.Subtract(AppVars.LastMessageAboutTraumaOrPoison).TotalMinutes > 10.0)
                        {
                            AppVars.LastMessageAboutTraumaOrPoison = DateTime.Now;
                            AppVars.MainForm.WriteChatMsgSafe(
                                "У вас небоевая травма. Почему бы не включить автолечение в настройках?");
                        }
                    }
                }
            }

            var location = userInfo.Location;

            if (!string.IsNullOrEmpty(location))
            {
                var tied = userInfo.Tied;
                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.BeginInvoke(
                            new UpdateTiedDelegate(AppVars.MainForm.UpdateTied), tied);
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }
            else
            {
                /*
                 * AppVars.SwitchToPerc = true;
                 * AppVars.SwitchToFlora = true;
                 */

                var tied = AppVars.Tied + 2;
                try
                {
                    if (AppVars.MainForm != null)
                    {
                        AppVars.MainForm.BeginInvoke(
                            new UpdateTiedDelegate(AppVars.MainForm.UpdateTied), tied);
                    }
                }
                catch (InvalidOperationException)
                {
                }
            }
        }
예제 #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 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();
        }
예제 #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)
            {
            }
        }
예제 #5
0
        private static void FastAttackAsync(object stateInfo)
        {
            var ai = (AttackInfo) stateInfo;
            var nick = StripItalic(ai.TargetNick);
            var userInfo = NeverApi.GetAll(nick);
            if (userInfo == null)
            {
                if (AppVars.MainForm != null)
                    AppVars.MainForm.WriteChatMsgSafe("Ошибка анализа инфы атакуемого.");

                return;
            }

            var flog = userInfo.FightLog;
            if (flog.Equals("0", StringComparison.Ordinal))
            {
                flog = string.Empty;
            }

            if (!string.IsNullOrEmpty(flog))
            {
                var scans = 0;
                var swatch = new Stopwatch();
                swatch.Start();
                AppVars.FastWaitEndOfBoiCancel = false;
                while (!AppVars.FastWaitEndOfBoiCancel)
                {
                    AppVars.FastWaitEndOfBoiActive = true;
                    var html = NeverApi.GetFlog(flog);
                    if (string.IsNullOrEmpty(html))
                        continue;

                    scans++;

                    // var off = 1;
                    // var off = 0;

                    var off = HelperStrings.SubString(html, "var off = ", ";");
                    if (string.IsNullOrEmpty(off))
                        continue;

                    if (off.Equals("1"))
                    {
                        break;
                    }
                    
                    if (
                        (html.IndexOf("нападение бота", StringComparison.CurrentCultureIgnoreCase) == -1) &&
                        (html.IndexOf("закрытый бой", StringComparison.CurrentCultureIgnoreCase) == -1) &&
                        (html.IndexOf("закрытое нападение", StringComparison.CurrentCultureIgnoreCase) == -1) &&
                        (html.IndexOf("закрытое кулачное нападение", StringComparison.CurrentCultureIgnoreCase) == -1) &&
                        (html.IndexOf("закрытое боевое нападение", StringComparison.CurrentCultureIgnoreCase) == -1)
                        )
                    {
                        if (!AppVars.WaitOpen)
                        {
                            break;
                        }
                    }

                    if (scans == 1)
                    {
                        if (AppVars.MainForm != null)
                            AppVars.MainForm.WriteChatMsgSafe("Ожидание окончания боя (отмена: меню/быстрые действия/отмена).");
                    }
                    else
                    {
                        if ((scans%100) == 0)
                        {
                            if (AppVars.MainForm != null)
                                AppVars.MainForm.WriteChatMsgSafe(
                                    $"Ожидание окончания боя (запросов: {scans}, средн: {swatch.ElapsedMilliseconds / scans}мс)");
                        }
                    }
                }
            }

            AppVars.FastWaitEndOfBoiActive = false;

            if (AppVars.FastWaitEndOfBoiCancel)
            {
                AppVars.FastWaitEndOfBoiCancel = false;
                if (AppVars.MainForm != null) 
                    AppVars.MainForm.WriteChatMsgSafe("Ожидание окончания боя прекращено.");
            }
            else
            {
                if (AppVars.MainForm != null)
                {
                    AppVars.MainForm.FastStartSafe(ai.Weapon, nick, AppVars.DoPerenap ? int.MaxValue : 1);
                    ReloadMainFrame();
                }
            }
        }