Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public JsonResult SaveGame(int gameId)
        {
            lock (Game)
            {
                using (var dao = new GameInstanceDAO())
                {
                    dao.UpdateGameInstance(Game);
                }

                return(Json(Result.Succes));
            }
        }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
        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();
                    }
                }
            }
        }