/// <summary> /// Call this when the server is stopped /// </summary> internal static void OnStopServer() { Logger.Info("Stopping server..."); LagCompensationManager.ServerShutdown(); PingManager.ServerShutdown(); //Stop advertising the server when the server stops netManager.gameDiscovery.StopDiscovery(); //Close server chat NetworkServer.UnregisterHandler <ChatMessage>(); //Close server online file stream try { serverOnlineFileStream.Close(); serverOnlineFileStream.Dispose(); serverOnlineFileStream = null; } catch (Exception ex) { Logger.Error(ex, "An error occurred while shutting down the server!"); } netManager = null; //Double check that the file is deleted if (File.Exists(serverOnlineFilePath)) { File.Delete(serverOnlineFilePath); } Logger.Info("Server stopped!"); }
public void Update() { if (mode == NetworkManagerMode.ServerOnly) { PingManager.ServerPingUpdate(); LagCompensationManager.ServerUpdate(); } }
IEnumerator Simulate() { Debug.Log("STARTPOS: " + transform.position); yield return(new WaitForSeconds(1)); LagCompensationManager.Simulate(1f, () => { for (int i = 0; i < LagCompensationManager.SimulationObjects.Count; i++) { Debug.Log(LagCompensationManager.SimulationObjects[i].transform.position); } }); }
protected void StopRayRollback(float timeDelay) { #if FIRSTGEARGAMES_COLLIDERROLLBACKS if (timeDelay > 0f) { RollbackManager.ReturnForward(); } #else if (timeDelay > 0f) { LagCompensationManager.StopSimulation(); } #endif }
protected void StartRayRollback(float timeDelay) { #if FIRSTGEARGAMES_COLLIDERROLLBACKS Debug.Log("RollbackCalled " + timeDelay); if (timeDelay > 0f) { RollbackManager.RollbackSteps(timeDelay, RollbackManager.PhysicsTypes.ThreeDimensional); } #else if (timeDelay > 0f) { LagCompensationManager.StartSimulation(timeDelay); } #endif }
private void SwingWeapon() { if (Time.time < nextTimeToFire) { return; } nextTimeToFire = Time.time + 1f / weaponFireRate; try { LagCompensationManager.Simulate(weaponManager.playerManager, WeaponRayCast); } catch (Exception ex) { Logger.Error(ex, "Error occured while simulating weapon shooting!"); } }
void Update() { if (isLocalPlayer) { transform.Translate(new Vector3(Input.GetAxis("Horizontal") * 2f * Time.deltaTime, 0, Input.GetAxis("Vertical") * 2f * Time.deltaTime)); if (Input.GetKeyDown(KeyCode.Space)) { StartCoroutine(Simulate()); return; LagCompensationManager.Simulate(1f, () => { for (int i = 0; i < LagCompensationManager.SimulationObjects.Count; i++) { GameObject go = new GameObject(); go.transform.position = LagCompensationManager.SimulationObjects[i].transform.position; } }); } } }
// [Note] Lad Compensation is still not working fine. The problem is because of client and server time mismatch. private void PerformShootRaycast(float clientTime, Vector3 shootPos, Vector3 shootDir) { if (!this.IsServer) { return; } // [Hack]Round the float to 2 decimal points otherwisse we will get KeyNotFound exception //float secondsAgo = Mathf.Round((NetworkingManager.Singleton.NetworkTime - clientTime) * 100) / 100f; // We will use round trip time instead of client time. float rttInSeconds = this.IsHost ? 0f : NetworkingManager.Singleton.NetworkConfig.NetworkTransport.GetCurrentRtt(this.OwnerClientId) / 1000f; // Mathf.Abs is a Hack to avoid negative value float secondsAgo = (rttInSeconds / 2f); Debug.Log($"PerformShootRaycast secondsAgo: {secondsAgo} Rtt: {rttInSeconds}"); LagCompensationManager.Simulate(secondsAgo, () => { RaycastHit hit; if (Physics.Raycast(shootPos, shootDir, out hit, m_currentWeapon.Range, LayerMask.GetMask(IVConstants.LAYER_REMOTE_PLAYER))) { Debug.Log("[Server] Hit the target " + hit.transform.name); if (hit.transform.CompareTag(IVConstants.TAG_REMOTE_PLAYER)) { IVClientPlayer targetPlayer = hit.transform.GetComponent <IVClientPlayer>(); targetPlayer.TakeGamage(m_currentWeapon.Damage); } } if (m_drawDebugRays) { Debug.DrawRay(shootPos, shootDir * m_currentWeapon.Range, Color.green, 60, false); } }); }
/// <summary> /// Call this when the server is started /// </summary> internal static void OnStartServer(TCNetworkManager workingNetManager) { serverOnlineFilePath = $"{Game.GetGameExecutePath()}/{ServerOnlineFile}"; if (File.Exists(serverOnlineFilePath)) { throw new Exception("Server is already online!"); } netManager = workingNetManager; Logger.Info("Starting server..."); //Get the online scene TCScene onlineScene = TCScenesManager.FindSceneInfo(Scene); if (onlineScene == null) { Logger.Error($"Failed to find scene {Scene}!"); throw new FileNotFoundException($"Scene {Scene} not found!"); } //Setup the server's config SetupServerConfig(); Application.targetFrameRate = netManager.serverTickRate; //Make some adjustments to scenes config if we are running headless if (Game.IsHeadless) { netManager.offlineScene = null; netManager.onlineScene = onlineScene.scene; TCScenesManager.LoadScene(onlineScene); } //Set what network address to use and start to advertise the server on lan netManager.networkAddress = NetHelper.LocalIpAddress(); netManager.gameDiscovery.AdvertiseServer(); //Setup ping related stuff PingManager.ServerSetup(); LagCompensationManager.ServerSetup(); //Run the server autoexec config ConsoleBackend.ExecuteFile("server-autoexec"); //Server chat NetworkServer.RegisterHandler <ChatMessage>(ServerChat.ReceivedChatMessage); //Create server online file try { serverOnlineFileStream = File.Create(serverOnlineFilePath, 128, FileOptions.DeleteOnClose); serverOnlineFileStream.Write(ServerOnlineFileMessage, 0, ServerOnlineFileMessage.Length); serverOnlineFileStream.Flush(); File.SetAttributes(serverOnlineFilePath, FileAttributes.Hidden); } catch (IOException ex) { Logger.Error(ex, "An error occurred while setting up the server!"); netManager.StopHost(); return; } Logger.Info("Server has started and is running on '{Address}' with max connections of {MaxPlayers}!", netManager.networkAddress, netManager.maxConnections); }