aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authormingchen2007-06-07 15:13:24 +0000
committermingchen2007-06-07 15:13:24 +0000
commit2c4dacc1d6d8ddb57bdecdce163622934bdc43bf (patch)
treec55751c326fbea6fccd88ac457b45412180b2192 /OpenSim
parentFixing SVN: Re-adding Types folder (with correct capitalization) ( 2 / 3 ) (diff)
downloadopensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.zip
opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.gz
opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.bz2
opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.xz
Fixing SVN: Adding hopefully everything else (2.5 / 3)
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj68
-rw-r--r--OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build44
-rw-r--r--OpenSim/OpenSim.RegionServer/OpenSimMain.cs14
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/IScriptContext.cs40
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/IScriptEntity.cs46
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/IScriptHandler.cs125
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/Script.cs53
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/ScriptFactory.cs35
-rw-r--r--OpenSim/OpenSim.RegionServer/Scripting/Scripts/FollowRandomAvatar.cs64
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Avatar.Client.cs60
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Avatar.Update.cs371
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs484
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/AvatarAnimations.cs73
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Entity.cs151
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs832
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs598
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/Primitive2.cs519
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/SceneObject.cs105
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/World.PacketHandlers.cs449
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs151
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/World.cs736
-rw-r--r--OpenSim/OpenSim.RegionServer/Simulator/WorldBase.cs205
-rw-r--r--OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.csproj4
-rw-r--r--OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.dll.build2
24 files changed, 5163 insertions, 66 deletions
diff --git a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj
index faa479f..298aab4 100644
--- a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj
+++ b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.csproj
@@ -124,7 +124,7 @@
124 </ProjectReference> 124 </ProjectReference>
125 </ItemGroup> 125 </ItemGroup>
126 <ItemGroup> 126 <ItemGroup>
127 <Compile Include="AuthenticateSessionsBase.cs"> 127 <Compile Include="UDPServer.cs">
128 <SubType>Code</SubType> 128 <SubType>Code</SubType>
129 </Compile> 129 </Compile>
130 <Compile Include="AuthenticateSessionsLocal.cs"> 130 <Compile Include="AuthenticateSessionsLocal.cs">
@@ -133,16 +133,19 @@
133 <Compile Include="AuthenticateSessionsRemote.cs"> 133 <Compile Include="AuthenticateSessionsRemote.cs">
134 <SubType>Code</SubType> 134 <SubType>Code</SubType>
135 </Compile> 135 </Compile>
136 <Compile Include="OpenSimNetworkHandler.cs">
137 <SubType>Code</SubType>
138 </Compile>
136 <Compile Include="Grid.cs"> 139 <Compile Include="Grid.cs">
137 <SubType>Code</SubType> 140 <SubType>Code</SubType>
138 </Compile> 141 </Compile>
139 <Compile Include="OpenSimNetworkHandler.cs"> 142 <Compile Include="RegionInfoBase.cs">
140 <SubType>Code</SubType> 143 <SubType>Code</SubType>
141 </Compile> 144 </Compile>
142 <Compile Include="RegionInfo.cs"> 145 <Compile Include="RegionInfo.cs">
143 <SubType>Code</SubType> 146 <SubType>Code</SubType>
144 </Compile> 147 </Compile>
145 <Compile Include="RegionInfoBase.cs"> 148 <Compile Include="AuthenticateSessionsBase.cs">
146 <SubType>Code</SubType> 149 <SubType>Code</SubType>
147 </Compile> 150 </Compile>
148 <Compile Include="VersionInfo.cs"> 151 <Compile Include="VersionInfo.cs">
@@ -154,91 +157,85 @@
154 <Compile Include="RegionServerBase.cs"> 157 <Compile Include="RegionServerBase.cs">
155 <SubType>Code</SubType> 158 <SubType>Code</SubType>
156 </Compile> 159 </Compile>
157 <Compile Include="PacketServer.cs">
158 <SubType>Code</SubType>
159 </Compile>
160 <Compile Include="UDPServer.cs">
161 <SubType>Code</SubType>
162 </Compile>
163 <Compile Include="OpenSimMain.cs"> 160 <Compile Include="OpenSimMain.cs">
164 <SubType>Code</SubType> 161 <SubType>Code</SubType>
165 </Compile> 162 </Compile>
166 <Compile Include="CAPS\AdminWebFront.cs"> 163 <Compile Include="PacketServer.cs">
167 <SubType>Code</SubType> 164 <SubType>Code</SubType>
168 </Compile> 165 </Compile>
169 <Compile Include="Assets\AssetCache.cs"> 166 <Compile Include="Simulator\Avatar.Client.cs">
170 <SubType>Code</SubType> 167 <SubType>Code</SubType>
171 </Compile> 168 </Compile>
172 <Compile Include="Assets\InventoryCache.cs"> 169 <Compile Include="Simulator\AvatarAnimations.cs">
173 <SubType>Code</SubType> 170 <SubType>Code</SubType>
174 </Compile> 171 </Compile>
175 <Compile Include="Estate\EstateManager.cs"> 172 <Compile Include="Simulator\World.Scripting.cs">
176 <SubType>Code</SubType> 173 <SubType>Code</SubType>
177 </Compile> 174 </Compile>
178 <Compile Include="Types\Mesh.cs"> 175 <Compile Include="Simulator\Entity.cs">
179 <SubType>Code</SubType> 176 <SubType>Code</SubType>
180 </Compile> 177 </Compile>
181 <Compile Include="Types\Triangle.cs"> 178 <Compile Include="Simulator\WorldBase.cs">
182 <SubType>Code</SubType> 179 <SubType>Code</SubType>
183 </Compile> 180 </Compile>
184 <Compile Include="Simulator\World.Scripting.cs"> 181 <Compile Include="Simulator\Primitive2.cs">
185 <SubType>Code</SubType> 182 <SubType>Code</SubType>
186 </Compile> 183 </Compile>
187 <Compile Include="Simulator\Entity.cs"> 184 <Compile Include="Simulator\SceneObject.cs">
188 <SubType>Code</SubType> 185 <SubType>Code</SubType>
189 </Compile> 186 </Compile>
190 <Compile Include="Simulator\Primitive.cs"> 187 <Compile Include="Simulator\Primitive.cs">
191 <SubType>Code</SubType> 188 <SubType>Code</SubType>
192 </Compile> 189 </Compile>
193 <Compile Include="Simulator\WorldBase.cs"> 190 <Compile Include="Simulator\Avatar.cs">
194 <SubType>Code</SubType>
195 </Compile>
196 <Compile Include="Simulator\SceneObject.cs">
197 <SubType>Code</SubType> 191 <SubType>Code</SubType>
198 </Compile> 192 </Compile>
199 <Compile Include="Simulator\World.cs"> 193 <Compile Include="Simulator\Avatar.Update.cs">
200 <SubType>Code</SubType> 194 <SubType>Code</SubType>
201 </Compile> 195 </Compile>
202 <Compile Include="Simulator\ParcelManager.cs"> 196 <Compile Include="Simulator\ParcelManager.cs">
203 <SubType>Code</SubType> 197 <SubType>Code</SubType>
204 </Compile> 198 </Compile>
205 <Compile Include="Simulator\World.PacketHandlers.cs"> 199 <Compile Include="Simulator\World.cs">
206 <SubType>Code</SubType> 200 <SubType>Code</SubType>
207 </Compile> 201 </Compile>
208 <Compile Include="Simulator\Avatar.cs"> 202 <Compile Include="Simulator\World.PacketHandlers.cs">
209 <SubType>Code</SubType> 203 <SubType>Code</SubType>
210 </Compile> 204 </Compile>
211 <Compile Include="Simulator\Avatar.Update.cs"> 205 <Compile Include="Estate\EstateManager.cs">
212 <SubType>Code</SubType> 206 <SubType>Code</SubType>
213 </Compile> 207 </Compile>
214 <Compile Include="Simulator\AvatarAnimations.cs"> 208 <Compile Include="CAPS\AdminWebFront.cs">
215 <SubType>Code</SubType> 209 <SubType>Code</SubType>
216 </Compile> 210 </Compile>
217 <Compile Include="Simulator\Primitive2.cs"> 211 <Compile Include="Assets\InventoryCache.cs">
218 <SubType>Code</SubType> 212 <SubType>Code</SubType>
219 </Compile> 213 </Compile>
220 <Compile Include="Simulator\Avatar.Client.cs"> 214 <Compile Include="Assets\AssetCache.cs">
221 <SubType>Code</SubType> 215 <SubType>Code</SubType>
222 </Compile> 216 </Compile>
223 <Compile Include="Scripting\IScriptContext.cs"> 217 <Compile Include="Scripting\IScriptContext.cs">
224 <SubType>Code</SubType> 218 <SubType>Code</SubType>
225 </Compile> 219 </Compile>
226 <Compile Include="Scripting\IScriptEntity.cs"> 220 <Compile Include="Scripting\IScriptHandler.cs">
227 <SubType>Code</SubType> 221 <SubType>Code</SubType>
228 </Compile> 222 </Compile>
229 <Compile Include="Scripting\Script.cs"> 223 <Compile Include="Scripting\IScriptEntity.cs">
230 <SubType>Code</SubType> 224 <SubType>Code</SubType>
231 </Compile> 225 </Compile>
232 <Compile Include="Scripting\ScriptFactory.cs"> 226 <Compile Include="Scripting\ScriptFactory.cs">
233 <SubType>Code</SubType> 227 <SubType>Code</SubType>
234 </Compile> 228 </Compile>
235 <Compile Include="Scripting\IScriptHandler.cs"> 229 <Compile Include="Scripting\Script.cs">
236 <SubType>Code</SubType> 230 <SubType>Code</SubType>
237 </Compile> 231 </Compile>
238 <Compile Include="Scripting\Scripts\FollowRandomAvatar.cs"> 232 <Compile Include="Scripting\Scripts\FollowRandomAvatar.cs">
239 <SubType>Code</SubType> 233 <SubType>Code</SubType>
240 </Compile> 234 </Compile>
241 <Compile Include="Client\ClientViewBase.cs"> 235 <Compile Include="Types\Mesh.cs">
236 <SubType>Code</SubType>
237 </Compile>
238 <Compile Include="Types\Triangle.cs">
242 <SubType>Code</SubType> 239 <SubType>Code</SubType>
243 </Compile> 240 </Compile>
244 <Compile Include="Client\ClientView.Grid.cs"> 241 <Compile Include="Client\ClientView.Grid.cs">
@@ -247,10 +244,13 @@
247 <Compile Include="Client\ClientView.PacketHandlers.cs"> 244 <Compile Include="Client\ClientView.PacketHandlers.cs">
248 <SubType>Code</SubType> 245 <SubType>Code</SubType>
249 </Compile> 246 </Compile>
250 <Compile Include="Client\ClientView.cs"> 247 <Compile Include="Client\ClientView.ProcessPackets.cs">
251 <SubType>Code</SubType> 248 <SubType>Code</SubType>
252 </Compile> 249 </Compile>
253 <Compile Include="Client\ClientView.ProcessPackets.cs"> 250 <Compile Include="Client\ClientViewBase.cs">
251 <SubType>Code</SubType>
252 </Compile>
253 <Compile Include="Client\ClientView.cs">
254 <SubType>Code</SubType> 254 <SubType>Code</SubType>
255 </Compile> 255 </Compile>
256 </ItemGroup> 256 </ItemGroup>
diff --git a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
index 82fc661..3516332 100644
--- a/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
+++ b/OpenSim/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
@@ -11,49 +11,49 @@
11 <resources prefix="OpenSim.RegionServer" dynamicprefix="true" > 11 <resources prefix="OpenSim.RegionServer" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AuthenticateSessionsBase.cs" /> 14 <include name="UDPServer.cs" />
15 <include name="AuthenticateSessionsLocal.cs" /> 15 <include name="AuthenticateSessionsLocal.cs" />
16 <include name="AuthenticateSessionsRemote.cs" /> 16 <include name="AuthenticateSessionsRemote.cs" />
17 <include name="Grid.cs" />
18 <include name="OpenSimNetworkHandler.cs" /> 17 <include name="OpenSimNetworkHandler.cs" />
19 <include name="RegionInfo.cs" /> 18 <include name="Grid.cs" />
20 <include name="RegionInfoBase.cs" /> 19 <include name="RegionInfoBase.cs" />
20 <include name="RegionInfo.cs" />
21 <include name="AuthenticateSessionsBase.cs" />
21 <include name="VersionInfo.cs" /> 22 <include name="VersionInfo.cs" />
22 <include name="AgentAssetUpload.cs" /> 23 <include name="AgentAssetUpload.cs" />
23 <include name="RegionServerBase.cs" /> 24 <include name="RegionServerBase.cs" />
24 <include name="PacketServer.cs" />
25 <include name="UDPServer.cs" />
26 <include name="OpenSimMain.cs" /> 25 <include name="OpenSimMain.cs" />
27 <include name="CAPS/AdminWebFront.cs" /> 26 <include name="PacketServer.cs" />
28 <include name="Assets/AssetCache.cs" /> 27 <include name="Simulator/Avatar.Client.cs" />
29 <include name="Assets/InventoryCache.cs" /> 28 <include name="Simulator/AvatarAnimations.cs" />
30 <include name="Estate/EstateManager.cs" />
31 <include name="Types/Mesh.cs" />
32 <include name="Types/Triangle.cs" />
33 <include name="Simulator/World.Scripting.cs" /> 29 <include name="Simulator/World.Scripting.cs" />
34 <include name="Simulator/Entity.cs" /> 30 <include name="Simulator/Entity.cs" />
35 <include name="Simulator/Primitive.cs" />
36 <include name="Simulator/WorldBase.cs" /> 31 <include name="Simulator/WorldBase.cs" />
32 <include name="Simulator/Primitive2.cs" />
37 <include name="Simulator/SceneObject.cs" /> 33 <include name="Simulator/SceneObject.cs" />
38 <include name="Simulator/World.cs" /> 34 <include name="Simulator/Primitive.cs" />
39 <include name="Simulator/ParcelManager.cs" />
40 <include name="Simulator/World.PacketHandlers.cs" />
41 <include name="Simulator/Avatar.cs" /> 35 <include name="Simulator/Avatar.cs" />
42 <include name="Simulator/Avatar.Update.cs" /> 36 <include name="Simulator/Avatar.Update.cs" />
43 <include name="Simulator/AvatarAnimations.cs" /> 37 <include name="Simulator/ParcelManager.cs" />
44 <include name="Simulator/Primitive2.cs" /> 38 <include name="Simulator/World.cs" />
45 <include name="Simulator/Avatar.Client.cs" /> 39 <include name="Simulator/World.PacketHandlers.cs" />
40 <include name="Estate/EstateManager.cs" />
41 <include name="CAPS/AdminWebFront.cs" />
42 <include name="Assets/InventoryCache.cs" />
43 <include name="Assets/AssetCache.cs" />
46 <include name="Scripting/IScriptContext.cs" /> 44 <include name="Scripting/IScriptContext.cs" />
45 <include name="Scripting/IScriptHandler.cs" />
47 <include name="Scripting/IScriptEntity.cs" /> 46 <include name="Scripting/IScriptEntity.cs" />
48 <include name="Scripting/Script.cs" />
49 <include name="Scripting/ScriptFactory.cs" /> 47 <include name="Scripting/ScriptFactory.cs" />
50 <include name="Scripting/IScriptHandler.cs" /> 48 <include name="Scripting/Script.cs" />
51 <include name="Scripting/Scripts/FollowRandomAvatar.cs" /> 49 <include name="Scripting/Scripts/FollowRandomAvatar.cs" />
52 <include name="Client/ClientViewBase.cs" /> 50 <include name="Types/Mesh.cs" />
51 <include name="Types/Triangle.cs" />
53 <include name="Client/ClientView.Grid.cs" /> 52 <include name="Client/ClientView.Grid.cs" />
54 <include name="Client/ClientView.PacketHandlers.cs" /> 53 <include name="Client/ClientView.PacketHandlers.cs" />
55 <include name="Client/ClientView.cs" />
56 <include name="Client/ClientView.ProcessPackets.cs" /> 54 <include name="Client/ClientView.ProcessPackets.cs" />
55 <include name="Client/ClientViewBase.cs" />
56 <include name="Client/ClientView.cs" />
57 </sources> 57 </sources>
58 <references basedir="${project::get-base-directory()}"> 58 <references basedir="${project::get-base-directory()}">
59 <lib> 59 <lib>
diff --git a/OpenSim/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim/OpenSim.RegionServer/OpenSimMain.cs
index 4d20e72..5aba625 100644
--- a/OpenSim/OpenSim.RegionServer/OpenSimMain.cs
+++ b/OpenSim/OpenSim.RegionServer/OpenSimMain.cs
@@ -404,23 +404,23 @@ namespace OpenSim
404 case "": 404 case "":
405 this.m_physicsEngine = "basicphysics"; 405 this.m_physicsEngine = "basicphysics";
406 configData.SetAttribute("PhysicsEngine", "basicphysics"); 406 configData.SetAttribute("PhysicsEngine", "basicphysics");
407 OpenSim.world.Avatar.PhysicsEngineFlying = false; 407 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = false;
408 break; 408 break;
409 409
410 case "basicphysics": 410 case "basicphysics":
411 this.m_physicsEngine = "basicphysics"; 411 this.m_physicsEngine = "basicphysics";
412 configData.SetAttribute("PhysicsEngine", "basicphysics"); 412 configData.SetAttribute("PhysicsEngine", "basicphysics");
413 OpenSim.world.Avatar.PhysicsEngineFlying = false; 413 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = false;
414 break; 414 break;
415 415
416 case "RealPhysX": 416 case "RealPhysX":
417 this.m_physicsEngine = "RealPhysX"; 417 this.m_physicsEngine = "RealPhysX";
418 OpenSim.world.Avatar.PhysicsEngineFlying = true; 418 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = true;
419 break; 419 break;
420 420
421 case "OpenDynamicsEngine": 421 case "OpenDynamicsEngine":
422 this.m_physicsEngine = "OpenDynamicsEngine"; 422 this.m_physicsEngine = "OpenDynamicsEngine";
423 OpenSim.world.Avatar.PhysicsEngineFlying = true; 423 OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying = true;
424 break; 424 break;
425 } 425 }
426 426
@@ -511,13 +511,13 @@ namespace OpenSim
511 m_console.Error("That is " + (DateTime.Now - startuptime).ToString()); 511 m_console.Error("That is " + (DateTime.Now - startuptime).ToString());
512 break; 512 break;
513 case "users": 513 case "users":
514 OpenSim.world.Avatar TempAv; 514 OpenSim.RegionServer.Simulator.Avatar TempAv;
515 m_console.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP")); 515 m_console.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16}{5,-16}", "Firstname", "Lastname", "Agent ID", "Session ID", "Circuit", "IP"));
516 foreach (libsecondlife.LLUUID UUID in LocalWorld.Entities.Keys) 516 foreach (libsecondlife.LLUUID UUID in LocalWorld.Entities.Keys)
517 { 517 {
518 if (LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar") 518 if (LocalWorld.Entities[UUID].ToString() == "OpenSim.RegionServer.Simulator.Avatar")
519 { 519 {
520 TempAv = (OpenSim.world.Avatar)LocalWorld.Entities[UUID]; 520 TempAv = (OpenSim.RegionServer.Simulator.Avatar)LocalWorld.Entities[UUID];
521 m_console.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString())); 521 m_console.Error(String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString()));
522 } 522 }
523 } 523 }
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/IScriptContext.cs b/OpenSim/OpenSim.RegionServer/Scripting/IScriptContext.cs
new file mode 100644
index 0000000..2ac0a2e
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/IScriptContext.cs
@@ -0,0 +1,40 @@
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 System.Text;
31using libsecondlife;
32
33namespace OpenSim.RegionServer.Scripting
34{
35 public interface IScriptContext
36 {
37 IScriptEntity Entity { get; }
38 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
39 }
40}
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/IScriptEntity.cs b/OpenSim/OpenSim.RegionServer/Scripting/IScriptEntity.cs
new file mode 100644
index 0000000..05a1237
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/IScriptEntity.cs
@@ -0,0 +1,46 @@
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 System.Text;
31using libsecondlife;
32
33namespace OpenSim.RegionServer.Scripting
34{
35 public interface IScriptReadonlyEntity
36 {
37 LLVector3 Pos { get; }
38 string Name { get; }
39 }
40
41 public interface IScriptEntity
42 {
43 LLVector3 Pos { get; set; }
44 string Name { get; }
45 }
46}
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/IScriptHandler.cs b/OpenSim/OpenSim.RegionServer/Scripting/IScriptHandler.cs
new file mode 100644
index 0000000..7431799
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/IScriptHandler.cs
@@ -0,0 +1,125 @@
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 System.Text;
31using libsecondlife;
32using OpenSim.Physics.Manager;
33using OpenSim.RegionServer.Simulator;
34using Avatar=OpenSim.RegionServer.Simulator.Avatar;
35using Primitive = OpenSim.RegionServer.Simulator.Primitive;
36
37namespace OpenSim.RegionServer.Scripting
38{
39 public delegate void ScriptEventHandler(IScriptContext context);
40
41 public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
42 {
43 private World m_world;
44 private Script m_script;
45 private Entity m_entity;
46
47 public LLUUID ScriptId
48 {
49 get
50 {
51 return m_script.ScriptId;
52 }
53 }
54
55 public void OnFrame()
56 {
57 m_script.OnFrame(this);
58 }
59
60 public ScriptHandler(Script script, Entity entity, World world)
61 {
62 m_script = script;
63 m_entity = entity;
64 m_world = world;
65 }
66
67 #region IScriptContext Members
68
69 IScriptEntity IScriptContext.Entity
70 {
71 get
72 {
73 return this;
74 }
75 }
76
77 bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
78 {
79 foreach (Entity entity in m_world.Entities.Values )
80 {
81 if( entity is Avatar )
82 {
83 avatar = entity;
84 return true;
85 }
86 }
87
88 avatar = null;
89 return false;
90 }
91
92 #endregion
93
94 #region IScriptEntity and IScriptReadonlyEntity Members
95
96 public string Name
97 {
98 get
99 {
100 return m_entity.Name;
101 }
102 }
103
104 public LLVector3 Pos
105 {
106 get
107 {
108 return m_entity.Pos;
109 }
110
111 set
112 {
113 if (m_entity is Primitive)
114 {
115 Primitive prim = m_entity as Primitive;
116 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
117 prim.UpdatePosition( value );
118 }
119 }
120 }
121
122 #endregion
123 }
124
125}
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/Script.cs b/OpenSim/OpenSim.RegionServer/Scripting/Script.cs
new file mode 100644
index 0000000..e6732a6
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/Script.cs
@@ -0,0 +1,53 @@
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 System.Text;
31using libsecondlife;
32
33namespace OpenSim.RegionServer.Scripting
34{
35 public class Script
36 {
37 private LLUUID m_scriptId;
38 public virtual LLUUID ScriptId
39 {
40 get
41 {
42 return m_scriptId;
43 }
44 }
45
46 public Script( LLUUID scriptId )
47 {
48 m_scriptId = scriptId;
49 }
50
51 public ScriptEventHandler OnFrame;
52 }
53}
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/ScriptFactory.cs b/OpenSim/OpenSim.RegionServer/Scripting/ScriptFactory.cs
new file mode 100644
index 0000000..525f63d
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/ScriptFactory.cs
@@ -0,0 +1,35 @@
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 System.Text;
31
32namespace OpenSim.RegionServer.Scripting
33{
34 public delegate Script ScriptFactory();
35}
diff --git a/OpenSim/OpenSim.RegionServer/Scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/OpenSim.RegionServer/Scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..8e4565a
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,64 @@
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 System.Text;
31using libsecondlife;
32
33namespace OpenSim.RegionServer.world.scripting
34{
35 public class FollowRandomAvatar : Script
36 {
37 public FollowRandomAvatar()
38 : base(LLUUID.Random())
39 {
40 OnFrame += MyOnFrame;
41 }
42
43 private void MyOnFrame(IScriptContext context)
44 {
45 LLVector3 pos = context.Entity.Pos;
46
47 IScriptReadonlyEntity avatar;
48
49 if (context.TryGetRandomAvatar(out avatar))
50 {
51 LLVector3 avatarPos = avatar.Pos;
52
53 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
54 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
55
56 LLVector3 newPos = new LLVector3(x, y, pos.Z);
57
58 context.Entity.Pos = newPos;
59 }
60 }
61 }
62
63
64}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Client.cs b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Client.cs
new file mode 100644
index 0000000..c6ce258
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Client.cs
@@ -0,0 +1,60 @@
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 System.Text;
31using libsecondlife.Packets;
32
33namespace OpenSim.RegionServer.Simulator
34{
35 partial class Avatar
36 {
37 private List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> updateList = new List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
38 private List<Entity> interestList = new List<Entity>();
39
40 public void SendPacketToViewer(Packet packet)
41 {
42 this.ControllingClient.OutPacket(packet);
43 }
44
45 public void AddTerseUpdateToViewersList(ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock)
46 {
47
48 }
49
50 public void SendUpdateListToViewer()
51 {
52
53 }
54
55 private void UpdateInterestList()
56 {
57
58 }
59 }
60}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Update.cs b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Update.cs
new file mode 100644
index 0000000..6f32c85
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.Update.cs
@@ -0,0 +1,371 @@
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 System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.RegionServer.Client;
34
35namespace OpenSim.RegionServer.Simulator
36{
37 partial class Avatar
38 {
39 public override void update()
40 {
41 if (!this.childAvatar)
42 {
43 if (this._physActor == null)
44 {
45 //HACKHACK: Note to work out why this entity does not have a physics actor
46 // and prehaps create one.
47 return;
48 }
49 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
50 if (this.updateflag)
51 {
52 //need to send movement info
53 //so create the improvedterseobjectupdate packet
54 //use CreateTerseBlock()
55 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
56 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
57 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
58 terse.RegionData.TimeDilation = 64096;
59 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
60 terse.ObjectData[0] = terseBlock;
61 List<Avatar> avList = this.m_world.RequestAvatarList();
62 foreach (Avatar client in avList)
63 {
64 client.SendPacketToViewer(terse);
65 }
66
67 updateflag = false;
68 //this._updateCount = 0;
69 }
70 else
71 {
72
73 if ((pos2 != this.positionLastFrame) || (this.movementflag == 16))
74 {
75 _updateCount++;
76 if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0))
77 {
78 //It has been a while since last update was sent so lets send one.
79 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
80 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
81 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
82 terse.RegionData.TimeDilation = 64096;
83 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
84 terse.ObjectData[0] = terseBlock;
85 List<Avatar> avList = this.m_world.RequestAvatarList();
86 foreach (Avatar client in avList)
87 {
88 client.SendPacketToViewer(terse);
89 }
90 _updateCount = 0;
91 }
92
93 if (this.movementflag == 16)
94 {
95 movementflag = 0;
96 }
97 }
98
99 }
100
101 if (positionFrameBeforeLast != pos2)
102 {
103 this.positionFrameBeforeLast = this.positionLastFrame;
104 this.positionLastFrame = pos2;
105 int tempRoundedX = (int)Math.Round(positionLastFrame.X);
106 int tempRoundedY = (int)Math.Round(positionLastFrame.Y);
107 if (this.positionRoundedX != tempRoundedX || this.positionRoundedY != tempRoundedY)
108 {
109
110 this.positionRoundedX = tempRoundedX;
111 this.positionRoundedY = tempRoundedY;
112 int currentParcelLocalID = m_world.parcelManager.getParcel(tempRoundedX, tempRoundedY).parcelData.localID;
113 if(currentParcelLocalID != this.positionParcelHoverLocalID)
114 {
115
116 Console.WriteLine("NEW PARCEL: " + m_world.parcelManager.getParcel(tempRoundedX, tempRoundedY).parcelData.parcelName);
117 m_world.parcelManager.getParcel(tempRoundedX, tempRoundedY).sendParcelProperties(this.parcelUpdateSequenceIncrement, false, 0,this.ControllingClient);
118 this.positionParcelHoverLocalID = currentParcelLocalID;
119 this.parcelUpdateSequenceIncrement++;
120 }
121 }
122 }
123
124 if (!this.ControllingClient.m_sandboxMode)
125 {
126 if (pos2.X < 0)
127 {
128 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
129 }
130
131 if (pos2.Y < 0)
132 {
133 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
134 }
135
136 if (pos2.X > 255)
137 {
138 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
139 }
140
141 if (pos2.Y > 255)
142 {
143 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
144 }
145 }
146 }
147
148 }
149
150 public void SendUpdateToOtherClient(Avatar remoteAvatar)
151 {
152 ObjectUpdatePacket objupdate = CreateUpdatePacket();
153 remoteAvatar.SendPacketToViewer(objupdate);
154 }
155
156 public ObjectUpdatePacket CreateUpdatePacket()
157 {
158 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
159 //send a objectupdate packet with information about the clients avatar
160 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
161 objupdate.RegionData.RegionHandle = m_regionHandle;
162 objupdate.RegionData.TimeDilation = 64096;
163 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
164
165 objupdate.ObjectData[0] = AvatarTemplate;
166 //give this avatar object a local id and assign the user a name
167 objupdate.ObjectData[0].ID = this.localid;
168 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
169 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
170
171 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
172
173 byte[] pb = pos2.GetBytes();
174
175 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
176 return objupdate;
177 }
178
179 public void SendInitialPosition()
180 {
181 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
182 //send a objectupdate packet with information about the clients avatar
183
184 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
185 objupdate.RegionData.RegionHandle = m_regionHandle;
186 objupdate.RegionData.TimeDilation = 64096;
187 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
188 objupdate.ObjectData[0] = AvatarTemplate;
189 //give this avatar object a local id and assign the user a name
190
191 objupdate.ObjectData[0].ID = this.localid;
192 this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
193 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
194 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z);
195 byte[] pb = pos2.GetBytes();
196 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
197 m_world._localNumber++;
198
199 List<Avatar> avList = this.m_world.RequestAvatarList();
200 foreach (Avatar client in avList)
201 {
202 client.SendPacketToViewer(objupdate);
203 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
204 {
205 SendAppearanceToOtherAgent(client);
206 }
207 }
208 }
209
210 public void SendOurAppearance()
211 {
212 ControllingClient.SendAppearance(this.Wearables);
213 }
214
215 public void SendOurAppearance(ClientView OurClient)
216 {
217 //event handler for wearables request
218 this.SendOurAppearance();
219 }
220
221 public void SendAppearanceToOtherAgent(Avatar avatarInfo)
222 {
223 AvatarAppearancePacket avp = new AvatarAppearancePacket();
224 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
225 avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes();
226
227 AvatarAppearancePacket.VisualParamBlock avblock = null;
228 for (int i = 0; i < 218; i++)
229 {
230 avblock = new AvatarAppearancePacket.VisualParamBlock();
231 avblock.ParamValue = visualParams[i];
232 avp.VisualParam[i] = avblock;
233 }
234
235 avp.Sender.IsTrial = false;
236 avp.Sender.ID = ControllingClient.AgentID;
237 avatarInfo.SendPacketToViewer(avp);
238 }
239
240 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
241 {
242 LLObject.TextureEntry tex = new LLObject.TextureEntry(texture, 0, texture.Length);
243 this.avatarAppearanceTexture = tex;
244
245 for (int i = 0; i < visualParam.Length; i++)
246 {
247 this.visualParams[i] = visualParam[i].ParamValue;
248 }
249
250 List<Avatar> avList = this.m_world.RequestAvatarList();
251 foreach (Avatar client in avList)
252 {
253 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
254 {
255 SendAppearanceToOtherAgent(client);
256 }
257 }
258 }
259
260 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
261 {
262 byte[] bytes = new byte[60];
263 int i = 0;
264 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
265
266 dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry;
267 libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0);
268 lock (m_world.LockPhysicsEngine)
269 {
270 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
271 }
272
273 uint ID = this.localid;
274
275 bytes[i++] = (byte)(ID % 256);
276 bytes[i++] = (byte)((ID >> 8) % 256);
277 bytes[i++] = (byte)((ID >> 16) % 256);
278 bytes[i++] = (byte)((ID >> 24) % 256);
279 bytes[i++] = 0;
280 bytes[i++] = 1;
281 i += 14;
282 bytes[i++] = 128;
283 bytes[i++] = 63;
284
285 byte[] pb = pos2.GetBytes();
286 Array.Copy(pb, 0, bytes, i, pb.Length);
287 i += 12;
288 ushort InternVelocityX;
289 ushort InternVelocityY;
290 ushort InternVelocityZ;
291 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0);
292 lock (m_world.LockPhysicsEngine)
293 {
294 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
295 }
296 internDirec = internDirec / 128.0f;
297 internDirec.x += 1;
298 internDirec.y += 1;
299 internDirec.z += 1;
300
301 InternVelocityX = (ushort)(32768 * internDirec.x);
302 InternVelocityY = (ushort)(32768 * internDirec.y);
303 InternVelocityZ = (ushort)(32768 * internDirec.z);
304
305 ushort ac = 32767;
306 bytes[i++] = (byte)(InternVelocityX % 256);
307 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
308 bytes[i++] = (byte)(InternVelocityY % 256);
309 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
310 bytes[i++] = (byte)(InternVelocityZ % 256);
311 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
312
313 //accel
314 bytes[i++] = (byte)(ac % 256);
315 bytes[i++] = (byte)((ac >> 8) % 256);
316 bytes[i++] = (byte)(ac % 256);
317 bytes[i++] = (byte)((ac >> 8) % 256);
318 bytes[i++] = (byte)(ac % 256);
319 bytes[i++] = (byte)((ac >> 8) % 256);
320
321 //rot
322 bytes[i++] = (byte)(ac % 256);
323 bytes[i++] = (byte)((ac >> 8) % 256);
324 bytes[i++] = (byte)(ac % 256);
325 bytes[i++] = (byte)((ac >> 8) % 256);
326 bytes[i++] = (byte)(ac % 256);
327 bytes[i++] = (byte)((ac >> 8) % 256);
328 bytes[i++] = (byte)(ac % 256);
329 bytes[i++] = (byte)((ac >> 8) % 256);
330
331 //rotation vel
332 bytes[i++] = (byte)(ac % 256);
333 bytes[i++] = (byte)((ac >> 8) % 256);
334 bytes[i++] = (byte)(ac % 256);
335 bytes[i++] = (byte)((ac >> 8) % 256);
336 bytes[i++] = (byte)(ac % 256);
337 bytes[i++] = (byte)((ac >> 8) % 256);
338
339 dat.Data = bytes;
340 return (dat);
341 }
342
343 // Sends animation update
344 public void SendAnimPack(LLUUID animID, int seq)
345 {
346 AvatarAnimationPacket ani = new AvatarAnimationPacket();
347 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
348 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
349 ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID;
350 ani.Sender = new AvatarAnimationPacket.SenderBlock();
351 ani.Sender.ID = ControllingClient.AgentID;
352 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1];
353 ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock();
354 ani.AnimationList[0].AnimID = this.current_anim = animID;
355 ani.AnimationList[0].AnimSequenceID = this.anim_seq = seq;
356
357 List<Avatar> avList = this.m_world.RequestAvatarList();
358 foreach (Avatar client in avList)
359 {
360 client.SendPacketToViewer(ani);
361 }
362
363 }
364
365 public void SendAnimPack()
366 {
367 this.SendAnimPack(this.current_anim, this.anim_seq);
368 }
369
370 }
371}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs
new file mode 100644
index 0000000..0135e26
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Avatar.cs
@@ -0,0 +1,484 @@
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 System.IO;
31using System.Text;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Physics.Manager;
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Interfaces;
37using OpenSim.RegionServer.Client;
38
39using Axiom.MathLib;
40
41namespace OpenSim.RegionServer.Simulator
42{
43 public partial class Avatar : Entity
44 {
45 public static bool PhysicsEngineFlying = false;
46 public static AvatarAnimations Animations;
47 public string firstname;
48 public string lastname;
49 public ClientView ControllingClient;
50 public LLUUID current_anim;
51 public int anim_seq;
52 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
53 private bool updateflag = false;
54 private byte movementflag = 0;
55 private List<NewForce> forcesList = new List<NewForce>();
56 private short _updateCount = 0;
57 private Axiom.MathLib.Quaternion bodyRot;
58 private LLObject.TextureEntry avatarAppearanceTexture = null;
59 private byte[] visualParams;
60 private AvatarWearable[] Wearables;
61 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
62 private LLVector3 positionFrameBeforeLast = new LLVector3(0, 0, 0);
63
64 private int positionRoundedX = 0;
65 private int positionRoundedY = 0;
66
67 private int positionParcelHoverLocalID = -1; //Local ID of the last parcel they were over
68 private int parcelUpdateSequenceIncrement = 1;
69 private ulong m_regionHandle;
70 //private Dictionary<uint, ClientView> m_clientThreads;
71 private string m_regionName;
72 private ushort m_regionWaterHeight;
73 private bool m_regionTerraform;
74 private bool childAvatar = false;
75
76 public Avatar(ClientView TheClient, World world, string regionName, Dictionary<uint, ClientView> clientThreads, ulong regionHandle, bool regionTerraform, ushort regionWater)
77 {
78 m_world = world;
79 // m_clientThreads = clientThreads;
80 m_regionName = regionName;
81 m_regionHandle = regionHandle;
82 m_regionTerraform = regionTerraform;
83 m_regionWaterHeight = regionWater;
84
85 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs - Loading details from grid (DUMMY)");
86 ControllingClient = TheClient;
87 localid = 8880000 + (this.m_world._localNumber++);
88 Pos = ControllingClient.startpos;
89 visualParams = new byte[218];
90 for (int i = 0; i < 218; i++)
91 {
92 visualParams[i] = 100;
93 }
94 Wearables = new AvatarWearable[13]; //should be 13 of these
95 for (int i = 0; i < 13; i++)
96 {
97 Wearables[i] = new AvatarWearable();
98 }
99 this.Wearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
100 this.Wearables[0].ItemID = LLUUID.Random();
101
102 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
103
104 //register for events
105 ControllingClient.OnRequestWearables += new ClientView.GenericCall(this.SendOurAppearance);
106 ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
107 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.CompleteMovement);
108 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.SendInitialPosition);
109 ControllingClient.OnAgentUpdate += new ClientView.GenericCall3(this.HandleAgentUpdate);
110 ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
111 ControllingClient.OnChildAgentStatus += new ClientView.StatusChange(this.ChildStatusChange);
112
113 }
114
115 public PhysicsActor PhysActor
116 {
117 set
118 {
119 this._physActor = value;
120 }
121 get
122 {
123 return _physActor;
124 }
125 }
126
127 public void ChildStatusChange(bool status)
128 {
129 this.childAvatar = status;
130
131 if (this.childAvatar == true)
132 {
133 this._physActor.Velocity = new PhysicsVector(0, 0, 0);
134 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
135 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
136 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
137 terse.RegionData.TimeDilation = 64096;
138 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
139 terse.ObjectData[0] = terseBlock;
140 List<Avatar> avList = this.m_world.RequestAvatarList();
141 foreach (Avatar client in avList)
142 {
143 client.SendPacketToViewer(terse);
144 }
145 }
146 else
147 {
148 LLVector3 startp = ControllingClient.StartPos;
149 lock (m_world.LockPhysicsEngine)
150 {
151 this._physActor.Position = new PhysicsVector(startp.X, startp.Y, startp.Z);
152 }
153 }
154 }
155
156 public override void addForces()
157 {
158 lock (this.forcesList)
159 {
160 if (this.forcesList.Count > 0)
161 {
162 for (int i = 0; i < this.forcesList.Count; i++)
163 {
164 NewForce force = this.forcesList[i];
165 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
166 lock (m_world.LockPhysicsEngine)
167 {
168 this._physActor.Velocity = phyVector;
169 }
170 this.updateflag = true;
171 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
172 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
173 }
174 for (int i = 0; i < this.forcesList.Count; i++)
175 {
176 this.forcesList.RemoveAt(0);
177 }
178 }
179 }
180 }
181
182 public static void SetupTemplate(string name)
183 {
184 FileInfo fInfo = new FileInfo(name);
185 long numBytes = fInfo.Length;
186 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
187 BinaryReader br = new BinaryReader(fStream);
188 byte[] data1 = br.ReadBytes((int)numBytes);
189 br.Close();
190 fStream.Close();
191
192 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
193
194 SetDefaultPacketValues(objdata);
195 objdata.TextureEntry = data1;
196 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
197 objdata.PathCurve = 16;
198 objdata.ProfileCurve = 1;
199 objdata.PathScaleX = 100;
200 objdata.PathScaleY = 100;
201 objdata.ParentID = 0;
202 objdata.OwnerID = LLUUID.Zero;
203 objdata.Scale = new LLVector3(1, 1, 1);
204 objdata.PCode = 47;
205 System.Text.Encoding enc = System.Text.Encoding.ASCII;
206 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
207 pos.X = 100f;
208 objdata.ID = 8880000;
209 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
210 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
211 //objdata.FullID=user.AgentID;
212 byte[] pb = pos.GetBytes();
213 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
214
215 Avatar.AvatarTemplate = objdata;
216 }
217
218 protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
219 {
220 objdata.PSBlock = new byte[0];
221 objdata.ExtraParams = new byte[1];
222 objdata.MediaURL = new byte[0];
223 objdata.NameValue = new byte[0];
224 objdata.Text = new byte[0];
225 objdata.TextColor = new byte[4];
226 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
227 objdata.JointPivot = new LLVector3(0, 0, 0);
228 objdata.Material = 4;
229 objdata.TextureAnim = new byte[0];
230 objdata.Sound = LLUUID.Zero;
231 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
232 objdata.TextureEntry = ntex.ToBytes();
233 objdata.State = 0;
234 objdata.Data = new byte[0];
235
236 objdata.ObjectData = new byte[76];
237 objdata.ObjectData[15] = 128;
238 objdata.ObjectData[16] = 63;
239 objdata.ObjectData[56] = 128;
240 objdata.ObjectData[61] = 102;
241 objdata.ObjectData[62] = 40;
242 objdata.ObjectData[63] = 61;
243 objdata.ObjectData[64] = 189;
244
245
246 }
247
248 public void CompleteMovement()
249 {
250 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
251 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
252 mov.AgentData.SessionID = this.ControllingClient.SessionID;
253 mov.AgentData.AgentID = this.ControllingClient.AgentID;
254 mov.Data.RegionHandle = this.m_regionHandle;
255 // TODO - dynamicalise this stuff
256 mov.Data.Timestamp = 1172750370;
257 mov.Data.Position = this.ControllingClient.startpos;
258 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
259
260 ControllingClient.OutPacket(mov);
261 }
262
263 public void HandleAgentUpdate(Packet pack)
264 {
265 this.HandleUpdate((AgentUpdatePacket)pack);
266 }
267
268 public void HandleUpdate(AgentUpdatePacket pack)
269 {
270 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0)
271 {
272 if (this._physActor.Flying == false)
273 {
274 this.current_anim = Animations.AnimsLLUUID["FLY"];
275 this.anim_seq = 1;
276 this.SendAnimPack();
277 }
278 this._physActor.Flying = true;
279
280 }
281 else
282 {
283 if (this._physActor.Flying == true)
284 {
285 this.current_anim = Animations.AnimsLLUUID["STAND"];
286 this.anim_seq = 1;
287 this.SendAnimPack();
288 }
289 this._physActor.Flying = false;
290 }
291 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
292 {
293 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
294 if (((movementflag & 1) == 0) || (q != this.bodyRot))
295 {
296
297 if (((movementflag & 1) == 0) && (!this._physActor.Flying))
298 {
299 this.current_anim = Animations.AnimsLLUUID["WALK"];
300 this.anim_seq = 1;
301 this.SendAnimPack();
302 }
303
304
305 //we should add a new force to the list
306 // but for now we will deal with velocities
307 NewForce newVelocity = new NewForce();
308 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
309 Axiom.MathLib.Vector3 direc = q * v3;
310 direc.Normalize();
311
312 //work out velocity for sim physics system
313 direc = direc * ((0.03f) * 128f);
314 if (this._physActor.Flying)
315 direc *= 4;
316
317 newVelocity.X = direc.x;
318 newVelocity.Y = direc.y;
319 newVelocity.Z = direc.z;
320 this.forcesList.Add(newVelocity);
321 movementflag = 1;
322 this.bodyRot = q;
323 }
324 }
325 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
326 {
327 if (((movementflag & 2) == 0) && this._physActor.Flying)
328 {
329 //we should add a new force to the list
330 // but for now we will deal with velocities
331 NewForce newVelocity = new NewForce();
332 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
333 Axiom.MathLib.Vector3 direc = v3;
334 direc.Normalize();
335
336 //work out velocity for sim physics system
337 direc = direc * ((0.03f) * 128f * 2);
338 newVelocity.X = direc.x;
339 newVelocity.Y = direc.y;
340 newVelocity.Z = direc.z;
341 this.forcesList.Add(newVelocity);
342 movementflag = 2;
343 }
344 }
345 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
346 {
347 if (((movementflag & 4) == 0) && this._physActor.Flying)
348 {
349 //we should add a new force to the list
350 // but for now we will deal with velocities
351 NewForce newVelocity = new NewForce();
352 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
353 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
354 Axiom.MathLib.Vector3 direc = v3;
355 direc.Normalize();
356
357 //work out velocity for sim physics system
358 direc = direc * ((0.03f) * 128f * 2);
359 newVelocity.X = direc.x;
360 newVelocity.Y = direc.y;
361 newVelocity.Z = direc.z;
362 this.forcesList.Add(newVelocity);
363 movementflag = 4;
364 }
365 }
366 else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
367 {
368 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
369 if (((movementflag & 8) == 0) || (q != this.bodyRot))
370 {
371 //we should add a new force to the list
372 // but for now we will deal with velocities
373 NewForce newVelocity = new NewForce();
374 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
375 Axiom.MathLib.Vector3 direc = q * v3;
376 direc.Normalize();
377
378 //work out velocity for sim physics system
379 direc = direc * ((0.03f) * 128f);
380 if (this._physActor.Flying)
381 direc *= 2;
382
383 newVelocity.X = direc.x;
384 newVelocity.Y = direc.y;
385 newVelocity.Z = direc.z;
386 this.forcesList.Add(newVelocity);
387 movementflag = 8;
388 this.bodyRot = q;
389 }
390 }
391 else
392 {
393 if (movementflag == 16)
394 {
395 movementflag = 0;
396 }
397 if ((movementflag) != 0)
398 {
399 NewForce newVelocity = new NewForce();
400 newVelocity.X = 0;
401 newVelocity.Y = 0;
402 newVelocity.Z = 0;
403 this.forcesList.Add(newVelocity);
404 movementflag = 0;
405 // We're standing still, so make it show!
406 if (this._physActor.Flying == false)
407 {
408 this.current_anim = Animations.AnimsLLUUID["STAND"];
409 this.anim_seq = 1;
410 this.SendAnimPack();
411 }
412 this.movementflag = 16;
413
414 }
415 }
416 }
417
418 //really really should be moved somewhere else (RegionInfo.cs ?)
419 public void SendRegionHandshake(World regionInfo)
420 {
421 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
422 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
423 RegionHandshakePacket handshake = new RegionHandshakePacket();
424
425 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
426 handshake.RegionInfo.BillableFactor = 0;
427 handshake.RegionInfo.IsEstateManager = false;
428 handshake.RegionInfo.TerrainHeightRange00 = regionInfo.m_regInfo.TerrainHeightRange00;
429 handshake.RegionInfo.TerrainHeightRange01 = regionInfo.m_regInfo.TerrainHeightRange01;
430 handshake.RegionInfo.TerrainHeightRange10 = regionInfo.m_regInfo.TerrainHeightRange10;
431 handshake.RegionInfo.TerrainHeightRange11 = regionInfo.m_regInfo.TerrainHeightRange11;
432 handshake.RegionInfo.TerrainStartHeight00 = regionInfo.m_regInfo.TerrainStartHeight00;
433 handshake.RegionInfo.TerrainStartHeight01 = regionInfo.m_regInfo.TerrainStartHeight01;
434 handshake.RegionInfo.TerrainStartHeight10 = regionInfo.m_regInfo.TerrainStartHeight10;
435 handshake.RegionInfo.TerrainStartHeight11 = regionInfo.m_regInfo.TerrainStartHeight11;
436 handshake.RegionInfo.SimAccess = 13;
437 handshake.RegionInfo.WaterHeight = m_regionWaterHeight;
438 uint regionFlags = 72458694;
439 if (this.m_regionTerraform)
440 {
441 regionFlags -= 64;
442 }
443 handshake.RegionInfo.RegionFlags = regionFlags;
444 handshake.RegionInfo.SimName = _enc.GetBytes(m_regionName + "\0");
445 handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
446 handshake.RegionInfo.TerrainBase0 = regionInfo.m_regInfo.TerrainBase0;
447 handshake.RegionInfo.TerrainBase1 = regionInfo.m_regInfo.TerrainBase1;
448 handshake.RegionInfo.TerrainBase2 = regionInfo.m_regInfo.TerrainBase2;
449 handshake.RegionInfo.TerrainBase3 = regionInfo.m_regInfo.TerrainBase3;
450 handshake.RegionInfo.TerrainDetail0 = regionInfo.m_regInfo.TerrainDetail0;
451 handshake.RegionInfo.TerrainDetail1 = regionInfo.m_regInfo.TerrainDetail1;
452 handshake.RegionInfo.TerrainDetail2 = regionInfo.m_regInfo.TerrainDetail2;
453 handshake.RegionInfo.TerrainDetail3 = regionInfo.m_regInfo.TerrainDetail3;
454 handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
455
456 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
457 this.ControllingClient.OutPacket(handshake);
458 }
459
460 public static void LoadAnims()
461 {
462 Avatar.Animations = new AvatarAnimations();
463 Avatar.Animations.LoadAnims();
464 }
465
466 public override void LandRenegerated()
467 {
468 Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f);
469 }
470 }
471
472 public class NewForce
473 {
474 public float X;
475 public float Y;
476 public float Z;
477
478 public NewForce()
479 {
480
481 }
482 }
483
484}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/AvatarAnimations.cs b/OpenSim/OpenSim.RegionServer/Simulator/AvatarAnimations.cs
new file mode 100644
index 0000000..c7557dc
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/AvatarAnimations.cs
@@ -0,0 +1,73 @@
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 System.Text;
31using libsecondlife;
32using System.Xml;
33
34namespace OpenSim.RegionServer.Simulator
35{
36 public class AvatarAnimations
37 {
38
39 public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>();
40 public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>();
41
42 public AvatarAnimations()
43 {
44 }
45
46 public void LoadAnims()
47 {
48 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:LoadAnims() - Loading avatar animations");
49 XmlTextReader reader = new XmlTextReader("data/avataranimations.xml");
50
51 XmlDocument doc = new XmlDocument();
52 doc.Load(reader);
53 foreach (XmlNode nod in doc.DocumentElement.ChildNodes)
54 {
55
56 if ( nod.Attributes["name"] != null)
57 {
58 AnimsLLUUID.Add(nod.Attributes["name"].Value, nod.InnerText);
59 }
60
61 }
62
63 reader.Close();
64
65 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)");
66
67 foreach (KeyValuePair<string, LLUUID> kp in OpenSim.RegionServer.Simulator.Avatar.Animations.AnimsLLUUID)
68 {
69 AnimsNames.Add(kp.Value, kp.Key);
70 }
71 }
72 }
73}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Entity.cs b/OpenSim/OpenSim.RegionServer/Simulator/Entity.cs
new file mode 100644
index 0000000..6d25c81
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Entity.cs
@@ -0,0 +1,151 @@
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 System.Text;
31using Axiom.MathLib;
32using OpenSim.Physics.Manager;
33using OpenSim.RegionServer.Types;
34using libsecondlife;
35using OpenSim.RegionServer.Scripting;
36
37namespace OpenSim.RegionServer.Simulator
38{
39 public abstract class Entity : IScriptReadonlyEntity
40 {
41 public libsecondlife.LLUUID uuid;
42 public uint localid;
43 public LLVector3 velocity;
44 public Quaternion rotation;
45 protected List<Entity> children;
46
47 protected string m_name;
48 public virtual string Name
49 {
50 get { return m_name; }
51 }
52
53 protected LLVector3 m_pos;
54 protected PhysicsActor _physActor;
55 protected World m_world;
56
57 public virtual LLVector3 Pos
58 {
59 get
60 {
61 if (this._physActor != null)
62 {
63 m_pos.X = _physActor.Position.X;
64 m_pos.Y = _physActor.Position.Y;
65 m_pos.Z = _physActor.Position.Z;
66 }
67
68 return m_pos;
69 }
70 set
71 {
72 if (this._physActor != null)
73 {
74 try
75 {
76 lock (this.m_world.LockPhysicsEngine)
77 {
78
79 this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
80 }
81 }
82 catch (Exception e)
83 {
84 Console.WriteLine(e.Message);
85 }
86 }
87
88 m_pos = value;
89 }
90 }
91
92 /// <summary>
93 /// Creates a new Entity (should not occur on it's own)
94 /// </summary>
95 public Entity()
96 {
97 uuid = new libsecondlife.LLUUID();
98 localid = 0;
99 m_pos = new LLVector3();
100 velocity = new LLVector3();
101 rotation = new Quaternion();
102 m_name = "(basic entity)";
103 children = new List<Entity>();
104 }
105
106 public virtual void addForces()
107 {
108 foreach (Entity child in children)
109 {
110 child.addForces();
111 }
112 }
113
114 /// <summary>
115 /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
116 /// </summary>
117 public virtual void update() {
118 // Do any per-frame updates needed that are applicable to every type of entity
119 foreach (Entity child in children)
120 {
121 child.update();
122 }
123 }
124
125 /// <summary>
126 /// Returns a mesh for this object and any dependents
127 /// </summary>
128 /// <returns>The mesh of this entity tree</returns>
129 public virtual Mesh getMesh()
130 {
131 Mesh mesh = new Mesh();
132
133 foreach (Entity child in children)
134 {
135 mesh += child.getMesh();
136 }
137
138 return mesh;
139 }
140
141 public virtual void BackUp()
142 {
143
144 }
145
146 public virtual void LandRenegerated()
147 {
148
149 }
150 }
151}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs b/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs
new file mode 100644
index 0000000..a9d4eea
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/ParcelManager.cs
@@ -0,0 +1,832 @@
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 System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.RegionServer.Simulator;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using OpenSim.RegionServer.Client;
37
38namespace OpenSim.RegionServer.Simulator
39{
40 public delegate void ParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, ClientView remote_client);
41 public delegate void ParcelDivideRequest(int west, int south, int east, int north, ClientView remote_client);
42 public delegate void ParcelJoinRequest(int west, int south, int east, int north, ClientView remote_client);
43 public delegate void ParcelPropertiesUpdateRequest(ParcelPropertiesUpdatePacket packet, ClientView remote_client);
44
45 #region ParcelManager Class
46 /// <summary>
47 /// Handles Parcel objects and operations requiring information from other Parcel objects (divide, join, etc)
48 /// </summary>
49 public class ParcelManager : OpenSim.Framework.Interfaces.ILocalStorageParcelReceiver
50 {
51
52 #region Constants
53 //Parcel types set with flags in ParcelOverlay.
54 //Only one of these can be used.
55 public const byte PARCEL_TYPE_PUBLIC = (byte)0; //Equals 00000000
56 public const byte PARCEL_TYPE_OWNED_BY_OTHER = (byte)1; //Equals 00000001
57 public const byte PARCEL_TYPE_OWNED_BY_GROUP = (byte)2; //Equals 00000010
58 public const byte PARCEL_TYPE_OWNED_BY_REQUESTER = (byte)3; //Equals 00000011
59 public const byte PARCEL_TYPE_IS_FOR_SALE = (byte)4; //Equals 00000100
60 public const byte PARCEL_TYPE_IS_BEING_AUCTIONED = (byte)5; //Equals 00000101
61
62
63 //Flags that when set, a border on the given side will be placed
64 //NOTE: North and East is assumable by the west and south sides (if parcel to east has a west border, then I have an east border; etc)
65 //This took forever to figure out -- jeesh. /blame LL for even having to send these
66 public const byte PARCEL_FLAG_PROPERTY_BORDER_WEST = (byte)64; //Equals 01000000
67 public const byte PARCEL_FLAG_PROPERTY_BORDER_SOUTH = (byte)128; //Equals 10000000
68
69 //RequestResults (I think these are right, they seem to work):
70 public const int PARCEL_RESULT_ONE_PARCEL = 0; // The request they made contained only one parcel
71 public const int PARCEL_RESULT_MULTIPLE_PARCELS = 1; // The request they made contained more than one parcel
72
73 //These are other constants. Yay!
74 public const int START_PARCEL_LOCAL_ID = 1;
75 #endregion
76
77 #region Member Variables
78 public Dictionary<int, Parcel> parcelList = new Dictionary<int, Parcel>();
79 private int lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
80 private int[,] parcelIDList = new int[64, 64];
81
82 private static World m_world;
83 #endregion
84
85 #region Constructors
86 public ParcelManager(World world)
87 {
88
89 m_world = world;
90 parcelIDList.Initialize();
91
92 }
93 #endregion
94
95 #region Member Functions
96
97 #region Parcel From Storage Functions
98 public void ParcelFromStorage(ParcelData data)
99 {
100 Parcel new_parcel = new Parcel(data.ownerID, data.isGroupOwned, m_world);
101 new_parcel.parcelData = data.Copy();
102 new_parcel.setParcelBitmapFromByteArray();
103 addParcel(new_parcel);
104
105 }
106
107 public void NoParcelDataFromStorage()
108 {
109 resetSimParcels();
110 }
111 #endregion
112
113 #region Parcel Add/Remove/Get/Create
114 /// <summary>
115 /// Creates a basic Parcel object without an owner (a zeroed key)
116 /// </summary>
117 /// <returns></returns>
118 public Parcel createBaseParcel()
119 {
120 return new Parcel(new LLUUID(), false, m_world);
121 }
122
123 /// <summary>
124 /// Adds a parcel to the stored list and adds them to the parcelIDList to what they own
125 /// </summary>
126 /// <param name="new_parcel">The parcel being added</param>
127 public void addParcel(Parcel new_parcel)
128 {
129 lastParcelLocalID++;
130 new_parcel.parcelData.localID = lastParcelLocalID;
131 parcelList.Add(lastParcelLocalID, new_parcel.Copy());
132
133
134 bool[,] parcelBitmap = new_parcel.getParcelBitmap();
135 int x, y;
136 for (x = 0; x < 64; x++)
137 {
138 for (y = 0; y < 64; y++)
139 {
140 if (parcelBitmap[x, y])
141 {
142 parcelIDList[x, y] = lastParcelLocalID;
143 }
144 }
145 }
146 parcelList[lastParcelLocalID].forceUpdateParcelInfo();
147
148
149 }
150 /// <summary>
151 /// Removes a parcel from the list. Will not remove if local_id is still owning an area in parcelIDList
152 /// </summary>
153 /// <param name="local_id">Parcel.localID of the parcel to remove.</param>
154 public void removeParcel(int local_id)
155 {
156 int x, y;
157 for (x = 0; x < 64; x++)
158 {
159 for (y = 0; y < 64; y++)
160 {
161 if (parcelIDList[x, y] == local_id)
162 {
163 throw new Exception("Could not remove parcel. Still being used at " + x + ", " + y);
164 }
165 }
166 }
167 m_world.localStorage.RemoveParcel(parcelList[local_id].parcelData);
168 parcelList.Remove(local_id);
169 }
170
171 public void performFinalParcelJoin(Parcel master, Parcel slave)
172 {
173 int x, y;
174 bool[,] parcelBitmapSlave = slave.getParcelBitmap();
175 for (x = 0; x < 64; x++)
176 {
177 for (y = 0; y < 64; y++)
178 {
179 if (parcelBitmapSlave[x, y])
180 {
181 parcelIDList[x, y] = master.parcelData.localID;
182 }
183 }
184 }
185 removeParcel(slave.parcelData.localID);
186 }
187 /// <summary>
188 /// Get the parcel at the specified point
189 /// </summary>
190 /// <param name="x">Value between 0 - 256 on the x axis of the point</param>
191 /// <param name="y">Value between 0 - 256 on the y axis of the point</param>
192 /// <returns>Parcel at the point supplied</returns>
193 public Parcel getParcel(int x, int y)
194 {
195 if (x > 256 || y > 256 || x < 0 || y < 0)
196 {
197 throw new Exception("Error: Parcel not found at point " + x + ", " + y);
198 }
199 else
200 {
201 return parcelList[parcelIDList[x / 4, y / 4]];
202 }
203
204 }
205 #endregion
206
207 #region Parcel Modification
208 /// <summary>
209 /// Subdivides a parcel
210 /// </summary>
211 /// <param name="start_x">West Point</param>
212 /// <param name="start_y">South Point</param>
213 /// <param name="end_x">East Point</param>
214 /// <param name="end_y">North Point</param>
215 /// <param name="attempting_user_id">LLUUID of user who is trying to subdivide</param>
216 /// <returns>Returns true if successful</returns>
217 public bool subdivide(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
218 {
219 //First, lets loop through the points and make sure they are all in the same parcel
220 //Get the parcel at start
221 Parcel startParcel = getParcel(start_x, start_y);
222 if (startParcel == null) return false; //No such parcel at the beginning
223
224 //Loop through the points
225 try
226 {
227 int totalX = end_x - start_x;
228 int totalY = end_y - start_y;
229 int x, y;
230 for (y = 0; y < totalY; y++)
231 {
232 for (x = 0; x < totalX; x++)
233 {
234 Parcel tempParcel = getParcel(start_x + x, start_y + y);
235 if (tempParcel == null) return false; //No such parcel at that point
236 if (tempParcel != startParcel) return false; //Subdividing over 2 parcels; no-no
237 }
238 }
239 }
240 catch (Exception e)
241 {
242 return false; //Exception. For now, lets skip subdivision
243 }
244
245 //If we are still here, then they are subdividing within one parcel
246 //Check owner
247 if (startParcel.parcelData.ownerID != attempting_user_id)
248 {
249 return false; //They cant do this!
250 }
251
252 //Lets create a new parcel with bitmap activated at that point (keeping the old parcels info)
253 Parcel newParcel = startParcel.Copy();
254 newParcel.parcelData.parcelName = "Subdivision of " + newParcel.parcelData.parcelName;
255 newParcel.parcelData.globalID = LLUUID.Random();
256
257 newParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(start_x, start_y, end_x, end_y));
258
259 //Now, lets set the subdivision area of the original to false
260 int startParcelIndex = startParcel.parcelData.localID;
261 parcelList[startParcelIndex].setParcelBitmap(Parcel.modifyParcelBitmapSquare(startParcel.getParcelBitmap(), start_x, start_y, end_x, end_y, false));
262 parcelList[startParcelIndex].forceUpdateParcelInfo();
263
264
265 //Now add the new parcel
266 addParcel(newParcel);
267
268
269
270
271
272 return true;
273 }
274 /// <summary>
275 /// Join 2 parcels together
276 /// </summary>
277 /// <param name="start_x">x value in first parcel</param>
278 /// <param name="start_y">y value in first parcel</param>
279 /// <param name="end_x">x value in second parcel</param>
280 /// <param name="end_y">y value in second parcel</param>
281 /// <param name="attempting_user_id">LLUUID of the avatar trying to join the parcels</param>
282 /// <returns>Returns true if successful</returns>
283 public bool join(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
284 {
285 end_x -= 4;
286 end_y -= 4;
287 Console.WriteLine("Joining Parcels between (" + start_x + ", " + start_y + ") and (" + end_x + ", " + end_y + ")");
288
289 //NOTE: The following only connects the parcels in each corner and not all the parcels that are within the selection box!
290 //This should be fixed later -- somewhat "incomplete code" --Ming
291 Parcel startParcel, endParcel;
292
293 try
294 {
295 startParcel = getParcel(start_x, start_y);
296 endParcel = getParcel(end_x, end_y);
297 }
298 catch (Exception e)
299 {
300 return false; //Error occured when trying to get the start and end parcels
301 }
302 if (startParcel == endParcel)
303 {
304 return false; //Subdivision of the same parcel is not allowed
305 }
306
307 //Check the parcel owners:
308 if (startParcel.parcelData.ownerID != endParcel.parcelData.ownerID)
309 {
310 return false;
311 }
312 if (startParcel.parcelData.ownerID != attempting_user_id)
313 {
314 //TODO: Group editing stuff. Avatar owner support for now
315 return false;
316 }
317
318 Console.WriteLine("Performing Join on parcel: " + startParcel.parcelData.parcelName + " - " + startParcel.parcelData.area + "sqm and " + endParcel.parcelData.parcelName + " - " + endParcel.parcelData.area + "sqm");
319 //Same owners! Lets join them
320 //Merge them to startParcel
321 parcelList[startParcel.parcelData.localID].setParcelBitmap(Parcel.mergeParcelBitmaps(startParcel.getParcelBitmap(), endParcel.getParcelBitmap()));
322 performFinalParcelJoin(startParcel, endParcel);
323
324 return true;
325
326
327
328 }
329 #endregion
330
331 #region Parcel Updating
332 /// <summary>
333 /// Where we send the ParcelOverlay packet to the client
334 /// </summary>
335 /// <param name="remote_client">The object representing the client</param>
336 public void sendParcelOverlay(ClientView remote_client)
337 {
338 const int PARCEL_BLOCKS_PER_PACKET = 1024;
339 int x, y = 0;
340 byte[] byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
341 int byteArrayCount = 0;
342 int sequenceID = 0;
343 ParcelOverlayPacket packet;
344
345 for (y = 0; y < 64; y++)
346 {
347 for (x = 0; x < 64; x++)
348 {
349 byte tempByte = (byte)0; //This represents the byte for the current 4x4
350 Parcel currentParcelBlock = getParcel(x * 4, y * 4);
351
352 if (currentParcelBlock.parcelData.ownerID == remote_client.AgentID)
353 {
354 //Owner Flag
355 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_REQUESTER);
356 }
357 else if (currentParcelBlock.parcelData.salePrice > 0 && (currentParcelBlock.parcelData.authBuyerID == LLUUID.Zero || currentParcelBlock.parcelData.authBuyerID == remote_client.AgentID))
358 {
359 //Sale Flag
360 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_IS_FOR_SALE);
361 }
362 else if (currentParcelBlock.parcelData.ownerID == LLUUID.Zero)
363 {
364 //Public Flag
365 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_PUBLIC);
366 }
367 else
368 {
369 //Other Flag
370 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_OTHER);
371 }
372
373
374 //Now for border control
375 if (x == 0)
376 {
377 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
378 }
379 else if (getParcel((x - 1) * 4, y * 4) != currentParcelBlock)
380 {
381 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
382 }
383
384 if (y == 0)
385 {
386 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
387 }
388 else if (getParcel(x * 4, (y - 1) * 4) != currentParcelBlock)
389 {
390 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
391 }
392
393 byteArray[byteArrayCount] = tempByte;
394 byteArrayCount++;
395 if (byteArrayCount >= PARCEL_BLOCKS_PER_PACKET)
396 {
397 byteArrayCount = 0;
398 packet = new ParcelOverlayPacket();
399 packet.ParcelData.Data = byteArray;
400 packet.ParcelData.SequenceID = sequenceID;
401 remote_client.OutPacket((Packet)packet);
402 sequenceID++;
403 byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
404 }
405 }
406 }
407
408 packet = new ParcelOverlayPacket();
409 packet.ParcelData.Data = byteArray;
410 packet.ParcelData.SequenceID = sequenceID; //Eh?
411 remote_client.OutPacket((Packet)packet);
412 }
413 #endregion
414
415 /// <summary>
416 /// Resets the sim to the default parcel (full sim parcel owned by the default user)
417 /// </summary>
418 public void resetSimParcels()
419 {
420 //Remove all the parcels in the sim and add a blank, full sim parcel set to public
421 parcelList.Clear();
422 lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
423 parcelIDList.Initialize();
424
425 Parcel fullSimParcel = new Parcel(LLUUID.Zero, false, m_world);
426
427 fullSimParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(0, 0, 256, 256));
428 fullSimParcel.parcelData.parcelName = "Your Sim Parcel";
429 fullSimParcel.parcelData.parcelDesc = "";
430
431 fullSimParcel.parcelData.ownerID = m_world.m_regInfo.MasterAvatarAssignedUUID;
432 fullSimParcel.parcelData.salePrice = 1;
433 fullSimParcel.parcelData.parcelFlags = libsecondlife.Parcel.ParcelFlags.ForSale;
434 fullSimParcel.parcelData.parcelStatus = libsecondlife.Parcel.ParcelStatus.Leased;
435
436 addParcel(fullSimParcel);
437
438 }
439 #endregion
440 }
441 #endregion
442
443
444 #region Parcel Class
445 /// <summary>
446 /// Keeps track of a specific parcel's information
447 /// </summary>
448 public class Parcel
449 {
450 #region Member Variables
451 public ParcelData parcelData = new ParcelData();
452 public World m_world;
453
454 private bool[,] parcelBitmap = new bool[64, 64];
455
456 #endregion
457
458
459 #region Constructors
460 public Parcel(LLUUID owner_id, bool is_group_owned, World world)
461 {
462 m_world = world;
463 parcelData.ownerID = owner_id;
464 parcelData.isGroupOwned = is_group_owned;
465
466 }
467 #endregion
468
469
470 #region Member Functions
471
472 #region General Functions
473 /// <summary>
474 /// Checks to see if this parcel contains a point
475 /// </summary>
476 /// <param name="x"></param>
477 /// <param name="y"></param>
478 /// <returns>Returns true if the parcel contains the specified point</returns>
479 public bool containsPoint(int x, int y)
480 {
481 if (x >= 0 && y >= 0 && x <= 256 && x <= 256)
482 {
483 return (parcelBitmap[x / 4, y / 4] == true);
484 }
485 else
486 {
487 return false;
488 }
489 }
490
491 public Parcel Copy()
492 {
493 Parcel newParcel = new Parcel(this.parcelData.ownerID, this.parcelData.isGroupOwned, m_world);
494
495 //Place all new variables here!
496 newParcel.parcelBitmap = (bool[,])(this.parcelBitmap.Clone());
497 newParcel.parcelData = parcelData.Copy();
498
499 return newParcel;
500 }
501
502 #endregion
503
504
505 #region Packet Request Handling
506 /// <summary>
507 /// Sends parcel properties as requested
508 /// </summary>
509 /// <param name="sequence_id">ID sent by client for them to keep track of</param>
510 /// <param name="snap_selection">Bool sent by client for them to use</param>
511 /// <param name="remote_client">Object representing the client</param>
512 public void sendParcelProperties(int sequence_id, bool snap_selection, int request_result, ClientView remote_client)
513 {
514
515 ParcelPropertiesPacket updatePacket = new ParcelPropertiesPacket();
516 updatePacket.ParcelData.AABBMax = parcelData.AABBMax;
517 updatePacket.ParcelData.AABBMin = parcelData.AABBMin;
518 updatePacket.ParcelData.Area = parcelData.area;
519 updatePacket.ParcelData.AuctionID = parcelData.auctionID;
520 updatePacket.ParcelData.AuthBuyerID =parcelData.authBuyerID; //unemplemented
521
522 updatePacket.ParcelData.Bitmap = parcelData.parcelBitmapByteArray;
523
524 updatePacket.ParcelData.Desc = libsecondlife.Helpers.StringToField(parcelData.parcelDesc);
525 updatePacket.ParcelData.Category = (byte)parcelData.category;
526 updatePacket.ParcelData.ClaimDate = parcelData.claimDate;
527 updatePacket.ParcelData.ClaimPrice = parcelData.claimPrice;
528 updatePacket.ParcelData.GroupID = parcelData.groupID;
529 updatePacket.ParcelData.GroupPrims = parcelData.groupPrims;
530 updatePacket.ParcelData.IsGroupOwned = parcelData.isGroupOwned;
531 updatePacket.ParcelData.LandingType = (byte)parcelData.landingType;
532 updatePacket.ParcelData.LocalID = parcelData.localID;
533 updatePacket.ParcelData.MaxPrims = 1000; //unemplemented
534 updatePacket.ParcelData.MediaAutoScale = parcelData.mediaAutoScale;
535 updatePacket.ParcelData.MediaID = parcelData.mediaID;
536 updatePacket.ParcelData.MediaURL = Helpers.StringToField(parcelData.mediaURL);
537 updatePacket.ParcelData.MusicURL = Helpers.StringToField(parcelData.musicURL);
538 updatePacket.ParcelData.Name = Helpers.StringToField(parcelData.parcelName);
539 updatePacket.ParcelData.OtherCleanTime = 0; //unemplemented
540 updatePacket.ParcelData.OtherCount = 0; //unemplemented
541 updatePacket.ParcelData.OtherPrims = 0; //unemplented
542 updatePacket.ParcelData.OwnerID = parcelData.ownerID;
543 updatePacket.ParcelData.OwnerPrims = 0; //unemplemented
544 updatePacket.ParcelData.ParcelFlags = (uint)parcelData.parcelFlags; //unemplemented
545 updatePacket.ParcelData.ParcelPrimBonus = (float)1.0; //unemplemented
546 updatePacket.ParcelData.PassHours = parcelData.passHours;
547 updatePacket.ParcelData.PassPrice = parcelData.passPrice;
548 updatePacket.ParcelData.PublicCount = 0; //unemplemented
549 updatePacket.ParcelData.RegionDenyAnonymous = false; //unemplemented
550 updatePacket.ParcelData.RegionDenyIdentified = false; //unemplemented
551 updatePacket.ParcelData.RegionDenyTransacted = false; //unemplemented
552 updatePacket.ParcelData.RegionPushOverride = true; //unemplemented
553 updatePacket.ParcelData.RentPrice = 0; //??
554 updatePacket.ParcelData.RequestResult = request_result;
555 updatePacket.ParcelData.SalePrice = parcelData.salePrice; //unemplemented
556 updatePacket.ParcelData.SelectedPrims = 0; //unemeplemented
557 updatePacket.ParcelData.SelfCount = 0;//unemplemented
558 updatePacket.ParcelData.SequenceID = sequence_id;
559 updatePacket.ParcelData.SimWideMaxPrims = 15000; //unemplemented
560 updatePacket.ParcelData.SimWideTotalPrims = 0; //unemplemented
561 updatePacket.ParcelData.SnapSelection = snap_selection;
562 updatePacket.ParcelData.SnapshotID = parcelData.snapshotID;
563 updatePacket.ParcelData.Status = (byte)parcelData.parcelStatus;
564 updatePacket.ParcelData.TotalPrims = 0; //unemplemented
565 updatePacket.ParcelData.UserLocation = parcelData.userLocation;
566 updatePacket.ParcelData.UserLookAt = parcelData.userLookAt;
567
568 remote_client.OutPacket((Packet)updatePacket);
569 }
570
571 public void updateParcelProperties(ParcelPropertiesUpdatePacket packet, ClientView remote_client)
572 {
573 if (remote_client.AgentID == parcelData.ownerID)
574 {
575 //Needs later group support
576 Console.WriteLine("Request for update - parcel #" + parcelData.localID);
577 parcelData.authBuyerID = packet.ParcelData.AuthBuyerID;
578 parcelData.category = (libsecondlife.Parcel.ParcelCategory)packet.ParcelData.Category;
579 parcelData.parcelDesc = Helpers.FieldToUTF8String(packet.ParcelData.Desc);
580 parcelData.groupID = packet.ParcelData.GroupID;
581 parcelData.landingType = packet.ParcelData.LandingType;
582 parcelData.mediaAutoScale = packet.ParcelData.MediaAutoScale;
583 parcelData.mediaID = packet.ParcelData.MediaID;
584 parcelData.mediaURL = Helpers.FieldToUTF8String(packet.ParcelData.MediaURL);
585 parcelData.musicURL = Helpers.FieldToUTF8String(packet.ParcelData.MusicURL);
586 parcelData.parcelName = libsecondlife.Helpers.FieldToUTF8String(packet.ParcelData.Name);
587 parcelData.parcelFlags = (libsecondlife.Parcel.ParcelFlags)packet.ParcelData.ParcelFlags;
588 parcelData.passHours = packet.ParcelData.PassHours;
589 parcelData.passPrice = packet.ParcelData.PassPrice;
590 parcelData.salePrice = packet.ParcelData.SalePrice;
591 parcelData.snapshotID = packet.ParcelData.SnapshotID;
592 parcelData.userLocation = packet.ParcelData.UserLocation;
593 parcelData.userLookAt = packet.ParcelData.UserLookAt;
594 }
595 }
596 #endregion
597
598
599 #region Update Functions
600 /// <summary>
601 /// Updates the AABBMin and AABBMax values after area/shape modification of parcel
602 /// </summary>
603 private void updateAABBAndAreaValues()
604 {
605 int min_x = 64;
606 int min_y = 64;
607 int max_x = 0;
608 int max_y = 0;
609 int tempArea = 0;
610 int x, y;
611 for (x = 0; x < 64; x++)
612 {
613 for (y = 0; y < 64; y++)
614 {
615 if (parcelBitmap[x, y] == true)
616 {
617 if (min_x > x) min_x = x;
618 if (min_y > y) min_y = y;
619 if (max_x < x) max_x = x;
620 if (max_y < y) max_y = y;
621 tempArea += 16; //16sqm parcel
622 }
623 }
624 }
625 parcelData.AABBMin = new LLVector3((float)(min_x * 4), (float)(min_y * 4), m_world.Terrain[(min_x * 4), (min_y * 4)]);
626 parcelData.AABBMax = new LLVector3((float)(max_x * 4), (float)(max_y * 4), m_world.Terrain[(max_x * 4), (max_y * 4)]);
627 parcelData.area = tempArea;
628 }
629
630 public void updateParcelBitmapByteArray()
631 {
632 parcelData.parcelBitmapByteArray = convertParcelBitmapToBytes();
633 }
634
635 /// <summary>
636 /// Update all settings in parcel such as area, bitmap byte array, etc
637 /// </summary>
638 public void forceUpdateParcelInfo()
639 {
640 this.updateAABBAndAreaValues();
641 this.updateParcelBitmapByteArray();
642 }
643
644 public void setParcelBitmapFromByteArray()
645 {
646 parcelBitmap = convertBytesToParcelBitmap();
647 }
648 #endregion
649
650
651 #region Parcel Bitmap Functions
652 /// <summary>
653 /// Sets the parcel's bitmap manually
654 /// </summary>
655 /// <param name="bitmap">64x64 block representing where this parcel is on a map</param>
656 public void setParcelBitmap(bool[,] bitmap)
657 {
658 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
659 {
660 //Throw an exception - The bitmap is not 64x64
661 throw new Exception("Error: Invalid Parcel Bitmap");
662 }
663 else
664 {
665 //Valid: Lets set it
666 parcelBitmap = bitmap;
667 forceUpdateParcelInfo();
668
669 }
670 }
671 /// <summary>
672 /// Gets the parcels bitmap manually
673 /// </summary>
674 /// <returns></returns>
675 public bool[,] getParcelBitmap()
676 {
677 return parcelBitmap;
678 }
679 /// <summary>
680 /// Converts the parcel bitmap to a packet friendly byte array
681 /// </summary>
682 /// <returns></returns>
683 private byte[] convertParcelBitmapToBytes()
684 {
685 byte[] tempConvertArr = new byte[512];
686 byte tempByte = 0;
687 int x, y, i, byteNum = 0;
688 i = 0;
689 for (y = 0; y < 64; y++)
690 {
691 for (x = 0; x < 64; x++)
692 {
693 tempByte = Convert.ToByte(tempByte | Convert.ToByte(parcelBitmap[x, y]) << (i++ % 8));
694 if (i % 8 == 0)
695 {
696 tempConvertArr[byteNum] = tempByte;
697 tempByte = (byte)0;
698 i = 0;
699 byteNum++;
700 }
701 }
702 }
703 return tempConvertArr;
704 }
705
706 private bool[,] convertBytesToParcelBitmap()
707 {
708 bool[,] tempConvertMap = new bool[64, 64];
709 tempConvertMap.Initialize();
710 byte tempByte = 0;
711 int x = 0, y = 0, i = 0, bitNum = 0;
712 for(i = 0; i < 512; i++)
713 {
714 tempByte = parcelData.parcelBitmapByteArray[i];
715 for(bitNum = 0; bitNum < 8; bitNum++)
716 {
717 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte)1);
718 tempConvertMap[x, y] = bit;
719 x++;
720 if(x > 63)
721 {
722 x = 0;
723 y++;
724 }
725
726 }
727
728 }
729 return tempConvertMap;
730 }
731 /// <summary>
732 /// Full sim parcel creation
733 /// </summary>
734 /// <returns></returns>
735 public static bool[,] basicFullRegionParcelBitmap()
736 {
737 return getSquareParcelBitmap(0, 0, 256, 256);
738 }
739
740 /// <summary>
741 /// Used to modify the bitmap between the x and y points. Points use 64 scale
742 /// </summary>
743 /// <param name="start_x"></param>
744 /// <param name="start_y"></param>
745 /// <param name="end_x"></param>
746 /// <param name="end_y"></param>
747 /// <returns></returns>
748 public static bool[,] getSquareParcelBitmap(int start_x, int start_y, int end_x, int end_y)
749 {
750
751 bool[,] tempBitmap = new bool[64, 64];
752 tempBitmap.Initialize();
753
754 tempBitmap = modifyParcelBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
755 return tempBitmap;
756 }
757
758 /// <summary>
759 /// Change a parcel's bitmap at within a square and set those points to a specific value
760 /// </summary>
761 /// <param name="parcel_bitmap"></param>
762 /// <param name="start_x"></param>
763 /// <param name="start_y"></param>
764 /// <param name="end_x"></param>
765 /// <param name="end_y"></param>
766 /// <param name="set_value"></param>
767 /// <returns></returns>
768 public static bool[,] modifyParcelBitmapSquare(bool[,] parcel_bitmap, int start_x, int start_y, int end_x, int end_y, bool set_value)
769 {
770 if (parcel_bitmap.GetLength(0) != 64 || parcel_bitmap.GetLength(1) != 64 || parcel_bitmap.Rank != 2)
771 {
772 //Throw an exception - The bitmap is not 64x64
773 throw new Exception("Error: Invalid Parcel Bitmap in modifyParcelBitmapSquare()");
774 }
775
776 int x, y;
777 for (y = 0; y < 64; y++)
778 {
779 for (x = 0; x < 64; x++)
780 {
781 if (x >= start_x / 4 && x < end_x / 4
782 && y >= start_y / 4 && y < end_y / 4)
783 {
784 parcel_bitmap[x, y] = set_value;
785 }
786 }
787 }
788 return parcel_bitmap;
789 }
790 /// <summary>
791 /// Join the true values of 2 bitmaps together
792 /// </summary>
793 /// <param name="bitmap_base"></param>
794 /// <param name="bitmap_add"></param>
795 /// <returns></returns>
796 public static bool[,] mergeParcelBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
797 {
798 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
799 {
800 //Throw an exception - The bitmap is not 64x64
801 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeParcelBitmaps");
802 }
803 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
804 {
805 //Throw an exception - The bitmap is not 64x64
806 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeParcelBitmaps");
807
808 }
809
810 int x, y;
811 for (y = 0; y < 64; y++)
812 {
813 for (x = 0; x < 64; x++)
814 {
815 if (bitmap_add[x, y])
816 {
817 bitmap_base[x, y] = true;
818 }
819 }
820 }
821 return bitmap_base;
822 }
823 #endregion
824
825 #endregion
826
827
828 }
829 #endregion
830
831
832}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs b/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs
new file mode 100644
index 0000000..f1417d0
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs
@@ -0,0 +1,598 @@
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 System.Text;
31using OpenSim.RegionServer.Types;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Physics.Manager;
36using OpenSim.Framework.Types;
37using OpenSim.RegionServer.Client;
38
39namespace OpenSim.RegionServer.Simulator
40{
41 public class Primitive : Entity
42 {
43 protected float mesh_cutbegin;
44 protected float mesh_cutend;
45 protected PrimData primData;
46 protected bool newPrimFlag = false;
47 protected bool updateFlag = false;
48 protected bool dirtyFlag = false;
49 private ObjectUpdatePacket OurPacket;
50 private bool physicsEnabled = false;
51 private bool physicstest = false;
52 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
53 private Dictionary<uint, ClientView> m_clientThreads;
54 private ulong m_regionHandle;
55 private const uint FULL_MASK_PERMISSIONS = 2147483647;
56
57 public bool PhysicsEnabled
58 {
59 get
60 {
61 return physicsEnabled;
62 }
63 set
64 {
65 physicsEnabled = value;
66 }
67 }
68 public bool UpdateFlag
69 {
70 get
71 {
72 return updateFlag;
73 }
74 set
75 {
76 updateFlag = value;
77 }
78 }
79 public LLVector3 Scale
80 {
81 set
82 {
83 LLVector3 offset = (value - primData.Scale);
84 offset.X /= 2;
85 offset.Y /= 2;
86 offset.Z /= 2;
87
88 this.primData.Position += offset;
89 this.primData.Scale = value;
90
91 this.dirtyFlag = true;
92 }
93 get
94 {
95 return this.primData.Scale;
96 }
97 }
98 public PhysicsActor PhysActor
99 {
100 set
101 {
102 this._physActor = value;
103 }
104 }
105
106 public Primitive(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world)
107 {
108 mesh_cutbegin = 0.0f;
109 mesh_cutend = 1.0f;
110
111 m_clientThreads = clientThreads;
112 m_regionHandle = regionHandle;
113 m_world = world;
114 }
115
116 public override Mesh getMesh()
117 {
118 Mesh mesh = new Mesh();
119 Triangle tri = new Triangle(
120 new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f),
121 new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f),
122 new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f));
123
124 mesh.AddTri(tri);
125 mesh += base.getMesh();
126
127 return mesh;
128 }
129
130 public byte[] GetByteArray()
131 {
132 return this.primData.ToBytes();
133 }
134
135 public void GetProperites(ClientView client)
136 {
137 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
138 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
139 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
140 proper.ObjectData[0].ItemID = LLUUID.Zero; // this.uuid;
141 proper.ObjectData[0].CreationDate = (ulong) this.primData.CreationDate;
142 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
143 proper.ObjectData[0].FolderID = LLUUID.Zero;
144 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
145 proper.ObjectData[0].GroupID = LLUUID.Zero;
146 proper.ObjectData[0].InventorySerial = 0;
147 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
148 proper.ObjectData[0].ObjectID = this.uuid;
149 proper.ObjectData[0].OwnerID = primData.OwnerID;
150 proper.ObjectData[0].TouchName = new byte[0];
151 proper.ObjectData[0].TextureID = new byte[0];
152 proper.ObjectData[0].SitName = new byte[0];
153 proper.ObjectData[0].Name = new byte[0];
154 proper.ObjectData[0].Description = new byte[0];
155 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
156 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
157 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
158 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
159 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
160
161 client.OutPacket(proper);
162 }
163
164 public void UpdatePosition(LLVector3 pos)
165 {
166 this.Pos = pos;
167 if (this._physActor != null) // && this.physicsEnabled)
168 {
169 try
170 {
171 lock (m_world.LockPhysicsEngine)
172 {
173 this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z);
174 }
175 }
176 catch (Exception e)
177 {
178 Console.WriteLine(e.Message);
179 }
180 }
181 this.updateFlag = true;
182 }
183
184 public override void update()
185 {
186 LLVector3 pos2 = new LLVector3(0, 0, 0);
187 if (this._physActor != null && this.physicsEnabled)
188 {
189
190 PhysicsVector pPos = this._physActor.Position;
191 pos2 = new LLVector3(pPos.X, pPos.Y, pPos.Z);
192 }
193 if (this.newPrimFlag)
194 {
195 foreach (ClientView client in m_clientThreads.Values)
196 {
197 client.OutPacket(OurPacket);
198 }
199 this.newPrimFlag = false;
200 }
201 else if (this.updateFlag)
202 {
203 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
204 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
205 terse.RegionData.TimeDilation = 64096;
206 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
207 terse.ObjectData[0] = this.CreateImprovedBlock();
208 foreach (ClientView client in m_clientThreads.Values)
209 {
210 client.OutPacket(terse);
211 }
212 this.updateFlag = false;
213 }
214 else if (this.dirtyFlag)
215 {
216 foreach (ClientView client in m_clientThreads.Values)
217 {
218 UpdateClient(client);
219 }
220 this.dirtyFlag = false;
221 }
222 else
223 {
224 if (this._physActor != null && this.physicsEnabled)
225 {
226 if (pos2 != this.positionLastFrame)
227 {
228 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
229 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
230 terse.RegionData.TimeDilation = 64096;
231 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
232 terse.ObjectData[0] = this.CreateImprovedBlock();
233 foreach (ClientView client in m_clientThreads.Values)
234 {
235 client.OutPacket(terse);
236 }
237 }
238 this.positionLastFrame = pos2;
239 }
240 }
241
242 if (this.physicstest)
243 {
244 LLVector3 pos = this.Pos;
245 pos.Z += 0.0001f;
246 this.UpdatePosition(pos);
247 this.physicstest = false;
248 }
249 }
250
251 public void UpdateClient(ClientView RemoteClient)
252 {
253
254 LLVector3 lPos;
255 if (this._physActor != null && this.physicsEnabled)
256 {
257 PhysicsVector pPos = this._physActor.Position;
258 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
259 }
260 else
261 {
262 lPos = this.Pos;
263 }
264 byte[] pb = lPos.GetBytes();
265 Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
266
267 // OurPacket should be update with the follwing in updateShape() rather than having to do it here
268 OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
269 OurPacket.ObjectData[0].PCode = this.primData.PCode;
270 OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
271 OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
272 OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
273 OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
274 OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
275 OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
276 OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
277 OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
278 OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
279 OurPacket.ObjectData[0].Scale = this.primData.Scale;
280 OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
281 OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
282 OurPacket.ObjectData[0].ParentID = this.primData.ParentID ;
283 OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
284 //finish off copying rest of shape data
285 OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
286 OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
287 OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
288 OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
289 OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
290 OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
291
292 RemoteClient.OutPacket(OurPacket);
293 }
294
295 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
296 {
297 this.primData.PathBegin = addPacket.PathBegin;
298 this.primData.PathEnd = addPacket.PathEnd;
299 this.primData.PathScaleX = addPacket.PathScaleX;
300 this.primData.PathScaleY = addPacket.PathScaleY;
301 this.primData.PathShearX = addPacket.PathShearX;
302 this.primData.PathShearY = addPacket.PathShearY;
303 this.primData.PathSkew = addPacket.PathSkew;
304 this.primData.ProfileBegin = addPacket.ProfileBegin;
305 this.primData.ProfileEnd = addPacket.ProfileEnd;
306 this.primData.PathCurve = addPacket.PathCurve;
307 this.primData.ProfileCurve = addPacket.ProfileCurve;
308 this.primData.ProfileHollow = addPacket.ProfileHollow;
309 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
310 this.primData.PathRevolutions = addPacket.PathRevolutions;
311 this.primData.PathTaperX = addPacket.PathTaperX;
312 this.primData.PathTaperY = addPacket.PathTaperY;
313 this.primData.PathTwist = addPacket.PathTwist;
314 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
315 this.dirtyFlag = true;
316 }
317
318 public void UpdateTexture(byte[] tex)
319 {
320 this.OurPacket.ObjectData[0].TextureEntry = tex;
321 this.primData.Texture = tex;
322 this.dirtyFlag = true;
323 }
324
325 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
326 {
327 if (this._physActor != null)
328 {
329 if (this._physActor.Kinematic == pack.AgentData.UsePhysics)
330 {
331 this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false
332 }
333 this.physicsEnabled = pack.AgentData.UsePhysics;
334 if (this._physActor.Kinematic == false)
335 {
336 LLVector3 pos = this.Pos;
337 this.UpdatePosition(pos);
338 pos.Z += 0.000001f;
339 this.UpdatePosition(pos);
340 this.physicstest = true;
341 }
342 else
343 {
344 PhysicsVector vec = this._physActor.Position;
345 LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
346 this.Pos = pos;
347 this.updateFlag = true;
348 }
349 }
350 }
351
352 public void MakeParent(Primitive prim)
353 {
354 this.primData.ParentID = prim.localid;
355 this.Pos -= prim.Pos;
356 this.dirtyFlag = true;
357 }
358
359 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
360 {
361 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
362 objupdate.RegionData.RegionHandle = m_regionHandle;
363 objupdate.RegionData.TimeDilation = 64096;
364
365 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
366 PrimData PData = new PrimData();
367 this.primData = PData;
368 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
369
370 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
371 objupdate.ObjectData[0].PSBlock = new byte[0];
372 objupdate.ObjectData[0].ExtraParams = new byte[1];
373 objupdate.ObjectData[0].MediaURL = new byte[0];
374 objupdate.ObjectData[0].NameValue = new byte[0];
375 objupdate.ObjectData[0].Text = new byte[0];
376 objupdate.ObjectData[0].TextColor = new byte[4];
377 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
378 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
379 objupdate.ObjectData[0].Material = 3;
380 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
381 objupdate.ObjectData[0].TextureAnim = new byte[0];
382 objupdate.ObjectData[0].Sound = LLUUID.Zero;
383 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
384 this.primData.Texture = objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
385 objupdate.ObjectData[0].State = 0;
386 objupdate.ObjectData[0].Data = new byte[0];
387 PData.OwnerID = objupdate.ObjectData[0].OwnerID = ownerID;
388 PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode;
389 PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin;
390 PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd;
391 PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX;
392 PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY;
393 PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX;
394 PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY;
395 PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew;
396 PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin;
397 PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd;
398 PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale;
399 PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve;
400 PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve;
401 PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
402 PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
403 PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
404 PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
405 PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
406 PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
407 PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
408 PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
409
410 objupdate.ObjectData[0].ID = (uint)(localID);
411 objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000"));
412 objupdate.ObjectData[0].ObjectData = new byte[60];
413 objupdate.ObjectData[0].ObjectData[46] = 128;
414 objupdate.ObjectData[0].ObjectData[47] = 63;
415 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
416 //update position
417 byte[] pb = pos1.GetBytes();
418 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
419 this.newPrimFlag = true;
420 this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID;
421 this.localid = objupdate.ObjectData[0].ID;
422 this.primData.Position = this.Pos = pos1;
423 this.OurPacket = objupdate;
424 }
425
426 public void CreateFromStorage(PrimData store)
427 {
428 this.CreateFromStorage(store, store.Position, store.LocalID, false);
429 }
430
431 public void CreateFromStorage(PrimData store, LLVector3 posi, uint localID, bool newprim)
432 {
433 //need to clean this up as it shares a lot of code with CreateFromPacket()
434 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
435 objupdate.RegionData.RegionHandle = m_regionHandle;
436 objupdate.RegionData.TimeDilation = 64096;
437 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
438
439 this.primData = store;
440 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
441 objupdate.ObjectData[0].PSBlock = new byte[0];
442 objupdate.ObjectData[0].ExtraParams = new byte[1];
443 objupdate.ObjectData[0].MediaURL = new byte[0];
444 objupdate.ObjectData[0].NameValue = new byte[0];
445 objupdate.ObjectData[0].Text = new byte[0];
446 objupdate.ObjectData[0].TextColor = new byte[4];
447 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
448 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
449 objupdate.ObjectData[0].Material = 3;
450 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
451 objupdate.ObjectData[0].TextureAnim = new byte[0];
452 objupdate.ObjectData[0].Sound = LLUUID.Zero;
453
454 if (store.Texture == null)
455 {
456 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
457 objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
458 }
459 else
460 {
461 objupdate.ObjectData[0].TextureEntry = store.Texture;
462 }
463
464 objupdate.ObjectData[0].State = 0;
465 objupdate.ObjectData[0].Data = new byte[0];
466 objupdate.ObjectData[0].OwnerID = this.primData.OwnerID;
467 objupdate.ObjectData[0].PCode = this.primData.PCode;
468 objupdate.ObjectData[0].PathBegin = this.primData.PathBegin;
469 objupdate.ObjectData[0].PathEnd = this.primData.PathEnd;
470 objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX;
471 objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY;
472 objupdate.ObjectData[0].PathShearX = this.primData.PathShearX;
473 objupdate.ObjectData[0].PathShearY = this.primData.PathShearY;
474 objupdate.ObjectData[0].PathSkew = this.primData.PathSkew;
475 objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
476 objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
477 objupdate.ObjectData[0].Scale = this.primData.Scale;
478 objupdate.ObjectData[0].PathCurve = this.primData.PathCurve;
479 objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
480 objupdate.ObjectData[0].ParentID = 0;
481 objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
482 //finish off copying rest of shape data
483 objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
484 objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
485 objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
486 objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
487 objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
488 objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
489
490 objupdate.ObjectData[0].ID = localID; // (uint)store.LocalID;
491 objupdate.ObjectData[0].FullID = store.FullID;
492
493 objupdate.ObjectData[0].ObjectData = new byte[60];
494 objupdate.ObjectData[0].ObjectData[46] = 128;
495 objupdate.ObjectData[0].ObjectData[47] = 63;
496 LLVector3 pos1 = posi; // store.Position;
497 //update position
498 byte[] pb = pos1.GetBytes();
499 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
500
501 this.uuid = objupdate.ObjectData[0].FullID;
502 this.localid = objupdate.ObjectData[0].ID;
503 this.Pos = pos1;
504 this.OurPacket = objupdate;
505 if (newprim)
506 {
507 this.newPrimFlag = true;
508 }
509 }
510
511 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
512 {
513 uint ID = this.localid;
514 byte[] bytes = new byte[60];
515
516 int i = 0;
517 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
518 //dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
519 dat.TextureEntry = new byte[0];
520 bytes[i++] = (byte)(ID % 256);
521 bytes[i++] = (byte)((ID >> 8) % 256);
522 bytes[i++] = (byte)((ID >> 16) % 256);
523 bytes[i++] = (byte)((ID >> 24) % 256);
524 bytes[i++] = 0;
525 bytes[i++] = 0;
526
527 LLVector3 lPos;
528 Axiom.MathLib.Quaternion lRot;
529 if (this._physActor != null && this.physicsEnabled)
530 {
531 PhysicsVector pPos = this._physActor.Position;
532 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
533 lRot = this._physActor.Orientation;
534 }
535 else
536 {
537 lPos = this.Pos;
538 lRot = this.rotation;
539 }
540 byte[] pb = lPos.GetBytes();
541 Array.Copy(pb, 0, bytes, i, pb.Length);
542 i += 12;
543 ushort ac = 32767;
544
545 //vel
546 bytes[i++] = (byte)(ac % 256);
547 bytes[i++] = (byte)((ac >> 8) % 256);
548 bytes[i++] = (byte)(ac % 256);
549 bytes[i++] = (byte)((ac >> 8) % 256);
550 bytes[i++] = (byte)(ac % 256);
551 bytes[i++] = (byte)((ac >> 8) % 256);
552
553 //accel
554 bytes[i++] = (byte)(ac % 256);
555 bytes[i++] = (byte)((ac >> 8) % 256);
556 bytes[i++] = (byte)(ac % 256);
557 bytes[i++] = (byte)((ac >> 8) % 256);
558 bytes[i++] = (byte)(ac % 256);
559 bytes[i++] = (byte)((ac >> 8) % 256);
560
561 ushort rw, rx, ry, rz;
562 rw = (ushort)(32768 * (lRot.w + 1));
563 rx = (ushort)(32768 * (lRot.x + 1));
564 ry = (ushort)(32768 * (lRot.y + 1));
565 rz = (ushort)(32768 * (lRot.z + 1));
566
567 //rot
568 bytes[i++] = (byte)(rx % 256);
569 bytes[i++] = (byte)((rx >> 8) % 256);
570 bytes[i++] = (byte)(ry % 256);
571 bytes[i++] = (byte)((ry >> 8) % 256);
572 bytes[i++] = (byte)(rz % 256);
573 bytes[i++] = (byte)((rz >> 8) % 256);
574 bytes[i++] = (byte)(rw % 256);
575 bytes[i++] = (byte)((rw >> 8) % 256);
576
577 //rotation vel
578 bytes[i++] = (byte)(ac % 256);
579 bytes[i++] = (byte)((ac >> 8) % 256);
580 bytes[i++] = (byte)(ac % 256);
581 bytes[i++] = (byte)((ac >> 8) % 256);
582 bytes[i++] = (byte)(ac % 256);
583 bytes[i++] = (byte)((ac >> 8) % 256);
584
585 dat.Data = bytes;
586 return dat;
587 }
588
589 public override void BackUp()
590 {
591 this.primData.FullID = this.uuid;
592 this.primData.LocalID = this.localid;
593 this.primData.Position = this.Pos;
594 this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
595 this.m_world.localStorage.StorePrim(this.primData);
596 }
597 }
598}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Primitive2.cs b/OpenSim/OpenSim.RegionServer/Simulator/Primitive2.cs
new file mode 100644
index 0000000..0286e54
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/Primitive2.cs
@@ -0,0 +1,519 @@
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 System.Text;
31using OpenSim.RegionServer.Types;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Physics.Manager;
36using OpenSim.Framework.Types;
37using OpenSim.Framework.Inventory;
38using OpenSim.RegionServer.Client;
39
40namespace OpenSim.RegionServer.Simulator
41{
42 public class Primitive2 : Entity
43 {
44 protected PrimData primData;
45 //private ObjectUpdatePacket OurPacket;
46 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
47 private Dictionary<uint, ClientView> m_clientThreads;
48 private ulong m_regionHandle;
49 private const uint FULL_MASK_PERMISSIONS = 2147483647;
50 private bool physicsEnabled = false;
51
52 private Dictionary<LLUUID, InventoryItem> inventoryItems;
53
54 #region Properties
55
56 public LLVector3 Scale
57 {
58 set
59 {
60 this.primData.Scale = value;
61 //this.dirtyFlag = true;
62 }
63 get
64 {
65 return this.primData.Scale;
66 }
67 }
68
69 public PhysicsActor PhysActor
70 {
71 set
72 {
73 this._physActor = value;
74 }
75 }
76 public override LLVector3 Pos
77 {
78 get
79 {
80 return base.Pos;
81 }
82 set
83 {
84 base.Pos = value;
85 }
86 }
87 #endregion
88
89 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world)
90 {
91 m_clientThreads = clientThreads;
92 m_regionHandle = regionHandle;
93 m_world = world;
94 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
95 }
96
97 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world, LLUUID owner)
98 {
99 m_clientThreads = clientThreads;
100 m_regionHandle = regionHandle;
101 m_world = world;
102 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
103 this.primData = new PrimData();
104 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
105 this.primData.OwnerID = owner;
106 }
107
108 public byte[] GetByteArray()
109 {
110 byte[] result = null;
111 List<byte[]> dataArrays = new List<byte[]>();
112 dataArrays.Add(primData.ToBytes());
113 foreach (Entity child in children)
114 {
115 if (child is OpenSim.RegionServer.Simulator.Primitive2)
116 {
117 dataArrays.Add(((OpenSim.RegionServer.Simulator.Primitive2)child).GetByteArray());
118 }
119 }
120 byte[] primstart = Helpers.StringToField("<Prim>");
121 byte[] primend = Helpers.StringToField("</Prim>");
122 int totalLength = primstart.Length + primend.Length;
123 for (int i = 0; i < dataArrays.Count; i++)
124 {
125 totalLength += dataArrays[i].Length;
126 }
127
128 result = new byte[totalLength];
129 int arraypos = 0;
130 Array.Copy(primstart, 0, result, 0, primstart.Length);
131 arraypos += primstart.Length;
132 for (int i = 0; i < dataArrays.Count; i++)
133 {
134 Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length);
135 arraypos += dataArrays[i].Length;
136 }
137 Array.Copy(primend, 0, result, arraypos, primend.Length);
138
139 return result;
140 }
141
142 #region Overridden Methods
143
144 public override void update()
145 {
146 LLVector3 pos2 = new LLVector3(0, 0, 0);
147 }
148
149 public override void BackUp()
150 {
151
152 }
153
154 #endregion
155
156 #region Packet handlers
157
158 public void UpdatePosition(LLVector3 pos)
159 {
160
161 }
162
163 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
164 {
165 this.primData.PathBegin = addPacket.PathBegin;
166 this.primData.PathEnd = addPacket.PathEnd;
167 this.primData.PathScaleX = addPacket.PathScaleX;
168 this.primData.PathScaleY = addPacket.PathScaleY;
169 this.primData.PathShearX = addPacket.PathShearX;
170 this.primData.PathShearY = addPacket.PathShearY;
171 this.primData.PathSkew = addPacket.PathSkew;
172 this.primData.ProfileBegin = addPacket.ProfileBegin;
173 this.primData.ProfileEnd = addPacket.ProfileEnd;
174 this.primData.PathCurve = addPacket.PathCurve;
175 this.primData.ProfileCurve = addPacket.ProfileCurve;
176 this.primData.ProfileHollow = addPacket.ProfileHollow;
177 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
178 this.primData.PathRevolutions = addPacket.PathRevolutions;
179 this.primData.PathTaperX = addPacket.PathTaperX;
180 this.primData.PathTaperY = addPacket.PathTaperY;
181 this.primData.PathTwist = addPacket.PathTwist;
182 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
183 }
184
185 public void UpdateTexture(byte[] tex)
186 {
187 this.primData.Texture = tex;
188 //this.dirtyFlag = true;
189 }
190
191 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
192 {
193
194 }
195
196 public void AssignToParent(Primitive prim)
197 {
198
199 }
200
201 public void GetProperites(ClientView client)
202 {
203 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
204 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
205 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
206 proper.ObjectData[0].ItemID = LLUUID.Zero;
207 proper.ObjectData[0].CreationDate = (ulong)this.primData.CreationDate;
208 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
209 proper.ObjectData[0].FolderID = LLUUID.Zero;
210 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
211 proper.ObjectData[0].GroupID = LLUUID.Zero;
212 proper.ObjectData[0].InventorySerial = 0;
213 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
214 proper.ObjectData[0].ObjectID = this.uuid;
215 proper.ObjectData[0].OwnerID = primData.OwnerID;
216 proper.ObjectData[0].TouchName = new byte[0];
217 proper.ObjectData[0].TextureID = new byte[0];
218 proper.ObjectData[0].SitName = new byte[0];
219 proper.ObjectData[0].Name = new byte[0];
220 proper.ObjectData[0].Description = new byte[0];
221 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
222 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
223 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
224 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
225 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
226
227 client.OutPacket(proper);
228 }
229
230 #endregion
231
232 # region Inventory Methods
233
234 public bool AddToInventory(InventoryItem item)
235 {
236 return false;
237 }
238
239 public InventoryItem RemoveFromInventory(LLUUID itemID)
240 {
241 return null;
242 }
243
244 public void RequestInventoryInfo(ClientView simClient, RequestTaskInventoryPacket packet)
245 {
246
247 }
248
249 public void RequestXferInventory(ClientView simClient, ulong xferID)
250 {
251 //will only currently work if the total size of the inventory data array is under about 1000 bytes
252 SendXferPacketPacket send = new SendXferPacketPacket();
253
254 send.XferID.ID = xferID;
255 send.XferID.Packet = 1 + 2147483648;
256 send.DataPacket.Data = this.ConvertInventoryToBytes();
257
258 simClient.OutPacket(send);
259 }
260
261 public byte[] ConvertInventoryToBytes()
262 {
263 System.Text.Encoding enc = System.Text.Encoding.ASCII;
264 byte[] result = new byte[0];
265 List<byte[]> inventoryData = new List<byte[]>();
266 int totallength = 0;
267 foreach (InventoryItem invItem in inventoryItems.Values)
268 {
269 byte[] data = enc.GetBytes(invItem.ExportString());
270 inventoryData.Add(data);
271 totallength += data.Length;
272 }
273 //TODO: copy arrays into the single result array
274
275 return result;
276 }
277
278 public void CreateInventoryFromBytes(byte[] data)
279 {
280
281 }
282
283 #endregion
284
285 #region Update viewers Methods
286
287 //should change these mehtods, so that outgoing packets are sent through the avatar class
288 public void SendFullUpdateToClient(ClientView remoteClient)
289 {
290 LLVector3 lPos;
291 if (this._physActor != null && this.physicsEnabled)
292 {
293 PhysicsVector pPos = this._physActor.Position;
294 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
295 }
296 else
297 {
298 lPos = this.Pos;
299 }
300
301 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
302 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
303 outPacket.ObjectData[0] = this.CreateUpdateBlock();
304 byte[] pb = lPos.GetBytes();
305 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
306
307 remoteClient.OutPacket(outPacket);
308 }
309
310 public void SendFullUpdateToAllClients()
311 {
312
313 }
314
315 public void SendTerseUpdateToClient(ClientView RemoteClient)
316 {
317
318 }
319
320 public void SendTerseUpdateToALLClients()
321 {
322
323 }
324
325 #endregion
326
327 #region Create Methods
328
329 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
330 {
331 PrimData PData = new PrimData();
332 this.primData = PData;
333 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
334
335 PData.OwnerID = ownerID;
336 PData.PCode = addPacket.ObjectData.PCode;
337 PData.PathBegin = addPacket.ObjectData.PathBegin;
338 PData.PathEnd = addPacket.ObjectData.PathEnd;
339 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
340 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
341 PData.PathShearX = addPacket.ObjectData.PathShearX;
342 PData.PathShearY = addPacket.ObjectData.PathShearY;
343 PData.PathSkew = addPacket.ObjectData.PathSkew;
344 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
345 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
346 PData.Scale = addPacket.ObjectData.Scale;
347 PData.PathCurve = addPacket.ObjectData.PathCurve;
348 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
349 PData.ParentID = 0;
350 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
351 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
352 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
353 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
354 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
355 PData.PathTwist = addPacket.ObjectData.PathTwist;
356 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
357 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
358 this.primData.FullID = this.uuid = LLUUID.Random();
359 this.localid = (uint)(localID);
360 this.primData.Position = this.Pos = pos1;
361 }
362
363 public void CreateFromBytes(byte[] data)
364 {
365
366 }
367
368 public void CreateFromPrimData(PrimData primData)
369 {
370 this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false);
371 }
372
373 public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim)
374 {
375
376 }
377
378 #endregion
379
380 #region Packet Update Methods
381 protected void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
382 {
383 objdata.PSBlock = new byte[0];
384 objdata.ExtraParams = new byte[1];
385 objdata.MediaURL = new byte[0];
386 objdata.NameValue = new byte[0];
387 objdata.Text = new byte[0];
388 objdata.TextColor = new byte[4];
389 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
390 objdata.JointPivot = new LLVector3(0, 0, 0);
391 objdata.Material = 3;
392 objdata.TextureAnim = new byte[0];
393 objdata.Sound = LLUUID.Zero;
394 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
395 this.primData.Texture = objdata.TextureEntry = ntex.ToBytes();
396 objdata.State = 0;
397 objdata.Data = new byte[0];
398
399 objdata.ObjectData = new byte[60];
400 objdata.ObjectData[46] = 128;
401 objdata.ObjectData[47] = 63;
402 }
403
404 protected void SetPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData)
405 {
406 objectData.OwnerID = this.primData.OwnerID;
407 objectData.PCode = this.primData.PCode;
408 objectData.PathBegin = this.primData.PathBegin;
409 objectData.PathEnd = this.primData.PathEnd;
410 objectData.PathScaleX = this.primData.PathScaleX;
411 objectData.PathScaleY = this.primData.PathScaleY;
412 objectData.PathShearX = this.primData.PathShearX;
413 objectData.PathShearY = this.primData.PathShearY;
414 objectData.PathSkew = this.primData.PathSkew;
415 objectData.ProfileBegin = this.primData.ProfileBegin;
416 objectData.ProfileEnd = this.primData.ProfileEnd;
417 objectData.Scale = this.primData.Scale;
418 objectData.PathCurve = this.primData.PathCurve;
419 objectData.ProfileCurve = this.primData.ProfileCurve;
420 objectData.ParentID = this.primData.ParentID;
421 objectData.ProfileHollow = this.primData.ProfileHollow;
422 objectData.PathRadiusOffset = this.primData.PathRadiusOffset;
423 objectData.PathRevolutions = this.primData.PathRevolutions;
424 objectData.PathTaperX = this.primData.PathTaperX;
425 objectData.PathTaperY = this.primData.PathTaperY;
426 objectData.PathTwist = this.primData.PathTwist;
427 objectData.PathTwistBegin = this.primData.PathTwistBegin;
428 }
429
430 #endregion
431 protected ObjectUpdatePacket.ObjectDataBlock CreateUpdateBlock()
432 {
433 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
434 this.SetDefaultPacketValues(objupdate);
435 objupdate.UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
436 this.SetPacketShapeData(objupdate);
437 byte[] pb = this.Pos.GetBytes();
438 Array.Copy(pb, 0, objupdate.ObjectData, 0, pb.Length);
439 return objupdate;
440 }
441
442 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
443 {
444 uint ID = this.localid;
445 byte[] bytes = new byte[60];
446
447 int i = 0;
448 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
449 dat.TextureEntry = new byte[0];
450 bytes[i++] = (byte)(ID % 256);
451 bytes[i++] = (byte)((ID >> 8) % 256);
452 bytes[i++] = (byte)((ID >> 16) % 256);
453 bytes[i++] = (byte)((ID >> 24) % 256);
454 bytes[i++] = 0;
455 bytes[i++] = 0;
456
457 LLVector3 lPos;
458 Axiom.MathLib.Quaternion lRot;
459 if (this._physActor != null && this.physicsEnabled)
460 {
461 PhysicsVector pPos = this._physActor.Position;
462 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
463 lRot = this._physActor.Orientation;
464 }
465 else
466 {
467 lPos = this.Pos;
468 lRot = this.rotation;
469 }
470 byte[] pb = lPos.GetBytes();
471 Array.Copy(pb, 0, bytes, i, pb.Length);
472 i += 12;
473 ushort ac = 32767;
474
475 //vel
476 bytes[i++] = (byte)(ac % 256);
477 bytes[i++] = (byte)((ac >> 8) % 256);
478 bytes[i++] = (byte)(ac % 256);
479 bytes[i++] = (byte)((ac >> 8) % 256);
480 bytes[i++] = (byte)(ac % 256);
481 bytes[i++] = (byte)((ac >> 8) % 256);
482
483 //accel
484 bytes[i++] = (byte)(ac % 256);
485 bytes[i++] = (byte)((ac >> 8) % 256);
486 bytes[i++] = (byte)(ac % 256);
487 bytes[i++] = (byte)((ac >> 8) % 256);
488 bytes[i++] = (byte)(ac % 256);
489 bytes[i++] = (byte)((ac >> 8) % 256);
490
491 ushort rw, rx, ry, rz;
492 rw = (ushort)(32768 * (lRot.w + 1));
493 rx = (ushort)(32768 * (lRot.x + 1));
494 ry = (ushort)(32768 * (lRot.y + 1));
495 rz = (ushort)(32768 * (lRot.z + 1));
496
497 //rot
498 bytes[i++] = (byte)(rx % 256);
499 bytes[i++] = (byte)((rx >> 8) % 256);
500 bytes[i++] = (byte)(ry % 256);
501 bytes[i++] = (byte)((ry >> 8) % 256);
502 bytes[i++] = (byte)(rz % 256);
503 bytes[i++] = (byte)((rz >> 8) % 256);
504 bytes[i++] = (byte)(rw % 256);
505 bytes[i++] = (byte)((rw >> 8) % 256);
506
507 //rotation vel
508 bytes[i++] = (byte)(ac % 256);
509 bytes[i++] = (byte)((ac >> 8) % 256);
510 bytes[i++] = (byte)(ac % 256);
511 bytes[i++] = (byte)((ac >> 8) % 256);
512 bytes[i++] = (byte)(ac % 256);
513 bytes[i++] = (byte)((ac >> 8) % 256);
514
515 dat.Data = bytes;
516 return dat;
517 }
518 }
519}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/SceneObject.cs b/OpenSim/OpenSim.RegionServer/Simulator/SceneObject.cs
new file mode 100644
index 0000000..1ef91c9
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/SceneObject.cs
@@ -0,0 +1,105 @@
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 System.Text;
31using OpenSim.RegionServer.Types;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Physics.Manager;
36using OpenSim.Framework.Types;
37using OpenSim.Framework.Inventory;
38using OpenSim.RegionServer.Client;
39
40namespace OpenSim.RegionServer.Simulator
41{
42 public class SceneObject : Entity
43 {
44 private LLUUID rootUUID;
45 private Dictionary<LLUUID, Primitive2> ChildPrimitives = new Dictionary<LLUUID, Primitive2>();
46 private Dictionary<uint, ClientView> m_clientThreads;
47 private World m_world;
48
49 public SceneObject()
50 {
51
52 }
53
54 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
55 {
56 }
57
58 public void CreateFromBytes(byte[] data)
59 {
60
61 }
62
63 public override void update()
64 {
65
66 }
67
68 public override void BackUp()
69 {
70
71 }
72
73 public void GetProperites(ClientView client)
74 {
75 /*
76 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
77 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
78 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
79 proper.ObjectData[0].ItemID = LLUUID.Zero;
80 proper.ObjectData[0].CreationDate = (ulong)this.primData.CreationDate;
81 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
82 proper.ObjectData[0].FolderID = LLUUID.Zero;
83 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
84 proper.ObjectData[0].GroupID = LLUUID.Zero;
85 proper.ObjectData[0].InventorySerial = 0;
86 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
87 proper.ObjectData[0].ObjectID = this.uuid;
88 proper.ObjectData[0].OwnerID = primData.OwnerID;
89 proper.ObjectData[0].TouchName = new byte[0];
90 proper.ObjectData[0].TextureID = new byte[0];
91 proper.ObjectData[0].SitName = new byte[0];
92 proper.ObjectData[0].Name = new byte[0];
93 proper.ObjectData[0].Description = new byte[0];
94 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
95 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
96 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
97 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
98 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
99
100 client.OutPacket(proper);
101 * */
102 }
103
104 }
105}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/World.PacketHandlers.cs b/OpenSim/OpenSim.RegionServer/Simulator/World.PacketHandlers.cs
new file mode 100644
index 0000000..2c5a05f
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/World.PacketHandlers.cs
@@ -0,0 +1,449 @@
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 System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Physics.Manager;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using OpenSim.Framework.Terrain;
37using OpenSim.Framework.Inventory;
38using OpenSim.Framework.Utilities;
39using OpenSim.RegionServer.Assets;
40using OpenSim.RegionServer.Client;
41
42namespace OpenSim.RegionServer.Simulator
43{
44 public partial class World
45 {
46 public void ModifyTerrain(byte action, float north, float west)
47 {
48 switch (action)
49 {
50 case 1:
51 // raise terrain
52 Terrain.raise(north, west, 10.0, 0.001);
53 RegenerateTerrain(true, (int)north, (int)west);
54 break;
55 case 2:
56 //lower terrain
57 Terrain.lower(north, west, 10.0, 0.001);
58 RegenerateTerrain(true, (int)north, (int)west);
59 break;
60 }
61 return;
62 }
63
64 public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
65 {
66 foreach (ClientView client in m_clientThreads.Values)
67 {
68 // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
69 int dis = (int)client.ClientAvatar.Pos.GetDistanceTo(fromPos);
70
71 switch (type)
72 {
73 case 0: // Whisper
74 if ((dis < 10) && (dis > -10))
75 {
76 //should change so the message is sent through the avatar rather than direct to the ClientView
77 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
78 }
79 break;
80 case 1: // Say
81 if ((dis < 30) && (dis > -30))
82 {
83 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
84 }
85 break;
86 case 2: // Shout
87 if ((dis < 100) && (dis > -100))
88 {
89 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
90 }
91 break;
92
93 case 0xff: // Broadcast
94 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
95 break;
96 }
97
98 }
99 }
100
101 public void RezObject(AssetBase primAsset, LLVector3 pos)
102 {
103 PrimData primd = new PrimData(primAsset.Data);
104 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
105 nPrim.CreateFromStorage(primd, pos, this._primCount, true);
106 this.Entities.Add(nPrim.uuid, nPrim);
107 this._primCount++;
108 }
109
110 public void DeRezObject(Packet packet, ClientView simClient)
111 {
112 DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet;
113
114 //Needs to delete object from physics at a later date
115 if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
116 {
117 //currently following code not used (or don't know of any case of destination being zero
118 libsecondlife.LLUUID[] DeRezEnts;
119 DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length];
120 int i = 0;
121 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
122 {
123
124 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
125 foreach (Entity ent in this.Entities.Values)
126 {
127 if (ent.localid == Data.ObjectLocalID)
128 {
129 DeRezEnts[i++] = ent.uuid;
130 this.localStorage.RemovePrim(ent.uuid);
131 KillObjectPacket kill = new KillObjectPacket();
132 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
133 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
134 kill.ObjectData[0].ID = ent.localid;
135 foreach (ClientView client in m_clientThreads.Values)
136 {
137 client.OutPacket(kill);
138 }
139 //Uncommenting this means an old UUID will be re-used, thus crashing the asset server
140 //Uncomment when prim/object UUIDs are random or such
141 //2007-03-22 - Randomskk
142 //this._primCount--;
143 OpenSim.Framework.Console.MainConsole.Instance.Verbose("Deleted UUID " + ent.uuid);
144 }
145 }
146 }
147 foreach (libsecondlife.LLUUID uuid in DeRezEnts)
148 {
149 lock (Entities)
150 {
151 Entities.Remove(uuid);
152 }
153 }
154 }
155 else
156 {
157 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
158 {
159 Entity selectedEnt = null;
160 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
161 foreach (Entity ent in this.Entities.Values)
162 {
163 if (ent.localid == Data.ObjectLocalID)
164 {
165 AssetBase primAsset = new AssetBase();
166 primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid
167 primAsset.InvType = 6;
168 primAsset.Type = 6;
169 primAsset.Name = "Prim";
170 primAsset.Description = "";
171 primAsset.Data = ((Primitive)ent).GetByteArray();
172 this._assetCache.AddAsset(primAsset);
173 this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset);
174 selectedEnt = ent;
175 break;
176 }
177 }
178 if (selectedEnt != null)
179 {
180 this.localStorage.RemovePrim(selectedEnt.uuid);
181 KillObjectPacket kill = new KillObjectPacket();
182 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
183 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
184 kill.ObjectData[0].ID = selectedEnt.localid;
185 foreach (ClientView client in m_clientThreads.Values)
186 {
187 client.OutPacket(kill);
188 }
189 lock (Entities)
190 {
191 Entities.Remove(selectedEnt.uuid);
192 }
193 }
194 }
195 }
196
197 }
198
199 public void SendAvatarsToClient(ClientView remoteClient)
200 {
201 foreach (ClientView client in m_clientThreads.Values)
202 {
203 if (client.AgentID != remoteClient.AgentID)
204 {
205 // ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket();
206 // RemoteClient.OutPacket(objupdate);
207 client.ClientAvatar.SendUpdateToOtherClient(remoteClient.ClientAvatar);
208 client.ClientAvatar.SendAppearanceToOtherAgent(remoteClient.ClientAvatar);
209 }
210 }
211 }
212
213 public void LinkObjects(uint parentPrim, List<uint> childPrims)
214 {
215 Primitive parentprim = null;
216 foreach (Entity ent in Entities.Values)
217 {
218 if (ent.localid == parentPrim)
219 {
220 parentprim = (OpenSim.RegionServer.Simulator.Primitive)ent;
221
222 }
223 }
224
225 for (int i = 0; i < childPrims.Count; i++)
226 {
227 uint childId = childPrims[i];
228 foreach (Entity ent in Entities.Values)
229 {
230 if (ent.localid == childId)
231 {
232 ((OpenSim.RegionServer.Simulator.Primitive)ent).MakeParent(parentprim);
233 }
234 }
235 }
236
237 }
238
239 public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
240 {
241 foreach (Entity ent in Entities.Values)
242 {
243 if (ent.localid == primLocalID)
244 {
245 ((OpenSim.RegionServer.Simulator.Primitive)ent).UpdateShape(shapeBlock);
246 break;
247 }
248 }
249 }
250
251 public void SelectPrim(uint primLocalID, ClientView remoteClient)
252 {
253 foreach (Entity ent in Entities.Values)
254 {
255 if (ent.localid == primLocalID)
256 {
257 ((OpenSim.RegionServer.Simulator.Primitive)ent).GetProperites(remoteClient);
258 break;
259 }
260 }
261 }
262
263 public void UpdatePrimFlags(uint localID, Packet packet, ClientView remoteClient)
264 {
265 foreach (Entity ent in Entities.Values)
266 {
267 if (ent.localid == localID)
268 {
269 ((OpenSim.RegionServer.Simulator.Primitive)ent).UpdateObjectFlags((ObjectFlagUpdatePacket) packet);
270 break;
271 }
272 }
273 }
274
275 public void UpdatePrimTexture(uint localID, byte[] texture, ClientView remoteClient)
276 {
277 foreach (Entity ent in Entities.Values)
278 {
279 if (ent.localid == localID)
280 {
281 ((OpenSim.RegionServer.Simulator.Primitive)ent).UpdateTexture(texture);
282 break;
283 }
284 }
285 }
286
287 public void UpdatePrimPosition(uint localID, LLVector3 pos, ClientView remoteClient)
288 {
289 foreach (Entity ent in Entities.Values)
290 {
291 if (ent.localid == localID)
292 {
293 ((OpenSim.RegionServer.Simulator.Primitive)ent).UpdatePosition(pos);
294 break;
295 }
296 }
297 }
298
299 public void UpdatePrimRotation(uint localID, LLQuaternion rot, ClientView remoteClient)
300 {
301 foreach (Entity ent in Entities.Values)
302 {
303 if (ent.localid == localID)
304 {
305 ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
306 ((OpenSim.RegionServer.Simulator.Primitive)ent).UpdateFlag = true;
307 break;
308 }
309 }
310 }
311
312 public void UpdatePrimScale(uint localID, LLVector3 scale, ClientView remoteClient)
313 {
314 foreach (Entity ent in Entities.Values)
315 {
316 if (ent.localid == localID)
317 {
318 ((OpenSim.RegionServer.Simulator.Primitive)ent).Scale = scale;
319 break;
320 }
321 }
322 }
323 #region Parcel Packet Handlers
324 void ParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, ClientView remote_client)
325 {
326 //Get the parcels within the bounds
327 List<OpenSim.RegionServer.Simulator.Parcel> temp = new List<OpenSim.RegionServer.Simulator.Parcel>();
328 int x, y, i;
329 int inc_x = end_x - start_x;
330 int inc_y = end_y - start_y;
331 for(x = 0; x < inc_x; x++)
332 {
333 for(y = 0; y < inc_y; y++)
334 {
335 OpenSim.RegionServer.Simulator.Parcel currentParcel = parcelManager.getParcel(start_x + x, start_y + y);
336 if(!temp.Contains(currentParcel))
337 {
338 currentParcel.
339 forceUpdateParcelInfo();
340 temp.Add(currentParcel);
341 }
342 }
343 }
344
345 int requestResult = OpenSim.RegionServer.Simulator.ParcelManager.PARCEL_RESULT_ONE_PARCEL;
346 if (temp.Count > 1)
347 {
348 requestResult = OpenSim.RegionServer.Simulator.ParcelManager.PARCEL_RESULT_MULTIPLE_PARCELS;
349 }
350
351 for (i = 0; i < temp.Count; i++)
352 {
353 temp[i].sendParcelProperties(sequence_id, snap_selection, requestResult, remote_client);
354 }
355
356
357 parcelManager.sendParcelOverlay(remote_client);
358 }
359
360 void ParcelDivideRequest(int west, int south, int east, int north, ClientView remote_client)
361 {
362 parcelManager.subdivide(west, south, east, north, remote_client.AgentID);
363 }
364 void ParcelJoinRequest(int west, int south, int east, int north, ClientView remote_client)
365 {
366 parcelManager.join(west, south, east, north, remote_client.AgentID);
367 }
368 void ParcelPropertiesUpdateRequest(ParcelPropertiesUpdatePacket packet, ClientView remote_client)
369 {
370 if (parcelManager.parcelList.ContainsKey(packet.ParcelData.LocalID))
371 {
372 parcelManager.parcelList[packet.ParcelData.LocalID].updateParcelProperties(packet, remote_client);
373 }
374 }
375 #endregion
376
377 /*
378 public void RequestMapBlock(ClientView simClient, int minX, int minY, int maxX, int maxY)
379 {
380 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
381 if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY)))
382 {
383 MapBlockReplyPacket mapReply = new MapBlockReplyPacket();
384 mapReply.AgentData.AgentID = simClient.AgentID;
385 mapReply.AgentData.Flags = 0;
386 mapReply.Data = new MapBlockReplyPacket.DataBlock[1];
387 mapReply.Data[0] = new MapBlockReplyPacket.DataBlock();
388 mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007");
389 mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX;
390 mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY;
391 mapReply.Data[0].WaterHeight = (byte)m_regInfo.RegionWaterHeight;
392 mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName);
393 mapReply.Data[0].RegionFlags = 72458694;
394 mapReply.Data[0].Access = 13;
395 mapReply.Data[0].Agents = 1; //should send number of clients connected
396 simClient.OutPacket(mapReply);
397 }
398 }
399 public bool RezObjectHandler(ClientView simClient, Packet packet)
400 {
401 RezObjectPacket rezPacket = (RezObjectPacket)packet;
402 AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID);
403 if (inven != null)
404 {
405 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
406 {
407 AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
408 if (asset != null)
409 {
410 PrimData primd = new PrimData(asset.Data);
411 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
412 nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true);
413 this.Entities.Add(nPrim.uuid, nPrim);
414 this._primCount++;
415 this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID);
416 }
417 }
418 }
419 return true;
420 }
421 public bool ModifyTerrain(ClientView simClient, Packet packet)
422 {
423 ModifyLandPacket modify = (ModifyLandPacket)packet;
424
425 switch (modify.ModifyBlock.Action)
426 {
427 case 1:
428 // raise terrain
429 if (modify.ParcelData.Length > 0)
430 {
431 Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
432 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
433 }
434 break;
435 case 2:
436 //lower terrain
437 if (modify.ParcelData.Length > 0)
438 {
439 Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
440 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
441 }
442 break;
443 }
444 return true;
445 }
446 */
447
448 }
449}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs b/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs
new file mode 100644
index 0000000..747730c
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/World.Scripting.cs
@@ -0,0 +1,151 @@
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 System.Text;
31using System.IO;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using libsecondlife;
37
38namespace OpenSim.RegionServer.Simulator
39{
40 public partial class World
41 {
42 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
43
44 private void LoadScriptEngines()
45 {
46 this.LoadScriptPlugins();
47 }
48
49 public void LoadScriptPlugins()
50 {
51 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
52 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
53
54
55 for (int i = 0; i < pluginFiles.Length; i++)
56 {
57 this.AddPlugin(pluginFiles[i]);
58 }
59 }
60
61 private void AddPlugin(string FileName)
62 {
63 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
64
65 foreach (Type pluginType in pluginAssembly.GetTypes())
66 {
67 if (pluginType.IsPublic)
68 {
69 if (!pluginType.IsAbstract)
70 {
71 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
72
73 if (typeInterface != null)
74 {
75 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
76 plug.Init(this);
77 this.scriptEngines.Add(plug.GetName(), plug);
78
79 }
80
81 typeInterface = null;
82 }
83 }
84 }
85
86 pluginAssembly = null;
87 }
88
89 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
90 {
91 if(this.scriptEngines.ContainsKey(scriptType))
92 {
93 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
94 }
95 }
96
97 #region IScriptAPI Methods
98
99 public OSVector3 GetEntityPosition(uint localID)
100 {
101 OSVector3 res = new OSVector3();
102 // Console.WriteLine("script- getting entity " + localID + " position");
103 foreach (Entity entity in this.Entities.Values)
104 {
105 if (entity.localid == localID)
106 {
107 res.X = entity.Pos.X;
108 res.Y = entity.Pos.Y;
109 res.Z = entity.Pos.Z;
110 }
111 }
112 return res;
113 }
114
115 public void SetEntityPosition(uint localID, float x , float y, float z)
116 {
117 foreach (Entity entity in this.Entities.Values)
118 {
119 if (entity.localid == localID && entity is Primitive)
120 {
121 LLVector3 pos = entity.Pos;
122 pos.X = x;
123 pos.Y = y;
124 Primitive prim = entity as Primitive;
125 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
126 prim.UpdatePosition(pos);
127 // Console.WriteLine("script- setting entity " + localID + " positon");
128 }
129 }
130
131 }
132
133 public uint GetRandomAvatarID()
134 {
135 //Console.WriteLine("script- getting random avatar id");
136 uint res = 0;
137 foreach (Entity entity in this.Entities.Values)
138 {
139 if (entity is Avatar)
140 {
141 res = entity.localid;
142 }
143 }
144 return res;
145 }
146
147 #endregion
148
149
150 }
151}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/World.cs b/OpenSim/OpenSim.RegionServer/Simulator/World.cs
new file mode 100644
index 0000000..150a092
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/World.cs
@@ -0,0 +1,736 @@
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;
30using libsecondlife.Packets;
31using System.Collections.Generic;
32using System.Text;
33using System.Reflection;
34using System.IO;
35using System.Threading;
36using OpenSim.Physics.Manager;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Types;
39using OpenSim.Framework.Terrain;
40using OpenSim.Framework.Inventory;
41using OpenSim.RegionServer.Assets;
42
43using OpenSim.RegionServer.Scripting;
44using OpenSim.Terrain;
45using OpenSim.Framework.Console;
46using OpenSim.RegionServer.Client;
47
48
49namespace OpenSim.RegionServer.Simulator
50{
51 public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI
52 {
53 public object LockPhysicsEngine = new object();
54 public Dictionary<libsecondlife.LLUUID, Avatar> Avatars;
55 public Dictionary<libsecondlife.LLUUID, Primitive> Prims;
56 //public ScriptEngine Scripts;
57 public uint _localNumber = 0;
58 private PhysicsScene phyScene;
59 private float timeStep = 0.1f;
60 public ILocalStorage localStorage;
61 private Random Rand = new Random();
62 private uint _primCount = 702000;
63 private int storageCount;
64 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
65 private Dictionary<string, ScriptFactory> m_scripts;
66 private Mutex updateLock;
67 public string m_datastore;
68 public OpenSim.RegionServer.Simulator.ParcelManager parcelManager;
69
70 #region Properties
71 public PhysicsScene PhysScene
72 {
73 set
74 {
75 this.phyScene = value;
76 }
77 get
78 {
79 return (this.phyScene);
80 }
81 }
82 #endregion
83
84 #region Constructors
85 /// <summary>
86 /// Creates a new World class, and a region to go with it.
87 /// </summary>
88 /// <param name="clientThreads">Dictionary to contain client threads</param>
89 /// <param name="regionHandle">Region Handle for this region</param>
90 /// <param name="regionName">Region Name for this region</param>
91 public World(Dictionary<uint, ClientView> clientThreads, RegionInfo regInfo, ulong regionHandle, string regionName)
92 {
93 try
94 {
95 updateLock = new Mutex(false);
96 m_clientThreads = clientThreads;
97 m_regionHandle = regionHandle;
98 m_regionName = regionName;
99 m_regInfo = regInfo;
100
101 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
102 m_scripts = new Dictionary<string, ScriptFactory>();
103
104 MainConsole.Instance.Notice("World.cs - creating new entitities instance");
105 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
106 Avatars = new Dictionary<LLUUID, Avatar>();
107 Prims = new Dictionary<LLUUID, Primitive>();
108
109 MainConsole.Instance.Notice("World.cs - creating LandMap");
110 TerrainManager = new TerrainManager(new SecondLife());
111 Terrain = new TerrainEngine();
112 Avatar.SetupTemplate("avatar-texture.dat");
113 // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
114 // Initialise this only after the world has loaded
115 // Scripts = new ScriptEngine(this);
116 Avatar.LoadAnims();
117 this.SetDefaultScripts();
118 this.LoadScriptEngines();
119
120 }
121 catch (Exception e)
122 {
123 OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Constructor failed with exception " + e.ToString());
124 }
125 }
126 #endregion
127
128 #region Script Methods
129 /// <summary>
130 /// Loads a new script into the specified entity
131 /// </summary>
132 /// <param name="entity">Entity to be scripted</param>
133 /// <param name="script">The script to load</param>
134 public void AddScript(Entity entity, Script script)
135 {
136 try
137 {
138 ScriptHandler scriptHandler = new ScriptHandler(script, entity, this);
139 m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler);
140 }
141 catch (Exception e)
142 {
143 MainConsole.Instance.Warn("World.cs: AddScript() - Failed with exception " + e.ToString());
144 }
145 }
146
147 /// <summary>
148 /// Loads a new script into the specified entity, using a script loaded from a string.
149 /// </summary>
150 /// <param name="entity">The entity to be scripted</param>
151 /// <param name="scriptData">The string containing the script</param>
152 public void AddScript(Entity entity, string scriptData)
153 {
154 try
155 {
156 int scriptstart = 0;
157 int scriptend = 0;
158 string substring;
159 scriptstart = scriptData.LastIndexOf("<Script>");
160 scriptend = scriptData.LastIndexOf("</Script>");
161 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
162 substring = substring.Trim();
163 //Console.WriteLine("searching for script to add: " + substring);
164
165 ScriptFactory scriptFactory;
166 //Console.WriteLine("script string is " + substring);
167 if (substring.StartsWith("<ScriptEngine:"))
168 {
169 string substring1 = "";
170 string script = "";
171 // Console.WriteLine("searching for script engine");
172 substring1 = substring.Remove(0, 14);
173 int dev = substring1.IndexOf(',');
174 string sEngine = substring1.Substring(0, dev);
175 substring1 = substring1.Remove(0, dev + 1);
176 int end = substring1.IndexOf('>');
177 string sName = substring1.Substring(0, end);
178 //Console.WriteLine(" script info : " + sEngine + " , " + sName);
179 int startscript = substring.IndexOf('>');
180 script = substring.Remove(0, startscript + 1);
181 // Console.WriteLine("script data is " + script);
182 if (this.scriptEngines.ContainsKey(sEngine))
183 {
184 this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid);
185 }
186 }
187 else if (this.m_scripts.TryGetValue(substring, out scriptFactory))
188 {
189 //Console.WriteLine("added script");
190 this.AddScript(entity, scriptFactory());
191 }
192 }
193 catch (Exception e)
194 {
195 MainConsole.Instance.Warn("World.cs: AddScript() - Failed with exception " + e.ToString());
196 }
197 }
198
199 #endregion
200
201 #region Update Methods
202 /// <summary>
203 /// Performs per-frame updates on the world, this should be the central world loop
204 /// </summary>
205 public override void Update()
206 {
207 updateLock.WaitOne();
208 try
209 {
210 if (this.phyScene.IsThreaded)
211 {
212 this.phyScene.GetResults();
213
214 }
215
216 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
217 {
218 Entities[UUID].addForces();
219 }
220
221 lock (this.LockPhysicsEngine)
222 {
223 this.phyScene.Simulate(timeStep);
224 }
225
226 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
227 {
228 Entities[UUID].update();
229 }
230
231 foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
232 {
233 scriptHandler.OnFrame();
234 }
235 foreach (IScriptEngine scripteng in this.scriptEngines.Values)
236 {
237 scripteng.OnFrame();
238 }
239 //backup world data
240 this.storageCount++;
241 if (storageCount > 1200) //set to how often you want to backup
242 {
243 this.Backup();
244 storageCount = 0;
245 }
246 }
247 catch (Exception e)
248 {
249 MainConsole.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString());
250 }
251 updateLock.ReleaseMutex();
252 }
253
254 public bool Backup()
255 {
256 try
257 {
258 // Terrain backup routines
259 if (Terrain.tainted > 0)
260 {
261 Terrain.tainted = 0;
262 MainConsole.Instance.Notice("World.cs: Backup() - Terrain tainted, saving.");
263 localStorage.SaveMap(Terrain.getHeights1D());
264 MainConsole.Instance.Notice("World.cs: Backup() - Rebuilding world map image.");
265 Terrain.exportImage("map_" + m_regInfo.RegionName.ToLower() + ".png", "defaultstripe.png");
266 MainConsole.Instance.Notice("World.cs: Backup() - Terrain saved, informing Physics.");
267 phyScene.SetTerrain(Terrain.getHeights1D());
268
269 // Needs optimising to just send patches which have changed.
270 MainConsole.Instance.Notice("World.cs: Backup() - Terrain changed, informing Clients.");
271 foreach (ClientView client in m_clientThreads.Values)
272 {
273 this.SendLayerData(client);
274 }
275 }
276
277 // Primitive backup routines -- should only do if there's been a change.
278 MainConsole.Instance.Notice("World.cs: Backup() - Backing up Primitives");
279 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
280 {
281 Entities[UUID].BackUp();
282 }
283
284
285 //Parcel backup routines. Yay!
286 ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count];
287 int i = 0;
288 foreach(OpenSim.RegionServer.Simulator.Parcel parcel in parcelManager.parcelList.Values)
289 {
290 parcels[i] = parcel.parcelData;
291 i++;
292 }
293 localStorage.SaveParcels(parcels);
294
295
296 // Backup successful
297 return true;
298 }
299 catch (Exception e)
300 {
301 // Backup failed
302 OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Backup() - Backup Failed with exception " + e.ToString());
303 return false;
304 }
305 }
306 #endregion
307
308 #region Setup Methods
309 /// <summary>
310 /// Loads a new storage subsystem from a named library
311 /// </summary>
312 /// <param name="dllName">Storage Library</param>
313 /// <returns>Successful or not</returns>
314 public bool LoadStorageDLL(string dllName)
315 {
316 try
317 {
318 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
319 ILocalStorage store = null;
320
321 foreach (Type pluginType in pluginAssembly.GetTypes())
322 {
323 if (pluginType.IsPublic)
324 {
325 if (!pluginType.IsAbstract)
326 {
327 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
328
329 if (typeInterface != null)
330 {
331 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
332 store = plug;
333
334 store.Initialise(this.m_datastore);
335 break;
336 }
337
338 typeInterface = null;
339 }
340 }
341 }
342 pluginAssembly = null;
343 this.localStorage = store;
344 return (store == null);
345 }
346 catch (Exception e)
347 {
348 MainConsole.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
349 return false;
350 }
351 }
352
353 public void SetDefaultScripts()
354 {
355 this.m_scripts.Add("FollowRandomAvatar", delegate()
356 {
357 return new OpenSim.RegionServer.Scripting.FollowRandomAvatar();
358 });
359 }
360
361 #endregion
362
363 #region Regenerate Terrain
364
365 /// <summary>
366 /// Rebuilds the terrain using a procedural algorithm
367 /// </summary>
368 public void RegenerateTerrain()
369 {
370 try
371 {
372 Terrain.hills();
373
374 lock (this.LockPhysicsEngine)
375 {
376 this.phyScene.SetTerrain(Terrain.getHeights1D());
377 }
378 this.localStorage.SaveMap(this.Terrain.getHeights1D());
379
380 foreach (ClientView client in m_clientThreads.Values)
381 {
382 this.SendLayerData(client);
383 }
384
385 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
386 {
387 Entities[UUID].LandRenegerated();
388 }
389 }
390 catch (Exception e)
391 {
392 MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
393 }
394 }
395
396 /// <summary>
397 /// Rebuilds the terrain using a 2D float array
398 /// </summary>
399 /// <param name="newMap">256,256 float array containing heights</param>
400 public void RegenerateTerrain(float[,] newMap)
401 {
402 try
403 {
404 this.Terrain.setHeights2D(newMap);
405 lock (this.LockPhysicsEngine)
406 {
407 this.phyScene.SetTerrain(this.Terrain.getHeights1D());
408 }
409 this.localStorage.SaveMap(this.Terrain.getHeights1D());
410
411 foreach (ClientView client in m_clientThreads.Values)
412 {
413 this.SendLayerData(client);
414 }
415
416 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
417 {
418 Entities[UUID].LandRenegerated();
419 }
420 }
421 catch (Exception e)
422 {
423 MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
424 }
425 }
426
427 /// <summary>
428 /// Rebuilds the terrain assuming changes occured at a specified point[?]
429 /// </summary>
430 /// <param name="changes">???</param>
431 /// <param name="pointx">???</param>
432 /// <param name="pointy">???</param>
433 public void RegenerateTerrain(bool changes, int pointx, int pointy)
434 {
435 try
436 {
437 if (changes)
438 {
439 /* Dont save here, rely on tainting system instead */
440
441 foreach (ClientView client in m_clientThreads.Values)
442 {
443 this.SendLayerData(pointx, pointy, client);
444 }
445 }
446 }
447 catch (Exception e)
448 {
449 MainConsole.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
450 }
451 }
452
453 #endregion
454
455 #region Load Terrain
456 /// <summary>
457 /// Loads the World heightmap
458 /// </summary>
459 public override void LoadWorldMap()
460 {
461 try
462 {
463 float[] map = this.localStorage.LoadWorld();
464 if (map == null)
465 {
466 if (string.IsNullOrEmpty(this.m_regInfo.TerrainFile))
467 {
468 Console.WriteLine("No default terrain, procedurally generating...");
469 this.Terrain.hills();
470
471 this.localStorage.SaveMap(this.Terrain.getHeights1D());
472 }
473 else
474 {
475 try
476 {
477 this.Terrain.loadFromFileF32(this.m_regInfo.TerrainFile);
478 this.Terrain *= this.m_regInfo.TerrainMultiplier;
479 }
480 catch (Exception e)
481 {
482 Console.WriteLine("Unable to load default terrain, procedurally generating instead...");
483 Terrain.hills();
484 }
485 this.localStorage.SaveMap(this.Terrain.getHeights1D());
486 }
487 }
488 else
489 {
490 this.Terrain.setHeights1D(map);
491 }
492 }
493 catch (Exception e)
494 {
495 MainConsole.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
496 }
497 }
498 #endregion
499
500 #region Primitives Methods
501
502 /// <summary>
503 /// Sends prims to a client
504 /// </summary>
505 /// <param name="RemoteClient">Client to send to</param>
506 public void GetInitialPrims(ClientView RemoteClient)
507 {
508 try
509 {
510 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
511 {
512 if (Entities[UUID] is Primitive)
513 {
514 Primitive primitive = Entities[UUID] as Primitive;
515 primitive.UpdateClient(RemoteClient);
516 }
517 }
518 }
519 catch (Exception e)
520 {
521 MainConsole.Instance.Warn("World.cs: GetInitialPrims() - Failed with exception " + e.ToString());
522 }
523 }
524
525 /// <summary>
526 /// Loads the World's objects
527 /// </summary>
528 public void LoadPrimsFromStorage()
529 {
530 try
531 {
532 MainConsole.Instance.Notice("World.cs: LoadPrimsFromStorage() - Loading primitives");
533 this.localStorage.LoadPrimitives(this);
534 }
535 catch (Exception e)
536 {
537 MainConsole.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
538 }
539 }
540
541 /// <summary>
542 /// Loads a specific object from storage
543 /// </summary>
544 /// <param name="prim">The object to load</param>
545 public void PrimFromStorage(PrimData prim)
546 {
547 try
548 {
549 if (prim.LocalID >= this._primCount)
550 {
551 _primCount = prim.LocalID + 1;
552 }
553 MainConsole.Instance.Notice("World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage");
554 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
555 nPrim.CreateFromStorage(prim);
556 this.Entities.Add(nPrim.uuid, nPrim);
557 }
558 catch (Exception e)
559 {
560 MainConsole.Instance.Warn("World.cs: PrimFromStorage() - Failed with exception " + e.ToString());
561 }
562 }
563
564 public void AddNewPrim(Packet addPacket, ClientView agentClient)
565 {
566 AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentID);
567 }
568
569 public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID)
570 {
571 try
572 {
573 MainConsole.Instance.Notice("World.cs: AddNewPrim() - Creating new prim");
574 Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this);
575 prim.CreateFromPacket(addPacket, ownerID, this._primCount);
576 PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z);
577 PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f);
578 if (OpenSim.RegionServer.Simulator.Avatar.PhysicsEngineFlying)
579 {
580 lock (this.LockPhysicsEngine)
581 {
582 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize);
583 }
584 }
585
586 this.Entities.Add(prim.uuid, prim);
587 this._primCount++;
588 }
589 catch (Exception e)
590 {
591 MainConsole.Instance.Warn("World.cs: AddNewPrim() - Failed with exception " + e.ToString());
592 }
593 }
594
595 #endregion
596
597 #region Add/Remove Avatar Methods
598
599 public override Avatar AddViewerAgent(ClientView agentClient)
600 {
601 //register for events
602 agentClient.OnChatFromViewer += new ChatFromViewer(this.SimChat);
603 agentClient.OnRezObject += new RezObject(this.RezObject);
604 agentClient.OnModifyTerrain += new ModifyTerrain(this.ModifyTerrain);
605 agentClient.OnRegionHandShakeReply += new ClientView.GenericCall(this.SendLayerData);
606 agentClient.OnRequestWearables += new ClientView.GenericCall(this.GetInitialPrims);
607 agentClient.OnRequestAvatarsData += new ClientView.GenericCall(this.SendAvatarsToClient);
608 agentClient.OnLinkObjects += new LinkObjects(this.LinkObjects);
609 agentClient.OnAddPrim += new ClientView.GenericCall4(this.AddNewPrim);
610 agentClient.OnUpdatePrimShape += new ClientView.UpdateShape(this.UpdatePrimShape);
611
612 agentClient.OnObjectSelect += new ClientView.ObjectSelect(this.SelectPrim);
613 agentClient.OnUpdatePrimFlags += new ClientView.UpdatePrimFlags(this.UpdatePrimFlags);
614 agentClient.OnUpdatePrimTexture += new ClientView.UpdatePrimTexture(this.UpdatePrimTexture);
615 agentClient.OnUpdatePrimPosition += new ClientView.UpdatePrimVector(this.UpdatePrimPosition);
616 agentClient.OnUpdatePrimRotation += new ClientView.UpdatePrimRotation(this.UpdatePrimRotation);
617 agentClient.OnUpdatePrimScale += new ClientView.UpdatePrimVector(this.UpdatePrimScale);
618 agentClient.OnDeRezObject += new ClientView.GenericCall4(this.DeRezObject);
619
620 agentClient.OnParcelPropertiesRequest += new OpenSim.RegionServer.Simulator.ParcelPropertiesRequest(ParcelPropertiesRequest);
621 agentClient.OnParcelDivideRequest += new OpenSim.RegionServer.Simulator.ParcelDivideRequest(ParcelDivideRequest);
622 agentClient.OnParcelJoinRequest+=new OpenSim.RegionServer.Simulator.ParcelJoinRequest(ParcelJoinRequest);
623 agentClient.OnParcelPropertiesUpdateRequest += new OpenSim.RegionServer.Simulator.ParcelPropertiesUpdateRequest(ParcelPropertiesUpdateRequest);
624 Avatar newAvatar = null;
625 try
626 {
627 MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
628 newAvatar = new Avatar(agentClient, this, m_regionName, m_clientThreads, m_regionHandle, true, 20);
629 MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Adding new avatar to world");
630 MainConsole.Instance.Notice("World.cs:AddViewerAgent() - Starting RegionHandshake ");
631 newAvatar.SendRegionHandshake(this);
632 //if (!agentClient.m_child)
633 //{
634
635 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
636 lock (this.LockPhysicsEngine)
637 {
638 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
639 }
640 // }
641 lock (Entities)
642 {
643 if (!Entities.ContainsKey(agentClient.AgentID))
644 {
645 this.Entities.Add(agentClient.AgentID, newAvatar);
646 }
647 else
648 {
649 Entities[agentClient.AgentID] = newAvatar;
650 }
651 }
652 lock (Avatars)
653 {
654 if (Avatars.ContainsKey(agentClient.AgentID))
655 {
656 Avatars[agentClient.AgentID] = newAvatar;
657 }
658 else
659 {
660 this.Avatars.Add(agentClient.AgentID, newAvatar);
661 }
662 }
663 }
664 catch (Exception e)
665 {
666 MainConsole.Instance.Warn("World.cs: AddViewerAgent() - Failed with exception " + e.ToString());
667 }
668 return newAvatar;
669 }
670
671
672
673
674
675
676
677 public override void RemoveViewerAgent(ClientView agentClient)
678 {
679 try
680 {
681 lock (Entities)
682 {
683 Entities.Remove(agentClient.AgentID);
684 }
685 lock (Avatars)
686 {
687 Avatars.Remove(agentClient.AgentID);
688 }
689 if (agentClient.ClientAvatar.PhysActor != null)
690 {
691 this.phyScene.RemoveAvatar(agentClient.ClientAvatar.PhysActor);
692 }
693 }
694 catch (Exception e)
695 {
696 MainConsole.Instance.Warn("World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString());
697 }
698 }
699 #endregion
700
701 #region Request Avatars List Methods
702 //The idea is to have a group of method that return a list of avatars meeting some requirement
703 // ie it could be all Avatars within a certain range of the calling prim/avatar.
704
705 public List<Avatar> RequestAvatarList()
706 {
707 List<Avatar> result = new List<Avatar>();
708
709 foreach (Avatar avatar in Avatars.Values)
710 {
711 result.Add(avatar);
712 }
713
714 return result;
715 }
716 #endregion
717
718 #region ShutDown
719 /// <summary>
720 /// Tidy before shutdown
721 /// </summary>
722 public override void Close()
723 {
724 try
725 {
726 this.localStorage.ShutDown();
727 }
728 catch (Exception e)
729 {
730 OpenSim.Framework.Console.MainConsole.Instance.Error("World.cs: Close() - Failed with exception " + e.ToString());
731 }
732 }
733 #endregion
734
735 }
736}
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/WorldBase.cs b/OpenSim/OpenSim.RegionServer/Simulator/WorldBase.cs
new file mode 100644
index 0000000..c09ddd0
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/Simulator/WorldBase.cs
@@ -0,0 +1,205 @@
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;
30using libsecondlife.Packets;
31using System.Collections.Generic;
32using System.Text;
33using System.Reflection;
34using System.IO;
35using System.Threading;
36using OpenSim.Physics.Manager;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Types;
39using OpenSim.Framework.Terrain;
40using OpenSim.Framework.Inventory;
41using OpenSim.RegionServer.Assets;
42using OpenSim.RegionServer.Scripting;
43using OpenSim.RegionServer.Client;
44using OpenSim.Terrain;
45using OpenSim.Framework.Console;
46
47namespace OpenSim.RegionServer.Simulator
48{
49 public class WorldBase
50 {
51 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
52 protected Dictionary<uint, ClientView> m_clientThreads;
53 protected ulong m_regionHandle;
54 protected string m_regionName;
55 protected InventoryCache _inventoryCache;
56 protected AssetCache _assetCache;
57 public RegionInfo m_regInfo;
58
59 public TerrainEngine Terrain; //TODO: Replace TerrainManager with this.
60 protected libsecondlife.TerrainManager TerrainManager; // To be referenced via TerrainEngine
61
62 #region Properties
63 public InventoryCache InventoryCache
64 {
65 set
66 {
67 this._inventoryCache = value;
68 }
69 }
70
71 public AssetCache AssetCache
72 {
73 set
74 {
75 this._assetCache = value;
76 }
77 }
78 #endregion
79
80 #region Constructors
81 public WorldBase()
82 {
83
84 }
85 #endregion
86
87 #region Setup Methods
88 /// <summary>
89 /// Register Packet handler Methods with the packet server (which will register them with the SimClient)
90 /// </summary>
91 /// <param name="packetServer"></param>
92 public virtual void RegisterPacketHandlers(PacketServer packetServer)
93 {
94
95 }
96 #endregion
97
98 #region Update Methods
99 /// <summary>
100 /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
101 /// </summary>
102 public virtual void Update()
103 {
104
105 }
106 #endregion
107
108 #region Terrain Methods
109
110 /// <summary>
111 /// Loads the World heightmap
112 /// </summary>
113 public virtual void LoadWorldMap()
114 {
115
116 }
117
118 /// <summary>
119 /// Send the region heightmap to the client
120 /// </summary>
121 /// <param name="RemoteClient">Client to send to</param>
122 public virtual void SendLayerData(ClientView RemoteClient)
123 {
124 try
125 {
126 int[] patches = new int[4];
127
128 for (int y = 0; y < 16; y++)
129 {
130 for (int x = 0; x < 16; x = x + 4)
131 {
132 patches[0] = x + 0 + y * 16;
133 patches[1] = x + 1 + y * 16;
134 patches[2] = x + 2 + y * 16;
135 patches[3] = x + 3 + y * 16;
136
137 Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches);
138 RemoteClient.OutPacket(layerpack);
139 }
140 }
141 }
142 catch (Exception e)
143 {
144 MainConsole.Instance.Warn("World.cs: SendLayerData() - Failed with exception " + e.ToString());
145 }
146 }
147
148 /// <summary>
149 /// Sends a specified patch to a client
150 /// </summary>
151 /// <param name="px">Patch coordinate (x) 0..16</param>
152 /// <param name="py">Patch coordinate (y) 0..16</param>
153 /// <param name="RemoteClient">The client to send to</param>
154 public void SendLayerData(int px, int py, ClientView RemoteClient)
155 {
156 try
157 {
158 int[] patches = new int[1];
159 int patchx, patchy;
160 patchx = px / 16;
161 patchy = py / 16;
162
163 patches[0] = patchx + 0 + patchy * 16;
164
165 Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches);
166 RemoteClient.OutPacket(layerpack);
167 }
168 catch (Exception e)
169 {
170 MainConsole.Instance.Warn("World.cs: SendLayerData() - Failed with exception " + e.ToString());
171 }
172 }
173 #endregion
174
175 #region Add/Remove Agent/Avatar
176 /// <summary>
177 /// Add a new Agent's avatar
178 /// </summary>
179 /// <param name="agentClient"></param>
180 public virtual Avatar AddViewerAgent(ClientView agentClient)
181 {
182 return null;
183 }
184
185 /// <summary>
186 /// Remove a Agent's avatar
187 /// </summary>
188 /// <param name="agentClient"></param>
189 public virtual void RemoveViewerAgent(ClientView agentClient)
190 {
191
192 }
193 #endregion
194
195 #region Shutdown
196 /// <summary>
197 /// Tidy before shutdown
198 /// </summary>
199 public virtual void Close()
200 {
201
202 }
203 #endregion
204 }
205}
diff --git a/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.csproj b/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.csproj
index 7d90947..af8285b 100644
--- a/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.csproj
+++ b/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.csproj
@@ -96,10 +96,10 @@
96 <Compile Include="MapStorage.cs"> 96 <Compile Include="MapStorage.cs">
97 <SubType>Code</SubType> 97 <SubType>Code</SubType>
98 </Compile> 98 </Compile>
99 <Compile Include="UUIDPrimQuery.cs"> 99 <Compile Include="UUIDParcelQuery.cs">
100 <SubType>Code</SubType> 100 <SubType>Code</SubType>
101 </Compile> 101 </Compile>
102 <Compile Include="UUIDParcelQuery.cs"> 102 <Compile Include="UUIDPrimQuery.cs">
103 <SubType>Code</SubType> 103 <SubType>Code</SubType>
104 </Compile> 104 </Compile>
105 <Compile Include="Db4LocalStorage.cs"> 105 <Compile Include="Db4LocalStorage.cs">
diff --git a/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.dll.build b/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.dll.build
index 9789712..72aac2a 100644
--- a/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.dll.build
+++ b/OpenSim/OpenSim.Storage/LocalStorageDb4o/OpenSim.Storage.LocalStorageDb4o.dll.build
@@ -13,8 +13,8 @@
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="AssemblyInfo.cs" /> 14 <include name="AssemblyInfo.cs" />
15 <include name="MapStorage.cs" /> 15 <include name="MapStorage.cs" />
16 <include name="UUIDPrimQuery.cs" />
17 <include name="UUIDParcelQuery.cs" /> 16 <include name="UUIDParcelQuery.cs" />
17 <include name="UUIDPrimQuery.cs" />
18 <include name="Db4LocalStorage.cs" /> 18 <include name="Db4LocalStorage.cs" />
19 </sources> 19 </sources>
20 <references basedir="${project::get-base-directory()}"> 20 <references basedir="${project::get-base-directory()}">