rcon.lua
a simple RCON library written in plain Lua, using LuaSocket (and optionally copas)
i wrote it to interface with Minecraft servers, but it should work with any game that implements the RCON protocol. currently the library
does not handle packet fragmentation, but i will definitely add that as soon as it causes issues for me :P
as an example of how to use the library:
local rcon = require "rcon"
local c = rcon.connect("localhost", 25575)
c:send("say hello from rcon!")
--> returns empty string (no response)
c:send("list")
--> returns "There are 0 of a max of 20 players online:"
c:close()
the library also provides a command-line tool to send rcon commands, either interactively or by passing arguments
usage: rcon [-H hostname] [-P port] [-t] [-s] [-w seconds] -p PASSWORD [command1] [command2]
the default hostname is localhost
, and the default port is 25575
(the vanilla server default).
if no RCON commands are specified, the tool will enter interactive mode.
multiple commands can be specified, and they will be run in order. commands with spaces in them should be enclosed in quotes.
the -p
(password) argument must be provided.
the -t
argument will start the interactive terminal even if commands are specified.
the -s
argument will silence all non-error output.
the -w
argument will wait for the specified number of seconds between each command (but not after the last command).
library reference
🔗 rcon.connect(address, port, password)
creates an RCON connection to the server at the specified address and port (following the rules of socket.connect), and authenticates using the specified password. note that the RCON protocol transmits this password in plain text.
returns the rconconnection
object, ornil
followed by an error message.🔗 rcon.login(socket, password)
authenticates on an existing socket, returning the rcon object likercon.connect
. this is useful for wrapping a socket with copas first:local c = rcon.login(copas.wrap(socket.connect("localhost", 25575)), "password")
🔗 connection:send(command)
sends a command (string) to the server and returns the server's response as a string. on error, returnsnil
followed by an error message.
the server may respond with an empty string if the command produces no output, and may respond with a string that is seemingly missing any newline characters.🔗 connection:close()
closes the socket of the connection.
download/install
install from Luarocks:
luarocks install rcon
or manually download the rock (rcon-0.1-1.all.rock) or its source (rcon-0.1.tar.gz)