/// <summary> /// Handle notifications sent when a friends has come online. /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> private void OnlineNotificationHandler(Packet packet, Simulator simulator) { if (packet.Type == PacketType.OnlineNotification) { OnlineNotificationPacket notification = ((OnlineNotificationPacket)packet); foreach (OnlineNotificationPacket.AgentBlockBlock block in notification.AgentBlock) { FriendInfo friend; lock (_Friends) { if (!_Friends.ContainsKey(block.AgentID)) { friend = new FriendInfo(block.AgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); _Friends.Add(block.AgentID, friend); } else { friend = _Friends[block.AgentID]; } } bool doNotify = !friend.IsOnline; friend.IsOnline = true; if (OnFriendOnline != null && doNotify) { try { OnFriendOnline(friend); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } }
/// <summary> /// Accept a friendship request /// </summary> /// <param name="imSessionID">imSessionID of the friendship request message</param> public void AcceptFriendship(LLUUID fromAgentID, LLUUID imSessionID) { LLUUID callingCardFolder = Client.Inventory.FindFolderForType(AssetType.CallingCard); AcceptFriendshipPacket request = new AcceptFriendshipPacket(); request.AgentData.AgentID = Client.Self.AgentID; request.AgentData.SessionID = Client.Self.SessionID; request.TransactionBlock.TransactionID = imSessionID; request.FolderData = new AcceptFriendshipPacket.FolderDataBlock[1]; request.FolderData[0] = new AcceptFriendshipPacket.FolderDataBlock(); request.FolderData[0].FolderID = callingCardFolder; Client.Network.SendPacket(request); FriendInfo friend = new FriendInfo(fromAgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); lock (_Friends) { if (!_Friends.ContainsKey(fromAgentID)) { _Friends.Add(friend.UUID, friend); } } lock (_Requests) { if (_Requests.ContainsKey(fromAgentID)) { _Requests.Remove(fromAgentID); } } Client.Avatars.RequestAvatarName(fromAgentID); }
private void Network_OnLoginResponse(bool loginSuccess, bool redirect, string message, string reason, LoginResponseData replyData) { if (loginSuccess) { lock (_Friends) { for (int i = 0; i < replyData.BuddyList.Length; i++) { FriendInfo friend = replyData.BuddyList[i]; _Friends[friend.UUID] = friend; } } } }
/// <summary> /// Handles relevant messages from the server encapsulated in instant messages. /// </summary> /// <param name="fromAgentID"></param> /// <param name="fromAgentName"></param> /// <param name="toAgentID"></param> /// <param name="parentEstateID"></param> /// <param name="regionID"></param> /// <param name="position"></param> /// <param name="dialog"></param> /// <param name="groupIM"></param> /// <param name="imSessionID"></param> /// <param name="timestamp"></param> /// <param name="message"></param> /// <param name="offline"></param> /// <param name="binaryBucket"></param> /// <param name="simulator"></param> private void MainAvatar_InstantMessage(InstantMessage im, Simulator simulator) { if (im.Dialog == InstantMessageDialog.FriendshipOffered) { if (OnFriendshipOffered != null) { lock (_Requests) { if (_Requests.ContainsKey(im.FromAgentID)) { _Requests[im.FromAgentID] = im.IMSessionID; } else { _Requests.Add(im.FromAgentID, im.IMSessionID); } } try { OnFriendshipOffered(im.FromAgentID, im.FromAgentName, im.IMSessionID); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } else if (im.Dialog == InstantMessageDialog.FriendshipAccepted) { FriendInfo friend = new FriendInfo(im.FromAgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); friend.Name = im.FromAgentName; lock (_Friends) _Friends[friend.UUID] = friend; if (OnFriendshipResponse != null) { try { OnFriendshipResponse(im.FromAgentID, im.FromAgentName, true); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } else if (im.Dialog == InstantMessageDialog.FriendshipDeclined) { if (OnFriendshipResponse != null) { try { OnFriendshipResponse(im.FromAgentID, im.FromAgentName, false); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } }
public FriendsListItem(FriendInfo friend) { this.friend = friend; }
public void Parse(NetworkManager.LoginMethodResponse reply) { AgentID = LLUUID.Parse(reply.agent_id); SessionID = LLUUID.Parse(reply.session_id); SecureSessionID = LLUUID.Parse(reply.secure_session_id); FirstName = reply.first_name; LastName = reply.last_name; StartLocation = reply.start_location; AgentAccess = reply.agent_access; LLSDArray look_at = (LLSDArray)LLSDParser.DeserializeNotation(reply.look_at); LookAt = new LLVector3( (float)look_at[0].AsReal(), (float)look_at[1].AsReal(), (float)look_at[2].AsReal()); if (reply.home != null) { LLSDMap home = (LLSDMap)LLSDParser.DeserializeNotation(reply.home); LLSDArray array = (LLSDArray)home["position"]; HomePosition = new LLVector3( (float)array[0].AsReal(), (float)array[1].AsReal(), (float)array[2].AsReal()); array = (LLSDArray)home["look_at"]; HomeLookAt = new LLVector3( (float)array[0].AsReal(), (float)array[1].AsReal(), (float)array[2].AsReal()); } CircuitCode = (uint)reply.circuit_code; RegionX = (uint)reply.region_x; RegionY = (uint)reply.region_y; SimPort = (ushort)reply.sim_port; SimIP = IPAddress.Parse(reply.sim_ip); SeedCapability = reply.seed_capability; if (reply.buddy_list != null) { BuddyList = new FriendInfo[reply.buddy_list.Length]; for (int i = 0; i < BuddyList.Length; ++i) { NetworkManager.BuddyListEntry buddy = reply.buddy_list[i]; BuddyList[i] = new FriendInfo(buddy.buddy_id, (FriendRights)buddy.buddy_rights_given, (FriendRights)buddy.buddy_rights_has); } } else { BuddyList = new FriendInfo[0]; } InventoryRoot = LLUUID.Parse(reply.inventory_root[0].folder_id); LibraryRoot = LLUUID.Parse(reply.inventory_lib_root[0].folder_id); LibraryOwner = LLUUID.Parse(reply.inventory_lib_owner[0].agent_id); InventorySkeleton = ParseSkeleton(reply.inventory_skeleton, AgentID); LibrarySkeleton = ParseSkeleton(reply.inventory_skel_lib, LibraryOwner); }
public void Parse(LLSDMap reply) { try { AgentID = ParseUUID("agent_id", reply); SessionID = ParseUUID("session_id", reply); SecureSessionID = ParseUUID("secure_session_id", reply); FirstName = ParseString("first_name", reply).Trim('"'); LastName = ParseString("last_name", reply).Trim('"'); StartLocation = ParseString("start_location", reply); AgentAccess = ParseString("agent_access", reply); LookAt = ParseLLVector3("look_at", reply); } catch (LLSDException e) { // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]' // need to handle that somehow Logger.DebugLog("login server returned (some) invalid data: " + e.Message); } // Home LLSDMap home = null; LLSD llsdHome = LLSDParser.DeserializeNotation(reply["home"].AsString()); if (llsdHome.Type == LLSDType.Map) { home = (LLSDMap)llsdHome; LLSD homeRegion; if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array) { LLSDArray homeArray = (LLSDArray)homeRegion; if (homeArray.Count == 2) { HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()); } else { HomeRegion = 0; } } HomePosition = ParseLLVector3("position", home); HomeLookAt = ParseLLVector3("look_at", home); } else { HomeRegion = 0; HomePosition = LLVector3.Zero; HomeLookAt = LLVector3.Zero; } CircuitCode = ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); SimPort = (ushort)ParseUInt("sim_port", reply); string simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); SeedCapability = ParseString("seed_capability", reply); // Buddy list LLSD buddyLLSD; if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array) { LLSDArray buddyArray = (LLSDArray)buddyLLSD; BuddyList = new FriendInfo[buddyArray.Count]; for (int i = 0; i < buddyArray.Count; i++) { if (buddyArray[i].Type == LLSDType.Map) { LLSDMap buddy = (LLSDMap)buddyArray[i]; BuddyList[i] = new FriendInfo( ParseUUID("buddy_id", buddy), (FriendRights)ParseUInt("buddy_rights_given", buddy), (FriendRights)ParseUInt("buddy_rights_has", buddy)); } } } SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply)); InventoryRoot = ParseMappedUUID("inventory-root", "folder_id", reply); InventorySkeleton = ParseInventoryFolders("inventory-skeleton", AgentID, reply); LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply); LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply); LibrarySkeleton = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply); }
//Separate thread private void Friends_OnFriendOnline(FriendInfo friend) { BeginInvoke(new MethodInvoker(RefreshFriendsList)); }
/// <summary> /// Handle notifications sent when a friends has come online. /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> private void OnlineNotificationHandler(Packet packet, Simulator simulator) { if (packet.Type == PacketType.OnlineNotification) { OnlineNotificationPacket notification = ((OnlineNotificationPacket)packet); foreach (OnlineNotificationPacket.AgentBlockBlock block in notification.AgentBlock) { FriendInfo friend; lock (FriendList) { if (!FriendList.ContainsKey(block.AgentID)) { friend = new FriendInfo(block.AgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); FriendList.Add(block.AgentID, friend); } else { friend = FriendList[block.AgentID]; } } bool doNotify = !friend.IsOnline; friend.IsOnline = true; if (OnFriendOnline != null && doNotify) { try { OnFriendOnline(friend); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } } }
/// <summary> /// Handles relevant messages from the server encapsulated in instant messages. /// </summary> /// <param name="im">InstantMessage object containing encapsalated instant message</param> /// <param name="simulator">Originating Simulator</param> private void MainAvatar_InstantMessage(InstantMessage im, Simulator simulator) { if (im.Dialog == InstantMessageDialog.FriendshipOffered) { if (OnFriendshipOffered != null) { lock (FriendRequests) { if (FriendRequests.ContainsKey(im.FromAgentID)) FriendRequests[im.FromAgentID] = im.IMSessionID; else FriendRequests.Add(im.FromAgentID, im.IMSessionID); } try { OnFriendshipOffered(im.FromAgentID, im.FromAgentName, im.IMSessionID); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } else if (im.Dialog == InstantMessageDialog.FriendshipAccepted) { FriendInfo friend = new FriendInfo(im.FromAgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); friend.Name = im.FromAgentName; lock (FriendList) FriendList[friend.UUID] = friend; if (OnFriendshipResponse != null) { try { OnFriendshipResponse(im.FromAgentID, im.FromAgentName, true); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } else if (im.Dialog == InstantMessageDialog.FriendshipDeclined) { if (OnFriendshipResponse != null) { try { OnFriendshipResponse(im.FromAgentID, im.FromAgentName, false); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } }
/// <summary> /// Accept a friendship request /// </summary> /// <param name="fromAgentID">agentID of avatatar to form friendship with</param> /// <param name="imSessionID">imSessionID of the friendship request message</param> public void AcceptFriendship(LLUUID fromAgentID, LLUUID imSessionID) { LLUUID callingCardFolder = Client.Inventory.FindFolderForType(AssetType.CallingCard); AcceptFriendshipPacket request = new AcceptFriendshipPacket(); request.AgentData.AgentID = Client.Self.AgentID; request.AgentData.SessionID = Client.Self.SessionID; request.TransactionBlock.TransactionID = imSessionID; request.FolderData = new AcceptFriendshipPacket.FolderDataBlock[1]; request.FolderData[0] = new AcceptFriendshipPacket.FolderDataBlock(); request.FolderData[0].FolderID = callingCardFolder; Client.Network.SendPacket(request); FriendInfo friend = new FriendInfo(fromAgentID, FriendRights.CanSeeOnline, FriendRights.CanSeeOnline); lock (FriendList) { if(!FriendList.ContainsKey(fromAgentID)) FriendList.Add(friend.UUID, friend); } lock (FriendRequests) { if (FriendRequests.ContainsKey(fromAgentID)) FriendRequests.Remove(fromAgentID); } Client.Avatars.RequestAvatarName(fromAgentID); }
/// <summary> /// Handle notifications sent when a friends has come online. /// </summary> /// <param name="packet"></param> /// <param name="simulator"></param> private void OnlineNotificationHandler(Packet packet, Simulator simulator) { if (packet.Type == PacketType.OnlineNotification) { OnlineNotificationPacket notification = ((OnlineNotificationPacket)packet); foreach (OnlineNotificationPacket.AgentBlockBlock block in notification.AgentBlock) { FriendInfo friend; lock (_Friends) { if (!_Friends.ContainsKey(block.AgentID)) { friend = new FriendInfo(block.AgentID, RightsFlags.CanSeeOnline, RightsFlags.CanSeeOnline); _Friends.Add(block.AgentID, friend); } else { friend = _Friends[block.AgentID]; } } bool doNotify = !friend.IsOnline; friend.IsOnline = true; if (OnFriendOnline != null && doNotify) { try { OnFriendOnline(friend); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } }
/// <summary> /// Adds a friend. Intended for use by the libsecondlife framework to build the /// initial list of friends from the buddy-list in the login reply XML /// </summary> /// <param name="agentID">ID of the agent being added to the list of friends</param> /// <param name="theirRights">rights the friend has</param> /// <param name="myRights">rights you have</param> internal void AddFriend(LLUUID agentID, RightsFlags theirRights, RightsFlags myRights) { lock (_Friends) { if (!_Friends.ContainsKey(agentID)) { FriendInfo friend = new FriendInfo(agentID, theirRights, myRights); _Friends[agentID] = friend; } } }
public void Friends_OnOnOffline(FriendInfo friend) { Hashtable hash = new Hashtable(); hash.Add("MessageType", "FriendOnOffline"); hash.Add("Name", friend.Name); hash.Add("ID", friend.UUID); hash.Add("TheirRights", friend.TheirFriendRights); hash.Add("MyRights", friend.MyFriendRights); hash.Add("Online", friend.IsOnline); enqueue(hash); }
public void Parse(LLSDMap reply) { try { AgentID = ParseUUID("agent_id", reply); SessionID = ParseUUID("session_id", reply); SecureSessionID = ParseUUID("secure_session_id", reply); FirstName = ParseString("first_name", reply).Trim('"'); LastName = ParseString("last_name", reply).Trim('"'); StartLocation = ParseString("start_location", reply); AgentAccess = ParseString("agent_access", reply); LookAt = ParseLLVector3("look_at", reply); } catch (LLSDException e) { // FIXME: sometimes look_at comes back with invalid values e.g: 'look_at':'[r1,r2.0193899999999998204e-06,r0]' // need to handle that somehow SecondLife.DebugLogStatic("login server returned (some) invalid data: " + e.Message); } // Home LLSDMap home = null; try { home = (LLSDMap)LLSDParser.DeserializeNotation(reply["home"].AsString()); } catch (LLSDException e) { SecondLife.DebugLogStatic("login server returned invalid home position: " + e.Message); } if (home != null) { LLSD homeRegion; if (home.TryGetValue("region_handle", out homeRegion) && homeRegion.Type == LLSDType.Array) { LLSDArray homeArray = (LLSDArray)homeRegion; if (homeArray.Count == 2) HomeRegion = Helpers.UIntsToLong((uint)homeArray[0].AsInteger(), (uint)homeArray[1].AsInteger()); else HomeRegion = 0; } HomePosition = ParseLLVector3("position", home); HomeLookAt = ParseLLVector3("look_at", home); } else { HomeRegion = 0; HomePosition = LLVector3.Zero; HomeLookAt = LLVector3.Zero; } CircuitCode = ParseUInt("circuit_code", reply); RegionX = ParseUInt("region_x", reply); RegionY = ParseUInt("region_y", reply); SimPort = (ushort)ParseUInt("sim_port", reply); string simIP = ParseString("sim_ip", reply); IPAddress.TryParse(simIP, out SimIP); SeedCapability = ParseString("seed_capability", reply); // Buddy list LLSD buddyLLSD; if (reply.TryGetValue("buddy-list", out buddyLLSD) && buddyLLSD.Type == LLSDType.Array) { LLSDArray buddyArray = (LLSDArray)buddyLLSD; BuddyList = new FriendInfo[buddyArray.Count]; for (int i = 0; i < buddyArray.Count; i++) { if (buddyArray[i].Type == LLSDType.Map) { LLSDMap buddy = (LLSDMap)buddyArray[i]; BuddyList[i] = new FriendInfo( ParseUUID("buddy_id", buddy), (FriendRights)ParseUInt("buddy_rights_given", buddy), (FriendRights)ParseUInt("buddy_rights_has", buddy)); } } } SecondsSinceEpoch = Helpers.UnixTimeToDateTime(ParseUInt("seconds_since_epoch", reply)); InventoryRoot = ParseMappedUUID("inventory-root", "folder_id", reply); InventorySkeleton = ParseInventoryFolders("inventory-skeleton", AgentID, reply); LibraryRoot = ParseMappedUUID("inventory-lib-root", "folder_id", reply); LibraryOwner = ParseMappedUUID("inventory-lib-owner", "agent_id", reply); LibrarySkeleton = ParseInventoryFolders("inventory-skel-lib", LibraryOwner, reply); }
private void SetFriend(FriendInfo friend) { if (friend == null) return; selectedFriend = friend; lblFriendName.Text = friend.Name + (friend.IsOnline ? " (online)" : " (offline)"); btnIM.Enabled = btnProfile.Enabled = btnOfferTeleport.Enabled = btnPay.Enabled = true; chkSeeMeOnline.Enabled = chkSeeMeOnMap.Enabled = chkModifyMyObjects.Enabled = true; chkSeeMeOnMap.Enabled = friend.CanSeeMeOnline; settingFriend = true; chkSeeMeOnline.Checked = friend.CanSeeMeOnline; chkSeeMeOnMap.Checked = friend.CanSeeMeOnMap; chkModifyMyObjects.Checked = friend.CanModifyMyObjects; settingFriend = false; }