diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | 217 |
1 files changed, 167 insertions, 50 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs index ab343c8..79b9a16 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/XmlRpcGroupsServicesConnectorModule.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text; | ||
32 | 33 | ||
33 | using Nwc.XmlRpc; | 34 | using Nwc.XmlRpc; |
34 | 35 | ||
@@ -61,7 +62,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
61 | 62 | ||
62 | private bool m_connectorEnabled = false; | 63 | private bool m_connectorEnabled = false; |
63 | 64 | ||
64 | private string m_serviceURL = string.Empty; | 65 | private string m_groupsServerURI = string.Empty; |
65 | 66 | ||
66 | private bool m_disableKeepAlive = false; | 67 | private bool m_disableKeepAlive = false; |
67 | 68 | ||
@@ -69,7 +70,17 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
69 | private string m_groupWriteKey = string.Empty; | 70 | private string m_groupWriteKey = string.Empty; |
70 | 71 | ||
71 | private IUserAccountService m_accountService = null; | 72 | private IUserAccountService m_accountService = null; |
72 | 73 | ||
74 | private ExpiringCache<string, XmlRpcResponse> m_memoryCache; | ||
75 | private int m_cacheTimeout = 30; | ||
76 | |||
77 | // Used to track which agents are have dropped from a group chat session | ||
78 | // Should be reset per agent, on logon | ||
79 | // TODO: move this to Flotsam XmlRpc Service | ||
80 | // SessionID, List<AgentID> | ||
81 | private Dictionary<UUID, List<UUID>> m_groupsAgentsDroppedFromChatSession = new Dictionary<UUID, List<UUID>>(); | ||
82 | private Dictionary<UUID, List<UUID>> m_groupsAgentsInvitedToChatSession = new Dictionary<UUID, List<UUID>>(); | ||
83 | |||
73 | 84 | ||
74 | #region IRegionModuleBase Members | 85 | #region IRegionModuleBase Members |
75 | 86 | ||
@@ -104,13 +115,13 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
104 | return; | 115 | return; |
105 | } | 116 | } |
106 | 117 | ||
107 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Initializing {0}", this.Name); | 118 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Initializing {0}", this.Name); |
108 | 119 | ||
109 | m_serviceURL = groupsConfig.GetString("XmlRpcServiceURL", string.Empty); | 120 | m_groupsServerURI = groupsConfig.GetString("GroupsServerURI", string.Empty); |
110 | if ((m_serviceURL == null) || | 121 | if ((m_groupsServerURI == null) || |
111 | (m_serviceURL == string.Empty)) | 122 | (m_groupsServerURI == string.Empty)) |
112 | { | 123 | { |
113 | m_log.ErrorFormat("Please specify a valid URL for XmlRpcServiceURL in OpenSim.ini, [Groups]"); | 124 | m_log.ErrorFormat("Please specify a valid URL for GroupsServerURI in OpenSim.ini, [Groups]"); |
114 | m_connectorEnabled = false; | 125 | m_connectorEnabled = false; |
115 | return; | 126 | return; |
116 | } | 127 | } |
@@ -120,17 +131,26 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
120 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); | 131 | m_groupReadKey = groupsConfig.GetString("XmlRpcServiceReadKey", string.Empty); |
121 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); | 132 | m_groupWriteKey = groupsConfig.GetString("XmlRpcServiceWriteKey", string.Empty); |
122 | 133 | ||
123 | |||
124 | 134 | ||
135 | m_cacheTimeout = groupsConfig.GetInt("GroupsCacheTimeout", 30); | ||
136 | if (m_cacheTimeout == 0) | ||
137 | { | ||
138 | m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Disabled."); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Groups Cache Timeout set to {0}.", m_cacheTimeout); | ||
143 | } | ||
125 | 144 | ||
126 | // If we got all the config options we need, lets start'er'up | 145 | // If we got all the config options we need, lets start'er'up |
146 | m_memoryCache = new ExpiringCache<string, XmlRpcResponse>(); | ||
127 | m_connectorEnabled = true; | 147 | m_connectorEnabled = true; |
128 | } | 148 | } |
129 | } | 149 | } |
130 | 150 | ||
131 | public void Close() | 151 | public void Close() |
132 | { | 152 | { |
133 | m_log.InfoFormat("[GROUPS-CONNECTOR]: Closing {0}", this.Name); | 153 | m_log.InfoFormat("[XMLRPC-GROUPS-CONNECTOR]: Closing {0}", this.Name); |
134 | } | 154 | } |
135 | 155 | ||
136 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) | 156 | public void AddRegion(OpenSim.Region.Framework.Scenes.Scene scene) |
@@ -756,6 +776,69 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
756 | 776 | ||
757 | XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param); | 777 | XmlRpcCall(requestingAgentID, "groups.addGroupNotice", param); |
758 | } | 778 | } |
779 | |||
780 | |||
781 | |||
782 | #endregion | ||
783 | |||
784 | #region GroupSessionTracking | ||
785 | |||
786 | public void ResetAgentGroupChatSessions(UUID agentID) | ||
787 | { | ||
788 | foreach (List<UUID> agentList in m_groupsAgentsDroppedFromChatSession.Values) | ||
789 | { | ||
790 | agentList.Remove(agentID); | ||
791 | } | ||
792 | } | ||
793 | |||
794 | public bool hasAgentBeenInvitedToGroupChatSession(UUID agentID, UUID groupID) | ||
795 | { | ||
796 | // If we're tracking this group, and we can find them in the tracking, then they've been invited | ||
797 | return m_groupsAgentsInvitedToChatSession.ContainsKey(groupID) | ||
798 | && m_groupsAgentsInvitedToChatSession[groupID].Contains(agentID); | ||
799 | } | ||
800 | |||
801 | public bool hasAgentDroppedGroupChatSession(UUID agentID, UUID groupID) | ||
802 | { | ||
803 | // If we're tracking drops for this group, | ||
804 | // and we find them, well... then they've dropped | ||
805 | return m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID) | ||
806 | && m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID); | ||
807 | } | ||
808 | |||
809 | public void AgentDroppedFromGroupChatSession(UUID agentID, UUID groupID) | ||
810 | { | ||
811 | if (m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)) | ||
812 | { | ||
813 | // If not in dropped list, add | ||
814 | if (!m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID)) | ||
815 | { | ||
816 | m_groupsAgentsDroppedFromChatSession[groupID].Add(agentID); | ||
817 | } | ||
818 | } | ||
819 | } | ||
820 | |||
821 | public void AgentInvitedToGroupChatSession(UUID agentID, UUID groupID) | ||
822 | { | ||
823 | // Add Session Status if it doesn't exist for this session | ||
824 | CreateGroupChatSessionTracking(groupID); | ||
825 | |||
826 | // If nessesary, remove from dropped list | ||
827 | if (m_groupsAgentsDroppedFromChatSession[groupID].Contains(agentID)) | ||
828 | { | ||
829 | m_groupsAgentsDroppedFromChatSession[groupID].Remove(agentID); | ||
830 | } | ||
831 | } | ||
832 | |||
833 | private void CreateGroupChatSessionTracking(UUID groupID) | ||
834 | { | ||
835 | if (!m_groupsAgentsDroppedFromChatSession.ContainsKey(groupID)) | ||
836 | { | ||
837 | m_groupsAgentsDroppedFromChatSession.Add(groupID, new List<UUID>()); | ||
838 | m_groupsAgentsInvitedToChatSession.Add(groupID, new List<UUID>()); | ||
839 | } | ||
840 | |||
841 | } | ||
759 | #endregion | 842 | #endregion |
760 | 843 | ||
761 | #region XmlRpcHashtableMarshalling | 844 | #region XmlRpcHashtableMarshalling |
@@ -849,50 +932,84 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
849 | /// </summary> | 932 | /// </summary> |
850 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) | 933 | private Hashtable XmlRpcCall(UUID requestingAgentID, string function, Hashtable param) |
851 | { | 934 | { |
852 | string UserService; | 935 | XmlRpcResponse resp = null; |
853 | UUID SessionID; | 936 | string CacheKey = null; |
854 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | 937 | |
855 | param.Add("requestingAgentID", requestingAgentID.ToString()); | 938 | // Only bother with the cache if it isn't disabled. |
856 | param.Add("RequestingAgentUserService", UserService); | 939 | if (m_cacheTimeout > 0) |
857 | param.Add("RequestingSessionID", SessionID.ToString()); | 940 | { |
858 | 941 | if (!function.StartsWith("groups.get")) | |
942 | { | ||
943 | // Any and all updates cause the cache to clear | ||
944 | m_memoryCache.Clear(); | ||
945 | } | ||
946 | else | ||
947 | { | ||
948 | StringBuilder sb = new StringBuilder(requestingAgentID + function); | ||
949 | foreach (object key in param.Keys) | ||
950 | { | ||
951 | if (param[key] != null) | ||
952 | { | ||
953 | sb.AppendFormat(",{0}:{1}", key.ToString(), param[key].ToString()); | ||
954 | } | ||
955 | } | ||
956 | |||
957 | CacheKey = sb.ToString(); | ||
958 | m_memoryCache.TryGetValue(CacheKey, out resp); | ||
959 | } | ||
859 | 960 | ||
860 | param.Add("ReadKey", m_groupReadKey); | 961 | } |
861 | param.Add("WriteKey", m_groupWriteKey); | 962 | |
963 | if( resp == null ) | ||
964 | { | ||
965 | string UserService; | ||
966 | UUID SessionID; | ||
967 | GetClientGroupRequestID(requestingAgentID, out UserService, out SessionID); | ||
968 | param.Add("requestingAgentID", requestingAgentID.ToString()); | ||
969 | param.Add("RequestingAgentUserService", UserService); | ||
970 | param.Add("RequestingSessionID", SessionID.ToString()); | ||
862 | 971 | ||
863 | 972 | ||
864 | IList parameters = new ArrayList(); | 973 | param.Add("ReadKey", m_groupReadKey); |
865 | parameters.Add(param); | 974 | param.Add("WriteKey", m_groupWriteKey); |
866 | 975 | ||
867 | ConfigurableKeepAliveXmlRpcRequest req; | ||
868 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); | ||
869 | 976 | ||
870 | XmlRpcResponse resp = null; | 977 | IList parameters = new ArrayList(); |
978 | parameters.Add(param); | ||
871 | 979 | ||
872 | try | 980 | ConfigurableKeepAliveXmlRpcRequest req; |
873 | { | 981 | req = new ConfigurableKeepAliveXmlRpcRequest(function, parameters, m_disableKeepAlive); |
874 | resp = req.Send(m_serviceURL, 10000); | ||
875 | } | ||
876 | catch (Exception e) | ||
877 | { | ||
878 | |||
879 | 982 | ||
880 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); | ||
881 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", e.ToString()); | ||
882 | 983 | ||
883 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine },StringSplitOptions.None)) | 984 | try |
884 | { | 985 | { |
885 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} ", ResponseLine); | 986 | resp = req.Send(m_groupsServerURI, 10000); |
886 | } | ||
887 | 987 | ||
888 | foreach (string key in param.Keys) | 988 | if ((m_cacheTimeout > 0) && (CacheKey != null)) |
989 | { | ||
990 | m_memoryCache.AddOrUpdate(CacheKey, resp, TimeSpan.FromSeconds(m_cacheTimeout)); | ||
991 | } | ||
992 | |||
993 | } | ||
994 | catch (Exception e) | ||
889 | { | 995 | { |
890 | m_log.WarnFormat("[XMLRPCGROUPDATA]: {0} :: {1}", key, param[key].ToString()); | 996 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: An error has occured while attempting to access the XmlRpcGroups server method: {0}", function); |
997 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", e.ToString()); | ||
998 | |||
999 | foreach (string ResponseLine in req.RequestResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) | ||
1000 | { | ||
1001 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} ", ResponseLine); | ||
1002 | } | ||
1003 | |||
1004 | foreach (string key in param.Keys) | ||
1005 | { | ||
1006 | m_log.WarnFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", key, param[key].ToString()); | ||
1007 | } | ||
1008 | |||
1009 | Hashtable respData = new Hashtable(); | ||
1010 | respData.Add("error", e.ToString()); | ||
1011 | return respData; | ||
891 | } | 1012 | } |
892 | |||
893 | Hashtable respData = new Hashtable(); | ||
894 | respData.Add("error", e.ToString()); | ||
895 | return respData; | ||
896 | } | 1013 | } |
897 | 1014 | ||
898 | if (resp.Value is Hashtable) | 1015 | if (resp.Value is Hashtable) |
@@ -906,21 +1023,21 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
906 | return respData; | 1023 | return respData; |
907 | } | 1024 | } |
908 | 1025 | ||
909 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString()); | 1026 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: The XmlRpc server returned a {1} instead of a hashtable for {0}", function, resp.Value.GetType().ToString()); |
910 | 1027 | ||
911 | if (resp.Value is ArrayList) | 1028 | if (resp.Value is ArrayList) |
912 | { | 1029 | { |
913 | ArrayList al = (ArrayList)resp.Value; | 1030 | ArrayList al = (ArrayList)resp.Value; |
914 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Contains {0} elements", al.Count); | 1031 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Contains {0} elements", al.Count); |
915 | 1032 | ||
916 | foreach (object o in al) | 1033 | foreach (object o in al) |
917 | { | 1034 | { |
918 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0} :: {1}", o.GetType().ToString(), o.ToString()); | 1035 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0} :: {1}", o.GetType().ToString(), o.ToString()); |
919 | } | 1036 | } |
920 | } | 1037 | } |
921 | else | 1038 | else |
922 | { | 1039 | { |
923 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Function returned: {0}", resp.Value.ToString()); | 1040 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Function returned: {0}", resp.Value.ToString()); |
924 | } | 1041 | } |
925 | 1042 | ||
926 | Hashtable error = new Hashtable(); | 1043 | Hashtable error = new Hashtable(); |
@@ -930,16 +1047,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
930 | 1047 | ||
931 | private void LogRespDataToConsoleError(Hashtable respData) | 1048 | private void LogRespDataToConsoleError(Hashtable respData) |
932 | { | 1049 | { |
933 | m_log.Error("[XMLRPCGROUPDATA]: Error:"); | 1050 | m_log.Error("[XMLRPC-GROUPS-CONNECTOR]: Error:"); |
934 | 1051 | ||
935 | foreach (string key in respData.Keys) | 1052 | foreach (string key in respData.Keys) |
936 | { | 1053 | { |
937 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: Key: {0}", key); | 1054 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: Key: {0}", key); |
938 | 1055 | ||
939 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); | 1056 | string[] lines = respData[key].ToString().Split(new char[] { '\n' }); |
940 | foreach (string line in lines) | 1057 | foreach (string line in lines) |
941 | { | 1058 | { |
942 | m_log.ErrorFormat("[XMLRPCGROUPDATA]: {0}", line); | 1059 | m_log.ErrorFormat("[XMLRPC-GROUPS-CONNECTOR]: {0}", line); |
943 | } | 1060 | } |
944 | 1061 | ||
945 | } | 1062 | } |
@@ -948,8 +1065,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
948 | 1065 | ||
949 | /// <summary> | 1066 | /// <summary> |
950 | /// Group Request Tokens are an attempt to allow the groups service to authenticate | 1067 | /// Group Request Tokens are an attempt to allow the groups service to authenticate |
951 | /// requests. Currently uses UserService, AgentID, and SessionID | 1068 | /// requests. |
952 | /// TODO: Find a better way to do this. | 1069 | /// TODO: This broke after the big grid refactor, either find a better way, or discard this |
953 | /// </summary> | 1070 | /// </summary> |
954 | /// <param name="client"></param> | 1071 | /// <param name="client"></param> |
955 | /// <returns></returns> | 1072 | /// <returns></returns> |