Exemplo n.º 1
0
        static void OnReceivedServerResponse(DiscoveryInfo info)
        {
            // check if data is valid
            if (!IsDataFromServerValid(info))
            {
                return;
            }

            // invoke event
            onReceivedServerResponse(info);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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;
 }
Exemplo n.º 7
0
 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));
 }