Ejemplo n.º 1
0
        private byte[] HomeLocation(Stream request, UUID agentID)
        {
            OSDMap rm           = (OSDMap)OSDParser.DeserializeLLSDXml(request);
            OSDMap HomeLocation = rm["HomeLocation"] as OSDMap;

            if (HomeLocation != null)
            {
                OSDMap  pos      = HomeLocation["LocationPos"] as OSDMap;
                Vector3 position = new Vector3((float)pos["X"].AsReal(),
                                               (float)pos["Y"].AsReal(),
                                               (float)pos["Z"].AsReal());
                OSDMap  lookat = HomeLocation["LocationLookAt"] as OSDMap;
                Vector3 lookAt = new Vector3((float)lookat["X"].AsReal(),
                                             (float)lookat["Y"].AsReal(),
                                             (float)lookat["Z"].AsReal());
                //int locationID = HomeLocation["LocationId"].AsInteger();

                m_agentInfoService.SetHomePosition(agentID.ToString(), m_service.Region.RegionID, position, lookAt);
            }

            rm.Add("success", OSD.FromBoolean(true));
            return(OSDParser.SerializeLLSDXmlBytes(rm));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="regionHandle"></param>
        /// <param name="position"></param>
        /// <param name="lookAt"></param>
        /// <param name="flags"></param>
        public void SetHomeRezPoint(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
        {
            Scene scene = (Scene)remoteClient.Scene;

            if (scene == null)
            {
                return;
            }

            IScenePresence SP     = scene.GetScenePresence(remoteClient.AgentId);
            IDialogModule  module = scene.RequestModuleInterface <IDialogModule>();

            if (SP != null)
            {
                if (scene.Permissions.CanSetHome(SP.UUID))
                {
                    IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule> ();
                    position.Z += appearance.Appearance.AvatarHeight / 2;
                    IAgentInfoService agentInfoService = scene.RequestModuleInterface <IAgentInfoService>();
                    if (agentInfoService != null &&
                        agentInfoService.SetHomePosition(remoteClient.AgentId.ToString(), scene.RegionInfo.RegionID, position, lookAt) &&
                        module != null) //Do this last so it doesn't screw up the rest
                    {
                        // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
                        module.SendAlertToUser(remoteClient, "Home position set.");
                    }
                    else if (module != null)
                    {
                        module.SendAlertToUser(remoteClient, "Set Home request failed.");
                    }
                }
                else if (module != null)
                {
                    module.SendAlertToUser(remoteClient, "Set Home request failed: Permissions do not allow the setting of home here.");
                }
            }
        }
Ejemplo n.º 3
0
        OSDMap CreateAccount(OSDMap map)
        {
            bool   Verified = false;
            string Name     = map ["Name"].AsString();

            string Password = "";

            if (map.ContainsKey("Password"))
            {
                Password = map ["Password"].AsString();
            }
            else
            {
                Password = map ["PasswordHash"].AsString();  //is really plaintext password, the system hashes it later. Not sure why it was called PasswordHash to start with. I guess the original design was to have the PHP code generate the salt and password hash, then just simply store it here
            }

            //string PasswordSalt = map["PasswordSalt"].AsString(); //not being used
            string HomeRegion    = map ["HomeRegion"].AsString();
            string Email         = map ["Email"].AsString();
            string AvatarArchive = map ["AvatarArchive"].AsString();
            int    userLevel     = map ["UserLevel"].AsInteger();
            string UserTitle     = map ["UserTitle"].AsString();

            //server expects: 0 is PG, 1 is Mature, 2 is Adult - use this when setting MaxMaturity and MaturityRating
            //viewer expects: 13 is PG, 21 is Mature, 42 is Adult

            int MaxMaturity = 2;                //set to adult by default

            if (map.ContainsKey("MaxMaturity")) //MaxMaturity is the highest level that they can change the maturity rating to in the viewer
            {
                MaxMaturity = map ["MaxMaturity"].AsInteger();
            }

            int MaturityRating = MaxMaturity;      //set the default to whatever MaxMaturity was set tom incase they didn't define MaturityRating

            if (map.ContainsKey("MaturityRating")) //MaturityRating is the rating the user wants to be able to see
            {
                MaturityRating = map ["MaturityRating"].AsInteger();
            }

            bool activationRequired = map.ContainsKey("ActivationRequired") ? map ["ActivationRequired"].AsBoolean() : false;

            IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService> ();

            if (accountService == null)
            {
                return(null);
            }

            if (!Password.StartsWith("$1$", System.StringComparison.Ordinal))
            {
                Password = "******" + Util.Md5Hash(Password);
            }
            Password = Password.Remove(0, 3);  //remove $1$

            accountService.CreateUser(Name, Password, Email);
            UserAccount       user             = accountService.GetUserAccount(null, Name);
            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService> ();
            IGridService      gridService      = m_registry.RequestModuleInterface <IGridService> ();

            if (agentInfoService != null && gridService != null)
            {
                GridRegion r = gridService.GetRegionByName(null, HomeRegion);
                if (r != null)
                {
                    agentInfoService.SetHomePosition(user.PrincipalID.ToString(), r.RegionID, new Vector3(r.RegionSizeX / 2, r.RegionSizeY / 2, 20), Vector3.Zero);
                }
                else
                {
                    MainConsole.Instance.DebugFormat("[API]: Could not set home position for user {0}, region \"{1}\" did not produce a result from the grid service", Name, HomeRegion);
                }
            }

            Verified = user != null;
            UUID userID = UUID.Zero;

            OSDMap resp = new OSDMap();

            resp ["Verified"] = OSD.FromBoolean(Verified);

            if (Verified)
            {
                userID         = user.PrincipalID;
                user.UserLevel = userLevel;

                // could not find a way to save this data here.
                DateTime RLDOB     = map ["RLDOB"].AsDate();
                string   RLGender  = map ["RLGender"].AsString();
                string   RLName    = map ["RLName"].AsString();
                string   RLAddress = map ["RLAddress"].AsString();
                string   RLCity    = map ["RLCity"].AsString();
                string   RLZip     = map ["RLZip"].AsString();
                string   RLCountry = map ["RLCountry"].AsString();
                string   RLIP      = map ["RLIP"].AsString();



                IAgentConnector con = DataPlugins.RequestPlugin <IAgentConnector> ();
                con.CreateNewAgent(userID);

                IAgentInfo agent = con.GetAgent(userID);

                agent.MaxMaturity    = MaxMaturity;
                agent.MaturityRating = MaturityRating;

                agent.OtherAgentInformation ["RLDOB"]     = RLDOB;
                agent.OtherAgentInformation ["RLGender"]  = RLGender;
                agent.OtherAgentInformation ["RLName"]    = RLName;
                agent.OtherAgentInformation ["RLAddress"] = RLAddress;
                agent.OtherAgentInformation ["RLCity"]    = RLCity;
                agent.OtherAgentInformation ["RLZip"]     = RLZip;
                agent.OtherAgentInformation ["RLCountry"] = RLCountry;
                agent.OtherAgentInformation ["RLIP"]      = RLIP;
                if (activationRequired)
                {
                    UUID activationToken = UUID.Random();
                    agent.OtherAgentInformation ["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + Password);
                    resp ["WebUIActivationToken"] = activationToken;
                }
                con.UpdateAgent(agent);

                accountService.StoreUserAccount(user);

                IProfileConnector profileData = DataPlugins.RequestPlugin <IProfileConnector> ();
                IUserProfileInfo  profile     = profileData.GetUserProfile(user.PrincipalID);
                if (profile == null)
                {
                    profileData.CreateNewProfile(user.PrincipalID);
                    profile = profileData.GetUserProfile(user.PrincipalID);
                }
                if (AvatarArchive.Length > 0)
                {
                    profile.AArchiveName = AvatarArchive;
                }
                //    MainConsole.Instance.InfoFormat("[WebUI] Triggered Archive load of " + profile.AArchiveName);
                profile.IsNewUser = true;

                profile.MembershipGroup = UserTitle;
                profile.CustomType      = UserTitle;

                profileData.UpdateUserProfile(profile);
                //   MainConsole.Instance.RunCommand("load avatar archive " + user.FirstName + " " + user.LastName + " Devil");
            }

            resp ["UUID"] = OSD.FromUUID(userID);
            return(resp);
        }
Ejemplo n.º 4
0
        public Dictionary <string, object> Fill(WebInterface webInterface, string filename, OSHttpRequest httpRequest,
                                                OSHttpResponse httpResponse, Dictionary <string, object> requestParameters,
                                                ITranslator translator, out string response)
        {
            response = null;
            var vars     = new Dictionary <string, object>();
            var settings = webInterface.GetWebUISettings();

            bool adminUser         = Authenticator.CheckAdminAuthentication(httpRequest, Constants.USER_GOD_CUSTOMER_SERVICE);
            bool allowRegistration = settings.WebRegistration;
            bool anonymousLogins;

            // allow configuration to override the web settings
            IConfig config = webInterface.Registry.RequestModuleInterface <ISimulationBase>().ConfigSource.Configs ["LoginService"];

            if (config != null)
            {
                anonymousLogins   = config.GetBoolean("AllowAnonymousLogin", allowRegistration);
                allowRegistration = (allowRegistration || anonymousLogins);
            }

            if (!adminUser && !allowRegistration)
            {
                vars.Add("ErrorMessage", "");
                vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
                vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
                vars.Add("Registrations", false);
                vars.Add("NoRegistrations", true);
                return(vars);
            }

            if (requestParameters.ContainsKey("Submit"))
            {
                string AvatarName          = requestParameters["AvatarName"].ToString();
                string AvatarPassword      = requestParameters["AvatarPassword"].ToString();
                string AvatarPasswordCheck = requestParameters["AvatarPassword2"].ToString();
                string FirstName           = requestParameters["FirstName"].ToString();
                string LastName            = requestParameters["LastName"].ToString();
                //removed - greythane - deemed not used
                //string UserAddress = requestParameters["UserAddress"].ToString();
                //string UserZip = requestParameters["UserZip"].ToString();
                string UserCity       = requestParameters["UserCity"].ToString();
                string UserEmail      = requestParameters["UserEmail"].ToString();
                string UserHomeRegion = requestParameters["UserHomeRegion"].ToString();
                string UserDOBMonth   = requestParameters["UserDOBMonth"].ToString();
                string UserDOBDay     = requestParameters["UserDOBDay"].ToString();
                string UserDOBYear    = requestParameters["UserDOBYear"].ToString();
                string AvatarArchive  = requestParameters.ContainsKey("AvatarArchive")
                                           ? requestParameters["AvatarArchive"].ToString()
                                           : "";
                bool ToSAccept = requestParameters.ContainsKey("ToSAccept") &&
                                 requestParameters["ToSAccept"].ToString() == "Accepted";

                string UserType = requestParameters.ContainsKey("UserType")         // only admins can set membership
                    ? requestParameters ["UserType"].ToString()
                    : "Resident";

                // revise UserDOBMonth to a number
                UserDOBMonth = ShortMonthToNumber(UserDOBMonth);

                // revise Type flags
                int UserFlags = webInterface.UserTypeToUserFlags(UserType);

                // a bit of idiot proofing
                if (AvatarName == "")
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarNameError") + "</h3>";
                    return(null);
                }
                if ((AvatarPassword == "") || (AvatarPassword != AvatarPasswordCheck))
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarPasswordError") + "</h3>";
                    return(null);
                }
                if (UserEmail == "")
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarEmailError") + "</h3>";
                    return(null);
                }

                // Thish -  Only one space is allowed in the name to seperate First and Last of the avatar name
                if (AvatarName.Split(' ').Length != 2)
                {
                    response = "<h3>" + translator.GetTranslatedString("AvatarNameSpacingError") + "</h3>";
                    return(null);
                }

                // so far so good...
                if (ToSAccept)
                {
                    AvatarPassword = Util.Md5Hash(AvatarPassword);

                    IUserAccountService accountService =
                        webInterface.Registry.RequestModuleInterface <IUserAccountService>();
                    UUID   userID = UUID.Random();
                    string error  = accountService.CreateUser(userID, settings.DefaultScopeID, AvatarName, AvatarPassword,
                                                              UserEmail);
                    if (error == "")
                    {
                        // set the user account type
                        UserAccount account = accountService.GetUserAccount(null, userID);
                        account.UserFlags = UserFlags;
                        accountService.StoreUserAccount(account);

                        // create and save agent info
                        IAgentConnector con = Framework.Utilities.DataManager.RequestPlugin <IAgentConnector> ();
                        con.CreateNewAgent(userID);
                        IAgentInfo agent = con.GetAgent(userID);
                        agent.OtherAgentInformation ["RLFirstName"] = FirstName;
                        agent.OtherAgentInformation ["RLLastName"]  = LastName;
                        //agent.OtherAgentInformation ["RLAddress"] = UserAddress;
                        agent.OtherAgentInformation ["RLCity"] = UserCity;
                        //agent.OtherAgentInformation ["RLZip"] = UserZip;
                        agent.OtherAgentInformation ["UserDOBMonth"] = UserDOBMonth;
                        agent.OtherAgentInformation ["UserDOBDay"]   = UserDOBDay;
                        agent.OtherAgentInformation ["UserDOBYear"]  = UserDOBYear;
                        agent.OtherAgentInformation ["UserFlags"]    = UserFlags;

                        /*if (activationRequired)
                         * {
                         *  UUID activationToken = UUID.Random();
                         *  agent.OtherAgentInformation["WebUIActivationToken"] = Util.Md5Hash(activationToken.ToString() + ":" + PasswordHash);
                         *  resp["WebUIActivationToken"] = activationToken;
                         * }*/
                        con.UpdateAgent(agent);

                        // create user profile details
                        IProfileConnector profileData =
                            Framework.Utilities.DataManager.RequestPlugin <IProfileConnector> ();
                        if (profileData != null)
                        {
                            IUserProfileInfo profile = profileData.GetUserProfile(userID);
                            if (profile == null)
                            {
                                profileData.CreateNewProfile(userID);
                                profile = profileData.GetUserProfile(userID);
                            }

                            if (AvatarArchive != "")
                            {
                                profile.AArchiveName = AvatarArchive;

                                List <AvatarArchive> avarchives = webInterface.Registry.RequestModuleInterface <IAvatarAppearanceArchiver>().GetAvatarArchives();
                                UUID snapshotUUID = UUID.Zero;
                                foreach (var archive in avarchives)
                                {
                                    if (archive.FolderName == AvatarArchive)
                                    {
                                        snapshotUUID = archive.Snapshot;
                                    }
                                }

                                if (snapshotUUID != UUID.Zero)
                                {
                                    profile.Image = snapshotUUID;
                                }
                            }
                            profile.MembershipGroup = webInterface.UserFlagToType(UserFlags, webInterface.EnglishTranslator);     // membership is english
                            profile.IsNewUser       = true;
                            profileData.UpdateUserProfile(profile);
                        }

                        IAgentInfoService agentInfoService = webInterface.Registry.RequestModuleInterface <IAgentInfoService> ();
                        Vector3           position         = new Vector3(128, 128, 25);
                        Vector3           lookAt           = new Vector3(0, 0, 22);

                        if (agentInfoService != null)
                        {
                            agentInfoService.SetHomePosition(userID.ToString(), (UUID)UserHomeRegion, position, lookAt);
                        }

                        vars.Add("ErrorMessage", "Successfully created account, redirecting to main page");
                        response = "<h3>Successfully created account, redirecting to main page</h3>" +
                                   "<script language=\"javascript\">" +
                                   "setTimeout(function() {window.location.href = \"index.html\";}, 3000);" +
                                   "</script>";
                    }
                    else
                    {
                        vars.Add("ErrorMessage", "<h3>" + error + "</h3>");
                        response = "<h3>" + error + "</h3>";
                    }
                }
                else
                {
                    response = "<h3>You did not accept the Terms of Service agreement.</h3>";
                }
                return(null);
            }

            List <Dictionary <string, object> > daysArgs = new List <Dictionary <string, object> >();

            for (int i = 1; i <= 31; i++)
            {
                daysArgs.Add(new Dictionary <string, object> {
                    { "Value", i }
                });
            }

            List <Dictionary <string, object> > monthsArgs = new List <Dictionary <string, object> >();

            //for (int i = 1; i <= 12; i++)
            //    monthsArgs.Add(new Dictionary<string, object> {{"Value", i}});

            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Jan_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Feb_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Mar_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Apr_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("May_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Jun_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Jul_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Aug_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Sep_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Oct_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Nov_Short") }
            });
            monthsArgs.Add(new Dictionary <string, object> {
                { "Value", translator.GetTranslatedString("Dec_Short") }
            });



            List <Dictionary <string, object> > yearsArgs = new List <Dictionary <string, object> >();

            for (int i = 1940; i <= 2013; i++)
            {
                yearsArgs.Add(new Dictionary <string, object> {
                    { "Value", i }
                });
            }

            vars.Add("Days", daysArgs);
            vars.Add("Months", monthsArgs);
            vars.Add("Years", yearsArgs);

            var sortBy = new Dictionary <string, bool>();

            sortBy.Add("RegionName", true);

            var RegionListVars = new List <Dictionary <string, object> >();
            var regions        = Framework.Utilities.DataManager.RequestPlugin <IRegionData>().Get((RegionFlags)0,
                                                                                                   RegionFlags.Hyperlink |
                                                                                                   RegionFlags.Foreign |
                                                                                                   RegionFlags.Hidden,
                                                                                                   null, null, sortBy);

            foreach (var region in regions)
            {
                RegionListVars.Add(new Dictionary <string, object> {
                    { "RegionName", region.RegionName },
                    { "RegionUUID", region.RegionID }
                });
            }

            vars.Add("RegionList", RegionListVars);
            vars.Add("UserHomeRegionText", translator.GetTranslatedString("UserHomeRegionText"));


            vars.Add("UserTypeText", translator.GetTranslatedString("UserTypeText"));
            vars.Add("UserType", webInterface.UserTypeArgs(translator));

            List <AvatarArchive> archives = webInterface.Registry.RequestModuleInterface <IAvatarAppearanceArchiver>().GetAvatarArchives();

            List <Dictionary <string, object> > avatarArchives = new List <Dictionary <string, object> >();
            IWebHttpTextureService webTextureService           = webInterface.Registry.
                                                                 RequestModuleInterface <IWebHttpTextureService>();

            foreach (var archive in archives)
            {
                avatarArchives.Add(new Dictionary <string, object>
                {
                    { "AvatarArchiveName", archive.FolderName },
                    { "AvatarArchiveSnapshotID", archive.Snapshot },
                    {
                        "AvatarArchiveSnapshotURL",
                        webTextureService.GetTextureURL(archive.Snapshot)
                    }
                });
            }

            vars.Add("AvatarArchive", avatarArchives);


            IConfig loginServerConfig =
                webInterface.Registry.RequestModuleInterface <ISimulationBase>().ConfigSource.Configs["LoginService"];
            string tosLocation = "";

            if (loginServerConfig != null && loginServerConfig.GetBoolean("UseTermsOfServiceOnFirstLogin", false))
            {
                tosLocation = loginServerConfig.GetString("FileNameOfTOS", "");
                tosLocation = PathHelpers.VerifyReadFile(tosLocation, ".txt", Constants.DEFAULT_DATA_DIR);
            }
            string ToS = "There are no Terms of Service currently. This may be changed at any point in the future.";

            if (tosLocation != "")
            {
                System.IO.StreamReader reader =
                    new System.IO.StreamReader(System.IO.Path.Combine(Environment.CurrentDirectory, tosLocation));
                ToS = reader.ReadToEnd();
                reader.Close();
            }

            // check for user name seed
            string[] m_userNameSeed = null;
            if (loginServerConfig != null)
            {
                string userNameSeed = loginServerConfig.GetString("UserNameSeed", "");
                if (userNameSeed != "")
                {
                    m_userNameSeed = userNameSeed.Split(',');
                }
            }

            Utilities.MarkovNameGenerator ufNames = new Utilities.MarkovNameGenerator();
            Utilities.MarkovNameGenerator ulNames = new Utilities.MarkovNameGenerator();
            string[] nameSeed = m_userNameSeed == null ? Utilities.UserNames : m_userNameSeed;

            string firstName   = ufNames.FirstName(nameSeed, 3, 4);
            string lastName    = ulNames.FirstName(nameSeed, 5, 6);
            string enteredName = firstName + " " + lastName;

            vars.Add("AvatarName", enteredName);
            vars.Add("ToSMessage", ToS);
            vars.Add("TermsOfServiceAccept", translator.GetTranslatedString("TermsOfServiceAccept"));
            vars.Add("TermsOfServiceText", translator.GetTranslatedString("TermsOfServiceText"));
            vars.Add("RegistrationsDisabled", "");
            //vars.Add("RegistrationsDisabled", translator.GetTranslatedString("RegistrationsDisabled"));
            vars.Add("RegistrationText", translator.GetTranslatedString("RegistrationText"));
            vars.Add("AvatarNameText", translator.GetTranslatedString("AvatarNameText"));
            vars.Add("AvatarPasswordText", translator.GetTranslatedString("Password"));
            vars.Add("AvatarPasswordConfirmationText", translator.GetTranslatedString("PasswordConfirmation"));
            vars.Add("AvatarScopeText", translator.GetTranslatedString("AvatarScopeText"));
            vars.Add("FirstNameText", translator.GetTranslatedString("FirstNameText"));
            vars.Add("LastNameText", translator.GetTranslatedString("LastNameText"));
            vars.Add("UserAddressText", translator.GetTranslatedString("UserAddressText"));
            vars.Add("UserZipText", translator.GetTranslatedString("UserZipText"));
            vars.Add("UserCityText", translator.GetTranslatedString("UserCityText"));
            vars.Add("UserCountryText", translator.GetTranslatedString("UserCountryText"));
            vars.Add("UserDOBText", translator.GetTranslatedString("UserDOBText"));
            vars.Add("UserEmailText", translator.GetTranslatedString("UserEmailText"));
            vars.Add("Accept", translator.GetTranslatedString("Accept"));
            vars.Add("Submit", translator.GetTranslatedString("Submit"));
            vars.Add("SubmitURL", "register.html");
            vars.Add("ErrorMessage", "");
            vars.Add("Registrations", true);
            vars.Add("NoRegistrations", false);

            return(vars);
        }
Ejemplo n.º 5
0
        public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason)
        {
            reason = string.Empty;

            string authURL = string.Empty;

            if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
            {
                authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
            }
            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2}",
                                            authURL, aCircuit.AgentID, destination.RegionName);

            //
            // Authenticate the user
            //
            if (!Authenticate(aCircuit))
            {
                reason = "Unable to verify identity";
                MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0}. Refusing service.", aCircuit.AgentID);
                return(false);
            }
            MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} @ {1}", aCircuit.AgentID, authURL);

            //
            // Check for impersonations
            //
            UserAccount account = null;

            if (m_UserAccountService != null)
            {
                // Check to see if we have a local user with that UUID
                account = m_UserAccountService.GetUserAccount(null, aCircuit.AgentID);
                if (account != null && m_userFinder.IsLocalGridUser(account.PrincipalID))
                {
                    // Make sure this is the user coming home, and not a foreign user with same UUID as a local user
                    if (m_UserAgentService != null)
                    {
                        if (!m_UserAgentService.AgentIsComingHome(aCircuit.SessionID, m_ExternalName))
                        {
                            // Can't do, sorry
                            reason = "Unauthorized";
                            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} has same ID as local user. Refusing service.",
                                                            aCircuit.AgentID);
                            return(false);
                        }
                    }
                }
            }
            MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: User is ok");

            // May want to authorize

            //bool isFirstLogin = false;
            //
            // Login the presence, if it's not there yet (by the login service)
            //
            UserInfo presence = m_PresenceService.GetUserInfo(aCircuit.AgentID.ToString());

            if (m_userFinder.IsLocalGridUser(aCircuit.AgentID) && presence != null && presence.IsOnline) // it has been placed there by the login service
            {
                //    isFirstLogin = true;
            }
            else
            {
                IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString());
                Vector3           position = Vector3.UnitY, lookAt = Vector3.UnitY;
                GridRegion        finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt);
                if (finalDestination == null)
                {
                    reason = "You do not have a home position set.";
                    return(false);
                }
                m_PresenceService.SetHomePosition(aCircuit.AgentID.ToString(), finalDestination.RegionID, position, lookAt);
                m_PresenceService.SetLoggedIn(aCircuit.AgentID.ToString(), true, true, destination.RegionID);
            }

            MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok");

            //
            // Get the region
            //
            destination = m_GridService.GetRegionByUUID(null, destination.RegionID);
            if (destination == null)
            {
                reason = "Destination region not found";
                return(false);
            }

            //
            // Adjust the visible name
            //
            if (account != null)
            {
                aCircuit.firstname = account.FirstName;
                aCircuit.lastname  = account.LastName;
            }
            if (account == null && !aCircuit.lastname.StartsWith("@"))
            {
                aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname;
                try
                {
                    Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
                    aCircuit.lastname = "@" + uri.Host; // + ":" + uri.Port;
                }
                catch
                {
                    MainConsole.Instance.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]);
                    aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString();
                }
                m_userFinder.AddUser(aCircuit.AgentID, aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs);
                m_UserAccountService.CacheAccount(new UserAccount(UUID.Zero, aCircuit.AgentID, aCircuit.firstname + aCircuit.lastname, "")
                {
                    UserFlags = 1024
                });
            }

retry:
            //
            // Finally launch the agent at the destination
            //
            TeleportFlags loginFlag = /*isFirstLogin ? */ TeleportFlags.ViaLogin /* : TeleportFlags.ViaHGLogin*/;
            IRegionClientCapsService regionClientCaps = null;

            if (m_CapsService != null)
            {
                //Remove any previous users
                string ServerCapsBase = Aurora.Framework.Capabilities.CapsUtil.GetRandomCapsObjectPath();
                m_CapsService.CreateCAPS(aCircuit.AgentID,
                                         Aurora.Framework.Capabilities.CapsUtil.GetCapsSeedPath(ServerCapsBase),
                                         destination.RegionHandle, true, aCircuit, 0);

                regionClientCaps = m_CapsService.GetClientCapsService(aCircuit.AgentID).GetCapsService(destination.RegionHandle);
                if (aCircuit.ServiceURLs == null)
                {
                    aCircuit.ServiceURLs = new Dictionary <string, object>();
                }
                aCircuit.ServiceURLs["IncomingCAPSHandler"] = regionClientCaps.CapsUrl;
            }
            aCircuit.child = false;//FIX THIS, OPENSIM ALWAYS SENDS CHILD!
            int  requestedUDPPort = 0;
            bool success          = m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, null, out requestedUDPPort, out reason);

            if (success)
            {
                if (regionClientCaps != null)
                {
                    if (requestedUDPPort == 0)
                    {
                        requestedUDPPort = destination.ExternalEndPoint.Port;
                    }
                    IPAddress ipAddress = destination.ExternalEndPoint.Address;
                    aCircuit.RegionUDPPort                     = requestedUDPPort;
                    regionClientCaps.LoopbackRegionIP          = ipAddress;
                    regionClientCaps.CircuitData.RegionUDPPort = requestedUDPPort;
                    OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason);
                    OSDMap SimSeedCaps = (OSDMap)responseMap["CapsUrls"];
                    regionClientCaps.AddCAPS(SimSeedCaps);
                }
            }
            else
            {
                if (m_CapsService != null)
                {
                    m_CapsService.RemoveCAPS(aCircuit.AgentID);
                }
                m_GridService.SetRegionUnsafe(destination.RegionID);
                if (!m_foundDefaultRegion)
                {
                    m_DefaultGatewayRegion = FindDefaultRegion();
                }
                if (destination != m_DefaultGatewayRegion)
                {
                    destination = m_DefaultGatewayRegion;
                    goto retry;
                }
                else
                {
                    m_DefaultGatewayRegion = FindDefaultRegion();
                    if (m_DefaultGatewayRegion == destination)
                    {
                        return(false);//It failed to find a new one
                    }
                    destination = m_DefaultGatewayRegion;
                    goto retry;//It found a new default region
                }
            }
            return(success);
        }
Ejemplo n.º 6
0
 public bool SetHomePosition(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt)
 {
     return(m_localService.SetHomePosition(userID, homeID, homePosition, homeLookAt));
 }
Ejemplo n.º 7
0
        private byte[] ProcessCreateAccount(OSDMap map)
        {
            bool   Verified     = false;
            string Name         = map["Name"].AsString();
            string PasswordHash = map["PasswordHash"].AsString();
            //string PasswordSalt = map["PasswordSalt"].AsString();
            string HomeRegion    = map["HomeRegion"].AsString();
            string Email         = map["Email"].AsString();
            string AvatarArchive = map["AvatarArchive"].AsString();



            IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService>();

            if (accountService == null)
            {
                return(null);
            }

            if (!PasswordHash.StartsWith("$1$"))
            {
                PasswordHash = "$1$" + Util.Md5Hash(PasswordHash);
            }
            PasswordHash = PasswordHash.Remove(0, 3); //remove $1$

            accountService.CreateUser(Name, PasswordHash, Email);
            UserAccount       user             = accountService.GetUserAccount(UUID.Zero, Name);
            IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService> ();
            IGridService      gridService      = m_registry.RequestModuleInterface <IGridService> ();

            if (agentInfoService != null && gridService != null)
            {
                GridRegion r = gridService.GetRegionByName(UUID.Zero, HomeRegion);
                agentInfoService.SetHomePosition(user.PrincipalID.ToString(), r.RegionID, new Vector3(r.RegionSizeX / 2, r.RegionSizeY / 2, 20), Vector3.Zero);
            }

            Verified = user != null;
            UUID userID = UUID.Zero;

            if (Verified)
            {
                // could not find a way to save this data here.

                /*DateTime RLDOB = map["RLDOB"].AsDate();
                 * string RLFirstName = map["RLFisrtName"].AsString();
                 * string RLLastName = map["RLLastName"].AsString();
                 * string RLAdress = map["RLAdress"].AsString();
                 * string RLCity = map["RLCity"].AsString();
                 * string RLZip = map["RLZip"].AsString();
                 * string RLCountry = map["RLCountry"].AsString();
                 * string RLIP = map["RLIP"].AsString();*/
                // could not find a way to save this data here.


                userID         = user.PrincipalID;
                user.UserLevel = -1;

                accountService.StoreUserAccount(user);

                IProfileConnector profileData = DataManager.RequestPlugin <IProfileConnector>();
                IUserProfileInfo  profile     = profileData.GetUserProfile(user.PrincipalID);
                if (profile == null)
                {
                    profileData.CreateNewProfile(user.PrincipalID);
                    profile = profileData.GetUserProfile(user.PrincipalID);
                }
                if (AvatarArchive.Length > 0)
                {
                    profile.AArchiveName = AvatarArchive + ".database";
                }

                profile.IsNewUser = true;
                profileData.UpdateUserProfile(profile);
            }

            OSDMap resp = new OSDMap();

            resp["Verified"] = OSD.FromBoolean(Verified);
            resp["UUID"]     = OSD.FromUUID(userID);
            string       xmlString = OSDParser.SerializeJsonString(resp);
            UTF8Encoding encoding  = new UTF8Encoding();

            return(encoding.GetBytes(xmlString));
        }
        /// <summary>
        /// Creates a user
        /// TODO: Does not implement the restrict to estate option
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        private OSD CreateUser(OSDMap map)
        {
            //Required params
            string username     = map["username"];
            int    last_name_id = map["last_name_id"];
            string email        = map["email"];
            string password     = map["password"];
            string dob          = map["dob"];

            //Optional params
            int    limited_to_estate = map["limited_to_estate"];
            string start_region_name = map["start_region_name"];
            float  start_local_x     = map["start_local_x"];
            float  start_local_y     = map["start_local_y"];
            float  start_local_z     = map["start_local_z"];
            float  start_look_at_x   = map["start_look_at_x"];
            float  start_look_at_y   = map["start_look_at_y"];
            float  start_look_at_z   = map["start_look_at_z"];
            OSD    resp = null;

            if (username != "" && last_name_id != 0 && email != "" &&
                password != "" && dob != "")
            {
                IUserAccountService accountService = m_registry.RequestModuleInterface <IUserAccountService>();
                if (m_lastNameRegistry.ContainsKey(last_name_id))
                {
                    string      lastName = m_lastNameRegistry[last_name_id];
                    UserAccount user     = accountService.GetUserAccount(null, username, lastName);
                    if (user == null)
                    {
                        //The pass is in plain text... so put it in and create the account
                        accountService.CreateUser(username + " " + lastName, password, email);
                        DateTime time = DateTime.ParseExact(dob, "YYYY-MM-DD", System.Globalization.CultureInfo.InvariantCulture);
                        user = accountService.GetUserAccount(null, username, lastName);
                        //Update the dob
                        user.Created = Util.ToUnixTime(time);
                        accountService.StoreUserAccount(user);

                        IAgentConnector agentConnector = Aurora.Framework.Utilities.DataManager.RequestPlugin <IAgentConnector>();
                        if (agentConnector != null)
                        {
                            agentConnector.CreateNewAgent(user.PrincipalID);
                            if (map.ContainsKey("limited_to_estate"))
                            {
                                IAgentInfo agentInfo = agentConnector.GetAgent(user.PrincipalID);
                                agentInfo.OtherAgentInformation["LimitedToEstate"] = limited_to_estate;
                                agentConnector.UpdateAgent(agentInfo);
                            }
                        }

                        MainConsole.Instance.Info("[RegApi]: Created new user " + user.Name);
                        try
                        {
                            if (start_region_name != "")
                            {
                                IAgentInfoService agentInfoService = m_registry.RequestModuleInterface <IAgentInfoService>();
                                if (agentInfoService != null)
                                {
                                    agentInfoService.SetHomePosition(user.PrincipalID.ToString(),
                                                                     m_registry.RequestModuleInterface <IGridService>().GetRegionByName
                                                                         (null, start_region_name).RegionID,
                                                                     new Vector3(start_local_x,
                                                                                 start_local_y,
                                                                                 start_local_z),
                                                                     new Vector3(start_look_at_x,
                                                                                 start_look_at_y,
                                                                                 start_look_at_z));
                                }
                            }
                        }
                        catch
                        {
                            MainConsole.Instance.Warn("[RegApi]: Encountered an error when setting the home position of a new user");
                        }
                        OSDMap r = new OSDMap();
                        r["agent_id"] = user.PrincipalID;
                        resp          = r;
                    }
                    else //Already exists
                    {
                        resp = false;
                    }
                }
                else //Could not find last name
                {
                    resp = false;
                }
            }
            else //Not enough params
            {
                resp = false;
            }

            return(resp);
        }