diff options
author | Teravus Ovares | 2008-01-01 06:12:04 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-01-01 06:12:04 +0000 |
commit | b4c9b6bd19c0725ae5bf60172db75ebc63ba72c6 (patch) | |
tree | d7e9e370371edbcbebb8436791ba8b1cd940ab69 /OpenSim/Region/Environment/Modules/FriendsModule.cs | |
parent | Make it possible for new inventory 'libraries' to be added without changing t... (diff) | |
download | opensim-SC-b4c9b6bd19c0725ae5bf60172db75ebc63ba72c6.zip opensim-SC-b4c9b6bd19c0725ae5bf60172db75ebc63ba72c6.tar.gz opensim-SC-b4c9b6bd19c0725ae5bf60172db75ebc63ba72c6.tar.bz2 opensim-SC-b4c9b6bd19c0725ae5bf60172db75ebc63ba72c6.tar.xz |
* You can add and remove a friend in standalone now within the same simulator. It saves.
* You can add and remove a friend in grid mode now within the same simulator. It doesn't save yet.
* I got rid of Mr. OpenSim as a friend.. he bothers me /:b...
Diffstat (limited to 'OpenSim/Region/Environment/Modules/FriendsModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/FriendsModule.cs | 175 |
1 files changed, 151 insertions, 24 deletions
diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/FriendsModule.cs index ee78f15..d6be63b 100644 --- a/OpenSim/Region/Environment/Modules/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/FriendsModule.cs | |||
@@ -35,53 +35,180 @@ using OpenSim.Framework.Console; | |||
35 | using OpenSim.Region.Environment.Interfaces; | 35 | using OpenSim.Region.Environment.Interfaces; |
36 | using OpenSim.Region.Environment.Scenes; | 36 | using OpenSim.Region.Environment.Scenes; |
37 | using libsecondlife; | 37 | using libsecondlife; |
38 | using libsecondlife.Packets; | ||
39 | 38 | ||
40 | namespace OpenSim.Region.Environment.Modules | 39 | namespace OpenSim.Region.Environment.Modules |
41 | { | 40 | { |
42 | public class FriendsModule : IRegionModule | 41 | public class FriendsModule : IRegionModule |
43 | { | 42 | { |
44 | private List<Scene> m_scenes = new List<Scene>(); | 43 | |
45 | private LogBase m_log; | 44 | private LogBase m_log; |
46 | 45 | ||
46 | private Scene m_scene; | ||
47 | |||
48 | Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>(); | ||
49 | |||
47 | public void Initialise(Scene scene, IConfigSource config) | 50 | public void Initialise(Scene scene, IConfigSource config) |
48 | { | 51 | { |
49 | m_log = MainLog.Instance; | 52 | m_log = MainLog.Instance; |
50 | if (!m_scenes.Contains(scene)) | 53 | m_scene = scene; |
51 | { | 54 | scene.EventManager.OnNewClient += OnNewClient; |
52 | m_scenes.Add(scene); | 55 | scene.EventManager.OnGridInstantMessageToFriendsModule += OnGridInstantMessage; |
53 | scene.EventManager.OnNewClient += OnNewClient; | ||
54 | } | ||
55 | } | 56 | } |
56 | 57 | ||
57 | private void OnNewClient(IClientAPI client) | 58 | private void OnNewClient(IClientAPI client) |
58 | { | 59 | { |
59 | //FormFriendship(client,new Guid("c43a67ab-b196-4d62-936c-b40369547dee")); | 60 | // All friends establishment protocol goes over instant message |
60 | //FormFriendship(client, new Guid("0a2f777b-f44c-4662-8b22-c90ae038a3e6")); | 61 | // There's no way to send a message from the sim |
61 | } | 62 | // to a user to 'add a friend' without causing dialog box spam |
63 | // | ||
64 | // The base set of friends are added when the user signs on in their XMLRPC response | ||
65 | // Generated by LoginService. The friends are retreived from the database by the UserManager | ||
62 | 66 | ||
63 | public void PostInitialise() | 67 | // Subscribe to instant messages |
68 | client.OnInstantMessage += OnInstantMessage; | ||
69 | client.OnApproveFriendRequest += OnApprovedFriendRequest; | ||
70 | client.OnDenyFriendRequest += OnDenyFriendRequest; | ||
71 | client.OnTerminateFriendship += OnTerminateFriendship; | ||
72 | |||
73 | |||
74 | } | ||
75 | private void OnInstantMessage(LLUUID fromAgentID, | ||
76 | LLUUID fromAgentSession, LLUUID toAgentID, | ||
77 | LLUUID imSessionID, uint timestamp, string fromAgentName, | ||
78 | string message, byte dialog, bool fromGroup, byte offline, | ||
79 | uint ParentEstateID, LLVector3 Position, LLUUID RegionID, | ||
80 | byte[] binaryBucket) | ||
64 | { | 81 | { |
82 | // Friend Requests go by Instant Message.. using the dialog param | ||
83 | // https://wiki.secondlife.com/wiki/ImprovedInstantMessage | ||
84 | |||
85 | // 38 == Offer friendship | ||
86 | if (dialog == (byte)38) | ||
87 | { | ||
88 | LLUUID friendTransactionID = LLUUID.Random(); | ||
89 | |||
90 | m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); | ||
91 | |||
92 | m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | ||
93 | GridInstantMessage msg = new GridInstantMessage(); | ||
94 | msg.fromAgentID = fromAgentID.UUID; | ||
95 | msg.fromAgentSession = fromAgentSession.UUID; | ||
96 | msg.toAgentID = toAgentID.UUID; | ||
97 | msg.imSessionID = friendTransactionID.UUID; // This is the item we're mucking with here | ||
98 | m_log.Verbose("FRIEND","Filling Session: " + msg.imSessionID.ToString()); | ||
99 | msg.timestamp = timestamp; | ||
100 | msg.fromAgentName = fromAgentName; | ||
101 | msg.message = message; | ||
102 | msg.dialog = dialog; | ||
103 | msg.fromGroup = fromGroup; | ||
104 | msg.offline = offline; | ||
105 | msg.ParentEstateID = ParentEstateID; | ||
106 | msg.Position = new sLLVector3(Position); | ||
107 | msg.RegionID = RegionID.UUID; | ||
108 | msg.binaryBucket = binaryBucket; | ||
109 | m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | ||
110 | } | ||
111 | if (dialog == (byte)39) | ||
112 | { | ||
113 | m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | ||
114 | |||
115 | } | ||
116 | if (dialog == (byte)40) | ||
117 | { | ||
118 | m_log.Verbose("FRIEND", "38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); | ||
119 | } | ||
120 | |||
121 | // 39 == Accept Friendship | ||
122 | |||
123 | // 40 == Decline Friendship | ||
124 | |||
65 | } | 125 | } |
66 | 126 | ||
67 | private void FormFriendship(IClientAPI client, Guid friend) | 127 | private void OnApprovedFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) |
68 | { | 128 | { |
69 | foreach (Scene scene in m_scenes) | 129 | if (m_pendingFriendRequests.ContainsKey(transactionID)) |
70 | { | 130 | { |
71 | if (scene.Entities.ContainsKey(client.AgentId) && scene.Entities[client.AgentId] is ScenePresence) | 131 | // Found Pending Friend Request with that Transaction.. |
72 | { | 132 | |
73 | OnlineNotificationPacket ONPack = new OnlineNotificationPacket(); | 133 | // Compose response to other agent. |
74 | OnlineNotificationPacket.AgentBlockBlock[] AgentBlock = new OnlineNotificationPacket.AgentBlockBlock[1]; | 134 | GridInstantMessage msg = new GridInstantMessage(); |
75 | 135 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; | |
76 | AgentBlock[0] = new OnlineNotificationPacket.AgentBlockBlock(); | 136 | msg.fromAgentID = agentID.UUID; |
77 | AgentBlock[0].AgentID = new LLUUID(friend); | 137 | msg.fromAgentName = client.FirstName + " " + client.LastName; |
78 | ONPack.AgentBlock = AgentBlock; | 138 | msg.fromAgentSession = client.SessionId.UUID; |
79 | client.OutPacket(ONPack,ThrottleOutPacketType.Task); | 139 | msg.fromGroup = false; |
80 | } | 140 | msg.imSessionID = transactionID.UUID; |
141 | msg.message = agentID.UUID.ToString(); | ||
142 | msg.ParentEstateID = 0; | ||
143 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
144 | msg.RegionID = m_scene.RegionInfo.RegionID.UUID; | ||
145 | msg.dialog = (byte)39;// Approved friend request | ||
146 | msg.Position = new sLLVector3(); | ||
147 | msg.offline = (byte)0; | ||
148 | msg.binaryBucket = new byte[0]; | ||
149 | m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | ||
150 | m_scene.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); | ||
151 | m_pendingFriendRequests.Remove(transactionID); | ||
152 | |||
153 | // TODO: Inform agent that the friend is online | ||
81 | } | 154 | } |
155 | } | ||
156 | private void OnDenyFriendRequest(IClientAPI client, LLUUID agentID, LLUUID transactionID, List<LLUUID> callingCardFolders) | ||
157 | { | ||
158 | if (m_pendingFriendRequests.ContainsKey(transactionID)) | ||
159 | { | ||
160 | // Found Pending Friend Request with that Transaction.. | ||
161 | |||
162 | // Compose response to other agent. | ||
163 | GridInstantMessage msg = new GridInstantMessage(); | ||
164 | msg.toAgentID = m_pendingFriendRequests[transactionID].UUID; | ||
165 | msg.fromAgentID = agentID.UUID; | ||
166 | msg.fromAgentName = client.FirstName + " " + client.LastName; | ||
167 | msg.fromAgentSession = client.SessionId.UUID; | ||
168 | msg.fromGroup = false; | ||
169 | msg.imSessionID = transactionID.UUID; | ||
170 | msg.message = agentID.UUID.ToString(); | ||
171 | msg.ParentEstateID = 0; | ||
172 | msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); | ||
173 | msg.RegionID = m_scene.RegionInfo.RegionID.UUID; | ||
174 | msg.dialog = (byte)40;// Deny friend request | ||
175 | msg.Position = new sLLVector3(); | ||
176 | msg.offline = (byte)0; | ||
177 | msg.binaryBucket = new byte[0]; | ||
178 | m_scene.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); | ||
179 | m_pendingFriendRequests.Remove(transactionID); | ||
180 | |||
181 | } | ||
182 | |||
183 | |||
184 | } | ||
185 | |||
186 | private void OnTerminateFriendship(IClientAPI client, LLUUID agent, LLUUID exfriendID) | ||
187 | { | ||
188 | m_scene.StoreRemoveFriendship(agent, exfriendID); | ||
189 | // TODO: Inform the client that the ExFriend is offline | ||
82 | 190 | ||
83 | } | 191 | } |
84 | 192 | ||
193 | |||
194 | private void OnGridInstantMessage(GridInstantMessage msg) | ||
195 | { | ||
196 | // Trigger the above event handler | ||
197 | OnInstantMessage(new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), | ||
198 | new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, | ||
199 | msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, | ||
200 | new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), | ||
201 | msg.binaryBucket); | ||
202 | |||
203 | } | ||
204 | |||
205 | |||
206 | public void PostInitialise() | ||
207 | { | ||
208 | } | ||
209 | |||
210 | |||
211 | |||
85 | public void Close() | 212 | public void Close() |
86 | { | 213 | { |
87 | } | 214 | } |
@@ -93,7 +220,7 @@ namespace OpenSim.Region.Environment.Modules | |||
93 | 220 | ||
94 | public bool IsSharedModule | 221 | public bool IsSharedModule |
95 | { | 222 | { |
96 | get { return true; } | 223 | get { return false; } |
97 | } | 224 | } |
98 | } | 225 | } |
99 | } \ No newline at end of file | 226 | } \ No newline at end of file |