Esempio n. 1
0
        /// <summary>
        /// Helper method to create a new session
        /// </summary>
        /// <param name="serverInfoService">service to get info from an A3 server</param>
        /// <param name="sessionDAO">DAO for sessions</param>
        /// <param name="host">A3 server host</param>
        /// <param name="port">A3 server port</param>
        /// <param name="inGame">Boolean to check if the server is currently in game</param>
        /// <returns>The new session</returns>
        private Session SetUpSession(ServerInfoService serverInfoService, SessionDAO sessionDAO, string host, int port, ref bool inGame)
        {
            Session returnSession = null;

            // initial info grab
            ServerInfo serverInfo = serverInfoService.GetServerInfo(host, port);

            inGame = CheckServerRunningState(serverInfo.ServerState);

            if (inGame)
            {
                // create a session
                Session session = new Session();
                session.HostName   = serverInfo.HostName;
                session.Version    = serverInfo.GameVersion;
                session.MaxPing    = serverInfo.Ping;
                session.MinPing    = serverInfo.Ping;
                session.MaxPlayers = serverInfo.NumPlayers;
                session            = sessionDAO.CreateSession(session);

                returnSession = session;
            }

            return(returnSession);
        }
Esempio n. 2
0
        /// <summary>
        /// Begins reporting on a session, should handle DAOs here
        /// </summary>
        public void StartReporting()
        {
            // define DAO objects to interact with databases
            MySqlConnection connection = null;
            PlayerDAO       playerDAO  = null;
            MissionDAO      missionDAO = null;
            SessionDAO      sessionDAO = null;

            try {
                // create DAO objects to interact with databases
                BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO);

                ServerInfoService serverInfoService = new ServerInfoService();

                // variables needed to track session playthough
                Session        session = null;
                MissionSession currentMissionSession = null;
                ISet <PlayerMissionSession> currentPlayersToMissionSession = new HashSet <PlayerMissionSession>();
                int  missionCount = 0;
                bool inGame       = false;

                Stopwatch runTime = new Stopwatch();
                runTime.Start();
                try {
                    while (session == null && CheckTimeThreshold(runTime.ElapsedMilliseconds))
                    {
                        try {
                            _logger.Debug("Trying to set up session");
                            session = SetUpSession(serverInfoService, sessionDAO, Settings.Default.armaServerAddress,
                                                   Settings.Default.armaServerPort, ref inGame);
                        } catch (MySqlException e) {
                            _logger.Error("Problem setting up session: ", e);
                            BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO);
                        }
                        Thread.Sleep(Settings.Default.pollRate);
                    }

                    while (CheckMissionThreshold(missionCount, inGame) && CheckTimeThreshold(runTime.ElapsedMilliseconds))
                    {
                        try {
                            _logger.Debug("Trying to update session details");
                            ServerInfo serverInfo = serverInfoService.GetServerInfo(Settings.Default.armaServerAddress, Settings.Default.armaServerPort);
                            inGame = CheckServerRunningState(serverInfo.ServerState);

                            if (inGame)
                            {
                                if (session.MaxPing < serverInfo.Ping)
                                {
                                    session.MaxPing = serverInfo.Ping;
                                }
                                else if (session.MinPing > serverInfo.Ping)
                                {
                                    session.MinPing = serverInfo.Ping;
                                }

                                if (session.MaxPlayers < serverInfo.Players.Count)
                                {
                                    session.MaxPlayers = serverInfo.Players.Count;
                                }

                                MissionSession missionSession = missionDAO.GetOrCreateMissionSession(serverInfo.MapName, serverInfo.Mission, session);
                                if (currentMissionSession != null && currentMissionSession.Id != missionSession.Id)   // handle case where missions changed between polls
                                {
                                    sessionDAO.UpdateSession(session);
                                    missionDAO.UpdateMissionSession(currentMissionSession);
                                    playerDAO.UpdatePlayerMissionSessions(currentPlayersToMissionSession);

                                    currentPlayersToMissionSession.Clear();
                                }

                                missionSession.Length += (Settings.Default.pollRate / 1000);
                                if (missionSession.Played == false && CheckPlayedThreshold(missionSession.Length))
                                {
                                    missionSession.Played = true;
                                    missionCount++;
                                }

                                currentMissionSession = missionSession;

                                ISet <PlayerMissionSession> playersToMissionSession = playerDAO.GetOrCreatePlayerMissionSessions(serverInfo.Players, missionSession);

                                foreach (PlayerMissionSession playerToMissionSession in playersToMissionSession)
                                {
                                    playerToMissionSession.Length += (Settings.Default.pollRate / 1000);
                                    if (playerToMissionSession.Played == false && CheckPlayedThreshold(playerToMissionSession.Length))
                                    {
                                        playerToMissionSession.Played = true;
                                    }
                                }

                                currentPlayersToMissionSession.UnionWith(playersToMissionSession);
                            }
                            else if (currentMissionSession != null)
                            {
                                sessionDAO.UpdateSession(session);
                                missionDAO.UpdateMissionSession(currentMissionSession);
                                playerDAO.UpdatePlayerMissionSessions(currentPlayersToMissionSession);

                                currentMissionSession = null;
                                currentPlayersToMissionSession.Clear();
                            }
                        } catch (MySqlException e) {
                            _logger.Error("Problem updating session details: ", e);
                            BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO);
                        }
                        Thread.Sleep(Settings.Default.pollRate);
                    }
                } catch (NoServerInfoException nsie) {
                    _logger.Error("Error reporting", nsie);
                }
            }
            finally {
                // Ensure disposable objects are disposed
                if (playerDAO != null)
                {
                    playerDAO.Dispose();
                }
                if (missionDAO != null)
                {
                    missionDAO.Dispose();
                }
                if (sessionDAO != null)
                {
                    sessionDAO.Dispose();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Helper method to update the session info
 /// </summary>
 /// <param name="serverInfoService">service to get info from an A3 server</param>
 /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param>
 /// <param name="playerDAO">DAO for <see cref="Player"/>s</param>
 /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param>
 /// <param name="host">A3 server host</param>
 /// <param name="port">A3 server port</param>
 /// <param name="session">The current game <see cref="Session"/></param>
 /// <param name="missionCount">The number of missions played</param>
 /// <param name="inGame">Boolean to check if the server is currently in game</param>
 /// <returns>The current mission session</returns>
 private Session UpdateInfo(ServerInfoService serverInfoService, SessionDAO sessionDAO, PlayerDAO playerDAO, MissionDAO missionDAO,
                            string host, int port, Session session, ref int missionCount, ref bool inGame)
 {
     return(session);
 }
        /// <summary>
        /// Begins reporting on a session, should handle DAOs here
        /// </summary>
        public void StartReporting() {
            // define DAO objects to interact with databases
            MySqlConnection connection = null;
            PlayerDAO playerDAO = null;
            MissionDAO missionDAO = null;
            SessionDAO sessionDAO = null;
            PlayerSessionToMissionSessionDAO pstmsDAO = null;

            try {
                // create DAO objects to interact with databases
                BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO, ref pstmsDAO);

                ServerInfoService serverInfoService = new ServerInfoService();

                // variables needed to track session playthough
                Session session = null;
                int missionCount = 0;
                bool inGame = false;

                Stopwatch runTime = new Stopwatch();
                runTime.Start();
                try {
                    while (session == null && CheckTimeThreshold(runTime.ElapsedMilliseconds)) {
                        try {
                            _logger.Debug("Trying to set up session");
                            session = SetUpSession(serverInfoService, sessionDAO, Settings.Default.armaServerAddress,
                                                   Settings.Default.armaServerPort, ref inGame);
                        } catch (MySqlException e) {
                            _logger.Error("Problem setting up session: ", e);
                            BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO, ref pstmsDAO);
                        }
                        Thread.Sleep(Settings.Default.pollRate);
                    }

                    while (CheckMissionThreshold(missionCount, inGame) && CheckTimeThreshold(runTime.ElapsedMilliseconds)) {
                        try {
                            _logger.Debug("Trying to update session details");
                            session = UpdateInfo(serverInfoService, sessionDAO, playerDAO, missionDAO, pstmsDAO,
                                                 Settings.Default.armaServerAddress, Settings.Default.armaServerPort,
                                                 session, ref missionCount, ref inGame);
                        } catch (MySqlException e) {
                            _logger.Error("Problem updating session details: ", e);
                            BuildDAOsIfNeeded(ref connection, ref playerDAO, ref missionDAO, ref sessionDAO, ref pstmsDAO);
                        }
                        Thread.Sleep(Settings.Default.pollRate);
                    }
                } catch (NoServerInfoException nsie) {
                    _logger.Error("Error reporting", nsie);
                }
            }
            finally {
                // Ensure disposable objects are disposed
                if (connection != null) {
                    connection.Dispose();
                }
                if (playerDAO != null) {
                    playerDAO.Dispose();
                }
                if (missionDAO != null) {
                    missionDAO.Dispose();
                }
                if (sessionDAO != null) {
                    sessionDAO.Dispose();
                }
                if (pstmsDAO != null) {
                    pstmsDAO.Dispose();
                }
            }
        }
 /// <summary>
 /// Helper method to update the session info
 /// </summary>
 /// <param name="serverInfoService">service to get info from an A3 server</param>
 /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param>
 /// <param name="playerDAO">DAO for <see cref="Player"/>s</param>
 /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param>
 /// <param name="pstmsDAO">DAO for <see cref="PlayerSessionToMissionSession"/>s</param>
 /// <param name="host">A3 server host</param>
 /// <param name="port">A3 server port</param>
 /// <param name="session">The current game <see cref="Session"/></param>
 /// <param name="missionCount">The number of missions played</param>
 /// <param name="inGame">Boolean to check if the server is currently in game</param>
 /// <returns>The current mission session</returns>
 private Session UpdateInfo(ServerInfoService serverInfoService, SessionDAO sessionDAO, PlayerDAO playerDAO, MissionDAO missionDAO, PlayerSessionToMissionSessionDAO pstmsDAO,
                            string host, int port, Session session, ref int missionCount, ref bool inGame) {
     ServerInfo serverInfo = serverInfoService.GetServerInfo(host, port);
     inGame = CheckServerRunningState(serverInfo.ServerState);
     if (inGame) {
         UpdateSessionData(sessionDAO, session, serverInfo);
         MissionSession missionSession = UpdateMissionData(missionDAO, session, serverInfo, ref missionCount);
         ISet<PlayerSession> playerSessions = UpdatePlayerData(playerDAO, session, serverInfo, missionSession);
         UpdatePTSTMTSData(pstmsDAO, missionSession, playerSessions);
     }
     return session;
 }
        /// <summary>
        /// Helper method to create a new session
        /// </summary>
        /// <param name="serverInfoService">service to get info from an A3 server</param>
        /// <param name="sessionDAO">DAO for sessions</param>
        /// <param name="host">A3 server host</param>
        /// <param name="port">A3 server port</param>
        /// <param name="inGame">Boolean to check if the server is currently in game</param>
        /// <returns>The new session</returns>
        private Session SetUpSession(ServerInfoService serverInfoService, SessionDAO sessionDAO, string host, int port, ref bool inGame) {
            Session returnSession = null;

            // initial info grab
            ServerInfo serverInfo = serverInfoService.GetServerInfo(host, port);
            inGame = CheckServerRunningState(serverInfo.ServerState);

            if (inGame) {
                // create a session
                Session session = new Session();
                session.HostName = serverInfo.HostName;
                session.Version = serverInfo.GameVersion;
                session.MaxPing = serverInfo.Ping;
                session.MinPing = serverInfo.Ping;
                session.MaxPlayers = serverInfo.NumPlayers;
                session = sessionDAO.CreateSession(session);

                returnSession = session;
            }

            return returnSession;
        }