Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NAT hole punching and make API server configurable #298

Merged
merged 10 commits into from
Jan 27, 2023

Conversation

kaenganxt
Copy link
Member

@kaenganxt kaenganxt commented Oct 24, 2022

When joining a server, the implementation will now

  1. Request the hole punching server to initiate the NAT hole punching
  2. The hole punching server returns a registered ip address and instructs the CSM server to punch a hole
  3. LiteNetLib performs the hole punching and tries to verify a working connection
  4. Our implementation tries to use the returned IP address to connect to the CSM server
  5. If unsuccessful or server is not known on the hole punching server, the given IP address is used to connect directly (e.g. for a local network or Hamachi)

The hole punching server was improved slightly, and is now included in this repository.

The server is currently running on api.citiesskylinesmultiplayer.com port 4240 (only IPv4 for now).

An additional feature introduced with this patch is the ability to change the API server through a mod setting (if someone wants to host their own setup).

- Add "more info" button on client when it fails to connect
- Add "more info" button in "Manage Server" menu when the port is not reachable
- Troubleshooting panel shows info about port forwarding, Windows Firewall and using Hamachi or ZeroTier
- Detect Hamachi through the availability of the 25.0.0.0/8 subnet
- When Hamachi is detected, display IP address in Host Game and Manage Game panels
- Improve connection check messages, display different messages when Hamachi is detected
@DominicMaas
Copy link
Member

Code wise (visually), it looks good, will test it out over the weekend.

- Include GlobalServer in CSM repo
- Use ProtoBuf-based protocol for GlobalServer communication
- Implement port checking into GlobalServer
- Refactor and cleanup
@kaenganxt
Copy link
Member Author

I finally had the time to include the port checking mechanism. For this, I refactored most of the CSM <-> GlobalServer communication and included the GS project into this repository. It is not included in the solution as this didn't work for me with Mono (Because the GS is .NET core).

Port checking works by simulating a CSM client on the GS and performing the same procedure as with the regular connection procedure.
I also created a Docker Registry for the GS image at https://github.com/orgs/CitiesSkylinesMultiplayer/packages/container/package/apiserver

Maybe I'll add the building of this Docker Image to the Github Action later today.
Please take a look again @DominicMaas :)

@DominicMaas
Copy link
Member

ooooh nice! I've got some free time at the moment so I'll check this out

@DominicMaas
Copy link
Member

hmmm, I'm unable to load the CSM project in Visual Studio:

image

@kaenganxt
Copy link
Member Author

hmmm, I'm unable to load the CSM project in Visual Studio:

The Data folder should be a symlink to the GS project's Data folder (so the packets are the same). Could this be a problem with Visual Studio? Does it look correct in the file system? I personally use Jetbrains Rider as an IDE where it works fine.

@DominicMaas
Copy link
Member

image

Do symlink's work through git? Ooh, are you developing on Linux?

@DominicMaas
Copy link
Member

I could probably get away with replacing paths to the data folder with relative paths in the csproj file, looks like there are issues with using linux symlinks on Windows (there are local ways to get around this, but would complicate PRs in the future for people wanting to contribute)

@kaenganxt
Copy link
Member Author

Do symlink's work through git? Ooh, are you developing on Linux?

Yes, I'm on Linux. In theory, symlinks should work on Windows. I just found this post: https://stackoverflow.com/a/59761201

If relative paths work properly, we can also use those. I just wanted to avoid duplicate code especially for the protocols.

@DominicMaas
Copy link
Member

I see, I'll give relative paths a try for now. I'd eventually like to try modernizing our c# csprojs and still build for .net 3.5 (which should be possible, but will need to see if mono freaks out, and if everything still works. Future PR though)

@DominicMaas
Copy link
Member

Hopefully this has not broken the CI or Linux builds

@kaenganxt
Copy link
Member Author

Looks good for me on Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants