OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
FriendsService.cs
Go to the documentation of this file.
1 /*
2  * Copyright (c) Contributors, http://opensimulator.org/
3  * See CONTRIBUTORS.TXT for a full list of copyright holders.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the OpenSimulator Project nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 using OpenMetaverse;
29 using OpenSim.Framework;
30 using System;
31 using System.Collections.Generic;
32 using OpenSim.Services.Interfaces;
33 using OpenSim.Data;
34 using Nini.Config;
35 using log4net;
37 
38 namespace OpenSim.Services.Friends
39 {
41  {
42  public FriendsService(IConfigSource config) : base(config)
43  {
44  }
45 
46  public virtual FriendInfo[] GetFriends(UUID PrincipalID)
47  {
48  FriendsData[] data = m_Database.GetFriends(PrincipalID);
49  List<FriendInfo> info = new List<FriendInfo>();
50 
51  foreach (FriendsData d in data)
52  {
53  FriendInfo i = new FriendInfo();
54 
55  i.PrincipalID = new UUID(d.PrincipalID);
56  i.Friend = d.Friend;
57  i.MyFlags = Convert.ToInt32(d.Data["Flags"]);
58  i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]);
59 
60  info.Add(i);
61  }
62 
63  return info.ToArray();
64  }
65 
66  public virtual FriendInfo[] GetFriends(string PrincipalID)
67  {
68  FriendsData[] data = m_Database.GetFriends(PrincipalID);
69  List<FriendInfo> info = new List<FriendInfo>();
70 
71  foreach (FriendsData d in data)
72  {
73  FriendInfo i = new FriendInfo();
74 
75  if (!UUID.TryParse(d.PrincipalID, out i.PrincipalID))
76  {
77  string tmp = string.Empty;
78  if (!Util.ParseUniversalUserIdentifier(d.PrincipalID, out i.PrincipalID, out tmp, out tmp, out tmp, out tmp))
79  // bad record. ignore this entry
80  continue;
81  }
82  i.Friend = d.Friend;
83  i.MyFlags = Convert.ToInt32(d.Data["Flags"]);
84  i.TheirFlags = Convert.ToInt32(d.Data["TheirFlags"]);
85 
86  info.Add(i);
87  }
88 
89  return info.ToArray();
90  }
91 
92  public virtual bool StoreFriend(string PrincipalID, string Friend, int flags)
93  {
94  FriendsData d = new FriendsData();
95 
96  d.PrincipalID = PrincipalID;
97  d.Friend = Friend;
98  d.Data = new Dictionary<string, string>();
99  d.Data["Flags"] = flags.ToString();
100 
101  return m_Database.Store(d);
102  }
103 
104  public bool Delete(string principalID, string friend)
105  {
106  return m_Database.Delete(principalID, friend);
107  }
108 
109  public virtual bool Delete(UUID PrincipalID, string Friend)
110  {
111  return m_Database.Delete(PrincipalID, Friend);
112  }
113 
114  }
115 }
OpenSim.Services.Interfaces.FriendInfo FriendInfo
virtual bool Delete(UUID PrincipalID, string Friend)
virtual FriendInfo[] GetFriends(string PrincipalID)
Interactive OpenSim region server
Definition: OpenSim.cs:55
virtual FriendInfo[] GetFriends(UUID PrincipalID)
bool Delete(string principalID, string friend)
virtual bool StoreFriend(string PrincipalID, string Friend, int flags)