breaking: obsolete Uri support

This commit is contained in:
vis2k 2021-05-13 13:19:18 +08:00
parent 089e5bbb59
commit 9bbbf51df5
18 changed files with 29 additions and 1 deletions

View File

@ -145,6 +145,7 @@ public static void Connect(string address)
} }
/// <summary>Connect client to a NetworkServer by Uri.</summary> /// <summary>Connect client to a NetworkServer by Uri.</summary>
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public static void Connect(Uri uri) public static void Connect(Uri uri)
{ {
// Debug.Log("Client Connect: " + uri); // Debug.Log("Client Connect: " + uri);

View File

@ -362,6 +362,7 @@ public void StartClient()
} }
/// <summary>Starts the client, connects it to the server via Uri</summary> /// <summary>Starts the client, connects it to the server via Uri</summary>
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public void StartClient(Uri uri) public void StartClient(Uri uri)
{ {
if (NetworkClient.active) if (NetworkClient.active)

View File

@ -394,6 +394,7 @@ public static T[] ReadArray<T>(this NetworkReader reader)
return result; return result;
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public static Uri ReadUri(this NetworkReader reader) public static Uri ReadUri(this NetworkReader reader)
{ {
return new Uri(reader.ReadString()); return new Uri(reader.ReadString());

View File

@ -413,6 +413,7 @@ public static void WriteGameObject(this NetworkWriter writer, GameObject value)
} }
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public static void WriteUri(this NetworkWriter writer, Uri uri) public static void WriteUri(this NetworkWriter writer, Uri uri)
{ {
writer.WriteString(uri.ToString()); writer.WriteString(uri.ToString());

View File

@ -63,6 +63,7 @@ public override void ClientConnect(string address)
available.ClientConnect(address); available.ClientConnect(address);
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override void ClientConnect(Uri uri) public override void ClientConnect(Uri uri)
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
@ -100,6 +101,7 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
// right now this just returns the first available uri, // right now this just returns the first available uri,
// should we return the list of all available uri? // should we return the list of all available uri?
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() => available.ServerUri(); public override Uri ServerUri() => available.ServerUri();
public override bool ServerActive() public override bool ServerActive()

View File

@ -139,6 +139,7 @@ void OnDisable()
} }
// server // server
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() public override Uri ServerUri()
{ {
UriBuilder builder = new UriBuilder(); UriBuilder builder = new UriBuilder();

View File

@ -143,6 +143,7 @@ public override void ClientConnect(string address)
wrap.ClientConnect(address); wrap.ClientConnect(address);
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override void ClientConnect(Uri uri) public override void ClientConnect(Uri uri)
{ {
wrap.OnClientConnected = OnClientConnected; wrap.OnClientConnected = OnClientConnected;
@ -167,6 +168,7 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
SimulateSend(0, segment, channelId, latency, reliableClientToServer, unreliableClientToServer); SimulateSend(0, segment, channelId, latency, reliableClientToServer, unreliableClientToServer);
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() => wrap.ServerUri(); public override Uri ServerUri() => wrap.ServerUri();
public override bool ServerActive() => wrap.ServerActive(); public override bool ServerActive() => wrap.ServerActive();

View File

@ -48,6 +48,7 @@ public override void ServerStart()
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) => inner.ServerSend(connectionId, segment, channelId); public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) => inner.ServerSend(connectionId, segment, channelId);
public override void ServerDisconnect(int connectionId) => inner.ServerDisconnect(connectionId); public override void ServerDisconnect(int connectionId) => inner.ServerDisconnect(connectionId);
public override string ServerGetClientAddress(int connectionId) => inner.ServerGetClientAddress(connectionId); public override string ServerGetClientAddress(int connectionId) => inner.ServerGetClientAddress(connectionId);
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() => inner.ServerUri(); public override Uri ServerUri() => inner.ServerUri();
#endregion #endregion
} }

View File

@ -101,6 +101,7 @@ public override void ClientConnect(string address)
throw new ArgumentException("No transport suitable for this platform"); throw new ArgumentException("No transport suitable for this platform");
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override void ClientConnect(Uri uri) public override void ClientConnect(Uri uri)
{ {
foreach (Transport transport in transports) foreach (Transport transport in transports)
@ -198,6 +199,7 @@ void AddServerCallbacks()
// for now returns the first uri, // for now returns the first uri,
// should we return all available uris? // should we return all available uris?
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() public override Uri ServerUri()
{ {
return transports[0].ServerUri(); return transports[0].ServerUri();

View File

@ -272,6 +272,7 @@ public override string ServerGetClientAddress(int connectionId)
return server.GetClientAddress(connectionId); return server.GetClientAddress(connectionId);
} }
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() public override Uri ServerUri()
{ {
UriBuilder builder = new UriBuilder UriBuilder builder = new UriBuilder

View File

@ -123,6 +123,7 @@ public override bool Available()
// client // client
public override bool ClientConnected() => client.Connected; public override bool ClientConnected() => client.Connected;
public override void ClientConnect(string address) => client.Connect(address, port); public override void ClientConnect(string address) => client.Connect(address, port);
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override void ClientConnect(Uri uri) public override void ClientConnect(Uri uri)
{ {
if (uri.Scheme != Scheme) if (uri.Scheme != Scheme)
@ -148,6 +149,7 @@ public override void ClientEarlyUpdate()
} }
// server // server
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() public override Uri ServerUri()
{ {
UriBuilder builder = new UriBuilder(); UriBuilder builder = new UriBuilder();

View File

@ -55,6 +55,7 @@ public abstract class Transport : MonoBehaviour
public abstract void ClientConnect(string address); public abstract void ClientConnect(string address);
/// <summary>Connects the client to the server at the Uri.</summary> /// <summary>Connects the client to the server at the Uri.</summary>
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public virtual void ClientConnect(Uri uri) public virtual void ClientConnect(Uri uri)
{ {
// By default, to keep backwards compatibility, just connect to the host // By default, to keep backwards compatibility, just connect to the host

View File

@ -113,6 +113,7 @@ public override void ClientEarlyUpdate()
} }
public override bool ServerActive() => serverActive; public override bool ServerActive() => serverActive;
[Obsolete("We are considering to remove Uri support, unless someone has a good reason to keep it.")]
public override Uri ServerUri() => throw new NotImplementedException(); public override Uri ServerUri() => throw new NotImplementedException();
public override void ServerStart() { serverActive = true; } public override void ServerStart() { serverActive = true; }
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)

View File

@ -176,6 +176,7 @@ public void TestServerGetClientAddress(int id, string result)
[Test] [Test]
[TestCase("tcp4://localhost:7777")] [TestCase("tcp4://localhost:7777")]
[TestCase("tcp4://example.com:7777")] [TestCase("tcp4://example.com:7777")]
#pragma warning disable 618
public void TestServerUri(string address) public void TestServerUri(string address)
{ {
Uri uri = new Uri(address); Uri uri = new Uri(address);
@ -185,6 +186,7 @@ public void TestServerUri(string address)
inner.Received(1).ServerUri(); inner.Received(1).ServerUri();
} }
#pragma warning restore 618
[Test] [Test]
public void TestClientConnectedCallback() public void TestClientConnectedCallback()

View File

@ -64,6 +64,7 @@ public void TestConnect()
} }
// A Test behaves as an ordinary method // A Test behaves as an ordinary method
#pragma warning disable 618
[Test] [Test]
public void TestConnectFirstUri() public void TestConnectFirstUri()
{ {
@ -76,9 +77,10 @@ public void TestConnectFirstUri()
transport1.Received().ClientConnect(uri); transport1.Received().ClientConnect(uri);
transport2.DidNotReceive().ClientConnect(uri); transport2.DidNotReceive().ClientConnect(uri);
} }
#pragma warning restore 61
// A Test behaves as an ordinary method // A Test behaves as an ordinary method
#pragma warning disable 618
[Test] [Test]
public void TestConnectSecondUri() public void TestConnectSecondUri()
{ {
@ -96,6 +98,7 @@ public void TestConnectSecondUri()
transport.ClientConnect(uri); transport.ClientConnect(uri);
transport2.Received().ClientConnect(uri); transport2.Received().ClientConnect(uri);
} }
#pragma warning restore 618
[Test] [Test]
public void TestConnected() public void TestConnected()

View File

@ -36,6 +36,7 @@ public void IsConnected()
Assert.That(NetworkClient.isConnected, Is.True); Assert.That(NetworkClient.isConnected, Is.True);
} }
#pragma warning disable 618
[Test] [Test]
public void ConnectUri() public void ConnectUri()
{ {
@ -44,6 +45,7 @@ public void ConnectUri()
UpdateTransport(); UpdateTransport();
Assert.That(NetworkClient.isConnected, Is.True); Assert.That(NetworkClient.isConnected, Is.True);
} }
#pragma warning restore 618
[Test] [Test]
public void DisconnectInHostMode() public void DisconnectInHostMode()

View File

@ -133,6 +133,7 @@ public void GetStartPositionTest()
} }
[Test] [Test]
#pragma warning disable 618
public void StartClientUriTest() public void StartClientUriTest()
{ {
UriBuilder uriBuilder = new UriBuilder UriBuilder uriBuilder = new UriBuilder
@ -146,5 +147,6 @@ public void StartClientUriTest()
Assert.That(manager.isNetworkActive, Is.EqualTo(true)); Assert.That(manager.isNetworkActive, Is.EqualTo(true));
Assert.That(manager.networkAddress, Is.EqualTo(uriBuilder.Uri.Host)); Assert.That(manager.networkAddress, Is.EqualTo(uriBuilder.Uri.Host));
} }
#pragma warning restore 618
} }
} }

View File

@ -904,6 +904,7 @@ public void TestWritingAndReading()
} }
[Test] [Test]
#pragma warning disable 618
public void TestWritingUri() public void TestWritingUri()
{ {
@ -915,6 +916,7 @@ public void TestWritingUri()
NetworkReader reader = new NetworkReader(writer.ToArray()); NetworkReader reader = new NetworkReader(writer.ToArray());
Assert.That(reader.ReadUri(), Is.EqualTo(testUri)); Assert.That(reader.ReadUri(), Is.EqualTo(testUri));
} }
#pragma warning restore 618
[Test] [Test]
public void TestList() public void TestList()