29 using System.Collections.Generic;
31 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Server.Base;
36 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Services.Interfaces;
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54 AllowXForwardedFor =
true,
55 ForgetTimeSpan = TimeSpan.FromMinutes(2),
56 MaxRequestsInTimeframe = 20,
57 ReportingName =
"FRIENDSDOSPROTECTOR",
58 RequestTimeSpan = TimeSpan.FromSeconds(5),
59 ThrottledAction = BasicDOSProtector.ThrottleAction.DoThrottledMethod
62 m_FriendsModule = fmodule;
68 StreamReader sr =
new StreamReader(requestData);
69 string body = sr.ReadToEnd();
77 Dictionary<string, object> request =
78 ServerUtils.ParseQueryString(body);
80 if (!request.ContainsKey(
"METHOD"))
81 return FailureResult();
83 string method = request[
"METHOD"].ToString();
84 request.Remove(
"METHOD");
88 case "friendship_offered":
89 return FriendshipOffered(request);
90 case "friendship_approved":
91 return FriendshipApproved(request);
92 case "friendship_denied":
93 return FriendshipDenied(request);
94 case "friendship_terminated":
95 return FriendshipTerminated(request);
97 return GrantRights(request);
99 return StatusNotification(request);
104 m_log.Debug(
"[FRIENDS]: Exception {0}" + e.ToString());
107 return FailureResult();
110 byte[] FriendshipOffered(Dictionary<string, object> request)
112 UUID fromID = UUID.Zero;
113 UUID toID = UUID.Zero;
114 string message = string.Empty;
116 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID"))
117 return FailureResult();
119 message = request[
"Message"].ToString();
121 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
122 return FailureResult();
124 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
125 return FailureResult();
127 UserAccount account = m_FriendsModule.UserAccountService.GetUserAccount(UUID.Zero, fromID);
128 string name = (account == null) ?
"Unknown" : account.
FirstName +
" " + account.
LastName;
131 (byte)InstantMessageDialog.FriendshipOffered, message,
false, Vector3.Zero);
134 im.imSessionID = im.fromAgentID;
136 if (m_FriendsModule.LocalFriendshipOffered(toID, im))
137 return SuccessResult();
139 return FailureResult();
142 byte[] FriendshipApproved(Dictionary<string, object> request)
144 UUID fromID = UUID.Zero;
145 UUID toID = UUID.Zero;
146 string fromName = string.Empty;
148 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID"))
149 return FailureResult();
151 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
152 return FailureResult();
154 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
155 return FailureResult();
157 if (request.ContainsKey(
"FromName"))
158 fromName = request[
"FromName"].ToString();
160 if (m_FriendsModule.LocalFriendshipApproved(fromID, fromName, toID))
161 return SuccessResult();
163 return FailureResult();
166 byte[] FriendshipDenied(Dictionary<string, object> request)
168 UUID fromID = UUID.Zero;
169 UUID toID = UUID.Zero;
170 string fromName = string.Empty;
172 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID"))
173 return FailureResult();
175 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
176 return FailureResult();
178 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
179 return FailureResult();
181 if (request.ContainsKey(
"FromName"))
182 fromName = request[
"FromName"].ToString();
184 if (m_FriendsModule.LocalFriendshipDenied(fromID, fromName, toID))
185 return SuccessResult();
187 return FailureResult();
190 byte[] FriendshipTerminated(Dictionary<string, object> request)
192 UUID fromID = UUID.Zero;
193 UUID toID = UUID.Zero;
195 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID"))
196 return FailureResult();
198 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
199 return FailureResult();
201 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
202 return FailureResult();
204 if (m_FriendsModule.LocalFriendshipTerminated(fromID, toID))
205 return SuccessResult();
207 return FailureResult();
210 byte[] GrantRights(Dictionary<string, object> request)
212 UUID fromID = UUID.Zero;
213 UUID toID = UUID.Zero;
214 int oldRights = 0, newRights = 0;
216 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID"))
217 return FailureResult();
219 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
220 return FailureResult();
222 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
223 return FailureResult();
225 if (!Int32.TryParse(request[
"UserFlags"].ToString(), out oldRights))
226 return FailureResult();
228 if (!Int32.TryParse(request[
"Rights"].ToString(), out newRights))
229 return FailureResult();
231 if (m_FriendsModule.LocalGrantRights(fromID, toID, oldRights, newRights))
232 return SuccessResult();
234 return FailureResult();
237 byte[] StatusNotification(Dictionary<string, object> request)
239 UUID fromID = UUID.Zero;
240 UUID toID = UUID.Zero;
243 if (!request.ContainsKey(
"FromID") || !request.ContainsKey(
"ToID") || !request.ContainsKey(
"Online"))
244 return FailureResult();
246 if (!UUID.TryParse(request[
"FromID"].ToString(), out fromID))
247 return FailureResult();
249 if (!UUID.TryParse(request[
"ToID"].ToString(), out toID))
250 return FailureResult();
252 if (!Boolean.TryParse(request[
"Online"].ToString(), out online))
253 return FailureResult();
255 if (m_FriendsModule.LocalStatusNotification(fromID, toID, online))
256 return SuccessResult();
258 return FailureResult();
263 private byte[] FailureResult()
265 return BoolResult(
false);
268 private byte[] SuccessResult()
270 return BoolResult(
true);
273 private byte[] BoolResult(
bool value)
275 XmlDocument doc =
new XmlDocument();
277 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
280 doc.AppendChild(xmlnode);
282 XmlElement rootElement = doc.CreateElement(
"",
"ServerResponse",
285 doc.AppendChild(rootElement);
287 XmlElement result = doc.CreateElement(
"",
"RESULT",
"");
288 result.AppendChild(doc.CreateTextNode(value.ToString()));
290 rootElement.AppendChild(result);
292 return Util.DocToBytes(doc);
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
OpenSim.Services.Interfaces.FriendInfo FriendInfo
FriendsRequestHandler(FriendsModule fmodule)
BaseStreamHandlerBasicDOSProtector Base streamed request handler.