public async Task <LoginResponse> Connect(string uri, Credential credential, Slurl slurl = null, bool getInventoryLibrary = true, bool godMode = false) { if (slurl == null) { slurl = new Slurl(Slurl.SIM_LOCATION_LAST); } Logger.LogDebug($"INFO Login.Connect: Connecting {credential.First} {credential.Last} using {uri}."); XmlRpcParameterArray parameters = CreateLoginParameters(credential, slurl, getInventoryLibrary, godMode); XmlRpcResponse response = await XmlRpcClient.Call(uri, "login_to_simulator", parameters); LoginResponse loginResponse = new LoginResponse(); if (response.FaultCode != 0) { loginResponse.LoginSucceeded = false; loginResponse.LoginFailReason = response.FaultCode.ToString(); loginResponse.Message = response.FaultString; loginResponse.MessageId = "XmlRpcError"; return(loginResponse); } if (response.Parameters.Count != 1 || (response.Parameters[0] is XmlRpcStruct == false)) { loginResponse.LoginSucceeded = false; loginResponse.LoginFailReason = "500"; loginResponse.Message = "Login response contained incorrect parameters."; loginResponse.MessageId = "XmlRpcError"; return(loginResponse); } XmlRpcStruct responseData = (XmlRpcStruct)response.Parameters[0]; if (responseData.Has("login") == false || (responseData["login"] is XmlRpcString == false) || ((XmlRpcString)responseData["login"]).Value != "true") { loginResponse.LoginSucceeded = false; loginResponse.LoginFailReason = responseData["reason"]?.AsString; loginResponse.Message = responseData["message"]?.AsString; loginResponse.MessageId = responseData["message_id"]?.AsString; return(loginResponse); } Logger.LogInfo("Login.Connect: Connection was successful."); if (ProcessLoginSuccessResponse(responseData, loginResponse)) { loginResponse.LoginSucceeded = true; return(loginResponse); } else { // Yet another error } return(loginResponse); }
protected XmlRpcParameterArray CreateLoginParameters(Credential credential, Slurl slurl, bool getInventoryLibrary, bool godMode) { XmlRpcArray options = new XmlRpcArray(); options.Append(new XmlRpcString("inventory-root")); options.Append(new XmlRpcString("inventory-skeleton")); //options.Append(new XmlRpcString("inventory-meat")); //options.Append(new XmlRpcString("inventory-skel-targets")); if (getInventoryLibrary == true) { options.Append(new XmlRpcString("inventory-lib-root")); options.Append(new XmlRpcString("inventory-lib-owner")); options.Append(new XmlRpcString("inventory-skel-lib")); //options.Append(new XmlRpcString("inventory-meat-lib")); } options.Append(new XmlRpcString("initial-outfit")); options.Append(new XmlRpcString("gestures")); options.Append(new XmlRpcString("display_names")); options.Append(new XmlRpcString("event_categories")); options.Append(new XmlRpcString("event_notifications")); options.Append(new XmlRpcString("classified_categories")); options.Append(new XmlRpcString("adult_compliant")); options.Append(new XmlRpcString("buddy-list")); options.Append(new XmlRpcString("newuser-config")); options.Append(new XmlRpcString("ui-config")); //send this info to login.cgi for stats gathering //since viewerstats isn't reliable enough options.Append(new XmlRpcString("advanced-mode")); options.Append(new XmlRpcString("max-agent-groups")); options.Append(new XmlRpcString("map-server-url")); options.Append(new XmlRpcString("voice-config")); options.Append(new XmlRpcString("tutorial_setting")); options.Append(new XmlRpcString("login-flags")); options.Append(new XmlRpcString("global-textures")); if (godMode == true) { options.Append(new XmlRpcString("UseDebugMenus")); options.Append(new XmlRpcString("god-connect")); } XmlRpcStruct data = new XmlRpcStruct(); data["start"] = new XmlRpcString(slurl.GetLoginString()); data["agree_to_tos"] = new XmlRpcBoolean(false); data["read_critical"] = new XmlRpcBoolean(false); data["last_exec_event"] = new XmlRpcInteger(LastExecEvent); data["last_exec_duration"] = new XmlRpcInteger(LastExecDuration); data["mac"] = new XmlRpcString(MachineId); data["version"] = new XmlRpcString(ViewerVersion); data["channel"] = new XmlRpcString(ViewerChannel); data["platform"] = new XmlRpcString(Platform); data["address_size"] = new XmlRpcInteger(ADDRESS_SIZE); data["platform_version"] = new XmlRpcString(PlatformVersion); data["platform_string"] = new XmlRpcString(PlatformVersionName); data["id0"] = new XmlRpcString(SerialNumber); data["host_id"] = new XmlRpcString(HostId); data["extended_errors"] = new XmlRpcBoolean(true); data["passwd"] = new XmlRpcString(credential.Secret); data["first"] = new XmlRpcString(credential.First); data["last"] = new XmlRpcString(credential.Last); data["options"] = options; XmlRpcParameterArray parameters = new XmlRpcParameterArray(); parameters.Append(data); return(parameters); }