diff options
Diffstat (limited to 'OpenSim/Services/UserAccountService/GridUserService.cs')
-rw-r--r-- | OpenSim/Services/UserAccountService/GridUserService.cs | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs new file mode 100644 index 0000000..697ba63 --- /dev/null +++ b/OpenSim/Services/UserAccountService/GridUserService.cs | |||
@@ -0,0 +1,159 @@ | |||
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.Reflection; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
37 | |||
38 | using OpenMetaverse; | ||
39 | using log4net; | ||
40 | |||
41 | namespace OpenSim.Services.UserAccountService | ||
42 | { | ||
43 | public class GridUserService : GridUserServiceBase, IGridUserService | ||
44 | { | ||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public GridUserService(IConfigSource config) : base(config) | ||
48 | { | ||
49 | m_log.Debug("[USER GRID SERVICE]: Starting user grid service"); | ||
50 | } | ||
51 | |||
52 | public GridUserInfo GetGridUserInfo(string userID) | ||
53 | { | ||
54 | GridUserData d = m_Database.Get(userID); | ||
55 | |||
56 | if (d == null) | ||
57 | return null; | ||
58 | |||
59 | GridUserInfo info = new GridUserInfo(); | ||
60 | info.UserID = d.UserID; | ||
61 | info.HomeRegionID = new UUID(d.Data["HomeRegionID"]); | ||
62 | info.HomePosition = Vector3.Parse(d.Data["HomePosition"]); | ||
63 | info.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); | ||
64 | |||
65 | info.LastRegionID = new UUID(d.Data["LastRegionID"]); | ||
66 | info.LastPosition = Vector3.Parse(d.Data["LastPosition"]); | ||
67 | info.LastLookAt = Vector3.Parse(d.Data["LastLookAt"]); | ||
68 | |||
69 | info.Online = bool.Parse(d.Data["Online"]); | ||
70 | info.Login = Util.ToDateTime(Convert.ToInt32(d.Data["Login"])); | ||
71 | info.Logout = Util.ToDateTime(Convert.ToInt32(d.Data["Logout"])); | ||
72 | |||
73 | return info; | ||
74 | } | ||
75 | |||
76 | public GridUserInfo LoggedIn(string userID) | ||
77 | { | ||
78 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is online", userID); | ||
79 | GridUserData d = m_Database.Get(userID); | ||
80 | |||
81 | if (d == null) | ||
82 | { | ||
83 | d = new GridUserData(); | ||
84 | d.UserID = userID; | ||
85 | } | ||
86 | |||
87 | d.Data["Online"] = true.ToString(); | ||
88 | d.Data["Login"] = Util.UnixTimeSinceEpoch().ToString(); | ||
89 | |||
90 | m_Database.Store(d); | ||
91 | |||
92 | return GetGridUserInfo(userID); | ||
93 | } | ||
94 | |||
95 | public bool LoggedOut(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | ||
96 | { | ||
97 | m_log.DebugFormat("[GRID USER SERVICE]: User {0} is offline", userID); | ||
98 | GridUserData d = m_Database.Get(userID); | ||
99 | |||
100 | if (d == null) | ||
101 | { | ||
102 | d = new GridUserData(); | ||
103 | d.UserID = userID; | ||
104 | } | ||
105 | |||
106 | d.Data["Online"] = false.ToString(); | ||
107 | d.Data["Logout"] = Util.UnixTimeSinceEpoch().ToString(); | ||
108 | d.Data["LastRegionID"] = regionID.ToString(); | ||
109 | d.Data["LastPosition"] = lastPosition.ToString(); | ||
110 | d.Data["LastLookAt"] = lastLookAt.ToString(); | ||
111 | |||
112 | return m_Database.Store(d); | ||
113 | } | ||
114 | |||
115 | protected bool StoreGridUserInfo(GridUserInfo info) | ||
116 | { | ||
117 | GridUserData d = new GridUserData(); | ||
118 | |||
119 | d.Data["HomeRegionID"] = info.HomeRegionID.ToString(); | ||
120 | d.Data["HomePosition"] = info.HomePosition.ToString(); | ||
121 | d.Data["HomeLookAt"] = info.HomeLookAt.ToString(); | ||
122 | |||
123 | return m_Database.Store(d); | ||
124 | } | ||
125 | |||
126 | public bool SetHome(string userID, UUID homeID, Vector3 homePosition, Vector3 homeLookAt) | ||
127 | { | ||
128 | GridUserData d = m_Database.Get(userID); | ||
129 | if (d == null) | ||
130 | { | ||
131 | d = new GridUserData(); | ||
132 | d.UserID = userID; | ||
133 | } | ||
134 | |||
135 | d.Data["HomeRegionID"] = homeID.ToString(); | ||
136 | d.Data["HomePosition"] = homePosition.ToString(); | ||
137 | d.Data["HomeLookAt"] = homeLookAt.ToString(); | ||
138 | |||
139 | return m_Database.Store(d); | ||
140 | } | ||
141 | |||
142 | public bool SetLastPosition(string userID, UUID regionID, Vector3 lastPosition, Vector3 lastLookAt) | ||
143 | { | ||
144 | //m_log.DebugFormat("[Grid User Service]: SetLastPosition for {0}", userID); | ||
145 | GridUserData d = m_Database.Get(userID); | ||
146 | if (d == null) | ||
147 | { | ||
148 | d = new GridUserData(); | ||
149 | d.UserID = userID; | ||
150 | } | ||
151 | |||
152 | d.Data["LastRegionID"] = regionID.ToString(); | ||
153 | d.Data["LastPosition"] = lastPosition.ToString(); | ||
154 | d.Data["LastLookAt"] = lastLookAt.ToString(); | ||
155 | |||
156 | return m_Database.Store(d); | ||
157 | } | ||
158 | } | ||
159 | } \ No newline at end of file | ||