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

Breaking: Headless servers reject clients #859

Closed
dylanh724 opened this issue Aug 15, 2023 · 3 comments
Closed

Breaking: Headless servers reject clients #859

dylanh724 opened this issue Aug 15, 2023 · 3 comments
Assignees
Labels
stat:awaiting response Status - Awaiting response from author. type:support Questions or other support

Comments

@dylanh724
Copy link

Describe the bug
When running a local headless Linux || Windows server (UDP), clients are auto-rejected.

To Reproduce
Steps to reproduce the behavior:

Server

Leaving default scene build order:

  1. Set NetworkManager !ConnectionApproval
  2. Set NetworkManager LogLevel to developer
  3. Set NetworkManager Address:Port to 127.0.0.1:7777
  4. Add #if UNITY_SERVER (or a cli -arg handler) to trigger NetworkManager.Singleton.StartServer();
  5. Build a headless Windows || Linux server
  6. Launch via CLI with -batchmode -nographics
  7. Confirm local server is running via logs, eg: 127.0.0.1:7777.

Client

(A)

  1. Play in Editor
  2. [UI] Join with direct IP: 127.0.0.1:7777 (should match server^)
  3. [Logs] StartClient -> Intialize -> Failed to connect to server

(B)

  1. Play in Editor
  2. [NetworkManager] Start Client
  3. [Logs] StartClient -> Intialize -> Failed to connect to server

Expected behavior
Client should connect to headless server running NetworkManager.Singleton.StartServer() on init

Screenshots
image

image

image

image

Environment (please complete the following information):

  • OS: Win11
  • Unity Version: 2022.3.5 LTS
  • BossRoom Version: Latest from 08/15/2023 clone

Additional context

Connection does work if solely using UI, leading me to believe the issue has something to do with NetworkManager handling with Startup. I'll continue to look into this. Perhaps if server start with MainMenu instead of Startup, it may work.

@dylanh724 dylanh724 added stat:awaiting triage Status - Awaiting triage from MLAPI team. type:bug Bug Report labels Aug 15, 2023
@dylanh724
Copy link
Author

dylanh724 commented Aug 15, 2023

Issue Identified

If I build the headless server and leave off the Startup scene, the Clients can connect to the headless Server from the Menu. However, only from logs; and only if !ConnectionApproval

image

The logs show a client<>server handshake and persists without disconnection. The server logs show confirmation of this:

[Netcode] StartServer
[Netcode] A ConnectionApproval callback is defined but ConnectionApproval is disabled. In order to use ConnectionApproval it has to be explicitly enabled
[Netcode] Initialize
[Netcode] Client Connected
No client player ID found mapped to the given client ID: 1
[Netcode] [Server-Side Client-Synchronization] NetworkObject serialization order:UIMessageManagerSceneLoaderPersistentPlayer1

Continued Issues

So we have a client<>server handshake, but UI does not respond as expected. To fix:

  1. Startup scene needs to handle headless server auto-startup. Currently, starting a server and moving to the Menu scene seems to destroy the server (without logs or indicators). Building a headless server without Startup scene is the only way I could get this to connect.
  2. When the Client connects to a headless server, the UI does not respond as expected: Nothing happens.

I have a feeling that the UI desync has to do with the log [Netcode] A ConnectionApproval callback is defined but ConnectionApproval is disabled. In order to use ConnectionApproval it has to be explicitly enabled.

Approval was enabled by default and the only way a headless server seems to be able to get this working is to disable this.

Missing Documentation

As a true use of a client/server will often be likely to have a headless (dedicated) server rather than connecting as a "Host" via the UI,

  • There needs to be steps/testing/documentation for how to run the server via a headless server that inits immediately (including handling of the Startup scene for when this occurs).
  • There should likely be an -arg handler to init the server asap (rather than forcing us to have our own).
  • If we don't want to "approve" a connection, how to handle this?
    • Or if we want to approve a connection, but we're a headless server, how to handle this?

Any possibility we can get some of this rolling? FishNet, Mirror and Photon all have the ability to auto-start a headless server (with documentation and -arg handlers), if that means anything.

@dylanh724 dylanh724 changed the title Headless servers reject clients Breaking: Headless servers reject clients Aug 15, 2023
@LPLafontaineB LPLafontaineB self-assigned this Aug 16, 2023
@LPLafontaineB
Copy link
Contributor

LPLafontaineB commented Aug 17, 2023

Hi Dylan! Boss Room is a sample showcasing the client-hosted model. It is not meant to provide education on the dedicated-server approach. In this case it is hard to say without looking directly at your code, but it seems the issue is with Connection Approval. Boss Room has a specific flow for connecting, which includes some setup on the host, and on the clients, with each client sending some specific data for approval, and the server giving them a reply with some more data. Bypassing the intended flow (done via UI) without making sure that the flow stays the same will prevent connection.

However, while Netcode for GameObjects does support dedicated servers (headless or not), porting a game sample intended for the client-hosting model to the dedicated server model will require significant changes. You can have a look at this documentation for more information about this process and for general information about the Dedicated Server model. Also, if you are using Unity 2023.1 or higher, there is the experimental Dedicated Server Package that provides many useful tools for this type of games. (This package is still experimental and in active development and is meant to be used with the purpose of workflow testing and providing feedback.)

We are also working on more educational content for the dedicated server flow with Netcode for GameObjects, but it is still in early development.

@LPLafontaineB LPLafontaineB added stat:awaiting response Status - Awaiting response from author. type:support Questions or other support and removed stat:awaiting triage Status - Awaiting triage from MLAPI team. type:bug Bug Report labels Aug 25, 2023
@LPLafontaineB
Copy link
Contributor

Closing this issue as it has been a few weeks. If you require additional support feel free to reach out to us, or to the NGO team in their repo or via our discord server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response Status - Awaiting response from author. type:support Questions or other support
Projects
None yet
Development

No branches or pull requests

2 participants