Previous | Contents | Next

## 10. Running a Server

This section describes how to run your own online Knights server.

### Installation

For Windows, the Knights server program is available as a separate download from the Knights web site. The file should be unzipped to a directory of your choice, and then you can run the server from the command line by cd-ing into that directory and typing "knights_server".

For Linux, the server is built and installed automatically as part of the normal build process. To run the server type "knights_server" on the command line.

### The configuration file

The server needs to read a configuration file before it can run. The default is to look for a file named "knights_config.txt" in the current directory. If you want to use a different config file you can specify it using the -c option, for example:

`knights_server -c path/to/my_config.txt`

The file itself is a plain text file consisting of "Setting = Value" pairs, for example, "MaxPlayers = 50". There is one setting per line. Comment lines may also be included by starting them with a # symbol. An example knights_config.txt file is included in the distribution and you are encouraged to use this as a basis for creating your own config file.

Please note that changes to the config file will not take effect until the server is restarted.

The full list of settings is as follows:

- Description: A short description of the server. This will appear in the game on the "Connect to Server" screen.
- KnightsDataDir: Specifies the location of the "knights_data" directory. If you have followed the standard install procedure then the game will find the directory automatically and this can be left unset; if you have installed the knights_data directory in a non-standard location then you can use this setting to tell the server where to find it.
- LogFile: Gives the name of a log file. The server will append log messages to the end of the file. Events logged include player connections/disconnections, games played, and all chat messages. If this parameter is unset then log messages will be printed on stdout.
- MaxGames: Sets a maximum number of games that can exist at any given time. If this number of games is reached then the server will not create any new games until the number drops down below the maximum again.
- MaxPlayers: Maximum number of players that can connect to the server at any one time. Default is 100.
- MOTDFile: Set to the name of a text file containing a Message Of The Day which will be displayed when players first connect to the server. The server re-reads the file each time a player connects, so you can edit the contents of the file without having to restart the server.
- OldMOTDFile: As MOTDFile, except that the OldMOTDFile will only be displayed if the client is running an older version of Knights. Can be used to display a message that a new version of Knights is available. Default: same as MOTDFile. (Note that it is not guaranteed that old client versions will be compatible with new server versions; in general, it is recommended to keep the client and server versions the same, if at all possible.)
- Password: If set, the server will be password protected and players must type in the password before they can connect. Please note that the passwords are not encrypted during transmission, so be careful not to use anything confidential as the password.
- Port: Which UDP port to use. The server listens for incoming connections on this port. Default 16399.
- UseBroadcast: This should be set to "yes" for a private, LAN-only server. Players on the local network will be able to see the server listed on their "Connect to Server" screen, but players on the wider Internet will not. (This is implemented by having the client send out broadcasts on UDP port 16398, which the server will then respond to.)
- UseMetaserver: This should be set to "yes" for a public server. Players across the internet will be able to see the server listed on their "Connect to Server" screen. (This is implemented by connecting to a "metaserver" running on the knightsgame.org.uk web site.)

Note that players connecting to the server must be running the same version of Knights that the server is using. If the versions do not match then the connection will be refused.

#### Experimental features

The following options allow games played on the server to be recorded, and then replayed at a later date. Note that the playback feature is highly experimental, and may not work very well. At the moment it is mostly only useful for debugging (i.e. if a player reports a bug, then we can go back and analyse the recording to try to work out what happened). It may be expanded to be more generally useful in the future.

- BinaryLog: Specify a filename to log game data to. If the file exists, the new data will be appended, otherwise a new file will be created.
- Replay: Specify the name of a file that was created with the BinaryLog option. The server will replay all the games that were recorded in the file. To watch the games, you can start up a copy of Knights and join the server as an observer.

### Suggestions

Here are some suggested ways of using the server.

- Public Internet server. Start your own public Knights server. The default settings should be fine, although you may want to set a "Description" and/or "MOTDFile".
- LAN server. For a LAN party (for example) you might want to run a separate server instead of using the "Host LAN Game" option. (The advantage of this is that you avoid the issue where all players get disconnected whenever the "host" player quits.) To run a LAN server, set "UseBroadcast" to "yes" and "UseMetaserver" to "no". The server will not appear in the public server list but it will appear to players on the current LAN.
- Private Internet server. If you want to run a private Internet server there are two methods:
  - Set "UseMetaserver" to "no". Your server will then not appear in the public server list; the only way for players to connect will be by typing the server's IP address directly into the Connect to Server screen.
  - Leave "UseMetaserver" set to "yes", but set a password. Your server will appear in the global server list, but only players who know the password will be able to log in.

### Keeping the server running

The distribution contains a Unix shell script, start_knights_server.sh, which checks whether the server is running, and if not, starts a new copy of the server. This allows the server to be automatically re-started in the event that it crashes. For instructions read the comments within the file.

Previous | Contents | Next
Game Options |  | Building/Installing from Source