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 available 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.
- 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.)
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.