Mirror/Assets/ScriptTemplates/56-Mirror__Network Discovery-NewNetworkDiscovery.cs.txt
Paul Pacheco e75b45f888
feat: LAN Network discovery (#1453)
* 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

* Grammar fix

* Extended Template

* fixed template

* Added guide link to template

* New image

* Update NetworkDiscovery.md

* Updated Guid Doc and Template

* fixed bullets

* Remove unnecessary using

* Make it like Mirror's

* Update ScriptTemplates Image & Zip

* Removed from Deprecations

* Updated ChangeLog

* Updated ChangeLog

* Update NetworkDiscovery.md

Remove last line...this was copied to the paragraph above the code block

Co-authored-by: MrGadget <chris@clevertech.net>
2020-01-29 09:56:29 +01:00

85 lines
3.0 KiB
Plaintext

using System.Net;
using Mirror;
using Mirror.Discovery;
/*
Discovery Guide: https://mirror-networking.com/docs/Guides/NetworkDiscovery.html
Documentation: https://mirror-networking.com/docs/Components/NetworkDiscovery.html
API Reference: https://mirror-networking.com/docs/api/Mirror.Discovery.NetworkDiscovery.html
*/
public class DiscoveryRequest : MessageBase
{
// Add properties for whatever information you want sent by clients
// in their broadcast messages that servers will consume.
}
public class DiscoveryResponse : MessageBase
{
// Add properties for whatever information you want the server to return to
// clients for them to display or consume for establishing a connection.
}
public class #SCRIPTNAME# : NetworkDiscoveryBase<DiscoveryRequest, DiscoveryResponse>
{
#region Server
/// <summary>
/// Reply to the client to inform it of this server
/// </summary>
/// <remarks>
/// Override if you wish to ignore server requests based on
/// custom criteria such as language, full server game mode or difficulty
/// </remarks>
/// <param name="request">Request comming from client</param>
/// <param name="endpoint">Address of the client that sent the request</param>
protected override void ProcessClientRequest(DiscoveryRequest request, IPEndPoint endpoint)
{
base.ProcessClientRequest(request, endpoint);
}
/// <summary>
/// Process the request from a client
/// </summary>
/// <remarks>
/// Override if you wish to provide more information to the clients
/// such as the name of the host player
/// </remarks>
/// <param name="request">Request comming from client</param>
/// <param name="endpoint">Address of the client that sent the request</param>
/// <returns>A message containing information about this server</returns>
protected override DiscoveryResponse ProcessRequest(DiscoveryRequest request, IPEndPoint endpoint)
{
return new DiscoveryResponse();
}
#endregion
#region Client
/// <summary>
/// Create a message that will be broadcasted on the network to discover servers
/// </summary>
/// <remarks>
/// Override if you wish to include additional data in the discovery message
/// such as desired game mode, language, difficulty, etc... </remarks>
/// <returns>An instance of ServerRequest with data to be broadcasted</returns>
protected override DiscoveryRequest GetRequest()
{
return new DiscoveryRequest();
}
/// <summary>
/// Process the answer from a server
/// </summary>
/// <remarks>
/// A client receives a reply from a server, this method processes the
/// reply and raises an event
/// </remarks>
/// <param name="response">Response that came from the server</param>
/// <param name="endpoint">Address of the server that replied</param>
protected override void ProcessResponse(DiscoveryResponse response, IPEndPoint endpoint) { }
#endregion
}