Pythelix communicates with clients over a raw TCP connection. By default it assumes UTF-8, which works for modern clients on Linux and macOS. Windows clients (especially classic telnet or MUD clients) may use a different encoding such as CP1252 or ISO-8859-15. Pythelix can handle all of these, either globally via configuration or on a per-client basis at runtime.
Supported encodings
| Name | Description |
|---|---|
"utf-8" |
Unicode UTF-8 (default) — modern terminals, Linux, macOS |
"cp1252" |
Windows-1252 — classic Windows telnet/MUD clients |
"iso-8859-15" |
ISO Latin-9 — Western European, common on older Unix terminals |
"iso-8859-1" |
ISO Latin-1 — older Western European standard |
Characters that cannot be represented in the target encoding are replaced with ?.
Setting the default encoding
The default encoding applies to every new client the moment it connects, before any scripting runs.
To change it, open the settings file (settings.txt, at the root of your game) and set DEFAULT_ENCODING:
DEFAULT_ENCODING=cp1252
Restart the server for the change to take effect. An environment variable named DEFAULT_ENCODING overrides the file, which deployment scripts may find handy.
If you run Pythelix from source with mix, the settings file isn’t used: open config/config.exs and set the default_encoding key instead:
config :pythelix,
...
default_encoding: "cp1252"
If the key is absent, "utf-8" is used.
The encoding of your worldlet files
This page is about players’ clients. Worldlet and scenario files have their own setting, WORLDLETS_ENCODING, used only for a file that isn’t valid UTF-8; it is described in the settings file.
Changing the encoding per client at runtime
You can read or change the encoding of any connected client through its encoding attribute in scripting. This is useful when the client announces its capabilities (for example, through a telnet negotiation or a login option).
Reading the current encoding:
enc = client.encoding # e.g. "utf-8"
Setting a new encoding:
client.encoding = "cp1252"
The change takes effect immediately: the very next message sent to or received from that client will use the new encoding. Setting an unsupported value raises a ValueError listing the accepted names.
A common pattern is to offer an encoding choice at login:
def input(client):
choice = client.last_input.strip().lower()
if choice == "1":
client.encoding = "utf-8"
elif choice == "2":
client.encoding = "cp1252"
elif choice == "3":
client.encoding = "iso-8859-15"
else:
client.msg("Invalid choice.")
return
client.msg("Encoding set.")
Changing the default for a running server without restart
Because client entities are virtual and reset on each connection, there is no way to change the default mid-session for existing clients. However, you can update all currently connected clients at once from a command or script:
for client in clients():
client.encoding = "cp1252"
clients() is a built-in that returns all currently connected client entities.