コード例 #1
0
        void OnPlayerChat(ChatEvent evt)
        {
            if (evt.Message.Contains("kick") || evt.Message.Contains("ban"))
            {
                var coopKickToken = new CoopKickToken {
                    KickMessage = "You said the magic word!", Banned = false
                };
                evt.RaisedBy.Disconnect(coopKickToken);
            }

            if (evt.Message.Contains("save"))
            {
                var gameObject = UnityEngine.GameObject.Find("PlayerPlanePosition");
                if (gameObject)
                {
                    TheForest.Utils.LocalPlayer.CamFollowHead.planePos = gameObject.transform;
                }

                LevelSerializer.SaveGame("Game");
                LevelSerializer.Checkpoint();
                LogWarning("Server has been saved!");
            }

            HookCalled("OnPlayerChat");
        }
コード例 #2
0
        private object IOnUserApprove(BoltConnection connection)
        {
            var id       = connection.RemoteEndPoint.SteamId.Id.ToString();
            var cSteamId = new CSteamID(connection.RemoteEndPoint.SteamId.Id);

            // Get IP address from Steam
            P2PSessionState_t sessionState;

            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out sessionState);
            var remoteIp = sessionState.m_nRemoteIP;
            var ip       = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            var canLogin = Interface.Call("CanClientLogin", connection) ?? Interface.Call("CanUserLogin", "Unnamed", id, ip);

            if (canLogin is string || (canLogin is bool && !(bool)canLogin))
            {
                var coopKickToken = new CoopKickToken
                {
                    KickMessage = canLogin is string?canLogin.ToString() : "Connection was rejected",   // TODO: Localization
                                      Banned = false
                };
                connection.Disconnect(coopKickToken);
                return(true);
            }

            return(Interface.Call("OnUserApprove", connection) ?? Interface.Call("OnUserApproved", "Unnamed", id, ip));
        }
コード例 #3
0
        private object IOnUserApprove(BoltConnection connection)
        {
            var id       = connection.RemoteEndPoint.SteamId.Id.ToString();
            var cSteamId = new CSteamID(connection.RemoteEndPoint.SteamId.Id);
            var name     = SteamFriends.GetFriendPersonaName(cSteamId);
            P2PSessionState_t sessionState;

            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out sessionState);
            var remoteIp = sessionState.m_nRemoteIP;
            var ip       = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            var canLogin = Interface.Call("CanClientLogin", connection) ?? Interface.Call("CanUserLogin", name, id, ip);

            if (canLogin is string)
            {
                var coopKickToken = new CoopKickToken {
                    KickMessage = canLogin.ToString(), Banned = false
                };
                connection.Disconnect(coopKickToken);
                return(true);
            }

            return(Interface.Call("OnUserApprove", connection) ?? Interface.Call("OnUserApproved", name, id, ip));
        }
コード例 #4
0
        /// <summary>
        /// Kicks the player from the game
        /// </summary>
        /// <param name="reason"></param>
        public void Kick(string reason)
        {
            var connection    = entity.source;
            var coopKickToken = new CoopKickToken()
            {
                KickMessage = reason,
                Banned      = false
            };

            connection.Disconnect(coopKickToken);
        }
コード例 #5
0
        private object IOnUserApprove(BoltConnection connection)
        {
            CSteamID cSteamId = SteamDSConfig.clientConnectionInfo[connection.ConnectionId];
            string   playerId = cSteamId.ToString();
            ulong    steamId  = cSteamId.m_SteamID;

            // Check for existing player's name
            IPlayer player = Covalence.PlayerManager.FindPlayerById(playerId);
            string  name   = !string.IsNullOrEmpty(player?.Name) ? player.Name : "Unnamed";

            // Handle universal player joining
            Covalence.PlayerManager.PlayerJoin(steamId, name);

            // Get IP address from Steam
            SteamGameServerNetworking.GetP2PSessionState(cSteamId, out P2PSessionState_t sessionState);
            uint   remoteIp = sessionState.m_nRemoteIP;
            string playerIp = string.Concat(remoteIp >> 24 & 255, ".", remoteIp >> 16 & 255, ".", remoteIp >> 8 & 255, ".", remoteIp & 255);

            // Call out and see if we should reject
            object loginSpecific  = Interface.Call("CanClientLogin", connection);
            object loginCovalence = Interface.Call("CanUserLogin", name, playerId, playerIp);
            object canLogin       = loginSpecific is null ? loginCovalence : loginSpecific;

            if (!serverInitialized || canLogin is string || canLogin is bool loginBlocked && !loginBlocked)
            {
                // Create kick token for player
                CoopKickToken coopKickToken = new CoopKickToken
                {
                    KickMessage = !serverInitialized ? "Server not initialized yet" : canLogin is string?canLogin.ToString() : "Connection was rejected",   // TODO: Localization
                                      Banned = false
                };

                // Disconnect player using kick token
                connection.Disconnect(coopKickToken);
                return(true);
            }

            // Call hooks for plugins
            object approvedSpecific  = Interface.Call("OnUserApprove", connection);
            object approvedCovalence = Interface.Call("OnUserApproved", name, playerId, playerIp);

            return(approvedSpecific is null ? approvedCovalence : approvedSpecific);
        }
コード例 #6
0
    public override void Disconnected(BoltConnection connection)
    {
        CoopKickToken coopKickToken = connection.DisconnectToken as CoopKickToken;

        if (coopKickToken != null)
        {
            CoopKick.Client_Banned      = coopKickToken.Banned;
            CoopKick.Client_KickMessage = coopKickToken.KickMessage;
            UnityEngine.Object.FindObjectOfType <CoopSteamClientStarter>().CancelInvoke("OnDisconnected");
            CoopClientCallbacks.OnDisconnected = null;
        }
        else
        {
            CoopKick.Client_Banned      = false;
            CoopKick.Client_KickMessage = string.Empty;
            if (CoopClientCallbacks.OnDisconnected != null)
            {
                CoopClientCallbacks.OnDisconnected();
            }
        }
    }
コード例 #7
0
    public override void Disconnected(BoltConnection connection)
    {
        CoopKickToken coopKickToken = connection.DisconnectToken as CoopKickToken;

        if (coopKickToken != null)
        {
            SteamClientConfig.Banned      = coopKickToken.Banned;
            SteamClientConfig.KickMessage = UiTranslationDatabase.TranslateKey(coopKickToken.KickMessage, "Kicked/Banned", false);
            CoopSteamClientStarter coopSteamClientStarter = UnityEngine.Object.FindObjectOfType <CoopSteamClientStarter>();
            if (coopSteamClientStarter)
            {
                coopSteamClientStarter.CancelInvoke("OnDisconnected");
            }
            CoopClientCallbacks.OnDisconnected = null;
            if (SteamClientDSConfig.isDedicatedClient)
            {
                BoltLauncher.Shutdown();
                UnityEngine.Object.Destroy(base.gameObject);
                SteamUser.TerminateGameConnection(SteamClientDSConfig.EndPoint.Address.Packed, SteamClientDSConfig.EndPoint.Port);
                this.ReturnToTitle();
            }
            else if (!TheForest.Utils.Scene.FinishGameLoad)
            {
                this.ReturnToTitle();
            }
        }
        else
        {
            SteamClientConfig.Banned      = false;
            SteamClientConfig.KickMessage = string.Empty;
            if (SteamClientDSConfig.isDedicatedClient)
            {
                CoopJoinDedicatedServerFailed coopJoinDedicatedServerFailed = connection.DisconnectToken as CoopJoinDedicatedServerFailed;
                if (coopJoinDedicatedServerFailed != null)
                {
                    CoopClientCallbacks.OnDisconnected            = null;
                    CoopPlayerCallbacks.WasDisconnectedFromServer = true;
                    CoopSteamClientStarter coopSteamClientStarter2 = UnityEngine.Object.FindObjectOfType <CoopSteamClientStarter>();
                    if (coopSteamClientStarter2)
                    {
                        coopSteamClientStarter2._connectionAttempts = 3;
                        coopSteamClientStarter2.CancelInvoke("OnDisconnected");
                        UnityEngine.Object.Destroy(coopSteamClientStarter2.gameObject);
                    }
                    BoltLauncher.Shutdown();
                    SteamClientConfig.KickMessage = "Incorrect password";
                    UnityEngine.Object.Destroy(base.gameObject);
                    this.ReturnToTitle();
                }
            }
            if (CoopClientCallbacks.OnDisconnected != null)
            {
                CoopClientCallbacks.OnDisconnected();
            }
        }
        if (SteamClientDSConfig.isDedicatedClient)
        {
            SteamUser.TerminateGameConnection(SteamClientDSConfig.EndPoint.Address.Packed, SteamClientDSConfig.EndPoint.Port);
            this.ReturnToTitle();
        }
    }