public void Test_Can_Serializer_MovementPacket_With_PathMovementData()
        {
            //arrange
            Unity3DProtobufPayloadRegister payloadRegister = new Unity3DProtobufPayloadRegister();

            payloadRegister.RegisterDefaults();
            payloadRegister.Register(ZoneServerMetadataMarker.ClientPayloadTypesByOpcode, ZoneServerMetadataMarker.ServerPayloadTypesByOpcode);
            GladNet.ProtobufNetGladNetSerializerAdapter gladnetProtobuf = new ProtobufNetGladNetSerializerAdapter(PrefixStyle.Fixed32);

            //act
            MovementDataUpdateEventPayload payload = new MovementDataUpdateEventPayload(new AssociatedMovementData[]
            {
                new AssociatedMovementData(new NetworkEntityGuid(55), new PathBasedMovementData(new Vector3[]
                {
                    new Vector3(1, 2, 3),
                    new Vector3(2, 3, 4)
                }, 55)),
            });

            byte[] serialize = gladnetProtobuf.Serialize(payload);

            //assert
            Assert.NotNull(serialize);
            Assert.IsNotEmpty(serialize);
        }
        /// <inheritdoc />
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register <IAuthenticationService>(context =>
            {
                IServiceDiscoveryService serviceDiscovery = context.Resolve <IServiceDiscoveryService>();

                return(new AsyncEndpointAuthenticationService(QueryForRemoteServiceEndpoint(serviceDiscovery, "Authentication"), new RefitSettings()
                {
                    HttpMessageHandlerFactory = () => new FiddlerEnabledWebProxyHandler()
                }));
            });

            //TODO: We should do this only once, so we should move this to it's own special setup scene for one-time stuff.
            Unity3DProtobufPayloadRegister payloadRegister = new Unity3DProtobufPayloadRegister();

            payloadRegister.RegisterDefaults();
            payloadRegister.Register(ZoneServerMetadataMarker.ClientPayloadTypesByOpcode, ZoneServerMetadataMarker.ServerPayloadTypesByOpcode);
        }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            ProtobufNetGladNetSerializerAdapter serializer = new ProtobufNetGladNetSerializerAdapter(PrefixStyle.Fixed32);

            Unity3DProtobufPayloadRegister payloadRegister = new Unity3DProtobufPayloadRegister();

            payloadRegister.RegisterDefaults();

            payloadRegister.Register(ZoneServerMetadataMarker.ClientPayloadTypesByOpcode, ZoneServerMetadataMarker.ServerPayloadTypesByOpcode);

            var client = new DotNetTcpClientNetworkClient()
                         .AddHeaderlessNetworkMessageReading(serializer)
                         .For <GameServerPacketPayload, GameClientPacketPayload, IGamePacketPayload>()
                         .Build()
                         .AsManaged(new ConsoleLogger(LogLevel.All));

            await client.ConnectAsync(IPAddress.Parse("127.0.0.1"), 5006);

            Thread.Sleep(3000);

            Console.WriteLine("Enter Character ID for test:");

            int characterId = int.Parse(Console.ReadLine());

            await client.SendMessage(new ClientSessionClaimRequestPayload("Test", characterId));

            int packetCount = 0;

            try
            {
                while (true)
                {
                    NetworkIncomingMessage <GameServerPacketPayload> message = await client.ReadMessageAsync()
                                                                               .ConfigureAwait(false);

                    Console.WriteLine($"\n#{packetCount} - Recieved Message Type: {message.Payload.GetType().Name}");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        /// <inheritdoc />
        protected override void Load(ContainerBuilder builder)
        {
            //https://stackoverflow.com/questions/4926676/mono-https-webrequest-fails-with-the-authentication-or-decryption-has-failed
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            ServicePointManager.CheckCertificateRevocationList = false;

            Unity3DProtobufPayloadRegister payloadRegister = new Unity3DProtobufPayloadRegister();

            payloadRegister.RegisterDefaults();
            payloadRegister.Register(ZoneServerMetadataMarker.ClientPayloadTypesByOpcode, ZoneServerMetadataMarker.ServerPayloadTypesByOpcode);

            //Set the sync context
            UnityExtended.InitializeSyncContext();

            //TODO: We need to not have such a high rate of Update and need to add prediction.
            Application.targetFrameRate = 60;

            builder.RegisterInstance(new ProtobufNetGladNetSerializerAdapter(PrefixStyle.Fixed32))
            .As <INetworkSerializationService>();

            builder.RegisterType <ZoneServerDefaultRequestHandler>()
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.RegisterInstance(new UnityLogger(LogLevel.All))
            .As <ILog>();

            builder.RegisterType <MessageHandlerService <GameClientPacketPayload, GameServerPacketPayload, IPeerSessionMessageContext <GameServerPacketPayload> > >()
            .As <MessageHandlerService <GameClientPacketPayload, GameServerPacketPayload, IPeerSessionMessageContext <GameServerPacketPayload> > >()
            .SingleInstance();

            builder.RegisterInstance(new DefaultSessionCollection())
            .As <IRegisterable <int, ZoneClientSession> >()
            .As <ISessionCollection>()
            .SingleInstance();

            builder.RegisterInstance(new NetworkAddressInfo(IPAddress.Parse("192.168.0.3"), 5006))
            .As <NetworkAddressInfo>()
            .SingleInstance()
            .ExternallyOwned();

            builder.RegisterType <ZoneServerApplicationBase>()
            .SingleInstance()
            .AsSelf();

            RegisterEntityMappableCollections(builder);

            //TODO: We should automate the registeration of message senders
            builder.RegisterType <VisibilityChangeMessageSender>()
            .AsImplementedInterfaces()
            .AsSelf();

            builder.RegisterType <DefaultGameObjectToEntityMappable>()
            .As <IReadonlyGameObjectToEntityMappable>()
            .As <IGameObjectToEntityMappable>()
            .SingleInstance();

            RegisterPlayerFactoryServices(builder);

            builder.RegisterType <DefaultEntityFactory <DefaultEntityCreationContext> >()
            .AsImplementedInterfaces()
            .AsSelf()
            .SingleInstance();

            builder.RegisterType <GenericMessageSender <PlayerSelfSpawnEventPayload> >()
            .AsSelf()
            .AsImplementedInterfaces();

            builder.RegisterType <DefaultManagedSessionFactory>()
            .AsImplementedInterfaces();

            //TODO: Extract this into a handlers registrar

            //This is for mapping connection IDs to the main controlled EntityGuid.
            builder.RegisterInstance(new ConnectionEntityMap())
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.RegisterType <PlayerEntityGuidEnumerable>()
            .As <IPlayerEntityGuidEnumerable>()
            .AsSelf();

            builder.RegisterType <MovementUpdateMessageSender>()
            .As <INetworkMessageSender <EntityMovementMessageContext> >()
            .AsSelf();

            //Keep this one here, zoneserver needs it.
            builder.Register <IServiceDiscoveryService>(context => RestService.For <IServiceDiscoveryService>(@"http://192.168.0.3:5000"));
            builder.Register(context =>
            {
                IServiceDiscoveryService serviceDiscovery = context.Resolve <IServiceDiscoveryService>();

                return(new AsyncEndpointZoneServerToGameServerService(QueryForRemoteServiceEndpoint(serviceDiscovery, "GameServer")));
            })
            .As <IZoneServerToGameServerClient>()
            .SingleInstance();

            builder.RegisterType <DefaultMovementHandlerService>()
            .As <IMovementDataHandlerService>()
            .AsSelf();

            builder.RegisterType <PathMovementBlockHandler>()
            .AsImplementedInterfaces()
            .AsSelf();

            builder.RegisterType <PositionChangeMovementBlockHandler>()
            .AsImplementedInterfaces()
            .AsSelf();

            builder.RegisterType <UtcNowNetworkTimeService>()
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.RegisterType <FieldValueUpdateFactory>()
            .AsSelf()
            .AsImplementedInterfaces();

            RegisterEntityDestructionServices(builder);

            //Honestly, before running this I think it'll be a MIRACLE if this actually works
            //Registering the generic networkmessage sender
            builder.RegisterGeneric(typeof(GenericMessageSender <>))
            .As(typeof(INetworkMessageSender <>).MakeGenericType(typeof(GenericSingleTargetMessageContext <>)))
            .SingleInstance();

            RegisterLockingPolicies(builder);

            //IPhysicsTriggerEventSubscribable TriggerEventSubscribable
            builder.RegisterInstance(GlobalPhysicsEventSystem.Instance)
            .AsImplementedInterfaces()
            .SingleInstance();
        }