Skip to content
Dominic Maas edited this page Jun 27, 2021 · 5 revisions

NAT Punchthrough & CSM Global Servers

Inspired by the following:

It's best to take a read of the above resources before continuing, as the idea is similar for CSM.

CSM Global Server (CSM GS)

A CSM Global Server runs on a static IP address not behind any routers (and by default, uses port 4240), it's similar to the LMP Master Server.

The primary CSM Global Server runs at gs.citiesskylinesmultiplayer.com:4240. (If you are using the testing client, the relay ip is 165.22.34.172)

In the future it would be good to have multiple CSM GS's that the user can choose from (maybe per region). But this is up to people donating spare VPS resources.

Server: When a local CSM server is created, the server will contact the CSM GS to register the new server, and ping it every 5 seconds. The CSM GS keeps the server in memory while it's running, and generates a unique token that can be used for connection (e.g. Steam Overlay). When a client requests access to the server, the NAT punchthrough magic will work.

Client: Using the servers IP address (or token), the client will connect to the CSM GS, check that the server exists (based on ip or token) and then perform a NAT punchthrough to then connect the client directly to the server (using a randomly determined port by the router).

Bonus Features

This system may give us some bonus features for free

  • Joining via token: This token can be exposed on the servers steam overlay, so you can simply right click their name in steam and join game (without leaking the IP address to everyone - but now that I think of this, I don't know if it would even help).
  • Server List: Since the CSM GS has to keep track of all connected servers, we now have an active server list. Might be possible to have an option let the user display their game on this list. By default, servers will always be hidden.