c# – How is a Challenge implemented for a game networking protocol?

Working on an authoritative online game using LiteNetLib. I’ve been reading about building a game network protocol and I’m feeling stuck with the “challenge” implementation.

  • The client requests a connection with the server.
  • The server then returns some sort of challenge (that only the client should be able to solve?).
  • The client returns the solution and the server allows the connection.

The first thing that I don’t get is how to have a “pending” connection without accepting it to begin with. With LiteNetLib, this is how the server handles incoming connections:

listener.ConnectionRequestEvent += request =>
    if(server.ConnectedPeersCount < 10 /* max connections */)

From the looks of it, the server must decide whether to allow the client or not at this very instant. If I want to send or receive a challenge, I need to accept the connection first don’t I? But that would defeat the point of the challenge implementation.

Is there a resource with an example of how this is done? The article doesn’t really go into detail, and when I google things like “online game protocol challenge request packet” the results aren’t quite related (almost as if the concept was coined by that article).