/// <summary> /// Helper function to update <see cref="PlayerSessionToMissionSession"/> data in the database /// </summary> /// <param name="pstmsDAO">DAO for <see cref="PlayerSessionToMissionSession"/>s</param> /// <param name="missionSession">The current <see cref="MissionSession"/></param> /// <param name="playerSessions">The current set of <see cref="PlayerSession"/>s</param> private void UpdatePTSTMTSData(PlayerSessionToMissionSessionDAO pstmsDAO, MissionSession missionSession, ISet<PlayerSession> playerSessions) { ISet<PlayerSessionToMissionSession> pstmses = pstmsDAO.GetOrCreatePSTMS(missionSession, playerSessions); foreach (PlayerSessionToMissionSession pstms in pstmses) { pstms.Updated = true; pstms.Length += (Settings.Default.pollRate / 1000); if (pstms.Played == false && CheckPlayedThreshold(pstms.Length)) { pstms.Played = true; } } pstmsDAO.UpdatePSTMS(pstmses); }
/// <summary> /// Build DAOs if we need to build DAOs /// </summary> /// <param name="connection">the current <see cref="MySqlConnection"/></param> /// <param name="playerDAO">DAO for <see cref="Player"/>s</param> /// <param name="missionDAO">DAO for <see cref="Mission"/>s</param> /// <param name="sessionDAO">DAO for <see cref="Session"/>s</param> /// <param name="pstmsDAO">DAO for <see cref="PlayerSessionToMissionSession"/>s</param> private void BuildDAOsIfNeeded(ref MySqlConnection connection, ref PlayerDAO playerDAO, ref MissionDAO missionDAO, ref SessionDAO sessionDAO, ref PlayerSessionToMissionSessionDAO pstmsDAO) { if (connection == null || connection.State == ConnectionState.Closed) { connection = DatabaseUtil.OpenDataSource(); playerDAO = new PlayerDAO(connection); missionDAO = new MissionDAO(connection); sessionDAO = new SessionDAO(connection); pstmsDAO = new PlayerSessionToMissionSessionDAO(connection); } }
/// <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; }