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; }
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 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(); }
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; }
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 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(); }
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; }