コード例 #1
0
ファイル: ScenePresence.cs プロジェクト: kf6kjg/halcyon
        // This function updates AbsolutePosition (m_pos) even during transit
        // Call this version if you already have m_posInfo locked!
        // You must either supply the parcel at agentPos, supply a non-null parent, or call the other variant without a parcel and WITHOUT m_posInfo locked.
        public void SetAgentPositionInfo(ILandObject parcel, bool forced, Vector3 agentPos, SceneObjectPart parent, Vector3 parentPos, Vector3 velocity)
        {
            Vector3 pos;
            Vector3 oldVelocity;

            lock (m_posInfo)
            {
                if ((!forced) && (IsInTransit) && (parent != m_posInfo.Parent))
                    return;

                if (parent == null)
                {
                    // not seated
                    if (parcel != null)
                    {
                        ParcelPropertiesStatus reason;
                        if (agentPos.Z < Scene.LandChannel.GetBanHeight() && parcel.DenyParcelAccess(this.UUID, out reason))
                        {
                            if (!forced)
                                return; // illegal position
                        }
                        else
                            lastKnownAllowedPosition = agentPos;
                    }
                }

                m_posInfo.Set(agentPos, parent, parentPos);
                oldVelocity = m_velocity;
                m_velocity = velocity;
                ForceAgentPositionInRegion();
                pos = m_posInfo.Position;
            }

            var pa = PhysicsActor;
            if (pa != null)
            {
                if (velocity != oldVelocity)
                    pa.Velocity = velocity;
                pa.Position = pos;
            }
        }
コード例 #2
0
ファイル: BotManager.cs プロジェクト: digitalmystic/halcyon
        public UUID CreateBot(string firstName, string lastName, Vector3 startPos, string outfitName, UUID itemID, UUID owner, out string reason)
        {
            try
            {
                UserProfileData userCheckData = m_scene.CommsManager.UserService.GetUserProfile(firstName, lastName);
                if (userCheckData != null)
                {
                    reason = "Invalid name: This name has already been taken.";
                    return(UUID.Zero);//You cannot use the same name as another user.
                }
                if (lastName.ToLower().Contains("inworldz") || firstName.ToLower().Contains("inworldz"))
                {
                    reason = "Invalid name: This name has already been taken.";
                    return(UUID.Zero);//You cannot put inworldz in the name
                }
                var regex = new Regex(@"\s");
                if (regex.IsMatch(firstName) || regex.IsMatch(lastName))
                {
                    reason = "Invalid name: The name cannot contain whitespace.";
                    return(UUID.Zero);
                }

                lock (m_bots)
                {
                    if (m_bots.Count + 1 > m_maxNumberOfBots)
                    {
                        reason = "The maximum number of bots has been reached.";
                        return(UUID.Zero);
                    }
                }
                if (!m_scene.Permissions.CanRezObject(0, owner, UUID.Zero, startPos, false))
                {
                    //Cannot create bot on a parcel that does not allow for rezzing an object
                    reason = "You do not have permissions to create a bot on this parcel.";
                    return(UUID.Zero);
                }

                ILandObject            parcel = m_scene.LandChannel.GetLandObject(startPos.X, startPos.Y);
                ParcelPropertiesStatus status;
                if (parcel.DenyParcelAccess(owner, out status))
                {
                    reason = "You do not have permissions to create a bot on this parcel.";
                    return(UUID.Zero);
                }

                AvatarAppearance appearance;
                UUID             originalOwner = UUID.Zero;
                string           ownerName     = "";
                bool             isSavedOutfit = !string.IsNullOrEmpty(outfitName);

                if (!isSavedOutfit)
                {
                    ScenePresence ownerSP = m_scene.GetScenePresence(owner);
                    if (ownerSP == null)
                    {
                        appearance = m_scene.CommsManager.AvatarService.GetUserAppearance(owner);
                        if (appearance == null)
                        {
                            reason = "No appearance could be found for the owner.";
                            return(UUID.Zero);
                        }
                        ownerName = m_scene.CommsManager.UserService.Key2Name(owner, false);
                        if (ownerName == String.Empty)
                        {
                            reason = "Owner could not be found.";
                            return(UUID.Zero);
                        }
                    }
                    else
                    {
                        //Do checks here to see whether the appearance can be saved
                        if (!CheckAppearanceForAttachmentCount(ownerSP))
                        {
                            reason = "The outfit has too many attachments and cannot be used.";
                            return(UUID.Zero);
                        }

                        appearance = new AvatarAppearance(ownerSP.Appearance);
                        ownerName  = ownerSP.Name;
                    }
                }
                else
                {
                    appearance = m_scene.CommsManager.AvatarService.GetBotOutfit(owner, outfitName);
                    if (appearance == null)
                    {
                        reason = "No such outfit could be found.";
                        return(UUID.Zero);
                    }
                    ownerName = m_scene.CommsManager.UserService.Key2Name(owner, false);
                    if (ownerName == String.Empty)
                    {
                        reason = "Owner could not be found.";
                        return(UUID.Zero);
                    }
                }

                if (!CheckAttachmentCount(appearance, parcel, appearance.Owner, out reason))
                {
                    //Too many objects already on this parcel/region
                    return(UUID.Zero);
                }


                BotClient client = new BotClient(firstName, lastName, m_scene, startPos, owner);

                originalOwner              = appearance.Owner;
                appearance.Owner           = client.AgentID;
                appearance.IsBotAppearance = true;
                string defaultAbout = "I am a 'bot' (a scripted avatar), owned by " + ownerName + ".";

                AgentCircuitData data = new AgentCircuitData()
                {
                    AgentID         = client.AgentId,
                    Appearance      = appearance,
                    BaseFolder      = UUID.Zero,
                    child           = false,
                    CircuitCode     = client.CircuitCode,
                    ClientVersion   = "",
                    FirstName       = client.FirstName,
                    InventoryFolder = UUID.Zero,
                    LastName        = client.LastName,
                    SecureSessionID = client.SecureSessionId,
                    SessionID       = client.SessionId,
                    startpos        = startPos
                };

                m_scene.ConnectionManager.NewConnection(data, Region.Framework.Connection.EstablishedBy.Login);
                m_scene.AddNewClient(client);
                m_scene.ConnectionManager.TryAttachUdpCircuit(client);

                ScenePresence sp;
                if (m_scene.TryGetAvatar(client.AgentId, out sp))
                {
                    sp.IsBot   = true;
                    sp.OwnerID = owner;

                    m_scene.CommsManager.UserService.AddTemporaryUserProfile(new UserProfileData()
                    {
                        AboutText          = defaultAbout,
                        Created            = Util.ToUnixTime(client.TimeCreated),
                        CustomType         = "Bot",
                        Email              = "",
                        FirstLifeAboutText = defaultAbout,
                        FirstLifeImage     = UUID.Zero,
                        FirstName          = client.FirstName,
                        GodLevel           = 0,
                        ID         = client.AgentID,
                        Image      = UUID.Zero,
                        ProfileURL = "",
                        SurName    = client.LastName,
                    });

                    sp.CompleteMovement();

                    new Thread(() =>
                    {
                        InitialAttachmentRez(sp, appearance.GetAttachments(), originalOwner, isSavedOutfit);
                    }).Start();

                    lock (m_bots)
                        m_bots.Add(client.AgentId, client);
                    BotRegisterForPathUpdateEvents(client.AgentID, itemID, owner);

                    reason = null;
                    return(client.AgentId);
                }
                reason = "Something went wrong.";
            }
            catch (Exception ex)
            {
                reason = "Something went wrong: " + ex.ToString();
            }
            return(UUID.Zero);
        }