Exemplo n.º 1
0
        public Game CreateGameWithScenario( User creator, string scenario, string name )
        {
            var game = new Game( name, creator.Id );
            game.Scenario = scenario;

            this.AddPlayer( game, creator.Id );

            return game;
        }
Exemplo n.º 2
0
        public void ReassignUser( string connectionId, User user )
        {
            if ( user.ConnectionId != null )
            {
                User garbage;
                this.users.TryRemove( user.ConnectionId, out garbage );
            }

            user.ConnectionId = connectionId;
            this.users.TryAdd( connectionId, user );
        }
Exemplo n.º 3
0
        public InitDto InitializeClient( string registrationId )
        {
            if ( this.registrationHandler.RegistrationExists( registrationId ) )
            {
                var rc = this.registrationHandler.RemoveRegistration( registrationId );

                if ( this.userHandler.UserExists( this.Context.ConnectionId ) )
                {
                    return null;
                }

                var user = this.userHandler.FindUserByIdentity( rc.Identity );

                if ( user == null )
                {
                    user = new User( this.Context.ConnectionId, rc );
                }
                else
                {
                    user.RegistrationTicket = rc;
                    this.userHandler.ReassignUser( this.Context.ConnectionId, user );
                }

                this.userHandler.AddUser( user ); // will ensure that they're persisted

                // add the user into the groups for any games to which he belongs
                var usersGames = this.gameHandler.GetGames().Where( a => a.Players.Any( b => b == user.Id ) );

                foreach ( var game in usersGames )
                {
                    this.Groups.Add( user.ConnectionId, game.GroupName );
                }

                return new InitDto
                {
                    Scenarios = this.scenarioHandler.GetScenarioNames(),
                    UserId = user.Id
                };
            }

            return null;
        }
Exemplo n.º 4
0
        public void AddUser( User user )
        {
            this.repository.Save<User>( user );

            this.users.TryAdd( user.ConnectionId, user );
        }