public static GameInstance GetGameInstanceById(int i) { lock (Games) { if (Games.ContainsKey(i)) { return(Games[i]); } else { using (var dao = new GameInstanceDAO()) { var game = dao.RestoreGameInstance(i); if (game == null) { throw new Error.GameNotExists(); } else { Games.Add(i, game); } return(game); } } } }
public static GameInstance NewGameInstance(GameDefinition definition, string name, string password) { GameInstance gameInstance = new GameInstance(definition); GameInstanceDAO dao = new GameInstanceDAO(); dao.AddGameInstance(gameInstance, name, password); Games.Add(gameInstance.Id, gameInstance); return(gameInstance); }
public JsonResult SaveGame(int gameId) { lock (Game) { using (var dao = new GameInstanceDAO()) { dao.UpdateGameInstance(Game); } return(Json(Result.Succes)); } }
public static List <DBGameInstance> GetGamesByUser(Permission.TYPE permission) { using (var dao = new GameInstanceDAO()) { if (IsUserLogged()) { return(dao.GetGameInstancesByUser(HttpContext.Current.User.Identity.Name, permission)); } else if (HttpContext.Current.Request.Cookies.AllKeys.Contains("_guid")) { return(dao.GetGameInstancesByGuid(HttpContext.Current.Request.Cookies["_guid"].Value, permission)); } return(null); } }
public void CheckGamePassword(int gameId, string password) { using (var dao = new GameInstanceDAO()) { string gamePassword = dao.GetGameInstance(gameId).Password; if (!(gamePassword == "" && ((password == null || password == "")))) { if (!Crypto.VerifyHashedPassword(gamePassword, password != null ? password : "")) { throw new Error.InvalidPassword(); } } } }