diff options
author | Melanie | 2014-02-04 02:29:02 +0000 |
---|---|---|
committer | Melanie | 2014-02-04 02:29:02 +0000 |
commit | f0f852b27fa33d8d5e0ee573a9a4a220150c9a44 (patch) | |
tree | deb6aa6b3c3561e6a8d4f78c242fc3ced6d3bcc0 /OpenSim/Server | |
parent | Adding the Avination XBakesModule, the client for the persistent bakes system (diff) | |
download | opensim-SC_OLD-f0f852b27fa33d8d5e0ee573a9a4a220150c9a44.zip opensim-SC_OLD-f0f852b27fa33d8d5e0ee573a9a4a220150c9a44.tar.gz opensim-SC_OLD-f0f852b27fa33d8d5e0ee573a9a4a220150c9a44.tar.bz2 opensim-SC_OLD-f0f852b27fa33d8d5e0ee573a9a4a220150c9a44.tar.xz |
Final code drop for appearance. Adding Avination's baked texture storage server.
Diffstat (limited to 'OpenSim/Server')
4 files changed, 364 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakes.cs b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs new file mode 100644 index 0000000..d1b2e12 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakes.cs | |||
@@ -0,0 +1,150 @@ | |||
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.Diagnostics; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using System.Reflection; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Console; | ||
37 | using OpenSim.Server.Base; | ||
38 | using OpenSim.Services.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using Nini.Config; | ||
41 | using log4net; | ||
42 | using OpenMetaverse; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.BakedTextures | ||
45 | { | ||
46 | public class XBakes : ServiceBase, IBakedTextureService | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger( | ||
50 | MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | protected string m_FSBase; | ||
53 | |||
54 | private System.Text.UTF8Encoding utf8encoding = | ||
55 | new System.Text.UTF8Encoding(); | ||
56 | |||
57 | public XBakes(IConfigSource config) : base(config) | ||
58 | { | ||
59 | MainConsole.Instance.Commands.AddCommand("fs", false, | ||
60 | "delete bakes", "delete bakes <ID>", | ||
61 | "Delete agent's baked textures from server", | ||
62 | HandleDeleteBakes); | ||
63 | |||
64 | IConfig assetConfig = config.Configs["BakedTextureService"]; | ||
65 | if (assetConfig == null) | ||
66 | { | ||
67 | throw new Exception("No BakedTextureService configuration"); | ||
68 | } | ||
69 | |||
70 | m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty); | ||
71 | if (m_FSBase == String.Empty) | ||
72 | { | ||
73 | m_log.ErrorFormat("[BAKES]: BaseDirectory not specified"); | ||
74 | throw new Exception("Configuration error"); | ||
75 | } | ||
76 | |||
77 | m_log.Info("[BAKES]: XBakes service enabled"); | ||
78 | } | ||
79 | |||
80 | public string Get(string id) | ||
81 | { | ||
82 | string file = HashToFile(id); | ||
83 | string diskFile = Path.Combine(m_FSBase, file); | ||
84 | |||
85 | if (File.Exists(diskFile)) | ||
86 | { | ||
87 | try | ||
88 | { | ||
89 | byte[] content = File.ReadAllBytes(diskFile); | ||
90 | |||
91 | return utf8encoding.GetString(content); | ||
92 | } | ||
93 | catch | ||
94 | { | ||
95 | } | ||
96 | } | ||
97 | return String.Empty; | ||
98 | } | ||
99 | |||
100 | public void Store(string id, string sdata) | ||
101 | { | ||
102 | string file = HashToFile(id); | ||
103 | string diskFile = Path.Combine(m_FSBase, file); | ||
104 | |||
105 | Directory.CreateDirectory(Path.GetDirectoryName(diskFile)); | ||
106 | |||
107 | File.Delete(diskFile); | ||
108 | |||
109 | byte[] data = utf8encoding.GetBytes(sdata); | ||
110 | FileStream fs = File.Create(diskFile); | ||
111 | |||
112 | fs.Write(data, 0, data.Length); | ||
113 | |||
114 | fs.Close(); | ||
115 | } | ||
116 | |||
117 | private void HandleDeleteBakes(string module, string[] args) | ||
118 | { | ||
119 | if (args.Length < 3) | ||
120 | { | ||
121 | MainConsole.Instance.Output("Syntax: delete bakes <ID>"); | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | string file = HashToFile(args[2]); | ||
126 | string diskFile = Path.Combine(m_FSBase, file); | ||
127 | |||
128 | if (File.Exists(diskFile)) | ||
129 | { | ||
130 | File.Delete(diskFile); | ||
131 | MainConsole.Instance.Output("Bakes deleted"); | ||
132 | return; | ||
133 | } | ||
134 | MainConsole.Instance.Output("Bakes not found"); | ||
135 | } | ||
136 | |||
137 | public string HashToPath(string hash) | ||
138 | { | ||
139 | return Path.Combine(hash.Substring(0, 2), | ||
140 | Path.Combine(hash.Substring(2, 2), | ||
141 | Path.Combine(hash.Substring(4, 2), | ||
142 | hash.Substring(6, 4)))); | ||
143 | } | ||
144 | |||
145 | public string HashToFile(string hash) | ||
146 | { | ||
147 | return Path.Combine(HashToPath(hash), hash); | ||
148 | } | ||
149 | } | ||
150 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs new file mode 100644 index 0000000..fb4b794 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesGetHandler.cs | |||
@@ -0,0 +1,70 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.BakedTextures | ||
44 | { | ||
45 | public class BakesServerGetHandler : BaseStreamHandler | ||
46 | { | ||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private IBakedTextureService m_BakesService; | ||
50 | private System.Text.UTF8Encoding utf8 = | ||
51 | new System.Text.UTF8Encoding(); | ||
52 | |||
53 | public BakesServerGetHandler(IBakedTextureService service) : | ||
54 | base("GET", "/bakes") | ||
55 | { | ||
56 | m_BakesService = service; | ||
57 | } | ||
58 | |||
59 | public override byte[] Handle(string path, Stream request, | ||
60 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
61 | { | ||
62 | string[] p = SplitParams(path); | ||
63 | |||
64 | if (p.Length == 0) | ||
65 | return new byte[0]; | ||
66 | |||
67 | return utf8.GetBytes(m_BakesService.Get(p[0])); | ||
68 | } | ||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs new file mode 100644 index 0000000..7bf7641 --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesHandler.cs | |||
@@ -0,0 +1,66 @@ | |||
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 Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | |||
35 | namespace OpenSim.Server.Handlers.BakedTextures | ||
36 | { | ||
37 | public class XBakesConnector : ServiceConnector | ||
38 | { | ||
39 | private IBakedTextureService m_BakesService; | ||
40 | private string m_ConfigName = "BakedTextureService"; | ||
41 | |||
42 | public XBakesConnector(IConfigSource config, IHttpServer server, string configName) : | ||
43 | base(config, server, configName) | ||
44 | { | ||
45 | if (configName != String.Empty) | ||
46 | m_ConfigName = configName; | ||
47 | |||
48 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
49 | if (serverConfig == null) | ||
50 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
51 | |||
52 | string assetService = serverConfig.GetString("LocalServiceModule", | ||
53 | String.Empty); | ||
54 | |||
55 | if (assetService == String.Empty) | ||
56 | throw new Exception("No BakedTextureService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_BakesService = | ||
60 | ServerUtils.LoadPlugin<IBakedTextureService>(assetService, args); | ||
61 | |||
62 | server.AddStreamHandler(new BakesServerGetHandler(m_BakesService)); | ||
63 | server.AddStreamHandler(new BakesServerPostHandler(m_BakesService)); | ||
64 | } | ||
65 | } | ||
66 | } | ||
diff --git a/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs new file mode 100644 index 0000000..69adb7f --- /dev/null +++ b/OpenSim/Server/Handlers/BakedTextures/XBakesPostHandler.cs | |||
@@ -0,0 +1,78 @@ | |||
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 Nini.Config; | ||
29 | using log4net; | ||
30 | using System; | ||
31 | using System.Reflection; | ||
32 | using System.IO; | ||
33 | using System.Net; | ||
34 | using System.Text; | ||
35 | using System.Text.RegularExpressions; | ||
36 | using System.Xml; | ||
37 | using System.Xml.Serialization; | ||
38 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | |||
43 | namespace OpenSim.Server.Handlers.BakedTextures | ||
44 | { | ||
45 | public class BakesServerPostHandler : BaseStreamHandler | ||
46 | { | ||
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | private IBakedTextureService m_BakesService; | ||
50 | |||
51 | private System.Text.UTF8Encoding utf8 = | ||
52 | new System.Text.UTF8Encoding(); | ||
53 | |||
54 | public BakesServerPostHandler(IBakedTextureService service) : | ||
55 | base("POST", "/bakes") | ||
56 | { | ||
57 | m_BakesService = service; | ||
58 | } | ||
59 | |||
60 | public override byte[] Handle(string path, Stream request, | ||
61 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
62 | { | ||
63 | string[] p = SplitParams(path); | ||
64 | |||
65 | if (p.Length == 0) | ||
66 | { | ||
67 | return new byte[0]; | ||
68 | } | ||
69 | |||
70 | StreamReader sr = new StreamReader(request); | ||
71 | |||
72 | m_BakesService.Store(p[0], sr.ReadToEnd()); | ||
73 | sr.Close(); | ||
74 | |||
75 | return new byte[0]; | ||
76 | } | ||
77 | } | ||
78 | } | ||