Beispiel #1
0
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var allConstructorFinder = new AllConstructorFinder();

            builder.RegisterType <DatabaseInitialization>().As <IStartable>().SingleInstance().FindConstructorsWith(allConstructorFinder).AutoActivate();
            builder.RegisterType <AuthenticationContextFactory>().As <IAuthenticationContextFactory>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <CharacterManagementContextFactory>().As <ICharacterManagementContextFactory>().SingleInstance().FindConstructorsWith(allConstructorFinder);
        }
Beispiel #2
0
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var allConstructorFinder = new AllConstructorFinder();

            builder.RegisterType <AuthenticationService>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <BCrypPasswordService>().As <IPasswordService>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LoginStateChatCommand>().As <IChatCommand>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <RegisterChatCommand>().As <IChatCommand>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LogOutChatCommand>().As <IChatCommand>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LoginMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LogoutMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <CreateAccountMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);

            //Component location
            builder.RegisterType <ComponentSelector <Account> >().AsSelf().SingleInstance();


            //Add a decorator to all script message handlers that do not handle login messages. The decorator automatically blocks all non login/create messages
            // from clients that are not yet logged in. Never trust the client...
            builder.RegisterDecorator <IScriptMessageHandler>((context, parameters, instance) =>
            {
                if (instance.SupportedMessage != ScriptMessages.Login && instance.SupportedMessage != ScriptMessages.CreateAccount)
                {
                    return(new AuthenticatedMessageHandlerDecorator(instance, context.Resolve <AuthenticationService>(),
                                                                    context.Resolve <ILoggerFactory>()));
                }
                else
                {
                    return(instance);
                }
            });
        }
Beispiel #3
0
        public GUCScripts()
        {
            var allConstructorFinder = new AllConstructorFinder();

            //Use the autofac dependency injection container to build the main objects.
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <ScriptClient>().AsSelf().SingleInstance();
            builder.RegisterType <ArenaControl>().AsSelf().SingleInstance();
            builder.RegisterType <PacketWriterFactory>().As <IPacketWriterFactory>().SingleInstance();
            builder.RegisterType <ScriptMessageSender>().AsSelf().SingleInstance();
            builder.RegisterType <Chat>().AsSelf().SingleInstance();
            builder.RegisterType <GameState>().AsSelf().SingleInstance();
            builder.RegisterType <LoginPacketWriter>().AsSelf().SingleInstance();
            builder.RegisterType <Login.Login>().AsSelf().SingleInstance();
            builder.RegisterType <GucLoggerFactory>().As <ILoggerFactory>().SingleInstance();
            builder.RegisterType <CharacterList>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LeaveGameSender>().AsSelf().SingleInstance();
            builder.RegisterType <CharListRequestSender>().AsSelf().SingleInstance();
            builder.RegisterType <AccountCreationMessageWriter>().AsSelf().SingleInstance();
            builder.RegisterType <AccountCreation>().AsSelf().SingleInstance();
            builder.RegisterType <CharacterCreation>().AsSelf().SingleInstance();
            builder.RegisterType <NpcDefList>().AsSelf().SingleInstance();
            builder.RegisterType <CharacterVisualsReader>().AsSelf().SingleInstance();
            builder.RegisterType <JoinGameSender>().AsSelf().SingleInstance();
            builder.RegisterType <ErrorScreenManager>().AsSelf().SingleInstance();


            //Message handling
            builder.RegisterType <ScriptMessageHandlerSelector>().As <IScriptMessageHandlerSelector>().SingleInstance();
            builder.RegisterType <LoginDeniedMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <LoginAcknowledgedMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <LogoutAcknowledgeMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <AccountCreationResultMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <CharacterCreationResultMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <CharacterListResultMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();
            builder.RegisterType <JoinGameResultMessageHandler>().As <IScriptMessageHandler>().AsSelf().SingleInstance();

            //GUI Menus
            builder.RegisterType <CharCreationMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <MainMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <ChatMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <ExitMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <StatusMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <LoginMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <WaitScreen>().As <IClosableMenu>().AsSelf().SingleInstance();
            builder.RegisterType <InGameMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <AccountCreationMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <CharacterSelectionMenu>().AsSelf().As <IClosableMenu>().SingleInstance();
            builder.RegisterType <ErrorScreen>().AsSelf().As <IClosableMenu>().SingleInstance();

            //Register event wiring classes used to wire the events between GUI views without circular references(and other bad stuff).
            builder.RegisterType <MainMenuEventWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <ExitMenuEventWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <LoginMenuWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <InGameMenuWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <CharacterLoadingEventWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <AccountCreationMenuEventWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <CharCreationMenuEventWiring>().AsSelf().SingleInstance().AutoActivate();
            builder.RegisterType <CharacterSelectionMenuEventWiring>().AsSelf().SingleInstance().AutoActivate();


            //Shared
            builder.RegisterType <GermanNameValidator>().As <ICharacterNameValidator>().SingleInstance();



            _DiBuilder = builder;
        }
Beispiel #4
0
        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var allConstructorFinder = new AllConstructorFinder();

            builder.RegisterType <CharacterVisualsWriter>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <DefaultSpawnPointProvider>().As <ISpawnPointProvider>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <CharacterTemplateSelector>().As <ICharacterTemplateSelector>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <CharacterBuilder>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);

            //Transactions(Encapsulations of database code heavy actions that can be triggered via the CharacterService)
            builder.RegisterType <CreateHumanPlayerCharacterTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <CheckCharacterExistsTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <AddCharacterOwnerShipTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <GetAccountOwnedCharactersTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <SetAccountActiveCharacterTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <GetAccountActiveCharacterTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <GetCharacterOwnershipsCountTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <SaveCharacterTransaction>().AsSelf().SingleInstance().FindConstructorsWith(allConstructorFinder);

            // Account components
            builder.RegisterType <CharacterListLocator>().As <IComponentLocator <Account> >().SingleInstance();


            //Register the service. This is a somewhat more complicated than because of the possible circular references with the transaction classes.
            builder.Register(context => new CharacterService()
            {
            }).OnActivated(args =>
            {
                args.Instance.AddCharacterOwnerShipTransaction =
                    args.Context.Resolve <AddCharacterOwnerShipTransaction>();
                args.Instance.GetAccountOwnedCharactersTransaction =
                    args.Context.Resolve <GetAccountOwnedCharactersTransaction>();
                args.Instance.CharacterExistsTransaction            = args.Context.Resolve <CheckCharacterExistsTransaction>();
                args.Instance.CreateHumanPlayerCharacterTransaction =
                    args.Context.Resolve <CreateHumanPlayerCharacterTransaction>();
                args.Instance.SetAccountActiveCharacterTransaction =
                    args.Context.Resolve <SetAccountActiveCharacterTransaction>();
                args.Instance.GetAccountActiveCharacterTransaction =
                    args.Context.Resolve <GetAccountActiveCharacterTransaction>();
                args.Instance.GetCharacterOwnershipsCountTransaction =
                    args.Context.Resolve <GetCharacterOwnershipsCountTransaction>();
                args.Instance.SaveCharacterTransaction =
                    args.Context.Resolve <SaveCharacterTransaction>();
                args.Instance.AuthenticationService =
                    args.Context.Resolve <AuthenticationService>();
                //Initialize the service.
                args.Instance.Init();
            }).AsSelf()
            .SingleInstance();


            //Message Handling
            builder.RegisterType <CharacterCreationMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <RequestCharacterListMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <JoinGameMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);
            builder.RegisterType <LeaveGameMessageHandler>().As <IScriptMessageHandler>().SingleInstance().FindConstructorsWith(allConstructorFinder);

            //Database initialization
            builder.RegisterType <CharacterItemsInitialization>().AsSelf().SingleInstance().AutoActivate().FindConstructorsWith(allConstructorFinder);

            //Other initializations
            builder.RegisterType <AccountLogoutHandling>().AsSelf().SingleInstance().AutoActivate();
        }