Exemplo n.º 1
0
        public void LoadData()
        {
            // loads users
            Loader loadedUsers = new Loader(this.configPath + "users.csv");

            foreach (List <string> userData in loadedUsers.Data)
            {
                User user = new User(Int32.Parse(userData[0]), userData[1], Int32.Parse(userData[2]), userData[3], Convert.ToBoolean(userData[4]), userData[5]);
                this.Users.Add(user);// puts user in list
            }
            // loads games
            Loader loadedGames = new Loader(this.configPath + "games.csv");

            foreach (List <string> gameData in loadedGames.Data)
            {
                Game game = new Game(Int32.Parse(gameData[0]), gameData[1], gameData[2], Int32.Parse(gameData[3]), gameData[5]);
                if (gameData[4] != "")
                {
                    game.SteamId = Int32.Parse(gameData[4]);
                }
                this.Games.Add(game);// puts game in list
            }
            // loads allowed play times
            Loader loadedTimes = new Loader(this.configPath + "allowed_playtime.csv");

            foreach (List <string> timeData in loadedTimes.Data)
            {
                if (this.GetUserById(Int32.Parse(timeData[0])) != null)
                {
                    PlayPeriod period = new PlayPeriod(Int32.Parse(timeData[1]), Int32.Parse(timeData[2]), Int32.Parse(timeData[3]));
                    this.GetUserById(Int32.Parse(timeData[0])).PlayPeriods.Add(period);// adds play period to correct player
                }
            }
            // loads game exeptions
            Loader loadedExeptions = new Loader(this.configPath + "play_exeptions.csv");

            foreach (List <string> exeptionData in loadedExeptions.Data)
            {
                if (this.GetGameById(Int32.Parse(exeptionData[1])) != null && this.GetUserById(Int32.Parse(exeptionData[0])) != null)
                {
                    GameExeption exeption = new GameExeption(this.GetGameById(Int32.Parse(exeptionData[1])), Convert.ToBoolean(exeptionData[2]));
                    this.GetUserById(Int32.Parse(exeptionData[0])).GameExeptions.Add(exeption);// adds game exeption to correct player
                }
            }
            // loads sessions
            Loader loadedSessions = new Loader(this.configPath + "sessions.csv");

            foreach (List <string> sessionData in loadedSessions.Data)
            {
                if (this.GetGameById(Int32.Parse(sessionData[0])) != null && this.GetUserById(Int32.Parse(sessionData[1])) != null)
                {
                    Session session = new Session(this.GetGameById(Int32.Parse(sessionData[0])), this.GetUserById(Int32.Parse(sessionData[1])));
                    session.Set(Int32.Parse(sessionData[2]), Int32.Parse(sessionData[3]));
                    this.Sessions.Add(session);
                }
            }

            // var hash = this.ActiveUser.HashPassword("admin");
            this.SaveData();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if this user is allowed to play the given game.
        /// </summary>
        public bool AllowedToPlay(Game game)
        {
            if (this.Admin == true)
            {
                return(true);    // admins are allowed to play every game!!!!
            }
            bool allowed = true; // nobody is allowed to play games... untill they are.

            if (this.Age < game.Age)
            {
                allowed = false;                      // is user old enough?
            }
            GameExeption exeption = this.GetGameExeption(game);

            if (exeption != null)
            {
                allowed = exeption.Allowed;                   // a game exeption overrides every condition exept admin and playperiod
            }
            if (!this.InPlayPeriod)
            {
                allowed = false;                     // players are only allowed to play if a play period is active
            }
            return(allowed);
        }