Ejemplo n.º 1
0
 void OnJoin(ICoreServerAPI api, IServerPlayer p)
 {
     if (IsPermaDeath(api.WorldManager.SaveGame, @p.PlayerUID))
     {
         p.Disconnect("You've died.");
     }
 }
Ejemplo n.º 2
0
        void OnDeath(ICoreServerAPI api, IServerPlayer p)
        {
            SetPermaDeath(api.WorldManager.SaveGame, @p.PlayerUID);

            //Small delay to prevent interfering with server updating
            api.Event.EnqueueMainThreadTask(() => p.Disconnect("You've died"), "");

            api.BroadcastMessageToAllGroups("The life of " + p.ServerData.LastKnownPlayername.ToUpper() + " has been extinguished.", EnumChatType.Notification);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Disconnects the specified server player.
        /// </summary>
        /// <param name="serverPlayer">The server player.</param>
        public void Disconnect(IServerPlayer serverPlayer)
        {
            // Ensure the connection is still valid.
            if (serverPlayer != null && serverPlayer.Connection != null && serverPlayer.Connection.Connected)
            {
                serverPlayer.Disconnect();
            }

            if (this.Connections.Contains(serverPlayer))
            {
                this.Connections.Remove(serverPlayer);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Disconnects everyone from the server.
        /// </summary>
        /// <exception cref="System.NotImplementedException">Throws an exception if the player is null</exception>
        public void DisconnectAll()
        {
            // Disconnect every client from the server.
            foreach (IServerPlayer serverPlayer in this.Connections.AsParallel())
            {
                IServerPlayer player = serverPlayer;
                if (player != null && player.Connection != null && player.Connection.Connected)
                {
                    player.Disconnect();
                }
            }

            this.Connections.Clear();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Stops the server, shutting down the network connection.
        /// All IServerPlayer objects will be disconnected.
        /// </summary>
        public void Stop()
        {
            this.LogMessage("Stopping the network server.");

            // Loop through each connection in parallel and disconnect them.
            foreach (IServerPlayer connection in this.Connections.AsParallel())
            {
                // Hold a locally scoped reference to avoid parallel issues.
                IServerPlayer client = connection;
                client.Disconnect();
            }

            // If the server socket is still connected, we shut it down.
            if (this.serverSocket.Connected)
            {
                this.serverSocket.Shutdown(SocketShutdown.Both);
            }

            this.Status    = ServerStatus.Stopped;
            this.IsEnabled = false;
        }