예제 #1
0
        private int GetRankAdjustment(CSSStatsDataContext statsDB, int playerLevel, int levelDifference, bool winner)
        {
            int returnValue = 0;

            var experianceExchange = statsDB.ExperianceExchanges.FirstOrDefault(p => p.LevelDiffMin == 0 && p.LevelDiffMax == 0);

            foreach (var currExperianceExchange in statsDB.ExperianceExchanges)
            {
                if (Math.Abs(levelDifference) >= currExperianceExchange.LevelDiffMin && Math.Abs(levelDifference) <= currExperianceExchange.LevelDiffMax)
                {
                    experianceExchange = currExperianceExchange;
                    break;
                }
            }

            if (winner)
            {
                // The player's level was greater than the opposition's level.
                if (levelDifference >= 0)
                {
                    returnValue = experianceExchange.HigherWin;
                }
                else if (levelDifference < 0)
                {
                    returnValue = experianceExchange.LowerWin;
                }

                foreach (var winFactor in statsDB.WinFactors)
                {
                    if (playerLevel >= winFactor.MinLevel && playerLevel <= winFactor.MaxLevel)
                    {
                        returnValue = (int)Math.Floor(((double)returnValue * ((double)winFactor.Factor / 100.0)));
                        break;
                    }
                }
            }
            else
            {
                // The player's level was greater than the opposition's level.
                if (levelDifference >= 0)
                {
                    returnValue = experianceExchange.HigherLoss;
                }
                else if (levelDifference < 0)
                {
                    returnValue = experianceExchange.LowerLoss;
                }

                foreach (var lossFactor in statsDB.LossFactors)
                {
                    if (playerLevel >= lossFactor.MinLevel && playerLevel <= lossFactor.MaxLevel)
                    {
                        returnValue = (int)Math.Floor(((double)returnValue * (double)lossFactor.Factor / 100.0));
                        break;
                    }
                }
            }

            return(returnValue);
        }
        private void BindData()
        {
            using (var db = new CSSStatsDataContext())
            {
                var game = db.Games.Where(p => p.GameIdentID == GameIdentID);
                gvGame.DataSource = game;
                gvGame.DataBind();

                var teams = db.GameTeams.Where(p => p.GameID == GameIdentID);
                rptTeams.DataSource = teams;
                rptTeams.DataBind();

                var chatLog = db.GameChatLogs
                              .Where(p => p.GameID == GameIdentID)
                              .OrderBy(p => p.GameChatTime)
                              .Select(p => new
                {
                    Time    = p.GameChatTime,
                    Speaker = p.GameChatSpeakerName,
                    Target  = p.GameChatTargetName,
                    Text    = p.GameChatText
                });

                gvChatLog.DataSource = chatLog;
                gvChatLog.DataBind();
            }
        }
        private void BindData()
        {
            using (var db = new CSSStatsDataContext())
            {
                var game = db.Games.Where(p => p.GameIdentID == GameIdentID);
                gvGame.DataSource = game;
                gvGame.DataBind();

                var teams = db.GameTeams.Where(p => p.GameID == GameIdentID);
                rptTeams.DataSource = teams;
                rptTeams.DataBind();

                var chatLog = db.GameChatLogs
                    .Where(p => p.GameID == GameIdentID)
                    .OrderBy(p => p.GameChatTime)
                    .Select(p => new
                    {
                        Time = p.GameChatTime,
                        Speaker = p.GameChatSpeakerName,
                        Target = p.GameChatTargetName,
                        Text = p.GameChatText
                    });

                gvChatLog.DataSource = chatLog;
                gvChatLog.DataBind();
            }
        }
        public LoadPlayerDataResponse(LoadPlayerDataRequest playerData)
        {
            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                using (CSSDataContext db = new CSSDataContext())
                {
                    var login = Login.FindLoginByUsernameOrCallsign(db, playerData.LoginUsername);

                    if (login == null)
                    {
                        Succeeded = false;
                        ErrorMessage = "Couldn't find player's login user id.";
                        return;
                    }

                    ScoreQueue scoreQueue = statsDB.ScoreQueues.FirstOrDefault(p => p.LoginId == login.Id && p.GameGuid == playerData.GameGuid);

                    if (scoreQueue == null)
                    {
                        statsDB.ScoreQueues.InsertOnSubmit(new ScoreQueue()
                        {
                            LoginId = login.Id,
                            GameGuid = playerData.GameGuid,
                            Score = playerData.Score,
                            PilotBaseKills = playerData.PilotBaseKills,
                            PilotBaseCaptures = playerData.PilotBaseCaptures,
                            WarpsSpotted = playerData.WarpsSpotted,
                            AsteroidsSpotted = playerData.AsteroidsSpotted,
                            MinerKills = playerData.MinerKills,
                            BuilderKills = playerData.BuilderKills,
                            LayerKills = playerData.LayerKills,
                            CarrierKills = playerData.CarrierKills,
                            PlayerKills = playerData.PlayerKills,
                            BaseKills = playerData.BaseKills,
                            BaseCaptures = playerData.BaseCaptures,
                            TechsRecovered = playerData.TechsRecovered,
                            Flags = playerData.Flags,
                            Artifacts = playerData.Artifacts,
                            Rescues = playerData.Rescues,
                            Kills = playerData.Kills,
                            Assists = playerData.Assists,
                            Deaths = playerData.Deaths,
                            Ejections = playerData.Ejections,
                            Win = playerData.Win,
                            Lose = playerData.Lose,
                            CommandWin = playerData.CommandWin,
                            CommandLose = playerData.CommandLose,
                            TimePlayed = playerData.TimePlayed,
                            TimeCommanded = playerData.TimeCommanded,
                            CommandCredit = playerData.CommandCredit,
                            CombatRating = playerData.CombatRating
                        });
                    }

                    statsDB.SubmitChanges();
                }
            }

            this.Succeeded = true;
        }
예제 #5
0
        private int GetLevelDifference(CSSStatsDataContext statsDB, int playerXp, int opposingXp)
        {
            int returnValue   = 0;
            int playerLevel   = GetLevel(statsDB, playerXp);
            int opposingLevel = GetLevel(statsDB, opposingXp);

            returnValue = playerLevel - opposingLevel;

            return(returnValue);
        }
예제 #6
0
        private int GetXp(CSSStatsDataContext statsDB, GameTeamMember gameTeamMember)
        {
            var leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == gameTeamMember.GameTeamMemberLoginID);

            if (leaderBoard != null)
            {
                return(leaderBoard.Xp);
            }

            return(0);
        }
예제 #7
0
        private int GetLevel(CSSStatsDataContext statsDB, int playerXp)
        {
            var level = statsDB.Levels.FirstOrDefault(p => p.MinXP <= playerXp && p.MaxXP >= playerXp);

            if (level == null)
            {
                return(0);
            }

            return(level.Level1);
        }
예제 #8
0
        private int GetAverageXp(CSSStatsDataContext statsDB, List <GameTeamMember> commanders)
        {
            if (commanders.Count == 0)
            {
                return(0);
            }

            int xpTotal = 0;

            foreach (var commander in commanders)
            {
                xpTotal += GetXp(statsDB, commander);
            }

            return((int)Math.Floor(xpTotal / (decimal)commanders.Count));
        }
예제 #9
0
        public static List <StatsLeaderboard> GetSortedLeaderboard(CSSStatsDataContext statsDB)
        {
            List <StatsLeaderboard> sortedLeaderboard = statsDB.StatsLeaderboards
                                                        .Where(p => p.DateModified > DateTime.Now.AddDays(-7))
                                                        .OrderByDescending(p => p.Rank)
                                                        .ToList();

            int counter = 1;

            foreach (var entry in sortedLeaderboard)
            {
                entry.Order = counter;
                entry.Place = counter;
                counter++;
            }

            //Select((p, index) => new StatsLeaderboard()
            //{
            //    Order = index + 1,
            //    Place = index + 1,
            //    Callsign = p.LoginUsername,
            //    Mu = p.Mu.ToString("F2"),
            //    Sigma = p.Sigma.ToString("F2"),
            //    Rank = p.Rank.ToString("F1"),
            //    Wins = p.Wins,
            //    Losses = p.Losses,
            //    Draws = p.Draws,
            //    Defects = p.Defects,
            //    StackRating = p.StackRating.ToString("F2"),
            //    CommandMu = p.CommandMu.ToString("F2"),
            //    CommandSigma = p.CommandSigma.ToString("F2"),
            //    CommandRank = p.CommandRank.ToString("F1"),
            //    CommandWins = p.CommandWins,
            //    CommandLosses = p.CommandLosses,
            //    CommandDraws = p.CommandDraws,
            //    Kills = p.Kills,
            //    Ejects = p.Ejects,
            //    DroneKills = p.DroneKills,
            //    StationKills = p.StationKills,
            //    StationCaptures = p.StationCaptures,
            //    HoursPlayed = Math.Round(p.HoursPlayed, 2)
            //}).ToList();


            return(sortedLeaderboard);
        }
예제 #10
0
        public static RankDetail GetRankForCallsign(CSSDataContext db, string callsign)
        {
            RankDetail rankDetail = new RankDetail();
            int?       loginID    = null;

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

            // Get the oldest login from the alias for ranking.
            if (alias != null)
            {
                loginID = alias.Login.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Id;
            }

            if (loginID != null)
            {
                using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
                {
                    var stats = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == loginID.GetValueOrDefault(0));

                    if (stats != null)
                    {
                        double rank  = stats.Rank;
                        double sigma = stats.Sigma;
                        double mu    = stats.Mu;

                        // mask the user's rank if they are logging in as ACS and they are in a pilot role.
                        if (Char.IsLetter(callsign[0]) == true && callsign.EndsWith("@acs", StringComparison.InvariantCultureIgnoreCase) == true)
                        {
                            rank  = 8;
                            mu    = 32.85;
                            sigma = 6.54;
                        }

                        rankDetail.Rank         = rank;
                        rankDetail.Sigma        = sigma;
                        rankDetail.Mu           = mu;
                        rankDetail.CommandRank  = stats.CommandRank;
                        rankDetail.CommandSigma = stats.CommandSigma;
                        rankDetail.CommandMu    = stats.CommandMu;
                    }
                }
            }

            return(rankDetail);
        }
예제 #11
0
        private void SetXp(CSSStatsDataContext statsDB, GameTeamMember gameTeamMember, int totalPlayerXpAdjustment)
        {
            var leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == gameTeamMember.GameTeamMemberLoginID);

            if (leaderBoard != null)
            {
                leaderBoard.Xp += totalPlayerXpAdjustment;
                if (leaderBoard.Xp < 0)
                {
                    leaderBoard.Xp = 0;
                }

                var level = statsDB.Levels.FirstOrDefault(p => p.MinXP <= leaderBoard.Xp && p.MaxXP >= leaderBoard.Xp);
                leaderBoard.PRank = level.Level1;

                statsDB.SubmitChanges();
            }
        }
        private void BindData()
        {
            if (String.IsNullOrEmpty(txtSearch.Text) == true)
            {
                txtSearch.Text = Request.Params["searchText"];
            }

            string searchText = txtSearch.Text;

            if (searchText.Contains("%") == false)
            {
                searchText = "%" + searchText + "%";
            }

            using (var db = new CSSStatsDataContext())
            {
                var games = db.Games
                            .Where(p => searchText.Length == 0 ||
                                   db.GameChatLogs
                                   .Where(
                                       r => r.GameChatTime > DateTime.Now.AddMonths(-3)
                                       &&
                                       (
                                           SqlMethods.Like(r.GameChatText, searchText) ||
                                           SqlMethods.Like(r.GameChatSpeakerName, searchText) ||
                                           SqlMethods.Like(r.GameChatTargetName, searchText)
                                       )
                                       )
                                   .Select(r => r.GameID)
                                   .Contains(p.GameIdentID))
                            .Join(db.GameServers, p => p.GameServer, r => r.GameServerID, (p, r) => new
                {
                    GameID        = p.GameID,
                    GameServer    = r.GameServerName,
                    GameName      = p.GameName,
                    GameStartTime = p.GameStartTime,                                     //.ToString("mm/dd/yy HH:MM")
                    GameIdentID   = p.GameIdentID
                })
                            .OrderByDescending(p => p.GameStartTime);

                gvGames.DataSource = games;
                gvGames.DataBind();
            }
        }
        protected void rptTeams_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataAccess.GameTeam gameTeam = (DataAccess.GameTeam)e.Item.DataItem;

            var gvTeam = (GridView) e.Item.FindControl("gvTeam");

            using (var db = new CSSStatsDataContext())
            {
                var teamMembers = db.GameTeamMembers
                    .Where(p => p.GameTeamID == gameTeam.GameTeamIdentID)
                    .Select(p => new
                    {
                        Callsign = p.GameTeamMemberCallsign,
                        Time = string.Format("{0:hh\\:mm\\:ss}", new TimeSpan(0, 0, p.GameTeamMemberDuration))
                    });

                gvTeam.DataSource = teamMembers;
                gvTeam.DataBind();
            }
        }
        protected void rptTeams_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataAccess.GameTeam gameTeam = (DataAccess.GameTeam)e.Item.DataItem;

            var gvTeam = (GridView)e.Item.FindControl("gvTeam");

            using (var db = new CSSStatsDataContext())
            {
                var teamMembers = db.GameTeamMembers
                                  .Where(p => p.GameTeamID == gameTeam.GameTeamIdentID)
                                  .Select(p => new
                {
                    Callsign = p.GameTeamMemberCallsign,
                    Time     = string.Format("{0:hh\\:mm\\:ss}", new TimeSpan(0, 0, p.GameTeamMemberDuration))
                });

                gvTeam.DataSource = teamMembers;
                gvTeam.DataBind();
            }
        }
        private void BindData()
        {
            if (String.IsNullOrEmpty(txtSearch.Text) == true)
                txtSearch.Text = Request.Params["searchText"];

            string searchText = txtSearch.Text;
            if (searchText.Contains("%") == false)
                searchText = "%" + searchText + "%";

            using (var db = new CSSStatsDataContext())
            {
                var games = db.Games
                    .Where(p => searchText.Length == 0 ||
                            db.GameChatLogs
                                .Where(
                                            r => r.GameChatTime > DateTime.Now.AddMonths(-3)
                                            &&
                                                (
                                                    SqlMethods.Like(r.GameChatText, searchText)
                                                    || SqlMethods.Like(r.GameChatSpeakerName, searchText)
                                                    || SqlMethods.Like(r.GameChatTargetName, searchText)
                                                )
                                        )
                                .Select(r => r.GameID)
                            .Contains(p.GameIdentID))
                    .Join(db.GameServers, p => p.GameServer, r => r.GameServerID, (p, r) => new
                        {
                            GameID = p.GameID,
                            GameServer = r.GameServerName,
                            GameName = p.GameName,
                            GameStartTime = p.GameStartTime, //.ToString("mm/dd/yy HH:MM")
                            GameIdentID = p.GameIdentID
                        })
                    .OrderByDescending(p => p.GameStartTime);

                gvGames.DataSource = games;
                gvGames.DataBind();
            }
        }
        private void SetXp(CSSStatsDataContext statsDB, GameTeamMember gameTeamMember, int totalPlayerXpAdjustment)
        {
            var leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == gameTeamMember.GameTeamMemberLoginID);
            if (leaderBoard != null)
            {
                leaderBoard.Xp += totalPlayerXpAdjustment;
                if (leaderBoard.Xp < 0)
                    leaderBoard.Xp = 0;

                var level = statsDB.Levels.FirstOrDefault(p => p.MinXP <= leaderBoard.Xp && p.MaxXP >= leaderBoard.Xp);
                leaderBoard.PRank = level.Level1;

                statsDB.SubmitChanges();
            }
        }
예제 #17
0
        public LoadPlayerDataResponse(LoadPlayerDataRequest playerData)
        {
            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                using (CSSDataContext db = new CSSDataContext())
                {
                    var login = Login.FindLoginByUsernameOrCallsign(db, playerData.LoginUsername);

                    if (login == null)
                    {
                        Succeeded    = false;
                        ErrorMessage = "Couldn't find player's login user id.";
                        return;
                    }

                    ScoreQueue scoreQueue = statsDB.ScoreQueues.FirstOrDefault(p => p.LoginId == login.Id && p.GameGuid == playerData.GameGuid);

                    if (scoreQueue == null)
                    {
                        statsDB.ScoreQueues.InsertOnSubmit(new ScoreQueue()
                        {
                            LoginId           = login.Id,
                            GameGuid          = playerData.GameGuid,
                            Score             = playerData.Score,
                            PilotBaseKills    = playerData.PilotBaseKills,
                            PilotBaseCaptures = playerData.PilotBaseCaptures,
                            WarpsSpotted      = playerData.WarpsSpotted,
                            AsteroidsSpotted  = playerData.AsteroidsSpotted,
                            MinerKills        = playerData.MinerKills,
                            BuilderKills      = playerData.BuilderKills,
                            LayerKills        = playerData.LayerKills,
                            CarrierKills      = playerData.CarrierKills,
                            PlayerKills       = playerData.PlayerKills,
                            BaseKills         = playerData.BaseKills,
                            BaseCaptures      = playerData.BaseCaptures,
                            TechsRecovered    = playerData.TechsRecovered,
                            Flags             = playerData.Flags,
                            Artifacts         = playerData.Artifacts,
                            Rescues           = playerData.Rescues,
                            Kills             = playerData.Kills,
                            Assists           = playerData.Assists,
                            Deaths            = playerData.Deaths,
                            Ejections         = playerData.Ejections,
                            Win           = playerData.Win,
                            Lose          = playerData.Lose,
                            CommandWin    = playerData.CommandWin,
                            CommandLose   = playerData.CommandLose,
                            TimePlayed    = playerData.TimePlayed,
                            TimeCommanded = playerData.TimeCommanded,
                            CommandCredit = playerData.CommandCredit,
                            CombatRating  = playerData.CombatRating
                        });
                    }



                    statsDB.SubmitChanges();
                }
            }

            this.Succeeded = true;
        }
        public static RankDetail GetRankForCallsign(CSSDataContext db, string callsign)
        {
            RankDetail rankDetail = new RankDetail();
            int? loginID = null;

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

            // Get the oldest login from the alias for ranking.
            if (alias != null)
                loginID = alias.Login.Identity.Logins.OrderBy(p => p.DateCreated).FirstOrDefault().Id;

            if (loginID != null)
            {
                using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
                {
                    var stats = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == loginID.GetValueOrDefault(0));

                    if (stats != null)
                    {
                        double rank = stats.Rank;
                        double sigma = stats.Sigma;
                        double mu = stats.Mu;

                        // mask the user's rank if they are logging in as ACS and they are in a pilot role.
                        if (Char.IsLetter(callsign[0]) == true && callsign.EndsWith("@acs", StringComparison.InvariantCultureIgnoreCase) == true)
                        {
                            rank = 8;
                            mu = 32.85;
                            sigma = 6.54;
                        }

                        rankDetail.Rank = rank;
                        rankDetail.Sigma = sigma;
                        rankDetail.Mu = mu;
                        rankDetail.CommandRank = stats.CommandRank;
                        rankDetail.CommandSigma = stats.CommandSigma;
                        rankDetail.CommandMu = stats.CommandMu;
                    }
                }
            }

            return rankDetail;
        }
예제 #19
0
 private bool IsPlayerIsValidToScore(CSSStatsDataContext statsDB, Game game, GameTeamMember gameTeamMember)
 {
     return(gameTeamMember.GameTeamMemberDuration >= 300);
 }
        private void InsertTestData(CSSDataContext db)
        {
            //Create test user
            CreateUser("Orion", "Test", "Test", 10);
            CreateUser("BackTrak", "Test", "Test", 20);
            CreateUser("TheBored", "Test", "Test", 30);

            for (int i = 0; i < 30; i++)
                CreateUser("TestPilot" + i, "Test", "Test", i * 6);

            //Create a tranform method
            db.TransformMethods.InsertOnSubmit(new TransformMethod()
            { Text = "int len = rand.Next(189, 350); for (int i = rand.Next(15, 35); i < len; i += 2) sb.Append((char)rand.Next(48, 122));" });

            //Create session statuses
            db.SessionStatus.InsertOnSubmit(new SessionStatus() { Id = 1, Name = "Pending Verification" });
            db.SessionStatus.InsertOnSubmit(new SessionStatus() { Id = 2, Name = "Active" });
            db.SessionStatus.InsertOnSubmit(new SessionStatus() { Id = 3, Name = "Closed" });

            //Create Roles
            db.Roles.InsertOnSubmit(new Role() { Id = (int)RoleType.SuperAdministrator, Name = RoleType.SuperAdministrator.ToString() });
            db.Roles.InsertOnSubmit(new Role() { Id = (int)RoleType.Administrator, Name = RoleType.Administrator.ToString() });
            db.Roles.InsertOnSubmit(new Role() { Id = (int)RoleType.Moderator, Name = RoleType.Moderator.ToString() });
            db.Roles.InsertOnSubmit(new Role() { Id = (int)RoleType.ZoneLeader, Name = RoleType.ZoneLeader.ToString() });
            db.Roles.InsertOnSubmit(new Role() { Id = (int)RoleType.User, Name = RoleType.User.ToString() });

            //Create lobby
            db.Lobbies.InsertOnSubmit(new Lobby() { Name = "Production", IsRestrictive = false, IsEnabled = true, BasePath = "test", Host = "test.alleg.net" });

            // Create GroupRole
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = '*', Name="Squad Leader" });
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = '^', Name="Assistant Squad Leader" });
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = '+', Name="Zone Lead" });
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = '$', Name="Developer" });
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = '?', Name = "Help Desk" });
            db.GroupRoles.InsertOnSubmit(new GroupRole() { Token = null, Name="Pilot" });

            // Add localhost game servers
            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                var gameServer = new DataAccess.GameServer() { GameServerName = "Test Server", GameServerOwnerName = "BackTrak" };
                statsDB.GameServers.InsertOnSubmit(gameServer);

                //db.GameServerIPs.InsertOnSubmit(new GameServerIP() { GameServer = gameServer, GameServerID = gameServer.GameServerID, IPAddress = "127.0.0.1" });
                statsDB.GameServerIPs.InsertOnSubmit(new GameServerIP() { GameServer = gameServer, IPAddress = "127.0.0.1" });

                statsDB.SubmitChanges();
            }

            //foreach(string name in Enum.GetNames(typeof(DataAccess.Enumerations.LinkedItemType)))
            //{
            //    db.LinkedItemTypes.InsertOnSubmit(new LinkedItemType()
            //    {
            //        Id = (int) Enum.Parse(typeof(DataAccess.Enumerations.LinkedItemType), name),
            //        Name = name
            //    });
            //}

            LoadTestMachineRecords();

            LoadTestMachineExclusions();

            LoadTestVirtualMachineMarkers();
        }
        private void InsertTestData(CSSDataContext db)
        {
            //Create test user
            CreateUser("Orion", "Test", "Test", 10);
            CreateUser("BackTrak", "Test", "Test", 20);
            CreateUser("TheBored", "Test", "Test", 30);

            for (int i = 0; i < 30; i++)
            {
                CreateUser("TestPilot" + i, "Test", "Test", i * 6);
            }


            //Create a tranform method
            db.TransformMethods.InsertOnSubmit(new TransformMethod()
            {
                Text = "int len = rand.Next(189, 350); for (int i = rand.Next(15, 35); i < len; i += 2) sb.Append((char)rand.Next(48, 122));"
            });

            //Create session statuses
            db.SessionStatus.InsertOnSubmit(new SessionStatus()
            {
                Id = 1, Name = "Pending Verification"
            });
            db.SessionStatus.InsertOnSubmit(new SessionStatus()
            {
                Id = 2, Name = "Active"
            });
            db.SessionStatus.InsertOnSubmit(new SessionStatus()
            {
                Id = 3, Name = "Closed"
            });

            //Create Roles
            db.Roles.InsertOnSubmit(new Role()
            {
                Id = (int)RoleType.SuperAdministrator, Name = RoleType.SuperAdministrator.ToString()
            });
            db.Roles.InsertOnSubmit(new Role()
            {
                Id = (int)RoleType.Administrator, Name = RoleType.Administrator.ToString()
            });
            db.Roles.InsertOnSubmit(new Role()
            {
                Id = (int)RoleType.Moderator, Name = RoleType.Moderator.ToString()
            });
            db.Roles.InsertOnSubmit(new Role()
            {
                Id = (int)RoleType.ZoneLeader, Name = RoleType.ZoneLeader.ToString()
            });
            db.Roles.InsertOnSubmit(new Role()
            {
                Id = (int)RoleType.User, Name = RoleType.User.ToString()
            });

            //Create lobby
            db.Lobbies.InsertOnSubmit(new Lobby()
            {
                Name = "Production", IsRestrictive = false, IsEnabled = true, BasePath = "test", Host = "test.alleg.net"
            });

            // Create GroupRole
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = '*', Name = "Squad Leader"
            });
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = '^', Name = "Assistant Squad Leader"
            });
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = '+', Name = "Zone Lead"
            });
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = '$', Name = "Developer"
            });
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = '?', Name = "Help Desk"
            });
            db.GroupRoles.InsertOnSubmit(new GroupRole()
            {
                Token = null, Name = "Pilot"
            });

            // Add localhost game servers
            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                var gameServer = new DataAccess.GameServer()
                {
                    GameServerName = "Test Server", GameServerOwnerName = "BackTrak"
                };
                statsDB.GameServers.InsertOnSubmit(gameServer);

                //db.GameServerIPs.InsertOnSubmit(new GameServerIP() { GameServer = gameServer, GameServerID = gameServer.GameServerID, IPAddress = "127.0.0.1" });
                statsDB.GameServerIPs.InsertOnSubmit(new GameServerIP()
                {
                    GameServer = gameServer, IPAddress = "127.0.0.1"
                });

                statsDB.SubmitChanges();
            }

            //foreach(string name in Enum.GetNames(typeof(DataAccess.Enumerations.LinkedItemType)))
            //{
            //    db.LinkedItemTypes.InsertOnSubmit(new LinkedItemType()
            //    {
            //        Id = (int) Enum.Parse(typeof(DataAccess.Enumerations.LinkedItemType), name),
            //        Name = name
            //    });
            //}

            LoadTestMachineRecords();

            LoadTestMachineExclusions();

            LoadTestVirtualMachineMarkers();
        }
        private int GetAverageXp(CSSStatsDataContext statsDB, List<GameTeamMember> commanders)
        {
            if (commanders.Count == 0)
                return 0;

            int xpTotal = 0;
            foreach (var commander in commanders)
                xpTotal += GetXp(statsDB, commander);

            return (int)Math.Floor(xpTotal / (decimal)commanders.Count);
        }
        public static List<StatsLeaderboard> GetSortedLeaderboard(CSSStatsDataContext statsDB)
        {
            List<StatsLeaderboard> sortedLeaderboard = statsDB.StatsLeaderboards
                    .Where(p => p.DateModified > DateTime.Now.AddDays(-1 * Common.Constants.Leaderboard.MaxLastActiveDays))
                    .OrderByDescending(p => p.Rank)
                    .ToList();

            int counter = 1;
            foreach (var entry in sortedLeaderboard)
            {
                entry.Order = counter;
                entry.Place = counter;
                counter++;
            }

                    //Select((p, index) => new StatsLeaderboard()
                    //{
                    //    Order = index + 1,
                    //    Place = index + 1,
                    //    Callsign = p.LoginUsername,
                    //    Mu = p.Mu.ToString("F2"),
                    //    Sigma = p.Sigma.ToString("F2"),
                    //    Rank = p.Rank.ToString("F1"),
                    //    Wins = p.Wins,
                    //    Losses = p.Losses,
                    //    Draws = p.Draws,
                    //    Defects = p.Defects,
                    //    StackRating = p.StackRating.ToString("F2"),
                    //    CommandMu = p.CommandMu.ToString("F2"),
                    //    CommandSigma = p.CommandSigma.ToString("F2"),
                    //    CommandRank = p.CommandRank.ToString("F1"),
                    //    CommandWins = p.CommandWins,
                    //    CommandLosses = p.CommandLosses,
                    //    CommandDraws = p.CommandDraws,
                    //    Kills = p.Kills,
                    //    Ejects = p.Ejects,
                    //    DroneKills = p.DroneKills,
                    //    StationKills = p.StationKills,
                    //    StationCaptures = p.StationCaptures,
                    //    HoursPlayed = Math.Round(p.HoursPlayed, 2)
                    //}).ToList();

            return sortedLeaderboard;
        }
        private int GetLevel(CSSStatsDataContext statsDB, int playerXp)
        {
            var level = statsDB.Levels.FirstOrDefault(p => p.MinXP <= playerXp && p.MaxXP >= playerXp);
            if (level == null)
                return 0;

            return level.Level1;
        }
        private int GetLevelDifference(CSSStatsDataContext statsDB, int playerXp, int opposingXp)
        {
            int returnValue = 0;
            int playerLevel = GetLevel(statsDB, playerXp);
            int opposingLevel = GetLevel(statsDB, opposingXp);

            returnValue = playerLevel - opposingLevel;

            return (returnValue);
        }
        private int GetRankAdjustment(CSSStatsDataContext statsDB, int playerLevel, int levelDifference, bool winner)
        {
            int returnValue = 0;

            var experianceExchange = statsDB.ExperianceExchanges.FirstOrDefault(p => p.LevelDiffMin == 0 && p.LevelDiffMax == 0);

            foreach (var currExperianceExchange in statsDB.ExperianceExchanges)
            {
                if (Math.Abs(levelDifference) >= currExperianceExchange.LevelDiffMin && Math.Abs(levelDifference) <= currExperianceExchange.LevelDiffMax)
                {
                    experianceExchange = currExperianceExchange;
                    break;
                }
            }

            if (winner)
            {
                // The player's level was greater than the opposition's level.
                if (levelDifference >= 0)
                {
                    returnValue = experianceExchange.HigherWin;
                }
                else if (levelDifference < 0)
                {
                    returnValue = experianceExchange.LowerWin;
                }

                foreach (var winFactor in statsDB.WinFactors)
                {
                    if (playerLevel >= winFactor.MinLevel && playerLevel <= winFactor.MaxLevel)
                    {
                        returnValue = (int)Math.Floor(((double)returnValue * ((double)winFactor.Factor / 100.0)));
                        break;
                    }
                }
            }
            else
            {
                // The player's level was greater than the opposition's level.
                if (levelDifference >= 0)
                {
                    returnValue = experianceExchange.HigherLoss;
                }
                else if (levelDifference < 0)
                {
                    returnValue = experianceExchange.LowerLoss;
                }

                foreach (var lossFactor in statsDB.LossFactors)
                {
                    if (playerLevel >= lossFactor.MinLevel && playerLevel <= lossFactor.MaxLevel)
                    {
                        returnValue = (int)Math.Floor(((double)returnValue * (double)lossFactor.Factor / 100.0));
                        break;
                    }
                }
            }

            return (returnValue);
        }
 private bool IsPlayerIsValidToScore(CSSStatsDataContext statsDB, Game game, GameTeamMember gameTeamMember)
 {
     return gameTeamMember.GameTeamMemberDuration >= 300;
 }
        private int GetXp(CSSStatsDataContext statsDB, GameTeamMember gameTeamMember)
        {
            var leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == gameTeamMember.GameTeamMemberLoginID);
            if (leaderBoard != null)
            {
                return leaderBoard.Xp;
            }

            return 0;
        }
예제 #29
0
        public CommitPlayerDataResponse(CommitPlayerDataRequest request)
        {
            ErrorMessage = String.Empty;
            Succeeded    = true;

            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                using (CSSDataContext db = new CSSDataContext())
                {
                    foreach (var scoreQueue in statsDB.ScoreQueues.Where(p => p.GameGuid == request.GameGuid))
                    {
                        var login = db.Logins.FirstOrDefault(p => p.Id == scoreQueue.LoginId);
                        if (login == null)
                        {
                            Succeeded     = false;
                            ErrorMessage += "Couldn't find login for login id: " + scoreQueue.LoginId;
                            continue;
                        }

                        string callsign = login.Username;

                        var primaryAlias = login.Aliases.FirstOrDefault(p => p.IsDefault == true);
                        if (primaryAlias == null)
                        {
                            primaryAlias = login.Aliases.FirstOrDefault();
                        }

                        if (primaryAlias != null)
                        {
                            callsign = primaryAlias.Callsign;
                        }

                        StatsLeaderboard leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == scoreQueue.LoginId);

                        if (leaderBoard == null)
                        {
                            leaderBoard = new StatsLeaderboard()
                            {
                                CommandDraws    = 0,
                                CommandLosses   = 0,
                                CommandMu       = 0,
                                CommandRank     = 0,
                                CommandSigma    = 0,
                                CommandWins     = 0,
                                DateModified    = DateTime.Now,
                                Defects         = 0,
                                Draws           = 0,
                                DroneKills      = 0,
                                Ejects          = 0,
                                HoursPlayed     = 0,
                                Kills           = 0,
                                LoginID         = scoreQueue.LoginId,
                                LoginUsername   = login.Username,
                                Losses          = 0,
                                Mu              = 0,
                                PRank           = 0,
                                Rank            = 0,
                                Sigma           = 0,
                                StationCaptures = 0,
                                StationKills    = 0,
                                Wins            = 0,
                                Xp              = 0
                            };

                            statsDB.StatsLeaderboards.InsertOnSubmit(leaderBoard);
                        }

                        // Add in the new values.
                        leaderBoard.CommandDraws  += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == false) ? 1 : 0;
                        leaderBoard.CommandLosses += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == true) ? 1 : 0;

                        //leaderBoard.CommandMu = 0;
                        //leaderBoard.CommandRank = 0;
                        //leaderBoard.CommandSigma = 0;
                        //leaderBoard.Mu = 0;
                        //leaderBoard.Sigma = 0;

                        leaderBoard.CommandWins += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == true && scoreQueue.CommandLose == false) ? 1 : 0;
                        leaderBoard.DateModified = DateTime.Now;
                        //leaderBoard.Defects = 0;
                        leaderBoard.Draws           += (scoreQueue.Win == false && scoreQueue.Lose == false) ? 1 : 0;
                        leaderBoard.DroneKills      += (int)Math.Round(scoreQueue.BuilderKills + scoreQueue.CarrierKills + scoreQueue.LayerKills + scoreQueue.MinerKills);
                        leaderBoard.Ejects          += scoreQueue.Deaths;
                        leaderBoard.HoursPlayed     += scoreQueue.TimePlayed.GetValueOrDefault(0) / 3600D;
                        leaderBoard.Kills           += (int)Math.Round(scoreQueue.PlayerKills);
                        leaderBoard.Losses          += (scoreQueue.Win == false && scoreQueue.Lose == true) ? 1 : 0;
                        leaderBoard.StationCaptures += scoreQueue.PilotBaseCaptures + (int)Math.Round(scoreQueue.BaseCaptures);
                        leaderBoard.StationKills    += scoreQueue.PilotBaseKills + (int)Math.Round(scoreQueue.BaseKills);
                        leaderBoard.Wins            += (scoreQueue.Win == true && scoreQueue.Lose == false) ? 1 : 0;
                        leaderBoard.Xp   += (int)Math.Round(scoreQueue.Score);
                        leaderBoard.PRank = 0;
                        leaderBoard.Rank  = GetLevel(statsDB, leaderBoard.Xp);

                        statsDB.ScoreQueues.DeleteOnSubmit(scoreQueue);

                        statsDB.SubmitChanges();
                    }
                }
            }

            this.Succeeded = true;
        }
        public CommitPlayerDataResponse(CommitPlayerDataRequest request)
        {
            ErrorMessage = String.Empty;
            Succeeded = true;

            using (CSSStatsDataContext statsDB = new CSSStatsDataContext())
            {
                using(CSSDataContext db = new CSSDataContext())
                {
                    foreach (var scoreQueue in statsDB.ScoreQueues.Where(p => p.GameGuid == request.GameGuid))
                    {
                        var login = db.Logins.FirstOrDefault(p => p.Id == scoreQueue.LoginId);
                        if(login == null)
                        {
                            Succeeded = false;
                            ErrorMessage += "Couldn't find login for login id: " + scoreQueue.LoginId;
                            continue;
                        }

                        string callsign = login.Username;

                        var primaryAlias = login.Aliases.FirstOrDefault(p => p.IsDefault == true);
                        if(primaryAlias == null)
                            primaryAlias = login.Aliases.FirstOrDefault();

                        if(primaryAlias != null)
                            callsign = primaryAlias.Callsign;

                        StatsLeaderboard leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == scoreQueue.LoginId);

                        if (leaderBoard == null)
                        {
                            leaderBoard = new StatsLeaderboard()
                            {
                                CommandDraws = 0,
                                CommandLosses = 0,
                                CommandMu = 0,
                                CommandRank = 0,
                                CommandSigma = 0,
                                CommandWins = 0,
                                DateModified = DateTime.Now,
                                Defects = 0,
                                Draws = 0,
                                DroneKills = 0,
                                Ejects = 0,
                                HoursPlayed = 0,
                                Kills = 0,
                                LoginID = scoreQueue.LoginId,
                                LoginUsername = login.Username,
                                Losses = 0,
                                Mu = 0,
                                PRank = 0,
                                Rank = 0,
                                Sigma = 0,
                                StationCaptures = 0,
                                StationKills = 0,
                                Wins = 0,
                                Xp = 0
                            };

                            statsDB.StatsLeaderboards.InsertOnSubmit(leaderBoard);
                        }

                        // Add in the new values.
                        leaderBoard.CommandDraws += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == false) ? 1 : 0;
                        leaderBoard.CommandLosses += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == true) ? 1 : 0;

                        //leaderBoard.CommandMu = 0;
                        //leaderBoard.CommandRank = 0;
                        //leaderBoard.CommandSigma = 0;
                        //leaderBoard.Mu = 0;
                        //leaderBoard.Sigma = 0;

                        leaderBoard.CommandWins += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == true && scoreQueue.CommandLose == false) ? 1 : 0;
                        leaderBoard.DateModified = DateTime.Now;
                        //leaderBoard.Defects = 0;
                        leaderBoard.Draws += (scoreQueue.Win == false && scoreQueue.Lose == false) ? 1 : 0;
                        leaderBoard.DroneKills += (int) Math.Round(scoreQueue.BuilderKills + scoreQueue.CarrierKills + scoreQueue.LayerKills + scoreQueue.MinerKills);
                        leaderBoard.Ejects += scoreQueue.Deaths;
                        leaderBoard.HoursPlayed += scoreQueue.TimePlayed.GetValueOrDefault(0) / 3600D;
                        leaderBoard.Kills += (int) Math.Round(scoreQueue.PlayerKills);
                        leaderBoard.Losses += (scoreQueue.Win == false && scoreQueue.Lose == true) ? 1 : 0;
                        leaderBoard.StationCaptures += scoreQueue.PilotBaseCaptures + (int) Math.Round(scoreQueue.BaseCaptures);
                        leaderBoard.StationKills += scoreQueue.PilotBaseKills + (int) Math.Round(scoreQueue.BaseKills);
                        leaderBoard.Wins += (scoreQueue.Win == true && scoreQueue.Lose == false) ? 1 : 0;
                        leaderBoard.Xp += (int) Math.Round(scoreQueue.Score);
                        leaderBoard.PRank = 0;
                        leaderBoard.Rank = GetLevel(statsDB, leaderBoard.Xp);

                        statsDB.ScoreQueues.DeleteOnSubmit(scoreQueue);

                        statsDB.SubmitChanges();
                    }
                }
            }

            this.Succeeded = true;
        }