public override void OnStopClient()         // Called on the client when closing connection
        {
            DebugLog.DebugWrite("OnStopClient", MessageType.Info);
            DebugLog.ToConsole("Disconnecting from server...", MessageType.Info);
            Destroy(GetComponent <RespawnOnDeath>());
            Destroy(GetComponent <ServerStateManager>());
            Destroy(GetComponent <ClientStateManager>());
            QSBPlayerManager.PlayerList.ForEach(player => player.HudMarker?.Remove());

            QSBWorldSync.RemoveWorldObjects();

            if (WakeUpSync.LocalInstance != null)
            {
                WakeUpSync.LocalInstance.OnDisconnect();
            }

            if (_everConnected)
            {
                var specificType = QSBCore.IsHost ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;
                QSBPatchManager.DoUnpatchType(specificType);
                QSBPatchManager.DoUnpatchType(QSBPatchTypes.OnClientConnect);
            }

            _everConnected = false;
        }
        private void CleanupConnection(NetworkConnection connection)
        {
            uint playerId;

            try
            {
                playerId = connection.playerControllers[0].gameObject.GetComponent <PlayerTransformSync>().netId.Value;
            }
            catch (Exception ex)
            {
                DebugLog.ToConsole("Error when getting playerId in CleanupConnection: " + ex.Message, MessageType.Error);
                return;
            }
            if (!PlayerRegistry.PlayerExists(playerId))
            {
                return;
            }
            var playerName = PlayerRegistry.GetPlayer(playerId).Name;

            DebugLog.ToConsole($"{playerName} disconnected.", MessageType.Info);
            PlayerRegistry.RemovePlayer(playerId);

            if (playerId != PlayerRegistry.LocalPlayerId) // We don't want to delete the local player!
            {
                var netIds = connection.clientOwnedObjects?.Select(x => x.Value).ToList();
                netIds.ForEach(CleanupNetworkBehaviour);
            }
        }
        private void InitPlayerName() =>
        Delay.RunWhen(PlayerData.IsLoaded, () =>
        {
            try
            {
                var titleScreenManager = FindObjectOfType <TitleScreenManager>();
                var profileManager     = titleScreenManager._profileManager;
                if (profileManager.GetType().Name == "MSStoreProfileManager")
                {
                    PlayerName = (string)profileManager.GetType().GetProperty("userDisplayName").GetValue(profileManager);
                }
                else
                {
                    PlayerName = StandaloneProfileManager.SharedInstance.currentProfile.profileName;
                }
            }
            catch (Exception ex)
            {
                DebugLog.ToConsole($"Error - Exception when getting player name : {ex}", MessageType.Error);
                PlayerName = "Player";
            }

            if (!QSBCore.DebugSettings.UseKcpTransport)
            {
                EOSSDKComponent.DisplayName = PlayerName;
            }
        });
Esempio n. 4
0
        public override void OnStopClient()         // Called on the client when closing connection
        {
            DebugLog.DebugWrite("OnStopClient", MessageType.Info);
            DebugLog.ToConsole("Disconnecting from server...", MessageType.Info);
            Destroy(GetComponent <RespawnOnDeath>());
            QSBEventManager.Reset();
            QSBPlayerManager.PlayerList.ForEach(player => player.HudMarker?.Remove());

            RemoveWorldObjects();
            QSBWorldSync.OrbSyncList.Clear();
            QSBWorldSync.OldDialogueTrees.Clear();

            if (_everConnected)
            {
                var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;
                QSBPatchManager.DoUnpatchType(specificType);
                QSBPatchManager.DoUnpatchType(QSBPatchTypes.OnClientConnect);
            }

            _lobby.CanEditName = true;
            QSBCore.HasWokenUp = false;

            IsReady        = false;
            _everConnected = false;
        }
        public override void OnStopServer()
        {
            DebugLog.DebugWrite("OnStopServer", MessageType.Info);
            Destroy(GetComponent <RespawnOnDeath>());
            DebugLog.ToConsole("Server stopped!", MessageType.Info);
            QSBPlayerManager.PlayerList.ForEach(player => player.HudMarker?.Remove());

            base.OnStopServer();
        }
 public override void OnStopServer()
 {
     Destroy(GetComponent <SectorSync>());
     Destroy(GetComponent <RespawnOnDeath>());
     Destroy(GetComponent <PreventShipDestruction>());
     EventList.Reset();
     DebugLog.ToConsole("Server stopped!", MessageType.Info);
     PlayerRegistry.PlayerList.ForEach(player => player.HudMarker?.Remove());
     NetworkServer.connections.ToList().ForEach(CleanupConnection);
     base.OnStopServer();
 }
        public override void OnStopClient() // Called on the client when closing connection
        {
            DebugLog.ToConsole("Disconnecting from server...", MessageType.Info);
            Destroy(GetComponent <SectorSync>());
            Destroy(GetComponent <RespawnOnDeath>());
            Destroy(GetComponent <PreventShipDestruction>());
            EventList.Reset();
            PlayerRegistry.PlayerList.ForEach(player => player.HudMarker?.Remove());

            foreach (var player in PlayerRegistry.PlayerList.Where(x => x.NetId != PlayerRegistry.LocalPlayerId).ToList())
            {
                PlayerRegistry.GetPlayerNetIds(player).ForEach(CleanupNetworkBehaviour);
                PlayerRegistry.RemovePlayer(player.NetId);
            }

            _lobby.CanEditName = true;
        }
Esempio n. 8
0
        private void Start()
        {
            Helper = ModHelper;
            DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info);

            NetworkAssetBundle = Helper.Assets.LoadBundle("assets/network");
            DebugLog.LogState("NetworkBundle", NetworkAssetBundle);

            ProbePatches.DoPatches();
            DeathPatches.DoPatches();

            // Turns out these are very finicky about what order they go. QSBNetworkManager seems to
            // want to go first-ish, otherwise the NetworkManager complains about the PlayerPrefab being
            // null (even though it isn't...)
            gameObject.AddComponent <QSBNetworkManager>();
            gameObject.AddComponent <NetworkManagerHUD>();
            gameObject.AddComponent <DebugActions>();
            gameObject.AddComponent <ElevatorManager>();
            gameObject.AddComponent <GeyserManager>();
            gameObject.AddComponent <QSBSectorManager>();
        }
        public override void OnServerDisconnect(NetworkConnectionToClient conn)         // Called on the server when any client disconnects
        {
            DebugLog.DebugWrite("OnServerDisconnect", MessageType.Info);

            // local conn = we are host, so skip
            if (conn is not LocalConnectionToClient)
            {
                // revert authority from ship
                if (ShipTransformSync.LocalInstance != null)
                {
                    var identity = ShipTransformSync.LocalInstance.netIdentity;
                    if (identity != null && identity.connectionToClient == conn)
                    {
                        identity.SetAuthority(QSBPlayerManager.LocalPlayerId);
                    }
                }

                // stop dragging for the orbs this player was dragging
                foreach (var qsbOrb in QSBWorldSync.GetWorldObjects <QSBOrb>())
                {
                    if (qsbOrb.TransformSync == null)
                    {
                        DebugLog.ToConsole($"{qsbOrb} TransformSync == null??????????", MessageType.Warning);
                        continue;
                    }

                    var identity = qsbOrb.TransformSync.netIdentity;
                    if (identity.connectionToClient == conn)
                    {
                        qsbOrb.SetDragging(false);
                        qsbOrb.SendMessage(new OrbDragMessage(false));
                    }
                }

                AuthorityManager.OnDisconnect(conn);
            }

            base.OnServerDisconnect(conn);
        }
Esempio n. 10
0
        public void Start()
        {
            Helper = ModHelper;
            DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info);

            NetworkAssetBundle      = Helper.Assets.LoadBundle("assets/network");
            InstrumentAssetBundle   = Helper.Assets.LoadBundle("assets/instruments");
            ConversationAssetBundle = Helper.Assets.LoadBundle("assets/conversation");

            QSBPatchManager.Init();

            gameObject.AddComponent <QSBNetworkManager>();
            gameObject.AddComponent <QNetworkManagerHUD>();
            gameObject.AddComponent <DebugActions>();
            gameObject.AddComponent <ConversationManager>();
            gameObject.AddComponent <QSBInputManager>();
            gameObject.AddComponent <TimeSyncUI>();
            gameObject.AddComponent <RepeatingManager>();
            gameObject.AddComponent <PlayerEntanglementWatcher>();

            // WorldObject managers
            gameObject.AddComponent <QuantumManager>();
            gameObject.AddComponent <SpiralManager>();
            gameObject.AddComponent <ElevatorManager>();
            gameObject.AddComponent <GeyserManager>();
            gameObject.AddComponent <OrbManager>();
            gameObject.AddComponent <QSBSectorManager>();
            gameObject.AddComponent <ItemManager>();
            gameObject.AddComponent <StatueManager>();
            gameObject.AddComponent <PoolManager>();
            gameObject.AddComponent <CampfireManager>();

            DebugBoxManager.Init();

            // Stop players being able to pause
            Helper.HarmonyHelper.EmptyMethod(typeof(OWTime).GetMethod("Pause"));
        }