Exemplo n.º 1
0
        public DateTime GetGameStartTime()
        {
            try
            {
                using (SmartWebClient client = new SmartWebClient(30000))
                {
                    // Proxy
                    client.Proxy = client.GetDefaulProxy();


                    string token = client.DownloadString(
                        String.Format("{0}/consumer/{1}/{2}/{3}/token", this.Server + "/observer-mode/rest",
                                      "getGameMetaData",
                                      Region,
                                      GameId));
                    GameMetaData gd    = JsonConvert.DeserializeObject <GameMetaData>(token);
                    DateTime     start = TimeZoneInfo.ConvertTime(DateTime.Parse(gd.startTime), TimeZoneInfo.FindSystemTimeZoneById(TimeZones[Region]), TimeZoneInfo.Local);
                    //       TimeSpan ts = new TimeSpan(gd.gameLength * TimeSpan.TicksPerSecond);

                    //  DateTime starttime = DateTime.Now.Subtract(ts);

                    return(start);
                }
            }



            catch
            {
            }
            return(DateTime.Now);
        }
Exemplo n.º 2
0
        void GetChunk()
        {
            using (SmartWebClient client = new SmartWebClient(30000))
            {
                // Proxy
                client.Proxy = client.GetDefaulProxy();
                // token

                //string token = client.DownloadString(
                //    String.Format("{0}/consumer/{1}/{2}/{3}/0/token", Server + "/observer-mode/rest",
                //    "getLastChunkInfo",
                //    Region,
                //    GameId));

                ChunkInfo ci = JsonConvert.DeserializeObject <ChunkInfo>(client.DownloadString(
                                                                             String.Format("{0}/consumer/{1}/{2}/{3}/0/token", Server + "/observer-mode/rest",
                                                                                           "getLastChunkInfo",
                                                                                           Region,
                                                                                           GameId)));

                int ChunkId = ci.chunkId;

                if (ChunkId == 0)
                {
                    //Try get chunk once avaliable
                    return;
                }

                // Save Replay
                if (LastChunkNumber == ChunkId)
                {
                    SaveReplay(client, ChunkId);
                    return;
                }

                //Get keyframe
                if (ChunkId % 2 == 0)
                {
                    int KeyFrameId = ci.keyFrameId;
                    if (KeyFrameId != 0)
                    {
                        DownloadKey(client, KeyFrameId);
                    }
                }

                // Get Current Chunk
                if (Recording)
                {
                    DownloadChunk(client, ChunkId);
                }

                LastChunkNumber = ChunkId;


                // Recover MISSING
                RecoverMissing(client, ci);

                Thread.Sleep(ci.nextAvailableChunk);
            }
        }
Exemplo n.º 3
0
        public ReplayRecorder(string Server, long GameId, string Region, string Key, GhostReplay rep)
        {
            try
            {
                this.DownloadTasks = new List <DownloadTask>();
                this.GameId        = GameId;
                this.Region        = Region;
                CurrentReplay      = rep;
                Recording          = true;

                if (Directory.Exists(rep.CacheDirectory))
                {
                    File.WriteAllText(rep.CacheDirectory + @"\cache.dat", Key);
                    if (!string.IsNullOrEmpty(rep.SummonerName))
                    {
                        File.WriteAllText(rep.CacheDirectory + @"\summoner.dat", rep.SummonerName);
                    }
                }

                if (!Server.StartsWith("127.0.0.1:90"))
                {
                    this.Server = "http://" + Server;

                    rep.ObserverKey = Key;

                    int ChunkTimeInterval;
                    int LastChunk = 0;
                    using (SmartWebClient client = new SmartWebClient(30000))
                    {
                        // Proxy
                        client.Proxy = client.GetDefaulProxy();
                        // Version
                        rep.Version = client.DownloadString(String.Format("{0}/consumer/version", this.Server + "/observer-mode/rest"));
                        // Token
                        string token = client.DownloadString(String.Format("{0}/consumer/{1}/{2}/{3}/token", this.Server + "/observer-mode/rest", "getGameMetaData", Region, GameId));

                        GameMetaData meta = JsonConvert.DeserializeObject <GameMetaData>(token);
                        ChunkTimeInterval = meta.chunkTimeInterval;
                        LastChunk         = meta.endStartupChunkId;
                    }

                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        while (Recording)
                        {
                            try
                            {
                                GetChunk();
                                RetryAttempt = 0;
                            }
                            catch (Exception ex)
                            {
                                RetryAttempt++;
                                if (OnProblemOccured != null)
                                {
                                    OnProblemOccured(this, EventArgs.Empty);
                                }

                                if (RetryAttempt >= 10 && OnFailedToRecord != null)
                                {
                                    Recording = false;
                                    OnFailedToRecord(ex);
                                }
                                else
                                {
                                    Thread.Sleep(15000);
                                }
                                if (RetryAttempt == 1)
                                {
                                    Logger.Instance.Log.Error("Failed to record [GET CHUNK]", ex);
                                }
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                if (OnFailedToRecord != null)
                {
                    OnFailedToRecord(ex);
                }
                Logger.Instance.Log.Error("Failed to record [GLOBAL]", ex);
                Recording = false;
            }
        }