[*Warcraft III: The Frozen Throne*](http://en.wikipedia.org/wiki/Warcraft_III:_The_Frozen_Throne) is an expansion pack for the tower defense game *Warcraft III* by Blizzard Entertainment. It was released for Microsoft Windows and Mac OS X in 2003. This article will explain how to get multiplayer gameplay working on Linux.

The game provides two options for multiplayer: "LAN" and "battle.net". The LAN option will work out of the box if all players are on the same subnet (broadcast traffic is routed properly). The "battle.net" option, which allows multiplayer over the open internet, is slightly more complicated because Blizzard has shut down the original *Warcraft III* multiplayer servers. Therefore, for this option to work:
1. [One player must set up a PvPGN server at a publicly reachable, static IPv4 address.](#host-instructions)
2. [All players must patch Warcraft III to use that server instead of the default.](#client-instructions)
3. Then, either:
    1. [The game host must enable port forwarding.](#port-forwarding)
    2. Or: [all players must connect to the same VPN.](#creating-a-vpn-with-wireguard)

These instructions focus on how to accomplish this on Linux, but the basic concept is the same regardless of operating system. Although the game did receive a Mac OS X release, that version will not work because the PvPGN patch is only available for Windows. Therefore, Mac users should also follow the WINE instructions.

### Dependencies
All players will need:

* *Warcraft III: The Frozen Throne* for Windows
* 32-bit WINE

## Running *Warcraft III* with WINE

To run the game on Linux, you must install [WINE](http://winehq.org), a compatibility layer created to allow running Windows applications on UNIX-like operating systems. There should be a package for it available from your Linux distro.

Once WINE is installed, check that it works by using it to run *Warcraft III*, as shown below. The game may not play nice with all desktop environments because it changes the screen resolution and runs in full screen. It seems to work acceptably in [i3](http://i3wm.org), although unfocusing the game window may cause issues.

```
$ cd /path/to/Warcraft_III
$ wine Frozen\ Throne.exe
```
*NOTE: If you only want LAN multiplayer, this completes setup.*

## Patching *Warcraft III* for Online Play

Once you've confirmed that the game works with WINE, it's time to patch it to use a chosen PvPGN multiplayer server, instead of (now defunct) battle.net server hosted by Blizzard.

### Host Instructions

To run your own PvPGN server, first you must build it from source. ohea.xyz provides a convenient Dockerfile and build script for doing this. The machine hosting the server should have a static, publicly reachable IPv4 address.

#### Using Docker

Clone the pvpgn Docker repo:

```
$ git clone https://git.ohea.xyz/containers/pvpgn
$ cp docker-compose.override.yml.example docker-compose.override.yml 
```

Now you need to configure `docker-compose.override.yml`. The default configuration should be sufficent for most users. If you want to customize the PvPGN configuration files, the provided terms of service, or the provided new account creation info, you can uncomment the corresponding mappings.

Run the docker container:

```
$ docker compose up -d
```

Your PvPGN server should now be running. It can be stopped by runnning:

```
$ docker compose down
```

#### Without Docker

To build and install:

```
$ git clone https://git.ohea.xyz/containers/pvpgn
$ cd pvpgn
$ sudo ./build.sh
```

To run the server:

```
$ sudo /usr/local/pvpgn/sbin/bnetd -D
```
Use `Ctrl+C` to quit.

### Client Instructions

1. Download the [Warcraft 3 Loader for PvPGN](http://pvpgn.pro/w3l.html) and extract the ZIP into the directory containing `Frozen Throne.exe`.

2. Create the necessary Windows registry entries to trick Warcraft 3 into connecting to your PvPGN server. This is most easily done by importing a `.reg` file with the correct value.
   * An online tool to generate this is available [here](http://ohea.xyz/wc3reggen/).
   * Alternatively, the pvpgn Docker repo contains a bash script with the same functionality. The first argument to the script is the name of the server, and the second is the URL or IP address. For example, to add a server called `ohea` with the URL `ohea.xyz`, you would run the following commands:
    ```
    $ git clone https://git.ohea.xyz/containers/pvpgn
    $ cd pvpgn
    $ ./wc3reggen.sh ohea ohea.xyz > wc3.reg
    ```
    * After using either method to generate the `.reg` file, add the server information to the Windows registry like so:
    ```
    $ wine regedit wc3.reg
    ```

## Port Forwarding

The player hosting in-game needs to log into his router and enable port forwarding for **TCP and UDP on ports 6113-6119**. How to do this depends on the router.

## Creating a VPN with Wireguard

Alternatively, if port forwarding isn't practical for your setup, [Wireguard](http://www.wireguard.com) can be used to create a Virtual Private Network (VPN) instead. This effectively tricks the players' computers into thinking they are all on the same network. One player must host the VPN, and the other players must then connect to it. (Note that this is independent of who hosts in-game.)

### Host Instructions

**(TODO)**

### Client Instructions

To connect to someone else's Wireguard VPN:

1. First, install Wireguard. It should be available as a package for your Linux distro.

2. Then, generate a public/private key pair, like so:
```
$ umask 077
$ wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey
```

3. Then create a config file, `/etc/wireguard/wg0.conf` as root:
```
[Interface]
PrivateKey = ****
Address = 10.0.5.*/24
DNS = 10.0.5.1

[Peer]
PublicKey = ****
PresharedKey = ****
AllowedIPs = 10.0.0.0/16
Endpoint = *.*.*.*:****
```
* `PrivateKey` should be the private key generated in Step 2. It is the contents of `/etc/wireguard/privatekey`. *Do not share this value with anyone.*
* In the value of `Address`, replace the `*` with an 8-bit positive integer (i.e. less than 256) of your choice.
* `PublicKey` should be the public key generated in Step 2. It is the contents of  `/etc/wireguard/publickey`. You must communicate this value to the VPN host.
* The VPN host must provide you with the value for `PresharedKey`.
* `Endpoint` should be the host VPN's IPv4 address, with the port to use Wireguard on after the `:` (default: 51820).
4. To start Wireguard, run the following command:
```
$ sudo wg-quick up wg0
```
If it works, the IP address at `DNS` in the `wg0.conf` you just created should be pingable. All of your internet traffic will now be through the VPN.
5. To disconnect from the VPN when you're done playing, run the following command:
```
$ sudo wg-quick down wg0
```
