示例#1
0
            public static LightData FromLLSD(LLSD llsd)
            {
                LightData light = new LightData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    light.Color.FromLLSD(map["color"]);
                    light.Intensity = (float)map["intensity"].AsReal();
                    light.Radius    = (float)map["radius"].AsReal();
                    light.Cutoff    = (float)map["cutoff"].AsReal();
                    light.Falloff   = (float)map["falloff"].AsReal();
                }

                return(light);
            }
示例#2
0
            public static FlexibleData FromLLSD(LLSD llsd)
            {
                FlexibleData flex = new FlexibleData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    flex.Softness = map["simulate_lod"].AsInteger();
                    flex.Gravity  = (float)map["gravity"].AsReal();
                    flex.Drag     = (float)map["air_friction"].AsReal();
                    flex.Wind     = (float)map["wind_sensitivity"].AsReal();
                    flex.Tension  = (float)map["tension"].AsReal();
                    flex.Force.FromLLSD(map["user_force"]);
                }

                return(flex);
            }
示例#3
0
        private void GatherCapsResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                LLSDMap respTable = (LLSDMap)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();
            }
        }
示例#4
0
        private void GatherLastNamesResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                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); }));
            }
        }
示例#5
0
            public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber)
            {
                LLSDMap map = (LLSDMap)llsd;

                TextureEntryFace face = new TextureEntryFace(defaultFace);

                faceNumber      = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1;
                face.RGBA       = LLColor.FromLLSD(map["colors"]);
                face.RepeatU    = (float)map["scales"].AsReal();
                face.RepeatV    = (float)map["scalet"].AsReal();
                face.OffsetU    = (float)map["offsets"].AsReal();
                face.OffsetV    = (float)map["offsett"].AsReal();
                face.Rotation   = (float)map["imagerot"].AsReal();
                face.Bump       = (Bumpiness)map["bump"].AsInteger();
                face.Shiny      = (Shininess)map["shiny"].AsInteger();
                face.Fullbright = map["fullbright"].AsBoolean();
                face.MediaFlags = map["media_flags"].AsBoolean();
                face.TexMapType = (MappingType)map["mapping"].AsInteger();
                face.Glow       = (float)map["glow"].AsReal();
                face.TextureID  = map["imageid"].AsUUID();

                return(face);
            }
示例#6
0
        private void GatherErrorMessagesResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                // 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++;
            }
        }
示例#7
0
            public LLSD ToLLSD(int faceNumber)
            {
                LLSDMap tex = new LLSDMap(10);

                if (faceNumber >= 0)
                {
                    tex["face_number"] = LLSD.FromInteger(faceNumber);
                }
                tex["colors"]      = RGBA.ToLLSD();
                tex["scales"]      = LLSD.FromReal(RepeatU);
                tex["scalet"]      = LLSD.FromReal(RepeatV);
                tex["offsets"]     = LLSD.FromReal(OffsetU);
                tex["offsett"]     = LLSD.FromReal(OffsetV);
                tex["imagerot"]    = LLSD.FromReal(Rotation);
                tex["bump"]        = LLSD.FromInteger((int)Bump);
                tex["shiny"]       = LLSD.FromInteger((int)Shiny);
                tex["fullbright"]  = LLSD.FromBoolean(Fullbright);
                tex["media_flags"] = LLSD.FromInteger(Convert.ToInt32(MediaFlags));
                tex["mapping"]     = LLSD.FromInteger((int)TexMapType);
                tex["glow"]        = LLSD.FromReal(Glow);
                tex["imageid"]     = LLSD.FromUUID(TextureID);

                return(tex);
            }
示例#8
0
            public static SculptData FromLLSD(LLSD llsd)
            {
                SculptData sculpt = new SculptData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    sculpt.SculptTexture = map["texture"].AsUUID();
                    sculpt.Type = (SculptType)map["type"].AsInteger();
                }

                return sculpt;
            }
        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, LLUUID.Zero, LLUUID.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); }
                }
                else
                {
                    try { callback(false, "Failed to parse asset and item UUIDs", LLUUID.Zero, LLUUID.Zero); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
                }
            }
            else
            {
                // Failure
                try { callback(false, status, LLUUID.Zero, LLUUID.Zero); }
                catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, _Client, e); }
            }
        }
示例#10
0
 /// <summary>
 /// Group Chat event handler
 /// </summary>
 /// <param name="capsKey">The capability Key</param>
 /// <param name="llsd"></param>
 /// <param name="simulator"></param>
 private void ChatterBoxSessionEventHandler(string capsKey, LLSD llsd, Simulator simulator)
 {
     LLSDMap map = (LLSDMap)llsd;
     if (map["success"].AsBoolean() != true)
     {
         Client.Log("Attempt to send group chat to non-existant session for group " + map["session_id"].AsString(), Helpers.LogLevel.Info);
     }
 }
示例#11
0
        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();

                        // Parse successful login replies in to LoginResponseData structs
                        if (loginSuccess)
                            data.Parse(map);

                        if (OnLoginResponse != null)
                        {
                            try { OnLoginResponse(loginSuccess, redirect, message, reason, data); }
                            catch (Exception ex) { Client.Log(ex.ToString(), Helpers.LogLevel.Error); }
                        }

                        if (loginSuccess && !redirect)
                        {
                            // Login succeeded

                            // 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) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                                    }
                                }
                                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 if (redirect)
                        {
                            // Login redirected

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

                            LoginParams loginParams = CurrentContext.Value;
                            loginParams.URI = LoginResponseData.ParseString("next_url", map);
                            //CurrentContext.Params.MethodName = LoginResponseData.ParseString("next_method", map);
                            // Ignore next_options and next_duration for now
                            CurrentContext = loginParams;

                            BeginLogin();
                        }
                        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
                    UpdateLoginStatus(LoginStatus.Failed, "Empty or unparseable login response");
                }
            }
            else
            {
                // Connection error
                UpdateLoginStatus(LoginStatus.Failed, error.Message);
            }
        }
示例#12
0
        public static Primitive FromLLSD(LLSD llsd)
        {
            Primitive prim = new Primitive();

            LLObject.ObjectData data = new ObjectData();

            LLSDMap map     = (LLSDMap)llsd;
            LLSDMap volume  = (LLSDMap)map["volume"];
            LLSDMap path    = (LLSDMap)volume["path"];
            LLSDMap profile = (LLSDMap)volume["profile"];

            #region Path/Profile

            data.PathBegin        = (float)path["begin"].AsReal();
            data.PathCurve        = (PathCurve)path["curve"].AsInteger();
            data.PathEnd          = (float)path["end"].AsReal();
            data.PathRadiusOffset = (float)path["radius_offset"].AsReal();
            data.PathRevolutions  = (float)path["revolutions"].AsReal();
            data.PathScaleX       = (float)path["scale_x"].AsReal();
            data.PathScaleY       = (float)path["scale_y"].AsReal();
            data.PathShearX       = (float)path["shear_x"].AsReal();
            data.PathShearY       = (float)path["shear_y"].AsReal();
            data.PathSkew         = (float)path["skew"].AsReal();
            data.PathTaperX       = (float)path["taper_x"].AsReal();
            data.PathTaperY       = (float)path["taper_y"].AsReal();
            data.PathTwist        = (float)path["twist"].AsReal();
            data.PathTwistBegin   = (float)path["twist_begin"].AsReal();

            data.ProfileBegin  = (float)profile["begin"].AsReal();
            data.ProfileCurve  = (ProfileCurve)profile["curve"].AsInteger();
            data.ProfileHole   = (HoleType)profile["hole"].AsInteger();
            data.ProfileEnd    = (float)profile["end"].AsReal();
            data.ProfileHollow = (float)profile["hollow"].AsReal();

            #endregion Path/Profile

            prim.Data = data;

            if (map["phantom"].AsBoolean())
            {
                prim.Flags |= ObjectFlags.Phantom;
            }

            if (map["physical"].AsBoolean())
            {
                prim.Flags |= ObjectFlags.Physics;
            }

            if (map["shadows"].AsBoolean())
            {
                prim.Flags |= ObjectFlags.CastShadows;
            }

            prim.ParentID = (uint)map["parentid"].AsInteger();
            prim.Position.FromLLSD(map["position"]);
            prim.Rotation.FromLLSD(map["rotation"]);
            prim.Scale.FromLLSD(map["scale"]);
            prim.Data.Material = (MaterialType)map["material"].AsInteger();
            prim.Flexible      = FlexibleData.FromLLSD(map["flex"]);
            prim.Light         = LightData.FromLLSD(map["light"]);
            prim.Sculpt        = SculptData.FromLLSD(map["sculpt"]);
            prim.Textures      = TextureEntry.FromLLSD(map["textures"]);
            if (!string.IsNullOrEmpty(map["name"].AsString()))
            {
                prim.Properties.Name = map["name"].AsString();
            }

            if (!string.IsNullOrEmpty(map["description"].AsString()))
            {
                prim.Properties.Description = map["description"].AsString();
            }

            return(prim);
        }
示例#13
0
        /// <summary>
        /// ParcelProperties replies sent over CAPS
        /// </summary>
        /// <param name="capsKey">Not used (will always be ParcelProperties)</param>
        /// <param name="llsd">LLSD Structured data</param>
        /// <param name="simulator">Object representing simulator</param>
        private void ParcelPropertiesReplyHandler(string capsKey, LLSD llsd, Simulator simulator)
        {

            if (OnParcelProperties != null || Client.Settings.PARCEL_TRACKING == true)
            {

                LLSDMap map = (LLSDMap)llsd;
                LLSDMap parcelDataBlock = (LLSDMap)(((LLSDArray)map["ParcelData"])[0]);
                LLSDMap ageVerifyBlock = (LLSDMap)(((LLSDArray)map["AgeVerificationBlock"])[0]);
                LLSDMap mediaDataBlock = (LLSDMap)(((LLSDArray)map["MediaData"])[0]);

                Parcel parcel = new Parcel(simulator, parcelDataBlock["LocalID"].AsInteger());

                parcel.AABBMax.FromLLSD(parcelDataBlock["AABBMax"]);
                parcel.AABBMin.FromLLSD(parcelDataBlock["AABBMin"]);
                parcel.Area = parcelDataBlock["Area"].AsInteger();
                parcel.AuctionID = (uint)parcelDataBlock["AuctionID"].AsInteger();
                parcel.AuthBuyerID = parcelDataBlock["AuthBuyerID"].AsUUID();
                parcel.Bitmap = parcelDataBlock["Bitmap"].AsBinary();
                parcel.Category = (Parcel.ParcelCategory)parcelDataBlock["Category"].AsInteger();
                parcel.ClaimDate = Helpers.UnixTimeToDateTime((uint)parcelDataBlock["ClaimDate"].AsInteger());
                parcel.ClaimPrice = parcelDataBlock["ClaimPrice"].AsInteger();
                parcel.Desc = parcelDataBlock["Desc"].AsString();
                
                // TODO: this probably needs to happen when the packet is deserialized.
                byte[] bytes = parcelDataBlock["ParcelFlags"].AsBinary();
                if (BitConverter.IsLittleEndian)
                    Array.Reverse(bytes);
                parcel.Flags = (Parcel.ParcelFlags)BitConverter.ToUInt32(bytes, 0);
                parcel.GroupID = parcelDataBlock["GroupID"].AsUUID();
                parcel.GroupPrims = parcelDataBlock["GroupPrims"].AsInteger();
                parcel.IsGroupOwned = parcelDataBlock["IsGroupOwned"].AsBoolean();
                parcel.LandingType = (byte)parcelDataBlock["LandingType"].AsInteger();
                parcel.LocalID = parcelDataBlock["LocalID"].AsInteger();
                parcel.MaxPrims = parcelDataBlock["MaxPrims"].AsInteger();
                parcel.MediaAutoScale = (byte)parcelDataBlock["MediaAutoScale"].AsInteger();
                parcel.MediaID = parcelDataBlock["MediaID"].AsUUID();
                parcel.MediaURL = parcelDataBlock["MediaURL"].AsString();
                parcel.MusicURL = parcelDataBlock["MusicURL"].AsString();
                parcel.Name = parcelDataBlock["Name"].AsString();
                parcel.OtherCleanTime = parcelDataBlock["OtherCleanTime"].AsInteger();
                parcel.OtherCount = parcelDataBlock["OtherCount"].AsInteger();
                parcel.OtherPrims = parcelDataBlock["OtherPrims"].AsInteger();
                parcel.OwnerID = parcelDataBlock["OwnerID"].AsUUID();
                parcel.OwnerPrims = parcelDataBlock["OwnerPrims"].AsInteger();
                parcel.ParcelPrimBonus = (float)parcelDataBlock["ParcelPrimBonus"].AsReal();
                parcel.PassHours = (float)parcelDataBlock["PassHours"].AsReal();
                parcel.PassPrice = parcelDataBlock["PassPrice"].AsInteger();
                parcel.PublicCount = parcelDataBlock["PublicCount"].AsInteger();
                parcel.RegionDenyAgeUnverified = ageVerifyBlock["RegionDenyAgeUnverified"].AsBoolean();
                parcel.RegionDenyAnonymous = parcelDataBlock["RegionDenyAnonymous"].AsBoolean();
                parcel.RegionPushOverride = parcelDataBlock["RegionPushOverride"].AsBoolean();
                parcel.RentPrice = parcelDataBlock["RentPrice"].AsInteger();
                parcel.RequestResult = parcelDataBlock["RequestResult"].AsInteger();
                parcel.SalePrice = parcelDataBlock["SalePrice"].AsInteger();
                parcel.SelectedPrims = parcelDataBlock["SelectedPrims"].AsInteger();
                parcel.SelfCount = parcelDataBlock["SelfCount"].AsInteger();
                parcel.SequenceID = parcelDataBlock["SequenceID"].AsInteger();
                parcel.Simulator = simulator;
                parcel.SimWideMaxPrims = parcelDataBlock["SimWideMaxPrims"].AsInteger();
                parcel.SimWideTotalPrims = parcelDataBlock["SimWideTotalPrims"].AsInteger();
                parcel.SnapSelection = parcelDataBlock["SnapSelection"].AsBoolean();
                parcel.SnapshotID = parcelDataBlock["SnapshotID"].AsUUID();
                parcel.Status = (Parcel.ParcelStatus)parcelDataBlock["Status"].AsInteger();
                parcel.TotalPrims = parcelDataBlock["TotalPrims"].AsInteger();
                parcel.UserLocation.FromLLSD(parcelDataBlock["UserLocation"]);
                parcel.UserLookAt.FromLLSD(parcelDataBlock["UserLookAt"]);
                parcel.MediaDesc = mediaDataBlock["MediaDesc"].AsString();
                parcel.MediaHeight = mediaDataBlock["MediaHeight"].AsInteger();
                parcel.MediaWidth = mediaDataBlock["MediaWidth"].AsInteger();
                parcel.MediaLoop = mediaDataBlock["MediaLoop"].AsBoolean();
                parcel.MediaType = mediaDataBlock["MediaType"].AsString();
                parcel.ObscureMedia = mediaDataBlock["ObscureMedia"].AsBoolean();
                parcel.ObscureMusic = mediaDataBlock["ObscureMusic"].AsBoolean();

                if (Client.Settings.PARCEL_TRACKING)
                {
                    lock (simulator.Parcels.Dictionary)
                        simulator.Parcels.Dictionary[parcel.LocalID] = parcel;

                    int y, x, index, bit;
                    for (y = 0; y < simulator.ParcelMap.GetLength(0); y++)
                    {
                        for (x = 0; x < simulator.ParcelMap.GetLength(1); x++)
                        {
                            if (simulator.ParcelMap[y, x] == 0)
                            {
                                index = (y * 64) + x;
                                bit = index % 8;
                                index >>= 3;

                                if ((parcel.Bitmap[index] & (1 << bit)) != 0)
                                    simulator.ParcelMap[y, x] = parcel.LocalID;
                            }
                        }

                    }
                }

                // auto request acl, will be stored in parcel tracking dictionary if enabled
                if (Client.Settings.ALWAYS_REQUEST_PARCEL_ACL)
                    Client.Parcels.AccessListRequest(simulator, parcel.LocalID,
                        AccessList.Both, parcel.SequenceID);

                // auto request dwell, will be stored in parcel tracking dictionary if enables
                if (Client.Settings.ALWAYS_REQUEST_PARCEL_DWELL)
                    Client.Parcels.DwellRequest(simulator, parcel.LocalID);

                // Fire the callback for parcel properties being received
                if (OnParcelProperties != null)
                {
                    try
                    {
                        OnParcelProperties(parcel, (ParcelResult)parcel.RequestResult,
                          parcel.SequenceID, parcel.SnapSelection);
                    }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }

                // Check if all of the simulator parcels have been retrieved, if so fire another callback
                if (OnSimParcelsDownloaded != null && simulator.IsParcelMapFull())
                {
                    try { OnSimParcelsDownloaded(simulator, simulator.Parcels, simulator.ParcelMap); }
                    catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); }
                }
            }
        }
示例#14
0
        public void Parse(LLSDMap reply)
        {
            try
            {
                AgentID         = ParseUUID("agent_id", reply);
                SessionID       = ParseUUID("session_id", reply);
                SecureSessionID = ParseUUID("secure_session_id", reply);
                FirstName       = ParseString("first_name", reply).Trim('"');
                LastName        = ParseString("last_name", reply).Trim('"');
                StartLocation   = ParseString("start_location", reply);
                AgentAccess     = ParseString("agent_access", reply);
                LookAt          = ParseLLVector3("look_at", reply);
            }
            catch (LLSDException e)
            {
                // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]'
                // need to handle that somehow
                Logger.DebugLog("login server returned (some) invalid data: " + e.Message);
            }

            // Home
            LLSDMap home     = null;
            LLSD    llsdHome = LLSDParser.DeserializeNotation(reply["home"].AsString());

            if (llsdHome.Type == LLSDType.Map)
            {
                home = (LLSDMap)llsdHome;

                LLSD homeRegion;
                if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array)
                {
                    LLSDArray homeArray = (LLSDArray)homeRegion;
                    if (homeArray.Count == 2)
                    {
                        HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger());
                    }
                    else
                    {
                        HomeRegion = 0;
                    }
                }

                HomePosition = ParseLLVector3("position", home);
                HomeLookAt   = ParseLLVector3("look_at", home);
            }
            else
            {
                HomeRegion   = 0;
                HomePosition = LLVector3.Zero;
                HomeLookAt   = LLVector3.Zero;
            }

            CircuitCode = ParseUInt("circuit_code", reply);
            RegionX     = ParseUInt("region_x", reply);
            RegionY     = ParseUInt("region_y", reply);
            SimPort     = (ushort)ParseUInt("sim_port", reply);
            string simIP = ParseString("sim_ip", reply);

            IPAddress.TryParse(simIP, out SimIP);
            SeedCapability = ParseString("seed_capability", reply);

            // Buddy list
            LLSD buddyLLSD;

            if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array)
            {
                LLSDArray buddyArray = (LLSDArray)buddyLLSD;
                BuddyList = new FriendInfo[buddyArray.Count];

                for (int i = 0; i < buddyArray.Count; i++)
                {
                    if (buddyArray[i].Type == LLSDType.Map)
                    {
                        LLSDMap buddy = (LLSDMap)buddyArray[i];
                        BuddyList[i] = new FriendInfo(
                            ParseUUID("buddy_id", buddy),
                            (FriendRights)ParseUInt("buddy_rights_given", buddy),
                            (FriendRights)ParseUInt("buddy_rights_has", buddy));
                    }
                }
            }

            SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply));
            InventoryRoot     = ParseMappedUUID("inventory-root", "folder_id", reply);
            InventorySkeleton = ParseInventoryFolders("inventory-skeleton", AgentID, reply);
            LibraryRoot       = ParseMappedUUID("inventory-lib-root", "folder_id", reply);
            LibraryOwner      = ParseMappedUUID("inventory-lib-owner", "agent_id", reply);
            LibrarySkeleton   = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply);
        }
 private void CheckNameResponse(CapsClient client, LLSD response, Exception error)
 {
     if (response.Type == LLSDType.Boolean)
     {
         // FIXME:
         //(bool)response;
     }
     else
     {
         // FIXME:
     }
 }
        private void GatherLastNamesResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                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); }));
            }
        }
        private void GatherErrorMessagesResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                // 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++;
            }
        }
        private void GatherCapsResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                LLSDMap respTable = (LLSDMap)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();
            }
        }
示例#19
0
        private void ProvisionCapsResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                LLSDMap respTable = (LLSDMap)response;

                if (OnProvisionAccount != null)
                {
                    try { OnProvisionAccount(respTable["username"].AsString(), respTable["password"].AsString()); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }
示例#20
0
        private void RequiredVoiceVersionEventHandler(string message, LLSD llsd, Simulator simulator)
        {
            LLSDMap body = (LLSDMap)llsd;

            if (body.ContainsKey("major_version"))
            {
                int majorVersion = body["major_version"].AsInteger();

                if (VOICE_MAJOR_VERSION != majorVersion)
                {
                    Client.Log(String.Format("Voice version mismatch! Got {0}, expecting {1}. Disabling the voice manager",
                        majorVersion, VOICE_MAJOR_VERSION), Helpers.LogLevel.Error);
                    Enabled = false;
                }
                else
                {
                    Client.DebugLog("Voice version " + majorVersion + " verified");
                }
            }
        }
示例#21
0
        private void ParcelVoiceInfoResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                LLSDMap respTable = (LLSDMap)response;

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

                string channelURI = null;
                if (respTable["voice_credentials"] is LLSDMap) {
                    LLSDMap creds = (LLSDMap)respTable["voice_credentials"];
                    channelURI = creds["channel_uri"].AsString();
                }
                
                if (OnParcelVoiceInfo != null) OnParcelVoiceInfo(regionName, localID, channelURI);
            }
        }
示例#22
0
        public static Primitive FromLLSD(LLSD llsd)
        {
            Primitive prim = new Primitive();
            LLObject.ObjectData data = new ObjectData();

            LLSDMap map = (LLSDMap)llsd;
            LLSDMap volume = (LLSDMap)map["volume"];
            LLSDMap path = (LLSDMap)volume["path"];
            LLSDMap profile = (LLSDMap)volume["profile"];

            #region Path/Profile

            data.PathBegin = (float)path["begin"].AsReal();
            data.PathCurve = (PathCurve)path["curve"].AsInteger();
            data.PathEnd = (float)path["end"].AsReal();
            data.PathRadiusOffset = (float)path["radius_offset"].AsReal();
            data.PathRevolutions = (float)path["revolutions"].AsReal();
            data.PathScaleX = (float)path["scale_x"].AsReal();
            data.PathScaleY = (float)path["scale_y"].AsReal();
            data.PathShearX = (float)path["shear_x"].AsReal();
            data.PathShearY = (float)path["shear_y"].AsReal();
            data.PathSkew = (float)path["skew"].AsReal();
            data.PathTaperX = (float)path["taper_x"].AsReal();
            data.PathTaperY = (float)path["taper_y"].AsReal();
            data.PathTwist = (float)path["twist"].AsReal();
            data.PathTwistBegin = (float)path["twist_begin"].AsReal();

            data.ProfileBegin = (float)profile["begin"].AsReal();
            data.ProfileCurve = (ProfileCurve)profile["curve"].AsInteger();
            data.ProfileHole = (HoleType)profile["hole"].AsInteger();
            data.ProfileEnd = (float)profile["end"].AsReal();
            data.ProfileHollow = (float)profile["hollow"].AsReal();

            #endregion Path/Profile

            prim.Data = data;
            
            if (map["phantom"].AsBoolean())
                prim.Flags |= ObjectFlags.Phantom;

            if (map["physical"].AsBoolean())
                prim.Flags |= ObjectFlags.Physics;

            if (map["shadows"].AsBoolean())
                prim.Flags |= ObjectFlags.CastShadows;

            prim.ParentID = (uint)map["parentid"].AsInteger();
            prim.Position.FromLLSD(map["position"]);
            prim.Rotation.FromLLSD(map["rotation"]);
            prim.Scale.FromLLSD(map["scale"]);
            prim.Data.Material = (MaterialType)map["material"].AsInteger();
            prim.Flexible = FlexibleData.FromLLSD(map["flex"]);
            prim.Light = LightData.FromLLSD(map["light"]);
            prim.Sculpt = SculptData.FromLLSD(map["sculpt"]);
            prim.Textures = TextureEntry.FromLLSD(map["textures"]);
            if (!string.IsNullOrEmpty(map["name"].AsString())) {
                prim.Properties.Name = map["name"].AsString();
            }

            if (!string.IsNullOrEmpty(map["description"].AsString())) {
                prim.Properties.Description = map["description"].AsString();
            }

            return prim;
        }
        private void CreateUserResponse(CapsClient client, LLSD response, Exception error)
        {
            if (response is LLSDMap)
            {
                // everything is okay
                // FIXME:
                //return new LLUUID(((Dictionary<string, object>)response)["agent_id"].ToString());
            }
            else
            {
                // an error happened
                LLSDArray al = (LLSDArray)response;

                StringBuilder sb = new StringBuilder();

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

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

                // FIXME:
                //throw new Exception("failed to create user: " + sb.ToString());
            }
        }
示例#24
0
        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!
            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");
        }
示例#25
0
 /// <summary>
 /// Group Chat event handler
 /// </summary>
 /// <param name="capsKey"></param>
 /// <param name="llsd"></param>
 /// <param name="simulator"></param>
 private void ChatterBoxSessionEventHandler(string capsKey, LLSD llsd, Simulator simulator)
 {
     // TODO: this appears to occur when you try and initiate group chat with an unopened session
     //       
     // Key=ChatterBoxSessionEventReply 
     // llsd={
     //    ("error": "generic")
     //    ("event": "message")
     //    ("session_id": "3dafea18-cda1-9813-d5f1-fd3de6b13f8c") // group uuid
     //    ("success": "0")}
     //LLSDMap map = (LLSDMap)llsd;
     //LLUUID groupUUID = map["session_id"].AsUUID();
     //Console.WriteLine("SessionEvent: Key={0} llsd={1}", capsKey, llsd.ToString());
 }
示例#26
0
        /// <summary>
        /// Someone joined or left group chat
        /// </summary>
        /// <param name="capsKey"></param>
        /// <param name="llsd"></param>
        /// <param name="simulator"></param>
        private void ChatterBoxSessionAgentListReplyHandler(string capsKey, LLSD llsd, Simulator simulator)
        {
            LLSDMap map = (LLSDMap)llsd;
            LLUUID sessionID = map["session_id"].AsUUID();
            LLSDMap update = (LLSDMap)map["updates"];
            string errormsg = map["error"].AsString();
            
            //if (errormsg.Equals("already in session"))
            //  return;

            foreach (KeyValuePair<string, LLSD> kvp in update)
            {
                if (kvp.Value.Equals("ENTER"))
                {
                    lock (GroupChatSessions.Dictionary)
                    {
                        if (!GroupChatSessions.Dictionary[sessionID].Contains((LLUUID)kvp.Key))
                            GroupChatSessions.Dictionary[sessionID].Add((LLUUID)kvp.Key);
                    }
                }
                else if (kvp.Value.Equals("LEAVE"))
                {
                    lock (GroupChatSessions.Dictionary)
                    {
                        if (GroupChatSessions.Dictionary[sessionID].Contains((LLUUID)kvp.Key))
                            GroupChatSessions.Dictionary[sessionID].Remove((LLUUID)kvp.Key);

                        // we left session, remove from dictionary
                        if (kvp.Key.Equals(Client.Self.id) && OnGroupChatLeft != null)
                        {
                            GroupChatSessions.Dictionary.Remove(sessionID);
                            OnGroupChatLeft(sessionID);
                        }
                    }
                }
            }
        }
示例#27
0
        public void FromLLSD(LLSD llsd)
        {
            if (llsd.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)llsd;

                if (array.Count == 3)
                {
                    X = (float)array[0].AsReal();
                    Y = (float)array[1].AsReal();
                    Z = (float)array[2].AsReal();

                    return;
                }
            }

            this = LLVector3.Zero;
        }
示例#28
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();
                }

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

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

                    _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();
            }
        }
示例#29
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) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }

            if (body.ContainsKey("MapBlocks"))
            {
                // TODO: At one point this will become activated
                Client.Log("Got MapBlocks through CAPS, please finish this function!", Helpers.LogLevel.Error);
            }
        }
示例#30
0
            public static TextureEntry FromLLSD(LLSD llsd)
            {
                LLSDArray array = (LLSDArray)llsd;
                LLSDMap faceLLSD;

                if (array.Count > 0)
                {
                    int faceNumber;
                    faceLLSD = (LLSDMap)array[0];
                    TextureEntryFace defaultFace = TextureEntryFace.FromLLSD(faceLLSD, null, out faceNumber);
                    TextureEntry te = new TextureEntry(defaultFace);

                    for (int i = 1; i < array.Count; i++)
                    {
                        TextureEntryFace tex = TextureEntryFace.FromLLSD(array[i], defaultFace, out faceNumber);
                        if (faceNumber >= 0 && faceNumber < te.FaceTextures.Length)
                            te.FaceTextures[faceNumber] = tex;
                    }

                    return te;
                }
                else
                {
                    throw new ArgumentException("LLSD contains no elements");
                }
            }
示例#31
0
        private void EstablishAgentCommunicationEventHandler(string message, LLSD llsd, Simulator simulator)
        {
            StructuredData.LLSDMap body = (StructuredData.LLSDMap)llsd;


            if (Client.Settings.MULTIPLE_SIMS && body.ContainsKey("sim-ip-and-port"))
            {
                string ipAndPort = body["sim-ip-and-port"].AsString();
                string[] pieces = ipAndPort.Split(':');
                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(pieces[0]), Convert.ToInt32(pieces[1]));
                Simulator sim = Client.Network.FindSimulator(endPoint);

                if (sim == null)
                {
                    Client.Log("Got EstablishAgentCommunication for unknown sim " + ipAndPort,
                        Helpers.LogLevel.Error);

                    // FIXME: Should we use this opportunity to connect to the simulator?
                }
                else
                {
                    Client.Log("Got EstablishAgentCommunication for " + sim.ToString(),
                        Helpers.LogLevel.Info);

                    sim.SetSeedCaps(body["seed-capability"].AsString());
                }
            }
        }
示例#32
0
        public void FromLLSD(LLSD llsd)
        {
            if (llsd.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)llsd;

                if (array.Count == 4)
                {
                    X = (float)array[0].AsReal();
                    Y = (float)array[1].AsReal();
                    Z = (float)array[2].AsReal();
                    W = (float)array[3].AsReal();

                    return;
                }
            }

            this = LLQuaternion.Identity;
        }
示例#33
0
        /// <summary>
        /// Response from request to join a group chat
        /// </summary>
        /// <param name="capsKey"></param>
        /// <param name="llsd"></param>
        /// <param name="simulator"></param>
        private void ChatterBoxSessionStartReplyHandler(string capsKey, LLSD llsd, Simulator simulator)
        {
            LLSDMap map = (LLSDMap)llsd;
            LLUUID sessionID = map["session_id"].AsUUID();
            LLUUID tmpSessionID = map["temp_session_id"].AsUUID();
            bool success = map["success"].AsBoolean();


            if (success)
            {
                LLSDArray agentlist = (LLSDArray)map["agents"];
                List<LLUUID> agents = new List<LLUUID>();
                foreach (LLSD id in agentlist)
                    agents.Add(id.AsUUID());

                lock (GroupChatSessions.Dictionary)
                {
                    if (GroupChatSessions.ContainsKey(sessionID))
                        GroupChatSessions.Dictionary[sessionID] = agents;
                    else
                        GroupChatSessions.Add(sessionID, agents);
                }
            }

            if (OnGroupChatJoin != null)
            {
                try { OnGroupChatJoin(sessionID, tmpSessionID, success); }
                catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
示例#34
0
        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();

                        // Parse successful login replies in to LoginResponseData structs
                        if (loginSuccess)
                        {
                            data.Parse(map);
                        }

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

                        if (loginSuccess && !redirect)
                        {
                            // Login succeeded

                            // 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 if (redirect)
                        {
                            // Login redirected

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

                            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
                        {
                            // 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);
            }
        }
示例#35
0
        /// <summary>
        /// Group Chat Request
        /// </summary>
        /// <param name="capsKey">Caps Key</param>
        /// <param name="llsd">LLSD Map containing invitation</param>
        /// <param name="simulator">Originating Simulator</param>
        private void ChatterBoxInvitationHandler(string capsKey, LLSD llsd, Simulator simulator)
        {       
                if (OnInstantMessage != null)
                {
                    LLSDMap map = (LLSDMap)llsd;
                    LLSDMap im = (LLSDMap)map["instantmessage"];
                    LLSDMap agent = (LLSDMap)im["agent_params"];
                    LLSDMap msg = (LLSDMap)im["message_params"];
                    LLSDMap msgdata = (LLSDMap)msg["data"];

                    InstantMessage message = new InstantMessage();
                    
                    message.FromAgentID = map["from_id"].AsUUID();
                    message.FromAgentName = map["from_name"].AsString();
                    message.ToAgentID = msg["to_id"].AsString();
                    message.ParentEstateID = (uint)msg["parent_estate_id"].AsInteger();
                    message.RegionID = msg["region_id"].AsUUID();
                    message.Position.FromLLSD(msg["position"]);
                    message.Dialog = (InstantMessageDialog)msgdata["type"].AsInteger();
                    message.GroupIM = true;
                    message.IMSessionID = map["session_id"].AsUUID();
                    message.Timestamp = new DateTime(msgdata["timestamp"].AsInteger());
                    message.Message = msg["message"].AsString();
                    message.Offline = (InstantMessageOnline)msg["offline"].AsInteger();
                    message.BinaryBucket = msg["binary_bucket"].AsBinary();

                    try { OnInstantMessage(message, simulator); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }             
        }
示例#36
0
            public static FlexibleData FromLLSD(LLSD llsd)
            {
                FlexibleData flex = new FlexibleData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    flex.Softness = map["simulate_lod"].AsInteger();
                    flex.Gravity = (float)map["gravity"].AsReal();
                    flex.Drag = (float)map["air_friction"].AsReal();
                    flex.Wind = (float)map["wind_sensitivity"].AsReal();
                    flex.Tension = (float)map["tension"].AsReal();
                    flex.Force.FromLLSD(map["user_force"]);
                }

                return flex;
            }
示例#37
0
            public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber)
            {
                LLSDMap map = (LLSDMap)llsd;

                TextureEntryFace face = new TextureEntryFace(defaultFace);
                faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1;
                face.RGBA = LLColor.FromLLSD(map["colors"]);
                face.RepeatU = (float)map["scales"].AsReal();
                face.RepeatV = (float)map["scalet"].AsReal();
                face.OffsetU = (float)map["offsets"].AsReal();
                face.OffsetV = (float)map["offsett"].AsReal();
                face.Rotation = (float)map["imagerot"].AsReal();
                face.Bump = (Bumpiness)map["bump"].AsInteger();
                face.Shiny = (Shininess)map["shiny"].AsInteger();
                face.Fullbright = map["fullbright"].AsBoolean();
                face.MediaFlags = map["media_flags"].AsBoolean();
                face.TexMapType = (MappingType)map["mapping"].AsInteger();
                face.Glow = (float)map["glow"].AsReal();
                face.TextureID = map["imageid"].AsUUID();

                return face;
            }
示例#38
0
            public static LightData FromLLSD(LLSD llsd)
            {
                LightData light = new LightData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    light.Color.FromLLSD(map["color"]);
                    light.Intensity = (float)map["intensity"].AsReal();
                    light.Radius = (float)map["radius"].AsReal();
                    light.Cutoff = (float)map["cutoff"].AsReal();
                    light.Falloff = (float)map["falloff"].AsReal();
                }

                return light;
            }
示例#39
0
        private void CreateItemFromAssetResponse(CapsClient client, LLSD result, Exception error)
        {
            LLSDMap contents = (LLSDMap)result;
            KeyValuePair<ItemCreatedFromAssetCallback, byte[]> kvp = (KeyValuePair<ItemCreatedFromAssetCallback, byte[]>)client.UserData;
            ItemCreatedFromAssetCallback 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(CreateItemFromAssetResponse);
                upload.UserData = kvp;
                upload.StartRequest(itemData, "application/octet-stream");
            }
            else if (status == "complete")
            {
                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) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
                else
                {
                    try { callback(false, "Failed to parse asset and item UUIDs", LLUUID.Zero, LLUUID.Zero); }
                    catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
            else
            {
                // Failure
                try { callback(false, status, LLUUID.Zero, LLUUID.Zero); }
                catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); }
            }
        }
示例#40
0
        public void FromLLSD(LLSD llsd)
        {
            if (llsd.Type == LLSDType.Array)
            {
                LLSDArray array = (LLSDArray)llsd;

                if (array.Count == 4)
                {
                    R = (float)array[0].AsReal();
                    G = (float)array[1].AsReal();
                    B = (float)array[2].AsReal();
                    A = (float)array[3].AsReal();

                    return;
                }
            }

            this = LLColor.Black;
        }