コード例 #1
0
 public static void InstallBasicClientHandlers(MessageRouter messageRouter, NetworkSystems networkSystems)
 {
     messageRouter
     .RegisterHandler(DefaultMessageHandlers.CreateObject(networkSystems.ObjectStore))
     .RegisterHandler(DefaultMessageHandlers.DeleteObject(networkSystems.ObjectStore))
     .RegisterHandler(DefaultMessageHandlers.ToObject(networkSystems.ObjectStore));
 }
コード例 #2
0
 public static void InstallBasicClientHandlers(MessageRouter messageRouter, NetworkSystems networkSystems, IDictionary <Guid, GameObject> preExistingObjects)
 {
     messageRouter
     .RegisterHandler(DefaultMessageHandlers.ReplicatePreExistingObject(networkSystems.ObjectStore, preExistingObjects))
     .RegisterHandler(DefaultMessageHandlers.CreateObject(networkSystems.ObjectMessageParser, networkSystems.ObjectStore))
     .RegisterHandler(DefaultMessageHandlers.DeleteObject(networkSystems.ObjectStore))
     .RegisterHandler(DefaultMessageHandlers.ToObject(networkSystems.ObjectMessageParser, networkSystems.ObjectStore));
 }
コード例 #3
0
        public static void InstallBasicServerHandlers(MessageRouter messageRouter,
                                                      IClock clock, IClock fixedClock, NetworkSystems networkSystems)
        {
            var messagePools  = networkSystems.MessagePool;
            var messageSender = networkSystems.MessageSender;

            messageRouter
            .RegisterHandler(DefaultMessageHandlers.Ping(clock, fixedClock, messagePools.GetPool <BasicMessage.Pong>(), messageSender))
            .RegisterHandler(DefaultMessageHandlers.ToObject(networkSystems.ObjectMessageParser, networkSystems.ObjectStore));
        }
コード例 #4
0
        public static NetworkSystems Create(
            IConnectionTransporter transporter,
            IConnectionlessTransporter connectionlessTransporter,
            TransportRouterConfig groupRouterConfig,
            TransportGroupId objectGroupId,
            IReadOnlyDictionary <ObjectType, Func <GameObject> > replicatedObjectPools,
            IMessageSender messageSender,
            IConnectionManager connectionManager,
            ILatencyInfo latencyInfo,
            DependencyContainer globalDependencies)
        {
            var connectionlessMessageSender = new ConnectionlessMessageSender(connectionlessTransporter);

            var messagePools        = MessageTypes.CreateMessagePool(MessageTypes.NetworkMessageTypes);
            var objectMessagePools  = MessageTypes.CreateMessagePool(MessageTypes.ObjectMessageTypes);
            var objectMessageParser = new ObjectMessageParser(MessageTypes.ObjectMessageTypes);

            var dependencies = globalDependencies.Copy();

            dependencies.AddDependency("latencyInfo", latencyInfo);
            foreach (var pool in messagePools.Pools)
            {
                dependencies.AddDependency(pool.ToString(), pool);
            }
            foreach (var pool in objectMessagePools.Pools)
            {
                dependencies.AddDependency(pool.ToString(), pool);
            }

            var groupRouter = new TransportGroupRouter(transporter, groupRouterConfig);

            Func <GameObject, ObjectMessageRouter> objectMessageDispatcherFactory =
                gameObject => new ObjectMessageRouter(MessageTypes.ObjectMessageTypes, gameObject);
            var networkMessagePool = new BasicObjectPool <ReplicatedObjectStore.ObjectMessageSender.MulticastNetworkMessage>(
                pool => new ReplicatedObjectStore.ObjectMessageSender.MulticastNetworkMessage(pool, MessageTypes.NetworkMessageTypes[typeof(BasicMessage.ToObject)]));
            var objectMessageSenderFactory = ReplicatedObjectStore.ObjectMessageSender.CreateFactory(
                messageSender,
                groupRouter,
                objectGroupId,
                networkMessagePool);

            var replicationDecorator = ReplicatedObjectStore.GameObjectReplicationDecorator(objectMessageDispatcherFactory,
                                                                                            objectMessageSenderFactory,
                                                                                            dependencies,
                                                                                            MessageTypes.ObjectMessageTypes);
            int replicatedObjectCapacity = 256;
            var replicatedObjectStore    = new ReplicatedObjectStore(replicatedObjectPools,
                                                                     replicationDecorator, replicatedObjectCapacity);

            var replicator = new Replicator(replicatedObjectStore,
                                            groupRouter.GetConnectionGroup(objectGroupId),
                                            new NetworkReplicator(messageSender, messagePools),
                                            objectMessageParser);

            var defaultMessageRouter = new MessageRouter(MessageTypes.NetworkMessageTypes, latencyInfo);

            groupRouter.SetDataHandler(groupRouterConfig.DefaultGroup, defaultMessageRouter);

            return(new NetworkSystems(
                       messageSender,
                       connectionlessMessageSender,
                       messagePools,
                       connectionManager,
                       groupRouter,
                       defaultMessageRouter,
                       replicatedObjectStore,
                       MessageTypes.NetworkMessageTypes,
                       MessageTypes.ObjectMessageTypes,
                       replicator,
                       objectMessageParser));
        }
コード例 #5
0
 public static MessageRouter RegisterHandler <T>(this MessageRouter router, Action <ConnectionId, IPEndPoint, T> handler) where T : IMessage, new()
 {
     return(router.RegisterHandler <T>((connectionId, endpoint, msg, reader) => handler(connectionId, endpoint, msg)));
 }
コード例 #6
0
 public static MessageRouter RegisterHandler <T>(this MessageRouter router, Action <MessageMetaData, T> handler) where T : IMessage, new()
 {
     return(router.RegisterHandler <T>((metadata, msg, reader) => handler(metadata, msg)));
 }