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.
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.
- 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.)
- Port: Which UDP port to use. The server listens for
incoming connections on this port. Default 16399.
- UseBroadcast: Setting this to "yes"
allows the server to respond to LAN broadcast packets from
game clients. In theory, this means that players on the local
network will be able to see the server listed on their
"Connect to Server" screen. (This is implemented by
having the client send out broadcasts on UDP port 16398, which
the server will then respond to. Note that many firewalls
nowadays block these packets, so depending on firewall
settings, the broadcast feature may not work.)
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.
Allowing players to find your server
If the server is running on a LAN then (if you are lucky)
the game client should be able to detect the server
automatically using the broadcast feature. However, broadcast
packets are often blocked by firewalls, so this may not work; in
that case, players will have to type in the IP address or
hostname of the server manually.
For Internet servers, there is currently no way for the game
client to automatically find the server, so you will have to
publish the hostname or IP address of your server somewhere, and
players will have to manually type the address into the game
client.