/// <summary> /// Tries to resolve a set of IP addresses with ports. /// </summary> /// <param name="ipOrHostInclPort">The array of IPs and ports separated with : as usual.</param> /// <param name="defaultPort">The default port if the port can not be resolved.</param> /// <returns>An array in length of the provided argument array. /// Each element should be checked for validity.</returns> public static NetworkEndPoint[] ResolveEndPoint(string[] ipOrHostInclPort, int defaultPort) { var retval = new NetworkEndPoint[ipOrHostInclPort.Length]; for (int i = 0; i < ipOrHostInclPort.Length; i++) { retval[i] = ResolveEndPoint(ipOrHostInclPort[i], defaultPort); } return(retval); }
public HostData PollKnownHostData(NetworkEndPoint target) { HostData data; if (!_knownHosts.TryGetValue(target, out data)) { return(null); } return(data); }
public static NetworkEndPoint[] Resolve(string[] hosts, int port) { var endpoints = new NetworkEndPoint[hosts.Length]; for (int i = 0; i < hosts.Length; i++) { endpoints[i] = Resolve(hosts[i], port); } return(endpoints); }
/// <summary> /// Tries to resolve a set of IP addresses and ports. /// Works just like <see cref="ResolveEndPoint(string[],int)"/> /// just uses different kinds of arguments. /// </summary> /// <param name="ipOrHostInclOrDefaultPort">The pairs of string addresses and default ports for each address.</param> /// <returns></returns> public static NetworkEndPoint[] ResolveEndPoint(KeyValuePair <string, int>[] ipOrHostInclOrDefaultPort) { var retval = new NetworkEndPoint[ipOrHostInclOrDefaultPort.Length]; for (int i = 0; i < ipOrHostInclOrDefaultPort.Length; i++) { var pair = ipOrHostInclOrDefaultPort[i]; retval[i] = ResolveEndPoint(pair.Key, pair.Value); } return(retval); }
public static bool TryResolve(string ipPortString, int defaultPort, out NetworkEndPoint endpoint) { try { endpoint = Resolve(ipPortString, defaultPort); return(true); } catch { endpoint = unassigned; return(false); } }
public void RequestKnownHostData(NetworkEndPoint target) { if (!_knownHosts.ContainsKey(target)) { _knownHosts.Add(target, new HostData(target)); } var msg = new UnconnectedMessage(UnconnectedMessage.InternalCode.KnownHostRequest); msg.stream.WriteDouble(NetworkTime.localTime); msg.stream.WriteBoolean(false); _SendUnconnectedRPC(msg, target); }
internal override LocalHostData _MasterGetLocalHostData(bool errorCheck, bool notifyOnError) { if (errorCheck) { if (_gameTypeOrNameIsDirty) { _gameTypeOrNameIsDirty = false; notifyOnError = true; } if (!isServer || _status != NetworkStatus.Connected) { if (notifyOnError) { _MasterNotifyEvent(MasterServerEvent.RegistrationFailedNoServer); } return(null); } if (String.IsNullOrEmpty(_gameType)) { if (notifyOnError) { _MasterNotifyEvent(MasterServerEvent.RegistrationFailedGameType); } return(null); } if (String.IsNullOrEmpty(_gameName)) { if (notifyOnError) { _MasterNotifyEvent(MasterServerEvent.RegistrationFailedGameName); } return(null); } } if (localIpAddress == null) { localIpAddress = Utility.TryGetLocalIP(); } var localEndPoint = new NetworkEndPoint(localIpAddress, listenPort); int countServerAsPlayer = (dedicatedServer ? 0 : 1); var data = new LocalHostData(_gameType, _gameName, gameMode, gameLevel, connectionCount + countServerAsPlayer, _ServerGetPlayerLimit() + countServerAsPlayer, !String.IsNullOrEmpty(incomingPassword), dedicatedServer, useNat, useProxy, comment, OnGetPlatform(), DateTime.UtcNow, localEndPoint); return(data); }
public override int ReceivePacket(byte[] buffer, int offset, int size, out NetworkEndPoint sourceEndPoint, out double localTimeRecv) { EndPoint tempEndPoint = _anyEndPoint; #if (UNITY_IOS || UNITY_TVOS) && !UNITY_EDITOR if (NetworkUtility.IsSupportIPv6()) { tempEndPoint = _anyEndPointIPv6; } #endif int read = _socket.ReceiveFrom(buffer, offset, size, SocketFlags.None, ref tempEndPoint); sourceEndPoint = tempEndPoint; localTimeRecv = NetworkTime.localTime; return(read); }
public void CopyFrom(LocalHostData data) { gameType = data.gameType; gameName = data.gameName; gameMode = data.gameMode; gameLevel = data.gameLevel; connectedPlayers = data.connectedPlayers; playerLimit = data.playerLimit; passwordProtected = data.passwordProtected; dedicatedServer = data.dedicatedServer; useNat = data.useNat; useProxy = data.useProxy; comment = data.comment; platform = data.platform; internalEndpoint = data.internalEndpoint; timestamp = data.timestamp; }
public LocalHostData(string gameType, string gameName, string gameMode, string gameLevel, int connectedPlayers, int playerLimit, bool passwordProtected, bool dedicatedServer, bool useNat, bool useProxy, string comment, string platform, DateTime timestamp, NetworkEndPoint internalEndpoint) { this.gameType = gameType; this.gameName = gameName; this.gameMode = gameMode; this.gameLevel = gameLevel; this.connectedPlayers = connectedPlayers; this.playerLimit = playerLimit; this.passwordProtected = passwordProtected; this.dedicatedServer = dedicatedServer; this.useNat = useNat; this.useProxy = useProxy; this.comment = comment; this.platform = platform; this.internalEndpoint = internalEndpoint; this.timestamp = timestamp; }
internal LocalHostData(NetBuffer buffer) { gameType = buffer.ReadString(); gameName = buffer.ReadString(); gameMode = buffer.ReadString(); gameLevel = buffer.ReadString(); connectedPlayers = buffer.ReadInt32(); playerLimit = buffer.ReadInt32(); passwordProtected = (buffer.ReadByte() == 1); dedicatedServer = (buffer.ReadByte() == 1); useNat = (buffer.ReadByte() == 1); useProxy = (buffer.ReadByte() == 1); comment = buffer.ReadString(); platform = buffer.ReadString(); timestamp = DateTime.FromBinary(buffer.ReadInt64()); internalEndpoint = buffer.ReadEndPoint(); }
public void DiscoverLocalHosts(HostDataFilter filter, int remoteStartPort, int remoteEndPort) { if (remoteEndPort - remoteStartPort >= 20) { Log.Warning(NetworkLogFlags.MasterServer, "Sending broadcast packets on more than 20 ports (with frequent interval) to discover local hosts, may cause some routers to block UDP traffic or behave undesirably."); } _timeOfDiscoveryRequest = NetworkTime.localTime; for (int port = remoteStartPort; port <= remoteEndPort; port++) { var msg = new UnconnectedMessage(UnconnectedMessage.InternalCode.DiscoverHostRequest); msg.stream.WriteHostDataFilter(filter); msg.stream.WriteDouble(NetworkTime.localTime); var broadcast = new NetworkEndPoint(IPAddress.Broadcast, port); _SendUnconnectedRPC(msg, broadcast); } }
internal override void _MasterSendProxyRequest(NetworkEndPoint host, string password) { _MasterConnect(); Log.Info(NetworkLogFlags.MasterServer | NetworkLogFlags.Client, "Sending proxy request for host ", host, String.IsNullOrEmpty(password) ? " without password" : " with password"); var msg = new NetworkMasterMessage(NetworkMasterMessage.InternalCode.ProxyRequest); msg.stream.WriteEndPoint(host); msg.stream.WritePassword(new Password(password)); if (_master.Status == NetConnectionStatus.Connected) { _master.SendMessage(msg.stream._buffer, NetChannel.ReliableInOrder1); } else { _pendingMessages[(int)NetworkMasterMessage.InternalCode.ProxyRequest] = msg; } }
public override void Bind(NetworkEndPoint listenEndPoint) { #if CHECK_ALREADYINUSE var ipListenEndPoint = (IPEndPoint)listenEndPoint; lock (_checkingAlreadyInUseLock) { foreach (var endpoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners()) { if (endpoint.Port == ipListenEndPoint.Port && (endpoint.Address.Equals(IPAddress.Any) || endpoint.Address.Equals(ipListenEndPoint.Address))) { return; // already in use } } #endif _socket.Bind(listenEndPoint); #if CHECK_ALREADYINUSE } #endif // TODO: assert(_socket.IsBound) }
public LocalPeerData(string peerType, string peerName, bool passwordProtected, string comment, string platform, DateTime timestamp, NetworkEndPoint internalEndpoint) { this.peerType = peerType; this.peerName = peerName; this.passwordProtected = passwordProtected; this.comment = comment; this.platform = platform; this.internalEndpoint = internalEndpoint; this.timestamp = timestamp; }
public abstract int ReceivePacket(byte[] buffer, int offset, int size, out NetworkEndPoint sourceEndPoint, out double localTimeRecv);
public abstract int SendPacket(byte[] buffer, int offset, int size, NetworkEndPoint targetEndPoint);
public abstract void Bind(NetworkEndPoint listenEndPoint);
// TODO: should probably be moved to a new Reliability Abstraction Layer. public virtual void Disconnect(NetworkEndPoint targetEndPoint) { }
/// <summary> /// Store location info for a favorite server (Known Host) in the client. /// </summary> /// <param name="endpoint">The <see cref="System.Net.NetworkEndPoint"/> of favorite server</param> /// <remarks> /// It is possible to store a separate list of known hosts (favorite servers) in the local uLink client. /// Use the API for Known Host Data in this class to build a feature for your users to /// store their favorite servers and access them easily /// when they try to reconnect to play the game again on the same server as before. /// </remarks> /// <seealso cref="PollKnownHostData"/> /// <seealso cref="RequestKnownHostData"/> /// <seealso cref="RemoveKnownHostData"/> /// <seealso cref="ClearKnownHosts"/> public static void AddKnownHostData(NetworkEndPoint endpoint) { Network._singleton.AddKnownHostData(endpoint); }
/// <summary> /// Remove location info for a favorite server (Known Host) in the client using server's <see cref="System.Net.NetworkEndPoint"/>. /// </summary> /// <param name="endpoint">The <see cref="System.Net.NetworkEndPoint"/> of favorite server.</param> /// <seealso cref="PollKnownHostData"/> /// <seealso cref="RequestKnownHostData"/> /// <seealso cref="AddKnownHostData"/> /// <seealso cref="ClearKnownHosts"/> public static void RemoveKnownHostData(NetworkEndPoint endpoint) { Network._singleton.RemoveKnownHostData(endpoint); }
internal NetworkPeer(NetBuffer buffer) { endpoint = buffer.ReadEndPoint(); }
/// <summary> /// Gets the HostData info for one favorite servers (Known Hosts) stored in the client. /// </summary> /// <param name="endpoint">The <see cref="System.Net.NetworkEndPoint"/> of the favorite server</param> /// <returns> /// <see cref="uLink.HostData"/> of polled favorite hosts. /// </returns> public static HostData PollKnownHostData(NetworkEndPoint endpoint) { return(Network._singleton.PollKnownHostData(endpoint)); }
/// <summary> /// Initializes a peer. /// </summary> /// <param name="hostnameOrIP">Host name or IP address of the peer.</param> /// <param name="port">The port that peer should listen to.</param> public NetworkPeer(string hostnameOrIP, int port) { endpoint = Utility.Resolve(hostnameOrIP, port); }
/// <summary> /// Initializes a peer. /// </summary> /// <param name="ip">IP address of the peer.</param> /// <param name="port">The port that the peer should listen to.</param> public NetworkPeer(IPAddress ip, int port) { endpoint = new NetworkEndPoint(ip, port); }
/// <summary> /// Initializes a peer. /// </summary> /// <param name="localPort">The port that we should listen to.</param> public NetworkPeer(int localPort) { endpoint = Utility.Resolve(localPort); }
public NetworkPeer(NetworkEndPoint endpoint) { this.endpoint = endpoint; }
internal HostData(NetworkEndPoint externalEndpoint) { this.externalEndpoint = externalEndpoint; }
internal HostData(NetBuffer buffer) : base(buffer) { externalEndpoint = buffer.ReadEndPoint(); ping = buffer.ReadInt32(); }
public HostData(HostData data) : base(data) { externalEndpoint = data.externalEndpoint; ping = data.ping; }