From e270111e0c2256da37b612654921f957c7c0c3f2 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Tue, 10 Mar 2020 16:43:46 -0700 Subject: [PATCH] fix caches --- Program.cs | 29 ++++++++++++++++++++ zGroupCaches.cs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 zGroupCaches.cs diff --git a/Program.cs b/Program.cs index 6fb71b2..8a25ca4 100644 --- a/Program.cs +++ b/Program.cs @@ -212,6 +212,7 @@ namespace Bot client.Self.ChatFromSimulator += onChatRecv; client.Self.GroupChatJoined += onJoinGroupChat; client.Self.IM += onIMEvent; + client.Groups.GroupRoleDataReply += CacheGroupRoles; //client.Objects.ObjectUpdate += onObjectUpdate; //client.Objects.ObjectProperties += onObjectProperties; @@ -791,6 +792,34 @@ namespace Bot } + private static void CacheGroupRoles(object sender, GroupRolesDataReplyEventArgs e) + { + //MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "[debug] role_reply"); + if (!Directory.Exists("zGroupCache")) Directory.CreateDirectory("zGroupCache"); // this should be purged at every bot restart!!! + + //MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "[debug] generating groupcache file"); + zGroupCaches newCache = new zGroupCaches(); + zGroupCaches.GroupMemoryData gmd = new zGroupCaches.GroupMemoryData(); + foreach (KeyValuePair roleData in e.Roles) + { + gmd.roleID = roleData.Value.ID; + gmd.RoleName = roleData.Value.Name; + gmd.Title = roleData.Value.Title; + gmd.Powers = roleData.Value.Powers; + + + newCache.GMD.Add(gmd); + + } + newCache.GroupID = e.GroupID; + newCache.Save(e.GroupID.ToString()); + RoleReply.Set(); + FileInfo fi = new FileInfo("GroupCache/" + e.GroupID.ToString() + ".bdf"); + + //MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "[debug] Roles for secondlife:///app/group/" + e.GroupID.ToString() + "/about have been saved to: GroupCache/" + e.GroupID.ToString() + ".bdf\nFileSize: "+fi.Length.ToString(), 55); + + + } private static Dictionary GroupsCache = null; private static ManualResetEvent GroupsEvent = new ManualResetEvent(false); private static ManualResetEvent RoleReply = new ManualResetEvent(false); diff --git a/zGroupCaches.cs b/zGroupCaches.cs new file mode 100644 index 0000000..4e6dd70 --- /dev/null +++ b/zGroupCaches.cs @@ -0,0 +1,73 @@ +/* + +Copyright © 2019 Tara Piccari (Aria; Tashia Redrose) +Licensed under the GPLv2 + +*/ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Bot; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using System.Threading; +using System.IO; + + + +namespace Bot +{ + [Serializable()] + public class zGroupCaches : IConfig + { + public float ConfigVersion { get { return 1.4f; } set { } } + public string ConfigFor { get { return "GroupCache"; } set { } } + public List Data { get; set; } + + public UUID GroupID { get; set; } + + [Serializable()] + public struct GroupMemoryData + { + public string RoleName; + public UUID roleID; + public string Title; + public GroupPowers Powers; + public string GroupName; + } + + public List GMD { get; set; } + + + public void Save(string CustomName) + { + + + //if (!File.Exists("OpenCollarBot.bdf")) return; + SerialManager sm = new SerialManager(); + sm.Write("zGroupCache/" + CustomName, this); + sm = null; + } + + public static zGroupCaches Reload(string CustomName) + { + if (!File.Exists("zGroupCache/" + CustomName + ".json")) return new zGroupCaches(); + SerialManager sm = new SerialManager(); + zGroupCaches ocb = sm.Read("GroupCache/" + CustomName); + if (ocb == null) + { + return new zGroupCaches(); + } + return ocb; + } + public zGroupCaches() + { + + GMD = new List(); + } + } +}