fix caches

This commit is contained in:
Zontreck 2020-03-10 16:43:46 -07:00
parent 6c085c9ac2
commit e270111e0c
2 changed files with 102 additions and 0 deletions

View file

@ -212,6 +212,7 @@ namespace Bot
client.Self.ChatFromSimulator += onChatRecv; client.Self.ChatFromSimulator += onChatRecv;
client.Self.GroupChatJoined += onJoinGroupChat; client.Self.GroupChatJoined += onJoinGroupChat;
client.Self.IM += onIMEvent; client.Self.IM += onIMEvent;
client.Groups.GroupRoleDataReply += CacheGroupRoles;
//client.Objects.ObjectUpdate += onObjectUpdate; //client.Objects.ObjectUpdate += onObjectUpdate;
//client.Objects.ObjectProperties += onObjectProperties; //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<UUID, GroupRole> 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<UUID, Group> GroupsCache = null; private static Dictionary<UUID, Group> GroupsCache = null;
private static ManualResetEvent GroupsEvent = new ManualResetEvent(false); private static ManualResetEvent GroupsEvent = new ManualResetEvent(false);
private static ManualResetEvent RoleReply = new ManualResetEvent(false); private static ManualResetEvent RoleReply = new ManualResetEvent(false);

73
zGroupCaches.cs Normal file
View file

@ -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<string> 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<GroupMemoryData> GMD { get; set; }
public void Save(string CustomName)
{
//if (!File.Exists("OpenCollarBot.bdf")) return;
SerialManager sm = new SerialManager();
sm.Write<zGroupCaches>("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<zGroupCaches>("GroupCache/" + CustomName);
if (ocb == null)
{
return new zGroupCaches();
}
return ocb;
}
public zGroupCaches()
{
GMD = new List<GroupMemoryData>();
}
}
}