public OpBuddy AddBuddy(string name, byte[] key) { ulong id = Utilities.KeytoID(key); OpBuddy buddy; if (BuddyList.TryGetValue(id, out buddy)) { return(buddy); } buddy = new OpBuddy() { ID = id, Name = name, Key = key }; BuddyList.SafeAdd(id, buddy); Core.IndexName(id, name); // always associate this buddy with name SaveList = true; Core.RunInGuiThread(GuiUpdate); Core.Locations.Research(id); return(buddy); }
private void Cache_FileAquired(OpVersionedFile file) { if (file.UserID != Network.Local.UserID) { return; } // only we can open the buddly list stored on the network byte[] key = Core.User.Settings.KeyPair.Decrypt(file.Header.FileKey, false); using (TaggedStream tagged = new TaggedStream(Cache.GetFilePath(file.Header), Network.Protocol)) using (IVCryptoStream crypto = IVCryptoStream.Load(tagged, key)) { BuddyList.SafeClear(); PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read); G2Header root = null; while (stream.ReadPacket(ref root)) { if (root.Name == BuddyPacket.Buddy) { OpBuddy buddy = OpBuddy.Decode(root); ulong id = Utilities.KeytoID(buddy.Key); Core.IndexKey(id, ref buddy.Key); Core.IndexName(id, buddy.Name); if (buddy.Ignored) { IgnoreList.SafeAdd(id, buddy); } else { BuddyList.SafeAdd(id, buddy); } } } } Core.RunInGuiThread(GuiUpdate); }
void BuddyView_DragDrop(object sender, DragEventArgs e) { Dragging = false; // Handle only FileDrop data. if (!e.Data.GetDataPresent(DataFormats.Text)) { return; } // get destination of drop BuddyItem overItem = GetItemAt(PointToClient(new Point(e.X, e.Y))) as BuddyItem; // must be dragging over a group label if (overItem == null || overItem.User != 0 || overItem.Text == "") { return; } string groupname = overItem.GroupLabel ? overItem.Text : null; try { string[] links = (string[])e.Data.GetData(DataFormats.Text); foreach (string link in links) { OpBuddy buddy = Buddies.AddBuddy(link); if (buddy != null) { Buddies.AddtoGroup(buddy.ID, groupname); } } RefreshView(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static OpBuddy Decode(G2Header root) { OpBuddy buddy = new OpBuddy(); if (G2Protocol.ReadPayload(root)) { buddy.Key = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); buddy.ID = Utilities.KeytoID(buddy.Key); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_Ignored) { buddy.Ignored = true; continue; } if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_Name: buddy.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Group: buddy.Group = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(buddy); }
public void Ignore(ulong user, bool ignore) { if (ignore) { OpBuddy buddy = new OpBuddy() { ID = user, Name = Core.GetName(user), Key = Core.KeyMap[user], //crit - not thread safe, change key map? Ignored = true }; IgnoreList.SafeAdd(user, buddy); } else { IgnoreList.SafeRemove(user); } SaveList = true; Core.RunInGuiThread(GuiUpdate); }
public static OpBuddy Decode(G2Header root) { OpBuddy buddy = new OpBuddy(); if (G2Protocol.ReadPayload(root)) { buddy.Key = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); buddy.ID = Utilities.KeytoID(buddy.Key); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (child.Name == Packet_Ignored) { buddy.Ignored = true; continue; } if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_Name: buddy.Name = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; case Packet_Group: buddy.Group = UTF8Encoding.UTF8.GetString(child.Data, child.PayloadPos, child.PayloadSize); break; } } return buddy; }
public void Ignore(ulong user, bool ignore) { if (ignore) { OpBuddy buddy = new OpBuddy() { ID = user, Name = Core.GetName(user), Key = Core.KeyMap[user], //crit - not thread safe, change key map? Ignored = true }; IgnoreList.SafeAdd(user, buddy); } else IgnoreList.SafeRemove(user); SaveList = true; Core.RunInGuiThread(GuiUpdate); }
public OpBuddy AddBuddy(string name, byte[] key) { ulong id = Utilities.KeytoID(key); OpBuddy buddy; if (BuddyList.TryGetValue(id, out buddy)) return buddy; buddy = new OpBuddy() { ID = id, Name = name, Key = key }; BuddyList.SafeAdd(id, buddy); Core.IndexName(id, name); // always associate this buddy with name SaveList = true; Core.RunInGuiThread(GuiUpdate); Core.Locations.Research(id); return buddy; }