예제 #1
0
        public ActionResult Results(string username, string platform, string gamemode, string minutesBehind)
        {
            // TEMP vvv
            ViewBag.Message = JsonConvert.SerializeObject(new { username, platform, gamemode, minutesBehind });
            // TEMP ^^^

            try
            {
                bool testFromMem = false;
                List <MatchPlayer> matchPlayers = new List <MatchPlayer>();
                if (testFromMem)
                {
                    //// save to disk for later testing : TESTING ONLY
                    //responseFromServer = SpyToolUtils.GetServerResponse(requestURI);
                    //string path = Server.MapPath("~/Logs/TestMatchPlayerDetails.txt");
                    //if (!System.IO.File.Exists(path))
                    //{
                    //    Debug.WriteLine("Could not find TestMatchPlayerDetails file to save to");
                    //}
                    //else
                    //{
                    //    System.IO.File.WriteAllText(path, responseFromServer);
                    //}

                    // Load from disk : TESTING
                    string path = Server.MapPath("~/Logs/TestMatchPlayerDetails.txt");
                    //List<MatchPlayer> matchPlayers = new List<MatchPlayer>();

                    if (!System.IO.File.Exists(path))
                    {
                        Debug.WriteLine($"Could not find credentials file to load from ({path})");
                    }
                    else
                    {
                        string jsonPlayerInfo = System.IO.File.ReadAllText(path);

                        matchPlayers = JsonConvert.DeserializeObject <List <MatchPlayer> >(jsonPlayerInfo);

                        return(View(matchPlayers));
                    }
                }

                // validate access to API
                string requestURI         = SpyToolUtils.GetRequestURI("ping");
                string responseFromServer = SpyToolUtils.GetServerResponse(requestURI);
                if (responseFromServer == null)
                {
                    // ERROR Server is down
                    Debug.WriteLine($"\n   ERROR: Ping to server was unsuccesful");
                    return(View());
                }
                Debug.WriteLine($"\n{responseFromServer}");

                // Load previous session info from memory
                APISession.LoadSessionInfo();
                Debug.WriteLine($"\nSessionInfo in Memory: \n  RetMsg = {APISession.sessionInfo.ret_msg} \n  SessionId = {APISession.sessionInfo.session_id} \n  Timestamp = {APISession.sessionInfo.timestamp}");

                // Find Player from username/portal input
                Portal portal;
                Enum.TryParse <Portal>(platform, out portal);
                //Player player = SpyToolUtils.GetPlayer(portal.GetId(), username);
                DetailPlayer player = SpyToolUtils.GetPlayer(portal.GetId(), username);
                Debug.WriteLine($"\n  Username: {username}\n  Player ID: {player.Id}");

                // TEMP vvv
                string id = player.Id;
                ViewBag.Message = JsonConvert.SerializeObject(new { username, id });
                // TEMP ^^^

                // Retrieve all current matches modified by (NOW - minnutesBehind)
                Gamemode mode;
                Enum.TryParse <Gamemode>(gamemode, out mode);
                List <string> activeMatchIds = SpyToolUtils.GetActiveMatchIds(mode, minutesSinceMatchStart: int.Parse(minutesBehind));

                // Find match that Player is in
                string matchId = SpyToolUtils.FindMatchIdByPlayerId(player.Id, activeMatchIds);

                if (matchId == null)
                {
                    Debug.WriteLine("\nCould not find player's match.");
                }
                else
                {
                    Debug.WriteLine($"\nFound Match! Match ID: {matchId}");
                }

                // Request Match Details of Found Match
                requestURI         = SpyToolUtils.GetRequestURI("getmatchplayerdetails", authParams: true, matchId);
                responseFromServer = SpyToolUtils.GetServerResponse(requestURI);

                /*List<MatchPlayer>*/
                matchPlayers = JsonConvert.DeserializeObject <List <MatchPlayer> >(responseFromServer);

                return(View(matchPlayers));
            }
            catch (Exception e)
            {
                return(Redirect(Url.Action("Index", "Error", new { error = e.Message })));
            }
        }