Annotation of /trunk/ModularRex/RexNetwork/RexLogin/RexLoginModule.cs
Parent Directory
|
Revision Log
Revision 6 - (view) (download)
| 1 : | afrisby | 3 | using System; |
| 2 : | afrisby | 5 | using System.Collections; |
| 3 : | afrisby | 3 | using System.Collections.Generic; |
| 4 : | afrisby | 6 | using System.Reflection; |
| 5 : | using log4net; | ||
| 6 : | afrisby | 3 | using Nini.Config; |
| 7 : | afrisby | 6 | using Nwc.XmlRpc; |
| 8 : | using OpenMetaverse; | ||
| 9 : | using OpenSim.Framework; | ||
| 10 : | using OpenSim.Framework.Communications; | ||
| 11 : | afrisby | 3 | using OpenSim.Region.Environment.Interfaces; |
| 12 : | using OpenSim.Region.Environment.Scenes; | ||
| 13 : | |||
| 14 : | namespace ModularRex.RexNetwork.RexLogin | ||
| 15 : | { | ||
| 16 : | afrisby | 6 | public class RexLoginModule : IRegionModule |
| 17 : | afrisby | 3 | { |
| 18 : | afrisby | 6 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 19 : | afrisby | 3 | |
| 20 : | afrisby | 6 | private readonly List<Scene> m_scenes = new List<Scene>(); |
| 21 : | private RexUDPServer m_udpserver; | ||
| 22 : | private IConfigSource m_config; | ||
| 23 : | |||
| 24 : | private RegionInfo m_primaryRegionInfo; | ||
| 25 : | private uint m_rexPort = 7000; | ||
| 26 : | |||
| 27 : | afrisby | 3 | public void Initialise(Scene scene, IConfigSource source) |
| 28 : | { | ||
| 29 : | afrisby | 5 | if (m_udpserver == null) |
| 30 : | m_udpserver = new RexUDPServer(); | ||
| 31 : | |||
| 32 : | afrisby | 6 | m_config = source; |
| 33 : | afrisby | 5 | |
| 34 : | afrisby | 6 | m_scenes.Add(scene); |
| 35 : | afrisby | 3 | } |
| 36 : | |||
| 37 : | afrisby | 6 | |
| 38 : | public void PostInitialise() | ||
| 39 : | afrisby | 5 | { |
| 40 : | afrisby | 6 | m_log.Info("[REX] Overloading Login_to_Simulator"); |
| 41 : | m_scenes[0].AddXmlRPCHandler("login_to_simulator", XmlRpcLoginMethod); | ||
| 42 : | afrisby | 5 | |
| 43 : | afrisby | 6 | m_primaryRegionInfo = m_scenes[0].RegionInfo; |
| 44 : | afrisby | 5 | |
| 45 : | afrisby | 6 | m_log.Info("[REX] Initialising"); |
| 46 : | m_udpserver.Initialise(m_primaryRegionInfo.ExternalEndPoint.Address, ref m_rexPort, 0, false, m_config, m_scenes[0].AssetCache, | ||
| 47 : | m_scenes[0].AuthenticateHandler); | ||
| 48 : | foreach (Scene scene in m_scenes) | ||
| 49 : | { | ||
| 50 : | m_udpserver.AddScene(scene); | ||
| 51 : | } | ||
| 52 : | m_udpserver.Start(); | ||
| 53 : | afrisby | 5 | |
| 54 : | |||
| 55 : | afrisby | 3 | } |
| 56 : | |||
| 57 : | public void Close() | ||
| 58 : | { | ||
| 59 : | |||
| 60 : | } | ||
| 61 : | |||
| 62 : | public string Name | ||
| 63 : | { | ||
| 64 : | get { return "RexLoginOverrider"; } | ||
| 65 : | } | ||
| 66 : | |||
| 67 : | public bool IsSharedModule | ||
| 68 : | { | ||
| 69 : | get { return true; } | ||
| 70 : | } | ||
| 71 : | afrisby | 6 | |
| 72 : | #region RexLoginHelper | ||
| 73 : | |||
| 74 : | public bool AuthenticateUser(string accountName, string sessionHash) | ||
| 75 : | { | ||
| 76 : | return true; | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | public virtual XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) | ||
| 80 : | { | ||
| 81 : | //CFK: CustomizeResponse contains sufficient strings to alleviate the need for this. | ||
| 82 : | //CKF: m_log.Info("[LOGIN]: Attempting login now..."); | ||
| 83 : | XmlRpcResponse response = new XmlRpcResponse(); | ||
| 84 : | Hashtable requestData = (Hashtable)request.Params[0]; | ||
| 85 : | |||
| 86 : | bool GoodXML = (requestData.Contains("account") && requestData.Contains("sessionhash")); | ||
| 87 : | bool GoodLogin; | ||
| 88 : | |||
| 89 : | string startLocationRequest = "last"; | ||
| 90 : | |||
| 91 : | LoginResponse logResponse = new LoginResponse(); | ||
| 92 : | |||
| 93 : | string account; | ||
| 94 : | string sessionHash; | ||
| 95 : | |||
| 96 : | if (GoodXML) | ||
| 97 : | { | ||
| 98 : | account = (string)requestData["account"]; | ||
| 99 : | sessionHash = (string)requestData["sessionhash"]; | ||
| 100 : | |||
| 101 : | m_log.InfoFormat( | ||
| 102 : | "[REX LOGIN BEGIN]: XMLRPC Received login request message from user '{0}' '{1}'", | ||
| 103 : | account, sessionHash); | ||
| 104 : | |||
| 105 : | string clientVersion = "Unknown"; | ||
| 106 : | |||
| 107 : | if (requestData.Contains("version")) | ||
| 108 : | { | ||
| 109 : | clientVersion = (string)requestData["version"]; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | if (requestData.Contains("start")) | ||
| 113 : | { | ||
| 114 : | startLocationRequest = (string)requestData["start"]; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | m_log.DebugFormat( | ||
| 118 : | "[REXLOGIN]: XMLRPC Client is {0}, start location is {1}", clientVersion, startLocationRequest); | ||
| 119 : | |||
| 120 : | GoodLogin = AuthenticateUser(account, sessionHash); | ||
| 121 : | } | ||
| 122 : | else | ||
| 123 : | { | ||
| 124 : | m_log.Info( | ||
| 125 : | "[REXLOGIN END]: XMLRPC login_to_simulator login message did not contain all the required data"); | ||
| 126 : | |||
| 127 : | return logResponse.CreateGridErrorResponse(); | ||
| 128 : | } | ||
| 129 : | |||
| 130 : | if (!GoodLogin) | ||
| 131 : | { | ||
| 132 : | m_log.InfoFormat("[LOGIN END]: XMLRPC User {0} ({1}) failed authentication", account, sessionHash); | ||
| 133 : | |||
| 134 : | return logResponse.CreateLoginFailedResponse(); | ||
| 135 : | } | ||
| 136 : | try | ||
| 137 : | { | ||
| 138 : | |||
| 139 : | // Inventory | ||
| 140 : | UUID invTemp = UUID.Random(); | ||
| 141 : | Hashtable TempHash = new Hashtable(); | ||
| 142 : | TempHash["name"] = "Root Folder"; | ||
| 143 : | TempHash["parent_id"] = UUID.Zero.ToString(); | ||
| 144 : | TempHash["version"] = 0; | ||
| 145 : | TempHash["type_default"] = 0; | ||
| 146 : | TempHash["folder_id"] = invTemp.ToString(); | ||
| 147 : | |||
| 148 : | |||
| 149 : | ArrayList AgentInventoryArray = new ArrayList(); | ||
| 150 : | AgentInventoryArray.Add(TempHash); | ||
| 151 : | |||
| 152 : | Hashtable InventoryRootHash = new Hashtable(); | ||
| 153 : | InventoryRootHash["folder_id"] = invTemp.ToString(); | ||
| 154 : | ArrayList InventoryRoot = new ArrayList(); | ||
| 155 : | InventoryRoot.Add(InventoryRootHash); | ||
| 156 : | /* | ||
| 157 : | // Inventory Library Section | ||
| 158 : | Hashtable InventoryLibRootHash = new Hashtable(); | ||
| 159 : | InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; | ||
| 160 : | ArrayList InventoryLibRoot = new ArrayList(); | ||
| 161 : | InventoryLibRoot.Add(InventoryLibRootHash); | ||
| 162 : | |||
| 163 : | logResponse.InventoryLibRoot = InventoryLibRoot; | ||
| 164 : | */ | ||
| 165 : | logResponse.InventoryRoot = InventoryRoot; | ||
| 166 : | logResponse.InventorySkeleton = AgentInventoryArray; | ||
| 167 : | // End Inventory | ||
| 168 : | |||
| 169 : | |||
| 170 : | |||
| 171 : | UUID agentID = GetAgentID(account); | ||
| 172 : | |||
| 173 : | logResponse.CircuitCode = Util.RandomClass.Next(); | ||
| 174 : | |||
| 175 : | |||
| 176 : | |||
| 177 : | logResponse.Lastname = "aka " + account; | ||
| 178 : | logResponse.Firstname = "Rex User"; | ||
| 179 : | |||
| 180 : | |||
| 181 : | |||
| 182 : | logResponse.AgentID = agentID; | ||
| 183 : | logResponse.SessionID = GetSessionID(account); | ||
| 184 : | logResponse.SecureSessionID = GetSecureID(account); | ||
| 185 : | logResponse.Message = "Welcome to ModularRex"; | ||
| 186 : | |||
| 187 : | logResponse.SimAddress = m_primaryRegionInfo.ExternalEndPoint.Address.ToString(); | ||
| 188 : | logResponse.SimPort = m_rexPort; | ||
| 189 : | logResponse.RegionX = m_primaryRegionInfo.RegionLocX; | ||
| 190 : | logResponse.RegionY = m_primaryRegionInfo.RegionLocY; | ||
| 191 : | |||
| 192 : | |||
| 193 : | logResponse.StartLocation = startLocationRequest; | ||
| 194 : | |||
| 195 : | string capsPath = Util.GetRandomCapsPath(); | ||
| 196 : | string seedcap = "http://" + m_scenes[0].RegionInfo.ExternalEndPoint.Address + ":" + | ||
| 197 : | "9000" + "/CAPS/" + capsPath + "0000/"; | ||
| 198 : | |||
| 199 : | logResponse.SeedCapability = seedcap; | ||
| 200 : | |||
| 201 : | foreach (Scene scene in m_scenes) | ||
| 202 : | { | ||
| 203 : | AgentCircuitData acd = new AgentCircuitData(); | ||
| 204 : | |||
| 205 : | acd.AgentID = agentID; | ||
| 206 : | acd.BaseFolder = UUID.Zero; | ||
| 207 : | acd.CapsPath = seedcap; | ||
| 208 : | |||
| 209 : | // Will login to the first region | ||
| 210 : | acd.child = scene == m_scenes[0]; | ||
| 211 : | |||
| 212 : | acd.circuitcode = (uint)logResponse.CircuitCode; | ||
| 213 : | acd.firstname = logResponse.Firstname; | ||
| 214 : | acd.InventoryFolder = UUID.Zero; | ||
| 215 : | acd.lastname = logResponse.Lastname; | ||
| 216 : | acd.SecureSessionID = logResponse.SecureSessionID; | ||
| 217 : | acd.SessionID = logResponse.SessionID; | ||
| 218 : | acd.startpos = new Vector3(128, 128, 128); | ||
| 219 : | |||
| 220 : | scene.NewUserConnection(acd); | ||
| 221 : | } | ||
| 222 : | |||
| 223 : | |||
| 224 : | |||
| 225 : | XmlRpcResponse rep = logResponse.ToXmlRpcResponse(); | ||
| 226 : | |||
| 227 : | Hashtable val = (Hashtable) rep.Value; | ||
| 228 : | val["rex"] = "running rex mode"; | ||
| 229 : | |||
| 230 : | m_log.Debug(rep.ToString()); | ||
| 231 : | |||
| 232 : | return rep; | ||
| 233 : | } | ||
| 234 : | catch (Exception e) | ||
| 235 : | { | ||
| 236 : | m_log.Info("[REXLOGIN END]: XMLRPC Login failed, " + e); | ||
| 237 : | } | ||
| 238 : | |||
| 239 : | m_log.Info("[REXLOGIN END]: XMLRPC Login failed. Sending back blank XMLRPC response"); | ||
| 240 : | return response; | ||
| 241 : | } | ||
| 242 : | |||
| 243 : | private static UUID GetAgentID(string account) | ||
| 244 : | { | ||
| 245 : | UUID agentID = new UUID(Util.Md5Hash(account)); | ||
| 246 : | return agentID; | ||
| 247 : | } | ||
| 248 : | |||
| 249 : | private static UUID GetSessionID(string account) | ||
| 250 : | { | ||
| 251 : | UUID agentID = new UUID(Util.Md5Hash(account + "session")); | ||
| 252 : | return agentID; | ||
| 253 : | } | ||
| 254 : | |||
| 255 : | /// <summary> | ||
| 256 : | /// Not really secure. | ||
| 257 : | /// </summary> | ||
| 258 : | private static UUID GetSecureID(string account) | ||
| 259 : | { | ||
| 260 : | UUID agentID = new UUID(Util.Md5Hash(account + "secure")); | ||
| 261 : | return agentID; | ||
| 262 : | } | ||
| 263 : | |||
| 264 : | #endregion | ||
| 265 : | |||
| 266 : | afrisby | 3 | } |
| 267 : | afrisby | 6 | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

