// Polite update - Wait for our jobs to complete naturally public void Update() { if (m_Disposed || m_ShuttingDown) { return; } m_SqpServer?.Update(); // Don't do anything more unless our jobs have been completed if (!m_UpdateHandle.IsCompleted) { return; } // Wait for the previous frames ping to complete before starting a new one m_UpdateHandle.Complete(); // Update the SQP server if (m_SqpServer != null) { m_Config.Info.CurrentPlayers = (ushort)m_Connections.Length; } // If there is at least one client connected update the activity so the server is not shutdown if (m_Connections.Length > 0) { DedicatedServerConfig.UpdateLastActivity(); } // Update the network drivers and our list of active connections WaitForNetworkUpdate(); // Figure out if we should wait for (and respond to) pings or shut down the server if (m_ShouldShutdownServer[0]) { DisconnectClientsAndShutdown(); } else { SchedulePongJob(); // Put our jobs on the stack to be processed without waiting for completion in this frame JobHandle.ScheduleBatchedJobs(); } }
void FixedUpdate() { // Wait for the previous frames ping to complete before starting a new one, the Complete in LateUpdate is not // enough since we can get multiple FixedUpdate per frame on slow clients m_updateHandle.Complete(); // If there is at least one client connected update the activity so the server is not shutdown if (m_connections.Length > 0) { DedicatedServerConfig.UpdateLastActivity(); } var updateJob = new DriverUpdateJob { driver = m_ServerDriver, connections = m_connections }; var pongJob = new PongJob { // PongJob is a ParallelFor job, it must use the concurrent NetworkDriver driver = m_ServerDriver.ToConcurrent(), // PongJob uses IJobParallelForDeferExtensions, we *must* use ToDeferredJobArray in order to access the // list from the job #if ENABLE_IL2CPP // IJobParallelForDeferExtensions is not working correctly with IL2CPP connections = m_connections #else connections = m_connections.ToDeferredJobArray() #endif }; // Update the driver should be the first job in the chain m_updateHandle = m_ServerDriver.ScheduleUpdate(); // The DriverUpdateJob which accepts new connections should be the second job in the chain, it needs to depend // on the driver update job m_updateHandle = updateJob.Schedule(m_updateHandle); // PongJob uses IJobParallelForDeferExtensions, we *must* schedule with a list as first parameter rather than // an int since the job needs to pick up new connections from DriverUpdateJob // The PongJob is the last job in the chain and it must depends on the DriverUpdateJob #if ENABLE_IL2CPP m_updateHandle = pongJob.Schedule(m_updateHandle); #else m_updateHandle = pongJob.Schedule(m_connections, 1, m_updateHandle); #endif } }
private void UpdateUdpPingServer() { // Respond to connected clients if (m_GameServerUdpPingHandler != null) { m_GameServerUdpPingHandler.Update(); // Trigger shutdown if requested by remote command if (m_GameServerUdpPingHandler.ShouldShutdown) { Debug.Log("Server received shutdown signal from a client; shutting down"); ShutdownServer(ExitCode.Ok); } // Update the activity check (while active) so the server is not auto-shutdown for idling if (m_GameServerUdpPingHandler.ConnectedClients > 0) { DedicatedServerConfig.UpdateLastActivity(); } } }