public void Init()
        {
            foreach (IClientEvent eventToHandle in this.options.EventsToHandle)
            {
                this.logger.LogDebug("Create subscription for {0}", eventToHandle.NodeEventType);

                async Task callback(EventBase eventBase)
                {
                    Type childType = eventBase.GetType();

                    IClientEvent clientEvent = this.options.EventsToHandle.FirstOrDefault(ev => ev.NodeEventType == childType);

                    if (clientEvent == null)
                    {
                        return;
                    }

                    clientEvent.BuildFrom(eventBase);

                    await this.eventsHub.SendToClientsAsync(clientEvent).ConfigureAwait(false);
                }

                this.signals.Subscribe(eventToHandle.NodeEventType, callback);
            }
        }
Beispiel #2
0
 public static bool IsPrivate(this IClientEvent @event)
 {
     if (@event == null)
     {
         throw new ArgumentNullException(nameof(@event));
     }
     return(@event.HasAttribute <PrivateAttribute>());
 }
Beispiel #3
0
 private async Task Process(IClientEvent @event)
 {
     if (_state != BotState.Started)
     {
         return;
     }
     await _entryBehaviour.Handle(new BotNotification <IClientEvent>(@event, _context));
 }
Beispiel #4
0
 public static EventEnvelope ToEnvelope(this IClientEvent @event)
 {
     if (@event == null)
     {
         throw new ArgumentNullException(nameof(@event));
     }
     return(new EventEnvelope(@event, @event.GetType().Name));
 }
Beispiel #5
0
        public byte[] CreateBinary(IClientEvent ev)
        {
            var         body     = ev.GetBytes();
            List <byte> header   = CreateHeader(ev.EventName, body.Count).ToList();
            var         checksum = hashAlgorithm.ComputeHash(body.Concat(header).ToArray());

            return(header.Concat(checksum.Reverse()).Concat(body).ToArray());
        }
Beispiel #6
0
        // ReSharper disable once UnusedMember.Global
        // This is invoked through reflection
        public void OnEvent(EventBase @event)
        {
            Type         childType   = @event.GetType();
            IClientEvent clientEvent = this.options.EventsToHandle.FirstOrDefault(ev => ev.NodeEventType == childType);

            if (clientEvent == null)
            {
                return;
            }
            clientEvent.BuildFrom(@event);
            this.eventsHub.SendToClients(clientEvent).ConfigureAwait(false).GetAwaiter().GetResult();
        }
Beispiel #7
0
        public async Task SendToClientsAsync(IClientEvent @event)
        {
            // Check if any there are any connected clients
            if (this.Clients == null)
            {
                return;
            }

            try
            {
                await this.Clients.All.SendAsync("receiveEvent", @event);
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Error sending to clients");
            }
        }
Beispiel #8
0
        private IEnumerator MoveToNextFrame()
        {
            // 自分のactionの送信
            int          currentFrame = Time.frameCount - startFrame;
            IClientEvent ev           = CreateActionEvent(currentFrame);

            tcpClient.Send(ev);
            yield return(null);

            // 他プレイヤーの行動待機
            int lagCounter = 0;

            while (currentFrame > latestFrame)
            {
                if (lagCounter++ % 60 != 0)
                {
                    break;
                }
                serverEventManager.CallEvents();
            }

            game.UpdateGame(this, ActionBuffers);
        }
Beispiel #9
0
        private void Handle(IClientEvent @event)
        {
            EnsureIsNotDisposed();
            if (@event == null)
            {
                _context.Logger.Error("[Bot:{BotId}:{UserId}] Received null event.", _context.BotId, _context.UserId);
                return;
            }
            if (_state == BotState.Stopped)
            {
                throw new InvalidOperationException("Bot is stopped.");
            }
            _received.Increment();
            _queueSize.Write();
            _context.Logger.Debug("[Bot:{BotId}:{UserId}]: Received {EventType} {@Event}",
                                  _context.BotId,
                                  _context.UserId,
                                  @event.GetType().Name,
                                  @event);
            if (_cancellationToken.IsCancellationRequested)
            {
                _context.Logger.Warning("[Bot:{BotId}:{UserId}] Bot execution cancelled.");
                Stop(new TaskCanceledException("Bot execution was cancelled."));
                return;
            }
            var posted = _processor.Post(@event);

            if (!posted)
            {
                _context.Logger.Warning("[Bot:{BotId}:{UserId}] Failed to accept {EventType}. Queue length exceeded.",
                                        _context.BotId,
                                        _context.UserId,
                                        @event.GetType().Name);
                Stop(new InvalidOperationException("Bot queue is too large."));
            }
        }
Beispiel #10
0
 public static bool IsPublic(this IClientEvent @event)
 {
     return([email protected]());
 }
Beispiel #11
0
        public void Send(IClientEvent ev)
        {
            var data = sender.CreateBinary(ev);

            Send(data);
        }
Beispiel #12
0
 private void OnClientEvent(IClientEvent @event)
 {
     Handle(@event);
 }
Beispiel #13
0
 private Task OnNext(IClientEvent @event, StreamSequenceToken token)
 {
     _subject.OnNext(@event);
     return(Task.CompletedTask);
 }