private void OnSessionRequest(P2PSessionRequest_t request) { CSteamID clientId = request.m_steamIDRemote; if (steamIdToConnection.ContainsKey(clientId)) { SteamNetworking.AcceptP2PSessionWithUser(clientId); } else { if (steamIdToConnection.Count < maxConnections - 1) { if (ShouldAcceptSteamId(clientId)) { if (SteamNetworking.AcceptP2PSessionWithUser(clientId)) { if (SteamNetworking.SendP2PPacket(clientId, null, 0, EP2PSend.k_EP2PSendReliable)) { var conn = new SteamNetConnection(clientId); ForceInitConnection(conn); steamIdToConnection.Add(clientId, conn); NetworkServer.AddExternalConnection(conn); } } } else { Debug.Log("Steam session request ignored"); } } } }
public bool StartSteamClient(CSteamID steamLobbyId) { if (steamNetworkingLoopCoroutine != null) { return(false); } remoteSteamId = SteamMatchmaking.GetLobbyOwner(steamLobbyId); if (remoteSteamId == CSteamID.Nil) { Debug.LogError("Cannot determine the lobby owner, did you join this lobby?"); return(false); } this.steamLobbyId = steamLobbyId; connectionIdCounter = -1; isClientConnected = false; var conn = new SteamNetConnection(remoteSteamId); var extClient = new NetworkClient(conn); extClient.Configure(GetSteamHostTopology()); ForceInitConnection(conn); UseExternalClient(extClient); sessionErrorCallback = Callback <P2PSessionConnectFail_t> .Create(OnSessionConnectFail); steamLobbyChatUpdate = Callback <LobbyChatUpdate_t> .Create(OnLobbyChatUpdate); SteamNetworking.SendP2PPacket(remoteSteamId, null, 0, EP2PSend.k_EP2PSendReliable); steamNetworkingLoopCoroutine = StartCoroutine(CoSteamNetworkingLoop()); return(true); }