Beispiel #1
0
        public Match[] UpdateMatches(Match[] notSortedMatches, CancellationToken token)
        {
            if (notSortedMatches == null)
            {
                throw new ArgumentNullException("notSortedMatches был null");
            }

            DotaPageWorker dotaPageWorker  = new DotaPageWorker();
            List <Match>   matchesNew      = new List <Match>();
            Match          LastoldMatch    = notSortedMatches[0];
            bool           lastMatchloaded = false;

            while (!lastMatchloaded)
            {
                List <Match> matches = new List <Match>();
                if (!TryLoadPage(dotaPageWorker, "Страница с матчами не загружается, если ее не загрузить, то парсинг прервется", token))
                {
                    return(matches.ToArray());
                }

                string[] matchURLs = dotaPageWorker.GetMatchesURLs();
                foreach (var matchURL in matchURLs)
                {
                    if (matchURL == LastoldMatch.URL)
                    {
                        lastMatchloaded = true;
                        break;
                    }
                    DotaMatchPageWorker matchPageWorker = new DotaMatchPageWorker(matchURL);

                    matchPageWorker.AfterLoadPage += (sender, URL) =>
                    {
                        MatchPageLoaded?.Invoke(this, URL);
                    };

                    if (!TryLoadPage(matchPageWorker, "Страница с матчем не загружается", token))
                    {
                        continue;
                    }

                    matches.Add(GetMatch(matchPageWorker));
                    MatchLoaded?.Invoke(this, matchPageWorker.URL);
                }

                PageOfMatchesLoaded?.Invoke(this, dotaPageWorker.URL);


                matchesNew.AddRange(matches);
                if (dotaPageWorker.NextPage == null)
                {
                    break;
                }

                dotaPageWorker = new DotaPageWorker(dotaPageWorker.NextPage);
            }
            matchesNew.AddRange(notSortedMatches);
            return(matchesNew.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Получение матчей по определенной страницу заданной dotaPageWorker
        /// </summary>
        /// <param name="dotaPageWorker">Страница с матчами</param>
        /// <param name="token">Токен отмены</param>
        /// <returns></returns>
        private Match[] GetMatches(DotaPageWorker dotaPageWorker, CancellationToken token)
        {
            if (dotaPageWorker == null)
            {
                throw new ArgumentNullException("dotaPageWorker был пуст");
            }

            List <Match> matches = new List <Match>();

            if (!TryLoadPage(dotaPageWorker, "Страница с матчами не загружается, если ее не загрузить, то парсинг прервется", token))
            {
                return(matches.ToArray());
            }

            string[] matchURLs = dotaPageWorker.GetMatchesURLs();
            foreach (var matchURL in matchURLs)
            {
                DotaMatchPageWorker matchPageWorker = new DotaMatchPageWorker(matchURL);

                matchPageWorker.AfterLoadPage += (sender, URL) =>
                {
                    MatchPageLoaded?.Invoke(this, URL);
                };

                if (!TryLoadPage(matchPageWorker, "Страница с матчем не загружается", token))
                {
                    continue;
                }

                matches.Add(GetMatch(matchPageWorker));
                MatchLoaded?.Invoke(this, matchPageWorker.URL);
            }

            PageOfMatchesLoaded?.Invoke(this, dotaPageWorker.URL);
            return(matches.ToArray());
        }
Beispiel #3
0
        async Task ProcessAsync(HttpListenerContext ctx)
        {
            if (ctx.Request.UserAgent != "osu!")
            {
                return;
            }
            if (ctx.Request.Url.AbsolutePath.StartsWith("/web/"))
            {
                return;
            }

            if (string.IsNullOrEmpty(ctx.Request.Headers["osu-token"]))
            {
                await Login.Handle(ctx);

                return;
            }

            Player p = Global.FindPlayer(ctx.Request.Headers["osu-token"]);

            if (p == null) // if they arent part of the player collection, force them to relogin
            {
                ctx.Response.StatusCode = 403;
                ctx.Response.OutputStream.Write(Packets.Packets.SingleIntPacket(5, -5));
                ctx.Response.Close();
                return;
            }

            using (MemoryStream ms = new MemoryStream())
                using (BinaryReader r = new BinaryReader(ms))
                {
                    await ctx.Request.InputStream.CopyToAsync(ms);

                    ms.Position = 0;
                    while (ms.Position < ctx.Request.ContentLength64 - 6)
                    {
                        short Id = r.ReadInt16();
                        ms.Position += 1;
                        int Length = r.ReadInt32();
                        if (ms.Position + Length > ctx.Request.ContentLength64)
                        {
                            break;
                        }
                        if (Id == 68 || Id == 79)
                        {
                            ms.Position += Length;
                            continue;
                        }

                        byte[] Data = r.ReadBytes(Length);
                        switch (Id)
                        {
                        case 4: p.Ping = DateTime.Now.Ticks; break;

                        case 0:
                            StatusUpdate.Handle(p, Data);
                            break;

                        case 1:
                            IrcMessage.Handle(p, Data);
                            break;

                        case 2:
                            Player.RemovePlayer(p);
                            break;

                        case 3:
                            await StatsUpdateRequest.Handle(p);

                            break;

                        case 16:
                            StartSpectating.Handle(p, Data);
                            break;

                        case 17:
                            StopSpectating.Handle(p);
                            break;

                        case 18:
                            SpectatorFrames.Handle(p, Data);
                            break;

                        case 25:
                            IrcMessage.HandlePrivate(p, Data);
                            break;

                        case 29:
                            Global.LeaveLobby(p);
                            break;

                        case 30:
                            Global.JoinLobby(p);
                            break;

                        case 31:
                            CreateMatch.Handle(p, Data);
                            break;

                        case 32:
                            JoinMatch.Handle(p, Data);
                            break;

                        case 33:
                            LeaveMatch.Handle(p);
                            break;

                        case 38:
                            ChangeSlot.Handle(p, Data);
                            break;

                        case 39:
                            MatchReady.Handle(p);
                            break;

                        case 40:
                            SlotLock.Handle(p, Data);
                            break;

                        case 41:
                            MatchSettings.Handle(p, Data);
                            break;

                        case 44:
                            MatchStart.Handle(p, Data);
                            break;

                        case 49:
                            MatchFinished.Handle(p);
                            break;

                        case 51:
                            ModsChange.Handle(p, Data);
                            break;

                        case 52:
                            MatchLoaded.Handle(p);
                            break;

                        case 54:
                            NoBeatmap.Handle(p);
                            break;

                        case 55:
                            MatchReady.Handle(p);
                            break;

                        case 56:
                            MatchFailed.Handle(p);
                            break;

                        case 59:
                            HasBeatmap.Handle(p);
                            break;

                        case 60:
                            MatchSkip.Handle(p);
                            break;

                        case 63:
                            ChannelJoinEvent.Handle(p, Data);
                            break;

                        case 70:
                            ChangeHost.Handle(p, Data);
                            break;

                        case 73:
                            AddFriend.Handle(p, Data);
                            break;

                        case 74:
                            RemoveFriend.Handle(p, Data);
                            break;

                        case 77:
                            ChangeTeam.Handle(p, Data);
                            break;

                        case 78:
                            ChannelLeaveEvent.Handle(p, Data);
                            break;

                        case 85:
                            StatsUpdateRequest.Handle(p, Data);
                            break;

                        case 90:
                            MatchChangePassword.Handle(p, Data);
                            break;

                        default:
                            Log.LogFormat($"%#FFFF%Unhandled Packet {Id} with {Length}");
                            break;
                        }
                    }
                }

            if (p.StreamLength != 0)
            {
                p.StreamCopyTo(ctx.Response.OutputStream);
            }
            ctx.Response.Close();
        }