コード例 #1
0
        // Creates a new user object and save it to the database
        public void RegisterClient(Client client, string email, string name, string password)
        {
            if (client == null)
            {
                return;
            }

            AuthResponse authResponse = new AuthResponse();

            try
            {
                string         salt           = _api.generateBCryptSalt(12);
                string         passwordHash   = _api.getPasswordHashBCrypt(password, salt);
                ExtendetClient extendetClient = _clientHandler.GetExtendetClient(client);

                extendetClient.Save();

                authResponse.Success = true;
            }
            catch (DbEntityValidationException e)
            {
                if (!e.Message.Contains("Validation failed for one or more"))
                {
                    authResponse.Error.Add(e.Message);
                }

                foreach (var eve in e.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        authResponse.Error.Add(ve.ErrorMessage);
                    }
                }

                authResponse.Success = false;
            }

            _eventHandler.InvokeClientEvent(client, "AuthResponse",
                                            JsonConvert.SerializeObject(authResponse));
        }
コード例 #2
0
        // gets called after the player/client connected and he is ready to receive triggers
        // If the users exists in the database, open the login otherwise the register
        public void OnPlayerReadyHandler(Client client, string eventName, object[] args)
        {
            ExtendetClient extendetClient = _clientHandler.GetExtendetClient(client);

            if (extendetClient.Properties.Name == null)
            {
                AuthOpen authOpen = new AuthOpen
                {
                    Type = "Register"
                };
                _eventHandler.InvokeClientEvent(client, "AuthOpen", JsonConvert.SerializeObject(authOpen));
            }
            else
            {
                AuthOpen authOpen = new AuthOpen
                {
                    Type     = "Login",
                    Username = extendetClient.Properties.Name
                };
                _eventHandler.InvokeClientEvent(client, "AuthOpen", JsonConvert.SerializeObject(authOpen));
            }
        }
コード例 #3
0
        // Gets the existing user object if there is one and login the user, otherwise return error to client
        public void LoginClient(Client client, string name, string password)
        {
            if (client == null)
            {
                return;
            }

            ExtendetClient extendetClient = _clientHandler.GetExtendetClient(client);

            AuthResponse authResponse = new AuthResponse();

            if (extendetClient.Properties.Name == null)
            {
                authResponse.Success = false;
                authResponse.Error.Add("Username not found!");
            }
            else if (!_api.verifyPasswordHashBCrypt(password, extendetClient.Properties.PasswordHash))
            {
                authResponse.Success = false;
                authResponse.Error.Add("The entered password is incorrect!");
            }
            else
            {
                authResponse.Success = true;

                extendetClient.Properties.SocialClubName = client.socialClubName;
                extendetClient.Properties.HwId           = client.uniqueHardwareId;
                extendetClient.Properties.LastLogin      = DateTime.Now;

                extendetClient.Spawn();
                _clientHandler.UnRestrict(extendetClient: extendetClient);
            }

            _eventHandler.InvokeClientEvent(client, "AuthResponse",
                                            JsonConvert.SerializeObject(authResponse));
        }