Example #1
0
        public override void SendRexObjectProperties(UUID id, RexObjectProperties x)
        {
            GenericMessagePacket gmp = new GenericMessagePacket();
            gmp.MethodData.Method = Utils.StringToBytes("RexPrimData");

            byte[] temprexprimdata = x.GetRexPrimDataToBytes(true); //send urls to ng-clients
            int numlines = 0;
            int i = 0;

            if (temprexprimdata != null)
            {
                while (i <= temprexprimdata.Length)
                {
                    numlines++;
                    i += 200;
                }
            }

            gmp.ParamList = new GenericMessagePacket.ParamListBlock[1 + numlines];
            gmp.ParamList[0] = new GenericMessagePacket.ParamListBlock();
            gmp.ParamList[0].Parameter = Utils.StringToBytes(id.ToString());

            for (i = 0; i < numlines; i++)
            {
                gmp.ParamList[i + 1] = new GenericMessagePacket.ParamListBlock();

                if ((temprexprimdata.Length - i * 200) < 200)
                {
                    gmp.ParamList[i + 1].Parameter = new byte[temprexprimdata.Length - i * 200];
                    Buffer.BlockCopy(temprexprimdata, i * 200, gmp.ParamList[i + 1].Parameter, 0, temprexprimdata.Length - i * 200);
                }
                else
                {
                    gmp.ParamList[i + 1].Parameter = new byte[200];
                    Buffer.BlockCopy(temprexprimdata, i * 200, gmp.ParamList[i + 1].Parameter, 0, 200);
                }
            }

            OutPacket(gmp, ThrottleOutPacketType.Task);
        }
Example #2
0
        public void SetRexPrimDataFromObject(RexObjectProperties source)
        {
            try
            {
                mProcessingPacketData = true;
                RexDrawType = source.RexDrawType;
                RexIsVisible = source.RexIsVisible;
                RexCastShadows = source.RexCastShadows;
                RexLightCreatesShadows = source.RexLightCreatesShadows;
                RexDescriptionTexture = source.RexDescriptionTexture;
                RexScaleToPrim = source.RexScaleToPrim;
                RexDrawDistance = source.RexDrawDistance;
                RexLOD = source.RexLOD;
                RexMeshUUID = source.RexMeshUUID;
                RexCollisionMeshUUID = source.RexCollisionMeshUUID;
                RexParticleScriptUUID = source.RexParticleScriptUUID;
                RexAnimationPackageUUID = source.RexAnimationPackageUUID;
                RexAnimationName = source.RexAnimationName;
                RexAnimationRate = source.RexAnimationRate;
                RexMaterials.ClearMaterials();
                RexMaterials = (RexMaterialsDictionary)source.RexMaterials.Clone();
                RexClassName = source.RexClassName;
                RexSoundUUID = source.RexSoundUUID;
                RexSoundVolume = source.RexSoundVolume;
                RexSoundRadius = source.RexSoundRadius;
                RexSelectPriority = source.RexSelectPriority;
                mProcessingPacketData = false;
                m_rexAnimationPackageURL = source.RexAnimationPackageURI;
                m_rexCollisionMeshURL = source.RexCollisionMeshURI;
                m_rexMeshURL = source.RexMeshURI;
                m_rexParticleScriptURL = source.RexParticleScriptURI;
                m_rexSoundURL = source.RexSoundURI;

                TriggerChangedRexObjectProperties();
            }
            catch (Exception e)
            {
                mProcessingPacketData = false;
                m_log.Error(e.ToString());
            }
        }
Example #3
0
        protected bool ConvertLegacyRexDataToModreX()
        {
            NHibernateRexLegacyData legacydata = new NHibernateRexLegacyData();

            //convert connnection string to NHibernate style
            //parse string like this: "URI=file:OpenSim.db,version=3"
            //and convert it to like this: "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"
            string arg1 = String.Empty;
            string arg2 = String.Empty;

            string[] components = m_connectionString.Split(',');
            if (components[0].StartsWith("URI=file:"))
            {
                arg1 = components[0].Substring(9);
            }
            else
            {
                m_log.ErrorFormat("[MODREXOBJECTS]: Error parseing connection string {0}", m_connectionString);
                return false;
            }
            if (components[1].StartsWith("version="))
            {
                arg2 = components[1].Substring(8);
            }
            else
            {
                m_log.ErrorFormat("[MODREXOBJECTS]: Error parseing connection string {0}", m_connectionString);
                return false;
            }

            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("SQLiteDialect;SQLite20Driver;Data Source={0};Version={1}", arg1, arg2);

            legacydata.Initialise(sb.ToString());
            if (!legacydata.Inizialized)
            {
                m_log.Info("[MODREXOBJECTS]: Legacy database failed to initialize.");
                return false;
            }

            List<RexLegacyPrimData> rexprimdata = legacydata.LoadAllRexPrimData();
            m_log.Info("[MODREXOBJECTS]: Legacy rexprimdata objects loaded:" + rexprimdata.Count.ToString());

            List<RexLegacyPrimMaterialData> rexprimmaterialdata = legacydata.LoadAllRexPrimMaterialData();
            m_log.Info("[MODREXOBJECTS]: Legacy rexprimmaterialdata objects loaded:" + rexprimmaterialdata.Count.ToString());

            Dictionary<UUID, RexObjectProperties> rexObjects = new Dictionary<UUID, RexObjectProperties>();

            foreach (RexLegacyPrimData prim in rexprimdata)
            {
                RexObjectProperties p = new RexObjectProperties();
                p.SetRexPrimDataFromLegacyData(prim);
                rexObjects.Add(prim.UUID, p);
            }

            foreach (RexLegacyPrimMaterialData primmat in rexprimmaterialdata)
            {
                if (rexObjects.ContainsKey(primmat.UUID) && rexObjects[primmat.UUID] != null)
                {
                    rexObjects[primmat.UUID].RexMaterials.AddMaterial((uint)primmat.MaterialIndex, primmat.MaterialUUID);
                }
                else
                {
                    m_log.WarnFormat("[MODREXOBJECTS]: Could not find RexObjectData for prim {0} while adding materials. Creating", primmat.UUID);
                    RexObjectProperties p = new RexObjectProperties();
                    p.ParentObjectID = primmat.UUID;
                    p.RexMaterials.AddMaterial((uint)primmat.MaterialIndex, primmat.MaterialUUID);
                    rexObjects.Add(primmat.UUID, p);
                }
            }

            //Add rex object to database
            NHibernateRexObjectData rexObjectManager = new NHibernateRexObjectData();
            rexObjectManager.Initialise(m_rexConnectionString);
            foreach (KeyValuePair<UUID, RexObjectProperties> data in rexObjects)
            {
                rexObjectManager.StoreObject(data.Value);
            }

            return true;
        }
        private void SaveOrUpdate(RexObjectProperties p)
        {
            try
            {
                IList<RexMaterialsDictionaryItem> templist = p.RexMaterialDictionaryItems;
                if (p.RexMaterialDictionaryItems == null)
                {
                    p.RexMaterialDictionaryItems = new List<RexMaterialsDictionaryItem>();
                }
                int i;
                ISession session = manager.GetSession();
                ICriteria criteria = session.CreateCriteria(typeof(RexObjectProperties)).Add(Restrictions.Eq("ParentObjectID", p.ParentObjectID)).SetProjection(Projections.Count("ParentObjectID"));
                if (session == null || criteria == null)
                {
                    i = 0;
                }
                else
                {
                    object tmp = criteria.UniqueResult(); //Q: how many objcts with same id
                    if (tmp is int && tmp != null)
                    {
                        i = (int)tmp;
                    }
                    else
                    {
                        i = 0;
                    }
                }
                session.Close();
                if (i != 0) //A: more than zero, update instead of insert
                {
                    m_log.DebugFormat("[NHIBERNATE] updating RexObjectProperties {0}", p.ParentObjectID);
                    manager.Update(p);
                }
                else //B: zero, insert
                {
                    m_log.DebugFormat("[NHIBERNATE] saving RexObjectProperties {0}", p.ParentObjectID);
                    p.RexMaterialDictionaryItems = new List<RexMaterialsDictionaryItem>();
                    manager.Insert(p);
                }

                //Process materials after inserting/updateing other data. New items have material if they are copied!
                if (templist != null && templist.Count > 0)
                {
                    ProcessMaterials(p, templist);
                }
            }
            catch (Exception e)
            {
                m_log.Error("[NHIBERNATE] issue saving RexObjectProperties: "+ e.Message + e.Source + e.StackTrace);
            }
        }
        private void ProcessMaterials(RexObjectProperties p, IList<RexMaterialsDictionaryItem> rexMaterials)
        {
            try
            {
                foreach (RexMaterialsDictionaryItem item in rexMaterials)
                {
                    if (item.ID == 0)
                    {
                        ISession session = manager.GetSession();
                        ICriteria criteria2 = session.CreateCriteria(typeof(RexMaterialsDictionaryItem));
                        criteria2.Add(Restrictions.Eq("RexObjectUUID", p.ParentObjectID));
                        criteria2.Add(Restrictions.Eq("Num", item.Num));
                        criteria2.SetMaxResults(1);
                        List<RexMaterialsDictionaryItem> list = (List<RexMaterialsDictionaryItem>)criteria2.List<RexMaterialsDictionaryItem>();
                        session.Close();
                        if (list.Count == 0)
                        {
                            item.RexObjectUUID = p.ParentObjectID;
                            manager.Insert(item);
                        }
                        else
                        {
                            list[0].AssetID = item.AssetID;
                            list[0].AssetURI = item.AssetURI;
                            manager.Update(list[0]);
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                m_log.Error("[NHibernate]: Exception was thrown while processing RexObjectMaterials" + ex);
            }
        }
 /// <summary>
 /// Adds an object into region storage
 /// </summary>
 /// <param name="obj">the object</param>
 /// <param name="regionUUID">the region UUID</param>
 public void StoreObject(RexObjectProperties obj)
 {
     try
     {
         SaveOrUpdate(obj);
     }
     catch (Exception e)
     {
         m_log.Error("Can't save: ", e);
     }
 }