Home | Rules | Authors | Mailing lists | Game options and menus | Network game | Command line parameters | Platform specific issues | User levels | Core algorithm | Source code | Bugs | To do | Copying

# Network game

## Basics

Since release 5.4.0, Liquid War includes network support, that's to say that people can play over a LAN (Local Area Network). However, due to limitations in Liquid War's legacy code, and also because of the lack of time I have, it might be a little tricky to set up a network game at first. So please read this section carefully.

You should keep in mind that:

- DOS only releases of Liquid War do not include network support, only Windows and GNU/Linux versions will allow you to set up a network game.
- The game should run fine on any LAN, but there's no garantee the game will be playable on the Internet. Indeed if your "ping delay" is not good enough, the game will be awfully slow. Bandwidth is not an issue, since Liquid War rarely needs more than 2 Kb/sec.
- You'll need to know what an IP address is.
- You don't need to set up a network game to run a multiplayer game. Liquid War was originally a multiplayer game without network support. Network support is here only for people who don't feel comfortable when playing at 6 on the same keyboard 8-)

## Getting started

### What do you need?

You'll basically need 2 computers connected on the same LAN. We'll call them computer A and B. You might be able to play over the Internet too, but the game can be harder to set up and - which is worse - very slow.

You'll also need to know the IP address of computer A. Type "ipconfig" under Windows or "ifconfig" as root under GNU/Linux to get this information if you don't have it.

### Starting the server

Liquid War uses a very traditionnal client/server approach. Basically, the server gets informations from all the clients and then dispatches the collected information to everybody.

So you'll need to start a server on computer A by running "liquidwar-server" on GNU/Linux or "lwwinsrv.exe" on windows. This is a console application, ie it does not set up any graphic mode.

Here's a small example of a server start on GNU/Linux:

    $ liquidwar-server
    How many teams will connect to this server?

At this point you must enter a number between 2 and 6, and then press "ENTER". In this example we will answer 4. The server really needs to know how many teams will be in the game: when enough teams are connected, the game starts. It's possible to skip this question by typing "liquidwar-server -4" instead of a plain "liquidwar-server".

    Use "-4" to get rid of this question.
    Register on "www.ufoot.org/metaserver/" (y/n)?

Now if we answer "y", then the server will automatically contact the "meta-server" and it will be listed on www.ufoot.org/liquidwar/metaserver.php3. This can be convenient for people who want to find other gamers to play with on the Net. For now, let's answer "n", we'll test this meta-server stuff later 8-)

    Use "-private" to get rid of this question.
    2002-06-03 16:43:00: Listening on port 8035...
    2002-06-03 16:43:00: Waiting for 4 teams...

Now the server is ready to accept clients. By default it listens to clients on port 8035. You could change this behavior setting by calling "liquidwar-server -port 8061" for instance, but let's use the default port to make things easier.

### Starting the clients

Start the client on computer A normally by typing "liquidwar" on GNU/Linux or double-click "lwwin.exe" on Windows.

Go to the "Teams" menu and select 2 teams, red and blue for instance. If you don't know how to do this, then try and play Liquid War on a single computer first.

Now come back to the main menu, and a "Net Game" button should be available. Click it. Now you should be able to:

- Start the game.
- Change the IP address of the server.
- Change the default communication port.
- Search for internet games automatically.

Since the server is also running on the same machine (A), you can leave the default IP address as is (127.0.0.1).

Now you are ready to start the second client on computer B. Like with computer A, you'll have to:

- Select 2 teams, green an yellow this time.
- Select "Net Game" in the main menu.

But this time you'll also need to change the server address, since the client is not running on the same computer than the server.

Now click on "Start game" on computer A. The server should display messages like this:

    2002-06-03 16:44:48: Connection from "127.0.0.1:34677"
    2002-06-03 16:44:48: Team "Napoleon" on client "127.0.0.1:34677" accepted
    2002-06-03 16:44:48: Team "Attila" on client "127.0.0.1:34677" accepted
    2002-06-03 16:44:49: Client "127.0.0.1:34677" accepted
    2002-06-03 16:44:49: Waiting for 2 teams...

And on the client you should see a screen which says "Waiting for 2 team(s)" with the list of connected players below (Napoleon and Attila). You do not need to click on the "Start now" button.

Now click on "Start game" on computer B. The server should display messages like this:

    2002-06-03 16:49:14: Connection from "192.168.1.1:1098"
    2002-06-03 16:49:14: Team "Henri IV" on client "192.168.1.1:1098" accepted
    2002-06-03 16:49:14: Team "Cesar" on client "192.168.1.1:1098" accepted
    2002-06-03 16:49:15: Client "192.168.1.1:1098" accepted
    2002-06-03 16:49:15: Client "192.168.1.1:1098" ready
    2002-06-03 16:49:15: Client "127.0.0.1:34677" ready
    2002-06-03 16:49:15: Sending info to "127.0.0.1:34677"
    2002-06-03 16:49:15: Sending info to "192.168.1.1:1098"
    2002-06-03 16:49:16: Game start

And at that point, the game should start 8-)

### Restart a new game

Once the game is over, you can start another network game on the clients without touching the server, because the server automatically restarts and waits for players to connect.

To stop the server - if you want to change its settings for instance, just go to the console where it's running and press CTRL-C.

## Using the meta-server

### Basics

The meta-server is a piece of software which is running on my web site, and allows servers to register themselves so that client can get a list of available servers.

It's written in PHP and is _very_ basic but I believe it's enough for what has to be done: maintain a list of running servers.

The source code for the meta-server is included in the source package of Liquid War, so you might run such a server yourself if you want to. However, by default, servers will register themselves on my web site, and will be listed on www.ufoot.org/liquidwar/metaserver.php3.

### How to register a server

Launch the server, and when you get the question:

    Register on "www.ufoot.org/metaserver/" (y/n)?

answer "y".

Note that if you're behind a proxy or a firewall, the server might be unable to register itself. Clients might also have problems to connect themselves on your server if there's a machine which does NAT (Network Address Translation) between you and the meta-server.

### How to find a server

In the main menu, click on "Net Game" and then "Search for internet games".

Now you should see a list of available servers. You can click on the items in the list to get more informations about a given server. Once you have chosen a server, click on "Join now".

Now you get on a "Waiting n teams" screen. You might be interested in using the "Start now" button. Indeed, if you are 4 players connected on a server that accepts up to 6 players, maybe you'll want to start the game right away without waiting for 2 more players. In this case, every player must click "Start now". A "*" character will replace the "-" in the players list when a player clicks on "Start now". When all the players are displayed with a "*a, the game starts.

Note that you can also get the list of available servers from www.ufoot.org/liquidwar/metaserver.php3. There you'll also find a little chat-box which will allow you to send exchange messages with other players.

## Options

### Server options

You can pass options to the server using the command line. The following parameters are accepted:

- "-n" where "n" is a number between 2 and 6 : with this option you can tell the server how many teams will connect to the game. Beware, there can be several teams on the same computer, so if you want to have a computer with 2 players on it and 2 other computers with a single player, then you need to use the "-4" option.
- "-lag n" where "n" is an integer : with this option, you can control the lag used at startup. Normally, Liquid War handles this parameter automatically, but you might want to force it to a given value.
- "-port n" where "n" is an integer : allows you to change the IP port used by the server to listen to the clients. if you omit this parameter, the default port is (8035) is used.
- "-netlog" : if you use this option, the server will dump all the network traffic on the standard output. This is usefull for debugging.
- "-log file.log" : dumps all informations in "file.log" instead of using the standard output.
- "-public" : skips the "Register on ..." question, and registers the server automatically on the meta-server, so that clients can find it easily.
- "-private" : skips the "Register on ..." question, and does not register the server at all.
- "-metaserver url" : redefines the URL of the meta-server. Usefull if you want to use your own meta-server.
- "-comment This_is_a_comment" : associates a comment to the server, which will be displayed by the meta-server. Note that the character "_" will be replaced by spaces. This makes command line parsing easier. I'm lazy 8-)
- "-password pw" : associates a password to the server. For now this option does not work since password support is not implemented yet.

### Client options

The "-netlog" option works for the client too. Otherwise, all the options can be set from the "Net Game" menu.

Note that when you play a network game, the settings such as those found in the "Rules" menu must be the same on every computer. However, Liquid War does this automatically. But a consequence is that after a network game, your settings might have changed if you were not on the machine from which the settings have been taken and then dispatched to every player.

## About Liquid War's network implementation

### Basics

Liquid War uses TCP sockets, and a single-threaded server. This implies that:

- The game can sometimes get blocked if you play on Internet.
- The server can't talk simultaneously with several clients.

I needed to use TCP sockets, since LW's algorithm can not cope with any data loss and it's not a reasonnable to try and anticipate what the map would be like if the player did not move etc...

I did not implement any multithreaded stuff since I'm lazy and however, clients need to have informations about all the other before something can be done. However, implementing a mutltithreaded server could have advantages over the current solution.

### What is this lag stuff anyway?

In Liquid War, all the clients send their key presses to the server, and then the server dispatches this information to everyone. This has to be done for every round.

You can easily imagine that if a player has a poor connection, with a very long "ping delay", it can take quite a long time to send the information to the server, and then get it back.

So what Liquid War does is that at the beginning of the game, the server sends a couple of "blank" key strokes to the clients. This way, clients receive data from the server before thay have sent any. The number of key strokes sent at the beginning of the game is called the "lag".

So if it takes 200 msec to send and then receive data from the server (approx the time returned by the "ping" command) then with a lag of 5, you can theorically play at a rate of 25 rounds/sec.

On one hand, setting the lag to a high value will avoid many network errors and allow you to play at a very fast pace, but the big drawback is that there will be quite a long time between the instant you send a key stroke to the server and the moment it comes back to you. On the other hand, setting the lag to a low value will limit dratically he number of rounds per second.

However, since release 5.4.1, the "lag" is modified automatically and should adapt itself to the situation. I've not been able to test it in real conditions yet, but it should work 8-)

Still, setting the lag to a sensible default value can save you some trouble. Indeed, by default, Liquid War will choose a value (5), but it can not guess if you are playing on Internet or on a 100 MBit LAN, and it can take quite a long time before Liquid War automatically finds the right value. To know the right value which should be used with the "-lag" option, simply play a few games and watch the average lag (which is displayed on the server console every minute) at the end of the game.

## Troubleshooting

### General information

Network support in 5.4 is still experimental in many ways, so you might get weird behaviors. Basically, if you have a problem, just do the following:

- Stop and restart the server when something goes wrong. To stop it, use CTRL-C.
- Check out that you have entered the correct IP addresses.
- Try and start the client and the server using the "-netlog" option to have an idea about what's happening.

### Bugs in 5.4.x corrected in 5.4.2

Liquid War 5.4.0 and 5.4.1 were very hard to play over the Internet. The reason is that the network routines did not do enough error checking, and therefore there were very often errors when sending and/or receiving the map to the server. Hopefully, this bug should not appear anymore in 5.4.2 or any other recent release.

This documentation is also available on: www.ufoot.org/liquidwar.