aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/UserServer/LoginServer.cs
diff options
context:
space:
mode:
authorMW2007-03-29 11:08:42 +0000
committerMW2007-03-29 11:08:42 +0000
commit17b00785ee10a71d290cbcddca9b0152fdf60c8f (patch)
tree88a78c0b9a0357af823e4ecdad25e09a64569f79 /OpenSim.RegionServer/UserServer/LoginServer.cs
parentDoh! need to return the response (diff)
downloadopensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.zip
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.gz
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.bz2
opensim-SC_OLD-17b00785ee10a71d290cbcddca9b0152fdf60c8f.tar.xz
Added lbsa71's http server changes.
So it now has a single http listener that passes incoming requests to the correct handler. This means that logins (in sandbox mode) now go through this listener, which for now is listening on the port you set in startup (default 9000). (This needs changing so that the http listener and udp server are not using the same port)
Diffstat (limited to 'OpenSim.RegionServer/UserServer/LoginServer.cs')
-rw-r--r--OpenSim.RegionServer/UserServer/LoginServer.cs303
1 files changed, 161 insertions, 142 deletions
diff --git a/OpenSim.RegionServer/UserServer/LoginServer.cs b/OpenSim.RegionServer/UserServer/LoginServer.cs
index 7b4c1f0..a68e013 100644
--- a/OpenSim.RegionServer/UserServer/LoginServer.cs
+++ b/OpenSim.RegionServer/UserServer/LoginServer.cs
@@ -50,7 +50,7 @@ namespace OpenSim.UserServer
50 /// <summary> 50 /// <summary>
51 /// When running in local (default) mode , handles client logins. 51 /// When running in local (default) mode , handles client logins.
52 /// </summary> 52 /// </summary>
53 public class LoginServer : LoginService , IUserServer 53 public class LoginServer : LoginService, IUserServer
54 { 54 {
55 private IGridServer m_gridServer; 55 private IGridServer m_gridServer;
56 private ushort _loginPort = 8080; 56 private ushort _loginPort = 8080;
@@ -66,7 +66,15 @@ namespace OpenSim.UserServer
66 private int m_simPort; 66 private int m_simPort;
67 private string m_simAddr; 67 private string m_simAddr;
68 68
69 public LoginServer(IGridServer gridServer, string simAddr, int simPort , bool useAccounts) 69 public LocalUserProfileManager LocalUserManager
70 {
71 get
72 {
73 return userManager;
74 }
75 }
76
77 public LoginServer(IGridServer gridServer, string simAddr, int simPort, bool useAccounts)
70 { 78 {
71 m_gridServer = gridServer; 79 m_gridServer = gridServer;
72 m_simPort = simPort; 80 m_simPort = simPort;
@@ -74,6 +82,14 @@ namespace OpenSim.UserServer
74 this.userAccounts = useAccounts; 82 this.userAccounts = useAccounts;
75 } 83 }
76 84
85 public void Startup()
86 {
87 this.InitializeLogin();
88 //Thread runLoginProxy = new Thread(new ThreadStart(RunLogin));
89 //runLoginProxy.IsBackground = true;
90 //runLoginProxy.Start();
91 }
92
77 // InitializeLogin: initialize the login 93 // InitializeLogin: initialize the login
78 private void InitializeLogin() 94 private void InitializeLogin()
79 { 95 {
@@ -94,129 +110,124 @@ namespace OpenSim.UserServer
94 SR.Close(); 110 SR.Close();
95 this._mpasswd = EncodePassword("testpass"); 111 this._mpasswd = EncodePassword("testpass");
96 112
97 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr ); 113 userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr);
98 userManager.InitUserProfiles(); 114 userManager.InitUserProfiles();
99 userManager.SetKeys("", "", "", "Welcome to OpenSim"); 115 userManager.SetKeys("", "", "", "Welcome to OpenSim");
100 116
101 loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 117 //loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
102 loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort)); 118 // loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort));
103 loginServer.Listen(1); 119 //loginServer.Listen(1);
104 }
105
106 public void Startup()
107 {
108 this.InitializeLogin();
109 Thread runLoginProxy = new Thread(new ThreadStart(RunLogin));
110 runLoginProxy.IsBackground = true;
111 runLoginProxy.Start();
112 }
113
114 private void RunLogin()
115 {
116 Console.WriteLine("Starting Login Server");
117 try
118 {
119 for (; ; )
120 {
121 Socket client = loginServer.Accept();
122 IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint;
123
124
125 NetworkStream networkStream = new NetworkStream(client);
126 StreamReader networkReader = new StreamReader(networkStream);
127 StreamWriter networkWriter = new StreamWriter(networkStream);
128
129 try
130 {
131 LoginRequest(networkReader, networkWriter);
132 }
133 catch (Exception e)
134 {
135 Console.WriteLine(e.Message);
136 }
137
138 networkWriter.Close();
139 networkReader.Close();
140 networkStream.Close();
141
142 client.Close();
143
144 // send any packets queued for injection
145
146 }
147 }
148 catch (Exception e)
149 {
150 Console.WriteLine(e.Message);
151 Console.WriteLine(e.StackTrace);
152 }
153 }
154
155 // ProxyLogin: proxy a login request
156 private void LoginRequest(StreamReader reader, StreamWriter writer)
157 {
158 lock (this)
159 {
160 string line;
161 int contentLength = 0;
162 // read HTTP header
163 do
164 {
165 // read one line of the header
166 line = reader.ReadLine();
167
168 // check for premature EOF
169 if (line == null)
170 throw new Exception("EOF in client HTTP header");
171
172 // look for Content-Length
173 Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line);
174 if (match.Success)
175 contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString());
176 } while (line != "");
177
178 // read the HTTP body into a buffer
179 char[] content = new char[contentLength];
180 reader.Read(content, 0, contentLength);
181
182 if (this.userAccounts)
183 {
184 //ask the UserProfile Manager to process the request
185 string reply = this.userManager.ParseXMLRPC(new String(content));
186 // forward the XML-RPC response to the client
187 writer.WriteLine("HTTP/1.0 200 OK");
188 writer.WriteLine("Content-type: text/xml");
189 writer.WriteLine();
190 writer.WriteLine(reply);
191 }
192 else
193 {
194 //handle ourselves
195 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content));
196 if (request.MethodName == "login_to_simulator")
197 {
198 this.ProcessXmlRequest(request, writer);
199 }
200 else
201 {
202 XmlRpcResponse PresenceErrorResp = new XmlRpcResponse();
203 Hashtable PresenceErrorRespData = new Hashtable();
204 PresenceErrorRespData["reason"] = "XmlRequest"; ;
205 PresenceErrorRespData["message"] = "Unknown Rpc request";
206 PresenceErrorRespData["login"] = "false";
207 PresenceErrorResp.Value = PresenceErrorRespData;
208 string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", "");
209 writer.WriteLine("HTTP/1.0 200 OK");
210 writer.WriteLine("Content-type: text/xml");
211 writer.WriteLine();
212 writer.WriteLine(reply);
213 }
214 }
215 }
216 } 120 }
217 121
218 public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer) 122 /* private void RunLogin()
123 {
124 Console.WriteLine("Starting Login Server");
125 try
126 {
127 for (; ; )
128 {
129 Socket client = loginServer.Accept();
130 IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint;
131
132
133 NetworkStream networkStream = new NetworkStream(client);
134 StreamReader networkReader = new StreamReader(networkStream);
135 StreamWriter networkWriter = new StreamWriter(networkStream);
136
137 try
138 {
139 LoginRequest(networkReader, networkWriter);
140 }
141 catch (Exception e)
142 {
143 Console.WriteLine(e.Message);
144 }
145
146 networkWriter.Close();
147 networkReader.Close();
148 networkStream.Close();
149
150 client.Close();
151
152 // send any packets queued for injection
153
154 }
155 }
156 catch (Exception e)
157 {
158 Console.WriteLine(e.Message);
159 Console.WriteLine(e.StackTrace);
160 }
161 }
162
163 // ProxyLogin: proxy a login request
164 private void LoginRequest(StreamReader reader, StreamWriter writer)
165 {
166 lock (this)
167 {
168 string line;
169 int contentLength = 0;
170 // read HTTP header
171 do
172 {
173 // read one line of the header
174 line = reader.ReadLine();
175
176 // check for premature EOF
177 if (line == null)
178 throw new Exception("EOF in client HTTP header");
179
180 // look for Content-Length
181 Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line);
182 if (match.Success)
183 contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString());
184 } while (line != "");
185
186 // read the HTTP body into a buffer
187 char[] content = new char[contentLength];
188 reader.Read(content, 0, contentLength);
189
190 if (this.userAccounts)
191 {
192 //ask the UserProfile Manager to process the request
193 string reply = this.userManager.ParseXMLRPC(new String(content));
194 // forward the XML-RPC response to the client
195 writer.WriteLine("HTTP/1.0 200 OK");
196 writer.WriteLine("Content-type: text/xml");
197 writer.WriteLine();
198 writer.WriteLine(reply);
199 }
200 else
201 {
202 //handle ourselves
203 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content));
204 if (request.MethodName == "login_to_simulator")
205 {
206 this.ProcessXmlRequest(request, writer);
207 }
208 else
209 {
210 XmlRpcResponse PresenceErrorResp = new XmlRpcResponse();
211 Hashtable PresenceErrorRespData = new Hashtable();
212 PresenceErrorRespData["reason"] = "XmlRequest"; ;
213 PresenceErrorRespData["message"] = "Unknown Rpc request";
214 PresenceErrorRespData["login"] = "false";
215 PresenceErrorResp.Value = PresenceErrorRespData;
216 string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", "");
217 writer.WriteLine("HTTP/1.0 200 OK");
218 writer.WriteLine("Content-type: text/xml");
219 writer.WriteLine();
220 writer.WriteLine(reply);
221 }
222 }
223 }
224 }
225 */
226 //public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer)
227
228 public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
219 { 229 {
230 Console.WriteLine("login attempt");
220 Hashtable requestData = (Hashtable)request.Params[0]; 231 Hashtable requestData = (Hashtable)request.Params[0];
221 string first; 232 string first;
222 string last; 233 string last;
@@ -224,6 +235,8 @@ namespace OpenSim.UserServer
224 LLUUID Agent; 235 LLUUID Agent;
225 LLUUID Session; 236 LLUUID Session;
226 237
238 XmlRpcResponse response = new XmlRpcResponse();
239
227 //get login name 240 //get login name
228 if (requestData.Contains("first")) 241 if (requestData.Contains("first"))
229 { 242 {
@@ -254,18 +267,24 @@ namespace OpenSim.UserServer
254 267
255 if (!Authenticate(first, last, passwd)) 268 if (!Authenticate(first, last, passwd))
256 { 269 {
257 XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); 270 /* XmlRpcResponse PresenceErrorResp = new XmlRpcResponse();
258 Hashtable PresenceErrorRespData = new Hashtable(); 271 Hashtable PresenceErrorRespData = new Hashtable();
259 PresenceErrorRespData["reason"] = "key"; ; 272 PresenceErrorRespData["reason"] = "key"; ;
260 PresenceErrorRespData["message"] = "You have entered an invalid name/password combination. Check Caps/lock."; 273 PresenceErrorRespData["message"] = "You have entered an invalid name/password combination. Check Caps/lock.";
261 PresenceErrorRespData["login"] = "false"; 274 PresenceErrorRespData["login"] = "false";
262 PresenceErrorResp.Value = PresenceErrorRespData; 275 PresenceErrorResp.Value = PresenceErrorRespData;
263 string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); 276 string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", "");
264 writer.WriteLine("HTTP/1.0 200 OK"); 277 writer.WriteLine("HTTP/1.0 200 OK");
265 writer.WriteLine("Content-type: text/xml"); 278 writer.WriteLine("Content-type: text/xml");
266 writer.WriteLine(); 279 writer.WriteLine();
267 writer.WriteLine(reply); 280 writer.WriteLine(reply);
268 return false; 281 return false;*/
282
283 Hashtable loginError = new Hashtable();
284 loginError["reason"] = "key"; ;
285 loginError["message"] = "You have entered an invalid name/password combination. Check Caps/lock.";
286 loginError["login"] = "false";
287 response.Value = loginError;
269 } 288 }
270 289
271 NumClients++; 290 NumClients++;
@@ -291,15 +310,15 @@ namespace OpenSim.UserServer
291 ArrayList GlobalTextures = new ArrayList(); 310 ArrayList GlobalTextures = new ArrayList();
292 GlobalTextures.Add(GlobalT); 311 GlobalTextures.Add(GlobalT);
293 312
294 XmlRpcResponse response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); 313 response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse);
295 Hashtable responseData = (Hashtable)response.Value; 314 Hashtable responseData = (Hashtable)response.Value;
296 315
297 responseData["sim_port"] = m_simPort; 316 responseData["sim_port"] = m_simPort;
298 responseData["sim_ip"] = m_simAddr; 317 responseData["sim_ip"] = m_simAddr;
299 responseData["agent_id"] = Agent.ToStringHyphenated(); 318 responseData["agent_id"] = Agent.ToStringHyphenated();
300 responseData["session_id"] = Session.ToStringHyphenated(); 319 responseData["session_id"] = Session.ToStringHyphenated();
301 responseData["secure_session_id"]= secureSess.ToStringHyphenated(); 320 responseData["secure_session_id"] = secureSess.ToStringHyphenated();
302 responseData["circuit_code"] = (Int32)(Util.RandomClass.Next()); 321 responseData["circuit_code"] = (Int32)(Util.RandomClass.Next());
303 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; 322 responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
304 responseData["login-flags"] = LoginFlags; 323 responseData["login-flags"] = LoginFlags;
305 responseData["global-textures"] = GlobalTextures; 324 responseData["global-textures"] = GlobalTextures;
@@ -337,16 +356,16 @@ namespace OpenSim.UserServer
337 ((LocalGridBase)m_gridServer).AddNewSession(_login); 356 ((LocalGridBase)m_gridServer).AddNewSession(_login);
338 } 357 }
339 358
340 // forward the XML-RPC response to the client 359 /* // forward the XML-RPC response to the client
341 writer.WriteLine("HTTP/1.0 200 OK"); 360 writer.WriteLine("HTTP/1.0 200 OK");
342 writer.WriteLine("Content-type: text/xml"); 361 writer.WriteLine("Content-type: text/xml");
343 writer.WriteLine(); 362 writer.WriteLine();
344 363
345 XmlTextWriter responseWriter = new XmlTextWriter(writer); 364 XmlTextWriter responseWriter = new XmlTextWriter(writer);
346 XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response); 365 XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response);
347 responseWriter.Close(); 366 responseWriter.Close();*/
348 367
349 return true; 368 return response;
350 } 369 }
351 370
352 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last) 371 protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last)