Container for user authentication in Photon. Set AuthValues before you connect - all else is handled.
On Photon, user authentication is optional but can be useful in many cases. If you want to FindFriends, a unique ID per user is very practical. There are basically three options for user authentication: None at all, the client sets some UserId or you can use some account web-service to authenticate a user (and set the UserId server-side). Custom Authentication lets you verify end-users by some kind of login or token. It sends those values to Photon which will verify them before granting access or disconnecting the client. The AuthValues are sent in OpAuthenticate when you connect, so they must be set before you connect. If the AuthValues.UserId is null or empty when it's sent to the server, then the Photon Server assigns a UserId! The Photon Cloud Dashboard will let you enable this feature and set important server values for it. https://dashboard.photonengine.com
Example #1
0
        /// <summary>
        /// Used to setup various settings in the chatbox like chat length, chat
        /// app settings, authentication values, finding player camera, finding
        /// your player, etc.
        /// </summary>
        protected virtual void Start()
        {
            nm = (nm == null) ? FindObjectOfType <NetworkManager>() : nm;
            FindPlayerCam();
            SetMyPlayer();

            if (chatAnim == null && GetComponent <Animator>())
            {
                chatAnim = GetComponent <Animator>();
            }

            Application.runInBackground = true;
            #if PHOTON_UNITY_NETWORKING
            chatAppSettings = PhotonNetwork.PhotonServerSettings.AppSettings;
            #endif
            if (string.IsNullOrEmpty(chatAppSettings.AppIdChat))
            {
                Debug.LogError("Chat - The chat id is empty in your photon server settings! The chat will not work until this is populated!");
                return;
            }
            authValues = new Photon.Chat.AuthenticationValues();
            images.AddRange(GetComponentsInChildren <Image>());
            texts.AddRange(GetComponentsInChildren <Text>());
            EnableChat(startEnabled);
            if (startEnabled == false)
            {
                EnableVisualBox(false);
            }
            SceneManager.sceneLoaded += SceneLoaded;
        }
Example #2
0
        // Token: 0x06002299 RID: 8857 RVA: 0x000AA870 File Offset: 0x000A8A70
        public bool Connect(string appId, string appVersion, AuthenticationValues authValues)
        {
            this.chatPeer.TimePingInterval = 3000;
            this.DisconnectedCause         = ChatDisconnectCause.None;
            this.AuthValues      = authValues;
            this.AppId           = appId;
            this.AppVersion      = appVersion;
            this.didAuthenticate = false;
            this.chatPeer.QuickResendAttempts = 2;
            this.chatPeer.SentCountAllowance  = 7;
            this.PublicChannels.Clear();
            this.PrivateChannels.Clear();
            this.PublicChannelsUnsubscribing.Clear();
            this.NameServerAddress = this.chatPeer.NameServerAddress;
            bool flag = this.chatPeer.Connect();

            if (flag)
            {
                this.State = ChatState.ConnectingToNameServer;
            }
            if (this.UseBackgroundWorkerForSending)
            {
                SupportClass.StartBackgroundCalls(new Func <bool>(this.SendOutgoingInBackground), this.msDeltaForServiceCalls, "ChatClient Service Thread");
            }
            return(flag);
        }
Example #3
0
 /// <summary>
 /// Make a copy of the current object.
 /// </summary>
 /// <param name="copy">The object to be copied into.</param>
 /// <returns>The copied object.</returns>
 public AuthenticationValues CopyTo(AuthenticationValues copy)
 {
     copy.AuthType          = this.AuthType;
     copy.AuthGetParameters = this.AuthGetParameters;
     copy.AuthPostData      = this.AuthPostData;
     copy.UserId            = this.UserId;
     return(copy);
 }
Example #4
0
 // public override void OnConnectedToMaster(){
 //     ConnectChatServer();
 // }
 public void Connect()
 {
     this.chatClient = new ChatClient(this);
     #if !UNITY_WEBGL
     this.chatClient.UseBackgroundWorkerForSending = true;
     #endif
     authenticationValues = new Photon.Chat.AuthenticationValues(PhotonNetwork.LocalPlayer.UserId);
     playerName           = PhotonNetwork.NickName;
     chatClient.Connect(this.chatAppSettings.AppIdChat, "1.0", authenticationValues);
 }
Example #5
0
    private void InitChat()
    {
        chatClient            = new ChatClient(this);
        chatClient.ChatRegion = "EU";

        Photon.Chat.AuthenticationValues authValues = new Photon.Chat.AuthenticationValues();
        authValues.UserId   = PlayerVariables.Inistance.getUserPlayFabID();
        authValues.AuthType = Photon.Chat.CustomAuthenticationType.None;

        chatClient.Connect(PHOTON_CHAT_ID, "0.01", authValues);
    }
Example #6
0
        /// <summary> Authenticates on NameServer. </summary>
        /// <returns>If the authentication operation request could be sent.</returns>
        public bool AuthenticateOnNameServer(string appId, string appVersion, string region,
                                             AuthenticationValues authValues)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
            }

            var opParameters = new Dictionary <byte, object>();

            opParameters[ParameterCode.AppVersion]    = appVersion;
            opParameters[ParameterCode.ApplicationId] = appId;
            opParameters[ParameterCode.Region]        = region;

            if (authValues != null)
            {
                if (!string.IsNullOrEmpty(authValues.UserId))
                {
                    opParameters[ParameterCode.UserId] = authValues.UserId;
                }

                if (authValues.AuthType != CustomAuthenticationType.None)
                {
                    opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
                    if (!string.IsNullOrEmpty(authValues.Token))
                    {
                        opParameters[ParameterCode.Secret] = authValues.Token;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                        {
                            opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthGetParameters;
                        }

                        if (authValues.AuthPostData != null)
                        {
                            opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
                        }
                    }
                }
            }

            return(this.SendOperation(ChatOperationCode.Authenticate, opParameters,
                                      new SendOptions()
            {
                Reliability = true, Encrypt = this.IsEncryptionAvailable
            }));
        }
Example #7
0
 public bool Connect() => default;                                                                                                 // 0x0000000182054D50-0x0000000182054E00
 public bool AuthenticateOnNameServer(string appId, string appVersion, string region, AuthenticationValues authValues) => default; // 0x0000000182054980-0x0000000182054B70
Example #8
0
        // Token: 0x060022CF RID: 8911 RVA: 0x000ABEF0 File Offset: 0x000AA0F0
        public bool AuthenticateOnNameServer(string appId, string appVersion, string region, AuthenticationValues authValues)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                base.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
            }
            Dictionary <byte, object> dictionary = new Dictionary <byte, object>();

            dictionary[220] = appVersion;
            dictionary[224] = appId;
            dictionary[210] = region;
            if (authValues != null)
            {
                if (!string.IsNullOrEmpty(authValues.UserId))
                {
                    dictionary[225] = authValues.UserId;
                }
                if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
                {
                    dictionary[217] = (byte)authValues.AuthType;
                    if (!string.IsNullOrEmpty(authValues.Token))
                    {
                        dictionary[221] = authValues.Token;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                        {
                            dictionary[216] = authValues.AuthGetParameters;
                        }
                        if (authValues.AuthPostData != null)
                        {
                            dictionary[214] = authValues.AuthPostData;
                        }
                    }
                }
            }
            return(this.SendOperation(230, dictionary, new SendOptions
            {
                Reliability = true,
                Encrypt = base.IsEncryptionAvailable
            }));
        }
Example #9
0
 // Token: 0x0600229A RID: 8858 RVA: 0x000AA934 File Offset: 0x000A8B34
 public bool ConnectAndSetStatus(string appId, string appVersion, AuthenticationValues authValues, int status = 2, object message = null)
 {
     this.statusToSetWhenConnected  = new int?(status);
     this.messageToSetWhenConnected = message;
     return(this.Connect(appId, appVersion, authValues));
 }