public static string GetSessionId()
        {
            string signature = SpyToolUtils.GetSignature("testsession");

            Debug.WriteLine("\nChecking current session ....");

            string requestURI         = SpyToolUtils.GetRequestURI("testsession", authParams: false, Credentials.DevId, signature, sessionInfo.session_id, GetSessionTimestamp());
            string responseFromServer = SpyToolUtils.GetServerResponse(requestURI);

            // create a new session if necessary
            if (responseFromServer == null || responseFromServer.Contains("Invalid") || responseFromServer.Contains("Exception"))
            {
                SessionInfo newSessionInfo = SpyToolUtils.CreateSession();
                Debug.WriteLine($"\nPast APISession Id was Invalid ({sessionInfo.session_id}).\nNew APISession Id is: {newSessionInfo.session_id}");
                sessionInfo = newSessionInfo;

                SaveSessionInfo();
            }
            else
            {
                Debug.WriteLine($"\n  Past APISession Id was Valid!");
            }

            return(sessionInfo.session_id);
        }
        public static string GetSessionTimestamp()
        {
            DateTime timestamp = sessionInfo.timestamp;

            // create a new session if necessary
            if (timestamp == null || timestamp == DateTime.MinValue)
            {
                SessionInfo newSessionInfo = SpyToolUtils.CreateSession();
                Debug.WriteLine($"\nPast Timestamp is Invalid ({timestamp}).\nNew Timestamp is: {newSessionInfo.timestamp}");
                sessionInfo = newSessionInfo;

                SaveSessionInfo();
            }

            return(sessionInfo.GetTimestampString());
        }
Beispiel #3
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 })));
            }
        }