Skip to content

Commit

Permalink
breaking: Transports can now provide their Uri (#1454)
Browse files Browse the repository at this point in the history
* Fix typo

* Updated Changelog

* first commit

* Add example for discovery

* NetworkDiscovery component should be added

* fixed UI

* Fix some warnings

* refactor: network discovery reimplemented

* Remove unused GUIstyle

* Fix namespaces

* Just send to the broadcast address

* Fix indentation

* Log errors in ClientListen

* Code formatting cleanup, HelpURL's fixed, comments revised. (#38)

* Transport can now provide server uri

* work with any transport by passing uri

* Move discovery initialization to start

* feat: Discovery can now be easily customized per game

* Use generics to simplify api

* Renamed ServerInfo -> ServerResponse

* Rename method

* Moved up one folder

* Move ServerId to NetworkDiscovery

* tests now reference Mirror.Discovery

* Cleaned up blank space

* Disable GUID apparently fixes it

* Use UnityEvents for ease of use

* Remove noisy log

* remove blank spaces

* Process request receives the client endpoint

* use consistent name for parameters

* Remove white space

* Keep it minimalistic,  we don't need age or totalPlayers

* Comment non obvious property

* Don't break transports

* Documentation and image

* Code formatting

* removed privates

* Added Range attribute

* Rename ActiveDiscoverySecondInterval

* Revised NetworkDiscovery doc

* Swapped field order (Cosmetics)

* Added ScriptTemplate

* Update ProjectSettings/ProjectVersion.txt

* Updated ScriptTemplate

* Updated xml comment and ScriptTemplate

* Updated ScriptTemplate

* Improve xmldocs

* Improve xmldocs

* Remove leftover comment

* Renamed event

* Moved discovery inside components

* Keep parameter names consistent

* Provide a guide for network discovery

* XML Comments and ScriptTemplate

* Moved Credits

* fixed template

* Removed comment

* removed comment

* xml comments and template

* fixed method name

* fixed method and template

* removed semicolon

* fixed template

* fixed method and template

* fixed template

* fixed template

* Fix copypasta error

* Show error if no url is available

Network Discovery now shows an error if the transport does not support
providing Url

* breaking: Make server uri mandatory

BREAKING CHANGE: Make the server uri method mandatory in transports

Co-authored-by: MrGadget <chris@clevertech.net>
  • Loading branch information
2 people authored and miwarnec committed Jan 28, 2020
1 parent a706ef7 commit b916064
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Assets/Mirror/CompilerSymbols/PreprocessorDefine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static void AddDefineSymbols()
"MIRROR_1726_OR_NEWER",
"MIRROR_3_0_OR_NEWER",
"MIRROR_3_12_OR_NEWER",
"MIRROR_4_0_OR_NEWER"
"MIRROR_4_0_OR_NEWER",
"MIRROR_8_0_OR_NEWER"
};
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", defines));
}
Expand Down
4 changes: 4 additions & 0 deletions Assets/Mirror/Runtime/Transport/FallbackTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ void InitServer()
}
}

// right now this just returns the first available uri,
// should we return the list of all available uri?
public override Uri ServerUri() => available.ServerUri();

public override bool ServerActive()
{
return available.ServerActive();
Expand Down
13 changes: 13 additions & 0 deletions Assets/Mirror/Runtime/Transport/LLAPITransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Types;
Expand Down Expand Up @@ -221,6 +222,18 @@ public override void ClientDisconnect()
#endregion

#region server

// right now this just returns the first available uri,
// should we return the list of all available uri?
public override Uri ServerUri()
{
UriBuilder builder = new UriBuilder();
builder.Scheme = Scheme;
builder.Host = Dns.GetHostName();
builder.Port = port;
return builder.Uri;
}

public override bool ServerActive()
{
return serverHostId != -1;
Expand Down
8 changes: 8 additions & 0 deletions Assets/Mirror/Runtime/Transport/MultiplexTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ void InitServer()
}
}

// for now returns the first uri,
// should we return all available uris?
public override Uri ServerUri()
{
return transports[0].ServerUri();
}


public override bool ServerActive()
{
// avoid Linq.All allocations
Expand Down
10 changes: 10 additions & 0 deletions Assets/Mirror/Runtime/Transport/TelepathyTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
using UnityEngine.Serialization;
Expand Down Expand Up @@ -119,6 +120,15 @@ public void LateUpdate()
while (enabled && ProcessServerMessage()) { }
}

public override Uri ServerUri()
{
UriBuilder builder = new UriBuilder();
builder.Scheme = Scheme;
builder.Host = Dns.GetHostName();
builder.Port = port;
return builder.Uri;
}

// server
public override bool ServerActive() => server.Active;
public override void ServerStart() => server.Start(port);
Expand Down
8 changes: 8 additions & 0 deletions Assets/Mirror/Runtime/Transport/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public virtual void ClientConnect(Uri uri)

#region Server


/// <summary>
/// Retrieves the address of this server.
/// Useful for network discovery
/// </summary>
/// <returns>the url at which this server can be reached</returns>
public abstract Uri ServerUri();

/// <summary>
/// Notify subscribers when a client connects to this server
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Assets/Mirror/Runtime/Transport/Websocket/WebsocketTransport.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using UnityEngine;

namespace Mirror.Websocket
Expand Down Expand Up @@ -86,6 +87,16 @@ public override bool ClientSend(int channelId, ArraySegment<byte> segment)

public override void ClientDisconnect() => client.Disconnect();

public override Uri ServerUri()
{
UriBuilder builder = new UriBuilder();
builder.Scheme = Secure? SecureScheme : Scheme;
builder.Host = Dns.GetHostName();
builder.Port = port;
return builder.Uri;
}


// server
public override bool ServerActive() => server.Active;

Expand Down

0 comments on commit b916064

Please sign in to comment.