private void UpdateList() { AjaxLife.Debug("BanList", "Loading ban list from " + AjaxLife.BAN_LIST + "..."); try { string sbanlist = ""; if (AjaxLife.BAN_LIST.StartsWith("http://")) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AjaxLife.BAN_LIST); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()); sbanlist = reader.ReadToEnd(); reader.Close(); response.Close(); } else { sbanlist = File.ReadAllText(AjaxLife.BAN_LIST); } char[] newline = { '\n' }; this.Bans = sbanlist.Split(newline); for (int i = 0; i < this.Bans.Length; ++i) { this.Bans[i] = this.Bans[i].Trim(); } AjaxLife.Debug("BanList", "Ban list up to date. " + Bans.Length + " banned names."); } catch (Exception e) { AjaxLife.Debug("BanList", "Ban list update failed: " + e.Message); } }
public static string FromHashtableQueue(Queue <Hashtable> queue) { StringWriter textWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(textWriter); jsonWriter.WriteStartArray(); JsonSerializer serializer = new JsonSerializer(); UUIDConverter UUID = new UUIDConverter(); serializer.Converters.Add(UUID); while (queue.Count > 0) { try { Hashtable hashtable = queue.Dequeue(); serializer.Serialize(jsonWriter, hashtable); } catch (Exception e) { AjaxLife.Debug("MakeJson.FromHashTable", e.Message); } } jsonWriter.WriteEndArray(); jsonWriter.Flush(); string text = textWriter.ToString(); jsonWriter.Close(); textWriter.Dispose(); return(text); }
public void Groups_OnGroupNames(Dictionary <LLUUID, string> groupNames) { AjaxLife.Debug("OnGroupNames", "OnGroupNames arrived."); Hashtable message = new Hashtable(); message.Add("MessageType", "GroupNames"); message.Add("Names", groupNames); enqueue(message); }
public void Groups_GroupNamesReply(object sender, GroupNamesEventArgs e) { AjaxLife.Debug("OnGroupNames", "OnGroupNames arrived."); Hashtable message = new Hashtable(); message.Add("MessageType", "GroupNames"); message.Add("Names", e.GroupNames); enqueue(message); }
public void Self_OnGroupChatJoin(LLUUID groupChatSessionID, LLUUID tmpSessionID, bool success) { AjaxLife.Debug("Events", "OnGroupChatJoin(" + groupChatSessionID + ", " + tmpSessionID + ", " + success.ToString() + ")"); Hashtable message = new Hashtable(); message.Add("MessageType", "GroupChatJoin"); message.Add("GroupChatSessionID", groupChatSessionID); message.Add("TmpSessionID", tmpSessionID); message.Add("Success", success); enqueue(message); }
public BanList() { if (AjaxLife.BAN_LIST != "") { if (AjaxLife.BAN_UPDATE_TIME > 0) { Time = new Timer(); Time.Interval = AjaxLife.BAN_UPDATE_TIME * 1000.0; Time.AutoReset = true; Time.Elapsed += new ElapsedEventHandler(TimerElapsed); Time.Start(); AjaxLife.Debug("BanList", "Set ban update timer for " + AjaxLife.BAN_UPDATE_TIME + " seconds."); } else { AjaxLife.Debug("BanList", "Ban update timer disabled."); } UpdateList(); } }
public void Assets_OnImageReceived(ImageDownload image, AssetTexture asset) { if (image.NotFound) { Console.WriteLine("Failed to download " + image.ID + " - not found."); Hashtable hash = new Hashtable(); hash.Add("MessageType", "ImageDownloaded"); hash.Add("UUID", image.ID); hash.Add("Success", false); hash.Add("Error", "Image not found in database."); enqueue(hash); } else if (image.Success) { bool success = true; string key = image.ID.ToString(); try { libsecondlife.Imaging.ManagedImage decoded; libsecondlife.Imaging.OpenJPEG.DecodeToImage(image.AssetData, out decoded); byte[] img = decoded.ExportTGA(); decoded.Clear(); File.WriteAllBytes(AjaxLife.TEXTURE_CACHE + key + ".tga", img); Process process = Process.Start("convert", AjaxLife.TEXTURE_CACHE + key + ".tga " + AjaxLife.TEXTURE_CACHE + key + ".png"); process.WaitForExit(); process.Dispose(); File.Delete(AjaxLife.TEXTURE_CACHE + key + ".tga"); Console.WriteLine("Downloaded image " + key + " - " + image.Size + " bytes."); if (AjaxLife.USE_S3) { try { IThreeSharp service = new ThreeSharpQuery(AjaxLife.S3Config); Affirma.ThreeSharp.Model.ObjectAddRequest request = new Affirma.ThreeSharp.Model.ObjectAddRequest(AjaxLife.TEXTURE_BUCKET, key + ".png"); request.LoadStreamWithFile(AjaxLife.TEXTURE_CACHE + key + ".png"); request.Headers.Add("x-amz-acl", "public-read"); service.ObjectAdd(request).DataStream.Close(); AjaxLife.CachedTextures.Add(image.ID); } catch { success = false; } File.Delete(AjaxLife.TEXTURE_CACHE + key + ".png"); } } catch (Exception e) { success = false; AjaxLife.Debug("Events", "Texture download for " + key + " failed: " + e.Message); } Hashtable hash = new Hashtable(); hash.Add("MessageType", "ImageDownloaded"); hash.Add("Success", success); hash.Add("Size", image.Size); hash.Add("UUID", key); hash.Add("URL", AjaxLife.TEXTURE_ROOT + key + ".png"); enqueue(hash); } else { Console.WriteLine("Failed to download " + image.ID + "."); Hashtable hash = new Hashtable(); hash.Add("MessageType", "ImageDownloaded"); hash.Add("UUID", image.ID); hash.Add("Success", false); hash.Add("Error", "Unknown error."); enqueue(hash); } }
public void Assets_TextureDownloadCallback(TextureRequestState state, AssetTexture texture) { if (state == TextureRequestState.NotFound || state == TextureRequestState.Aborted || state == TextureRequestState.Timeout) { Console.WriteLine("Failed to download " + texture.AssetID + " - " + state.ToString() + "."); Hashtable hash = new Hashtable(); hash.Add("MessageType", "ImageDownloaded"); hash.Add("UUID", texture.AssetID); hash.Add("Success", false); hash.Add("Error", "Image could not be downloaded: " + state.ToString()); enqueue(hash); } else if (state == TextureRequestState.Finished) { bool success = true; string key = texture.AssetID.ToString(); try { texture.Decode(); byte[] img = texture.Image.ExportRaw(); int size = img.Length; int width = texture.Image.Width; int height = texture.Image.Height; texture.Image.Clear(); // Helpfully, it's upside-down, and has red and blue flipped. // Assuming 32 bits (accurate) and a height as a multiple of two (accurate), // this will vertically invert the image. int length = width * 4; byte[] fliptemp = new byte[length]; for (int i = 0; i < height / 2; ++i) { int index = i * width * 4; int endindex = size - ((i + 1) * width * 4); Array.Copy(img, index, fliptemp, 0, length); Array.Copy(img, endindex, img, index, length); Array.Copy(fliptemp, 0, img, endindex, length); } // This changes RGBA to BGRA. Or possibly vice-versa. I don't actually know. // The documentation is vague/nonexistent. for (int i = 0; i < size; i += 4) { byte temp = img[i + 2]; img[i + 2] = img[i]; img[i] = temp; } // Use System.Drawing.Bitmap to create a PNG. This requires us to feed it a pointer to an array // for whatever reason, so we temporarily pin the image array. GCHandle handle = GCHandle.Alloc(img, GCHandleType.Pinned); Bitmap bitmap = new Bitmap(texture.Image.Width, texture.Image.Height, texture.Image.Width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, handle.AddrOfPinnedObject()); bitmap.Save(AjaxLife.TEXTURE_CACHE + key + ".png", System.Drawing.Imaging.ImageFormat.Png); bitmap.Dispose(); handle.Free(); if (AjaxLife.USE_S3) { try { IThreeSharp service = new ThreeSharpQuery(AjaxLife.S3Config); Affirma.ThreeSharp.Model.ObjectAddRequest request = new Affirma.ThreeSharp.Model.ObjectAddRequest(AjaxLife.TEXTURE_BUCKET, key + ".png"); request.LoadStreamWithFile(AjaxLife.TEXTURE_CACHE + key + ".png"); request.Headers.Add("x-amz-acl", "public-read"); request.Headers.Add("Content-Type", "image/png"); service.ObjectAdd(request).DataStream.Close(); AjaxLife.CachedTextures.Add(texture.AssetID); File.Delete(AjaxLife.TEXTURE_CACHE + key + ".png"); } catch { success = false; } } } catch (Exception e) { success = false; AjaxLife.Debug("Events", "Texture download for " + key + " failed (" + e.GetType().Name + "): " + e.Message); } Hashtable hash = new Hashtable(); hash.Add("MessageType", "ImageDownloaded"); hash.Add("Success", success); hash.Add("UUID", key); hash.Add("URL", AjaxLife.TEXTURE_ROOT + key + ".png"); enqueue(hash); } }
public void TimerElapsed(object obj, ElapsedEventArgs args) { AjaxLife.Debug("BanList", "Timer elapsed."); UpdateList(); }