类 RconClient

  • 所有已实现的接口:
    Closeable, AutoCloseable

    public class RconClient
    extends Object
    implements Closeable
    An RCON client to remotely control a Minecraft server. Use open(String, int, String) to create an instance of RconClient, open a connection to a Minecraft server, and authenticate. Then use sendCommand(String) to send a command to the server. Make sure to close the connection again using close().

    The connection is only opened when the client is created. If for any reason the connection is closed or broken (eg. by the server shutting down or some network failure), no attempt is made to re-establish the connection. When sendCommand is invoked in such a case, an exception will occur.

    To enable RCON support in your Minecraft server, add the following to your server.properties (or modify existing properties if they are already present):

    
     enable-rcon=true
     rcon.password=<your password>
     rcon.port=<1-65535>
     
    另请参阅:
    Page describing the RCON protocol, Minecraft server.properties documentation
    • 字段详细资料

      • AUTHENTICATION_FAILURE_ID

        protected static final int AUTHENTICATION_FAILURE_ID
        另请参阅:
        常量字段值
      • DEFAULT_PAYLOAD_CHARSET

        protected static final Charset DEFAULT_PAYLOAD_CHARSET
      • TYPE_COMMAND

        protected static final int TYPE_COMMAND
        另请参阅:
        常量字段值
      • TYPE_AUTH

        protected static final int TYPE_AUTH
        另请参阅:
        常量字段值
      • PAYLOAD_CHARSET

        protected Charset PAYLOAD_CHARSET
      • currentRequestId

        protected final AtomicInteger currentRequestId
      • isAutoRead

        protected boolean isAutoRead
    • 构造器详细资料

      • RconClient

        protected RconClient​(SocketChannel socketChannel)
    • 方法详细资料

      • open

        public static RconClient open​(String host,
                                      int port,
                                      String password)
                               throws IOException
        Create an instance of RconClient, opening a connection to the specified host and port, and authenticate using the specified password. If no connection can be established, RconClientException is thrown, wrapping any exception of the underlying communication channel (eg. IOException). If the password is incorrect, an AuthFailureException is thrown.
        参数:
        host - The server's host name or IP address
        port - The server RCON port number (rcon.port in server.properties)
        password - The server's RCON password (rcon.password in server.properties)
        返回:
        An RconClient with an established connection
        抛出:
        RconClientException - When any exception is thrown by the communication channel
        AuthFailureException - When the password is wrong
        IOException
      • getCharset

        public Charset getCharset()
      • autoRead

        public boolean autoRead()
      • setAutoRead

        public void setAutoRead​(boolean r)
      • sendCommand

        public String sendCommand​(String command)
                           throws IOException
        Send command to the server, returning any data that was returned by the server. Note that in a lot of cases when the command is delivered and executed successfully, an empty response is returned by the server, resulting in an empty String as a return value of this method. When an unknown command is sent, the server will return some text along the lines of "Unknown command. Try /help for a list of commands".

        When any communication failure occurs (eg. broken connection, server has shut down), an RconClientException is thrown, wrapping any exception of the underlying communication channel (eg. IOException).

        参数:
        command - The command to send to the server
        返回:
        Response as returned by the server
        抛出:
        RconClientException - When any exception is thrown by the communication channel
        IOException
      • isOpen

        public boolean isOpen()
      • send_

        protected byte[] send_​(int type,
                               byte[] payload,
                               int from,
                               int length)
                        throws IOException
        抛出:
        IOException
      • toByteBuffer

        protected ByteBuffer toByteBuffer​(int requestId,
                                          int type,
                                          byte[] payload,
                                          int from,
                                          int length)
      • toByteBuffer

        protected ByteBuffer toByteBuffer​(int requestId,
                                          int type,
                                          String payload)