private void BeginLogin()
{
LoginParams loginParams = CurrentContext.Value;
// Sanity check
if (loginParams.Options == null)
loginParams.Options = new List<string>();
// Convert the password to MD5 if it isn't already
if (loginParams.Password.Length != 35 && !loginParams.Password.StartsWith("$1$"))
loginParams.Password = Utils.MD5(loginParams.Password);
// Override SSL authentication mechanisms. DO NOT convert this to the
// .NET 2.0 preferred method, the equivalent function in Mono has a
// different name and it will break compatibility!
#pragma warning disable 0618
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
// TODO: At some point, maybe we should check the cert?
// Create the CAPS login structure
OSDMap loginLLSD = new OSDMap();
loginLLSD["first"] = OSD.FromString(loginParams.FirstName);
loginLLSD["last"] = OSD.FromString(loginParams.LastName);
loginLLSD["passwd"] = OSD.FromString(loginParams.Password);
loginLLSD["start"] = OSD.FromString(loginParams.Start);
loginLLSD["channel"] = OSD.FromString(loginParams.Channel);
loginLLSD["version"] = OSD.FromString(loginParams.Version);
loginLLSD["platform"] = OSD.FromString(loginParams.Platform);
loginLLSD["mac"] = OSD.FromString(loginParams.MAC);
loginLLSD["agree_to_tos"] = OSD.FromBoolean(true);
loginLLSD["read_critical"] = OSD.FromBoolean(true);
loginLLSD["viewer_digest"] = OSD.FromString(loginParams.ViewerDigest);
loginLLSD["id0"] = OSD.FromString(loginParams.id0);
// Create the options LLSD array
OSDArray optionsOSD = new OSDArray();
for (int i = 0; i < loginParams.Options.Count; i++)
optionsOSD.Add(OSD.FromString(loginParams.Options[i]));
foreach (string[] callbackOpts in CallbackOptions.Values)
{
if (callbackOpts != null)
{
for (int i = 0; i < callbackOpts.Length; i++)
{
if (!optionsOSD.Contains(callbackOpts[i]))
optionsOSD.Add(callbackOpts[i]);
}
}
}
loginLLSD["options"] = optionsOSD;
// Make the CAPS POST for login
Uri loginUri;
try
{
loginUri = new Uri(loginParams.URI);
}
catch (Exception ex)
{
Logger.Log(String.Format("Failed to parse login URI {0}, {1}", loginParams.URI, ex.Message),
Helpers.LogLevel.Error, Client);
throw ex;
}
CapsClient loginRequest = new CapsClient(loginUri);
loginRequest.OnComplete += new CapsClient.CompleteCallback(LoginReplyHandler);
loginRequest.UserData = CurrentContext;
UpdateLoginStatus(LoginStatus.ConnectingToLogin, String.Format("Logging in as {0} {1}...", loginParams.FirstName, loginParams.LastName));
loginRequest.StartRequest(OSDParser.SerializeLLSDXmlBytes(loginLLSD), "application/xml+llsd");
}