Parse() 개인적인 메소드

private Parse ( string start, string end ) : string
start string
end string
리턴 string
예제 #1
0
        private int AddAccountsFromSource(string src)
        {
            // No accounts
            if (!src.Contains("PLAY!"))
            {
                return 0;
            }

            Parser m1 = new Parser(src);
            int serverid;
            if (!int.TryParse(m1.Parse("serverid=", "\""), out serverid))
            {
                return 0;
            }

            int ret = 0;
            foreach (
                string t in
                    m1.MultiParse("<font color=\"#FFFF00\" face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">",
                                  "PLAY!"))
            {
                Parser p = new Parser(t);
                string name = p.Parse("<b>", "</b>");
                int id;
                if (!int.TryParse(p.Parse("suid=", "&"), out id))
                {
                    continue;
                }

                Add(name, id, Server.IdToName(serverid));
                ret++;
                Last.Socket.Cookie = HttpSocket.DefaultInstance.Cookie + " ow_userid=" + id
                                     + "; ow_serverid=" + serverid;
            }
            return ret;
        }
예제 #2
0
파일: Mob.cs 프로젝트: Quintinon/outwar-dca
        internal void Initialize()
        {
            if (mInitialized)
            {
                return;
            }

            CoreUI.Instance.LogPanel.Log("Loading '" + mName + "'");

            mLoadSrc = mRoom.Mover.Socket.Get(mURL);

            if (mQuit)
            {
                return;
            }

            // Parse level and rage
            Parser mm = new Parser(mLoadSrc);
            if (!long.TryParse(mm.Parse("(Level ", ")"), out mLevel)
                || !long.TryParse(mm.Parse("Attack!</a> (<b>", " rage"), out mRage))
            {
                mQuit = true;
                return;
            }

            mInitialized = true;
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns>0 on success, 1 on hash error, 2 on key, 3 on DC broken.  4 to stop all attacking</returns>
        internal int Load()
        {
            // create url
            string url = string.Format("ajax_changeroomb.php?room={0}&lastroom={1}", Id, Mover.Location.Id);
            if (IsDoor)
            {
                url += "&door=1";
            }
            string src = Mover.Socket.Get(url);
            src = src.Replace("\\s", "s"); // Hack for new Outwar regex
            src = System.Text.RegularExpressions.Regex.Unescape(src);

            Parser p = new Parser(src);
            // TODO look how error messages changed
            if (src.Contains("Error #301"))
            {
                // hash error
                return 1;
            }
            if (src.Contains("you must be carrying") || src.Contains("cast on you to enter this room."))
            {
                // need a key
                return 2;
            }
            if (src.Contains("Rampid Gaming Login"))
            {
                // logged out
                return 4;
            }

            if (Id == 0)
            {
                // loading world.php; figure out where we are
                string tmp = Parser.Parse(src, "\"curRoom\":\"", "\"");
                int tmpid;
                if (!int.TryParse(tmp, out tmpid))
                {
                    return 3;
                }
                Id = tmpid;
            }
            Name = p.Parse("\"name\":\"", "\"");

            EnumRooms(src);

            if (Globals.AttackMode || Globals.Spidering)
            {
                EnumMobs(src);
            }
            else if (CoreUI.Instance.Settings.AutoTrain || CoreUI.Instance.Settings.AutoQuest || CoreUI.Instance.Settings.AlertQuests)
            {
                EnumMobs(src);

                if (CoreUI.Instance.Settings.AutoTrain)
                    Trained = Train();
                if (CoreUI.Instance.Settings.AutoQuest || CoreUI.Instance.Settings.AlertQuests)
                    Quest();
            }

            return 0;
        }
예제 #4
0
        internal void EnumMobs(string src)
        {
            // TODO this should really just throw an exception
            if (string.IsNullOrEmpty(src))
            {
                Load();
            }
            Mobs = new List<Mob>();

            //foreach (string s in Parser.MultiParse(src, "<table ", "</table>"))
            foreach(string s in src.Split(new string[] { "<table "}, StringSplitOptions.RemoveEmptyEntries))
            {
                Parser p = new Parser(s);

                string url = "mob.php?" + p.Parse("mob.php?", "\"");
                string name;
                string attackurl = string.Empty;
                bool trainer = false;
                bool quest = false;
                bool spawn = false;

                if (s.Contains("Spawned by"))
                {
                    name = string.Format("*{0}*", p.Parse("\">*", " ["));
                    if (name.Contains("<"))
                    {
                        // TODO this is a bandaid fix re: a bug with the parser.  It will pick up html from killed spawn mobs
                        continue;
                    }
                    spawn = true;
                    // log spawn sighting, but don't attack it if we shouldn't
                    if (Globals.AttackOn)
                    {
                        CoreUI.Instance.SpawnsPanel.Log(string.Format("{0} sighted {1} in room {2}", Mover.Account.Name, name, Id));
                        CoreUI.Instance.SpawnsPanel.Sighted(Id);
                        if (!CoreUI.Instance.Settings.AttackSpawns)
                            continue;
                    }
                }
                else
                {
                    //name = Parser.Parse(Parser.CutLeading(s, url + "\">"), "\">", " [");
                    name = Parser.Parse(s, "><b>", "</b>"); // "'<b>Spawned By:</b>" occurs, use ><b> for starting
                }

                if (s.Contains("somethingelse.php"))
                {
                    attackurl = "somethingelse.php" + p.Parse("somethingelse.php", "\"");
                }
                else
                {
                    continue;
                }

                if (s.Contains("talk_icon.jpg"))
                {
                    quest = true;
                }
                if (s.Contains("dc_trainer.gif"))
                {
                    trainer = true;
                }

                /*
                if (string.IsNullOrEmpty(attackurl) && !quest && !trainer)
                {
                    continue;
                }*/

                Mob mb = new Mob(name, url, attackurl, quest, trainer, spawn, this);
                Mobs.Add(mb);
            }
        }
예제 #5
0
파일: Account.cs 프로젝트: typpo/outwar-dca
        internal void GetStats(string source)
        {
            Parser mm = new Parser(source);

            int.TryParse(mm.Parse("<b>LEVEL:</b><span id=\"level\">", "</span>").Trim(), out mLevel);
            int.TryParse(mm.Parse(">RAGE</span>:</b><span id=\"rage\">", "</span>").Trim(), out mRage);

            long.TryParse(mm.Parse("EXP:</b><span id=\"exp\">", "</span>").Trim().Replace(",", ""), out mExp);

            long.TryParse(mm.Parse("Gold:</b></td><td>", "</td>").Trim(), out mGold);

            NeedsLevel = source.Contains("LEVEL!");
        }
예제 #6
0
        private void Run()
        {
            SetStatus("Loading open message...");
            string src =
                HttpSocket.DefaultInstance.Get("http://www.typpo.us/dctopen.txt")
                    .Replace("\n", "\r\n");

            txtMain.Text = src;

            Parser p = new Parser(src);
            CoreUI.Instance.ChatPanel.Channel = p.Parse("<chan>", "</chan>");
            CoreUI.Instance.ChatPanel.Server = p.Parse("<svr>", "</svr>");
            int tmp;
            if (int.TryParse(p.Parse("<port>", "</port>"), out tmp))
                CoreUI.Instance.ChatPanel.Port = tmp;
            else
            {
                CoreUI.Instance.ChatPanel.Port = 6667;
            }
            CoreUI.Instance.Changes = p.Parse("Change History:", "End Changes").Replace("\r", "").Trim();

            if (src.Contains("<msg>"))
            {
                MessageBox.Show(p.Parse("<msg>", "</msg>"), "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Focus();
                txtMain.SelectionLength = 0;
            }

            if (Version.Full != p.Parse("<ver>", "</ver>"))
            {
                string url = p.Parse("<url>", "</url>");

                if (url == "ERROR")
                {
                    SetStatus("Could not access server.");
                    txtMain.Text = " Could not access startup server.  If you already had map data saved on your computer, the program should work but you will not receive software or map updates automatically.";
                    MessageBox.Show(
                        "Could not read startup instructions from server.  If map data has already been saved to your computer, the program should work.\n\nIf this error persists (and you can get to www.typpo.us), please close or adjust any firewall/router/antivirus/antispyware that is blocking this program's connection to the internet.",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SetStatus("Attempting to build map data...");
                    ThreadEngine.DefaultInstance.DoParameterized(Pathfinder.BuildMap, false);
                    SetStatus("Could not contact server");
                    //Globals.Terminate = true;
                    //Application.Exit();
                    return;
                }

                SetStatus("Downloading new version...");
                try
                {
                    string local = url.Substring(url.LastIndexOf("/") + 1);
                    if (File.Exists(local))
                    {
                        SetStatus("You've already downloaded the new version, use it instead: " + local);
                    }
                    else
                    {
                        new WebClient().DownloadFile(new Uri(url), local);
                    }

                    Process.Start(local);
                    Globals.Terminate = true;
                    Application.Exit();
                    return;
                }
                catch
                {
                    MessageBox.Show("Automatic updating failed.\n\n"
                                    +
                                    "You will be directed to a manual download.  Place the file in "
                                    + Application.StartupPath,
                                    "Updating Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Process.Start(url);
                    Globals.Terminate = true;
                    Application.Exit();
                    return;
                }
            }

            string mapupdate = p.Parse("<map>", "</map>");
            if (mapupdate != "ERROR")
            {
                try
                {
                    DateTime last = DateTime.ParseExact(mapupdate, "yyyy-MM-dd HH:mm", null);

                    if (last > CoreUI.Instance.Settings.LastMapUpdate)
                    {
                        // new maps
                        SetStatus("Building latest DC maps from host site...");
                        ThreadEngine.DefaultInstance.DoParameterized(Pathfinder.BuildMap, true);
                        SetStatus("Ready with latest maps...");
                    }
                    else
                    {
                        ThreadEngine.DefaultInstance.DoParameterized(Pathfinder.BuildMap, false);
                        SetStatus("Ready...");
                    }
                }
                catch (FormatException)
                {
                    ThreadEngine.DefaultInstance.DoParameterized(Pathfinder.BuildMap, false);
                    SetStatus("Could not read new map status, update maps manually");
                }
            }
            else
            {
                ThreadEngine.DefaultInstance.DoParameterized(Pathfinder.BuildMap, false);
                SetStatus("Could not read new map status, update maps manually");
            }
        }