AuthenticateOnNameServer
How do I use Authenticate On Name Server
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: ChatClient.cs
Copy
620 void IPhotonPeerListener.OnStatusChanged(StatusCode statusCode)
621 {
622 switch (statusCode)
623 {
624 case StatusCode.Connect:
625 this.chatPeer.EstablishEncryption();
626 if (this.State == ChatState.ConnectingToNameServer)
627 {
628 this.State = ChatState.ConnectedToNameServer;
629 this.listener.OnChatStateChange(this.State);
630 }
631 else if (this.State == ChatState.ConnectingToFrontEnd)
632 {
633 this.AuthenticateOnFrontEnd();
634 }
635 break;
636 case StatusCode.EncryptionEstablished:
637 // once encryption is availble, the client should send one (secure) authenticate. it includes the AppId (which identifies your app on the Photon Cloud)
638 if (!this.didAuthenticate)
639 {
640 this.didAuthenticate = this.chatPeer.AuthenticateOnNameServer(this.AppId, this.AppVersion, this.chatRegion, this.UserId, this.CustomAuthenticationValues);
641 if (!this.didAuthenticate)
642 {
643 ((IPhotonPeerListener) this).DebugReturn(DebugLevel.ERROR, "Error calling OpAuthenticate! Did not work. Check log output, CustomAuthenticationValues and if you're connected. State: " + this.State);
644 }
645 }
646 break;
647 case StatusCode.EncryptionFailedToEstablish:
648 this.State = ChatState.Disconnecting;
649 this.chatPeer.Disconnect();
650 break;
651 case StatusCode.Disconnect:
652 if (this.State == ChatState.Authenticated)
653 {
654 this.ConnectToFrontEnd();
655 }
656 else
657 {
658 this.State = ChatState.Disconnected;
659 this.listener.OnChatStateChange(ChatState.Disconnected);
660 this.listener.OnDisconnected();
661 }
662 break;
663 }
664 }
File name: ChatPeer.cs
Copy
31 public bool AuthenticateOnNameServer(string appId, string appVersion, string region, string userId, AuthenticationValues authValues)
32 {
33 if (this.DebugOut >= DebugLevel.INFO)
34 {
35 this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
36 }
37
38 var opParameters = new Dictionary
39
40 opParameters[ParameterCode.AppVersion] = appVersion;
41 opParameters[ParameterCode.ApplicationId] = appId;
42 opParameters[ParameterCode.Region] = region;
43
44 if (!string.IsNullOrEmpty(userId))
45 {
46 opParameters[ParameterCode.UserId] = userId;
47 }
48
49 if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
50 {
51 opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
52 if (!string.IsNullOrEmpty(authValues.Secret))
53 {
54 opParameters[ParameterCode.Secret] = authValues.Secret;
55 }
56 else
57 {
58 if (!string.IsNullOrEmpty(authValues.AuthParameters))
59 {
60 opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthParameters;
61 }
62 if (authValues.AuthPostData != null)
63 {
64 opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
65 }
66 }
67 }
68
69 return this.OpCustom((byte)ChatOperationCode.Authenticate, opParameters, true, (byte)0, this.IsEncryptionAvailable);
70 }
AuthenticateOnNameServer 114 lượt xem
Gõ tìm kiếm nhanh...