Пример #1
0
        private void HandleNewConnection(CSteamID steamID)
        {
            if (LogFilter.Debug || debug)
            {
                Debug.LogError("HandleNewConnection " + steamID);
            }

            //check if we have a connection already stored for this steam account
            try
            {
                SteamClient steamClient = steamConnectionMap.fromSteamID[steamID];
                if (steamClient.state == SteamClient.ConnectionState.CONNECTED || steamClient.state == SteamClient.ConnectionState.CONNECTING)
                {
                    if (LogFilter.Debug || debug)
                    {
                        Debug.Log("HandleNewConnection ACCEPT");
                    }
                    //accept! We thought they were anyway
                    SteamNetworking.AcceptP2PSessionWithUser(steamID);
                    return;
                }

                if (LogFilter.Debug || debug)
                {
                    Debug.Log("HandleNewConnection REJECT - disconnecting");
                }
                //currently in disconnecting state. Dont accept another connection
                SteamNetworking.CloseP2PSessionWithUser(steamID);
                return;
            }
            catch (KeyNotFoundException)
            {
            }

            if (LogFilter.Debug || debug)
            {
                Debug.Log("HandleNewConnection New");
            }

            if ((mode == Mode.SERVER && getNumberOfActiveConnection() >= maxConnections) || (mode == Mode.CLIENT && steamID != steamClientServer.steamID))
            {
                Debug.LogError("HandleNewConnection Reject, full or unexpected");

                //either too many people connecting to server Or we are a client and someone else is tryign to connect! Dont accept
                SteamNetworking.CloseP2PSessionWithUser(steamID);
                return;
            }

            if (LogFilter.Debug || debug)
            {
                Debug.Log("HandleNewConnection ACCEPT NEW");
            }
            //just accept! so we can start communicating
            SteamNetworking.AcceptP2PSessionWithUser(steamID);

            //new connection id
            int connectionId = nextConnectionID++;

            steamConnectionMap.Add(steamID, connectionId, SteamClient.ConnectionState.CONNECTING);
        }
        private void HandleNewConnection(CSteamID steamID)
        {
            //check if we have a connection already stored for this steam account
            try
            {
                SteamClient steamClient = steamConnectionMap.fromSteamID[steamID];
                if (steamClient.state == SteamClient.ConnectionState.CONNECTED || steamClient.state == SteamClient.ConnectionState.CONNECTING)
                {
                    //accept! We thought they were anyway
                    SteamNetworking.AcceptP2PSessionWithUser(steamID);
                    return;
                }
            }
            catch (KeyNotFoundException)
            {
            }

            if ((mode == Mode.SERVER && getNumberOfActiveConnection() >= maxConnections) || (mode == Mode.CLIENT && steamID != steamClientServer.steamID))
            {
                //TODO error report?
                //either too many people connecting to server Or we are a client! Dont accept

                return;
            }

            //just accept!
            SteamNetworking.AcceptP2PSessionWithUser(steamID);

            //new connection id
            int connectionId = nextConnectionID++;

            steamConnectionMap.Add(steamID, connectionId, SteamClient.ConnectionState.CONNECTING);

            //Reply with an empty packet to also confirm connection to client.. this will mean the client receives a "connected" message as this isnt TCP!
            SteamNetworking.SendP2PPacket(steamID, null, 0, EP2PSend.k_EP2PSendReliable, (int)SteamChannels.SEND_TO_CLIENT);

            //we have to queue this connection up so we can let the ReceiveFromHost method return the new connection
            steamNewConnections.Enqueue(connectionId);
        }