public ActionResult ChangePassword(string oldPassword, string newPassword, string newPassword2) { var db = new ZkDataContext(); var acc = db.Accounts.Find(Global.AccountID); if (acc == null) { return(Content("Invalid accountID")); } if (string.IsNullOrEmpty(acc.PasswordBcrypt)) { return(Content("Your account is password-less, use steam")); } if (AuthServiceClient.VerifyAccountPlain(acc.Name, oldPassword) == null) { Trace.TraceWarning("Failed password check for {0} on attempted password change", Global.Account.Name); Global.Server.LoginChecker.LogIpFailure(Request.UserHostAddress); return(Content("Invalid password")); } if (newPassword != newPassword2) { return(Content("New passwords do not match")); } if (string.IsNullOrWhiteSpace(newPassword)) { return(Content("New password cannot be blank")); } acc.SetPasswordPlain(newPassword); db.SaveChanges(); //return Content("Old: " + oldPassword + "; new: " + newPassword); return(RedirectToAction("Logout", "Home")); }
public void MovePlayers(string autohostName, string autohostPassword, List <MovePlayerEntry> moves) { var db = new ZkDataContext(); var acc = AuthServiceClient.VerifyAccountPlain(autohostName, autohostPassword); if (acc == null) { throw new Exception("Invalid password"); } var name = autohostName.TrimNumbers(); var entry = db.AutohostConfigs.SingleOrDefault(x => x.Login == name); if (entry == null) { throw new Exception("Not an autohost"); } try { foreach (var m in moves) { Global.Nightwatch.Tas.ForceJoinBattle(m.PlayerName, m.BattleHost); } } catch (Exception ex) { Trace.TraceError("Error while moving players: {0}", ex); } }
public void UndeleteMission(int missionID, string author, string password) { var db = new ZkDataContext(); var prev = db.Missions.Where(x => x.MissionID == missionID).SingleOrDefault(); if (prev != null) { var acc = AuthServiceClient.VerifyAccountPlain(author, password); if (acc == null) { Trace.TraceWarning("Invalid login attempt for {0}", author); System.Threading.Thread.Sleep(new Random().Next(2000)); throw new ApplicationException("Cannot verify user account"); } if (acc.AccountID != prev.AccountID && acc.AdminLevel < AdminLevel.Moderator) { throw new ApplicationException("You cannot undelete a mission from an other user"); } prev.IsDeleted = false; db.SaveChanges(); } else { throw new ApplicationException("No such mission found"); } }
public AccountInfo GetAccountInfo(string login, string password) { var acc = AuthServiceClient.VerifyAccountPlain(login, password); if (acc == null) { return(null); } else { return new AccountInfo() { Name = acc.Name, Country = acc.Country, Aliases = acc.Aliases, ZeroKAccountID = acc.AccountID, ZeroKLevel = acc.Level, ClanID = acc.ClanID ?? 0, ClanName = acc.Clan != null ? acc.Clan.ClanName : null, IsZeroKAdmin = acc.IsZeroKAdmin, Avatar = acc.Avatar, Elo = (float)acc.Elo, EffectiveElo = acc.EffectiveElo, EloWeight = (float)acc.EloWeight, FactionID = acc.FactionID ?? 0, FactionName = acc.Faction != null ? acc.Faction.Name : null, SpringieLevel = acc.GetEffectiveSpringieLevel(), LobbyID = acc.LobbyID ?? 0 } }; }
public bool VerifyAccountData(string login, string password) { var acc = AuthServiceClient.VerifyAccountPlain(login, password); if (acc == null) { return(false); } return(true); }
public void SplitAutohost(BattleContext context, string password) { if (AuthServiceClient.VerifyAccountPlain(context.AutohostName, password) == null) { throw new Exception("Invalid password"); } if (context.GetConfig() == null) { throw new Exception("Not an autohost"); } Balancer.SplitAutohost(context); }
public AccountInfo GetAccountInfo(string login, string password) { var acc = AuthServiceClient.VerifyAccountPlain(login, password); if (acc == null) { return(null); } else { return new AccountInfo() { Name = acc.Name, LobbyID = acc.LobbyID ?? 0, Country = acc.Country, Aliases = acc.Aliases, ZeroKAccountID = acc.AccountID, ZeroKLevel = acc.Level, ClanID = acc.ClanID ?? 0, ClanName = acc.Clan != null? acc.Clan.ClanName : null, LobbyTimeRank = acc.LobbyTimeRank, IsLobbyAdmin = acc.IsLobbyAdministrator, IsZeroKAdmin = acc.IsZeroKAdmin, Avatar = acc.Avatar, Elo = (float)acc.Elo, EffectiveElo = acc.EffectiveElo, EloWeight = (float)acc.EloWeight, FactionID = acc.FactionID ?? 0, FactionName = acc.Faction != null? acc.Faction.Name:null, SpringieLevel = acc.GetEffectiveSpringieLevel() } }; } string GetUserIP() { var ip = Context.Request.ServerVariables["REMOTE_ADDR"]; return(ip); }
public void UndeleteMission(int missionID, string author, string password) { var db = new ZkDataContext(); var prev = db.Missions.Where(x => x.MissionID == missionID).SingleOrDefault(); if (prev != null) { var acc = AuthServiceClient.VerifyAccountPlain(author, password); if (acc == null) { throw new ApplicationException("Invalid login name or password"); } if (acc.AccountID != prev.AccountID && !acc.IsZeroKAdmin && !acc.IsLobbyAdministrator) { throw new ApplicationException("You cannot undelete a mission from an other user"); } prev.IsDeleted = false; db.SubmitChanges(); } else { throw new ApplicationException("No such mission found"); } }
public void SendMission(Mission mission, List <MissionSlot> slots, string author, string password, Mod modInfo) { if (mission == null) { throw new ApplicationException("Mission is null"); } Account acc = null; var db = new ZkDataContext(); if (Debugger.IsAttached) { acc = db.Accounts.SingleOrDefault(x => x.Name == "Testor303"); } else { acc = AuthServiceClient.VerifyAccountPlain(author, password); } if (acc == null) { throw new ApplicationException("Cannot verify user account"); } Mission prev = db.Missions.SingleOrDefault(x => x.MissionID == mission.MissionID || (x.Name == mission.Name && x.AccountID == acc.AccountID)); // previous mission by id or name + account if (prev == null && db.Missions.Any(x => x.Name == mission.Name)) { throw new ApplicationException("Mission name must be unique"); } var map = db.Resources.SingleOrDefault(x => x.InternalName == mission.Map && x.TypeID == ZkData.ResourceType.Map); if (map == null) { throw new ApplicationException("Map name is unknown"); } var mod = db.Resources.SingleOrDefault(x => x.InternalName == mission.Mod && x.TypeID == ZkData.ResourceType.Mod); if (mod == null) { throw new ApplicationException("Mod name is unknown"); } //if (db.Resources.Any(x => x.InternalName == mission.Name && x.MissionID != null)) throw new ApplicationException("Name already taken by other mod/map"); modInfo.MissionMap = mission.Map; if (prev != null) { if (prev.AccountID != acc.AccountID && !acc.IsLobbyAdministrator && !acc.IsZeroKAdmin) { throw new ApplicationException("Invalid author or password"); } prev.Description = mission.Description; prev.DescriptionStory = mission.DescriptionStory; prev.Mod = mission.Mod; prev.Map = mission.Map; prev.Name = mission.Name; prev.ScoringMethod = mission.ScoringMethod; prev.ModRapidTag = mission.ModRapidTag; prev.ModOptions = mission.ModOptions; prev.Image = mission.Image; prev.MissionEditorVersion = mission.MissionEditorVersion; prev.SpringVersion = mission.SpringVersion; prev.Revision++; prev.Mutator = mission.Mutator; prev.ForumThread.Title = mission.Name; mission = prev; } else { mission.CreatedTime = DateTime.UtcNow; mission.ForumThread = new ForumThread() { Title = mission.Name, ForumCategory = db.ForumCategories.FirstOrDefault(x => x.IsMissions), CreatedAccountID = acc.AccountID, LastPostAccountID = acc.AccountID }; mission.ForumThread.UpdateLastRead(acc.AccountID, true); db.Missions.InsertOnSubmit(mission); } mission.AccountID = acc.AccountID; mission.Script = Regex.Replace(mission.Script, "GameType=([^;]+);", (m) => { return(string.Format("GameType={0};", mission.NameWithVersion)); }); mission.MinHumans = slots.Count(x => x.IsHuman && x.IsRequired); mission.MaxHumans = slots.Count(x => x.IsHuman); mission.ModifiedTime = DateTime.UtcNow; mission.IsDeleted = true; mission.IsCoop = slots.Where(x => x.IsHuman).GroupBy(x => x.AllyID).Count() == 1; db.SubmitChanges(); var updater = new MissionUpdater(); updater.UpdateMission(db, mission, modInfo); mission.IsDeleted = false; db.SubmitChanges(); }
public static string SubmitSpringBattleResult(BattleContext context, string password, BattleResult result, List <BattlePlayerResult> players, List <string> extraData) { try { Account acc = AuthServiceClient.VerifyAccountPlain(context.AutohostName, password); if (acc == null) { throw new Exception("Account name or password not valid"); } AutohostMode mode = context.GetMode(); var db = new ZkDataContext(); if (extraData == null) { extraData = new List <string>(); } var sb = new SpringBattle { HostAccountID = acc.AccountID, Duration = result.Duration, EngineGameID = result.EngineBattleID, MapResourceID = db.Resources.Single(x => x.InternalName == result.Map).ResourceID, ModResourceID = db.Resources.Single(x => x.InternalName == result.Mod).ResourceID, HasBots = result.IsBots, IsMission = result.IsMission, PlayerCount = players.Count(x => !x.IsSpectator), StartTime = result.StartTime, Title = result.Title, ReplayFileName = result.ReplayName, EngineVersion = result.EngineVersion, }; db.SpringBattles.InsertOnSubmit(sb); foreach (BattlePlayerResult p in players) { sb.SpringBattlePlayers.Add(new SpringBattlePlayer { AccountID = db.Accounts.First(x => x.AccountID == p.LobbyID).AccountID, AllyNumber = p.AllyNumber, CommanderType = p.CommanderType, IsInVictoryTeam = p.IsVictoryTeam, IsSpectator = p.IsSpectator, LoseTime = p.LoseTime }); } db.SubmitChanges(); // awards foreach (string line in extraData.Where(x => x.StartsWith("award"))) { string[] partsSpace = line.Substring(6).Split(new[] { ' ' }, 3); string name = partsSpace[0]; string awardType = partsSpace[1]; string awardText = partsSpace[2]; SpringBattlePlayer player = sb.SpringBattlePlayers.FirstOrDefault(x => x.Account.Name == name); if (player != null) { db.AccountBattleAwards.InsertOnSubmit(new AccountBattleAward { AccountID = player.AccountID, SpringBattleID = sb.SpringBattleID, AwardKey = awardType, AwardDescription = awardText }); } } var text = new StringBuilder(); bool isPlanetwars = false; if (mode == AutohostMode.Planetwars && sb.SpringBattlePlayers.Count(x => !x.IsSpectator) >= 2 && sb.Duration >= GlobalConst.MinDurationForPlanetwars) { // test that factions are not intermingled (each faction only has one ally number) - if they are it wasnt actually PW balanced if ( sb.SpringBattlePlayers.Where(x => !x.IsSpectator && x.Account.Faction != null) .GroupBy(x => x.Account.Faction) .All(grp => grp.Select(x => x.AllyNumber).Distinct().Count() < 2)) { isPlanetwars = true; List <int> winnerTeams = sb.SpringBattlePlayers.Where(x => x.IsInVictoryTeam && !x.IsSpectator).Select(x => x.AllyNumber).Distinct().ToList(); int?winNum = null; if (winnerTeams.Count == 1) { winNum = winnerTeams[0]; if (winNum > 1) { winNum = null; text.AppendLine("ERROR: Invalid winner"); } } PlanetWarsTurnHandler.EndTurn(result.Map, extraData, db, winNum, sb.SpringBattlePlayers.Where(x => !x.IsSpectator).Select(x => x.Account).ToList(), text, sb, sb.SpringBattlePlayers.Where(x => !x.IsSpectator && x.AllyNumber == 0).Select(x => x.Account).ToList()); Global.PlanetWarsMatchMaker.RemoveFromRunningBattles(context.AutohostName); } else { text.AppendLine("Battle wasn't PlanetWars balanced, it counts as a normal team game only"); } } bool noElo = (extraData.FirstOrDefault(x => x.StartsWith("noElo")) != null); try { db.SubmitChanges(); } catch (System.Data.Linq.DuplicateKeyException ex) { Trace.TraceError(ex.ToString()); } Dictionary <int, int> orgLevels = sb.SpringBattlePlayers.Select(x => x.Account).ToDictionary(x => x.AccountID, x => x.Level); sb.CalculateAllElo(noElo, isPlanetwars); foreach (var u in sb.SpringBattlePlayers.Where(x => !x.IsSpectator)) { u.Account.CheckLevelUp(); } db.SubmitAndMergeChanges(); try { foreach (Account a in sb.SpringBattlePlayers.Where(x => !x.IsSpectator).Select(x => x.Account)) { Global.Server.PublishAccountUpdate(a); } } catch (Exception ex) { Trace.TraceError("error updating extension data: {0}", ex); } foreach (Account account in sb.SpringBattlePlayers.Select(x => x.Account)) { if (account.Level > orgLevels[account.AccountID]) { try { string message = string.Format("Congratulations {0}! You just leveled up to level {1}. {3}/Users/Detail/{2}", account.Name, account.Level, account.AccountID, GlobalConst.BaseSiteUrl); //text.AppendLine(message); Global.Server.GhostPm(account.Name, message); } catch (Exception ex) { Trace.TraceError("Error sending level up lobby message: {0}", ex); } } } text.AppendLine(string.Format("BATTLE DETAILS AND REPLAY ----> {1}/Battles/Detail/{0} <-----", sb.SpringBattleID, GlobalConst.BaseSiteUrl)); /* * // create debriefing room, join players there and output message * string channelName = "B" + sb.SpringBattleID; * var joinplayers = new List<string>(); * joinplayers.AddRange(context.Players.Select(x => x.Name)); // add those who were there at start * joinplayers.AddRange(sb.SpringBattlePlayers.Select(x => x.Account.Name)); // add those who played * Battle bat = Global.Server.Battles.Values.FirstOrDefault(x => x.Founder.Name == context.AutohostName); // add those in lobby atm * * * var conf = context.GetConfig(); * if (bat != null && (conf == null || conf.MinToJuggle == null)) // if not qm room do not join those who are in battle * { * List<string> inbatPlayers = bat.Users.Keys.ToList(); * joinplayers.RemoveAll(x => inbatPlayers.Contains(x)); * } * foreach (string jp in joinplayers.Distinct().Where(x => x != context.AutohostName)) tas.ForceJoinChannel(jp, channelName); * tas.JoinChannel(channelName); // join nightwatch and say it * tas.Say(SayPlace.Channel, channelName, text.ToString(), true); * tas.LeaveChannel(channelName);*/ //text.Append(string.Format("Debriefing in #{0} - zk://chat/channel/{0} ", channelName)); return(text.ToString()); } catch (Exception ex) { Trace.TraceError(ex.ToString()); return(ex.ToString()); } }