Пример #1
0
        private async void OnContext(HttpListenerContext context)
        {
            var path = context.Request.Url.PathAndQuery;

            if (path == "/")
            {
                path = "/website-cacher://static-content/controlPanel.html";
            }

            var controlProtocol = "/website-cacher://";

            if (path.StartsWith(controlProtocol))
            {
                var controller = new ServerDriver(this);
                await controller.Process(path.Substring(controlProtocol.Length), context);

                controller.Output(context.Response);
            }
            else
            {
                var controller = new WebResourceController(this);
                await controller.Process(path.Substring(1), context);

                controller.Output(context.Response);
            }

            context.Response.OutputStream.Close();
        }
        public void StartServer()
        {
            if (started) return;

            started = true;
            server = new IISExpress();
            //            server = new WebApiServer();
            server.Start();
        }
Пример #3
0
 public void AddMOOOOOOREPlayers()
 {
     driver = new ServerDriver();
     for (int i = 0; i < 6; i++)
     {
         driver.JoinLobby();
         Debug.Log("Player №" + (i + 1) + " Connected");
     }
 }
 protected override void OnDestroy()
 {
     // Destroy NetworkDrivers if the manager is destroyed with live entities
     if (ServerDriver.IsCreated)
     {
         ServerDriver.Dispose();
     }
     if (ClientDriver.IsCreated)
     {
         ClientDriver.Dispose();
     }
 }
    protected override JobHandle OnUpdate(JobHandle inputDep)
    {
        var commandBuffer = m_Barrier.CreateCommandBuffer();

        // Destroy drivers if the PingDriverComponents were removed
        if (!m_DestroyedDriverGroup.IsEmptyIgnoreFilter)
        {
            inputDep.Complete();
            var destroyedDriverEntity = m_DestroyedDriverGroup.ToEntityArray(Allocator.TempJob);
            var destroyedDriverList   = m_DestroyedDriverGroup.ToComponentDataArray <PingDriverComponentData>(Allocator.TempJob);
            for (int i = 0; i < destroyedDriverList.Length; ++i)
            {
                if (destroyedDriverList[i].isServer != 0)
                {
                    var serverConnectionList = m_ServerConnectionGroup.ToEntityArray(Allocator.TempJob);
                    // Also destroy all active connections when the driver dies
                    for (int con = 0; con < serverConnectionList.Length; ++con)
                    {
                        commandBuffer.DestroyEntity(serverConnectionList[con]);
                    }
                    serverConnectionList.Dispose();
                    ServerDriver.Dispose();
                }
                else
                {
                    ClientDriver.Dispose();
                }

                commandBuffer.RemoveComponent <PingDriverStateComponent>(destroyedDriverEntity[i]);
            }

            destroyedDriverList.Dispose();
            destroyedDriverEntity.Dispose();
        }

        // Create drivers if new PingDriverComponents were added
        if (!m_NewDriverGroup.IsEmptyIgnoreFilter)
        {
            inputDep.Complete();
            var newDriverEntity = m_NewDriverGroup.ToEntityArray(Allocator.TempJob);
            var newDriverList   = m_NewDriverGroup.ToComponentDataArray <PingDriverComponentData>(Allocator.TempJob);
            for (int i = 0; i < newDriverList.Length; ++i)
            {
                if (newDriverList[i].isServer != 0)
                {
                    if (ServerDriver.IsCreated)
                    {
                        throw new InvalidOperationException("Cannot create multiple server drivers");
                    }
                    var drv  = new UdpNetworkDriver(new INetworkParameter[0]);
                    var addr = NetworkEndPoint.AnyIpv4;
                    addr.Port = 9000;
                    if (drv.Bind(addr) != 0)
                    {
                        throw new Exception("Failed to bind to port 9000");
                    }
                    else
                    {
                        drv.Listen();
                    }
                    ServerDriver           = drv;
                    ConcurrentServerDriver = ServerDriver.ToConcurrent();
                }
                else
                {
                    if (ClientDriver.IsCreated)
                    {
                        throw new InvalidOperationException("Cannot create multiple client drivers");
                    }
                    ClientDriver           = new UdpNetworkDriver(new INetworkParameter[0]);
                    ConcurrentClientDriver = ClientDriver.ToConcurrent();
                }

                commandBuffer.AddComponent(newDriverEntity[i],
                                           new PingDriverStateComponent {
                    isServer = newDriverList[i].isServer
                });
            }
            newDriverList.Dispose();
            newDriverEntity.Dispose();
        }

        JobHandle clientDep = default(JobHandle);
        JobHandle serverDep = default(JobHandle);

        // Go through and update all drivers, also accept all incoming connections for server drivers
        if (ServerDriver.IsCreated)
        {
            // Schedule a chain with driver update, a job to accept all connections and finally a job to delete all invalid connections
            serverDep = ServerDriver.ScheduleUpdate(inputDep);
            var acceptJob = new DriverAcceptJob
            {
                driver = ServerDriver, commandBuffer = commandBuffer
            };
            serverDep = acceptJob.Schedule(serverDep);
            var cleanupJob = new DriverCleanupJob
            {
                commandBuffer = m_Barrier.CreateCommandBuffer().ToConcurrent()
            };
            serverDep = cleanupJob.Schedule(this, serverDep);
            m_Barrier.AddJobHandleForProducer(serverDep);
        }

        if (ClientDriver.IsCreated)
        {
            clientDep = ClientDriver.ScheduleUpdate(inputDep);
        }

        return(JobHandle.CombineDependencies(clientDep, serverDep));
    }
Пример #6
0
    protected override JobHandle OnUpdate(JobHandle inputDep)
    {
        inputDep.Complete();
        var commandBuffer = m_Barrier.CreateCommandBuffer();

        // Destroy drivers if the PingDriverComponents were removed
        for (int i = 0; i < destroyedDriverList.state.Length; ++i)
        {
            if (destroyedDriverList.state[i].isServer != 0)
            {
                // Allso destroy all active connections when the driver dies
                for (int con = 0; con < serverConnectionList.connections.Length; ++con)
                {
                    commandBuffer.DestroyEntity(serverConnectionList.entities[con]);
                }
                ServerDriver.Dispose();
            }
            else
            {
                ClientDriver.Dispose();
            }
            commandBuffer.RemoveComponent <PingDriverStateComponent>(destroyedDriverList.entities[i]);
        }
        // Create drivers if new PingDriverComponents were added
        for (int i = 0; i < newDriverList.drivers.Length; ++i)
        {
            if (newDriverList.drivers[i].isServer != 0)
            {
                if (ServerDriver.IsCreated)
                {
                    throw new InvalidOperationException("Cannot create multiple server drivers");
                }
                var drv = new UdpCNetworkDriver(new INetworkParameter[0]);
                if (drv.Bind(new IPEndPoint(IPAddress.Any, 9000)) != 0)
                {
                    throw new Exception("Failed to bind to port 9000");
                }
                else
                {
                    drv.Listen();
                }
                ServerDriver = drv;
            }
            else
            {
                if (ClientDriver.IsCreated)
                {
                    throw new InvalidOperationException("Cannot create multiple client drivers");
                }
                ClientDriver = new UdpCNetworkDriver(new INetworkParameter[0]);
            }
            commandBuffer.AddComponent(newDriverList.entities[i], new PingDriverStateComponent {
                isServer = newDriverList.drivers[i].isServer
            });
        }

        JobHandle clientDep = default(JobHandle);
        JobHandle serverDep = default(JobHandle);

        // Go through and update all drivers, also accept all incoming connections for server drivers
        for (int i = 0; i < driverList.drivers.Length; ++i)
        {
            if (driverList.drivers[i].isServer != 0)
            {
                // Schedule a chain with driver update, a job to accept all connections and finally a job to delete all invalid connections
                serverDep = ServerDriver.ScheduleUpdate();
                var acceptJob = new DriverAcceptJob
                {
                    driver = ServerDriver, commandBuffer = commandBuffer
                };
                serverDep = acceptJob.Schedule(serverDep);
                var cleanupJob = new DriverCleanupJob
                {
                    serverConnections        = serverConnectionList.connections,
                    serverConnectionEntities = serverConnectionList.entities,
                    commandBuffer            = commandBuffer
                };
                serverDep = cleanupJob.Schedule(serverDep);
            }
            else
            {
                clientDep = ClientDriver.ScheduleUpdate();
            }
        }

        return(JobHandle.CombineDependencies(clientDep, serverDep));
    }
 public void SearchButtonClickListener()
 {
     ServerDriver driver = new ServerDriver();
     driver.LeaveLobby();
     OpenTitleScreen();
 }