aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs')
-rw-r--r--Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs161
1 files changed, 161 insertions, 0 deletions
diff --git a/Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs b/Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs
new file mode 100644
index 0000000..2b23131
--- /dev/null
+++ b/Common/OpenGrid.Framework.Data.DB4o/DB4oGridData.cs
@@ -0,0 +1,161 @@
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 System.Collections.Generic;
31using System.Text;
32using OpenGrid.Framework.Data;
33using libsecondlife;
34
35
36namespace OpenGrid.Framework.Data.DB4o
37{
38 /// <summary>
39 /// A grid server storage mechanism employing the DB4o database system
40 /// </summary>
41 class DB4oGridData : IGridData
42 {
43 /// <summary>
44 /// The database manager object
45 /// </summary>
46 DB4oGridManager manager;
47
48 /// <summary>
49 /// Called when the plugin is first loaded (as constructors are not called)
50 /// </summary>
51 public void Initialise() {
52 manager = new DB4oGridManager("gridserver.yap");
53 }
54
55 /// <summary>
56 /// Returns a list of regions within the specified ranges
57 /// </summary>
58 /// <param name="a">minimum X coordinate</param>
59 /// <param name="b">minimum Y coordinate</param>
60 /// <param name="c">maximum X coordinate</param>
61 /// <param name="d">maximum Y coordinate</param>
62 /// <returns>An array of region profiles</returns>
63 public SimProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d)
64 {
65 return null;
66 }
67
68 /// <summary>
69 /// Returns a region located at the specified regionHandle (warning multiple regions may occupy the one spot, first found is returned)
70 /// </summary>
71 /// <param name="handle">The handle to search for</param>
72 /// <returns>A region profile</returns>
73 public SimProfileData GetProfileByHandle(ulong handle) {
74 lock (manager.simProfiles)
75 {
76 foreach (LLUUID UUID in manager.simProfiles.Keys)
77 {
78 if (manager.simProfiles[UUID].regionHandle == handle)
79 {
80 return manager.simProfiles[UUID];
81 }
82 }
83 }
84 throw new Exception("Unable to find profile with handle (" + handle.ToString() + ")");
85 }
86
87 /// <summary>
88 /// Returns a specific region
89 /// </summary>
90 /// <param name="uuid">The region ID code</param>
91 /// <returns>A region profile</returns>
92 public SimProfileData GetProfileByLLUUID(LLUUID uuid)
93 {
94 lock (manager.simProfiles)
95 {
96 if (manager.simProfiles.ContainsKey(uuid))
97 return manager.simProfiles[uuid];
98 }
99 throw new Exception("Unable to find profile with UUID (" + uuid.ToStringHyphenated() + ")");
100 }
101
102 /// <summary>
103 /// Adds a new specified region to the database
104 /// </summary>
105 /// <param name="profile">The profile to add</param>
106 /// <returns>A dataresponse enum indicating success</returns>
107 public DataResponse AddProfile(SimProfileData profile)
108 {
109 lock (manager.simProfiles)
110 {
111 if (manager.AddRow(profile))
112 {
113 return DataResponse.RESPONSE_OK;
114 }
115 else
116 {
117 return DataResponse.RESPONSE_ERROR;
118 }
119 }
120 }
121
122 /// <summary>
123 /// Authenticates a new region using the shared secrets. NOT SECURE.
124 /// </summary>
125 /// <param name="uuid">The UUID the region is authenticating with</param>
126 /// <param name="handle">The location the region is logging into (unused in Db4o)</param>
127 /// <param name="key">The shared secret</param>
128 /// <returns>Authenticated?</returns>
129 public bool AuthenticateSim(LLUUID uuid, ulong handle, string key) {
130 if (manager.simProfiles[uuid].regionRecvKey == key)
131 return true;
132 return false;
133 }
134
135 /// <summary>
136 /// Shuts down the database
137 /// </summary>
138 public void Close()
139 {
140 manager = null;
141 }
142
143 /// <summary>
144 /// Returns the providers name
145 /// </summary>
146 /// <returns>The name of the storage system</returns>
147 public string getName()
148 {
149 return "DB4o Grid Provider";
150 }
151
152 /// <summary>
153 /// Returns the providers version
154 /// </summary>
155 /// <returns>The version of the storage system</returns>
156 public string getVersion()
157 {
158 return "0.1";
159 }
160 }
161}