예제 #1
0
        private void CreateItemFromAssetResponse(CapsClient client, LLSD result, Exception error)
        {
            object[] args = (object[])client.UserData;
            CapsClient.ProgressCallback progCallback = (CapsClient.ProgressCallback)args[0];
            ItemCreatedFromAssetCallback callback = (ItemCreatedFromAssetCallback)args[1];
            byte[] itemData = (byte[])args[2];

            LLSDMap contents = (LLSDMap)result;

            if (result == null)
            {
                try { callback(false, error.Message, UUID.Zero, UUID.Zero); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                return;
            }

            string status = contents["state"].AsString().ToLower();

            if (status == "upload")
            {
                string uploadURL = contents["uploader"].AsString();

                Logger.DebugLog("CreateItemFromAsset: uploading to " + uploadURL);

                // This makes the assumption that all uploads go to CurrentSim, to avoid
                // the problem of HttpRequestState not knowing anything about simulators
                CapsClient upload = new CapsClient(new Uri(uploadURL));
                upload.OnProgress += progCallback;
                upload.OnComplete += new CapsClient.CompleteCallback(CreateItemFromAssetResponse);
                upload.UserData = new object[] { null, callback, itemData };
                upload.StartRequest(itemData, "application/octet-stream");
            }
            else if (status == "complete")
            {
                Logger.DebugLog("CreateItemFromAsset: completed");

                if (contents.ContainsKey("new_inventory_item") && contents.ContainsKey("new_asset"))
                {
                    try { callback(true, String.Empty, contents["new_inventory_item"].AsUUID(), contents["new_asset"].AsUUID()); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }

                    // Notify everyone of the creation.
                    // TODO: Is there a way to avoid fetching the whole thing?
                    FetchItemsCallback fetchCallback =
                        delegate(List<ItemData> items)
                        {
                            if (items.Count > 0)
                            {
                                ItemData item = items[0];
                                item.AssetUUID = contents["new_asset"].AsUUID();
                                try { OnItemCreated(true, item); }
                                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                            }
                        };
                    RequestFetchItems(new UUID[] { contents["new_inventory_item"].AsUUID() }, _Agents.AgentID, fetchCallback);
                }
                else
                {
                    try { callback(false, "Failed to parse asset and item UUIDs", UUID.Zero, UUID.Zero); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
            }
            else
            {
                // Failure
                try { callback(false, status, UUID.Zero, UUID.Zero); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
            }
        }
예제 #2
0
파일: Caps.cs 프로젝트: RavenB/gridsearch
        private void SeedRequestCompleteHandler(CapsClient client, LLSD result, Exception error)
        {
            if (result != null && result.Type == LLSDType.Map)
            {
                LLSDMap respTable = (LLSDMap)result;

                StringBuilder capsList = new StringBuilder();

                foreach (string cap in respTable.Keys)
                {
                    capsList.Append(cap);
                    capsList.Append(' ');

                    _Caps[cap] = respTable[cap].AsUri();
                }

                Logger.DebugLog("Got capabilities: " + capsList.ToString(), Simulator.Client);

                if (_Caps.ContainsKey("EventQueueGet"))
                {
                    Logger.DebugLog("Starting event queue for " + Simulator.ToString(), Simulator.Client);

                    _EventQueueCap = new EventQueueClient(_Caps["EventQueueGet"]);
                    _EventQueueCap.OnConnected += new EventQueueClient.ConnectedCallback(EventQueueConnectedHandler);
                    _EventQueueCap.OnEvent += new EventQueueClient.EventCallback(EventQueueEventHandler);
                    _EventQueueCap.Start();
                }
            }
            else
            {
                // The initial CAPS connection failed, try again
                MakeSeedRequest();
            }
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="notecardID"></param>
        /// <param name="callback"></param>
        public void RequestUploadNotecardAsset(byte[] data, UUID notecardID, NotecardUploadedAssetCallback callback)
        {
            if (_Network.CurrentSim == null || _Network.CurrentSim.Caps == null)
                throw new Exception("UpdateNotecardAgentInventory capability is not currently available");

            Uri url = _Network.CurrentSim.Caps.CapabilityURI("UpdateNotecardAgentInventory");

            if (url != null)
            {
                LLSDMap query = new LLSDMap();
                query.Add("item_id", LLSD.FromUUID(notecardID));

                byte[] postData = StructuredData.LLSDParser.SerializeXmlBytes(query);

                // Make the request
                CapsClient request = new CapsClient(url);
                request.OnComplete += new CapsClient.CompleteCallback(UploadNotecardAssetResponse);
                request.UserData = new object[2] { new KeyValuePair<NotecardUploadedAssetCallback, byte[]>(callback, data), notecardID };
                request.StartRequest(postData);
            }
            else
            {
                throw new Exception("UpdateNotecardAgentInventory capability is not currently available");
            }
        }
예제 #4
0
        private void ProvisionCapsResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                OSDMap respTable = (OSDMap)response;

                if (OnProvisionAccount != null)
                {
                    try { OnProvisionAccount(respTable["username"].AsString(), respTable["password"].AsString()); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="layer"></param>
        public void RequestMapLayer(GridLayerType layer)
        {
            Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("MapLayer");

            if (url != null)
            {
                LLSDMap body = new LLSDMap();
                body["Flags"] = LLSD.FromInteger((int)layer);

                CapsClient request = new CapsClient(url);
                request.OnComplete += new CapsClient.CompleteCallback(MapLayerResponseHandler);
                request.StartRequest(body);
            }
        }
예제 #6
0
파일: Login.cs 프로젝트: RavenB/gridsearch
        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 = Helpers.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
            LLSDMap loginLLSD = new LLSDMap();
            loginLLSD["first"] = LLSD.FromString(loginParams.FirstName);
            loginLLSD["last"] = LLSD.FromString(loginParams.LastName);
            loginLLSD["passwd"] = LLSD.FromString(loginParams.Password);
            loginLLSD["start"] = LLSD.FromString(loginParams.Start);
            loginLLSD["channel"] = LLSD.FromString(loginParams.Channel);
            loginLLSD["version"] = LLSD.FromString(loginParams.Version);
            loginLLSD["platform"] = LLSD.FromString(loginParams.Platform);
            loginLLSD["mac"] = LLSD.FromString(loginParams.MAC);
            loginLLSD["agree_to_tos"] = LLSD.FromBoolean(true);
            loginLLSD["read_critical"] = LLSD.FromBoolean(true);
            loginLLSD["viewer_digest"] = LLSD.FromString(loginParams.ViewerDigest);
            loginLLSD["id0"] = LLSD.FromString(loginParams.id0);

            // Create the options LLSD array
            LLSDArray optionsLLSD = new LLSDArray();
            for (int i = 0; i < loginParams.Options.Count; i++)
                optionsLLSD.Add(LLSD.FromString(loginParams.Options[i]));
            foreach (string[] callbackOpts in CallbackOptions.Values)
            {
                if (callbackOpts != null)
                {
                    for (int i = 0; i < callbackOpts.Length; i++)
                    {
                        if (!optionsLLSD.Contains(callbackOpts[i]))
                            optionsLLSD.Add(callbackOpts[i]);
                    }
                }
            }
            loginLLSD["options"] = optionsLLSD;

            // 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);
                return;
            }

            CapsClient loginRequest = new CapsClient(new Uri(loginParams.URI));
            loginRequest.OnComplete += new CapsClient.CompleteCallback(LoginReplyHandler);
            loginRequest.UserData = CurrentContext;
            loginRequest.StartRequest(LLSDParser.SerializeXmlBytes(loginLLSD), "application/xml+llsd");
        }
예제 #7
0
        private void ProxyLoginSD(NetworkStream netStream, byte[] content)
        {
            lock (this) {
                ServicePointManager.CertificatePolicy = new OpenMetaverse.AcceptAllCertificatePolicy();
                AutoResetEvent remoteComplete = new AutoResetEvent(false);
                //CapsClient loginRequest = new CapsClient(proxyConfig.remoteLoginUri);
                CapsClient loginRequest = new CapsClient(new Uri("https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi"));
                OSD response = null;
                loginRequest.OnComplete += new CapsClient.CompleteCallback(
                    delegate(CapsClient client, OSD result, Exception error)
                    {
                        if (error == null) {
                            if (result != null && result.Type == OSDType.Map) {
                                response = result;
                            }
                        }
                        remoteComplete.Set();
                    }
                    );
                loginRequest.StartRequest(content, "application/xml"); //xml+llsd
                remoteComplete.WaitOne(30000, false);

                if (response == null) {
                    byte[] wr = Encoding.ASCII.GetBytes("HTTP/1.0 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n");
                    netStream.Write(wr, 0, wr.Length);
                    return;
                }

                OSDMap map = (OSDMap)response;

                OSD llsd;
                string sim_port = null, sim_ip = null, seed_capability = null;
                map.TryGetValue("sim_port", out llsd);
                if (llsd != null) sim_port = llsd.AsString();
                map.TryGetValue("sim_ip", out llsd);
                if (llsd != null) sim_ip = llsd.AsString();
                map.TryGetValue("seed_capability", out llsd);
                if (llsd != null) seed_capability = llsd.AsString();

                if (sim_port == null || sim_ip == null || seed_capability == null) {
                    byte[] wr = Encoding.ASCII.GetBytes("HTTP/1.0 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n");
                    netStream.Write(wr, 0, wr.Length);
                    return;
                }

                IPEndPoint realSim = new IPEndPoint(IPAddress.Parse(sim_ip), Convert.ToUInt16(sim_port));
                IPEndPoint fakeSim = ProxySim(realSim);
                map["sim_ip"] = OSD.FromString(fakeSim.Address.ToString());
                map["sim_port"] = OSD.FromInteger(fakeSim.Port);
                activeCircuit = realSim;

                // start a new proxy session
                Reset();

                CapInfo info = new CapInfo(seed_capability, activeCircuit, "SeedCapability");
                info.AddDelegate(new CapsDelegate(FixupSeedCapsResponse));

                KnownCaps[seed_capability] = info;
                map["seed_capability"] = OSD.FromString(loginURI + seed_capability);

                StreamWriter writer = new StreamWriter(netStream);
                writer.Write("HTTP/1.0 200 OK\r\n");
                writer.Write("Content-type: application/xml+llsd\r\n");
                writer.Write("\r\n");
                writer.Write(OSDParser.SerializeLLSDXmlString(response));
                writer.Close();
            }
        }
예제 #8
0
        private void GatherLastNamesResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                //LLSDMap respTable = (LLSDMap)response;

                //FIXME:
                //_lastNames = new List<LastName>(respTable.Count);

                //for (Dictionary<string, object>.Enumerator it = respTable.GetEnumerator(); it.MoveNext(); )
                //{
                //    LastName ln = new LastName();

                //    ln.ID = int.Parse(it.Current.Key.ToString());
                //    ln.Name = it.Current.Value.ToString();

                //    _lastNames.Add(ln);
                //}

                //_lastNames.Sort(new Comparison<LastName>(delegate(LastName a, LastName b) { return a.Name.CompareTo(b.Name); }));
            }
        }
예제 #9
0
        public bool CheckName(string firstName, LastName lastName)
        {
            if (Initializing)
                throw new InvalidOperationException("still initializing");

            if (_caps.CheckName == null)
                throw new InvalidOperationException("access denied; only approved developers have access to the registration api");

            // Create the POST data
            OSDMap query = new OSDMap();
            query.Add("username", OSD.FromString(firstName));
            query.Add("last_name_id", OSD.FromInteger(lastName.ID));
            //byte[] postData = OSDParser.SerializeXmlBytes(query);

            CapsClient request = new CapsClient(_caps.CheckName);
            request.OnComplete += new CapsClient.CompleteCallback(CheckNameResponse);
            request.StartRequest();

            // FIXME:
            return false;
        }
예제 #10
0
        private void GatherErrorMessagesResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                // parse

                //FIXME: wtf?
                //foreach (KeyValuePair<string, object> error in (Dictionary<string, object>)response)
                //{
                    //StringBuilder sb = new StringBuilder();

                    //sb.Append(error[1]);
                    //sb.Append(" (");
                    //sb.Append(error[0]);
                    //sb.Append("): ");
                    //sb.Append(error[2]);

                    //_errors.Add((int)error[0], sb.ToString());
                //}

                // finalize
                _initializing++;
            }
        }
예제 #11
0
        public void GatherLastNames()
        {
            if (Initializing)
                throw new InvalidOperationException("still initializing");

            if (_caps.GetLastNames == null)
                throw new InvalidOperationException("access denied: only approved developers have access to the registration api");

            CapsClient request = new CapsClient(_caps.GetLastNames);
            request.OnComplete += new CapsClient.CompleteCallback(GatherLastNamesResponse);
            request.StartRequest();

            // FIXME: Block
        }
예제 #12
0
        private void GatherErrorMessages()
        {
            if (_caps.GetErrorCodes == null)
                throw new InvalidOperationException("access denied");	// this should work even for not-approved users

            CapsClient request = new CapsClient(_caps.GetErrorCodes);
            request.OnComplete += new CapsClient.CompleteCallback(GatherErrorMessagesResponse);
            request.StartRequest();
        }
예제 #13
0
        private void GatherCapsResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                OSDMap respTable = (OSDMap)response;

                // parse
                _caps = new RegistrationCaps();

                _caps.CreateUser = respTable["create_user"].AsUri();
                _caps.CheckName = respTable["check_name"].AsUri();
                _caps.GetLastNames = respTable["get_last_names"].AsUri();
                _caps.GetErrorCodes = respTable["get_error_codes"].AsUri();

                // finalize
                _initializing++;

                GatherErrorMessages();
            }
        }
예제 #14
0
        private void GatherCaps()
        {
            // build post data
            byte[] postData = Encoding.ASCII.GetBytes(
                String.Format("first_name={0}&last_name={1}&password={2}", _userInfo.FirstName, _userInfo.LastName, 
                _userInfo.Password));

            CapsClient request = new CapsClient(RegistrationApiCaps);
            request.OnComplete += new CapsClient.CompleteCallback(GatherCapsResponse);
            request.StartRequest(postData);
        }
예제 #15
0
        private void UploadNotecardAssetResponse(CapsClient client, LLSD result, Exception error)
        {
            LLSDMap contents = (LLSDMap)result;
            KeyValuePair<NotecardUploadedAssetCallback, byte[]> kvp = (KeyValuePair<NotecardUploadedAssetCallback, byte[]>)(((object[])client.UserData)[0]);
            NotecardUploadedAssetCallback callback = kvp.Key;
            byte[] itemData = (byte[])kvp.Value;

            string status = contents["state"].AsString();

            if (status == "upload")
            {
                string uploadURL = contents["uploader"].AsString();

                // This makes the assumption that all uploads go to CurrentSim, to avoid
                // the problem of HttpRequestState not knowing anything about simulators
                CapsClient upload = new CapsClient(new Uri(uploadURL));
                upload.OnComplete += new CapsClient.CompleteCallback(UploadNotecardAssetResponse);
                upload.UserData = new object[2] { kvp, (UUID)(((object[])client.UserData)[1]) };
                upload.StartRequest(itemData, "application/octet-stream");
            }
            else if (status == "complete")
            {
                if (contents.ContainsKey("new_asset"))
                {
                    try { callback(true, String.Empty, (UUID)(((object[])client.UserData)[1]), contents["new_asset"].AsUUID()); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
                else
                {
                    try { callback(false, "Failed to parse asset and item UUIDs", UUID.Zero, UUID.Zero); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
            }
            else
            {
                // Failure
                try { callback(false, status, UUID.Zero, UUID.Zero); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
            }
        }
예제 #16
0
 private void CheckNameResponse(CapsClient client, OSD response, Exception error)
 {
     if (response.Type == OSDType.Boolean)
     {
         // FIXME:
         //(bool)response;
     }
     else
     {
         // FIXME:
     }
 }
예제 #17
0
        /// <summary>
        /// Moderate a chat session
        /// </summary>
        /// <param name="sessionID">the <see cref="UUID"/> of the session to moderate, for group chats this will be the groups UUID</param>
        /// <param name="memberID">the <see cref="UUID"/> of the avatar to moderate</param>
        /// <param name="moderateText">true to moderate (silence user), false to allow avatar to speak</param>
        public void ModerateChatSessions(UUID sessionID, UUID memberID, bool moderateText)
        {
            if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Caps == null)
                throw new Exception("ChatSessionRequest capability is not currently available");

            Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("ChatSessionRequest");

            if (url != null)
            {
                LLSDMap req = new LLSDMap();
                req.Add("method", LLSD.FromString("mute update"));

                LLSDMap mute_info = new LLSDMap();
                mute_info.Add("text", LLSD.FromBoolean(moderateText));

                LLSDMap parameters = new LLSDMap();
                parameters["agent_id"] = LLSD.FromUUID(memberID);
                parameters["mute_info"] = mute_info;

                req["params"] = parameters;

                req.Add("session-id", LLSD.FromUUID(sessionID));

                byte[] postData = StructuredData.LLSDParser.SerializeXmlBytes(req);

                CapsClient request = new CapsClient(url);
                request.StartRequest(postData);
            }
            else
            {
                throw new Exception("ChatSessionRequest capability is not currently available");
            }
        }
예제 #18
0
        /// <summary>
        /// Returns the new user ID or throws an exception containing the error code
        /// The error codes can be found here: https://wiki.secondlife.com/wiki/RegAPIError
        /// </summary>
        /// <param name="user">New user account to create</param>
        /// <returns>The Guid of the new user account</returns>
        public Guid CreateUser(CreateUserParam user)
        {
            if (Initializing)
                throw new InvalidOperationException("still initializing");

            if (_caps.CreateUser == null)
                throw new InvalidOperationException("access denied; only approved developers have access to the registration api");

            // Create the POST data
            OSDMap query = new OSDMap();
            query.Add("username", OSD.FromString(user.FirstName));
            query.Add("last_name_id", OSD.FromInteger(user.LastName.ID));
            query.Add("email", OSD.FromString(user.Email));
            query.Add("password", OSD.FromString(user.Password));
            query.Add("dob", OSD.FromString(user.Birthdate.ToString("yyyy-MM-dd")));

            if (user.LimitedToEstate != null)
                query.Add("limited_to_estate", OSD.FromInteger(user.LimitedToEstate.Value));

            if (!string.IsNullOrEmpty(user.StartRegionName))
                query.Add("start_region_name", OSD.FromInteger(user.LimitedToEstate.Value));

            if (user.StartLocation != null)
            {
                query.Add("start_local_x", OSD.FromReal(user.StartLocation.Value.X));
                query.Add("start_local_y", OSD.FromReal(user.StartLocation.Value.Y));
                query.Add("start_local_z", OSD.FromReal(user.StartLocation.Value.Z));
            }

            if (user.StartLookAt != null)
            {
                query.Add("start_look_at_x", OSD.FromReal(user.StartLookAt.Value.X));
                query.Add("start_look_at_y", OSD.FromReal(user.StartLookAt.Value.Y));
                query.Add("start_look_at_z", OSD.FromReal(user.StartLookAt.Value.Z));
            }

            //byte[] postData = OSDParser.SerializeXmlBytes(query);

            // Make the request
            CapsClient request = new CapsClient(_caps.CreateUser);
            request.OnComplete += new CapsClient.CompleteCallback(CreateUserResponse);
            request.StartRequest();

            // FIXME: Block
            return Guid.Empty;
        }
예제 #19
0
파일: Login.cs 프로젝트: RavenB/gridsearch
        private void LoginReplyHandler(CapsClient client, LLSD result, Exception error)
        {
            if (error == null)
            {
                if (result != null && result.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)result;

                    LLSD llsd;
                    string reason, message;

                    if (map.TryGetValue("reason", out llsd))
                        reason = llsd.AsString();
                    else
                        reason = String.Empty;

                    if (map.TryGetValue("message", out llsd))
                        message = llsd.AsString();
                    else
                        message = String.Empty;

                    if (map.TryGetValue("login", out llsd))
                    {
                        bool loginSuccess = llsd.AsBoolean();
                        bool redirect = (llsd.AsString() == "indeterminate");
                        LoginResponseData data = new LoginResponseData();

                        if (redirect)
                        {
                            // Login redirected

                            // Make the next login URL jump
                            UpdateLoginStatus(LoginStatus.Redirecting, message);

                            LoginParams loginParams = CurrentContext.Value;
                            loginParams.URI = LoginResponseData.ParseString("next_url", map);
                            //CurrentContext.Params.MethodName = LoginResponseData.ParseString("next_method", map);

                            // Sleep for some amount of time while the servers work
                            int seconds = (int)LoginResponseData.ParseUInt("next_duration", map);
                            Logger.Log("Sleeping for " + seconds + " seconds during a login redirect",
                                Helpers.LogLevel.Info);
                            Thread.Sleep(seconds * 1000);

                            // Ignore next_options for now
                            CurrentContext = loginParams;

                            BeginLogin();
                        }
                        else if (loginSuccess)
                        {
                            // Login succeeded

                            // Parse successful login replies into LoginResponseData structs
                            data.Parse(map);

                            // Fire the login callback
                            if (OnLoginResponse != null)
                            {
                                try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                                catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
                            }

                            // These parameters are stored in NetworkManager, so instead of registering
                            // another callback for them we just set the values here
                            CircuitCode = data.CircuitCode;
                            LoginSeedCapability = data.SeedCapability;

                            UpdateLoginStatus(LoginStatus.ConnectingToSim, "Connecting to simulator...");

                            ulong handle = Helpers.UIntsToLong(data.RegionX, data.RegionY);

                            if (data.SimIP != null && data.SimPort != 0)
                            {
                                // Connect to the sim given in the login reply
                                if (Connect(data.SimIP, data.SimPort, handle, true, LoginSeedCapability) != null)
                                {
                                    // Request the economy data right after login
                                    SendPacket(new EconomyDataRequestPacket());

                                    // Update the login message with the MOTD returned from the server
                                    UpdateLoginStatus(LoginStatus.Success, message);

                                    // Fire an event for connecting to the grid
                                    if (OnConnected != null)
                                    {
                                        try { OnConnected(this.Client); }
                                        catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                                    }
                                }
                                else
                                {
                                    UpdateLoginStatus(LoginStatus.Failed,
                                        "Unable to establish a UDP connection to the simulator");
                                }
                            }
                            else
                            {
                                UpdateLoginStatus(LoginStatus.Failed,
                                    "Login server did not return a simulator address");
                            }
                        }
                        else
                        {
                            // Login failed

                            // Make sure a usable error key is set
                            if (reason != String.Empty)
                                InternalErrorKey = reason;
                            else
                                InternalErrorKey = "unknown";

                            UpdateLoginStatus(LoginStatus.Failed, message);
                        }
                    }
                    else
                    {
                        // Got an LLSD map but no login value
                        UpdateLoginStatus(LoginStatus.Failed, "login parameter missing in the response");
                    }
                }
                else
                {
                    // No LLSD response
                    InternalErrorKey = "bad response";
                    UpdateLoginStatus(LoginStatus.Failed, "Empty or unparseable login response");
                }
            }
            else
            {
                // Connection error
                InternalErrorKey = "no connection";
                UpdateLoginStatus(LoginStatus.Failed, error.Message);
            }
        }
예제 #20
0
        private void CreateUserResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                // everything is okay
                // FIXME:
                //return new Guid(((Dictionary<string, object>)response)["agent_id"].ToString());
            }
            else
            {
                // an error happened
                OSDArray al = (OSDArray)response;

                StringBuilder sb = new StringBuilder();

                foreach (OSD ec in al)
                {
                    if (sb.Length > 0)
                        sb.Append("; ");

                    sb.Append(_errors[ec.AsInteger()]);
                }

                // FIXME:
                //throw new Exception("failed to create user: " + sb.ToString());
            }
        }
예제 #21
0
        private bool RequestVoiceInternal(string me, CapsClient.CompleteCallback callback, string capsName)
        {
            if (Enabled && Client.Network.Connected)
            {
                if (Client.Network.CurrentSim != null && Client.Network.CurrentSim.Caps != null)
                {
                    Uri url = Client.Network.CurrentSim.Caps.CapabilityURI(capsName);

                    if (url != null)
                    {
                        CapsClient request = new CapsClient(url);
                        OSDMap body = new OSDMap();
                        request.OnComplete += new CapsClient.CompleteCallback(callback);
                        request.StartRequest(body);

                        return true;
                    }
                    else
                    {
                        Logger.Log("VoiceManager." + me + "(): " + capsName + " capability is missing", 
                                   Helpers.LogLevel.Info, Client);
                        return false;
                    }
                }
            }

            Logger.Log("VoiceManager.RequestVoiceInternal(): Voice system is currently disabled", 
                       Helpers.LogLevel.Info, Client);
            return false;
            
        }
예제 #22
0
        private void CreateItemFromAssetResponse(CapsClient client, OSD result, Exception error)
        {
            object[] args = (object[])client.UserData;
            CapsClient.ProgressCallback progCallback = (CapsClient.ProgressCallback)args[0];
            ItemCreatedFromAssetCallback callback = (ItemCreatedFromAssetCallback)args[1];
            byte[] itemData = (byte[])args[2];

            if (result == null)
            {
                try { callback(false, error.Message, Guid.Empty, Guid.Empty); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                return;
            }

            OSDMap contents = (OSDMap)result;

            string status = contents["state"].AsString().ToLower();

            if (status == "upload")
            {
                string uploadURL = contents["uploader"].AsString();

                Logger.DebugLog("CreateItemFromAsset: uploading to " + uploadURL);

                // This makes the assumption that all uploads go to CurrentSim, to avoid
                // the problem of HttpRequestState not knowing anything about simulators
                CapsClient upload = new CapsClient(new Uri(uploadURL));
                upload.OnProgress += progCallback;
                upload.OnComplete += new CapsClient.CompleteCallback(CreateItemFromAssetResponse);
                upload.UserData = new object[] { null, callback, itemData };
                upload.StartRequest(itemData, "application/octet-stream");
            }
            else if (status == "complete")
            {
                Logger.DebugLog("CreateItemFromAsset: completed"); 

                if (contents.ContainsKey("new_inventory_item") && contents.ContainsKey("new_asset"))
                {
                    try { callback(true, String.Empty, contents["new_inventory_item"].AsGuid(), contents["new_asset"].AsGuid()); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
                else
                {
                    try { callback(false, "Failed to parse asset and item Guids", Guid.Empty, Guid.Empty); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
            }
            else
            {
                // Failure
                try { callback(false, status, Guid.Empty, Guid.Empty); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
            }
        }
예제 #23
0
        private void ParcelVoiceInfoResponse(CapsClient client, OSD response, Exception error)
        {
            if (response is OSDMap)
            {
                OSDMap respTable = (OSDMap)response;

                string regionName = respTable["region_name"].AsString();
                int localID = (int)respTable["parcel_local_id"].AsInteger();

                string channelURI = null;
                if (respTable["voice_credentials"] is OSDMap)
                {
                    OSDMap creds = (OSDMap)respTable["voice_credentials"];
                    channelURI = creds["channel_uri"].AsString();
                }
                
                if (OnParcelVoiceInfo != null) OnParcelVoiceInfo(regionName, localID, channelURI);
            }
        }
예제 #24
0
        public void RequestCreateItemFromAsset(byte[] data, string name, string description, AssetType assetType,
            InventoryType invType, UUID folderID, CapsClient.ProgressCallback progCallback, ItemCreatedFromAssetCallback callback)
        {
            if (_Network.CurrentSim == null || _Network.CurrentSim.Caps == null)
                throw new Exception("NewFileAgentInventory capability is not currently available");

            Uri url = _Network.CurrentSim.Caps.CapabilityURI("NewFileAgentInventory");

            if (url != null)
            {
                LLSDMap query = new LLSDMap();
                query.Add("folder_id", LLSD.FromUUID(folderID));
                query.Add("asset_type", LLSD.FromString(AssetTypeToString(assetType)));
                query.Add("inventory_type", LLSD.FromString(InventoryTypeToString(invType)));
                query.Add("name", LLSD.FromString(name));
                query.Add("description", LLSD.FromString(description));

                // Make the request
                CapsClient request = new CapsClient(url);
                request.OnComplete += new CapsClient.CompleteCallback(CreateItemFromAssetResponse);
                request.UserData = new object[] { progCallback, callback, data };

                request.StartRequest(query);
            }
            else
            {
                throw new Exception("NewFileAgentInventory capability is not currently available");
            }
        }
예제 #25
0
        private void MapLayerResponseHandler(CapsClient client, LLSD result, Exception error)
        {
            LLSDMap body = (LLSDMap)result;
            LLSDArray layerData = (LLSDArray)body["LayerData"];

            if (OnGridLayer != null)
            {
                for (int i = 0; i < layerData.Count; i++)
                {
                    LLSDMap thisLayerData = (LLSDMap)layerData[i];

                    GridLayer layer;
                    layer.Bottom = thisLayerData["Bottom"].AsInteger();
                    layer.Left = thisLayerData["Left"].AsInteger();
                    layer.Top = thisLayerData["Top"].AsInteger();
                    layer.Right = thisLayerData["Right"].AsInteger();
                    layer.ImageID = thisLayerData["ImageID"].AsUUID();

                    try { OnGridLayer(layer); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }
            }

            if (body.ContainsKey("MapBlocks"))
            {
                // TODO: At one point this will become activated
                Logger.Log("Got MapBlocks through CAPS, please finish this function!", Helpers.LogLevel.Error, Client);
            }
        }
예제 #26
0
파일: Caps.cs 프로젝트: RavenB/gridsearch
        private void MakeSeedRequest()
        {
            if (Simulator == null || !Simulator.Client.Network.Connected)
                return;

            // Create a request list
            LLSDArray req = new LLSDArray();
            req.Add("ChatSessionRequest");
            req.Add("CopyInventoryFromNotecard");
            req.Add("DispatchRegionInfo");
            req.Add("EstateChangeInfo");
            req.Add("EventQueueGet");
            req.Add("FetchInventoryDescendents");
            req.Add("GroupProposalBallot");
            req.Add("MapLayer");
            req.Add("MapLayerGod");
            req.Add("NewFileAgentInventory");
            req.Add("ParcelPropertiesUpdate");
            req.Add("ParcelVoiceInfoRequest");
            req.Add("ProvisionVoiceAccountRequest");
            req.Add("RemoteParcelRequest");
            req.Add("RequestTextureDownload");
            req.Add("SearchStatRequest");
            req.Add("SearchStatTracking");
            req.Add("SendPostcard");
            req.Add("SendUserReport");
            req.Add("SendUserReportWithScreenshot");
            req.Add("ServerReleaseNotes");
            req.Add("StartGroupProposal");
            req.Add("UpdateGestureAgentInventory");
            req.Add("UpdateNotecardAgentInventory");
            req.Add("UpdateScriptAgentInventory");
            req.Add("UpdateGestureTaskInventory");
            req.Add("UpdateNotecardTaskInventory");
            req.Add("UpdateScriptTaskInventory");
            req.Add("ViewerStartAuction");
            req.Add("UntrustedSimulatorMessage");
            req.Add("ViewerStats");

            _SeedRequest = new CapsClient(new Uri(_SeedCapsURI));
            _SeedRequest.OnComplete += new CapsClient.CompleteCallback(SeedRequestCompleteHandler);
            _SeedRequest.StartRequest(req);
        }