protected override void Encode(IChannelHandlerContext context, SendContext message, List <object> output)
        {
            var type       = message.Message.GetType();
            var isInternal = RmiMessageFactory.Default.ContainsType(type);
            var factory    = isInternal
                ? RmiMessageFactory.Default
                : _userMessageFactories.FirstOrDefault(userFactory => userFactory.ContainsType(type));

            if (factory == null)
            {
                throw new ProudException($"No {nameof(MessageFactory)} found for message {type.FullName}");
            }

            var opCode = factory.GetOpCode(type);
            var buffer = context.Allocator.Buffer(2);

            using (var w = new WriteOnlyByteBufferStream(buffer, false).ToBinaryWriter(false))
            {
                w.Write(opCode);
                try
                {
                    _serializer.Serialize(w, message.Message);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Unable to serialize {message.Message.GetType().FullName}", ex);
                }
            }

            message.Message = buffer;
            output.Add(message);
        }
Beispiel #2
0
            public void Serialize(BlubSerializer serializer, BinaryWriter writer, NotifyServerConnectionHintMessage value)
            {
                var pubKey       = DotNetUtilities.GetRsaPublicKey(value.PublicKey);
                var pubKeyStruct = new RsaPublicKeyStructure(pubKey.Modulus, pubKey.Exponent);
                var encodedKey   = pubKeyStruct.GetDerEncoded();

                serializer.Serialize(writer, value.Config);
                writer.WriteStruct(encodedKey);
            }
Beispiel #3
0
        public static void Encode(BlubSerializer serializer, ICoreMessage message, IByteBuffer buffer)
        {
            var opCode = CoreMessageFactory.Default.GetOpCode(message.GetType());

            using (var w = new WriteOnlyByteBufferStream(buffer, false).ToBinaryWriter(false))
            {
                w.WriteEnum(opCode);
                serializer.Serialize(w, (object)message);
            }
        }
Beispiel #4
0
        public static byte[] Encode(BlubSerializer serializer, ICoreMessage message)
        {
            var opCode = CoreMessageFactory.Default.GetOpCode(message.GetType());

            using (var w = new MemoryStream().ToBinaryWriter(false))
            {
                w.WriteEnum(opCode);
                serializer.Serialize(w, (object)message);
                return(w.ToArray());
            }
        }
        public async Task <bool> OnHandle(MessageContext context, CNewShopUpdateCheckReqMessage message)
        {
            var session = context.Session;

            var version = _gameDataService.ShopVersion;
            var flags   = ShopResourceType.None;

            if (message.PriceVersion != version)
            {
                flags |= ShopResourceType.Price;
            }

            if (message.EffectVersion != version)
            {
                flags |= ShopResourceType.Effect;
            }

            if (message.ItemVersion != version)
            {
                flags |= ShopResourceType.Item;
            }

            session.Send(new SNewShopUpdateCheckAckMessage
            {
                PriceVersion      = version,
                EffectVersion     = version,
                ItemVersion       = version,
                UniqueItemVersion = message.UniqueItemVersion,
                Flags             = flags
            });

            if (flags == ShopResourceType.None)
            {
                return(true);
            }

            foreach (var pair in _shopResourceSelector)
            {
                if (!flags.HasFlag(pair.Key))
                {
                    continue;
                }

                using (var w = new BinaryWriter(new MemoryStream()))
                {
                    _serializer.Serialize(w, pair.Value(_gameDataService));
                    var data = w.ToArray();
                    var decompressedLength = data.Length;
                    var compressed         = data.CompressLZO();
                    session.Send(new SNewShopUpdateInfoAckMessage(pair.Key,
                                                                  compressed, (uint)compressed.Length, (uint)decompressedLength, version));
                }
            }

            // TODO unique item (What is this even?)
            // using (var w = new BinaryWriter(new MemoryStream()))
            // {
            //     w.Write(0);
            //
            //     session.Send(new SNewShopUpdateInfoAckMessage
            //     {
            //         Type = ShopResourceType.UniqueItem,
            //         Data = w.ToArray(),
            //         Version = version
            //     });
            // }

            return(true);
        }