Annotation of /trunk/ModularRex/RexParts/ModrexObjects.cs
Parent Directory
|
Revision Log
Revision 42 - (view) (download)
| 1 : | mikkopa | 39 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | using System.IO; | ||
| 4 : | using System.Reflection; | ||
| 5 : | using log4net; | ||
| 6 : | using ModularRex.RexFramework; | ||
| 7 : | using ModularRex.RexNetwork; | ||
| 8 : | using Nini.Config; | ||
| 9 : | using OpenMetaverse; | ||
| 10 : | using OpenSim.Region.Environment.Interfaces; | ||
| 11 : | using OpenSim.Region.Environment.Scenes; | ||
| 12 : | using OpenSim.Data.NHibernate; | ||
| 13 : | |||
| 14 : | namespace ModularRex.RexParts | ||
| 15 : | { | ||
| 16 : | public class ModrexObjects : IRegionModule | ||
| 17 : | { | ||
| 18 : | private static readonly ILog m_log = | ||
| 19 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 20 : | |||
| 21 : | //private Dictionary<UUID,RexObjectProperties> m_objs = new Dictionary<UUID, RexObjectProperties>(); | ||
| 22 : | private List<Scene> m_scenes = new List<Scene>(); | ||
| 23 : | |||
| 24 : | private NHibernateRexObjectData m_db; | ||
| 25 : | private string m_db_connectionstring; | ||
| 26 : | |||
| 27 : | mikkopa | 42 | public event OnChangePythonClassDelegate OnPythonClassChange; |
| 28 : | |||
| 29 : | mikkopa | 39 | public void Initialise(Scene scene, IConfigSource source) |
| 30 : | { | ||
| 31 : | m_scenes.Add(scene); | ||
| 32 : | |||
| 33 : | scene.EventManager.OnClientConnect += EventManager_OnClientConnect; | ||
| 34 : | |||
| 35 : | |||
| 36 : | if (m_db == null) | ||
| 37 : | { | ||
| 38 : | m_db = new NHibernateRexObjectData(); | ||
| 39 : | } | ||
| 40 : | |||
| 41 : | if (source != null) | ||
| 42 : | { | ||
| 43 : | try | ||
| 44 : | { | ||
| 45 : | m_db_connectionstring = source.Configs["realXtend"].GetString("db_connectionstring", "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"); | ||
| 46 : | |||
| 47 : | } | ||
| 48 : | catch (Exception) | ||
| 49 : | { | ||
| 50 : | |||
| 51 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 52 : | } | ||
| 53 : | } | ||
| 54 : | else | ||
| 55 : | { | ||
| 56 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 57 : | } | ||
| 58 : | } | ||
| 59 : | |||
| 60 : | void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) | ||
| 61 : | { | ||
| 62 : | RexClientView rcv; | ||
| 63 : | if (client.TryGet(out rcv)) | ||
| 64 : | { | ||
| 65 : | rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; | ||
| 66 : | //rcv.OnChatFromClient += rcv_OnChatFromClient; | ||
| 67 : | |||
| 68 : | // Send them the current Scene. | ||
| 69 : | SendAllPropertiesToUser(rcv); | ||
| 70 : | } | ||
| 71 : | } | ||
| 72 : | |||
| 73 : | //void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) | ||
| 74 : | //{ | ||
| 75 : | // if (e.Message.StartsWith("/rexobj ")) | ||
| 76 : | // { | ||
| 77 : | // string uuid = e.Message.Split(' ')[1]; | ||
| 78 : | // string asset = e.Message.Split(' ')[2]; | ||
| 79 : | |||
| 80 : | // UUID prim = new UUID(uuid); | ||
| 81 : | // UUID assetID = new UUID(asset); | ||
| 82 : | |||
| 83 : | // m_objs[prim].RexMeshUUID = assetID; | ||
| 84 : | // SendPropertiesToAllUsers(prim, m_objs[prim]); | ||
| 85 : | // } | ||
| 86 : | //} | ||
| 87 : | |||
| 88 : | void SendPropertiesToAllUsers(UUID id, RexObjectProperties props) | ||
| 89 : | { | ||
| 90 : | foreach (Scene scene in m_scenes) | ||
| 91 : | { | ||
| 92 : | scene.ForEachScenePresence( | ||
| 93 : | delegate(ScenePresence avatar) | ||
| 94 : | { | ||
| 95 : | RexClientView rex; | ||
| 96 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 97 : | { | ||
| 98 : | rex.SendRexObjectProperties(id,props); | ||
| 99 : | } | ||
| 100 : | }); | ||
| 101 : | } | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | void SendAllPropertiesToUser(RexClientView user) | ||
| 105 : | { | ||
| 106 : | if (m_db.Inizialized) | ||
| 107 : | { | ||
| 108 : | foreach (Scene s in m_scenes) | ||
| 109 : | { | ||
| 110 : | foreach (EntityBase e in s.Entities) | ||
| 111 : | { | ||
| 112 : | RexObjectProperties p = m_db.LoadObject(e.UUID); | ||
| 113 : | if (p != null) | ||
| 114 : | { | ||
| 115 : | user.SendRexObjectProperties(e.UUID, p); | ||
| 116 : | mikkopa | 42 | p.OnPythonClassChange += PythonClassNameChanged; |
| 117 : | mikkopa | 39 | } |
| 118 : | } | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | } | ||
| 122 : | |||
| 123 : | mikkopa | 42 | private void PythonClassNameChanged(UUID id) |
| 124 : | { | ||
| 125 : | if (OnPythonClassChange != null) | ||
| 126 : | { | ||
| 127 : | OnPythonClassChange(id); | ||
| 128 : | } | ||
| 129 : | } | ||
| 130 : | mikkopa | 39 | |
| 131 : | mikkopa | 42 | |
| 132 : | mikkopa | 39 | void rcv_OnRexObjectProperties(RexClientView sender, UUID id, RexObjectProperties props) |
| 133 : | { | ||
| 134 : | m_log.Info("[REXOBJS] Recieved RexObjData for " + id); | ||
| 135 : | if (props.ParentObjectID == UUID.Zero) | ||
| 136 : | props.ParentObjectID = id; | ||
| 137 : | props.PrintRexPrimdata(); | ||
| 138 : | |||
| 139 : | m_db.StoreObject(props); | ||
| 140 : | SendPropertiesToAllUsers(id, props); | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | public void PostInitialise() | ||
| 144 : | { | ||
| 145 : | lock (m_db) | ||
| 146 : | { | ||
| 147 : | if (!m_db.Inizialized) | ||
| 148 : | { | ||
| 149 : | m_db.Initialise(m_db_connectionstring); | ||
| 150 : | } | ||
| 151 : | } | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | public void Close() | ||
| 155 : | { | ||
| 156 : | ; | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | public string Name | ||
| 160 : | { | ||
| 161 : | get { return "RexObjectsModule"; } | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | public bool IsSharedModule | ||
| 165 : | { | ||
| 166 : | get { return true; } | ||
| 167 : | } | ||
| 168 : | mikkopa | 42 | |
| 169 : | public RexObjectProperties Load(UUID id) | ||
| 170 : | { | ||
| 171 : | RexObjectProperties robject = m_db.LoadObject(id); | ||
| 172 : | if (robject == null) | ||
| 173 : | { | ||
| 174 : | robject = new RexObjectProperties(); | ||
| 175 : | robject.ParentObjectID = id; | ||
| 176 : | } | ||
| 177 : | return robject; | ||
| 178 : | } | ||
| 179 : | |||
| 180 : | public void Save(RexObjectProperties obj) | ||
| 181 : | { | ||
| 182 : | m_db.StoreObject(obj); | ||
| 183 : | } | ||
| 184 : | mikkopa | 39 | } |
| 185 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

