aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server')
-rw-r--r--OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs23
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs112
2 files changed, 97 insertions, 38 deletions
diff --git a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
index 64002e1..71c3c73 100644
--- a/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Friends/FriendsServerPostHandler.cs
@@ -82,6 +82,9 @@ namespace OpenSim.Server.Handlers.Friends
82 case "getfriends": 82 case "getfriends":
83 return GetFriends(request); 83 return GetFriends(request);
84 84
85 case "getfriends_string":
86 return GetFriendsString(request);
87
85 case "storefriend": 88 case "storefriend":
86 return StoreFriend(request); 89 return StoreFriend(request);
87 90
@@ -111,7 +114,25 @@ namespace OpenSim.Server.Handlers.Friends
111 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends"); 114 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends");
112 115
113 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); 116 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID);
114 //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); 117
118 return PackageFriends(finfos);
119 }
120
121 byte[] GetFriendsString(Dictionary<string, object> request)
122 {
123 string principalID = string.Empty;
124 if (request.ContainsKey("PRINCIPALID"))
125 principalID = request["PRINCIPALID"].ToString();
126 else
127 m_log.WarnFormat("[FRIENDS HANDLER]: no principalID in request to get friends");
128
129 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID);
130
131 return PackageFriends(finfos);
132 }
133
134 private byte[] PackageFriends(FriendInfo[] finfos)
135 {
115 136
116 Dictionary<string, object> result = new Dictionary<string, object>(); 137 Dictionary<string, object> result = new Dictionary<string, object>();
117 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) 138 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0)))
diff --git a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
index 13d1502..dde7875 100644
--- a/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
+++ b/OpenSim/Server/Handlers/Hypergrid/HGFriendsServerPostHandler.cs
@@ -82,8 +82,8 @@ namespace OpenSim.Server.Handlers.Hypergrid
82 82
83 switch (method) 83 switch (method)
84 { 84 {
85 case "getfriends": 85 case "getfriendperms":
86 return GetFriends(request); 86 return GetFriendPerms(request);
87 87
88 case "newfriendship": 88 case "newfriendship":
89 return NewFriendship(request); 89 return NewFriendship(request);
@@ -102,58 +102,45 @@ namespace OpenSim.Server.Handlers.Hypergrid
102 102
103 #region Method-specific handlers 103 #region Method-specific handlers
104 104
105 byte[] GetFriends(Dictionary<string, object> request) 105 byte[] GetFriendPerms(Dictionary<string, object> request)
106 { 106 {
107 if (!VerifyServiceKey(request))
108 return FailureResult();
109
107 UUID principalID = UUID.Zero; 110 UUID principalID = UUID.Zero;
108 if (request.ContainsKey("PRINCIPALID")) 111 if (request.ContainsKey("PRINCIPALID"))
109 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID); 112 UUID.TryParse(request["PRINCIPALID"].ToString(), out principalID);
110 else 113 else
111 m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friends"); 114 {
112 115 m_log.WarnFormat("[HGFRIENDS HANDLER]: no principalID in request to get friend perms");
113 FriendInfo[] finfos = m_FriendsService.GetFriends(principalID); 116 return FailureResult();
114 //m_log.DebugFormat("[FRIENDS HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count); 117 }
115 118
116 Dictionary<string, object> result = new Dictionary<string, object>(); 119 UUID friendID = UUID.Zero;
117 if ((finfos == null) || ((finfos != null) && (finfos.Length == 0))) 120 if (request.ContainsKey("FRIENDID"))
118 result["result"] = "null"; 121 UUID.TryParse(request["FRIENDID"].ToString(), out friendID);
119 else 122 else
120 { 123 {
121 int i = 0; 124 m_log.WarnFormat("[HGFRIENDS HANDLER]: no friendID in request to get friend perms");
122 foreach (FriendInfo finfo in finfos) 125 return FailureResult();
123 {
124 Dictionary<string, object> rinfoDict = finfo.ToKeyValuePairs();
125 result["friend" + i] = rinfoDict;
126 i++;
127 }
128 } 126 }
129 127
130 string xmlString = ServerUtils.BuildXmlResponse(result); 128 string perms = "0";
131 //m_log.DebugFormat("[FRIENDS HANDLER]: resp string: {0}", xmlString); 129 FriendInfo[] friendsInfo = m_FriendsService.GetFriends(principalID);
132 UTF8Encoding encoding = new UTF8Encoding(); 130 foreach (FriendInfo finfo in friendsInfo)
133 return encoding.GetBytes(xmlString); 131 {
132 if (finfo.Friend.StartsWith(friendID.ToString()))
133 return SuccessResult(finfo.TheirFlags.ToString());
134 }
134 135
136 return FailureResult("Friend not found");
135 } 137 }
136 138
137 byte[] NewFriendship(Dictionary<string, object> request) 139 byte[] NewFriendship(Dictionary<string, object> request)
138 { 140 {
139 if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID")) 141 if (!VerifyServiceKey(request))
140 {
141 m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID");
142 return FailureResult();
143 }
144
145 string serviceKey = request["KEY"].ToString();
146 string sessionStr = request["SESSIONID"].ToString();
147 UUID sessionID;
148 UUID.TryParse(sessionStr, out sessionID);
149
150 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
151 {
152 m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID);
153 return FailureResult(); 142 return FailureResult();
154 }
155 143
156 m_log.DebugFormat("[XXX] Verification ok");
157 // OK, can proceed 144 // OK, can proceed
158 FriendInfo friend = new FriendInfo(request); 145 FriendInfo friend = new FriendInfo(request);
159 146
@@ -172,6 +159,29 @@ namespace OpenSim.Server.Handlers.Hypergrid
172 159
173 #region Misc 160 #region Misc
174 161
162 private bool VerifyServiceKey(Dictionary<string, object> request)
163 {
164 if (!request.ContainsKey("KEY") || !request.ContainsKey("SESSIONID"))
165 {
166 m_log.WarnFormat("[HGFRIENDS HANDLER]: ignoring request without Key or SessionID");
167 return false;
168 }
169
170 string serviceKey = request["KEY"].ToString();
171 string sessionStr = request["SESSIONID"].ToString();
172 UUID sessionID;
173 UUID.TryParse(sessionStr, out sessionID);
174
175 if (!m_UserAgentService.VerifyAgent(sessionID, serviceKey))
176 {
177 m_log.WarnFormat("[HGFRIENDS HANDLER]: Key {0} for session {1} did not match existing key. Ignoring request", serviceKey, sessionID);
178 return false;
179 }
180
181 m_log.DebugFormat("[XXX] Verification ok");
182 return true;
183 }
184
175 private byte[] SuccessResult() 185 private byte[] SuccessResult()
176 { 186 {
177 XmlDocument doc = new XmlDocument(); 187 XmlDocument doc = new XmlDocument();
@@ -194,6 +204,34 @@ namespace OpenSim.Server.Handlers.Hypergrid
194 return DocToBytes(doc); 204 return DocToBytes(doc);
195 } 205 }
196 206
207 private byte[] SuccessResult(string value)
208 {
209 XmlDocument doc = new XmlDocument();
210
211 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
212 "", "");
213
214 doc.AppendChild(xmlnode);
215
216 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
217 "");
218
219 doc.AppendChild(rootElement);
220
221 XmlElement result = doc.CreateElement("", "Result", "");
222 result.AppendChild(doc.CreateTextNode("Success"));
223
224 rootElement.AppendChild(result);
225
226 XmlElement message = doc.CreateElement("", "Value", "");
227 message.AppendChild(doc.CreateTextNode(value));
228
229 rootElement.AppendChild(message);
230
231 return DocToBytes(doc);
232 }
233
234
197 private byte[] FailureResult() 235 private byte[] FailureResult()
198 { 236 {
199 return FailureResult(String.Empty); 237 return FailureResult(String.Empty);