Ejemplo n.º 1
0
        CorralEvent PostToAction(Post post)
        {
            String       actor      = post.Poster.Name;
            CorralAction verb       = CorralAction.NoAction;
            String       target     = "no target";
            String       parameter  = "no parameter";
            String       title      = post.Title;
            String       msg        = post.Content.Trim();
            Int32        id         = post.PostId;
            Int32        postNumber = post.PostNumber;

            foreach (Bold b in post.Bolded)
            {
                String content = b.Content.Trim().ToLower();
                String shoot   = "shoot ";
                if (content.StartsWith(shoot))
                {
                    target = content.Substring(shoot.Length).Trim();
                    verb   = CorralAction.Shoot;
                    break;
                }
            }
            CorralEvent ga = new CorralEvent(actor, verb, target, parameter, post.Time, title, msg, id, postNumber);

            return(ga);
        }
Ejemplo n.º 2
0
        CorralEvent PMToAction(PrivateMessage pm)
        {
            String       actor      = pm.From;
            CorralAction verb       = CorralAction.NoAction;
            String       target     = "no target";
            String       parameter  = "no parameter";
            String       title      = pm.Title;
            String       msg        = pm.Content.Trim();
            Int32        id         = pm.Id;
            Int32        postNumber = 0;
            Match        m          = Regex.Match(msg, @"(\w+)\s+(.*)", RegexOptions.Singleline);

            // action: arm, unarm, shoot, trade suit, steal suit, steal gun
            if (m.Success)
            {
                String action = m.Groups[1].Value.ToLower();
                String rem    = m.Groups[2].Value.Trim();
                switch (action)
                {
                case "arm":
                {
                    verb      = CorralAction.Arm;
                    parameter = TrimLead(rem, "with");
                }
                break;

                case "unarm":
                {
                    verb = CorralAction.UnArm;
                }
                break;

                case "shoot":
                {
                    target = rem;
                    verb   = CorralAction.Shoot;
                    Console.WriteLine("shooting '{0}'", target);
                }
                break;

                case "trade":
                {
                    rem    = TrimLead(rem, "suit");
                    target = TrimLead(rem, "with");
                    verb   = CorralAction.Trade;
                }
                break;

                case "steal":
                {
                    parameter = ParseFirstWord(ref rem);
                    target    = TrimLead(rem, "from");
                    verb      = CorralAction.Steal;
                }
                break;

                case "toss":
                {
                    parameter = TrimLead(rem, "gun");
                    verb      = CorralAction.Toss;
                }
                break;

                default:
                {
                    Console.WriteLine("unknown action '{0}'", action);
                }
                break;
                }
            }
            CorralEvent ga = new CorralEvent(actor, verb, target, parameter, pm.TimeStamp.Value, title, msg, id, postNumber);

            return(ga);
        }
Ejemplo n.º 3
0
        void PollPostsPMs()
        {
            List <PrivateMessage> pms = new List <PrivateMessage>();

            _posts.Clear();
            _readingPosts = true;
            _thread.ReadPages(_url, _pageStart, Int32.MaxValue, null);
            _forum.CheckPMs(0, 1, null, (folderpage, errMessage, cookie) =>
            {
                for (int i = 0; i < folderpage.MessagesThisPage; i++)
                {
                    PMHeader header = folderpage[i];
                    if ((_minTime <= header.Timestamp) && (_maxTime >= header.Timestamp) && (header.Id > _lastPMProcessed))
                    {
                        _forum.ReadPM(header.Id, null, (id, pm, cake) =>
                        {
                            pms.Add(pm);
                        });
                    }
                }
            }
                            );
            while (_readingPosts)
            {
                System.Threading.Thread.Sleep(50);
            }
            String             msg     = String.Empty;
            List <CorralEvent> actions = new List <CorralEvent>();
            Int32 lastPost             = 0;

            foreach (var post in _posts)
            {
                if (post.PostNumber <= _lastPostProcessed)
                {
                    continue;
                }
                if ((post.Time < _minTime) || (post.Time > _maxTime))
                {
                    continue;
                }
                msg     += String.Format("{0} {1}:\r{2}", post.Time, post.Poster.Name, post.Content);
                lastPost = Math.Max(lastPost, post.PostNumber);
                CorralEvent action = PostToAction(post);
                actions.Add(action);
            }
            if (lastPost > _lastPostProcessed)
            {
                _lastPostProcessed = lastPost;
            }
            Int32 lastPMId = 0;

            foreach (var pm in pms)
            {
                if (pm.Id <= _lastPMProcessed)
                {
                    continue;
                }
                msg     += String.Format("{0} {1}: {2}\r{3}", pm.TimeStamp, pm.From, pm.Title, pm.Content);
                lastPMId = Math.Max(lastPMId, pm.Id);
                CorralEvent action = PMToAction(pm);
                actions.Add(action);
            }
            if (lastPMId > _lastPMProcessed)
            {
                _lastPMProcessed = lastPMId;
            }
            actions.Sort((x, y) =>
            {
                int rc = x.TimeStamp.CompareTo(y.TimeStamp);
                if (rc == 0)
                {
                    // same timestamp.
                    rc = x.Action.CompareTo(y.Action);
                    if (rc == 0)
                    {
                        rc = x.Id.CompareTo(y.Id);
                    }
                }
                return(rc);
            });
            CorralEvents oActions = new CorralEvents(actions);

            try
            {
                OnPlayerActions(oActions);
            }
            catch (Exception)
            {
                // don't sweat it. Writing clients is hard.
            }
        }