| 1 |
using System; |
using System; |
| 2 |
using System.Collections; |
using System.Collections; |
| 3 |
using System.Collections.Generic; |
using System.Collections.Generic; |
| 4 |
using System.Text; |
using System.Reflection; |
| 5 |
|
using log4net; |
| 6 |
using Nini.Config; |
using Nini.Config; |
| 7 |
using OpenSim.Region.ClientStack; |
using Nwc.XmlRpc; |
| 8 |
|
using OpenMetaverse; |
| 9 |
|
using OpenSim.Framework; |
| 10 |
|
using OpenSim.Framework.Communications; |
| 11 |
using OpenSim.Region.Environment.Interfaces; |
using OpenSim.Region.Environment.Interfaces; |
| 12 |
using OpenSim.Region.Environment.Scenes; |
using OpenSim.Region.Environment.Scenes; |
| 13 |
|
|
| 14 |
namespace ModularRex.RexNetwork.RexLogin |
namespace ModularRex.RexNetwork.RexLogin |
| 15 |
{ |
{ |
| 16 |
class RexLoginModule : IRegionModule |
public class RexLoginModule : IRegionModule |
| 17 |
{ |
{ |
| 18 |
private Scene m_firstScene; |
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 19 |
private IClientNetworkServer m_udpserver; |
|
| 20 |
|
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 |
public void Initialise(Scene scene, IConfigSource source) |
public void Initialise(Scene scene, IConfigSource source) |
| 28 |
{ |
{ |
| 29 |
if (m_udpserver == null) |
if (m_udpserver == null) |
| 30 |
m_udpserver = new RexUDPServer(); |
m_udpserver = new RexUDPServer(); |
| 31 |
|
|
| 32 |
m_udpserver.AddScene(scene); |
m_config = source; |
| 33 |
|
|
| 34 |
m_firstScene = scene; |
m_scenes.Add(scene); |
|
scene.AddHTTPHandler("/rexlogin", OnLoginRequest); |
|
| 35 |
} |
} |
| 36 |
|
|
| 37 |
public Hashtable OnLoginRequest(Hashtable keysvals) |
|
| 38 |
|
public void PostInitialise() |
| 39 |
{ |
{ |
| 40 |
Hashtable reply = new Hashtable(); |
m_log.Info("[REX] Overloading Login_to_Simulator"); |
| 41 |
int statuscode = 200; |
m_scenes[0].AddXmlRPCHandler("login_to_simulator", XmlRpcLoginMethod); |
| 42 |
|
|
| 43 |
reply["str_response_string"] = "Test"; |
m_primaryRegionInfo = m_scenes[0].RegionInfo; |
|
reply["int_response_code"] = statuscode; |
|
|
reply["content_type"] = "text/xml"; |
|
| 44 |
|
|
| 45 |
return reply; |
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 |
|
|
| 54 |
|
|
|
public void PostInitialise() |
|
|
{ |
|
| 55 |
} |
} |
| 56 |
|
|
| 57 |
public void Close() |
public void Close() |
| 68 |
{ |
{ |
| 69 |
get { return true; } |
get { return true; } |
| 70 |
} |
} |
| 71 |
|
|
| 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 |
} |
} |
| 267 |
} |
} |