CosmoServer

From Cosmoteer Wiki
Jump to: navigation, search

CosmoServer is the "Cosmoteer Lobby Server". It is a small command-line application that runs a simple server. Cosmoteer players can connect to a CosmoServer to chat and play multiplayer games with anyone else on that server. CosmoServer does not actually run any gameplay logic, and so it is compatible with all Cosmoteer mods. (But individual players must still be using the same mods in order to play with each other.)

Connecting to a CosmoServer

To connect to a CosmoServer, first click Multiplayer on the title screen and then click on the Online tab (if it is not already selected). Near the top-right of the screen there is a dropdown list of available servers that should already be populated with a list of official servers. If you want to connect to a non-official server, click the menu button just right of the dropdown and select "Add Custom Server". Type in a name for the non-official server (it can be anything you want) and enter its public I.P. address. If the server is running on a non-default port (anything other than 35872) or requires a password to join, enter those as well.

If you want to connect to a server running on your own network, you'll want to enter the private I.P. address of the computer running the server, because many routers have issues when a computer on its own network uses its public I.P. address (even if port-forwarding is correctly configured). If the server is running on the same computer you're playing Cosmoteer on, you can simply enter localhost as the I.P. address.

Running your own CosmoServer

Unlike Cosmoteer itself, which currently only supports the Windows operating system, CosmoServer actually works just fine on Mac OS and Linux as well.

If you want to run CosmoServer on a Windows, Mac OS, or Linux computer, then the first thing you'll need to do is install the .NET 5 Runtime for your operating system. (You do not need the full SDK, ASP.NET, or Desktop runtimes; only installing the basic runtime is sufficient.)

Next, download the latest CosmoServer and extract the .zip file to wherever you want on your computer. If you're on Windows, you can simply double-click the Cosmoteer.exe file. If you're on any other OS, open a command terminal, navigate to the directory where you extracted CosmoServer, and then run the command dotnet CosmoServer.dll (note the .dll extension instead of the .exe extension).

Port Forwarding

If you're running CosmoServer behind a router, you'll need to setup "port forwarding" (sometimes called "virtual server") so that players on the outside of your network can connect to your server. If your server is running on the default port of 35872, you'll want to forward UDP port 35872 to the computer actually running the server. (Make sure you forward UDP port 35872, not TCP port 35872.) Here is a website that describes how to setup port forwarding for many common routers.

Command-line Arguments

Running CosmoServer with no command-line arguments will by default start up a server that is running on UDP port 35872, has a maximum of 1000 simultaneously-connected players, and requires no password to join. But CosmoServer does support a handful of command-line arguments to configure its behavior:

--help This argument causes the program to print the full list of command-line arguments to the console and then exit.

--port 35872 This argument allows you to customize the UDP port on which the server communicates. If you omit it, it uses the default port of 35872.

--log-verbose If this argument is specified, the server will print various status updates such as connections and disconnections to the console.

--log-chat If this argument is specified, the server will log all chat messages to the console.

--maxplayers 1000 This argument allows you to change the maximum number of players that can be simultaneously connected to the server. If more players try to connect than the server allows, they will fail to connect. If you omit this argument, then it will default to a maximum of 1000 players.

--password "mypassword" This argument allows you to require a password in order to join the server, if you don't want just anyone to be able to join. Players will have to enter the password you specify when they add your custom server in Cosmoteer.

(There are also some additional arguments that are useful when running the server in the background. These are described below.)

Server Commands

Once a server is running, there are some additional commands that you can type to check its status or modify its behavior:

shutdown Disconnects all players and shuts down the server. This will immediately interrupt all in-progress games that anyone is playing.

stats Prints out various statistics such as the number of currently-connected players and bandwidth usage.

list Prints out the I.P. address and port of every player currently connected to the server.

drain Blocks all new attempts to connect to the server but does not disconnect any already-connected players. This can be useful if you want to shut down a server soon but don't want to interrupt anyone already playing on it.

Banning Players

It is possible to ban individual players from connecting to your server. To do this, create a text file somewhere on your hard drive, and enter the I.P. addresses of the players you want to ban, each I.P. on its own line. Then you need to tell CosmoServer to use that file by specifying a command-line argument:

--banlist "path/to/ban/file.txt"

Any players attempting to connect to the server using an I.P. address in that file won't be able to and will receive a message telling them that they have been banned.

CosmoServer will automatically reload the banlist file every 10 minutes, but you can force it to reload immediately by typing the reload-banlist command.

Running CosmoServer as a background process

If you run CosmoServer by double-clicking CosmoServer.exe or opening up a command-line and running it from there, it will run as a "foreground" process, meaning that you can type commands into it and the server will quit if you ever close the command-line window. This works fine for testing and for short-lived servers, but for long-lived servers, you'll probably want to run it in the "background", meaning that you can't see or interact with it but it's still running. How exactly you do this depends on your operating system (for operating systems using systemd such as Ubuntu 16.04, see the guide below), but regardless of your operating system, there are some additional command-line arguments of CosmoServer that you'll likely want to take advantage of:

First, since you're running CosmoServer in the background, it won't be able to read any user input from the console, which can actually cause CosmoServer to use abnormally high CPU as it continuously tries and fails to read user input. To prevent CosmoServer from doing this, you should specify the --nostdin command-line argument.

Second, even though it can't read input from the console, you'll probably still want to be able to interact with it by typing in commands. The way we can do this is by running a foreground instance of CosmoServer and having it "attach" to the already-running background instance of CosmoServer. In order to do this you'll need to use another couple of command-line arguments:

--attachable This argument should be specified when running CosmoServer in the background. It allows another CosmoServer to "attach" to it and send it commands.

--attach This argument should be specified when running a foreground CosmoServer that you want to attach to a background CosmoServer. Instead of running an actual server that players can join, it will instead "attach" to an already-running server on the same computer and allow you to type commands into it. (To detach from the background server, simply type the detach command.)

When CosmoServer attaches to another CosmoServer, it does so using a local TCP connection, which by default uses TCP port 35872. If for some reason that port is not available, you can change what port it uses by specifying the --attachport 35872 command-line argument on both the foreground and background servers.

Running CosmoServer as a background process using systemd (Ubuntu 16.04)

Follow these instructions if you want to run CosmoServer on Ubuntu 16.04 (perhaps because you can get a cheap Ubuntu 16.04 cloud server on DigitalOcean for only $5/month). This has been tested on Ubuntu 16.04 but is likely to work with minor modifications on any operating system running systemd.

First, you'll want to create the file that tells systemd how to run CosmoServer as a service. Type the following into your command-line:

sudo nano /lib/systemd/system/cosmoserver.service

And then paste the following code into that file:

[Unit]
Description=CosmoServer

[Service]
Type=simple
ExecStart=/usr/bin/dotnet /path/to/CosmoServer.exe --attachable --nostdin
Restart=always
RestartSec=5
User=walt

[Install]
WantedBy=multi-user.target

(You'll want to replace /path/to/CosmoServer.exe with the actual path where you copied the CosmoServer.exe file.)

(Ensure you change the line User=walt to the user you want to run the server as.)

This basically tells systemd to run CosmoServer in the background, don't read input from the console (to prevent high CPU usage), and to allow a foreground CosmoServer to attach to it. It also tells systemd to restart the server automatically if it ever crashes.

Once you've created and saved this file, you should tell systemd to actually start the server by typing:

sudo systemctl start cosmoserver

CosmoServer should now be running in the background, which you can test by running Cosmoteer, adding your server as a custom server, and connecting to it. If you can't connect to it, then you probably need to allow connections to the server through your firewall:

sudo ufw allow 35872/udp

One last thing, which is that CosmoServer still won't run automatically whenever your system boots. To make it run automatically upon boot, simply type:

sudo systemctl enable cosmoserver

Servers

  • test server : 142.93.71.196 port 35873