private void ConsumeMessage(IdentifyContract message, INetworkConnection connection) { var p = connection.RemotePeer; Host.Peerstore.AddProtocols(p, message.Protocols); ConsumeObservedAddress(message.ObservedAddress, connection); var lmaddrs = message.ListenAddresses.Select(Multiaddress.Decode).ToArray(); if (HasConsistentTransport(connection.RemoteMultiaddress, lmaddrs)) { lmaddrs = lmaddrs.Append(connection.RemoteMultiaddress); } Host.Peerstore.SetAddresses(p, lmaddrs, AddressManager.ConnectedAddrTTL); if (!ProtocolVersionsAreCompatible(message.ProtocolVersion, LibP2PVersion)) { connection.Dispose(); return; } Host.Peerstore.Put(p, "ProtocolVersion", message.ProtocolVersion); Host.Peerstore.Put(p, "AgentVersion", message.AgentVersion); ConsumeReceivedPublicKey(connection, message.PublicKey); }
private void Host_Connected(INetworkConnection connection) { Debug.LogFormat("Connected to {0}", connection.Id); PlayerId playerId; if (!GetNextPlayerId(out playerId)) { connection.Dispose(); // Diconnect! throw new InvalidOperationException("No more room! Unable to find next available player id."); } else { // Associate player id ConnectionToPlayer[connection] = playerId; // Create network input handler for player InputHandlers[playerId] = gameObject.AddComponent <NetworkInputHandler>(); // Create flyer var flyerObject = Instantiate(FlyerPrefab); FlyerObjects[playerId] = flyerObject; // Get var flyer = flyerObject.GetComponent <FlyerPlayer>(); flyer.Input = InputHandlers[playerId]; // Move object into camera's 2D coordinate flyer.transform.position = (Vector2)Camera.main.transform.position; // Inform player of their respective identifier. Debug.LogFormat("Sending {0} to {1}", playerId, connection.Id); Network.SendPacket("info", connection.Id, new PlayerAcceptPacket(playerId)); } }
/// <summary> /// Disconnect this connection from a remote host. /// </summary> public void Disconnect(INetworkConnection connection) { // if (!IsOpen) { throw new InvalidOperationException("Unable to disconnect from remote host, local host not open."); } connection.Dispose(); }