diff --git a/README.md b/README.md index 4d5204b14b7..1957d129d88 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ Mirage has many new features * Server Rpcs can [return values](https://miragenet.github.io/Mirage/Articles/Guides/Communications/RemoteActions.html) * The default transport features DoS prevention * The default transport has CRC64 integrity check -* Mirage provides unreliable channel out of the box If you look under the hood, the code base has some significant differences based on the core values of each project * Mirage follows the [SOLID principles](https://en.wikipedia.org/wiki/SOLID). @@ -93,22 +92,14 @@ If you want to contribute to Mirage, follow these steps: If you don't enable symlinks, you will be able to work on Mirage but Unity will not see the examples. 3) Open in unity 2019.4.x or later -## Transports -Here is a list of some transports supported by NG and how they compare to each other - -| | Kcp | [Websocket](https://github.com/MirageNet/WebsocketNG) | [Steam](https://github.com/dragonslaya84/FizzySteamyMirror) | [LiteNetLibNG](https://github.com/uweenukr/LiteNetLibNG) | [IgnoranceNG](https://github.com/dragonslaya84/IgnoranceNG) | -| -------------- | :----------------: | :--------------------------------------------------: | :---------------------------------------------------------: | :------------------------------------------------------: | :---------------------------------------------------------: | -| **CCU** | 1000+ | ? | ? | ? | ? | -| **Protocol** | UDP | TCP | UDP | UDP | UDP | -| **Unreliable** | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: | -| **WebGL** | | :white_check_mark: | | | | -| **Mobile** | :white_check_mark: | | | ? | ? | -| **CPU** | LOW | HIGH | ? | ? | ? | -| **NAT Punch** | | | :white_check_mark: | | | -| **Encryption** | | :white_check_mark: | :white_check_mark: | | | -| **IPV6** | :white_check_mark: | :white_check_mark: | ? | ? | ? | -| **Managed** | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | -| **Based on** | KCP | Websockets | Steam Game Networking Sockets | LiteNetLib | ENet | +## Transport and Sockets + +Mirage supports multiple ways of transporting data: +- c# UDP Socket (default) +- Native UDP socket (coming soon) +- Websocket, to support webgl clients (coming soon) +- Steam (coming soon) + ## Contributing diff --git a/doc/Articles/Components/Authenticators/index.md b/doc/Articles/Components/Authenticators/index.md index aa084b86204..697924cb48a 100644 --- a/doc/Articles/Components/Authenticators/index.md +++ b/doc/Articles/Components/Authenticators/index.md @@ -1,61 +1,62 @@ # Authentication -When you have a multiplayer game, often you need to store information about your player for later games, keep game stats or communicate with your friends. For all these use cases, you often need a way to uniquely identify a user. Being able to tell users apart is called authentication. There are several methods available, some examples include: -- Ask the user for username and password -- Use a third party OAuth2 or OpenID identity provider, such as Facebook, Twitter, Google -- Use a third party service such as PlayFab, GameLift or Steam -- Use the device id, very popular method in mobile -- Use Google Play in Android -- Use Game Center in IOS -- Use a web service in your website +For some games you may want to limit who can join or uniquely identity a user in order to save stats or communicate with friends. Authentication is checking if a user is valid and is who they say they are. There are several methods available, some examples include: +- Ask the user for username and password +- Use a third party OAuth2 or OpenID identity provider, such as Facebook, Twitter, Google +- Use a third party service such as PlayFab, GameLift or Steam +- Use the device id, very popular method in mobile +- Use Google Play in Android +- Use Game Center in IOS +- Use a web service in your website + ## Encryption Notice -By default Mirage uses Kcp, which is not encrypted, so if you want to do authentication through Mirage, we highly recommend you use a transport that supports encryption. +By default Mirage is not encrypted, so if you want to do authentication through Mirage, we highly recommend you use a transport that supports encryption. ## Basic Authenticator -- [Basic Authenticator](Basic.md) - Mirage includes a Basic Authenticator in the Mirage / Authenticators folder which just uses a simple username and password. +[Basic Authenticator](Basic.md) + +Mirage includes a Basic Authenticator in the `Mirage/Authenticators` folder which just uses a simple password. This will only allow people with the password to join the server. For example, a password on a hosted game so that only friends can join. + ## Custom Authenticators -Authenticators are derived from an `Authenticator` abstract class that allows you to implement any authentication scheme you need. +To Create a custom authenticator implement the `NetworkAuthenticator` abstract class and override the `ServerAuthenticated` and `ClientAuthenticated` methods. -When a client is successfully authenticated, call `base.OnServerAuthenticated.Invoke(conn)` on the server and `base.OnClientAuthenticated.Invoke(conn)` on the client. Mirage is listening for these events to proceed with the connection sequence. Subscribe to OnServerAuthenticated and OnClientAuthenticated events if you wish to perform additional steps after authentication. +After authenticating a player call either `ServerAccept`, `ServerReject`, `ClientAccept` or `ClientReject` depending if running on Server or Client and if you it was successful or not. -## Message Registration +Calling the `Accept` method will cause mirage to invoke the `OnServerAuthenticated` or `OnClientAuthenticated` events. Subscribe to OnServerAuthenticated and OnClientAuthenticated events if you wish to perform additional steps after authentication. -By default all messages registered to `NetworkServer` and `NetworkClient` require authentication unless explicitly indicated otherwise. To register messages to bypass authentication, you need to specify `false` for a bool parameter to the `RegisterMessage` method: +Calling the `Reject` method will cause the player to be disconnected after a short delay. + +When Rejecting, It is a good idea to send a message to the client to tell them that authentication failed, for example: "Server password invalid" or "Login failed". -``` -NetworkServer.RegisterHandler(OnAuthRequestMessage, false); -``` -Certain internal messages already have been set to bypass authentication: +## Check if a player is authenticated -- Server - - `ConnectMessage` - - `DisconnectMessage` - - `ErrorMessage` - - `NetworkPingMessage` -- Client - - `ConnectMessage` - - `DisconnectMessage` - - `ErrorMessage` - - `SceneMessage` - - `NetworkPongMessage` +After a player has been accepted `IsAuthenticated` will be set to true. The bool can be used alongside `AuthenticationData` to check if a user is allowed to do certain actions. -### Tips -- Register handlers for messages in `OnStartServer` and `OnStartClient`. They're called from StartServer/StartHost, and StartClient, respectively. -- Send a message to the client if authentication fails, especially if there's some issue they can resolve. -- Call the `Disconnect()` method of the `NetworkConnection` on the server and client when authentication fails. If you want to give the user a few tries to get their credentials right, you certainly can, but Mirage will not do the disconnect for you. - - Remember to put a small delay on the Disconnect call on the server if you send a failure message so that it has a chance to be delivered before the connection is dropped. -- `NetworkConnection` has an `authenticationData` object where you can drop any data you need to persist on the server related to the authentication, such as account id's, tokens, character selection, etc. +## Storing Authentication data + +The `NetworkPlayer` object has an `AuthenticationData` property that can be used to store any data related to authentication, such as account id, tokens, or players username. + +This property is of type `object` so can be set to any object and can be cast back to that object when you need to read the data. + +```cs +if (player.IsAuthenticated) +{ + var loginData = (MyLogInData)player.AuthenticationData; + var username = loginData.Username; + // do something with username :) +} +``` + Now that you have the foundation of a custom Authenticator component, the rest is up to you. You can exchange any number of custom messages between the server and client as necessary to complete your authentication process before approving the client. Authentication can also be extended to character selection and customization, just by crafting additional messages and exchanging them with the client before completing the authentication process. This means this process takes place before the client player actually enters the game or changes to the Online scene. -If you write a good authenticator, consider sharing it with other users or donating it to the Mirage project. +If you write a good authenticator, consider sharing it with other users or contributing it to the Mirage project. diff --git a/doc/Articles/Guides/CommunityGuides/MirageQuickStartGuide/index.md b/doc/Articles/Guides/CommunityGuides/MirageQuickStartGuide/index.md index 94cd26f7b81..20fffd1077d 100644 --- a/doc/Articles/Guides/CommunityGuides/MirageQuickStartGuide/index.md +++ b/doc/Articles/Guides/CommunityGuides/MirageQuickStartGuide/index.md @@ -1,4 +1,8 @@ # Mirage Quick Start Guide + +> [!WARNING] +> This guide was written for mirror so some information might be out-of-date for mirage + This guide currently shows you: - [Basic scene setup](#part-1) - [Player movement](#part-4) @@ -11,7 +15,6 @@ It is best to first make a mini practice game before converting your single play The Pre-made Mirage examples are great for using as reference, it is recommend to use them regarding connection setup, with ports and firewalls. This can be a huge topic that changes from person to person, and is not covered in this guide, here we will use localHost (multiple games on same PC). - ## Part 1 Blank Project, import UniTask and Mirage using Unity package manager. diff --git a/doc/Articles/Guides/DevServer/gcloud/index.md b/doc/Articles/Guides/DevServer/gcloud/index.md index 46ea6ba6c85..610c7a44a63 100644 --- a/doc/Articles/Guides/DevServer/gcloud/index.md +++ b/doc/Articles/Guides/DevServer/gcloud/index.md @@ -91,7 +91,7 @@ This will allow other people to connect to your server using its IP and port - Source IP ranges: 0.0.0.0/0 - Protocols or ports: Select UDP, and then enter port 7777 into the field provided. -> note UDP and port 7777 is default settings for KCP transport, if you are using a different transport you will need to find out what settings that uses. +> note UDP and port 7777 is default settings for socket, if you are using a different socket you will need to find out what settings that uses. ![Create network rule](./07-create-network-rule.jpg) diff --git a/doc/Articles/Guides/Sync/index.md b/doc/Articles/Guides/Sync/index.md index 7f03ddec2a3..d20452f83c4 100644 --- a/doc/Articles/Guides/Sync/index.md +++ b/doc/Articles/Guides/Sync/index.md @@ -209,5 +209,3 @@ public override void DeserializeSyncVars(NetworkReader reader, bool initialState ``` If a has a base class that also has serialization functions, the base class functions should also be called. - -Note that the `UpdateVar` packets created for game object state updates may be aggregated in buffers before being sent to the client, so a single transport layer packet may contain updates for multiple game objects.