Manual:Networking Functions

From Mudlet
Jump to: navigation, search

Networking Functions

A collection of functions for managing networking.


connectToServer(host, port, [save])
Connects to a given game.
  • host:
Server domain or IP address.
  • port:
Servers port.
  • save:
(optional, boolean) if provided, saves the new connection parameters in the profile so they'll be used next time you open it.

Note Note: save is available in Mudlet 3.2+.

connectToServer("", 3000)

-- save to disk so these parameters are used next time when opening the profile
connectToServer("", 3000, true)


Disconnects you from the game right away. Note that this will not properly log you out of the game - use an ingame command for that. Such commands vary, but typically QUIT will work.
See also: reconnect()


downloadFile(saveto, url)
Downloads the resource at the given url into the saveto location on disk. This does not pause the script until the file is downloaded - instead, it lets it continue right away and downloads in the background. When a download is finished, the sysDownloadDone event is raised (with the saveto location as the argument), or when a download fails, the sysDownloadError event is raised with the reason for failure. You may call downloadFile multiple times and have multiple downloads going on at once - but they aren’t guaranteed to be downloaded in the same order that you started them in.

Note Note: Since Mudlet 3.0, https downloads are supported and the actual url that was used for the download is returned - useful in case of redirects.

-- just download a file and save it in our profile folder
local saveto = getMudletHomeDir().."/"
local url = ""
downloadFile(saveto, url)
cecho("<white>Downloading <green>"..url.."<white> to <green>"..saveto.."\n")

A more advanced example that downloads a webpage, reads it, and prints a result from it:

-- create a function to parse the downloaded webpage and display a result
function downloaded_file(_, filename)
  -- is the file that downloaded ours?
  if not filename:find("achaea-who-count.html", 1, true) then return end

  -- read the contents of the webpage in
  local f, s, webpage =
  if f then webpage = f:read("*a"); io.close(f) end
  -- delete the file on disk, don't clutter

  -- parse our downloaded file for the player count
  local pc = webpage:match([[Total: (%d+) players online]])
  display("Achaea has "..tostring(pc).." players on right now.")

-- register our function to run on the event that something was downloaded
registerAnonymousEventHandler("sysDownloadDone", "downloaded_file")

-- download a list of fake users for a demo
downloadFile(getMudletHomeDir().."/achaea-who-count.html", "")

Result should look like this:

DownloadFile demo.png.


Returns a list of channels the IRC client is joined to as a lua table. If the client is not yet started the value returned is loaded from disk and represents channels the client will auto-join when started.
See also: setIrcChannels()

Note Note: Available in Mudlet 3.3+

-- Prints: {"#mudlet", "#lua"}


Returns true+host where host is a string containing the host name of the IRC server, as given to the client by the server while starting the IRC connection. If the client has not yet started or finished connecting this will return false and an empty string.
This function can be particularly useful for testing if the IRC client has connected to a server prior to sending data, and it will not auto-start the IRC client.
The hostname value this function returns can be used to test if sysIrcMessage events are sent from the server or a user on the network.
local status, hostname = getIrcConnectedHost()

if status == true then
  -- do something with connected IRC, send IRC commands, store 'hostname' elsewhere.
  -- if sysIrcMessage sender = hostname from above, message is likely a status, command response, or an error from the Server.
  -- print a status, change connection settings, or just continue waiting to send IRC data.

Note Note: Available in Mudlet 3.3+


Returns a string containing the IRC client nickname. If the client is not yet started, your default nickname is loaded from IRC client configuration.
See also: setIrcNick()

Note Note: Available in Mudlet 3.3+

local nick = getIrcNick()
-- Prints: "Sheldor"


Returns the IRC client server name and port as a string and a number respectively. If the client is not yet started your default server is loaded from IRC client configuration.
See also: setIrcServer()

Note Note: Available in Mudlet 3.3+

local server, port = getIrcServer()
echo("server: "..server..", port: "..port.."\n")


Returns the last measured response time between the sent command and the server reply in seconds - e.g. 0.058 (=58 milliseconds lag) or 0.309 (=309 milliseconds). This is the N: number you see bottom-right of Mudlet.

Also known as server lag.


Need example


openUrl (url)
Opens the default OS browser for the given URL.


Force-reconnects (so if you're connected, it'll disconnect) you to the game.
-- you could trigger this on a log out message to reconnect, if you'd like


Restarts the IRC client connection, reloading configurations from disk before reconnecting the IRC client.

Note Note: Available in Mudlet 3.3+


sendAll(list of things to send, [echo back or not])
sends multiple things to the game. If you'd like the commands not to be shown, include false at the end.
See also: send()
-- instead of using many send() calls, you can use one sendAll
sendAll("outr paint", "outr canvas", "paint canvas")
-- can also have the commands not be echoed
sendAll("hi", "bye", false)


sendATCP(message, what)
Need description
See also: ATCP Protocol, ATCP Extensions, Achaea Telnet Client Protocol specification, Description by forum user KaVir (2013), Description by forum user Iocun (2009)
  • message:
The message that you want to send.
  • what:
Need description

Need example


Sends a GMCP message to the server. The IRE document on GMCP has information about what can be sent, and what tables it will use, etcetera.
Note that this function is rarely used in practice. For most GMCP modules, the messages are automatically sent by the server when a relevant event happens in the game. For example, LOOKing in your room prompts the server to send the room description and contents, as well as the GMCP message gmcp.Room. A call to sendGMCP would not be required in this case.
See also: GMCP Scripting
--This would send "Core.KeepAlive" to the server, which resets the timeout

--This would send a request for the server to send an update to the gmcp.Char.Skills.Groups table.
sendGMCP("Char.Skills.Get {}")

--This would send a request for the server to send a list of the skills in the 
--vision group to the gmcp.Char.Skills.List table.

sendGMCP("Char.Skills.Get " .. yajl.to_string{group = "vision"})

--And finally, this would send a request for the server to send the info for 
--hide in the woodlore group to the gmcp.Char.Skills.Info table

sendGMCP("Char.Skills.Get " .. yajl.to_string{group="MWP", name="block"})


sendMSDP(variable[, value][, value...])
Sends a MSDP message to the server.
  • variable:
The variable, in MSDP terms, that you want to request from the server.
  • value:
The variables value that you want to request. You can request more than one value at a time.
See Also: MSDP support in Mudlet, Mud Server Data Protocol specification
-- ask for a list of commands, lists, and reportable variables that the server supports

-- ask the server to start keeping you up to date on your health

-- or on your health and location


sendIrc(target, message)
Sends a message to an IRC channel or person. Returns true+status if message could be sent or was successfully processed by the client, or nil+error if the client is not ready for sending, and false+status if the client filtered the message or failed to send it for some reason. If the IRC client hasn't started yet, this function will initiate the IRC client and begin a connection.

Note Note: Since Mudlet 3.3, auto-opens the IRC window and returns the success status.

  • target:
nick or channel name and if omitted will default to the first available channel in the list of joined channels.
  • message:
The message to send, may contain IRC client commands which start with / and can use all commands which are available through the client window.
-- this would send "hello from Mudlet!" to the channel #mudlet on
sendIrc("#mudlet", "hello from Mudlet!")
-- this would send "identify password" in a private message to Nickserv on
sendIrc("Nickserv", "identify password")

-- use an in-built IRC command
sendIrc("#mudlet", "/topic")

Note Note: The following IRC commands are available since Mudlet 3.3:

  • /ACTION <target> <message...>
  • /ADMIN (<server>)
  • /AWAY (<reason...>)
  • /CLEAR (<buffer>) -- Clears the text log for the given buffer name. Uses the current active buffer if none are given.
  • /CLOSE (<buffer>) -- Closes the buffer and removes it from the Buffer list. Uses the current active buffer if none are given.
  • /HELP (<command>) -- Displays some help information about a given command or lists all available commands.
  • /INFO (<server>)
  • /INVITE <user> (<#channel>)
  • /JOIN <#channel> (<key>)
  • /KICK (<#channel>) <user> (<reason...>)
  • /KNOCK <#channel> (<message...>)
  • /LIST (<channels>) (<server>)
  • /ME [target] <message...>
  • /MODE (<channel/user>) (<mode>) (<arg>)
  • /MOTD (<server>)
  • /MSG <target> <message...> -- Sends a message to target, can be used to send Private messages.
  • /NAMES (<#channel>)
  • /NICK <nick>
  • /NOTICE <#channel/user> <message...>
  • /PART (<#channel>) (<message...>)
  • /PING (<user>)
  • /RECONNECT -- Issues a Quit command to the IRC Server and closes the IRC connection then reconnects to the IRC server. The same as calling ircRestart() in Lua.
  • /QUIT (<message...>)
  • /QUOTE <command> (<parameters...>)
  • /STATS <query> (<server>)
  • /TIME (<user>)
  • /TOPIC (<#channel>) (<topic...>)
  • /TRACE (<target>)
  • /USERS (<server>)
  • /VERSION (<user>)
  • /WHO <mask>
  • /WHOIS <user>
  • /WHOWAS <user>

Note Note: The following IRC commands are available since Mudlet 3.15:

  • /MSGLIMIT <limit> (<buffer>) -- Sets the limit for messages to keep in the IRC client message buffers and saves this setting. If a specific buffer/channel name is given the limit is not saved and applies to the given buffer until the application is closed or the limit is changed again. For this reason, global settings should be applied first, before settings for specific channels/PM buffers.


Sends a message via the 102 subchannel back to the MUD (that's used in Aardwolf). The msg is in a two byte format; see the link below to the Aardwolf Wiki for how that works.
-- turn prompt flags on:

-- turn prompt flags off:

To see the list of options that Aardwolf supports go to: Using Telnet negotiation to control MUD client interaction.


setIrcChannels( channels )
Saves the given channels to disk as the new IRC client channel auto-join configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()
See also: getIrcChannels(), restartIrc()
  • channels:
A table containing strings which are valid channel names. Any channels in the list which aren't valid are removed from the list.

Note Note: Available in Mudlet 3.3+

setIrcChannels( {"#mudlet", "#lua", "irc"} )
-- Only the first two will be accepted, as "irc" is not a valid channel name.


setIrcNick( nickname )
Saves the given nickname to disk as the new IRC client configuration. This value is not applied to the current active IRC client until it is restarted with restartIrc()
See also: getIrcNick(), restartIrc()
  • nickname:
A string with your new desired name in IRC.

Note Note: Available in Mudlet 3.3+

setIrcNick( "Sheldor" )


setIrcServer( hostname, port )
Saves the given server's address to disk as the new IRC client connection configuration. These values are not applied to the current active IRC client until it is restarted with restartIrc()
See also: getIrcServer(), restartIrc()
  • hostname:
A string containing the hostname of the IRC server.
  • port:
(optional) A number indicating the port of the IRC server. Defaults to 6667, if not provided.

Note Note: Available in Mudlet 3.3+

setIrcServer( "", 6667 )