opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 System;
29 using System.Collections.Generic;
30 using System.Net;
31 using System.Reflection;
32 using Nini.Config;
33 using log4net;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
36 using OpenSim.Data;
37 using OpenSim.Services.Interfaces;
38 using OpenMetaverse;
39  
40 namespace OpenSim.Services.PresenceService
41 {
42 public class PresenceService : PresenceServiceBase, IPresenceService
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47  
48 protected bool m_allowDuplicatePresences = false;
49  
50 public PresenceService(IConfigSource config)
51 : base(config)
52 {
53 m_log.Debug("[PRESENCE SERVICE]: Starting presence service");
54  
55 IConfig presenceConfig = config.Configs["PresenceService"];
56 if (presenceConfig != null)
57 {
58 m_allowDuplicatePresences =
59 presenceConfig.GetBoolean("AllowDuplicatePresences",
60 m_allowDuplicatePresences);
61 }
62 }
63  
64 public bool LoginAgent(string userID, UUID sessionID,
65 UUID secureSessionID)
66 {
67 //PresenceData[] d = m_Database.Get("UserID", userID);
68 //m_Database.Get("UserID", userID);
69  
70 if (!m_allowDuplicatePresences)
71 m_Database.Delete("UserID", userID.ToString());
72  
73 PresenceData data = new PresenceData();
74  
75 data.UserID = userID;
76 data.RegionID = UUID.Zero;
77 data.SessionID = sessionID;
78 data.Data = new Dictionary<string, string>();
79 data.Data["SecureSessionID"] = secureSessionID.ToString();
80  
81 m_Database.Store(data);
82  
83 m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent {0} with session {1} and ssession {2}",
84 userID, sessionID, secureSessionID);
85 return true;
86 }
87  
88 public bool LogoutAgent(UUID sessionID)
89 {
90 m_log.DebugFormat("[PRESENCE SERVICE]: Session {0} logout", sessionID);
91 return m_Database.Delete("SessionID", sessionID.ToString());
92 }
93  
94 public bool LogoutRegionAgents(UUID regionID)
95 {
96 m_Database.LogoutRegionAgents(regionID);
97  
98 return true;
99 }
100  
101  
102 public bool ReportAgent(UUID sessionID, UUID regionID)
103 {
104 // m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent with session {0} in region {1}", sessionID, regionID);
105 try
106 {
107 PresenceData pdata = m_Database.Get(sessionID);
108 if (pdata == null)
109 return false;
110 if (pdata.Data == null)
111 return false;
112  
113 return m_Database.ReportAgent(sessionID, regionID);
114 }
115 catch (Exception e)
116 {
117 m_log.DebugFormat("[PRESENCE SERVICE]: ReportAgent threw exception {0}", e.StackTrace);
118 return false;
119 }
120 }
121  
122 public PresenceInfo GetAgent(UUID sessionID)
123 {
124 PresenceInfo ret = new PresenceInfo();
125  
126 PresenceData data = m_Database.Get(sessionID);
127 if (data == null)
128 return null;
129  
130 ret.UserID = data.UserID;
131 ret.RegionID = data.RegionID;
132  
133 return ret;
134 }
135  
136 public PresenceInfo[] GetAgents(string[] userIDs)
137 {
138 List<PresenceInfo> info = new List<PresenceInfo>();
139  
140 foreach (string userIDStr in userIDs)
141 {
142 PresenceData[] data = m_Database.Get("UserID",
143 userIDStr);
144  
145 foreach (PresenceData d in data)
146 {
147 PresenceInfo ret = new PresenceInfo();
148  
149 ret.UserID = d.UserID;
150 ret.RegionID = d.RegionID;
151  
152 info.Add(ret);
153 }
154  
155 // m_log.DebugFormat(
156 // "[PRESENCE SERVICE]: GetAgents for {0} found {1} presences", userIDStr, data.Length);
157 }
158  
159 return info.ToArray();
160 }
161 }
162 }