#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
    protected override void OnCreateManager()
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
    {
        var reliabilityParams = new ReliableUtility.Parameters {
            WindowSize = 32
        };

        if (UnityEngine.Debug.isDebugBuild)
        {
            m_ClientPacketDelay = UnityEngine.PlayerPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDelay");
            m_ClientPacketDrop  = UnityEngine.PlayerPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDropRate");
            int networkRate = 60; // TODO: read from some better place
            // All 3 packet types every frame stored for maximum delay, doubled for safety margin
            int maxPackets      = 2 * (networkRate * 3 * m_ClientPacketDelay + 999) / 1000;
            var simulatorParams = new SimulatorUtility.Parameters
            {
                MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = m_ClientPacketDelay, PacketDropPercentage = m_ClientPacketDrop
            };
            m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams);
            UnityEngine.Debug.Log("Using simulator with latency=" + m_ClientPacketDelay + " packet drop=" + m_ClientPacketDrop);
        }
        else
        {
            m_Driver = new UdpNetworkDriver(reliabilityParams);
        }

        m_ConcurrentDriver   = m_Driver.ToConcurrent();
        m_UnreliablePipeline = NetworkPipeline.Null;
        m_ReliablePipeline   = NetworkPipeline.Null;
        m_DriverListening    = false;
        m_Barrier            = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
        numNetworkIds        = new NativeArray <int>(1, Allocator.Persistent);
        freeNetworkIds       = new NativeQueue <int>(Allocator.Persistent);
        rpcQueue             = InternalRpcCollection.GetRpcQueue <RpcSetNetworkId>();
    }
Beispiel #2
0
 protected override void OnCreateManager()
 {
     m_Barrier    = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
     m_RpcQueue   = World.GetOrCreateSystem <MultiplayerSampleRpcSystem>().GetRpcQueue <RpcLoadLevel>();
     m_LevelGroup = GetEntityQuery(ComponentType.ReadWrite <LevelComponent>());
     RequireSingletonForUpdate <ServerSettings>();
 }
Beispiel #3
0
        public async Task <T> ExecuteOnRemotePeer <T>(string?remotePeerID,
                                                      string methodName, params object[] methodParameters)
        {
            // Enqueue in the corresponding channel and await call
            try {
                var method  = new RpcMethod(methodName, methodParameters);
                var call    = PrepareCall(remotePeerID, method);
                var channel = GetChannel(remotePeerID);
                if (channel == null)
                {
                    string msg = remotePeerID != null ?
                                 $"No client with ID {remotePeerID} connected" : "No connection to server";
                    // The given client is not connected. If the command is retryable and if
                    // a backlog is registered, remember it.
                    if (call.IsRetryable() && Settings.Backlog != null)
                    {
                        await RpcQueue.AddToBacklogIfApplicable(call, Settings.Backlog);

                        msg += ", but adding the call to the backlog";
                    }
                    throw new Exception(msg);
                }
                var result = await channel.Run(call);

                if (result.Failure != null)
                {
                    throw new RpcException(result.Failure);
                }
                else if (result.ReturnValue != null)
                {
                    return(Serializer.Deserialize <T>(result.ReturnValue));
                }
                else
                {
                    return(default !); // void methods are called with T = object, thus null
Beispiel #4
0
 protected override void OnCreate()
 {
     m_CommandBuffer     = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
     m_RpcSettingsQueue  = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcPlayerSetup>();
     m_RpcRemoteCmdQueue = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcRemoteCommand>();
     m_ConnectionQuery   = GetEntityQuery(ComponentType.ReadOnly <NetworkStreamConnection>());
 }
    protected override void OnCreateManager()
    {
        var reliabilityParams = new ReliableUtility.Parameters {
            WindowSize = 32
        };

        #if UNITY_EDITOR
        m_ClientPacketDelay = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDelay");
        m_ClientPacketDrop  = UnityEditor.EditorPrefs.GetInt("MultiplayerPlayMode_" + UnityEngine.Application.productName + "_ClientDropRate");
        int networkRate = 60; // TODO: read from some better place
        // All 3 packet types every frame stored for maximum delay, doubled for safety margin
        int maxPackets      = 2 * (networkRate * 3 * m_ClientPacketDelay + 999) / 1000;
        var simulatorParams = new SimulatorUtility.Parameters
        {
            MaxPacketSize = NetworkParameterConstants.MTU, MaxPacketCount = maxPackets, PacketDelayMs = m_ClientPacketDelay, PacketDropPercentage = m_ClientPacketDrop
        };
        m_Driver = new UdpNetworkDriver(simulatorParams, reliabilityParams);
        #else
        m_Driver = new UdpNetworkDriver(reliabilityParams);
        #endif

        m_ConcurrentDriver   = m_Driver.ToConcurrent();
        m_UnreliablePipeline = NetworkPipeline.Null;
        m_ReliablePipeline   = NetworkPipeline.Null;
        m_DriverListening    = false;
        m_Barrier            = World.GetOrCreateManager <BeginSimulationEntityCommandBufferSystem>();
        numNetworkIds        = new NativeArray <int>(1, Allocator.Persistent);
        freeNetworkIds       = new NativeQueue <int>(Allocator.Persistent);
        rpcQueue             = World.GetOrCreateManager <RpcSystem>().GetRpcQueue <RpcSetNetworkId>();
    }
Beispiel #6
0
        protected override void OnCreate()
        {
            m_Barrier  = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
            m_RpcQueue = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcLevelLoaded, RpcLevelLoaded>();

            RequireForUpdate(GetEntityQuery(ComponentType.ReadOnly <LevelLoadRequest>(), ComponentType.ReadOnly <ReceiveRpcCommandRequestComponent>()));
            // This is just here to make sure the subscen is streamed in before the client sets up the level data
            RequireSingletonForUpdate <GhostPrefabCollectionComponent>();
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new channel with the given information, already established connection,
        /// and optionally the given backlog.
        /// </summary>
        public static async Task <RpcChannel> Create(RpcPeerInfo remoteInfo, IRpcConnection connection,
                                                     IRpcMethodExecutor executor, IRpcBacklog?backlog = null)
        {
            var ret = new RpcChannel(remoteInfo, connection, executor);

            ret.callsQueue = await RpcQueue.Create(remoteInfo.PeerID, backlog);

            return(ret);
        }
        protected override void OnCreate()
        {
            m_Barrier  = World.GetOrCreateSystem <BeginSimulationEntityCommandBufferSystem>();
            m_RpcQueue = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcLevelLoaded>();

            // The level always exist, "loading" just resizes it
            m_LevelSingleton = EntityManager.CreateEntity();
            EntityManager.AddComponentData(m_LevelSingleton, new LevelComponent {
                width = 0, height = 0
            });
            m_LevelGroup = GetEntityQuery(ComponentType.ReadWrite <LevelComponent>());
            RequireForUpdate(m_LevelGroup);
        }
        public static void SendMapToServer()
        {
            ZLog.Log("-------------------- SENDING VPLUSMAPSYNC DATA");

            //Convert exploration data to ranges
            List <MapRange> exploredAreas = ExplorationDataToMapRanges(Minimap.instance.m_explored);

            //If we have no data to send, just send an empty RPC to trigger the server end to sync.
            if (exploredAreas.Count == 0)
            {
                ZPackage pkg = new ZPackage();

                pkg.Write(0);    //Number of explored areas we're sending (zero in this case)
                pkg.Write(true); //Trigger server sync by telling the server this is the last package we'll be sending.

                ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "VPlusMapSync",
                                                    new object[] { pkg });
            }
            else //We have data to send. Prep it and send it.
            {
                //Chunk map data
                List <ZPackage> packages = ChunkMapData(exploredAreas);

                //Route all chunks to the server
                foreach (ZPackage pkg in packages)
                {
                    RpcQueue.Enqueue(new RpcData()
                    {
                        Name    = "VPlusMapSync",
                        Payload = new object[] { pkg },
                        Target  = ZRoutedRpc.instance.GetServerPeerID()
                    });
                }

                ZLog.Log($"Sent my map data to the server ({exploredAreas.Count} map ranges, {packages.Count} chunks)");
            }
        }
Beispiel #10
0
 protected override void OnCreateManager()
 {
     m_RpcQueue = World.GetOrCreateManager <RpcSystem>().GetRpcQueue <RpcSpawn>();
 }
Beispiel #11
0
 private static void Postfix()
 {
     RpcQueue.SendNextRpc();
 }
Beispiel #12
0
 public static void RPC_VPlusAck(long sender)
 {
     RpcQueue.GotAck();
 }
Beispiel #13
0
 protected override void OnCreateManager()
 {
     m_Barrier    = World.GetOrCreateManager <BeginSimulationEntityCommandBufferSystem>();
     m_RpcQueue   = World.GetOrCreateManager <RpcSystem>().GetRpcQueue <RpcLoadLevel>();
     m_LevelGroup = GetComponentGroup(ComponentType.ReadWrite <LevelComponent>());
 }
 protected override void OnCreate()
 {
     m_RpcChatQueue = World.GetOrCreateSystem <RpcSystem>().GetRpcQueue <RpcChatMessage>();
 }
Beispiel #15
0
 public void ClientRPCQueue()
 {
     var rpcClient = new RpcQueue();
     rpcClient.Call("rabbit.png");
     rpcClient.Close();
 }
Beispiel #16
0
 protected override void OnCreateManager()
 {
     m_RpcQueue          = World.GetOrCreateSystem <MultiplayerSampleRpcSystem>().GetRpcQueue <RpcSpawn>();
     m_NetworkTimeSystem = World.GetOrCreateSystem <NetworkTimeSystem>();
 }
Beispiel #17
0
 public static void ClientRPCQueue()
 {
     var rpcClient = new RpcQueue();
     var response = rpcClient.Call("rabbit.png");
     rpcClient.Close();
 }
Beispiel #18
0
        public static void RPC_VPlusMapSync(long sender, ZPackage mapPkg)
        {
            if (ZNet.m_isServer) //Server
            {
                if (sender == ZRoutedRpc.instance.GetServerPeerID())
                {
                    return;
                }

                if (mapPkg == null)
                {
                    return;
                }

                //Get number of explored areas
                int exploredAreaCount = mapPkg.ReadInt();

                if (exploredAreaCount > 0)
                {
                    //Iterate and add them to server's combined map data.
                    for (int i = 0; i < exploredAreaCount; i++)
                    {
                        MapRange exploredArea = mapPkg.ReadVPlusMapRange();

                        for (int x = exploredArea.StartingX; x < exploredArea.EndingX; x++)
                        {
                            ServerMapData[exploredArea.Y * Minimap.instance.m_textureSize + x] = true;
                        }
                    }

                    ZLog.Log($"Received {exploredAreaCount} map ranges from peer #{sender}.");

                    //Send Ack
                    VPlusAck.SendAck(sender);
                }

                //Check if this is the last chunk from the client.
                bool lastMapPackage = mapPkg.ReadBool();

                if (!lastMapPackage)
                {
                    return;                  //This package is one of many chunks, so don't update clients until we get all of them.
                }
                //Convert map data into ranges
                List <MapRange> serverExploredAreas = ExplorationDataToMapRanges(ServerMapData);

                //Chunk up the map data
                List <ZPackage> packages = ChunkMapData(serverExploredAreas);

                //Send the updated server map to all clients
                foreach (ZPackage pkg in packages)
                {
                    RpcQueue.Enqueue(new RpcData()
                    {
                        Name    = "VPlusMapSync",
                        Payload = new object[] { pkg },
                        Target  = ZRoutedRpc.Everybody
                    });
                }

                ZLog.Log($"-------------------------- Packages: {packages.Count}");

                ZLog.Log($"Sent map updates to all clients ({serverExploredAreas.Count} map ranges, {packages.Count} chunks)");
            }
            else //Client
            {
                if (sender != ZRoutedRpc.instance.GetServerPeerID())
                {
                    return;                                                  //Only bother if it's from the server.
                }
                if (mapPkg == null)
                {
                    ZLog.LogWarning("Warning: Got empty map sync package from server.");
                    return;
                }

                //Get number of explored areas
                int exploredAreaCount = mapPkg.ReadInt();

                if (exploredAreaCount > 0)
                {
                    //Iterate and add them to explored map
                    for (int i = 0; i < exploredAreaCount; i++)
                    {
                        MapRange exploredArea = mapPkg.ReadVPlusMapRange();

                        for (int x = exploredArea.StartingX; x < exploredArea.EndingX; x++)
                        {
                            Minimap.instance.Explore(x, exploredArea.Y);
                        }
                    }

                    //Update fog texture
                    Minimap.instance.m_fogTexture.Apply();

                    ZLog.Log($"I got {exploredAreaCount} map ranges from the server!");

                    //Send Ack
                    VPlusAck.SendAck(sender);
                }
                else
                {
                    ZLog.Log("Server has no explored areas to sync, continuing.");
                }
            }
        }