aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Data.DB4o
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:10:25 +0000
committerAdam Frisby2007-07-11 08:10:25 +0000
commite2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch)
tree8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Framework/Data.DB4o
parent* Wiping trunk in prep for Sugilite (diff)
parent* Applying dalien's patches from bug#177 and #179 (diff)
downloadopensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Framework/Data.DB4o')
-rw-r--r--OpenSim/Framework/Data.DB4o/DB4oGridData.cs162
-rw-r--r--OpenSim/Framework/Data.DB4o/DB4oManager.cs163
-rw-r--r--OpenSim/Framework/Data.DB4o/DB4oUserData.cs202
-rw-r--r--OpenSim/Framework/Data.DB4o/Properties/AssemblyInfo.cs33
4 files changed, 560 insertions, 0 deletions
diff --git a/OpenSim/Framework/Data.DB4o/DB4oGridData.cs b/OpenSim/Framework/Data.DB4o/DB4oGridData.cs
new file mode 100644
index 0000000..5fec367
--- /dev/null
+++ b/OpenSim/Framework/Data.DB4o/DB4oGridData.cs
@@ -0,0 +1,162 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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
29using System;
30using libsecondlife;
31
32namespace OpenSim.Framework.Data.DB4o
33{
34 /// <summary>
35 /// A grid server storage mechanism employing the DB4o database system
36 /// </summary>
37 class DB4oGridData : IGridData
38 {
39 /// <summary>
40 /// The database manager object
41 /// </summary>
42 DB4oGridManager manager;
43
44 /// <summary>
45 /// Called when the plugin is first loaded (as constructors are not called)
46 /// </summary>
47 public void Initialise() {
48 manager = new DB4oGridManager("gridserver.yap");
49 }
50
51 /// <summary>
52 /// Returns a list of regions within the specified ranges
53 /// </summary>
54 /// <param name="a">minimum X coordinate</param>
55 /// <param name="b">minimum Y coordinate</param>
56 /// <param name="c">maximum X coordinate</param>
57 /// <param name="d">maximum Y coordinate</param>
58 /// <returns>An array of region profiles</returns>
59 public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d)
60 {
61 return null;
62 }
63
64 /// <summary>
65 /// Returns a region located at the specified regionHandle (warning multiple regions may occupy the one spot, first found is returned)
66 /// </summary>
67 /// <param name="handle">The handle to search for</param>
68 /// <returns>A region profile</returns>
69 public SimProfileData GetProfileByHandle(ulong handle) {
70 lock (manager.simProfiles)
71 {
72 foreach (LLUUID UUID in manager.simProfiles.Keys)
73 {
74 if (manager.simProfiles[UUID].regionHandle == handle)
75 {
76 return manager.simProfiles[UUID];
77 }
78 }
79 }
80 throw new Exception("Unable to find profile with handle (" + handle.ToString() + ")");
81 }
82
83 /// <summary>
84 /// Returns a specific region
85 /// </summary>
86 /// <param name="uuid">The region ID code</param>
87 /// <returns>A region profile</returns>
88 public SimProfileData GetProfileByLLUUID(LLUUID uuid)
89 {
90 lock (manager.simProfiles)
91 {
92 if (manager.simProfiles.ContainsKey(uuid))
93 return manager.simProfiles[uuid];
94 }
95 throw new Exception("Unable to find profile with UUID (" + uuid.ToStringHyphenated() + "). Total Registered Regions: " + manager.simProfiles.Count);
96 }
97
98 /// <summary>
99 /// Adds a new specified region to the database
100 /// </summary>
101 /// <param name="profile">The profile to add</param>
102 /// <returns>A dataresponse enum indicating success</returns>
103 public DataResponse AddProfile(SimProfileData profile)
104 {
105 lock (manager.simProfiles)
106 {
107 if (manager.AddRow(profile))
108 {
109 return DataResponse.RESPONSE_OK;
110 }
111 else
112 {
113 return DataResponse.RESPONSE_ERROR;
114 }
115 }
116 }
117
118 /// <summary>
119 /// Authenticates a new region using the shared secrets. NOT SECURE.
120 /// </summary>
121 /// <param name="uuid">The UUID the region is authenticating with</param>
122 /// <param name="handle">The location the region is logging into (unused in Db4o)</param>
123 /// <param name="key">The shared secret</param>
124 /// <returns>Authenticated?</returns>
125 public bool AuthenticateSim(LLUUID uuid, ulong handle, string key) {
126 if (manager.simProfiles[uuid].regionRecvKey == key)
127 return true;
128 return false;
129 }
130
131 /// <summary>
132 /// Shuts down the database
133 /// </summary>
134 public void Close()
135 {
136 manager = null;
137 }
138
139 /// <summary>
140 /// Returns the providers name
141 /// </summary>
142 /// <returns>The name of the storage system</returns>
143 public string getName()
144 {
145 return "DB4o Grid Provider";
146 }
147
148 /// <summary>
149 /// Returns the providers version
150 /// </summary>
151 /// <returns>The version of the storage system</returns>
152 public string getVersion()
153 {
154 return "0.1";
155 }
156
157 public ReservationData GetReservationAtPoint(uint x, uint y)
158 {
159 return null;
160 }
161 }
162}
diff --git a/OpenSim/Framework/Data.DB4o/DB4oManager.cs b/OpenSim/Framework/Data.DB4o/DB4oManager.cs
new file mode 100644
index 0000000..0df6350
--- /dev/null
+++ b/OpenSim/Framework/Data.DB4o/DB4oManager.cs
@@ -0,0 +1,163 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using System.Collections.Generic;
30using Db4objects.Db4o;
31using libsecondlife;
32
33namespace OpenSim.Framework.Data.DB4o
34{
35 /// <summary>
36 /// A Database manager for Db4o
37 /// </summary>
38 class DB4oGridManager
39 {
40 /// <summary>
41 /// A list of the current regions connected (in-memory cache)
42 /// </summary>
43 public Dictionary<LLUUID, SimProfileData> simProfiles = new Dictionary<LLUUID, SimProfileData>();
44 /// <summary>
45 /// Database File Name
46 /// </summary>
47 string dbfl;
48
49 /// <summary>
50 /// Creates a new grid storage manager
51 /// </summary>
52 /// <param name="db4odb">Filename to the database file</param>
53 public DB4oGridManager(string db4odb)
54 {
55 dbfl = db4odb;
56 IObjectContainer database;
57 database = Db4oFactory.OpenFile(dbfl);
58 IObjectSet result = database.Get(typeof(SimProfileData));
59 // Loads the file into the in-memory cache
60 foreach(SimProfileData row in result) {
61 simProfiles.Add(row.UUID, row);
62 }
63 database.Close();
64 }
65
66 /// <summary>
67 /// Adds a new profile to the database (Warning: Probably slow.)
68 /// </summary>
69 /// <param name="row">The profile to add</param>
70 /// <returns>Successful?</returns>
71 public bool AddRow(SimProfileData row)
72 {
73 if (simProfiles.ContainsKey(row.UUID))
74 {
75 simProfiles[row.UUID] = row;
76 }
77 else
78 {
79 simProfiles.Add(row.UUID, row);
80 }
81
82 try
83 {
84 IObjectContainer database;
85 database = Db4oFactory.OpenFile(dbfl);
86 database.Set(row);
87 database.Close();
88 return true;
89 }
90 catch (Exception)
91 {
92 return false;
93 }
94 }
95
96
97 }
98
99 /// <summary>
100 /// A manager for the DB4o database (user profiles)
101 /// </summary>
102 class DB4oUserManager
103 {
104 /// <summary>
105 /// A list of the user profiles (in memory cache)
106 /// </summary>
107 public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>();
108 /// <summary>
109 /// Database filename
110 /// </summary>
111 string dbfl;
112
113 /// <summary>
114 /// Initialises a new DB manager
115 /// </summary>
116 /// <param name="db4odb">The filename to the database</param>
117 public DB4oUserManager(string db4odb)
118 {
119 dbfl = db4odb;
120 IObjectContainer database;
121 database = Db4oFactory.OpenFile(dbfl);
122 // Load to cache
123 IObjectSet result = database.Get(typeof(UserProfileData));
124 foreach (UserProfileData row in result)
125 {
126 userProfiles.Add(row.UUID, row);
127 }
128 database.Close();
129 }
130
131 /// <summary>
132 /// Adds a new profile to the database (Warning: Probably slow.)
133 /// </summary>
134 /// <param name="row">The profile to add</param>
135 /// <returns>Successful?</returns>
136 public bool AddRow(UserProfileData row)
137 {
138 if (userProfiles.ContainsKey(row.UUID))
139 {
140 userProfiles[row.UUID] = row;
141 }
142 else
143 {
144 userProfiles.Add(row.UUID, row);
145 }
146
147 try
148 {
149 IObjectContainer database;
150 database = Db4oFactory.OpenFile(dbfl);
151 database.Set(row);
152 database.Close();
153 return true;
154 }
155 catch (Exception)
156 {
157 return false;
158 }
159 }
160
161
162 }
163}
diff --git a/OpenSim/Framework/Data.DB4o/DB4oUserData.cs b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
new file mode 100644
index 0000000..2e33ab0
--- /dev/null
+++ b/OpenSim/Framework/Data.DB4o/DB4oUserData.cs
@@ -0,0 +1,202 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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*/
28using System;
29using libsecondlife;
30
31namespace OpenSim.Framework.Data.DB4o
32{
33 /// <summary>
34 /// A User storage interface for the DB4o database system
35 /// </summary>
36 public class DB4oUserData : IUserData
37 {
38 /// <summary>
39 /// The database manager
40 /// </summary>
41 DB4oUserManager manager;
42
43 /// <summary>
44 /// Artificial constructor called upon plugin load
45 /// </summary>
46 public void Initialise()
47 {
48 manager = new DB4oUserManager("userprofiles.yap");
49 }
50
51 /// <summary>
52 /// Loads a specified user profile from a UUID
53 /// </summary>
54 /// <param name="uuid">The users UUID</param>
55 /// <returns>A user profile</returns>
56 public UserProfileData getUserByUUID(LLUUID uuid)
57 {
58 if(manager.userProfiles.ContainsKey(uuid))
59 return manager.userProfiles[uuid];
60 return null;
61 }
62
63 /// <summary>
64 /// Returns a user by searching for its name
65 /// </summary>
66 /// <param name="name">The users account name</param>
67 /// <returns>A matching users profile</returns>
68 public UserProfileData getUserByName(string name)
69 {
70 return getUserByName(name.Split(' ')[0], name.Split(' ')[1]);
71 }
72
73 /// <summary>
74 /// Returns a user by searching for its name
75 /// </summary>
76 /// <param name="fname">The first part of the users account name</param>
77 /// <param name="lname">The second part of the users account name</param>
78 /// <returns>A matching users profile</returns>
79 public UserProfileData getUserByName(string fname, string lname)
80 {
81 foreach (UserProfileData profile in manager.userProfiles.Values)
82 {
83 if (profile.username == fname && profile.surname == lname)
84 return profile;
85 }
86 return null;
87 }
88
89 /// <summary>
90 /// Returns a user by UUID direct
91 /// </summary>
92 /// <param name="uuid">The users account ID</param>
93 /// <returns>A matching users profile</returns>
94 public UserAgentData getAgentByUUID(LLUUID uuid)
95 {
96 try
97 {
98 return getUserByUUID(uuid).currentAgent;
99 }
100 catch (Exception)
101 {
102 return null;
103 }
104 }
105
106 /// <summary>
107 /// Returns a session by account name
108 /// </summary>
109 /// <param name="name">The account name</param>
110 /// <returns>The users session agent</returns>
111 public UserAgentData getAgentByName(string name)
112 {
113 return getAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
114 }
115
116 /// <summary>
117 /// Returns a session by account name
118 /// </summary>
119 /// <param name="fname">The first part of the users account name</param>
120 /// <param name="lname">The second part of the users account name</param>
121 /// <returns>A user agent</returns>
122 public UserAgentData getAgentByName(string fname, string lname)
123 {
124 try
125 {
126 return getUserByName(fname,lname).currentAgent;
127 }
128 catch (Exception)
129 {
130 return null;
131 }
132 }
133
134 /// <summary>
135 /// Creates a new user profile
136 /// </summary>
137 /// <param name="user">The profile to add to the database</param>
138 public void addNewUserProfile(UserProfileData user)
139 {
140 try
141 {
142 manager.AddRow(user);
143 }
144 catch (Exception e)
145 {
146 Console.WriteLine(e.ToString());
147 }
148 }
149
150 /// <summary>
151 /// Creates a new user agent
152 /// </summary>
153 /// <param name="agent">The agent to add to the database</param>
154 public void addNewUserAgent(UserAgentData agent)
155 {
156 // Do nothing. yet.
157 }
158
159 /// <summary>
160 /// Transfers money between two user accounts
161 /// </summary>
162 /// <param name="from">Starting account</param>
163 /// <param name="to">End account</param>
164 /// <param name="amount">The amount to move</param>
165 /// <returns>Success?</returns>
166 public bool moneyTransferRequest(LLUUID from, LLUUID to, uint amount)
167 {
168 return true;
169 }
170
171 /// <summary>
172 /// Transfers inventory between two accounts
173 /// </summary>
174 /// <remarks>Move to inventory server</remarks>
175 /// <param name="from">Senders account</param>
176 /// <param name="to">Recievers account</param>
177 /// <param name="item">Inventory item</param>
178 /// <returns>Success?</returns>
179 public bool inventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
180 {
181 return true;
182 }
183
184 /// <summary>
185 /// Returns the name of the storage provider
186 /// </summary>
187 /// <returns>Storage provider name</returns>
188 public string getName()
189 {
190 return "DB4o Userdata";
191 }
192
193 /// <summary>
194 /// Returns the version of the storage provider
195 /// </summary>
196 /// <returns>Storage provider version</returns>
197 public string getVersion()
198 {
199 return "0.1";
200 }
201 }
202}
diff --git a/OpenSim/Framework/Data.DB4o/Properties/AssemblyInfo.cs b/OpenSim/Framework/Data.DB4o/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..905cd9b
--- /dev/null
+++ b/OpenSim/Framework/Data.DB4o/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.InteropServices;
3// General Information about an assembly is controlled through the following
4// set of attributes. Change these attribute values to modify the information
5// associated with an assembly.
6[assembly: AssemblyTitle("OpenSim.Framework.Data.DB4o")]
7[assembly: AssemblyDescription("")]
8[assembly: AssemblyConfiguration("")]
9[assembly: AssemblyCompany("")]
10[assembly: AssemblyProduct("OpenSim.Framework.Data.DB4o")]
11[assembly: AssemblyCopyright("Copyright © 2007")]
12[assembly: AssemblyTrademark("")]
13[assembly: AssemblyCulture("")]
14
15// Setting ComVisible to false makes the types in this assembly not visible
16// to COM components. If you need to access a type in this assembly from
17// COM, set the ComVisible attribute to true on that type.
18[assembly: ComVisible(false)]
19
20// The following GUID is for the ID of the typelib if this project is exposed to COM
21[assembly: Guid("57991e15-79da-41b7-aa06-2e6b49165a63")]
22
23// Version information for an assembly consists of the following four values:
24//
25// Major Version
26// Minor Version
27// Build Number
28// Revision
29//
30// You can specify all the values or you can default the Revision and Build Numbers
31// by using the '*' as shown below:
32[assembly: AssemblyVersion("1.0.0.0")]
33[assembly: AssemblyFileVersion("1.0.0.0")]