static void OnReceivedServerResponse(DiscoveryInfo info)
        {
            // check if data is valid
            if (!IsDataFromServerValid(info))
            {
                return;
            }

            // invoke event
            onReceivedServerResponse(info);
        }
示例#2
0
        void OnReceivedServerResponse(DiscoveryInfo info)
        {
            // Validation is our capacity to decode the message, if the payload is so different we cant parse it we silently dump it!
            NetworkDiscoveryUtility.RunSafe(() => {
                info.unpackedData = (GameBroadcastPacket)ByteStreamer.StreamFromBytes(info.packetData);
            }, false);

            if (info.unpackedData != null)
            {
                onReceivedServerResponse(info);
            }
        }
        static void OnReceivedBroadcast(DiscoveryInfo info)
        {
            if (info.KeyValuePairs.ContainsKey(kSignatureKey) && info.KeyValuePairs[kSignatureKey] == GetSignature())
            {
                // signature matches
                // send response

                Profiler.BeginSample("Send response");
                byte[] bytes = ConvertDictionaryToByteArray(m_responseData);
                m_serverUdpCl.Send(bytes, bytes.Length, info.EndPoint);
                Profiler.EndSample();
            }
        }
示例#4
0
        void ServerOnClientBroadcast(DiscoveryInfo info)
        {
            // This is the handshake, objective is not security just sheer improbability
            if (handshakeData.Length == info.packetData.Length &&
                handshakeData.SequenceEqual(info.packetData))
            {
                // signature matches
                // send response
                Profiler.BeginSample("Send response");
                serverUdpClient.Send(serverBroadcastPacket, serverBroadcastPacket.Length, info.EndPoint);

                Profiler.EndSample();
            }
        }
示例#5
0
        void Connect(DiscoveryInfo info)
        {
            if (NetworkManager.singleton == null ||
                Transport.activeTransport == null)
            {
                return;
            }
            if (!(Transport.activeTransport is TelepathyTransport))
            {
                Debug.LogErrorFormat("Only {0} is supported", typeof(TelepathyTransport));
                return;
            }

            // assign address and port
            NetworkManager.singleton.networkAddress = info.EndPoint.Address.ToString();
            ((TelepathyTransport)Transport.activeTransport).port = (ushort)info.unpackedData.port;

            NetworkManager.singleton.StartClient();
        }
示例#6
0
 void OnDiscoveredServer(DiscoveryInfo info)
 {
     // Note that you can check the versioning to decide if you can connect to the server or not using this method
     m_discoveredServers[info.unpackedData.serverGUID] = info;
 }
 public static bool IsDataFromServerValid(DiscoveryInfo data)
 {
     // data must contain signature which matches, and port number
     return(data.KeyValuePairs.ContainsKey(kSignatureKey) && data.KeyValuePairs[kSignatureKey] == GetSignature() &&
            data.KeyValuePairs.ContainsKey(kPortKey));
 }