Annotation of /trunk/ModularRex/RexNetwork/RexEventQueue.cs
Parent Directory
|
Revision Log
Revision 99 - (view) (download)
| 1 : | mikkopa | 99 | using System; |
| 2 : | using System.Collections; | ||
| 3 : | using System.Collections.Generic; | ||
| 4 : | using System.Net; | ||
| 5 : | using System.Reflection; | ||
| 6 : | using System.Text; | ||
| 7 : | using System.Threading; | ||
| 8 : | using OpenSim.Framework; | ||
| 9 : | using OpenSim.Framework.Servers; | ||
| 10 : | using OpenSim.Region.Framework.Interfaces; | ||
| 11 : | using OpenSim.Region.Framework.Scenes; | ||
| 12 : | using log4net; | ||
| 13 : | using OpenMetaverse; | ||
| 14 : | using OpenMetaverse.StructuredData; | ||
| 15 : | using OpenSim.Region.CoreModules.Framework.EventQueue; | ||
| 16 : | //using BlockingLLSDQueue = OpenSim.Framework.BlockingQueue<OpenMetaverse.StructuredData.OSD>; | ||
| 17 : | using Caps = OpenSim.Framework.Communications.Capabilities.Caps; | ||
| 18 : | |||
| 19 : | namespace ModularRex.RexNetwork | ||
| 20 : | { | ||
| 21 : | |||
| 22 : | /// <summary> | ||
| 23 : | /// This module is intended to replace EventQueueGetModule. This module enables multiregion and grid support. | ||
| 24 : | /// | ||
| 25 : | /// To disable that module set "EventQueue = false" to OpenSim.ini under [Startup] | ||
| 26 : | /// </summary> | ||
| 27 : | public class RexEventQueue : EventQueueGetModule | ||
| 28 : | { | ||
| 29 : | private static readonly ILog m_log = | ||
| 30 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 31 : | |||
| 32 : | private Dictionary<UUID, Type> m_agent_type = new Dictionary<UUID, Type>(); | ||
| 33 : | |||
| 34 : | #region IRegionModule Members | ||
| 35 : | |||
| 36 : | public override void Close() | ||
| 37 : | { | ||
| 38 : | //TODO: deregister module interface | ||
| 39 : | m_scene.EventManager.OnClientClosed -= ClientClosed; | ||
| 40 : | m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; | ||
| 41 : | m_scene.EventManager.OnNewClient -= OnNewClient; | ||
| 42 : | } | ||
| 43 : | |||
| 44 : | public override void Initialise(Scene scene, Nini.Config.IConfigSource source) | ||
| 45 : | { | ||
| 46 : | m_scene = scene; | ||
| 47 : | |||
| 48 : | bool enable_now = ReadAndPopulateConfig(source); | ||
| 49 : | |||
| 50 : | if (enable_now) | ||
| 51 : | { | ||
| 52 : | scene.RegisterModuleInterface<IEventQueue>(this); | ||
| 53 : | |||
| 54 : | scene.EventManager.OnClientClosed += ClientClosed; | ||
| 55 : | scene.EventManager.OnRegisterCaps += OnRegisterCaps; | ||
| 56 : | |||
| 57 : | scene.EventManager.OnNewClient += OnNewClient; | ||
| 58 : | } | ||
| 59 : | else | ||
| 60 : | { | ||
| 61 : | ; | ||
| 62 : | } | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | private void ClientClosed(UUID clientID) | ||
| 66 : | { | ||
| 67 : | m_agent_type.Remove(clientID); | ||
| 68 : | } | ||
| 69 : | |||
| 70 : | private void OnNewClient(IClientAPI client) | ||
| 71 : | { | ||
| 72 : | if (client is RexClientView) | ||
| 73 : | { | ||
| 74 : | m_agent_type.Add(client.AgentId, typeof(RexClientView)); | ||
| 75 : | } | ||
| 76 : | else | ||
| 77 : | { | ||
| 78 : | m_agent_type.Add(client.AgentId, typeof(IClientAPI)); | ||
| 79 : | } | ||
| 80 : | } | ||
| 81 : | |||
| 82 : | private bool ReadAndPopulateConfig(Nini.Config.IConfigSource source) | ||
| 83 : | { | ||
| 84 : | bool rex_conf = CheckRexConfig(source); | ||
| 85 : | if (CheckStartupConfig(source)) | ||
| 86 : | { | ||
| 87 : | //Default event queue enabled or line missing | ||
| 88 : | if (rex_conf) | ||
| 89 : | { | ||
| 90 : | m_log.Warn("[REXEVENTQUEUE]: Both default and Rex Event Queue enabled. Using default."); | ||
| 91 : | } | ||
| 92 : | return false; | ||
| 93 : | } | ||
| 94 : | else | ||
| 95 : | { | ||
| 96 : | //Default event queue disabled | ||
| 97 : | if (rex_conf) | ||
| 98 : | { | ||
| 99 : | m_log.Info("[REXEVENTQUEUE]: Using Rex Event Queue"); | ||
| 100 : | return rex_conf; | ||
| 101 : | } | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | return false; | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | private bool CheckStartupConfig(Nini.Config.IConfigSource source) | ||
| 108 : | { | ||
| 109 : | if (source.Configs["Startup"] != null) | ||
| 110 : | { | ||
| 111 : | return source.Configs["Startup"].GetBoolean("EventQueue", true); | ||
| 112 : | } | ||
| 113 : | else | ||
| 114 : | { | ||
| 115 : | return true; | ||
| 116 : | } | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | private bool CheckRexConfig(Nini.Config.IConfigSource source) | ||
| 120 : | { | ||
| 121 : | if (source.Configs["realXtend"] != null) | ||
| 122 : | { | ||
| 123 : | if (source.Configs["realXtend"].GetBoolean("RexEventQueue", true)) | ||
| 124 : | { | ||
| 125 : | return true; | ||
| 126 : | } | ||
| 127 : | } | ||
| 128 : | return false; | ||
| 129 : | } | ||
| 130 : | |||
| 131 : | public override string Name | ||
| 132 : | { | ||
| 133 : | get { return "RexEventQueue"; } | ||
| 134 : | } | ||
| 135 : | |||
| 136 : | #endregion | ||
| 137 : | |||
| 138 : | /// <summary> | ||
| 139 : | /// Checks if the user is RexClientView or not | ||
| 140 : | /// </summary> | ||
| 141 : | /// <param name="AgentId">UUID of the user to check</param> | ||
| 142 : | /// <returns>Returns false if not or if not found</returns> | ||
| 143 : | bool IsRexClient(UUID AgentId) | ||
| 144 : | { | ||
| 145 : | if (m_agent_type.ContainsKey(AgentId)) | ||
| 146 : | { | ||
| 147 : | if (m_agent_type[AgentId] == typeof(RexClientView)) | ||
| 148 : | { | ||
| 149 : | return true; | ||
| 150 : | } | ||
| 151 : | else | ||
| 152 : | { | ||
| 153 : | return false; | ||
| 154 : | } | ||
| 155 : | } | ||
| 156 : | return false; | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | string ModifyCAPS(string caps) | ||
| 160 : | { | ||
| 161 : | return caps; | ||
| 162 : | //Example CAPS construction | ||
| 163 : | //string capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort | ||
| 164 : | // + "/CAPS/" + a.CapsPath + "0000/"; | ||
| 165 : | //http://192.168.0.101:9000/CAPS/da43e83f-4e45-47de-bc7c-546150df0000/ | ||
| 166 : | |||
| 167 : | int start = caps.IndexOf(':', 6); | ||
| 168 : | int end = caps.IndexOf('/', start); | ||
| 169 : | |||
| 170 : | string port = caps.Substring(start + 1, (end - start - 1)); | ||
| 171 : | //m_log.InfoFormat("[REXEVENTQUEUE]: parse port {0}", port); | ||
| 172 : | int iPort = Convert.ToInt32(port); | ||
| 173 : | |||
| 174 : | string newCaps = caps.Substring(0, start+1) + (iPort - 2000).ToString() + caps.Substring(end); | ||
| 175 : | m_log.InfoFormat("[REXEVENTQUEUE]: new caps {0}", newCaps); | ||
| 176 : | return newCaps; | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | #region IEventQueue Members | ||
| 180 : | |||
| 181 : | //Can't be inherited | ||
| 182 : | public override void CrossRegion(ulong handle, OpenMetaverse.Vector3 pos, OpenMetaverse.Vector3 lookAt, System.Net.IPEndPoint newRegionExternalEndPoint, string capsURL, OpenMetaverse.UUID avatarID, OpenMetaverse.UUID sessionID) | ||
| 183 : | { | ||
| 184 : | IPEndPoint endpoint; | ||
| 185 : | if (IsRexClient(avatarID)) | ||
| 186 : | { | ||
| 187 : | endpoint = new IPEndPoint(newRegionExternalEndPoint.Address, newRegionExternalEndPoint.Port - 2000); | ||
| 188 : | capsURL = ModifyCAPS(capsURL); | ||
| 189 : | } | ||
| 190 : | else | ||
| 191 : | endpoint = newRegionExternalEndPoint; | ||
| 192 : | |||
| 193 : | OSD item = EventQueueHelper.CrossRegion(handle, pos, lookAt, endpoint, | ||
| 194 : | capsURL, avatarID, sessionID); | ||
| 195 : | |||
| 196 : | Enqueue(item, avatarID); | ||
| 197 : | } | ||
| 198 : | |||
| 199 : | //Can't be inherited | ||
| 200 : | public override void EnableSimulator(ulong handle, System.Net.IPEndPoint endPoint, OpenMetaverse.UUID avatarID) | ||
| 201 : | { | ||
| 202 : | IPEndPoint newEndpoint; | ||
| 203 : | if (IsRexClient(avatarID)) | ||
| 204 : | { | ||
| 205 : | newEndpoint = new IPEndPoint(endPoint.Address, endPoint.Port - 2000); | ||
| 206 : | } | ||
| 207 : | else | ||
| 208 : | newEndpoint = endPoint; | ||
| 209 : | |||
| 210 : | OSD item = EventQueueHelper.EnableSimulator(handle, newEndpoint); | ||
| 211 : | Enqueue(item, avatarID); | ||
| 212 : | } | ||
| 213 : | |||
| 214 : | //Can't be inherited | ||
| 215 : | public override void EstablishAgentCommunication(OpenMetaverse.UUID avatarID, System.Net.IPEndPoint endPoint, string capsPath) | ||
| 216 : | { | ||
| 217 : | IPEndPoint newEndpoint; | ||
| 218 : | if (IsRexClient(avatarID)) | ||
| 219 : | { | ||
| 220 : | newEndpoint = new IPEndPoint(endPoint.Address, endPoint.Port - 2000); | ||
| 221 : | //endPoint.Port = endPoint.Port - 2000; | ||
| 222 : | capsPath = ModifyCAPS(capsPath); | ||
| 223 : | } | ||
| 224 : | else | ||
| 225 : | newEndpoint = endPoint; | ||
| 226 : | |||
| 227 : | OSD item = EventQueueHelper.EstablishAgentCommunication(avatarID, newEndpoint.ToString(), capsPath); | ||
| 228 : | Enqueue(item, avatarID); | ||
| 229 : | } | ||
| 230 : | |||
| 231 : | //Can't be inherited | ||
| 232 : | public override void TeleportFinishEvent(ulong regionHandle, byte simAccess, System.Net.IPEndPoint regionExternalEndPoint, uint locationID, uint flags, string capsURL, OpenMetaverse.UUID agentID) | ||
| 233 : | { | ||
| 234 : | IPEndPoint newEndpoint; | ||
| 235 : | if (IsRexClient(agentID)) | ||
| 236 : | { | ||
| 237 : | newEndpoint = new IPEndPoint(regionExternalEndPoint.Address, regionExternalEndPoint.Port - 2000); | ||
| 238 : | //regionExternalEndPoint.Port = regionExternalEndPoint.Port - 2000; | ||
| 239 : | capsURL = ModifyCAPS(capsURL); | ||
| 240 : | } | ||
| 241 : | else | ||
| 242 : | newEndpoint = regionExternalEndPoint; | ||
| 243 : | |||
| 244 : | OSD item = EventQueueHelper.TeleportFinishEvent(regionHandle, simAccess, newEndpoint, | ||
| 245 : | locationID, flags, capsURL, agentID); | ||
| 246 : | Enqueue(item, agentID); | ||
| 247 : | } | ||
| 248 : | |||
| 249 : | #endregion | ||
| 250 : | } | ||
| 251 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

