private static string GetInfo(string url) { string html = null; using (var wc = new CookieAwareWebClient { Proxy = AppVars.LocalProxy }) { try { IdleManager.AddActivity(); var buffer = wc.DownloadData(url); if (buffer != null) { html = AppVars.Codepage.GetString(buffer); if (html.IndexOf("Cookie...", StringComparison.CurrentCultureIgnoreCase) != -1) { buffer = wc.DownloadData(url); if (buffer != null) { html = AppVars.Codepage.GetString(buffer); } } } } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } finally { IdleManager.RemoveActivity(); } } return(html); }
private static void RoomAsync(object stateInfo) { while (!_doStop) { if (AppVars.DoShowWalkers) { try { IdleManager.AddActivity(); var wr = (HttpWebRequest)WebRequest.Create("http://neverlands.ru/ch.php?lo=1&"); wr.Method = "GET"; wr.Proxy = AppVars.LocalProxy; var cookies = CookiesManager.Obtain("www.neverlands.ru"); wr.Headers.Add("Cookie", cookies); var resp = wr.GetResponse(); var webstream = resp.GetResponseStream(); if (webstream != null) { using (var reader = new StreamReader(webstream, AppVars.Codepage)) { var responseFromServer = reader.ReadToEnd(); { var ssum = HelperStrings.SubString(responseFromServer, "</b></font></a> [ ", " ]"); var slist = HelperStrings.SubString(responseFromServer, "var ChatListU = new Array(", ");"); var newRoom = $"[{ssum}] {slist}"; if (string.Compare(newRoom, _oldRoom, StringComparison.Ordinal) != 0) { Process(responseFromServer); _oldRoom = newRoom; try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new ReloadChPhpInvokeDelegate(AppVars.MainForm.ReloadChPhpInvoke), new object[] {}); } } catch (InvalidOperationException) { } } } } } } catch (WebException) { } catch (IOException) { } finally { IdleManager.RemoveActivity(); } } Event.WaitOne(100, false); } }
internal void Process(string html) { var currentTimeStamp = DateTime.Now; if (string.IsNullOrEmpty(html)) { return; } var params0 = HelperStrings.SubString(html, "var params = [[", "],"); if (string.IsNullOrEmpty(params0)) { return; } var hpmp = HelperStrings.SubString(html, "var hpmp = [", "]"); if (string.IsNullOrEmpty(hpmp)) { return; } var spar1 = HelperStrings.ParseArguments(hpmp); if (spar1.Length < 5) { return; } var stied = spar1[4]; int tied; if (int.TryParse(stied, out tied)) { tied = 100 - tied; } var slots = HelperStrings.SubString(html, "var slots = ['", "'];"); if (string.IsNullOrEmpty(slots)) { return; } var pslots = slots.Split('@'); if (pslots.Length < 16) { return; } var isKa = false; var sslots = new StringBuilder(); for (var indexSlot = 0; indexSlot < pslots.Length; indexSlot++) { if ((indexSlot != 0) && (indexSlot != 1) && (indexSlot != 2) && (indexSlot != 3) && (indexSlot != 7) && (indexSlot != 10) && (indexSlot != 11) && (indexSlot != 12) && (indexSlot != 13) && (indexSlot != 14) && (indexSlot != 15)) { continue; } var ps = pslots[indexSlot].Split(':'); if (ps.Length != 3) { sslots.Append('-'); } else { var thingImage = ps[0]; if (!isKa) { var tl = ThingsDb.Find(thingImage); if (tl.Count == 0) { isKa = true; } } sslots.Append(thingImage); } sslots.Append('@'); } if (sslots.Length == 0) { return; } sslots.Length--; var spar0 = HelperStrings.ParseArguments(params0); if (spar0.Length < 9) { return; } var nick = spar0[0].Trim(); var align = spar0[1]; var sign = spar0[2]; var level = spar0[3]; var location = spar0[5]; var isonline = !string.IsNullOrEmpty(location); var flog = spar0[7]; if (flog.Equals("0", StringComparison.Ordinal)) { flog = string.Empty; } var clan = spar0[8]; var woundCounts = 0; var wounds = new int[4]; var isMolch = false; var codeEffects = new List <string>(); var nameEffects = new List <string>(); // var effects = [[1,'Боевая травма (x9) (еще 23:06:17)'],[2,'Тяжелая травма (x2) (еще 07:01:22)'],[17,'Молчанка (еще 00:00:05)']]; 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( @" <img src=http://image.neverlands.ru/pinfo/eff_{0}.gif width=15 height=15 align=absmiddle title=""{1}"">", effcode, effname); var effcountstr = HelperStrings.SubString(effname, "(x", ")"); int effcount = 0; if (!string.IsNullOrEmpty(effcountstr)) { int.TryParse(effcountstr, out effcount); } switch (effcode) { case "1": woundCounts += effcount; wounds[3] = effcount; break; case "2": woundCounts += effcount; wounds[2] = effcount; break; case "3": woundCounts += effcount; wounds[1] = effcount; break; case "4": woundCounts += effcount; wounds[0] = effcount; break; case "17": isMolch = true; break; default: codeEffects.Add(effcode); var pos = effname.IndexOf(" (", StringComparison.Ordinal); var ename = (pos >= 0 ? effname.Substring(0, pos) : effname).Trim('\''); nameEffects.Add(ename); break; } } } var splocation = location.Split(new[] { " [" }, StringSplitOptions.RemoveEmptyEntries); if (splocation.Length == 2) { splocation[1] = splocation[1].Substring(0, splocation[1].Length - 1); if ((splocation[1].IndexOf(splocation[0], StringComparison.OrdinalIgnoreCase) != -1) || splocation[1].Contains(",")) { location = splocation[1]; } } Name = nick; Level = level; Align = align; Sign = sign; Clan = clan; var sb = new StringBuilder(); var messagePrefix = HtmlContactEntry(this) /* + sbeff*/; // Вход/выход if (!_isFirst && IsOnline != isonline) { if (sb.Length > 0) { sb.Append(','); } if (isonline) { sb.AppendFormat(@" появляется в <font color=""#3F7F62"">{0}</font>", location); } else { sb.AppendFormat( isKa ? @" исчезает в <font color=""#3F7F62"">{0}</font>" : @" выходит из игры в <font color=""#3F7F62"">{0}</font>", Location); } } // Переодевания if (ClassId != 2) { if (!_isFirst) { var sbp = new StringBuilder(); var changes = 0; if (pslots != null && PSlots != null && pslots.Length == PSlots.Length) { for (var i = 0; i < pslots.Length; i++) { var opars = PSlots[i].Split(':'); if (opars.Length < 2) { continue; } var npars = pslots[i].Split(':'); if (npars.Length < 2) { continue; } var oimage = opars[0]; var nimage = npars[0]; var oname = opars[1]; var nname = npars[1]; if (oimage.Equals(nimage, StringComparison.CurrentCultureIgnoreCase) && oname.Equals(nname, StringComparison.CurrentCultureIgnoreCase)) { continue; } sbp.Append(sbp.Length > 0 ? ", " : " "); if (nimage.StartsWith("sl_")) { sbp.Append("снимает"); sbp.Append(" «"); sbp.Append(oname); } else { sbp.Append("одевает"); sbp.Append(" «"); sbp.Append(nname); } sbp.Append("»"); changes++; } } if (sbp.Length > 0) { if (sb.Length > 0) { sb.Append(','); } sb.Append(changes > 3 ? " переодевается" : sbp.ToString()); } } } // Изменение усталости if (ClassId != 2) { if (!_isFirst && isonline && IsOnline && Location != location && !string.IsNullOrEmpty(location)) { if (sb.Length > 0) { sb.Append(','); } if (Tied != tied) { sb.AppendFormat(@" усталость <b>{0}</b> в <font color=""#3F7F62"">{1}</font>", tied, location); } else { sb.AppendFormat(@" переходит в <font color=""#3F7F62"">{0}</font>", location); } } else { if (!_isFirst && isonline && IsOnline && Location == location && Tied < tied && !string.IsNullOrEmpty(location)) { if (sb.Length > 0) { sb.Append(','); } sb.AppendFormat(@" усталость {0}→<b>{1}</b> в <font color=""#3F7F62"">{2}</font>", Tied, tied, location); } } } // Вступление в бой if (!_isFirst && isonline && ((string.IsNullOrEmpty(Flog) && !string.IsNullOrEmpty(flog)) || (!string.IsNullOrEmpty(Flog) && !string.IsNullOrEmpty(flog) && !Flog.Equals(flog, StringComparison.Ordinal)))) { IsBotLog = false; var wc = new WebClient { Proxy = AppVars.LocalProxy }; byte[] bufferLog = null; try { IdleManager.AddActivity(); bufferLog = wc.DownloadData("http://www.neverlands.ru/logs.fcg?fid=" + flog); } catch (Exception ex) { Debug.Print(ex.Message); } finally { wc.Dispose(); IdleManager.RemoveActivity(); } // var logs = [[1387615150,6],[[0,"12:39"],"Бой между",[4,1]," и",[1,2,"*Трогвар*",22,1,"c138"]," начался (закрытое боевое нападение) (21.12.2013 12:39:10)."]]; // var logs = [[1387626458,6],[[0,"15:47"],"Бой между",[4,1]," и",[1,2,"~Shtaket~",18,3,"c167"]," начался (боевое нападение) (21.12.2013 15:47:38)."],[[0,"15:47"],[1,1,"Ruber",22,1,"necr"]," <B>вмешался в бой.</B>"],[[0,"15:49"],[1,1,"_NickName_",22,1,"glow"]," использовал заклинание <img src=http://image.neverlands.ru/signs/darks.gif width=15 height=12 border=0 align=absmiddle> «<B>Темное нападение</B>» и вмешался в бой.</B>"],[[0,"15:49"],[1,2,"~Shtaket~",18,3,"c167"]," получил осложненную травму <font color=#E34242><b>«Множественные повреждения основания свода черепа»</b></font>."],[[0,"15:49"],"<B>Бой закончен по таймауту</B> (",[4,1]," )."],[[0,"15:49"],"<B>Победа за</B>",[4,1],",",[1,1,"_NickName_",22,1,"glow"],",",[1,1,"Ruber",22,1,"necr"],"."]]; if (bufferLog != null) { var fight = Russian.Codepage.GetString(bufferLog); if ((fight.IndexOf("(нападение бота)", StringComparison.OrdinalIgnoreCase) != -1) || (fight.IndexOf("var logs = [];", StringComparison.OrdinalIgnoreCase) != -1)) { IsBotLog = true; } if (!IsBotLog) { if (sb.Length > 0) { sb.Append(','); } var fighttype = HelperStrings.SubString(fight, " начался (", ")") ?? "обычное нападение"; if (fight.IndexOf("Бой (жертвенный)", StringComparison.OrdinalIgnoreCase) != -1) { fighttype = "жертвенный бой"; } var livesg1 = HelperStrings.SubString(fight, "var lives_g1 = [", "];"); if (!string.IsNullOrEmpty(livesg1)) { var pars = livesg1.Split(','); var nick1 = (pars.Length > 2) && !livesg1.StartsWith("[4") ? pars[1].Trim(new[] { '"' }) : "невидимка"; var livesg2 = HelperStrings.SubString(fight, "var lives_g2 = [", "];"); if (!string.IsNullOrEmpty(livesg2)) { pars = livesg2.Split(','); var nick2 = (pars.Length > 2) && !livesg2.StartsWith("[4") ? pars[1].Trim(new[] { '"' }) : "невидимка"; if (livesg2.IndexOf(Name, StringComparison.Ordinal) == -1) { // нападает на перса nick2 sb.AppendFormat( @" <a href=http://www.neverlands.ru/logs.fcg?fid={0} onclick=""window.open(this.href);"">нападает</a> на {1} ({2})", flog, HtmlPercEntry(nick2), fighttype); } else { if (nick1.Equals("невидимка", StringComparison.OrdinalIgnoreCase)) { // на меня напал невидимка sb.AppendFormat( @" <a href=http://www.neverlands.ru/logs.fcg?fid={0} onclick=""window.open(this.href);"">атакован</a> невидимкой ({1})", flog, fighttype); } else { // на меня напал перс nick1 sb.AppendFormat( @" <a href=http://www.neverlands.ru/logs.fcg?fid={0} onclick=""window.open(this.href);"">атакован</a> {1} ({2})", flog, HtmlPercEntry(nick1), fighttype); } } } } } } } // Получение молчанки if (!_isFirst && IsMolch != isMolch) { if (sb.Length > 0) { sb.Append(','); } sb.AppendFormat(isMolch ? " получает молчанку" : " выходит из молчания"); } // Травмы if (!_isFirst && (WoundCounts > 0) && (woundCounts == 0)) { if (sb.Length > 0) { sb.Append(','); } sb.AppendFormat(" излечивается от всех травм"); } // Травмы if (!_isFirst && (WoundCounts > 0) && (woundCounts > 0) && (woundCounts < WoundCounts)) { if (sb.Length > 0) { sb.Append(','); } sb.AppendFormat(" излечивается (травм стало: {0})", woundCounts); } // Травмы if (!_isFirst && (woundCounts > WoundCounts)) { if (sb.Length > 0) { sb.Append(','); } if ((woundCounts - WoundCounts) > 1) { sb.AppendFormat(" получает несколько травм"); } else { string wound = "никакую"; if (wounds[3] > Wounds[3]) { wound = "боевую"; } else { if (wounds[2] > Wounds[2]) { wound = "тяжелую"; } else { if (wounds[1] > Wounds[1]) { wound = "среднюю"; } else { if (wounds[0] > Wounds[0]) { wound = "легкую"; } } } } sb.AppendFormat(" получает {0} травму (травм стало: {1})", wound, woundCounts); } } // Эффекты if (ClassId != 2) { if (!_isFirst) { var sbadd = new StringBuilder(); for (var i = 0; i < codeEffects.Count; i++) { if (Array.IndexOf(CodeEffects, codeEffects[i]) < 0) { if (sbadd.Length == 0) { sbadd.Append(" получает"); } sbadd.Append( $" <img src=http://image.neverlands.ru/pinfo/eff_{codeEffects[i]}.gif width=15 height=15 align=absmiddle title=\"{nameEffects[i]}\"> {nameEffects[i]}"); } } if (sbadd.Length > 0) { if (sb.Length > 0) { sb.Append(','); } sb.Append(sbadd); } var sbrem = new StringBuilder(); for (var i = 0; i < CodeEffects.Length; i++) { if (!codeEffects.Contains(CodeEffects[i])) { if (sbrem.Length == 0) { sbrem.Append(" теряет"); } sbrem.Append( $" <img src=http://image.neverlands.ru/pinfo/eff_{CodeEffects[i]}.gif width=15 height=15 align=absmiddle title=\"{NameEffects[i]}\"> {NameEffects[i]}"); } } if (sbrem.Length > 0) { if (sb.Length > 0) { sb.Append(','); } sb.Append(sbrem); } } } NameEffects = nameEffects.ToArray(); CodeEffects = codeEffects.ToArray(); IsOnline = isonline; Location = location; Tied = tied; Flog = flog; PSlots = pslots; IsMolch = isMolch; WoundCounts = woundCounts; Wounds = wounds; _isFirst = false; if (sb.Length > 0) { _delay = 0; var message = messagePrefix + sb; if (currentTimeStamp > LastUpdated) { LastUpdated = currentTimeStamp; try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateChatDelegate(AppVars.MainForm.UpdateChat), new object[] { message }); } } catch (InvalidOperationException) { } } } else { _delay += Dice.Make(1, 1000); if (_delay > 10000) { _delay = 10000; } } if (!IsOnline) { if (ClassId != 2) { _delay = 60000; } } NextCheck = DateTime.Now.AddMilliseconds(_delay); try { if (AppVars.MainForm != null) { AppVars.MainForm.BeginInvoke( new UpdateContactDelegate(AppVars.MainForm.UpdateContact), new object[] { this }); } } catch (InvalidOperationException) { } }