Ejemplo n.º 1
0
 public void BroadcastMessage(ITypedMessage typedMessage, ushort from, ushort except = 0xFFFF)
 {
     try
     {
         if (!typedMessage.GetMessageType().OnlyBroadcasted())
         {
             throw new DnmpException("Message is not broadcastable");
         }
         foreach (var client in realClient.ClientsById.Values.Where(x =>
                                                                    x.ParentId == realClient.SelfClient.Id || x.Id == realClient.SelfClient.ParentId))
         {
             if (client.Id == except)
             {
                 continue;
             }
             if (typedMessage.GetMessageType() == MessageType.DataBroadcast)
             {
                 client.DataBytesSent += typedMessage.GetBytes().Length;
             }
             SendReliableMessage(typedMessage, from, 0xFFFF, client.Id, client.EndPoint, MessageFlags.IsRedirected);
         }
     }
     catch (Exception)
     {
         if (realClient.CurrentStatus == DnmpClient.ClientStatus.Disconnecting ||
             realClient.CurrentStatus == DnmpClient.ClientStatus.NotConnected)
         {
             return;
         }
         throw;
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <Type> GetHandlersTypesForMessage(ITypedMessage message)
        {
            List <Type> handlerTypes;

            _typeMessageHandlers.TryGetValue(message.AssemblyQualifiedTypeName, out handlerTypes);
            return(handlerTypes);
        }
 protected override void Given()
 {
     _message = JsonTypedMessage.FromMessage(new PrototypeMessage());
     _module = new PrototypeModule();
     _factory = TypedMessageHandlerFactory.ForMessage(_message);
     _handler = _factory.GetHandlers(_module).Single();
 }
 protected override void Given()
 {
     _message = JsonTypedMessage.FromMessage(new PrototypeMessage());
     _module  = new PrototypeModule();
     _factory = TypedMessageHandlerFactory.ForMessage(_message);
     _handler = _factory.GetHandlers(_module).Single();
 }
Ejemplo n.º 5
0
 public void SendReliableMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId,
                                 ushort realDestinationId, IEndPoint to, MessageFlags messageFlags = MessageFlags.None)
 {
     try
     {
         if (!typedMessage.GetMessageType().IsReliable())
         {
             throw new DnmpException("Message is not reliable");
         }
         var id          = Guid.NewGuid();
         var message     = new BaseMessage(typedMessage, sourceId, destinationId, realClient.SelfClient?.Id ?? 0xFFFF, realDestinationId, id, messageFlags);
         var messageInfo = new BaseMessagePair
         {
             Message  = message,
             EndPoint = to
         };
         reliableMessages.TryAdd(id, messageInfo);
         SendBaseMessage(message, to);
         EventQueue.AddEvent(ReliableCallback, new KeyValuePair <Guid, BaseMessagePair>(id, messageInfo),
                             DateTime.Now.AddMilliseconds(500), id);
     }
     catch (Exception)
     {
         if (realClient.CurrentStatus == DnmpClient.ClientStatus.Disconnecting || realClient.CurrentStatus == DnmpClient.ClientStatus.NotConnected)
         {
             return;
         }
         throw;
     }
 }
Ejemplo n.º 6
0
        public void Send(ITypedMessage message, NetEndPoint to)
        {
            ThreadChecker.AssertMainThread();

            this.sendInfoCollection.Enqueue(new SendInfo {
                message = message, to = to
            });
        }
        protected override void Given()
        {
            var registrations = new List <MessageModule> {
                new PrototypeModule()
            };

            _host    = HandlerTypeResolver.Init(registrations);
            _message = JsonTypedMessage.FromMessage(new PrototypeMessage());
        }
Ejemplo n.º 8
0
 public void SendReliableMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, MessageFlags messageFlags = MessageFlags.None)
 {
     SendReliableMessage(typedMessage, sourceId, destinationId,
                         realClient.ClientsById[destinationId].RedirectPing.Id == 0xFFFF
             ? realClient.ClientsById[destinationId].Id
             : realClient.ClientsById[realClient.ClientsById[destinationId].RedirectPing.Id].Id,
                         realClient.ClientsById[destinationId].RedirectPing.Id == 0xFFFF
             ? realClient.ClientsById[destinationId].EndPoint
             : realClient.ClientsById[realClient.ClientsById[destinationId].RedirectPing.Id].EndPoint, messageFlags);
 }
        public void SendBroadcast(ITypedMessage message, Predicate <TPlayer> predicate, Channel channel)
        {
            ThreadChecker.AssertMainThread();

            var sendValue = new SendValue()
            {
                message = message, predicate = predicate, channel = channel
            };

            this._playerCollection.ForEach(SendPredicate, sendValue);
        }
Ejemplo n.º 10
0
            public void Send(ITypedMessage message, Channel channel)
            {
                switch (channel)
                {
                case Channel.reliable: this.reliableChannel.Send(message); break;

                case Channel.unreliable:
                    if (!this.remoteIdentifiedEndPoint.HasValue)
                    {
                        break;
                    }
                    this.unreliableChannel.Send(message, this.remoteIdentifiedEndPoint.Value); break;
                }
            }
        public void Send(ITypedMessage message, Channel channel)
        {
            ThreadChecker.AssertMainThread();
            switch (channel)
            {
            case Channel.reliable:
                this.networkClient.reliableChannel.Send(message);
                break;

            case Channel.unreliable:
                var remote = this.networkClient.remoteEndPoint;
                this.networkClient.unreliableChannel.Send(message, remote);
                break;
            }
        }
 protected override void Given()
 {
     var registrations = new List<MessageModule> {new PrototypeModule()};
     _host = HandlerTypeResolver.Init(registrations);
     _message = JsonTypedMessage.FromMessage(new PrototypeMessage());
 }
Ejemplo n.º 13
0
 private TypedMessageHandlerFactory(ITypedMessage message)
 {
     _message = message;
 }
Ejemplo n.º 14
0
 public void SendReliableMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, IEndPoint to, MessageFlags messageFlags = MessageFlags.None)
 {
     SendReliableMessage(typedMessage, sourceId, destinationId, destinationId, to, messageFlags);
 }
Ejemplo n.º 15
0
 public BaseMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, Guid id = new Guid(), MessageFlags messageFlags = MessageFlags.None) :
     this(typedMessage, sourceId, destinationId, sourceId, destinationId, id, messageFlags)
 {
 }
Ejemplo n.º 16
0
 public MessageAdapter(ITypedMessage inner)
 {
     _inner = inner;
 }
Ejemplo n.º 17
0
 public BaseMessage(ITypedMessage typedMessage, ushort sourceId, ushort destinationId, ushort realSourceId, ushort realDestinationId, Guid id = new Guid(), MessageFlags messageFlags = MessageFlags.None) :
     this(typedMessage.GetBytes(), typedMessage.GetMessageType(), sourceId, destinationId, realSourceId, realDestinationId, id, messageFlags)
 {
 }
Ejemplo n.º 18
0
 public void Handle(ITypedMessage message)
 {
     _innerHandler.Invoke(new MessageAdapter <T>(message));
 }
 public IEnumerable<Type> GetHandlersTypesForMessage(ITypedMessage message)
 {
     List<Type> handlerTypes;
     _typeMessageHandlers.TryGetValue(message.AssemblyQualifiedTypeName, out handlerTypes);
     return handlerTypes;
 }
Ejemplo n.º 20
0
 public static IMessageHandlerFactory ForMessage(ITypedMessage message)
 {
     return(new TypedMessageHandlerFactory(message));
 }
Ejemplo n.º 21
0
 public bool MessageHandlersExist(ITypedMessage message)
 {
     return(_typeMessageHandlers.ContainsKey(message.AssemblyQualifiedTypeName));
 }
        public void Send(ITypedMessage message)
        {
            ThreadChecker.AssertMainThread();

            this.writer.Write(message);
        }