Skip to main content

New Page

# Getting the Ether Saga Odyssey updater working on a private server

A guide for game masters who want players' clients to update themselves through the stock updater
(`Launcher.exe` + `patcher.exe`) instead of passing zips around. It is based on getting the updater that ships with
the v655 client working against our own patch server: from reading what the programs do, and from running the real
Launcher and patcher against a test server. Other client builds may differ in the details (key size, file names), so
check each step against your own copy.

## 1. How the updater works

The updater has three parts in the client folder:

| Folder      | Program                         | Job                                                                                                         |
| ----------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `launcher/` | `Launcher.exe`                  | Updates the patcher's own files first, then starts `patcher.exe` and closes.                                |
| `patcher/`  | `patcher.exe` (+ `packdll.dll`) | Updates the game files in `element/`, then starts the game from its big button.                             |
| `element/`  | `elementclient.exe`             | The game. Most of its data lives inside `.pck` archives (`configs.pck`, `surfaces.pck`, `models.pck`, ...). |

On a normal start the Launcher checks the server, updates the patcher if needed, and starts it. The patcher opens
every `.pck` archive, works out which version the client is at, asks the server for its current version, and
downloads **one combined list** of every file changed since the player's version. For each file in that list it checks
whether the client already has those exact bytes. If not, it downloads the file, checks it, and writes it either as a
loose file or **into** the right archive. When it is done it closes the archives ("Folder closed successfully") and
shows the new game version with the start button ready.

Things worth knowing from the start:

- **Every list is signed.** The updater carries an RSA public key and refuses any list not signed with the matching
  private key. Out of the box that is the original publisher's key, so your first job is to put **your** key into the
  updater (section 3).
- **It uses plain HTTP and fetches one file at a time.** Update time grows with the number of files times the round
  trip to your server, more than with their size. A distant player with thousands of small files to fetch waits a long
  time even on a fast connection.
- **It never applies only the newest version.** A player who skipped twenty updates gets every file from all twenty
  in one go.
- **Files are compared by content, not by date.** A file the client already has with the same bytes is skipped.

## 2. Set up the patch server

Any static web server works (we use nginx). The updater is given one base URL, for example
`http://patch.example.com/patch/`, and requests everything under it:

```
patch/
  info/pid          the updater's first request: one number
  element/          game files
  patcher/          the patcher's own files
  launcher/         the launcher's files
```

Each of the three channel folders holds:

| File                      | What it is                                                                     |
| ------------------------- | ------------------------------------------------------------------------------ |
| `version`                 | the channel's current version, as `<N> 0`                                      |
| `v-1.inc`, `v-2.inc`, ... | signed change lists. Each lists every file changed over the last K versions.   |
| `files.md5`               | a signed list of every published file, used by the patcher's **Verify** button |
| the files themselves      | stored under encoded names (section 4)                                         |

- **Create all three channels, even ones you never publish into.** The updater asks for them on every run. An unused
  channel is `version` = `1 0` with an empty signed list and an empty signed `files.md5`.
- **`info/pid`** must contain the same number as `pid=` in the client's `patcher/server/pid.ini`. If it is missing, players
  get "Update server connection failed". If it differs, the Launcher stops updating the patcher's own files.
- **Serve plain HTTP**, with no redirect to HTTPS on the patch path (the Launcher does not follow redirects). Your
  website can still use HTTPS.
- **Allow byte-range requests**, so interrupted downloads can resume. nginx does this by default.
- **Don't cache the patch path** on a CDN or proxy. A cached old `version` means players quietly stop updating, and a
  changed file keeps its name, so a cache can also hand out the old copy, which then fails its check.

## 3. Make the updater trust your server (the signing key)

`patcher.exe` and `Launcher.exe` each contain the publisher's RSA public key as a plain-text PEM block
(`-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----`). To use your own server:

1. **Make a key pair once.** Use RSA, the same size as the key already in the exe (the stock v655 updater holds a
   1024-bit key). Keep the private key on the machine that publishes.
2. **Replace the key text in both exes** with your public key. The new block must be exactly the same length and use
   the same line endings as the old one, so nothing else in the file moves.
3. **If the exe has a Windows code signature, remove it.** It no longer matches after the edit, and an unsigned
   program is better than one with a broken signature.
4. Ship these exes in your client (section 6).

**Signing a list:** after the list text, add a line `-----BEGIN ELEMENT SIGNATURE-----`, then the signature in base64,
in lines of 64 characters. The signature is RSA PKCS#1 v1.5 with MD5 over the exact bytes of the list above that line.
Write lists with `\n` line endings, and never edit or re-upload a list in text mode after signing it.

**Back up the private key somewhere safe, off the server.** If you lose it, every player's updater rejects every list
from then on, and the only fix is getting new exes to every player by hand.

## 4. Point the client at your server

Two small files in the client tell the updater where to go. Both are UTF-16 little-endian with a byte-order mark.

- **`patcher/server/updateserver.txt`**: the server's name and base URL, each in double quotes, separated by a tab:
  `"MyServer"<TAB>"http://patch.example.com/patch/"`
- **`config/patcher/update.cfg`**: picks that entry and turns automatic updating on:

  ```
  AutoContinue 0
  SelectServerEveryTime 0
  AutoUpdating 1
  UpdateServerSelect MyServer
  ```

The game server's address is separate (`element/userdata/server/serverlist.txt` and
`element/userdata/currentserver.ini`, as `<port>:<host>`).

**Use hostnames, not IP addresses, for both from day one.** Every client you ship keeps these addresses until a patch
changes them, and clients that never update keep them forever. With a hostname, moving servers later is a DNS change.

## 5. Publishing an update

For each new version:

1. **Pack each changed file:** its original size as a 4-byte little-endian number, then the zlib-compressed bytes (or
   the raw bytes, when zlib does not make it smaller). The archives use the same form inside, which is why the patcher
   can write a download straight into a `.pck`.
2. **Take the MD5 of the packed bytes** (not the original file). That MD5 goes in the lists, and the patcher checks
   every download against it.
3. **Encode the path.** Paths are relative to the client's `element/` folder. Each path segment is base64-encoded
   (UTF-8) using `+` and `-` (not `+` and `/`), and the segments are joined with `/`. For example,
   `configs/item_ext_desc.txt` becomes `/Y29uZmlncw==/aXRlbV9leHRfZGVzYy50eHQ=`. Store the packed file on the server
   under that name, inside the channel folder.
4. **Rewrite every change list.** The patcher asks for `v-K.inc`, where K is how many versions behind the player is,
   rounded up (exact for 1 to 10, then 12, 15, 19, 24, 30, ...). So after each publish, every list a player could ask
   for must be rewritten to cover the new version. Each line is `!<md5> <encoded path>` with the file's latest MD5.
5. **Rewrite `files.md5`** (`<md5> <encoded path>` for every published file), and sign every list.
6. **Write `version` last**, after the files and lists are in place. Write each file to a temporary name and rename
   it into place, so nobody downloads a half-written list.
7. **Check from a PC outside your server:** the new version shows, the files download, their MD5s match the list, and
   they unpack to exactly what you meant to send. Then update one real test client through the Launcher (section 7).

Keep a record of every publish (which version changed which files). You need it to rebuild the lists each time.

## 6. What to publish, and what to avoid

- **Single files into archives:** if a path starts with the name of an archive (`configs`, `surfaces`, `interfaces`,
  `gfx`, `models`, `textures`, ...), the patcher writes it **into** that `.pck`. That is how you change almost all game
  data. Anything else becomes a loose file.
- **The archive wins:** the game reads an archive's copy before a loose file of the same name. A loose
  `configs/x.txt` next to a `configs.pck` that already has `x.txt` is ignored.
- **Never publish a whole `.pck`.** The patcher has the archives open while it works and drops a whole archive sent as
  one file, so it never lands. A big archive in `files.md5` can also crash the 32-bit patcher's Verify. Publish the
  changed entries instead.
- **One spelling per file.** Upper/lower case and `/` vs `\` count as the same file. If you publish two spellings
  with different content, players end up with whichever was written last.
- **Deleting is possible:** a list line starting with `-` (for example `-` and 32 zeros in place of the MD5) removes
  a loose file or an archive entry. Moving and renaming are not possible: delete the old path and add the new one.
- **To undo a change,** publish the old file as a new version. Never lower the version number.
- **Exes can be published,** but the patcher refuses to update while **any** Ether Saga client is open on the PC,
  including other servers' clients.

## 7. Ship a full client that patches

New players need a starting client, and this is where most of our early failures came from: the Launcher refused
every hand-built client with **"File folder corrupted"** even though all the files were there.

The client keeps update state files in `config/element/`:

| File                        | What it is                                                                         |
| --------------------------- | ---------------------------------------------------------------------------------- |
| `version.sw`                | the client's version                                                               |
| `inc.sw`, `ustate.sw`       | the list and progress of an update **in progress**. A finished client has neither. |
| `FullList.sw`, `Listver.sw` | Verify bookkeeping. Keep them.                                                     |

Each archive also records the version it was last updated to, and the client counts as the **lowest** of all of
these. The Launcher refuses a folder where they disagree.

**What broke it for us:**

- writing a new number into `version.sw` by hand,
- deleting `inc.sw` / `ustate.sw` from a client that was halfway through an update, leaving archives at different
  versions,
- starting from a client that had been zipped while its updater was still running,
- removing files under `config/` while "cleaning up".

**What works:**

1. Start from a real client that **finished** updating against your server.
2. Remove only junk: logs, screenshots, crash dumps, backups, caches, personal character files under `userdata/`.
   Leave `config/` and every `.pck` alone.
3. Make sure it carries your re-keyed updater, your server addresses, and the right `pid.ini`.
4. Zip it, install it fresh in a new folder, and run the Launcher. **Success:** it downloads no game files, shows the
   current version, and the game starts.

**Rebuild the download now and then.** Every update published after the zip was built is something each new player
has to fetch one file at a time.

**Tell players to start the game through the Launcher.** Players who start `elementclient.exe` directly never update.

## 8. Common problems

**Where to look:**

- **Your web server's access log, first.** It shows exactly what the updater asked for, in order: `info/pid`, then the
  patcher channel, then `element/version`, then the list, then the files. If `element/version` never appears, the
  problem comes before the game files, whatever the window says.
- `config/element/update.log`: "Start update", "Download file", "Folder closed successfully".
- `patcher/Logs/AF.log`: archive errors. It is overwritten at every start, so read it while the patcher is still open.
- `element/logs/EC.log`: the game's own log, if the game fails to start after an update.

| Symptom                                              | Likely cause                                                                                                         | What to do                                                                                                        |
| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| "Update server connection failed"                    | Wrong URL, `info/pid` missing, or the server not reachable over HTTP                                                 | Open `<base URL>info/pid` in a browser from the player's PC.                                                      |
| Updates never apply                                  | Lists not signed with the key in the players' exes, or a list changed after signing                                  | Re-sign; upload in binary mode.                                                                                   |
| Patcher says up to date but nothing changed          | The server version is not ahead of the client, or the update stopped before the game files                           | Check the access log for `element/version`.                                                                       |
| "File folder corrupted" on a fresh client            | Hand-edited or missing state files, or a missing archive                                                             | Rebuild the client as in section 7.                                                                               |
| "File folder corrupted" right after closing the game | A known false alarm in the old patcher                                                                               | Wait a couple of minutes and start again. **Don't press Verify then**: it can empty the archive it fails to read. |
| "Client running / Unable to proceed"                 | An Ether Saga client is open, even one from another server                                                           | Close every client (check Task Manager).                                                                          |
| "Update is large. Manual / Auto" on some PCs         | A quirk in how the patcher reads the list header                                                                     | Press **Auto**; it continues normally.                                                                            |
| A download keeps failing its check                   | The list MD5 was taken of the unpacked file, or a cache serves an old copy                                           | MD5 the packed bytes; purge caches.                                                                               |
| A published file never shows in game                 | A whole `.pck` was published, the file went out under two spellings, or a loose file is shadowed by an archive entry | Publish the archive entry, with one spelling.                                                                     |
| The game crashes after an update on one PC           | That player's update was interrupted (closed early, full disk, antivirus) and an archive is damaged                  | Replace the archive from a healthy client at the same version. Verify is not a reliable repair.                   |
| Updates are very slow for distant players            | Too many small files                                                                                                 | Rebuild the full-client download.                                                                                 |

**About interrupted updates:** an archive's index is written only when the patcher closes it at the end of a session, and
every session rewrites every archive. If the patcher is killed or the disk fills up in that phase, archives can be
left unreadable, even ones that had no changes. Tell players to let the patcher finish ("Folder closed successfully")
and to keep a few GB of disk free.