public void Test_Client_Can_Create_MessageHandlerService_From_DependencyModules()
        {
            //TODO: This won't work if we have multiple configurable modules.
            //arrange
            ContainerBuilder builder = TestIoC.CreateDefaultContainer();

            IContainer resolver = builder.Build();

            MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> handler = null;

            //act
            try
            {
                handler = resolver.Resolve <MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> >();
            }
            catch (DependencyResolutionException e)
            {
                //This makes it so the error is more readable. So we can see the exact dependency that is missing.
                DependencyResolutionException dependencyResolveException = e;

                while (dependencyResolveException.InnerException is DependencyResolutionException)
                {
                    dependencyResolveException = (DependencyResolutionException)dependencyResolveException.InnerException;
                }

                Assert.Fail($"Failed: {dependencyResolveException.Message}\n\n{dependencyResolveException.StackTrace}");
            }


            //assert
            Assert.NotNull(handler);
        }
 /// <inheritdoc />
 public DefaultManagedClientSessionFactory(
     [NotNull] ILog logger,
     [NotNull] MessageHandlerService <BaseGameClientPayload, BaseGameServerPayload, IPeerSessionMessageContext <BaseGameServerPayload> > handlerService)
 {
     Logger         = logger ?? throw new ArgumentNullException(nameof(logger));
     HandlerService = handlerService ?? throw new ArgumentNullException(nameof(handlerService));
 }
Beispiel #3
0
        //Turn Related Material

        public Timer turnSpanner(MessageHandlerService instance, Timer initTimer, GameRoom room)
        {
            if (turn == 0)
            {
                initTimer.Dispose();
                timer2 = enableActions();
                timer3 = executeActionsTimer(room);
            }
            TimeSpan startTimeSpan  = TimeSpan.Zero;
            TimeSpan periodTimeSpan = TimeSpan.FromSeconds(60);
            Timer    timer          = new Timer(async(e) =>
            {
                if (turn != 0)
                {
                    editable = false;
                    GameRequest GameRequest = new GameRequest();
                    GameRequest.EventType   = "UpdateInformation";
                    try
                    {
                        await instance.updateTurnAsync(GameRequest, room, "server");
                    } catch (HttpRequestException exc)
                    {
                        Console.WriteLine("Server could not parse user data;\n" + exc.ToString());
                    }
                    canMakeEditable = true;
                }
                Console.WriteLine("Editable? =>" + editable);
                turn++;
            }, null, startTimeSpan, periodTimeSpan);

            return(timer);
        }
        internal async Task ConnectAsync(DiscordBotConfig config)
        {
            Log.Information("Initializing connection.");
            _commandHandler    = new CommandHandlerService(_client, _logger, config, _service, _serviceProvider);
            _messageHandler    = new MessageHandlerService(_client, _logger, config, _levelingService, _userAccountRepository);
            _userEventsHandler = new UserEventsHandlerService(_client, _logger, config, _userAccountRepository);
            _client.Log       += _logger.Log;
            _client.Ready     += ReadyAsync;
            if (config.Token == null || config.Token == "")
            {
                throw new ArgumentNullException("Token", "Discord Bot Token is empty!");
            }
            if (config.CmdPrefix == null || config.CmdPrefix == "")
            {
                throw new ArgumentNullException("cmdPrefix", "Discord Bot cmdPrefix is empty!");
            }

            await _client.LoginAsync(TokenType.Bot, config.Token);

            await _client.StartAsync();

            await _commandHandler.InitializeAsync();

            _messageHandler.Initialize();
            _userEventsHandler.Initialize();
            await Task.Delay(-1);
        }
Beispiel #5
0
 public Startup(IServiceProvider services)
 {
     _services       = services;
     _client         = _services.GetRequiredService <DiscordSocketClient>();
     _commands       = _services.GetRequiredService <CommandService>();
     _log            = _services.GetRequiredService <LogService>();
     _messageHandler = _services.GetRequiredService <MessageHandlerService>();
     _tokens         = _services.GetRequiredService <Tokens>();
 }
Beispiel #6
0
 /// <inheritdoc />
 public ZoneClientSession(IManagedNetworkServerClient <GameServerPacketPayload, GameClientPacketPayload> internalManagedNetworkClient,
                          SessionDetails details,
                          MessageHandlerService <GameClientPacketPayload, GameServerPacketPayload, IPeerSessionMessageContext <GameServerPacketPayload> > messageHandlers,
                          [NotNull] ILog logger)
     : base(internalManagedNetworkClient, details)
 {
     MessageHandlers = messageHandlers ?? throw new ArgumentNullException(nameof(messageHandlers));
     Logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #7
0
 /// <inheritdoc />
 protected BaseUnityNetworkClient(
     MessageHandlerService <TIncomingPayloadType, TOutgoingPayloadType> handlers,
     ILog logger,
     IPeerMessageContextFactory messageContextFactory)
 {
     Handlers = handlers;
     Logger   = logger;
     MessageContextFactory = messageContextFactory;
 }
 /// <inheritdoc />
 public DefaultManagedClientSessionFactory(
     [NotNull] ILog logger,
     [NotNull] MessageHandlerService <GameClientPacketPayload, GameServerPacketPayload, IPeerSessionMessageContext <GameServerPacketPayload> > handlerService,
     [NotNull] IRegisterable <int, ZoneClientSession> sessionRegisterable)
 {
     Logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     HandlerService      = handlerService ?? throw new ArgumentNullException(nameof(handlerService));
     SessionRegisterable = sessionRegisterable ?? throw new ArgumentNullException(nameof(sessionRegisterable));
 }
Beispiel #9
0
        /// <inheritdoc />
        public AuthServerClientSession(IManagedNetworkServerClient <AuthenticationServerPayload, AuthenticationClientPayload> internalManagedNetworkClient, SessionDetails details,
                                       [NotNull] MessageHandlerService <AuthenticationClientPayload, AuthenticationServerPayload, IPeerSessionMessageContext <AuthenticationServerPayload> > authMessageHandlerService)
            : base(internalManagedNetworkClient, details)
        {
            if (authMessageHandlerService == null)
            {
                throw new ArgumentNullException(nameof(authMessageHandlerService));
            }

            AuthMessageHandlerService = authMessageHandlerService;
        }
Beispiel #10
0
 public HackyInstanceSharedClientData([NotNull] INetworkSerializationService serializerService,
                                      [JetBrains.Annotations.NotNull] MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> messageHandler,
                                      [JetBrains.Annotations.NotNull] IPeerMessageContextFactory messageContextFactory,
                                      [JetBrains.Annotations.NotNull] IConnectionService connectionService,
                                      [JetBrains.Annotations.NotNull] IPeerPayloadSendService <GameClientPacketPayload> sendService)
 {
     SerializerService     = serializerService ?? throw new ArgumentNullException(nameof(serializerService));
     MessageHandler        = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));
     MessageContextFactory = messageContextFactory ?? throw new ArgumentNullException(nameof(messageContextFactory));
     ConnectionService     = connectionService ?? throw new ArgumentNullException(nameof(connectionService));
     SendService           = sendService ?? throw new ArgumentNullException(nameof(sendService));
 }
Beispiel #11
0
 public View(DiscordService discord,
             MessageHandlerService messageHandler,
             ReactionHandlerService reactionHandler,
             InteractiveManager interactive,
             FeedChannelUpdateService feedChannelUpdater)
 {
     _discord            = discord;
     _messageHandler     = messageHandler;
     _reactionHandler    = reactionHandler;
     _interactive        = interactive;
     _feedChannelUpdater = feedChannelUpdater;
 }
Beispiel #12
0
        /// <summary>
        /// Implements must override this and implement domain-specific message handling logic.
        /// </summary>
        /// <param name="message">The message to handle.</param>
        /// <param name="context">The actor message context.</param>
        /// <returns>True if the message was successfully handled.</returns>
        protected Task <bool> HandleMessageAsync(EntityActorMessage message, EntityActorMessageContext context)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(MessageHandlerService.HandleMessageAsync(context, message, CancellationToken.None));
        }
        /// <inheritdoc />
        public ProxiedManagedClientSession(IManagedNetworkServerClient <TPayloadWriteType, TPayloadReadType> internalManagedNetworkClient, SessionDetails details,
                                           [NotNull] MessageHandlerService <TPayloadReadType, TPayloadWriteType, TMessageContextType> authMessageHandlerService,
                                           IGenericMessageContextFactory <TPayloadWriteType, TMessageContextType> messageContextFactory)
            : base(internalManagedNetworkClient, details)
        {
            if (authMessageHandlerService == null)
            {
                throw new ArgumentNullException(nameof(authMessageHandlerService));
            }

            AuthMessageHandlerService = authMessageHandlerService;
            MessageContextFactory     = messageContextFactory;
        }
 /// <inheritdoc />
 public GameNetworkClient(MessageHandlerService <GameServerPacketPayload, GameClientPacketPayload> handlers, ILog logger, IPeerMessageContextFactory messageContextFactory)
     : base(handlers, logger, messageContextFactory)
 {
 }
Beispiel #15
0
 /// <inheritdoc />
 public GenericProxiedManagedClientSession(IManagedNetworkServerClient <TPayloadWriteType, TPayloadReadType> internalManagedNetworkClient, SessionDetails details, [NotNull] MessageHandlerService <TPayloadReadType, TPayloadWriteType, IProxiedMessageContext <TPayloadWriteType, TPayloadReadType> > authMessageHandlerService, IGenericMessageContextFactory <TPayloadWriteType, IProxiedMessageContext <TPayloadWriteType, TPayloadReadType> > messageContextFactory)
     : base(internalManagedNetworkClient, details, authMessageHandlerService, messageContextFactory)
 {
 }