/// <summary> /// </summary> /// <param name="client"></param> /// <param name="ctype">The type of Cache system to use for images.</param> /// <param name="directory">The directory to use for disk based caching.</param> private void Init(SecondLife client, CacheTypes ctype, string directory) { slClient = client; // Setup Image Caching CacheType = ctype; if (ctype == CacheTypes.Disk) { if (directory != null) { CacheDirectory = directory; } try { if (!Directory.Exists(CacheDirectory)) { Directory.CreateDirectory(CacheDirectory); } } catch (Exception e) { slClient.Log("Disk Cache directory could not be established, defaulting to Memory Cache: " + Environment.NewLine + e.ToString(), Helpers.LogLevel.Warning); CacheType = CacheTypes.Memory; } } // Image Packet Helpers ImagePacketHelper = new ImagePacketHelpers(client); // Image Callbacks slClient.Network.RegisterCallback(PacketType.ImageData, new NetworkManager.PacketCallback(ImageDataCallbackHandler)); slClient.Network.RegisterCallback(PacketType.ImagePacket, new NetworkManager.PacketCallback(ImagePacketCallbackHandler)); slClient.Network.RegisterCallback(PacketType.ImageNotInDatabase, new NetworkManager.PacketCallback(ImageNotInDatabaseCallbackHandler)); }
/// <summary> /// Add the specified wearables to your outfit, replace existing ones if nessesary. /// </summary> /// <param name="wearables"></param> public void Wear(List <InventoryWearable> wearables) { // Make sure we have some Wearable Data to start with. if (AgentWearablesSignal.WaitOne(1000, false) == false) { Client.Log("You must have set appearance at least once, before calling Wear(). AgentWearablesSignal not set.", Helpers.LogLevel.Error); return; } // Update with specified wearables foreach (InventoryWearable iw in wearables) { byte type = (byte)((AssetWearable)iw.Asset).AppearanceLayer; AgentWearablesData[type].ItemID = iw.ItemID; AgentWearablesData[type].AssetID = iw.AssetID; } // Create AgentIsNowWearing Packet, and send it SendAgentIsNowWearing(); // Update local Appearance Info GetAvatarAppearanceInfoFromWearableAssets(); // Send updated AgentSetAppearance to the grid BeginAgentSendAppearance(); }
public static bool PersistentLogin(SecondLife client, string firstName, string lastName, string password, string userAgent, string start, string author) { int unknownLogins = 0; Start: if (client.Network.Login(firstName, lastName, password, userAgent, start, author)) { client.Log("Logged in to " + client.Network.CurrentSim, Helpers.LogLevel.Info); return true; } else { if (client.Network.LoginErrorKey == "god") { client.Log("Grid is down, waiting 10 minutes", Helpers.LogLevel.Warning); LoginWait(10); goto Start; } else if (client.Network.LoginErrorKey == "key") { client.Log("Bad username or password, giving up on login", Helpers.LogLevel.Error); return false; } else if (client.Network.LoginErrorKey == "presence") { client.Log("Server is still logging us out, waiting 1 minute", Helpers.LogLevel.Warning); LoginWait(1); goto Start; } else if (client.Network.LoginErrorKey == "disabled") { client.Log("This account has been banned! Giving up on login", Helpers.LogLevel.Error); return false; } else if (client.Network.LoginErrorKey == "timed out") { client.Log("Login request timed out, waiting 1 minute", Helpers.LogLevel.Warning); LoginWait(1); goto Start; } else { ++unknownLogins; if (unknownLogins < 5) { client.Log("Unknown login error, waiting 2 minutes: " + client.Network.LoginErrorKey, Helpers.LogLevel.Warning); LoginWait(2); goto Start; } else { client.Log("Too many unknown login error codes, giving up", Helpers.LogLevel.Error); return false; } } } }
public void DownloadSimParcels(Simulator simulator) { if (simulator == null) { Client.Log("DownloadSimParcels() will not work with a null simulator", Helpers.LogLevel.Error); return; } lock (active_sims) { if (active_sims.Contains(simulator)) { Client.Log("DownloadSimParcels(" + simulator + ") called more than once?", Helpers.LogLevel.Error); return; } active_sims.Add(simulator); } lock (ParcelMarked) { if (!ParcelMarked.ContainsKey(simulator)) { ParcelMarked[simulator] = new int[64, 64]; Parcels[simulator] = new Dictionary<int, Parcel>(); } } Client.Parcels.PropertiesRequest(simulator, 0.0f, 0.0f, 0.0f, 0.0f, 0, false); }
public int RequestCaptureDevices() { if (_DaemonPipe.Connected) { _DaemonPipe.SendData(Encoding.ASCII.GetBytes(String.Format( "<Request requestId=\"{0}\" action=\"Aux.GetCaptureDevices.1\"></Request>{1}", _CommandCookie++, REQUEST_TERMINATOR))); return(_CommandCookie - 1); } else { Client.Log("VoiceManager.RequestCaptureDevices() called when the daemon pipe is disconnected", Helpers.LogLevel.Error); return(-1); } }
public void DownloadInventory() { ClearState(); if (FolderDownloadStatus == null) { // Create status table FolderDownloadStatus = new Dictionary <LLUUID, DownloadRequest_Folder>(); } else { if (FolderDownloadStatus.Count != 0) { throw new Exception("Inventory Download requested while previous download in progress."); } } if (alFolderRequestQueue == null) { alFolderRequestQueue = new List <DownloadRequest_Folder>(); } // Set last packet received to now, just so out time-out timer works LastPacketRecievedAtTick = Environment.TickCount; // Send Packet requesting the root Folder, // this should recurse through all folders RequestFolder(new DownloadRequest_Folder(slClient.Self.InventoryRootFolderUUID)); while ((FolderDownloadStatus.Count > 0) || (alFolderRequestQueue.Count > 0)) { if (FolderDownloadStatus.Count == 0) { DownloadRequest_Folder dr = alFolderRequestQueue[0]; alFolderRequestQueue.RemoveAt(0); RequestFolder(dr); } int curTick = Environment.TickCount; if ((curTick - LastPacketRecievedAtTick) > 10000) { slClient.Log("Time-out while waiting for packets (" + ((curTick - LastPacketRecievedAtTick) / 1000) + " seconds since last packet)", Helpers.LogLevel.Warning); // have to make a seperate list otherwise we run into modifying the original array // while still enumerating it. List <DownloadRequest_Folder> alRestartList = new List <DownloadRequest_Folder>(); foreach (DownloadRequest_Folder dr in FolderDownloadStatus.Values) { alRestartList.Add(dr); } LastPacketRecievedAtTick = Environment.TickCount; foreach (DownloadRequest_Folder dr in alRestartList) { RequestFolder(dr); } } slClient.Tick(); } }
public void GetAvatarAppearanceInfoFromWearableAssets() { AgentWearablesUpdatePacket.WearableDataBlock[] wdbs = GetWearables(); foreach (AgentWearablesUpdatePacket.WearableDataBlock wdb in wdbs) { if (wdb.ItemID == LLUUID.Zero) { continue; } AssetWearable wearableAsset; switch (wdb.WearableType) { case 0: case 1: case 2: case 3: wearableAsset = new AssetWearable_Body(wdb.AssetID, null); break; default: wearableAsset = new AssetWearable_Clothing(wdb.AssetID, null); break; } AManager.GetInventoryAsset(wearableAsset); if ((wearableAsset.AssetData == null) || (wearableAsset.AssetData.Length == 0)) { Client.Log("Asset retrieval failed for AssetID: " + wearableAsset.AssetID, Helpers.LogLevel.Warning); } try { foreach (KeyValuePair <uint, LLUUID> texture in wearableAsset.Textures) { AgentTextureEntry.CreateFace(texture.Key).TextureID = texture.Value; } foreach (KeyValuePair <uint, float> kvp in wearableAsset.Parameters) { AgentAppearanceParams[kvp.Key] = kvp.Value; } } catch (Exception e) { Client.Log("ItemID: " + wdb.ItemID + Environment.NewLine + "WearableType: " + wdb.WearableType + Environment.NewLine + "Retrieving as type: " + wearableAsset.Type + Environment.NewLine + e.ToString() + Environment.NewLine + wearableAsset.AssetDataToString(), Helpers.LogLevel.Error); } } // Correct the order of the textures foreach (uint faceid in AgentTextureEntry.FaceTextures.Keys) { switch (faceid) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 12: case 13: case 14: case 15: case 16: case 17: case 18: break; default: Client.Log("Unknown order for FaceID: " + faceid + Environment.NewLine + "Your wearables define a face that we don't know the order of. Please " + "capture a AgentSetAppearance packet for your current outfit and submit to " + "[email protected], thanks!", Helpers.LogLevel.Info); break; } } //Re-order texture faces to match Linden Labs internal data structure. TextureEntry te2 = new TextureEntry(AgentTextureEntry.DefaultTexture.TextureID); te2.CreateFace(18).TextureID = AgentTextureEntry.GetFace(18).TextureID; te2.CreateFace(17).TextureID = AgentTextureEntry.GetFace(17).TextureID; te2.CreateFace(16).TextureID = AgentTextureEntry.GetFace(16).TextureID; te2.CreateFace(15).TextureID = AgentTextureEntry.GetFace(15).TextureID; te2.CreateFace(14).TextureID = AgentTextureEntry.GetFace(14).TextureID; te2.CreateFace(13).TextureID = AgentTextureEntry.GetFace(13).TextureID; te2.CreateFace(12).TextureID = AgentTextureEntry.GetFace(12).TextureID; // I wonder if shoes are somewhere in here? te2.CreateFace(7).TextureID = AgentTextureEntry.GetFace(7).TextureID; te2.CreateFace(6).TextureID = AgentTextureEntry.GetFace(6).TextureID; te2.CreateFace(5).TextureID = AgentTextureEntry.GetFace(5).TextureID; te2.CreateFace(4).TextureID = AgentTextureEntry.GetFace(4).TextureID; te2.CreateFace(3).TextureID = AgentTextureEntry.GetFace(3).TextureID; te2.CreateFace(2).TextureID = AgentTextureEntry.GetFace(2).TextureID; te2.CreateFace(1).TextureID = AgentTextureEntry.GetFace(1).TextureID; te2.CreateFace(0).TextureID = AgentTextureEntry.GetFace(0).TextureID; AgentTextureEntry = te2; }
private void LoadImage() { string lowfilename = FileName.ToLower(); Bitmap bitmap = null; try { if (lowfilename.EndsWith(".jp2") || lowfilename.EndsWith(".j2c")) { // Upload JPEG2000 images untouched UploadData = System.IO.File.ReadAllBytes(FileName); bitmap = (Bitmap)OpenJPEGNet.OpenJPEG.DecodeToImage(UploadData); Client.Log("Loaded raw JPEG2000 data " + FileName, Helpers.LogLevel.Info); } else { if (lowfilename.EndsWith(".tga")) { bitmap = OpenJPEGNet.LoadTGAClass.LoadTGA(FileName); } else { bitmap = (Bitmap)System.Drawing.Image.FromFile(FileName); } Client.Log("Loaded image " + FileName, Helpers.LogLevel.Info); int oldwidth = bitmap.Width; int oldheight = bitmap.Height; if (!IsPowerOfTwo((uint)oldwidth) || !IsPowerOfTwo((uint)oldheight)) { Client.Log("Image has irregular dimensions " + oldwidth + "x" + oldheight + ", resizing to 256x256", Helpers.LogLevel.Info); Bitmap resized = new Bitmap(256, 256, bitmap.PixelFormat); Graphics graphics = Graphics.FromImage(resized); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(bitmap, 0, 0, 256, 256); bitmap.Dispose(); bitmap = resized; oldwidth = 256; oldheight = 256; } // Handle resizing to prevent excessively large images if (oldwidth > 1024 || oldheight > 1024) { int newwidth = (oldwidth > 1024) ? 1024 : oldwidth; int newheight = (oldheight > 1024) ? 1024 : oldheight; Client.Log("Image has oversized dimensions " + oldwidth + "x" + oldheight + ", resizing to " + newwidth + "x" + newheight, Helpers.LogLevel.Info); Bitmap resized = new Bitmap(newwidth, newheight, bitmap.PixelFormat); Graphics graphics = Graphics.FromImage(resized); graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; graphics.DrawImage(bitmap, 0, 0, newwidth, newheight); bitmap.Dispose(); bitmap = resized; } Client.Log("Encoding image...", Helpers.LogLevel.Info); UploadData = OpenJPEGNet.OpenJPEG.EncodeFromImage(bitmap, chkLossless.Checked); Client.Log("Finished encoding", Helpers.LogLevel.Info); } } catch (Exception ex) { UploadData = null; cmdUpload.Enabled = false; MessageBox.Show(ex.ToString(), "SL Image Upload", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } picPreview.Image = bitmap; lblSize.Text = Math.Round((double)UploadData.Length / 1024.0d, 2) + "KB"; prgUpload.Maximum = UploadData.Length; if (Client.Network.Connected) { cmdUpload.Enabled = true; } }