| 9 |
using OpenMetaverse; |
using OpenMetaverse; |
| 10 |
using OpenSim.Region.Framework.Interfaces; |
using OpenSim.Region.Framework.Interfaces; |
| 11 |
using OpenSim.Region.Framework.Scenes; |
using OpenSim.Region.Framework.Scenes; |
|
using OpenSim.Data.NHibernate; |
|
| 12 |
using OpenSim.Framework; |
using OpenSim.Framework; |
| 13 |
|
using ModularRex.NHibernate; |
| 14 |
|
using OpenSim.Framework.Communications.Cache; |
| 15 |
|
|
| 16 |
namespace ModularRex.RexParts |
namespace ModularRex.RexParts |
| 17 |
{ |
{ |
| 18 |
public class ModrexObjects : IRegionModule, IRexObjectPropertiesEventManager |
public class ModrexObjects : IRegionModule, IRexObjectPropertiesEventManager, IModrexObjectsProvider |
| 19 |
{ |
{ |
| 20 |
private static readonly ILog m_log = |
private static readonly ILog m_log = |
| 21 |
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 33 |
{ |
{ |
| 34 |
m_scenes.Add(scene); |
m_scenes.Add(scene); |
| 35 |
|
|
| 36 |
|
scene.RegisterModuleInterface<ModrexObjects>(this); |
| 37 |
|
scene.RegisterModuleInterface<IModrexObjectsProvider>(this); |
| 38 |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
| 39 |
scene.m_sceneGraph.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
scene.SceneContents.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
| 40 |
scene.m_sceneGraph.OnObjectRemove += SceneGraph_OnObjectRemove; |
scene.SceneContents.OnObjectRemove += SceneGraph_OnObjectRemove; |
| 41 |
|
|
| 42 |
|
scene.AddCommand(this, "modreximport", "load 0.4 rex database <connstring>", "conn string example: SQLiteDialect;SQLite20Driver;Data Source=beneath_the_waves.db;Version=3", HandleLoadRexLegacyData); |
| 43 |
|
|
| 44 |
if (m_db == null) |
if (m_db == null) |
| 45 |
{ |
{ |
| 67 |
|
|
| 68 |
void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
| 69 |
{ |
{ |
| 70 |
RexClientView rcv; |
RexClientViewBase rcv; |
| 71 |
if (client.TryGet(out rcv)) |
if (client.TryGet(out rcv)) |
| 72 |
{ |
{ |
| 73 |
rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; |
rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; |
| 74 |
|
rcv.OnPrimFreeData += rcv_OnPrimFreeData; |
| 75 |
//rcv.OnChatFromClient += rcv_OnChatFromClient; |
//rcv.OnChatFromClient += rcv_OnChatFromClient; |
| 76 |
|
|
| 77 |
// Send them the current Scene. |
// Send them the current Scene. |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
|
private void rcv_OnPrimFreeData(IClientAPI sender, List<string> parameters) |
| 83 |
|
{ |
| 84 |
|
m_log.Info("[REXOBJS] Received Prim free data"); |
| 85 |
|
if (parameters.Count >= 2) |
| 86 |
|
{ |
| 87 |
|
UUID primID = new UUID(parameters[0]); |
| 88 |
|
string data = String.Empty; |
| 89 |
|
if(parameters.Count == 2) |
| 90 |
|
{ |
| 91 |
|
data = parameters[1]; |
| 92 |
|
}else |
| 93 |
|
{ |
| 94 |
|
for (int i = 1; i < parameters.Count; i++) |
| 95 |
|
{ |
| 96 |
|
data += parameters[i]; |
| 97 |
|
} |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
RexObjectProperties props = GetObject(primID); |
| 101 |
|
props.RexData = data; |
| 102 |
|
|
| 103 |
|
SendPrimFreeDataToAllUsers(primID, data); |
| 104 |
|
} |
| 105 |
|
else |
| 106 |
|
{ |
| 107 |
|
m_log.Warn("[REXOBJS] unexpected number of parameters"); |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
void SendPrimFreeDataToAllUsers(UUID id, string data) |
| 112 |
|
{ |
| 113 |
|
foreach (Scene scene in m_scenes) |
| 114 |
|
{ |
| 115 |
|
scene.ForEachScenePresence( |
| 116 |
|
delegate(ScenePresence avatar) |
| 117 |
|
{ |
| 118 |
|
RexClientViewBase rex; |
| 119 |
|
if (avatar.ClientView.TryGet(out rex)) |
| 120 |
|
{ |
| 121 |
|
rex.SendRexPrimFreeData(id, data); |
| 122 |
|
} |
| 123 |
|
}); |
| 124 |
|
} |
| 125 |
|
} |
| 126 |
|
|
| 127 |
void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
| 128 |
{ |
{ |
| 129 |
RexObjectProperties origprops = GetObject(original.UUID); |
RexObjectProperties origprops = GetObject(original.UUID); |
| 160 |
scene.ForEachScenePresence( |
scene.ForEachScenePresence( |
| 161 |
delegate(ScenePresence avatar) |
delegate(ScenePresence avatar) |
| 162 |
{ |
{ |
| 163 |
RexClientView rex; |
RexClientViewBase rex; |
| 164 |
if (avatar.ClientView.TryGet(out rex)) |
if (avatar.ClientView.TryGet(out rex)) |
| 165 |
{ |
{ |
| 166 |
rex.SendRexObjectProperties(id,props); |
rex.SendRexObjectProperties(id,props); |
| 169 |
} |
} |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
void SendAllPropertiesToUser(RexClientView user) |
private void SendPreloadAssetsToUser(RexClientViewBase user) |
| 173 |
|
{ |
| 174 |
|
try |
| 175 |
|
{ |
| 176 |
|
Scene ourScene = null; |
| 177 |
|
foreach (Scene s in m_scenes) |
| 178 |
|
{ |
| 179 |
|
if (user.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle) |
| 180 |
|
ourScene = s; |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
if (ourScene != null) |
| 184 |
|
{ |
| 185 |
|
if (ourScene.Modules.ContainsKey("RexAssetPreload")) |
| 186 |
|
{ |
| 187 |
|
RexAssetPreload module = (RexAssetPreload)ourScene.Modules["RexAssetPreload"]; |
| 188 |
|
if (module.PreloadAssetDictionary.Count > 0) |
| 189 |
|
{ |
| 190 |
|
user.SendRexPreloadAssets(module.PreloadAssetDictionary); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
} |
| 194 |
|
} |
| 195 |
|
catch (Exception e) |
| 196 |
|
{ |
| 197 |
|
m_log.Error("[MODREXOBJECTS]: Sending preload assets failed.", e); |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
void SendAllPropertiesToUser(RexClientViewBase user) |
| 202 |
{ |
{ |
| 203 |
|
SendPreloadAssetsToUser(user); |
| 204 |
|
|
| 205 |
foreach (RexObjectProperties p in GetObjects()) |
foreach (RexObjectProperties p in GetObjects()) |
| 206 |
{ |
{ |
| 207 |
user.SendRexObjectProperties(p.ParentObjectID, p); |
user.SendRexObjectProperties(p.ParentObjectID, p); |
| 208 |
|
if (p.RexData.Length > 0) //send rex data also if exists |
| 209 |
|
{ |
| 210 |
|
user.SendRexPrimFreeData(p.ParentObjectID, p.RexData); |
| 211 |
|
} |
| 212 |
} |
} |
| 213 |
} |
} |
| 214 |
|
|
| 215 |
void rcv_OnRexObjectProperties(RexClientView sender, UUID id, RexObjectProperties props) |
void rcv_OnRexObjectProperties(IClientAPI sender, UUID id, RexObjectProperties props) |
| 216 |
{ |
{ |
| 217 |
m_log.Info("[REXOBJS] Received RexObjData for " + id); |
m_log.Info("[REXOBJS] Received RexObjData for " + id); |
| 218 |
if (props.ParentObjectID == UUID.Zero) |
if (props.ParentObjectID == UUID.Zero) |
| 267 |
// return; |
// return; |
| 268 |
|
|
| 269 |
RexObjectProperties p = GetObject(id); |
RexObjectProperties p = GetObject(id); |
| 270 |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
SceneObjectPart sop = null;// = m_scenes[0].GetSceneObjectPart(id); |
| 271 |
|
foreach (Scene scene in m_scenes) |
| 272 |
|
{ |
| 273 |
|
SceneObjectPart part = scene.GetSceneObjectPart(id); |
| 274 |
|
if (part != null) |
| 275 |
|
{ |
| 276 |
|
sop = part; |
| 277 |
|
break; |
| 278 |
|
} |
| 279 |
|
} |
| 280 |
|
|
| 281 |
if (sop == null) |
if (sop == null) |
| 282 |
{ |
{ |
| 283 |
m_log.Error("[REXOBJS] TriggerOnChangeCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
m_log.Error("[REXOBJS] TriggerOnChangeCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
| 318 |
{ |
{ |
| 319 |
RexObjectProperties props = GetObject(id); |
RexObjectProperties props = GetObject(id); |
| 320 |
|
|
| 321 |
m_db.StoreObject(props); |
//instead of saving right away, set timer to save after a sec. |
| 322 |
|
//m_db.StoreObject(props); |
| 323 |
SendPropertiesToAllUsers(id,props); |
SendPropertiesToAllUsers(id,props); |
| 324 |
|
props.ScheduleSave(); |
| 325 |
} |
} |
| 326 |
|
|
| 327 |
public void TriggerOnChangeRexObjectMetaData(UUID id) |
public void TriggerOnChangeRexObjectMetaData(UUID id) |
| 341 |
// return; |
// return; |
| 342 |
|
|
| 343 |
RexObjectProperties p = GetObject(id); |
RexObjectProperties p = GetObject(id); |
| 344 |
SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
SceneObjectPart sop = null;// m_scenes[0].GetSceneObjectPart(id); |
| 345 |
|
foreach (Scene s in m_scenes) |
| 346 |
|
{ |
| 347 |
|
SceneObjectPart part = s.GetSceneObjectPart(id); |
| 348 |
|
if (part != null) |
| 349 |
|
{ |
| 350 |
|
sop = part; |
| 351 |
|
break; |
| 352 |
|
} |
| 353 |
|
} |
| 354 |
|
|
| 355 |
if (sop == null) |
if (sop == null) |
| 356 |
{ |
{ |
| 357 |
m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
| 360 |
|
|
| 361 |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor is IRexPhysicsActor) |
if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor is IRexPhysicsActor) |
| 362 |
{ |
{ |
| 363 |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID, false); |
AssetBase tempmodel = sop.ParentGroup.Scene.AssetService.Get(p.RexCollisionMeshUUID.ToString()); |
| 364 |
if (tempmodel != null) |
if (tempmodel != null) |
| 365 |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(tempmodel.Data, tempmodel.Metadata.Name, p.RexScaleToPrim); |
((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(tempmodel.Data, tempmodel.Name, p.RexScaleToPrim); |
| 366 |
} |
} |
| 367 |
} |
} |
| 368 |
|
|
| 369 |
public byte GetAssetType(UUID assetid) |
public byte GetAssetType(UUID assetid) |
| 370 |
{ |
{ |
| 371 |
AssetBase tempmodel = m_scenes[0].AssetCache.GetAsset(assetid, true); |
AssetBase tempmodel = m_scenes[0].AssetService.Get(assetid.ToString()); |
| 372 |
if (tempmodel == null) |
if (tempmodel == null) |
| 373 |
m_scenes[0].AssetCache.GetAsset(assetid, false); |
m_scenes[0].AssetService.Get(assetid.ToString()); |
| 374 |
|
|
| 375 |
if (tempmodel != null) |
if (tempmodel != null) |
| 376 |
return(byte)(tempmodel.Metadata.Type); |
return(byte)(tempmodel.Type); |
| 377 |
else |
else |
| 378 |
return 0; |
return 0; |
| 379 |
} |
} |
| 380 |
|
|
| 381 |
|
|
| 382 |
|
public void TriggerOnSaveObject(UUID id) |
| 383 |
|
{ |
| 384 |
|
RexObjectProperties props = GetObject(id); |
| 385 |
|
m_db.StoreObject(props); |
| 386 |
|
} |
| 387 |
#endregion |
#endregion |
| 388 |
|
|
| 389 |
|
|
| 436 |
RexObjectProperties props = RexObjectPropertiesCache[id]; |
RexObjectProperties props = RexObjectPropertiesCache[id]; |
| 437 |
if (props == null) |
if (props == null) |
| 438 |
{ |
{ |
| 439 |
|
//Objects that are not in the scene can't be found from cache. |
| 440 |
|
//So before we create new properties, we try to find them from db |
| 441 |
|
props = m_db.LoadObject(id); |
| 442 |
|
if (props == null) |
| 443 |
|
{ |
| 444 |
props = new RexObjectProperties(id, this); |
props = new RexObjectProperties(id, this); |
| 445 |
|
} |
| 446 |
RexObjectPropertiesCache.Add(id, props); |
RexObjectPropertiesCache.Add(id, props); |
| 447 |
} |
} |
| 448 |
return props; |
return props; |
| 464 |
return false; |
return false; |
| 465 |
} |
} |
| 466 |
|
|
|
|
|
| 467 |
#endregion |
#endregion |
| 468 |
|
|
| 469 |
|
|
| 470 |
|
public void HandleLoadRexLegacyData(string module, string[] args) |
| 471 |
|
{ |
| 472 |
|
NHibernateRexLegacyData legacydata = new NHibernateRexLegacyData(); |
| 473 |
|
|
| 474 |
|
legacydata.Initialise(args[1]); |
| 475 |
|
if(!legacydata.Inizialized) |
| 476 |
|
{ |
| 477 |
|
m_log.Info("[MODREXOBJECTS]: Legacy database failed to initialize."); |
| 478 |
|
return; |
| 479 |
|
} |
| 480 |
|
|
| 481 |
|
List<RexLegacyPrimData> rexprimdata = legacydata.LoadAllRexPrimData(); |
| 482 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimdata objects loaded:" + rexprimdata.Count.ToString()); |
| 483 |
|
|
| 484 |
|
List<RexLegacyPrimMaterialData> rexprimmaterialdata = legacydata.LoadAllRexPrimMaterialData(); |
| 485 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimmaterialdata objects loaded:" + rexprimmaterialdata.Count.ToString()); |
| 486 |
|
|
| 487 |
|
foreach (RexLegacyPrimData prim in rexprimdata) |
| 488 |
|
{ |
| 489 |
|
RexObjectProperties p = GetObject(prim.UUID); |
| 490 |
|
p.SetRexPrimDataFromLegacyData(prim); |
| 491 |
|
} |
| 492 |
|
|
| 493 |
|
foreach (RexLegacyPrimMaterialData primmat in rexprimmaterialdata) |
| 494 |
|
{ |
| 495 |
|
RexObjectProperties p = GetObject(primmat.UUID); |
| 496 |
|
p.RexMaterials.AddMaterial((uint)primmat.MaterialIndex,primmat.MaterialUUID); |
| 497 |
|
} |
| 498 |
|
} |
| 499 |
|
|
| 500 |
} |
} |
| 501 |
} |
} |