56-Mirror__Network Discovery-NewNetworkDiscovery.cs.txt 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Net;
  2. using Mirror;
  3. using Mirror.Discovery;
  4. /*
  5. Documentation: https://mirror-networking.gitbook.io/docs/components/network-discovery
  6. API Reference: https://mirror-networking.com/docs/api/Mirror.Discovery.NetworkDiscovery.html
  7. */
  8. public class DiscoveryRequest : NetworkMessage
  9. {
  10. // Add properties for whatever information you want sent by clients
  11. // in their broadcast messages that servers will consume.
  12. }
  13. public class DiscoveryResponse : NetworkMessage
  14. {
  15. // Add properties for whatever information you want the server to return to
  16. // clients for them to display or consume for establishing a connection.
  17. }
  18. public class #SCRIPTNAME# : NetworkDiscoveryBase<DiscoveryRequest, DiscoveryResponse>
  19. {
  20. #region Server
  21. /// <summary>
  22. /// Reply to the client to inform it of this server
  23. /// </summary>
  24. /// <remarks>
  25. /// Override if you wish to ignore server requests based on
  26. /// custom criteria such as language, full server game mode or difficulty
  27. /// </remarks>
  28. /// <param name="request">Request coming from client</param>
  29. /// <param name="endpoint">Address of the client that sent the request</param>
  30. protected override void ProcessClientRequest(DiscoveryRequest request, IPEndPoint endpoint)
  31. {
  32. base.ProcessClientRequest(request, endpoint);
  33. }
  34. /// <summary>
  35. /// Process the request from a client
  36. /// </summary>
  37. /// <remarks>
  38. /// Override if you wish to provide more information to the clients
  39. /// such as the name of the host player
  40. /// </remarks>
  41. /// <param name="request">Request coming from client</param>
  42. /// <param name="endpoint">Address of the client that sent the request</param>
  43. /// <returns>A message containing information about this server</returns>
  44. protected override DiscoveryResponse ProcessRequest(DiscoveryRequest request, IPEndPoint endpoint)
  45. {
  46. return new DiscoveryResponse();
  47. }
  48. #endregion
  49. #region Client
  50. /// <summary>
  51. /// Create a message that will be broadcasted on the network to discover servers
  52. /// </summary>
  53. /// <remarks>
  54. /// Override if you wish to include additional data in the discovery message
  55. /// such as desired game mode, language, difficulty, etc... </remarks>
  56. /// <returns>An instance of ServerRequest with data to be broadcasted</returns>
  57. protected override DiscoveryRequest GetRequest()
  58. {
  59. return new DiscoveryRequest();
  60. }
  61. /// <summary>
  62. /// Process the answer from a server
  63. /// </summary>
  64. /// <remarks>
  65. /// A client receives a reply from a server, this method processes the
  66. /// reply and raises an event
  67. /// </remarks>
  68. /// <param name="response">Response that came from the server</param>
  69. /// <param name="endpoint">Address of the server that replied</param>
  70. protected override void ProcessResponse(DiscoveryResponse response, IPEndPoint endpoint) { }
  71. #endregion
  72. }