Ejemplo n.º 1
0
        private void SaveTeams(ACSSAuth.DataAccess.CSSDataContext db, DataAccess.CSSStatsDataContext statsDB, ACSSAuth.Server.Data.GameDataset.GameRow gameRow, int gameIdentID)
        {
            foreach (Data.GameDataset.TeamRow teamRow in gameRow.GetTeamRows())
            {
                var commanderAlias   = DataAccess.Alias.GetAliasByCallsign(db, teamRow.Commander);
                int commanderLoginID = 0;

                if (commanderAlias != null)
                {
                    commanderLoginID = commanderAlias.Login.Id;
                }

                DataAccess.GameTeam team = new ACSSAuth.DataAccess.GameTeam()
                {
                    GameID                   = gameIdentID,
                    GameTeamCommander        = TrimString(teamRow.Commander, 49),
                    GameTeamCommanderLoginID = commanderLoginID,
                    GameTeamExpansion        = teamRow.ResearchedExpansion,
                    GameTeamFaction          = teamRow.Faction,
                    GameTeamID               = teamRow.TeamID,
                    GameTeamName             = TrimString(teamRow.TeamName, 49),
                    GameTeamNumber           = teamRow.TeamNumber,
                    GameTeamShipyard         = teamRow.ResearchedShipyard,
                    GameTeamStarbase         = teamRow.ResearchedStarbase,
                    GameTeamSupremacy        = teamRow.ResearchedSupremacy,
                    GameTeamTactical         = teamRow.ResearchedTactical,
                    GameTeamWinner           = teamRow.Won
                };

                statsDB.GameTeams.InsertOnSubmit(team);
                statsDB.SubmitChanges();

                foreach (Data.GameDataset.TeamMemberRow teamMemberRow in teamRow.GetTeamMemberRows())
                {
                    var teamMemberAlias = DataAccess.Alias.GetAliasByCallsign(db, teamMemberRow.Callsign);
                    int loginID         = 0;
                    if (teamMemberAlias != null)
                    {
                        loginID = teamMemberAlias.Login.Id;
                    }

                    DataAccess.GameTeamMember teamMember = new ACSSAuth.DataAccess.GameTeamMember()
                    {
                        GameTeamID             = team.GameTeamIdentID,
                        GameTeamMemberCallsign = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, teamMemberRow.Callsign), 49),
                        GameTeamMemberDuration = teamMemberRow.Duration,
                        GameTeamMemberLoginID  = loginID
                    };

                    statsDB.GameTeamMembers.InsertOnSubmit(teamMember);
                }

                statsDB.SubmitChanges();
            }
        }
Ejemplo n.º 2
0
        public void GetCallsignFromStringWithTokensAndTags()
        {
            string noTags          = "BackTrak";
            string withTag         = "BackTrak@BS";
            string withToken       = "?BackTrak";
            string withTagAndToken = "*BackTrak@BS";

            using (DataAccess.CSSDataContext db = new ACSSAuth.DataAccess.CSSDataContext())
            {
                Assert.AreEqual(noTags, DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, noTags));
                Assert.AreEqual(noTags, DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, withTag));
                Assert.AreEqual(noTags, DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, withToken));
                Assert.AreEqual(noTags, DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, withTagAndToken));
            }
        }
Ejemplo n.º 3
0
        private void SaveChatLog(ACSSAuth.DataAccess.CSSDataContext db, DataAccess.CSSStatsDataContext statsDB, ACSSAuth.Server.Data.GameDataset.GameRow gameRow, int gameIdentID)
        {
            foreach (Data.GameDataset.ChatLogRow chatLogRow in gameRow.GetChatLogRows())
            {
                DataAccess.GameChatLog chatLog = new ACSSAuth.DataAccess.GameChatLog()
                {
                    GameChatSpeakerName = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, chatLogRow.SpeakerName), 49),
                    GameChatTargetName  = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, chatLogRow.TargetName), 49),
                    GameChatText        = TrimString(chatLogRow.Text, 2063),
                    GameChatTime        = chatLogRow.ChatTime,
                    GameID = gameIdentID
                };

                statsDB.GameChatLogs.InsertOnSubmit(chatLog);
            }
        }
Ejemplo n.º 4
0
        private void UpdateLeaderboard(int gameIdentID)
        {
            using (DataAccess.CSSDataContext db = new ACSSAuth.DataAccess.CSSDataContext())
            {
                using (DataAccess.CSSStatsDataContext statsDB = new ACSSAuth.DataAccess.CSSStatsDataContext())
                {
                    var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                    if (game == null)
                    {
                        throw new Exception("Couldn't get game for ID: " + gameIdentID);
                    }

                    if (IsGameEligibleForLogging(game) == false)
                    {
                        return;
                    }

                    bool isDrawGame = IsDrawGame(game);

                    foreach (DataAccess.GameTeam team in game.GameTeams)
                    {
                        var commanderAlias = DataAccess.Alias.GetAliasByCallsign(db, team.GameTeamCommander);

                        foreach (DataAccess.GameTeamMember teamMember in team.GameTeamMembers)
                        {
                            int shipKills       = 0;
                            int stationKills    = 0;
                            int stationCaptures = 0;
                            int droneKills      = 0;
                            int ejects          = 0;
                            int defection       = 0;
                            int score           = 0;

                            var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.GameTeamMemberCallsign);

                            if (alias == null)
                            {
                                continue;
                            }

                            // Check current team member for defections.
                            foreach (DataAccess.GameTeam otherTeam in game.GameTeams)
                            {
                                if (otherTeam.GameTeamID == team.GameTeamID)
                                {
                                    continue;
                                }

                                foreach (DataAccess.GameTeamMember otherTeamMember in otherTeam.GameTeamMembers)
                                {
                                    var otherLogin = DataAccess.Alias.GetAliasByCallsign(db, otherTeamMember.GameTeamMemberCallsign);

                                    if (otherLogin != null && otherLogin.LoginId == alias.LoginId)
                                    {
                                        defection = 1;
                                        break;
                                    }
                                }

                                if (defection != 0)
                                {
                                    break;
                                }
                            }

                            var primaryMemberEvents = game.GameEvents.Where
                                                      (
                                p => p.GameEventPerformerID != 1
                                &&
                                (
                                    p.GameEventPerformerLoginID == alias.Login.Id &&
                                    (
                                        p.EventID == (int)AllegianceEventIDs.StationDestroyed ||
                                        p.EventID == (int)AllegianceEventIDs.StationCaptured ||
                                        p.EventID == (int)AllegianceEventIDs.ShipKilled
                                    )
                                )
                                ||
                                (
                                    p.GameEventTargetLoginID == alias.Login.Id &&
                                    p.EventID == (int)AllegianceEventIDs.ShipKilled
                                )
                                                      );

                            foreach (var primaryMemberEvent in primaryMemberEvents)
                            {
                                switch (primaryMemberEvent.EventID)
                                {
                                case (int)Common.Enumerations.AllegianceEventIDs.ShipKilled:
                                    if (primaryMemberEvent.GameEventPerformerName.StartsWith(".") == true)
                                    {
                                        droneKills++;
                                        score += DroneKillPoints;
                                    }
                                    else
                                    {
                                        if (primaryMemberEvent.GameEventPerformerLoginID == teamMember.GameTeamMemberLoginID)
                                        {
                                            ejects++;
                                        }
                                        else
                                        {
                                            shipKills++;
                                            score += ShipKillPoints;
                                        }
                                    }
                                    break;

                                case (int)Common.Enumerations.AllegianceEventIDs.StationCaptured:
                                {
                                    stationCaptures++;
                                    score += StationCapturePoints;
                                }
                                break;

                                case (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed:
                                {
                                    stationKills++;
                                    score += StationKillPoints;
                                }
                                break;
                                }
                            }

                            if (alias != null)
                            {
                                var leaderboard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == alias.Login.Id);

                                if (leaderboard == null)
                                {
                                    leaderboard = new ACSSAuth.DataAccess.StatsLeaderboard()
                                    {
                                        CommandDraws    = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandLosses   = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandMu       = 25D,
                                        CommandRank     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandSigma    = 25D / 3D,
                                        CommandWins     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Defects         = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Draws           = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DroneKills      = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Ejects          = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        HoursPlayed     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Kills           = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        LoginUsername   = alias.Login.Username,
                                        LoginID         = alias.Login.Id,
                                        Losses          = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Mu              = 25D,
                                        Rank            = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Sigma           = 25D / 3D,
                                        StackRating     = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationCaptures = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationKills    = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Wins            = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DateModified    = DateTime.Now



                                                          //CommandDraws = commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0,
                                                          //CommandLosses = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                                          //CommandMu = 25D,
                                                          //CommandRank = 0,
                                                          //CommandSigma = 25D / 3D,
                                                          //CommandWins = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                                          //Defects = defection,
                                                          //Draws = isDrawGame == true && defection == 0 ? 1 : 0,
                                                          //DroneKills = droneKills,
                                                          //Ejects = ejects,
                                                          //HoursPlayed = teamMember.GameTeamMemberDuration / 60.0 / 60.0,
                                                          //Kills = shipKills,
                                                          //LoginUsername = alias.Login.Username,
                                                          //LoginID = alias.Login.Id,
                                                          //Losses = team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                                          //Mu = 25D,
                                                          //Rank = 0,
                                                          //Sigma = 25D / 3D,
                                                          //StackRating = 0,
                                                          //StationCaptures = stationCaptures,
                                                          //StationKills = stationKills,
                                                          //Wins = team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                                          //DateModified = DateTime.Now
                                    };

                                    statsDB.StatsLeaderboards.InsertOnSubmit(leaderboard);
                                }
                                else
                                {
                                    // These values are all set by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.

                                    //leaderboard.CommandDraws += commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandLosses += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandWins += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.Defects += defection;
                                    //leaderboard.Draws += isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DroneKills += droneKills;
                                    //leaderboard.Ejects += ejects;
                                    //leaderboard.HoursPlayed += teamMember.GameTeamMemberDuration / 60.0 / 60.0;
                                    //leaderboard.Kills += shipKills;
                                    //leaderboard.Losses += team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.StationCaptures += stationCaptures;
                                    //leaderboard.StationKills += stationKills;
                                    //leaderboard.Wins += team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DateModified = DateTime.Now;
                                }

                                teamMember.Score = score;

                                statsDB.SubmitChanges();
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void SaveGameEvents(ACSSAuth.DataAccess.CSSDataContext db, DataAccess.CSSStatsDataContext statsDB, ACSSAuth.Server.Data.GameDataset.GameRow gameRow, int gameIdentID)
        {
            foreach (Data.GameDataset.GameEventRow gameEventRow in gameRow.GetGameEventRows())
            {
                int performerLoginID = 0;
                int targetLoginID    = 0;

                try
                {
                    var performerAlias = DataAccess.Alias.GetAliasByCallsign(db, gameEventRow.PerformerName);

                    if (performerAlias != null)
                    {
                        performerLoginID = performerAlias.Login.Id;
                    }

                    var targetAlias = DataAccess.Alias.GetAliasByCallsign(db, gameEventRow.TargetName);

                    if (targetAlias != null)
                    {
                        targetLoginID = targetAlias.Login.Id;
                    }

                    DataAccess.GameEvent gameEvent = new DataAccess.GameEvent()
                    {
                        GameEventTime             = gameEventRow.EventTime,
                        GameID                    = gameIdentID,
                        GameEventIndirectID       = gameEventRow.IndirectID,
                        GameEventIndirectName     = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.IndirectName), 254),
                        GameEventPerformerID      = gameEventRow.PerformerID,
                        GameEventPerformerName    = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.PerformerName), 254),
                        GameEventPerformerLoginID = performerLoginID,
                        GameEventTargetID         = gameEventRow.TargetID,
                        GameEventTargetName       = TrimString(DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.TargetName), 254),
                        GameEventTargetLoginID    = targetLoginID,
                        EventID                   = gameEventRow.EventID
                    };

                    statsDB.GameEvents.InsertOnSubmit(gameEvent);

                    statsDB.SubmitChanges();
                }
                catch (Exception ex)
                {
                    string errorDetails = String.Format(@"SaveGameEvents(): Insert error! 
		gameIdentID = {0},
		gameEventRow.EventID = {1},
		gameEventRow.EventTime = {2},
		gameEventRow.GameID = {3},
		gameEventRow.IndirectID = {4},
		gameEventRow.IndirectName = {5},
		gameEventRow.PerformerID = {6},
		gameEventRow.PerformerName = {7},
		gameEventRow.TargetID = {8},
		gameEventRow.TargetName = {9},
		performerLoginID = {10},
		targetLoginID = {11},
		DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.IndirectName) = {12},
		DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.PerformerName) = {13},
		DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.TargetName) = {14}
		===================================================
{15}
",
                                                        gameIdentID,
                                                        gameEventRow.EventID,
                                                        gameEventRow.EventTime,
                                                        gameEventRow.GameID,
                                                        gameEventRow.IndirectID,
                                                        gameEventRow.IndirectName,
                                                        gameEventRow.PerformerID,
                                                        gameEventRow.PerformerName,
                                                        gameEventRow.TargetID,
                                                        gameEventRow.TargetName,
                                                        performerLoginID,
                                                        targetLoginID,
                                                        DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.IndirectName),
                                                        DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.PerformerName),
                                                        DataAccess.Alias.GetCallsignFromStringWithTokensAndTags(db, gameEventRow.TargetName),
                                                        ex.ToString());

                    if (String.IsNullOrEmpty(Settings.Default.TagExceptionLogFileName) == false)
                    {
                        File.AppendAllText(Settings.Default.TagExceptionLogFileName, DateTime.Now.ToString() + ": " + errorDetails + "\n\n\n");
                    }
                }
            }
        }