Пример #1
0
        public Session GetSession(string login, string password)
        {
            Player playerOverview = null;
            try
            {
                playerOverview = daoPlayer.Get(login);
            }
            catch (Exception e)
            {
                // Exception caugth from persistenceManager, technical raison, not buiness
                var toRethrow = new InvalidCredentialException(e.Message);
                throw toRethrow;
            }

            // No result found
            if (playerOverview == null)
            {
                throw new InvalidCredentialException(InvalidCredentialEnum.NoLoginFound);
            }

            // Invalid Password
            if (playerOverview.Password !=password)
            {
                throw new InvalidCredentialException(InvalidCredentialEnum.BadPassword);
            }

            var session = new Session
            {
                PlayerInBattle = new PlayerInBattle
                {
                    Battle = null,
                    Player = playerOverview
                },
                Id = Guid.NewGuid().ToString(),
                MaxValidity = DateTime.UtcNow.AddHours(numberOfHourBeforeTimeOut)
            };

            Add(session);
            return session;
        }
Пример #2
0
 private void Add(Session session)
 {
     lock (internalLock)
     {
         this.allSessions.Add(session.Id, session);
     }
 }
Пример #3
0
        public Session GetSession(Session otherSession, int gameId)
        {
            var gameOverview = this.daoGame.GetParticipation(otherSession.PlayerInBattle.Player, gameId);
            if (gameOverview == null)
            {
                throw new InvalidCredentialException(InvalidCredentialEnum.PlayerNotInvolvedInGame);
            }

            var session = new Session
            {
                PlayerInBattle = gameOverview,
                Id = Guid.NewGuid().ToString(),
                MaxValidity = DateTime.UtcNow.AddHours(numberOfHourBeforeTimeOut)
            };
            Add(session);
            return session;
        }