Donation

Help us to pay our server!
(: Consider a donation :)



Social Media

  • Facebook
  • Google+

Currently Online

Latest Posts

Changes in DedicatedServer

Revision Differences of Revision 12

# Dedicated Server ¶

## Contents ¶
[TOC] ¶


## What this page is all about ¶

One major problem of playing Widelands online is the need of a server, that is connectable from the internet. As stated and described in the wiki article InternetGaming the set up of a system to meet this criteria depends a lot of the used operating system as well as the way the Widelands server 'to be' is connected to the internet. In short: This set up is in no way trivial. ¶

A common way to ease the online playing of other games is the use of dedicated servers - servers, that do not provide a graphical frontend and do not actively interfere in the game, they just act as host for games. ¶

Widelands provides such a dedicated server module since release of Build 16 - and that's what this side is all about. ¶

If you want to know more about how this dedicated server works or perhaps even want to host a dedicated server, please read on. ¶



## How to get or compile a dedicated server? ¶

The dedicated server is integrated in the main Widelands executable. So to say the dedicated server is not a real dedicated server, but a "dedicated server modus" of the Widelands executable. ¶

The positive aspect of this fact (besides the easier development ;)) is, that the dedicated server should be available in every version of Widelands you can get - it is integrated by default. The negative aspect of this fact is, that for installation and/or compilation of the dedicated Widelands server, all libraries that Widelands needs are needed as well (well in fact you install/compile a complete Widelands version, so no wonder) - some of those libraries are normally used for graphical backends (like SDL, !OpenGL, etc.), but no fear: the dedicated server runs in text mode only. ¶
However the libraries are needed for compilation and/or install and some are even used during runtime (e.g. SDL_net functions are used for network, etc.) ¶



## Dedicated server in Build16 ¶

### Starting the server ¶

To start the dedicated Widelands server - basic set up: ¶

* Run Widelands in a terminal like this: _widelands --dedicated=<path to default map>_ ¶
* The server will now start up, connect to the metaserver and open a game with the default map. ¶
* The clients can now connect to, set up the server via chat commands and can start the game. ¶
* Once started the game runs until the last player left. Afterwards, the dedicated server closes the game, reconnects to the metaserver and reopens a new game with the default map. ¶

### Start up commandline arguments ¶

There are some commandline arguments (either specific for the dedicated server or at least useful for the dedicated server as well) that can be used for more specific dedicated server setup. All these options (except --dedicated=<path to default map>) can as well be set in the ~/.widelands/config file as well. ¶

* _--dedicated=<path to default map>_ : Mandatory to run the dedicated server. The map given in argument will be loaded at startup and at each restart (after end of a game). ¶
* _--nickname=<hostname>_ : The name that will be used for login into the metaserver. ¶
* _--servername=<servername>_ : The name that will show up in the server list ¶
* _--autosave=<number>_ : number of seconds between each autosave ¶



### Commands at runtime ¶

There are several commands you can give a dedicated server by sending a private message (e.g. "@dedicated start") ¶

#### General ¶

These commands can be executed during set up time and in a running game. ¶

* _help_ : Shows all available commands (same as this paragraph). ¶
* _host_ : Runs a host command like "/announce <msg>", "/warn <user> <msg>" or "/kick <user> <reason>" ¶

#### During game setup ¶

These commands can be used to set up the server before starting the game ¶

* _start_ : Starts the game ¶
* _ls_maps_ : Shows a list of available/selectable maps on the host. ¶
* _ls_saved_games_ : Shows a list of available/selectable saved games on the host. ¶
* _switch_map $_ : Switch to map $ (full name with .wmf) ¶
* _switch_save $_ : Switch to saved game $ (full name with .wgf) ¶
* _toggle_type #_ : Toggle type of player # ¶
* _toggle_tribe #_ : Toggle tribe of player # ¶
* _toggle_init #_ : Toggle initialization of player # ¶
* _toggle_win_con_ : Toggles the win condition ¶





## The dedicated server in Build17 (+ current development snapshots) ¶

### Starting the server ¶

To start the dedicated Widelands server - basic set up: ¶

* Run Widelands in a terminal like this: _widelands --dedicated=<path to default map>_ ¶
* The server will now start up, connect to the metaserver and open a game with the default map. ¶
* The clients can now connect to and set up the server via their user interface - just as if they were the host themselves. ¶
* Once started the game runs until the last player left. Afterwards, the dedicated server closes the game, reconnects to the metaserver and reopens a new game with the default map. ¶



### Start up commandline arguments ¶

There are some commandline arguments (either specific for the dedicated server or at least useful for the dedicated server as well) that can be used for more specific dedicated server setup. All these options (except --dedicated=<path to default map> and --daemon) can as well be set in the ~/.widelands/config file as well. ¶

* _--dedicated=<path to default map>_ : Mandatory to run the dedicated server. The map given in argument will be loaded at startup and at each restart (after end of a game). ¶
* _--daemon_ : Starts the dedicated server as daemon -> use this feature especially, if you plan to use Widelands as *init.d script*. See chapter *daemon* for a more specific explanation ¶
* _--nickname=<hostname>_ : The name that will be used for login into the metaserver. ¶
* _--servername=<servername>_ : The name that will show up in the server list. ¶
* _--maxclients=<number of maximal clients in game>_ : The maximum number of clients that may be connected to the game. ¶
* _--autosave=<number>_ : number of seconds between each autosave. ¶
* _--dedicated_saving=<true/false>_ : if true(default), players can send the server a message to save the game under a specific name, to continue the game later on. ¶
* _--dedicated_password=<password>_ : The password, if the server is supposed to be password protected ¶
* _--dedicated_motd=<Message of the day>_: If you want to replace the default "this is a dedicated server write "@server help" to get help" message, write your message to this command. ¶
* _--dedicated_chat_file_path=<path were Widelands should save the chat log>_ : See chapter *Html output* below for a longer explanation. ¶
* _--dedicated_info_file_path=<path were Widelands should save the info log>_ : See chapter *Html output* below for a longer explanation. ¶
* _--dedicated_log_file_path=<path were Widelands should save the normal log>_ : See chapter *Html output* below for a longer explanation. ¶
* _--



### Commands at runtime ¶

There are several commands you can give a dedicated server by sending a private message (e.g. "@dedicated start") ¶

#### General ¶

These commands can be executed during set up time and in a running game. ¶

* _help_ : Shows all available commands (same as this paragraph). ¶
* _host_ : Runs a host command like "/announce <msg>", "/warn <user> <msg>" or "/kick <user> <reason>" ¶
* _pwd_ : can be used to send the password to the server, if the dedicated server is password protected. ¶

#### During playing ¶

* _save $:_ : Tries to save the game to save/$.wgf, if possible and if enabled on dedicated server (default) ¶



### Html output ¶

The dedicated server can be set up to write log files in HTML table formation style. This file can easily be integrated in dynamical generated webpages (like php, python or perl pages). ¶
To use this feature, you can set three commandline arguments, where each must have a value with a writeable path to a file where (depending on the variable) the general infos, the chat log or the general log is saved. If you do not set one, two or all of these variables the unset variables will just lead to a skip of the corresponding log output - so e.g. if you want the general info, but not the chat and general log, just add the commandline argument for the info file, the others will just be skipped. ¶

The output itself is: ¶

* in case of the info file a complete html table with tr, th und td ¶
* in case of the log and the chat file only the rows - so the table tags must be added for correct formation ¶

A css style file template for nicer formation of the tables can be found at [https://www.widelands.org/~peter/dedicated](https://www.widelands.org/~peter/dedicated) ¶



### daemon ¶

With use of the commandline argument --daemon, the dedicated server can fork itself and run as daemon. Forking means in this case: ¶

* Widelands is restarted as daemon and thus as different user - the original process is ended after the output of the pid of the daemon process ¶
* As the daemon is running as daemon user, all configurations set in the ~/.widelands/config file are not used. There are two possibilities to set the dedicated server options: ¶
* Via command line argument ¶
* Via /.widelands/config file (at least that's how it works on Mageia Linux - in this case the daemon user might work different on other linux OS). But keep in mind, that the --dedicated=path/to/map must be set via commandline. ¶

An example init.d script for starting Widelands as daemon on system start can be found at [https://www.widelands.org/~peter/dedicated](https://www.widelands.org/~peter/dedicated) ¶