All of this is in regards to the LLAPI.
From what I understand, when you open up a connection such as like this
void Setup()
{
ConnectionConfig config = new ConnectionConfig();
channelID = config.AddChannel(QosType.Unreliable);
HostTopology topology = new HostTopology(config, maxConnections);
socketId = NetworkTransport.AddHost(topology, socketPort);
}
Whenever someone calls Connect, like this
targetConnectionID = NetworkTransport.Connect(socketId, address, port, 0, out error);
The opened connection will just blindly accept anyone that asks.
Is there a way to decide if you actually want to connect?
For example, steamworks peer to peer has something called P2PSessionRequest_t, which I think is sent by steams servers to you when someone requests to connect to you. You can then grab the steamID from the request and check if the player is actually in the same lobby as you, and if so you can safely accept the connection by using AcceptP2PSessionWithUser.
I was thinking I could do all of that, then when I accept the connection and get their ip address by using steams
GetP2PSessionState( CSteamID steamIDRemote, P2PSessionState_t *pConnectionState )
which the P2PSessionState_t struct has the IP Address and Port in the m_nRemoteIP variable.
Then ill send a Connect request through unitys networking so that I dont have to use steamworks networking.
Then hopefully I can end the connection on the steamworks side without it messing up anything such as if steam decided to use a relay server for the connection, hopefully it keeps the relay.
Still not sure how to block connections before they actually connect.
I tried something like this…
NetworkEventType receiveNetworkEvent = NetworkTransport.Receive(out recSocketId, out recConnectionId, out recChannelId, recBuffer, bufferSize, out dataSize, out error);
switch(receiveNetworkEvent)
{
//......
case NetworkEventType.ConnectEvent:
NetworkTransport.RemoveHost(recSocketId);
break;
//....
}
This was tested only over localhost (editor and build on the same computer).
RemoveHost Doesnt seem to work to refuse the connection, the other end still receives a ConnectEvent
It seems when you RemoveHost, you dont get a DisconnectEvent on your side for the connection.
It also seems RemoveHost doesnt send a Disconnect event to the connections on the socket, so instead they are disconnected by the DisconnectTimeout.
I think you’re basically talking about code that would be implemented on top of the transport. It would be up to you to sort through incoming connections and refuse ones you don’t want based on whatever you can see from their connection (not much) or based on data they send you, such as an authentication token, lobby membership, whatever.
It could be something simple, like a event OnConnectionRequest(ConnectionRequestInfo connectionRequestInfo) we can subscribe to in the NetworkTransport.
We can have connections accepted by default, but if you subscribe to the OnConnectionRequest youll have the ability to call NetworkTransport.RefuseConnection(connectionRequestInfo.connectionID) so that the connection is never made and no packets are sent back to the other end so that they have no idea if there is anything to really connect to.