Exemplo n.º 1
0
            public void Serialize(BlubSerializer serializer, BinaryWriter writer, DamageRemoteInfoMessage value)
            {
                writer.Write(value.Target);
                writer.WriteEnum(value.AttackAttribute);
                writer.Write(value.GameTime);
                writer.Write(value.Source);
                writer.WriteRotation(value.Rotation);
                writer.WriteCompressed(value.Position);
                writer.WriteCompressed(value.Unk);
                writer.WriteCompressed(value.Damage);

                var ls = new List <byte>();
                var bw = new BitStreamWriter(ls);

                bw.Write(value.Flag1, 2);
                bw.Write(value.Flag2, 1);
                bw.Write(value.Flag3, 1);
                bw.Write(value.Flag4, 1);
                bw.Write(value.Flag5, 3);

                bw.Write(value.Flag6, 4);
                bw.Write(value.Flag7, 4);

                writer.Write(ls);
            }
Exemplo n.º 2
0
            public DamageRemoteInfoMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var message = new DamageRemoteInfoMessage();

                message.Target          = reader.ReadUInt16();
                message.AttackAttribute = reader.ReadEnum <AttackAttribute>();
                message.GameTime        = reader.ReadUInt32();
                message.Source          = reader.ReadUInt16();
                message.Rotation        = reader.ReadRotation();
                message.Position        = reader.ReadCompressedVector3();
                message.Unk             = reader.ReadCompressedFloat();
                message.Damage          = reader.ReadCompressedFloat();

                var br = new BitStreamReader(reader.ReadBytes(2));

                message.Flag1 = br.ReadByte(2);
                message.Flag2 = br.ReadByte(1);
                message.Flag3 = br.ReadByte(1);
                message.Flag4 = br.ReadByte(1);
                message.Flag5 = br.ReadByte(3);

                message.Flag6 = br.ReadByte(4);
                message.Flag7 = br.ReadByte(4);

                return(message);
            }
Exemplo n.º 3
0
 public RelayHandler(ISessionManagerFactory sessionManagerFactory, UdpSocketManager udpSocketManager,
                     BlubSerializer serializer)
 {
     _magicNumberSessionManager = sessionManagerFactory.GetSessionManager <Guid>(SessionManagerType.MagicNumber);
     _udpSocketManager          = udpSocketManager;
     _serializer = serializer;
 }
 public static ICoreMessage Decode(BlubSerializer serializer, IByteBuffer buffer)
 {
     using (var r = new ReadOnlyByteBufferStream(buffer, false).ToBinaryReader(false))
     {
         var opCode = r.ReadEnum <ProudCoreOpCode>();
         return(CoreMessageFactory.Default.GetMessage(serializer, opCode, r));
     }
 }
Exemplo n.º 5
0
 public UdpHandler(ILogger <UdpHandler> logger, BlubSerializer serializer,
                   ISessionManagerFactory sessionManagerFactory)
 {
     _serializer = serializer;
     _logger     = logger;
     _magicNumberSessionManager = sessionManagerFactory.GetSessionManager <Guid>(SessionManagerType.MagicNumber);
     _udpSessionManager         = sessionManagerFactory.GetSessionManager <uint>(SessionManagerType.UdpId);
 }
Exemplo n.º 6
0
        public object GetMessage(BlubSerializer serializer, ushort opCode, Stream stream)
        {
            if (!_typeLookup.TryGetValue(opCode, out var type))
            {
                throw new ProudException($"No type found for opcode {opCode}");
            }

            return(serializer.Deserialize(stream, type));
        }
Exemplo n.º 7
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);
            }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        public object GetMessage(BlubSerializer serializer, ushort opCode, BinaryReader reader)
        {
            if (!_typeLookup.TryGetValue(opCode, out var type))
#if DEBUG
            { throw new ProudBadOpCodeException(opCode, reader.ReadToEnd()); }
#else
            { throw new ProudBadOpCodeException(opCode); }
#endif

            return(serializer.Deserialize(reader, type));
        }
Exemplo n.º 10
0
 public ResourceHandler(GameDataService gameDataService, BlubSerializer serializer)
 {
     _gameDataService      = gameDataService;
     _serializer           = serializer;
     _shopResourceSelector = new Dictionary <ShopResourceType, Func <GameDataService, object> >
     {
         [ShopResourceType.Price]  = x => x.ShopPrices,
         [ShopResourceType.Effect] = x => x.ShopEffects,
         [ShopResourceType.Item]   = x => x.ShopItems
     };
 }
Exemplo n.º 11
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());
            }
        }
Exemplo n.º 12
0
            public NotifyServerConnectionHintMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var config     = serializer.Deserialize <NetConfigDto>(reader);
                var encodedKey = reader.ReadStruct();
                var sequence   = (DerSequence)Asn1Object.FromByteArray(encodedKey);
                var modulus    = ((DerInteger)sequence[0]).Value.ToByteArrayUnsigned();
                var exponent   = ((DerInteger)sequence[1]).Value.ToByteArrayUnsigned();
                var publicKey  = new RSAParameters {
                    Exponent = exponent, Modulus = modulus
                };

                return(new NotifyServerConnectionHintMessage(config, publicKey));
            }
Exemplo n.º 13
0
        public void Serialize(BlubSerializer blubSerializer, BinaryWriter writer, ImmutableDictionary <int, ShopEffectGroup> value)
        {
            writer.Write(value.Count);
            foreach (var group in value.Values)
            {
                writer.WriteProudString(group.Id.ToString());

                writer.Write(group.Effects.Count);
                foreach (var effect in group.Effects)
                {
                    writer.Write(effect.Effect);
                }
            }
        }
Exemplo n.º 14
0
            public void Serialize(BlubSerializer serializer, BinaryWriter writer, SInventoryInfoAckMessage value)
            {
                using (var w2 = new BinaryWriter(new MemoryStream()))
                {
                    w2.Write((ushort)value.Items.Length);

                    var itemSerializer = serializer.GetSerializer <ItemDto>();
                    foreach (var item in value.Items)
                    {
                        itemSerializer.Serialize(serializer, w2, item);
                    }

                    var data = w2.ToArray().CompressLZO();
                    writer.WriteStruct(data);
                    writer.Write(data.Length);
                }
            }
Exemplo n.º 15
0
            public void Serialize(BlubSerializer serializer, BinaryWriter writer, SGameRoomListAckMessage value)
            {
                using (var w2 = new BinaryWriter(new MemoryStream()))
                {
                    w2.WriteEnum(value.ListType);
                    w2.Write((ushort)value.Rooms.Length);

                    var roomSerializer = serializer.GetSerializer <RoomDto>();
                    foreach (var room in value.Rooms)
                    {
                        roomSerializer.Serialize(serializer, w2, room);
                    }

                    var data = w2.ToArray().CompressLZO();
                    writer.WriteStruct(data);
                    writer.Write(data.Length);
                }
            }
Exemplo n.º 16
0
            public void Serialize(BlubSerializer serializer, BinaryWriter writer, SChannelPlayerListAckMessage value)
            {
                using (var w2 = new BinaryWriter(new MemoryStream()))
                {
                    w2.Write((ushort)value.UserData.Length);

                    var userDataSerializer = serializer.GetSerializer <UserDataWithNickDto>();
                    foreach (var userData in value.UserData)
                    {
                        userDataSerializer.Serialize(serializer, w2, userData);
                    }

                    var data       = w2.ToArray();
                    var compressed = data.CompressLZO();
                    writer.WriteStruct(compressed);
                    writer.Write(compressed.Length);
                }
            }
Exemplo n.º 17
0
        public void Serialize(BlubSerializer blubSerializer, BinaryWriter writer, ImmutableDictionary <ItemNumber, ShopItem> value)
        {
            writer.Write(value.Count);
            foreach (var item in value.Values)
            {
                writer.Write(item.ItemNumber);

                switch (item.Gender)
                {
                case Gender.Female:
                    writer.Write((uint)1);
                    break;

                case Gender.Male:
                    writer.Write((uint)0);
                    break;

                case Gender.None:
                    writer.Write((uint)2);
                    break;
                }

                writer.Write((ushort)item.License);
                writer.Write((ushort)item.ColorGroup);
                writer.Write((ushort)item.UniqueColorGroup);
                writer.Write((ushort)item.MinLevel);
                writer.Write((ushort)item.MaxLevel);
                writer.Write((ushort)item.MasterLevel);
                writer.Write(0); // RepairCost
                writer.Write(item.IsOneTimeUse);
                writer.Write(!item.IsDestroyable);

                writer.Write(item.ItemInfos.Count);
                foreach (var info in item.ItemInfos)
                {
                    writer.WriteProudString(info.IsEnabled ? "on" : "off");
                    writer.WriteEnum(info.PriceGroup.PriceType);
                    writer.Write((ushort)info.Discount);
                    writer.WriteProudString(info.PriceGroup.Id.ToString());
                    writer.WriteProudString(info.EffectGroup.Effects.Count > 0 ? info.EffectGroup.Id.ToString() : "");
                }
            }
        }
Exemplo n.º 18
0
            public SChannelPlayerListAckMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var compressed = reader.ReadStruct();

                reader.ReadInt32(); // length

                var decompressed = compressed.DecompressLZO(compressed.Length * 10);

                using (var r2 = decompressed.ToBinaryReader())
                {
                    var userDataSerializer = serializer.GetSerializer <UserDataWithNickDto>();
                    var userData           = new UserDataWithNickDto[r2.ReadInt16()];
                    for (var i = 0; i < userData.Length; i++)
                    {
                        userData[i] = userDataSerializer.Deserialize(serializer, r2);
                    }

                    return(new SChannelPlayerListAckMessage(userData));
                }
            }
Exemplo n.º 19
0
        public void Serialize(BlubSerializer blubSerializer, BinaryWriter writer, ImmutableDictionary <int, ShopPriceGroup> value)
        {
            writer.Write(value.Count);
            foreach (var group in value.Values)
            {
                writer.WriteProudString(group.Id.ToString());
                writer.WriteEnum(group.PriceType);

                writer.Write(group.Prices.Count);
                foreach (var price in group.Prices)
                {
                    writer.WriteEnum(price.PeriodType);
                    writer.Write(price.Period);
                    writer.Write(price.Price);
                    writer.Write(price.CanRefund);
                    writer.Write(price.Durability);
                    writer.Write(price.IsEnabled);
                }
            }
        }
Exemplo n.º 20
0
            public SInventoryInfoAckMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var message    = new SInventoryInfoAckMessage();
                var compressed = reader.ReadStruct();

                reader.ReadUInt32(); // length

                var decompressed = compressed.DecompressLZO(compressed.Length * 4);

                using (var r2 = decompressed.ToBinaryReader())
                {
                    message.Items = new ItemDto[r2.ReadInt16()];
                    var itemSerializer = serializer.GetSerializer <ItemDto>();
                    for (var i = 0; i < message.Items.Length; i++)
                    {
                        message.Items[i] = itemSerializer.Deserialize(serializer, r2);
                    }
                }

                return(message);
            }
Exemplo n.º 21
0
            public SGameRoomListAckMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var message    = new SGameRoomListAckMessage();
                var compressed = reader.ReadStruct();

                reader.ReadUInt32(); // length

                var decompressed = compressed.DecompressLZO(compressed.Length * 4);

                using (var r2 = decompressed.ToBinaryReader())
                {
                    message.ListType = r2.ReadEnum <ChannelInfoRequest>();
                    message.Rooms    = new RoomDto[r2.ReadInt16()];
                    var roomSerializer = serializer.GetSerializer <RoomDto>();
                    for (var i = 0; i < message.Rooms.Length; i++)
                    {
                        message.Rooms[i] = roomSerializer.Deserialize(serializer, r2);
                    }
                }

                return(message);
            }
Exemplo n.º 22
0
 public SendContextEncoder(BlubSerializer serializer)
 {
     _serializer = serializer;
 }
Exemplo n.º 23
0
 public MessageDecoder(BlubSerializer serializer, MessageFactory[] userMessageFactories)
 {
     _serializer           = serializer;
     _userMessageFactories = userMessageFactories;
 }
Exemplo n.º 24
0
        public ProudNetServerBuilder(IHostBuilder hostBuilder)
        {
            _hostBuilder = hostBuilder;
            _serializer  = new BlubSerializer();

            _hostBuilder.ConfigureServices((context, collection) =>
            {
                collection
                .AddOptions()

                // Logging
                .AddSingleton <ILoggerFactory, LoggerFactory>()
                .AddTransient <ILogger, Logger>()
                .AddTransient(typeof(ILogger <>), typeof(Logger <>))

                // Hosted services
                .AddSingleton <ISchedulerService, SchedulerService>()
                .AddSingleton <IProudNetServerService, ProudNetServerService>()
                .AddSingleton(_ => (IHostedService)_.GetRequiredService <ISchedulerService>())
                .AddSingleton(_ => (IHostedService)_.GetRequiredService <IProudNetServerService>())

                // Session managers
                .AddSingleton <ISessionManagerFactory>(x =>
                {
                    /*
                     * External code can access the default session manager(by host id lookup)
                     * by using the public ISessionManager interface
                     *
                     * Internal code can use the ISessionManagerFactory interface
                     * to request additional internal session managers
                     */
                    var schedulerService = x.GetRequiredService <ISchedulerService>();
                    var sessionManager   = new SessionManager(schedulerService);
                    return(new SessionManagerFactory(new Dictionary <SessionManagerType, object>
                    {
                        [SessionManagerType.HostId] = sessionManager,
                        [SessionManagerType.UdpId] = new SessionManager <uint>(schedulerService),
                        [SessionManagerType.MagicNumber] = new SessionManager <Guid>(schedulerService)
                    }));
                })
                .AddSingleton(_ => (ISessionManager)_.GetRequiredService <ISessionManagerFactory>()
                              .GetSessionManager <uint>(SessionManagerType.HostId))
                .AddSingleton(_serializer)
                .AddSingleton(new RSACryptoServiceProvider(1024))
                .AddSingleton <P2PGroupManager>()
                .AddSingleton <UdpSocketManager>()
                .AddTransient <UdpSocket>()

                // Pipeline handlers & en-/decoders
                .AddTransient <SessionHandler>()
                .AddTransient <ProudFrameDecoder>()
                .AddTransient <ProudFrameEncoder>()
                .AddTransient <MessageContextDecoder>()
                .AddTransient <CoreMessageDecoder>()
                .AddTransient <CoreMessageEncoder>()
                .AddTransient <SendContextEncoder>()
                .AddTransient <MessageDecoder>()
                .AddTransient <MessageEncoder>()
                .AddTransient <ErrorHandler>()
                .AddTransient <UdpHandler>()

                // User message factories
                .AddTransient(_ => _.GetServices <MessageFactory>().ToArray());
            });

            ConfigureSerializer(serializer =>
            {
                serializer.AddSerializer(new ArrayWithScalarSerializer());
                serializer.AddSerializer(new IPEndPointSerializer());
                serializer.AddSerializer(new StringSerializer());
            });
        }
Exemplo n.º 25
0
            public CompressedMessage Deserialize(BlubSerializer serializer, BinaryReader reader)
            {
                var length = reader.ReadScalar();

                return(new CompressedMessage(reader.ReadScalar(), reader.ReadBytes(length)));
            }
Exemplo n.º 26
0
 public ImmutableDictionary <int, ShopPriceGroup> Deserialize(BlubSerializer blubSerializer, BinaryReader reader)
 {
     // This is not needed
     throw new NotSupportedException();
 }
Exemplo n.º 27
0
 public ImmutableDictionary <ItemNumber, ShopItem> Deserialize(BlubSerializer blubSerializer, BinaryReader reader)
 {
     // This is not needed
     throw new NotSupportedException();
 }
Exemplo n.º 28
0
 public CoreMessageDecoder(BlubSerializer serializer)
 {
     _serializer = serializer;
 }
Exemplo n.º 29
0
 public void Serialize(BlubSerializer serializer, BinaryWriter writer, CompressedMessage value)
 {
     writer.WriteScalar(value.Data.Length);
     writer.WriteScalar(value.DecompressedLength);
     writer.Write(value.Data);
 }
Exemplo n.º 30
0
 public EventHandler(ILogger <EventHandler> logger, BlubSerializer serializer)
 {
     _logger     = logger;
     _serializer = serializer;
 }