Well with the P2P api there really aren’t connections per say. It functions a little more like UDP. You can send whatever data you want to whomever you want as long as you have the SteamID to send to. This is especially annoying for disconnect conditions. I ended up having to add code to periodically check to see how long it’s been since we’ve received data over a connection as well as send a disconnect message from the client for normal disconnection.
Copying and building off the Spidermonkey default client and server turned out to be the way to go because of the oddness of working with steam p2p. I ended up needing to reserve the first 4 channels in order to deal with the self connection issue. I made the “Server” side read on channels 0 and 1 and send on 2 and 3. The client reads on 2 and 3 and sends on 0 and 1. It’s also allowed me to start with direct byte buffers instead of doing another copy inside the connection / endpoints.
At this point, I think the networking code is just about done. The hard part at this point is getting the SteamID to connect to in the first place. Dedicated servers are pretty easy to work with, but self hosting games require a lot of hoops to jump through. At least in Spoxel’s case it does. I had to write code to create a lobby, then once it’s been created register your steam ID as the game to start it but only once the server is running, then once the steam ID has been registered you can go into the game. In order to join you have to find the lobby ID -> join the lobby -> wait for the game to start or check if the game has already been started -> grab the ID -> connect. Spoxel has the extra wrinkle that I have to let users select a character before they connect so there are extra steps in there.