aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:10:25 +0000
committerAdam Frisby2007-07-11 08:10:25 +0000
commite2ff441e31328e60c8bb1d4bb32fa4ac64f91978 (patch)
tree8405b6cef57b66a58f31a24c859846085d0b81f7 /OpenSim/Region/Environment
parent* Wiping trunk in prep for Sugilite (diff)
parent* Applying dalien's patches from bug#177 and #179 (diff)
downloadopensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.zip
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.gz
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.bz2
opensim-SC-e2ff441e31328e60c8bb1d4bb32fa4ac64f91978.tar.xz
* Bringing Sugilite in to trunk
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/EstateManager.cs300
-rw-r--r--OpenSim/Region/Environment/ParcelManager.cs891
-rw-r--r--OpenSim/Region/Environment/RegionManager.cs29
-rw-r--r--OpenSim/Region/Environment/Scenes/Entity.cs115
-rw-r--r--OpenSim/Region/Environment/Scenes/EntityBase.cs142
-rw-r--r--OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs14
-rw-r--r--OpenSim/Region/Environment/Scenes/Primitive.cs594
-rw-r--r--OpenSim/Region/Environment/Scenes/PrimitiveOld.cs583
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs570
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs806
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneBase.cs198
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneEvents.cs50
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObject.cs246
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs74
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs85
-rw-r--r--OpenSim/Region/Environment/Scenes/ScenePresence.cs597
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs102
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs102
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs45
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs503
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs43
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs135
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs427
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs96
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs40
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs29
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs45
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs46
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs37
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs171
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs42
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs49
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs119
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Script.cs64
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs25
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs58
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs99
44 files changed, 7659 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/EstateManager.cs b/OpenSim/Region/Environment/EstateManager.cs
new file mode 100644
index 0000000..b5a74ad
--- /dev/null
+++ b/OpenSim/Region/Environment/EstateManager.cs
@@ -0,0 +1,300 @@
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.Framework.Console;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using OpenSim.Region.Environment.Scenes;
37using Avatar = OpenSim.Region.Environment.Scenes.ScenePresence;
38
39
40namespace OpenSim.Region.Environment
41{
42
43 /// <summary>
44 /// Processes requests regarding estates. Refer to EstateSettings.cs in OpenSim.Framework. Types for all of the core settings
45 /// </summary>
46 public class EstateManager
47 {
48 private Scene m_world;
49 private RegionInfo m_regInfo;
50
51 public EstateManager(Scene world,RegionInfo reginfo)
52 {
53 m_world = world; //Estate settings found at world.m_regInfo.estateSettings
54 m_regInfo = reginfo;
55 }
56
57 private bool convertParamStringToBool(byte[] field)
58 {
59 string s = Helpers.FieldToUTF8String(field);
60 if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
61 {
62 return true;
63 }
64 return false;
65 }
66
67 public void handleEstateOwnerMessage(EstateOwnerMessagePacket packet, IClientAPI remote_client)
68 {
69 if (remote_client.AgentId == m_regInfo.MasterAvatarAssignedUUID)
70 {
71 switch (Helpers.FieldToUTF8String(packet.MethodData.Method))
72 {
73 case "getinfo":
74 Console.WriteLine("GETINFO Requested");
75 this.sendRegionInfoPacketToAll();
76
77 break;
78 case "setregioninfo":
79 if (packet.ParamList.Length != 9)
80 {
81 MainLog.Instance.Error("EstateOwnerMessage: SetRegionInfo method has a ParamList of invalid length");
82 }
83 else
84 {
85 m_regInfo.estateSettings.regionFlags = Simulator.RegionFlags.None;
86
87 if (convertParamStringToBool(packet.ParamList[0].Parameter))
88 {
89 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockTerraform;
90 }
91
92 if (convertParamStringToBool(packet.ParamList[1].Parameter))
93 {
94 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.NoFly;
95 }
96
97 if (convertParamStringToBool(packet.ParamList[2].Parameter))
98 {
99 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowDamage;
100 }
101
102 if (convertParamStringToBool(packet.ParamList[3].Parameter) == false)
103 {
104 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockLandResell;
105 }
106
107
108 int tempMaxAgents = Convert.ToInt16(Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[4].Parameter)));
109 m_regInfo.estateSettings.maxAgents = (byte)tempMaxAgents;
110
111 float tempObjectBonusFactor = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
112 m_regInfo.estateSettings.objectBonusFactor = tempObjectBonusFactor;
113
114 int tempMatureLevel = Convert.ToInt16(Helpers.FieldToUTF8String(packet.ParamList[6].Parameter));
115 m_regInfo.estateSettings.simAccess = (Simulator.SimAccess)tempMatureLevel;
116
117
118 if (convertParamStringToBool(packet.ParamList[7].Parameter))
119 {
120 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.RestrictPushObject;
121 }
122
123 if (convertParamStringToBool(packet.ParamList[8].Parameter))
124 {
125 m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowParcelChanges;
126 }
127
128 sendRegionInfoPacketToAll();
129
130 }
131 break;
132 case "texturebase":
133 foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
134 {
135 string s = Helpers.FieldToUTF8String(block.Parameter);
136 string[] splitField = s.Split(' ');
137 if (splitField.Length == 2)
138 {
139 LLUUID tempUUID = new LLUUID(splitField[1]);
140 switch (Convert.ToInt16(splitField[0]))
141 {
142 case 0:
143 m_regInfo.estateSettings.terrainBase0 = tempUUID;
144 break;
145 case 1:
146 m_regInfo.estateSettings.terrainBase1 = tempUUID;
147 break;
148 case 2:
149 m_regInfo.estateSettings.terrainBase2 = tempUUID;
150 break;
151 case 3:
152 m_regInfo.estateSettings.terrainBase3 = tempUUID;
153 break;
154 }
155 }
156 }
157 break;
158 case "texturedetail":
159 foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
160 {
161
162 string s = Helpers.FieldToUTF8String(block.Parameter);
163 string[] splitField = s.Split(' ');
164 if (splitField.Length == 2)
165 {
166 LLUUID tempUUID = new LLUUID(splitField[1]);
167 switch (Convert.ToInt16(splitField[0]))
168 {
169 case 0:
170 m_regInfo.estateSettings.terrainDetail0 = tempUUID;
171 break;
172 case 1:
173 m_regInfo.estateSettings.terrainDetail1 = tempUUID;
174 break;
175 case 2:
176 m_regInfo.estateSettings.terrainDetail2 = tempUUID;
177 break;
178 case 3:
179 m_regInfo.estateSettings.terrainDetail3 = tempUUID;
180 break;
181 }
182 }
183 }
184 break;
185 case "textureheights":
186 foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
187 {
188
189 string s = Helpers.FieldToUTF8String(block.Parameter);
190 string[] splitField = s.Split(' ');
191 if (splitField.Length == 3)
192 {
193
194 float tempHeightLow = (float)Convert.ToDecimal(splitField[1]);
195 float tempHeightHigh = (float)Convert.ToDecimal(splitField[2]);
196
197 switch (Convert.ToInt16(splitField[0]))
198 {
199 case 0:
200 m_regInfo.estateSettings.terrainStartHeight0 = tempHeightLow;
201 m_regInfo.estateSettings.terrainHeightRange0 = tempHeightHigh;
202 break;
203 case 1:
204 m_regInfo.estateSettings.terrainStartHeight1 = tempHeightLow;
205 m_regInfo.estateSettings.terrainHeightRange1 = tempHeightHigh;
206 break;
207 case 2:
208 m_regInfo.estateSettings.terrainStartHeight2 = tempHeightLow;
209 m_regInfo.estateSettings.terrainHeightRange2 = tempHeightHigh;
210 break;
211 case 3:
212 m_regInfo.estateSettings.terrainStartHeight3 = tempHeightLow;
213 m_regInfo.estateSettings.terrainHeightRange3 = tempHeightHigh;
214 break;
215 }
216 }
217 }
218 break;
219 case "texturecommit":
220 sendRegionHandshakeToAll();
221 break;
222 case "setregionterrain":
223 if (packet.ParamList.Length != 9)
224 {
225 MainLog.Instance.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
226 }
227 else
228 {
229 m_regInfo.estateSettings.waterHeight = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[0].Parameter));
230 m_regInfo.estateSettings.terrainRaiseLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[1].Parameter));
231 m_regInfo.estateSettings.terrainLowerLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[2].Parameter));
232 m_regInfo.estateSettings.useFixedSun = this.convertParamStringToBool(packet.ParamList[4].Parameter);
233 m_regInfo.estateSettings.sunHour = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
234
235 sendRegionInfoPacketToAll();
236 }
237 break;
238 default:
239 MainLog.Instance.Error("EstateOwnerMessage: Unknown method requested\n" + packet.ToString());
240 break;
241 }
242 }
243 }
244
245 public void sendRegionInfoPacketToAll()
246 {
247 List<Avatar> avatars = m_world.RequestAvatarList();
248
249 for (int i = 0; i < avatars.Count; i++)
250 {
251 this.sendRegionInfoPacket(avatars[i].ControllingClient);
252 }
253 }
254
255 public void sendRegionHandshakeToAll()
256 {
257 List<Avatar> avatars = m_world.RequestAvatarList();
258
259 for (int i = 0; i < avatars.Count; i++)
260 {
261 this.sendRegionHandshake(avatars[i].ControllingClient);
262 }
263 }
264
265 public void sendRegionInfoPacket(IClientAPI remote_client)
266 {
267 Encoding _enc = Encoding.ASCII;
268
269 AgentCircuitData circuitData = remote_client.RequestClientInfo();
270
271 RegionInfoPacket regionInfoPacket = new RegionInfoPacket();
272 regionInfoPacket.AgentData.AgentID = circuitData.AgentID;
273 regionInfoPacket.AgentData.SessionID = circuitData.SessionID;
274 regionInfoPacket.RegionInfo.BillableFactor = m_regInfo.estateSettings.billableFactor;
275 regionInfoPacket.RegionInfo.EstateID = m_regInfo.estateSettings.estateID;
276 regionInfoPacket.RegionInfo.MaxAgents = m_regInfo.estateSettings.maxAgents;
277 regionInfoPacket.RegionInfo.ObjectBonusFactor = m_regInfo.estateSettings.objectBonusFactor;
278 regionInfoPacket.RegionInfo.ParentEstateID = m_regInfo.estateSettings.parentEstateID;
279 regionInfoPacket.RegionInfo.PricePerMeter = m_regInfo.estateSettings.pricePerMeter;
280 regionInfoPacket.RegionInfo.RedirectGridX = m_regInfo.estateSettings.redirectGridX;
281 regionInfoPacket.RegionInfo.RedirectGridY = m_regInfo.estateSettings.redirectGridY;
282 regionInfoPacket.RegionInfo.RegionFlags = (uint)m_regInfo.estateSettings.regionFlags;
283 regionInfoPacket.RegionInfo.SimAccess = (byte)m_regInfo.estateSettings.simAccess;
284 regionInfoPacket.RegionInfo.SimName = _enc.GetBytes( m_regInfo.RegionName);
285 regionInfoPacket.RegionInfo.SunHour = m_regInfo.estateSettings.sunHour;
286 regionInfoPacket.RegionInfo.TerrainLowerLimit = m_regInfo.estateSettings.terrainLowerLimit;
287 regionInfoPacket.RegionInfo.TerrainRaiseLimit = m_regInfo.estateSettings.terrainRaiseLimit;
288 regionInfoPacket.RegionInfo.UseEstateSun = !m_regInfo.estateSettings.useFixedSun;
289 regionInfoPacket.RegionInfo.WaterHeight = m_regInfo.estateSettings.waterHeight;
290
291 remote_client.OutPacket(regionInfoPacket);
292 }
293
294 public void sendRegionHandshake(IClientAPI remoteClient)
295 {
296 remoteClient.SendRegionHandshake(m_regInfo);
297 }
298
299 }
300}
diff --git a/OpenSim/Region/Environment/ParcelManager.cs b/OpenSim/Region/Environment/ParcelManager.cs
new file mode 100644
index 0000000..2059b3f
--- /dev/null
+++ b/OpenSim/Region/Environment/ParcelManager.cs
@@ -0,0 +1,891 @@
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 libsecondlife;
31using libsecondlife.Packets;
32using OpenSim.Framework.Interfaces;
33using OpenSim.Framework.Types;
34using OpenSim.Region.Environment.Scenes;
35using Avatar = OpenSim.Region.Environment.Scenes.ScenePresence;
36
37namespace OpenSim.Region.Environment
38{
39
40
41 #region ParcelManager Class
42 /// <summary>
43 /// Handles Parcel objects and operations requiring information from other Parcel objects (divide, join, etc)
44 /// </summary>
45 public class ParcelManager : ILocalStorageParcelReceiver
46 {
47
48 #region Constants
49 //Parcel types set with flags in ParcelOverlay.
50 //Only one of these can be used.
51 public const byte PARCEL_TYPE_PUBLIC = (byte)0; //Equals 00000000
52 public const byte PARCEL_TYPE_OWNED_BY_OTHER = (byte)1; //Equals 00000001
53 public const byte PARCEL_TYPE_OWNED_BY_GROUP = (byte)2; //Equals 00000010
54 public const byte PARCEL_TYPE_OWNED_BY_REQUESTER = (byte)3; //Equals 00000011
55 public const byte PARCEL_TYPE_IS_FOR_SALE = (byte)4; //Equals 00000100
56 public const byte PARCEL_TYPE_IS_BEING_AUCTIONED = (byte)5; //Equals 00000101
57
58
59 //Flags that when set, a border on the given side will be placed
60 //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)
61 //This took forever to figure out -- jeesh. /blame LL for even having to send these
62 public const byte PARCEL_FLAG_PROPERTY_BORDER_WEST = (byte)64; //Equals 01000000
63 public const byte PARCEL_FLAG_PROPERTY_BORDER_SOUTH = (byte)128; //Equals 10000000
64
65 //RequestResults (I think these are right, they seem to work):
66 public const int PARCEL_RESULT_ONE_PARCEL = 0; // The request they made contained only one parcel
67 public const int PARCEL_RESULT_MULTIPLE_PARCELS = 1; // The request they made contained more than one parcel
68
69 //These are other constants. Yay!
70 public const int START_PARCEL_LOCAL_ID = 1;
71 #endregion
72
73 #region Member Variables
74 public Dictionary<int, Parcel> parcelList = new Dictionary<int, Parcel>();
75 private int lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
76 private int[,] parcelIDList = new int[64, 64];
77
78 private Scene m_world;
79 private RegionInfo m_regInfo;
80
81 #endregion
82
83 #region Constructors
84 public ParcelManager(Scene world, RegionInfo reginfo)
85 {
86
87 m_world = world;
88 m_regInfo = reginfo;
89 parcelIDList.Initialize();
90
91 }
92 #endregion
93
94 #region Member Functions
95
96 #region Parcel From Storage Functions
97 public void ParcelFromStorage(ParcelData data)
98 {
99 Parcel new_parcel = new Parcel(data.ownerID, data.isGroupOwned, m_world);
100 new_parcel.parcelData = data.Copy();
101 new_parcel.setParcelBitmapFromByteArray();
102 addParcel(new_parcel);
103
104 }
105
106 public void NoParcelDataFromStorage()
107 {
108 resetSimParcels();
109 }
110 #endregion
111
112 #region Parcel Add/Remove/Get/Create
113 /// <summary>
114 /// Creates a basic Parcel object without an owner (a zeroed key)
115 /// </summary>
116 /// <returns></returns>
117 public Parcel createBaseParcel()
118 {
119 return new Parcel(new LLUUID(), false, m_world);
120 }
121
122 /// <summary>
123 /// Adds a parcel to the stored list and adds them to the parcelIDList to what they own
124 /// </summary>
125 /// <param name="new_parcel">The parcel being added</param>
126 public void addParcel(Parcel new_parcel)
127 {
128 lastParcelLocalID++;
129 new_parcel.parcelData.localID = lastParcelLocalID;
130 parcelList.Add(lastParcelLocalID, new_parcel.Copy());
131
132
133 bool[,] parcelBitmap = new_parcel.getParcelBitmap();
134 int x, y;
135 for (x = 0; x < 64; x++)
136 {
137 for (y = 0; y < 64; y++)
138 {
139 if (parcelBitmap[x, y])
140 {
141 parcelIDList[x, y] = lastParcelLocalID;
142 }
143 }
144 }
145 parcelList[lastParcelLocalID].forceUpdateParcelInfo();
146
147
148 }
149 /// <summary>
150 /// Removes a parcel from the list. Will not remove if local_id is still owning an area in parcelIDList
151 /// </summary>
152 /// <param name="local_id">Parcel.localID of the parcel to remove.</param>
153 public void removeParcel(int local_id)
154 {
155 int x, y;
156 for (x = 0; x < 64; x++)
157 {
158 for (y = 0; y < 64; y++)
159 {
160 if (parcelIDList[x, y] == local_id)
161 {
162 throw new Exception("Could not remove parcel. Still being used at " + x + ", " + y);
163 }
164 }
165 }
166 m_world.localStorage.RemoveParcel(parcelList[local_id].parcelData);
167 parcelList.Remove(local_id);
168 }
169
170 private void performFinalParcelJoin(Parcel master, Parcel slave)
171 {
172 int x, y;
173 bool[,] parcelBitmapSlave = slave.getParcelBitmap();
174 for (x = 0; x < 64; x++)
175 {
176 for (y = 0; y < 64; y++)
177 {
178 if (parcelBitmapSlave[x, y])
179 {
180 parcelIDList[x, y] = master.parcelData.localID;
181 }
182 }
183 }
184 removeParcel(slave.parcelData.localID);
185 }
186 /// <summary>
187 /// Get the parcel at the specified point
188 /// </summary>
189 /// <param name="x">Value between 0 - 256 on the x axis of the point</param>
190 /// <param name="y">Value between 0 - 256 on the y axis of the point</param>
191 /// <returns>Parcel at the point supplied</returns>
192 public Parcel getParcel(int x, int y)
193 {
194 if (x > 256 || y > 256 || x < 0 || y < 0)
195 {
196 throw new Exception("Error: Parcel not found at point " + x + ", " + y);
197 }
198 else
199 {
200 return parcelList[parcelIDList[x / 4, y / 4]];
201 }
202
203 }
204 #endregion
205
206 #region Parcel Modification
207 /// <summary>
208 /// Subdivides a parcel
209 /// </summary>
210 /// <param name="start_x">West Point</param>
211 /// <param name="start_y">South Point</param>
212 /// <param name="end_x">East Point</param>
213 /// <param name="end_y">North Point</param>
214 /// <param name="attempting_user_id">LLUUID of user who is trying to subdivide</param>
215 /// <returns>Returns true if successful</returns>
216 private bool subdivide(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
217 {
218 //First, lets loop through the points and make sure they are all in the same parcel
219 //Get the parcel at start
220 Parcel startParcel = getParcel(start_x, start_y);
221 if (startParcel == null) return false; //No such parcel at the beginning
222
223 //Loop through the points
224 try
225 {
226 int totalX = end_x - start_x;
227 int totalY = end_y - start_y;
228 int x, y;
229 for (y = 0; y < totalY; y++)
230 {
231 for (x = 0; x < totalX; x++)
232 {
233 Parcel tempParcel = getParcel(start_x + x, start_y + y);
234 if (tempParcel == null) return false; //No such parcel at that point
235 if (tempParcel != startParcel) return false; //Subdividing over 2 parcels; no-no
236 }
237 }
238 }
239 catch (Exception)
240 {
241 return false; //Exception. For now, lets skip subdivision
242 }
243
244 //If we are still here, then they are subdividing within one parcel
245 //Check owner
246 if (startParcel.parcelData.ownerID != attempting_user_id)
247 {
248 return false; //They cant do this!
249 }
250
251 //Lets create a new parcel with bitmap activated at that point (keeping the old parcels info)
252 Parcel newParcel = startParcel.Copy();
253 newParcel.parcelData.parcelName = "Subdivision of " + newParcel.parcelData.parcelName;
254 newParcel.parcelData.globalID = LLUUID.Random();
255
256 newParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(start_x, start_y, end_x, end_y));
257
258 //Now, lets set the subdivision area of the original to false
259 int startParcelIndex = startParcel.parcelData.localID;
260 parcelList[startParcelIndex].setParcelBitmap(Parcel.modifyParcelBitmapSquare(startParcel.getParcelBitmap(), start_x, start_y, end_x, end_y, false));
261 parcelList[startParcelIndex].forceUpdateParcelInfo();
262
263
264 //Now add the new parcel
265 addParcel(newParcel);
266
267
268
269
270
271 return true;
272 }
273 /// <summary>
274 /// Join 2 parcels together
275 /// </summary>
276 /// <param name="start_x">x value in first parcel</param>
277 /// <param name="start_y">y value in first parcel</param>
278 /// <param name="end_x">x value in second parcel</param>
279 /// <param name="end_y">y value in second parcel</param>
280 /// <param name="attempting_user_id">LLUUID of the avatar trying to join the parcels</param>
281 /// <returns>Returns true if successful</returns>
282 private bool join(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
283 {
284 end_x -= 4;
285 end_y -= 4;
286
287 //NOTE: The following only connects the parcels in each corner and not all the parcels that are within the selection box!
288 //This should be fixed later -- somewhat "incomplete code" --Ming
289 Parcel startParcel, endParcel;
290
291 try
292 {
293 startParcel = getParcel(start_x, start_y);
294 endParcel = getParcel(end_x, end_y);
295 }
296 catch (Exception)
297 {
298 return false; //Error occured when trying to get the start and end parcels
299 }
300 if (startParcel == endParcel)
301 {
302 return false; //Subdivision of the same parcel is not allowed
303 }
304
305 //Check the parcel owners:
306 if (startParcel.parcelData.ownerID != endParcel.parcelData.ownerID)
307 {
308 return false;
309 }
310 if (startParcel.parcelData.ownerID != attempting_user_id)
311 {
312 //TODO: Group editing stuff. Avatar owner support for now
313 return false;
314 }
315
316 //Same owners! Lets join them
317 //Merge them to startParcel
318 parcelList[startParcel.parcelData.localID].setParcelBitmap(Parcel.mergeParcelBitmaps(startParcel.getParcelBitmap(), endParcel.getParcelBitmap()));
319 performFinalParcelJoin(startParcel, endParcel);
320
321 return true;
322
323
324
325 }
326 #endregion
327
328 #region Parcel Updating
329 /// <summary>
330 /// Where we send the ParcelOverlay packet to the client
331 /// </summary>
332 /// <param name="remote_client">The object representing the client</param>
333 public void sendParcelOverlay(IClientAPI remote_client)
334 {
335 const int PARCEL_BLOCKS_PER_PACKET = 1024;
336 int x, y = 0;
337 byte[] byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
338 int byteArrayCount = 0;
339 int sequenceID = 0;
340 ParcelOverlayPacket packet;
341
342 for (y = 0; y < 64; y++)
343 {
344 for (x = 0; x < 64; x++)
345 {
346 byte tempByte = (byte)0; //This represents the byte for the current 4x4
347 Parcel currentParcelBlock = getParcel(x * 4, y * 4);
348
349 if (currentParcelBlock.parcelData.ownerID == remote_client.AgentId)
350 {
351 //Owner Flag
352 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_REQUESTER);
353 }
354 else if (currentParcelBlock.parcelData.salePrice > 0 && (currentParcelBlock.parcelData.authBuyerID == LLUUID.Zero || currentParcelBlock.parcelData.authBuyerID == remote_client.AgentId))
355 {
356 //Sale Flag
357 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_IS_FOR_SALE);
358 }
359 else if (currentParcelBlock.parcelData.ownerID == LLUUID.Zero)
360 {
361 //Public Flag
362 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_PUBLIC);
363 }
364 else
365 {
366 //Other Flag
367 tempByte = Convert.ToByte(tempByte | PARCEL_TYPE_OWNED_BY_OTHER);
368 }
369
370
371 //Now for border control
372 if (x == 0)
373 {
374 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
375 }
376 else if (getParcel((x - 1) * 4, y * 4) != currentParcelBlock)
377 {
378 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_WEST);
379 }
380
381 if (y == 0)
382 {
383 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
384 }
385 else if (getParcel(x * 4, (y - 1) * 4) != currentParcelBlock)
386 {
387 tempByte = Convert.ToByte(tempByte | PARCEL_FLAG_PROPERTY_BORDER_SOUTH);
388 }
389
390 byteArray[byteArrayCount] = tempByte;
391 byteArrayCount++;
392 if (byteArrayCount >= PARCEL_BLOCKS_PER_PACKET)
393 {
394 byteArrayCount = 0;
395 packet = new ParcelOverlayPacket();
396 packet.ParcelData.Data = byteArray;
397 packet.ParcelData.SequenceID = sequenceID;
398 remote_client.OutPacket((Packet)packet);
399 sequenceID++;
400 byteArray = new byte[PARCEL_BLOCKS_PER_PACKET];
401 }
402 }
403 }
404
405 packet = new ParcelOverlayPacket();
406 packet.ParcelData.Data = byteArray;
407 packet.ParcelData.SequenceID = sequenceID; //Eh?
408 remote_client.OutPacket((Packet)packet);
409 }
410
411 public void handleParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, IClientAPI remote_client)
412 {
413 //Get the parcels within the bounds
414 List<Parcel> temp = new List<Parcel>();
415 int x, y, i;
416 int inc_x = end_x - start_x;
417 int inc_y = end_y - start_y;
418 for (x = 0; x < inc_x; x++)
419 {
420 for (y = 0; y < inc_y; y++)
421 {
422 Parcel currentParcel = getParcel(start_x + x, start_y + y);
423 if (!temp.Contains(currentParcel))
424 {
425 currentParcel.forceUpdateParcelInfo();
426 temp.Add(currentParcel);
427 }
428 }
429 }
430
431 int requestResult = PARCEL_RESULT_ONE_PARCEL;
432 if (temp.Count > 1)
433 {
434 requestResult = PARCEL_RESULT_MULTIPLE_PARCELS;
435 }
436
437 for (i = 0; i < temp.Count; i++)
438 {
439 temp[i].sendParcelProperties(sequence_id, snap_selection, requestResult, remote_client);
440 }
441
442
443 sendParcelOverlay(remote_client);
444 }
445
446 public void handleParcelPropertiesUpdateRequest(ParcelPropertiesUpdatePacket packet, IClientAPI remote_client)
447 {
448 if (parcelList.ContainsKey(packet.ParcelData.LocalID))
449 {
450 parcelList[packet.ParcelData.LocalID].updateParcelProperties(packet, remote_client);
451 }
452 }
453 public void handleParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
454 {
455 subdivide(west, south, east, north, remote_client.AgentId);
456 }
457 public void handleParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
458 {
459 join(west, south, east, north, remote_client.AgentId);
460
461 }
462 #endregion
463
464 /// <summary>
465 /// Resets the sim to the default parcel (full sim parcel owned by the default user)
466 /// </summary>
467 public void resetSimParcels()
468 {
469 //Remove all the parcels in the sim and add a blank, full sim parcel set to public
470 parcelList.Clear();
471 lastParcelLocalID = START_PARCEL_LOCAL_ID - 1;
472 parcelIDList.Initialize();
473
474 Parcel fullSimParcel = new Parcel(LLUUID.Zero, false, m_world);
475
476 fullSimParcel.setParcelBitmap(Parcel.getSquareParcelBitmap(0, 0, 256, 256));
477 fullSimParcel.parcelData.parcelName = "Your Sim Parcel";
478 fullSimParcel.parcelData.parcelDesc = "";
479
480 fullSimParcel.parcelData.ownerID = m_regInfo.MasterAvatarAssignedUUID;
481 fullSimParcel.parcelData.salePrice = 1;
482 fullSimParcel.parcelData.parcelFlags = libsecondlife.Parcel.ParcelFlags.ForSale;
483 fullSimParcel.parcelData.parcelStatus = libsecondlife.Parcel.ParcelStatus.Leased;
484
485 addParcel(fullSimParcel);
486
487 }
488 #endregion
489 }
490 #endregion
491
492
493 #region Parcel Class
494 /// <summary>
495 /// Keeps track of a specific parcel's information
496 /// </summary>
497 public class Parcel
498 {
499 #region Member Variables
500 public ParcelData parcelData = new ParcelData();
501 public Scene m_world;
502
503 private bool[,] parcelBitmap = new bool[64, 64];
504
505 #endregion
506
507
508 #region Constructors
509 public Parcel(LLUUID owner_id, bool is_group_owned, Scene world)
510 {
511 m_world = world;
512 parcelData.ownerID = owner_id;
513 parcelData.isGroupOwned = is_group_owned;
514
515 }
516 #endregion
517
518
519 #region Member Functions
520
521 #region General Functions
522 /// <summary>
523 /// Checks to see if this parcel contains a point
524 /// </summary>
525 /// <param name="x"></param>
526 /// <param name="y"></param>
527 /// <returns>Returns true if the parcel contains the specified point</returns>
528 public bool containsPoint(int x, int y)
529 {
530 if (x >= 0 && y >= 0 && x <= 256 && x <= 256)
531 {
532 return (parcelBitmap[x / 4, y / 4] == true);
533 }
534 else
535 {
536 return false;
537 }
538 }
539
540 public Parcel Copy()
541 {
542 Parcel newParcel = new Parcel(this.parcelData.ownerID, this.parcelData.isGroupOwned, m_world);
543
544 //Place all new variables here!
545 newParcel.parcelBitmap = (bool[,])(this.parcelBitmap.Clone());
546 newParcel.parcelData = parcelData.Copy();
547
548 return newParcel;
549 }
550
551 #endregion
552
553
554 #region Packet Request Handling
555 /// <summary>
556 /// Sends parcel properties as requested
557 /// </summary>
558 /// <param name="sequence_id">ID sent by client for them to keep track of</param>
559 /// <param name="snap_selection">Bool sent by client for them to use</param>
560 /// <param name="remote_client">Object representing the client</param>
561 public void sendParcelProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
562 {
563
564 ParcelPropertiesPacket updatePacket = new ParcelPropertiesPacket();
565 updatePacket.ParcelData.AABBMax = parcelData.AABBMax;
566 updatePacket.ParcelData.AABBMin = parcelData.AABBMin;
567 updatePacket.ParcelData.Area = parcelData.area;
568 updatePacket.ParcelData.AuctionID = parcelData.auctionID;
569 updatePacket.ParcelData.AuthBuyerID = parcelData.authBuyerID; //unemplemented
570
571 updatePacket.ParcelData.Bitmap = parcelData.parcelBitmapByteArray;
572
573 updatePacket.ParcelData.Desc = Helpers.StringToField(parcelData.parcelDesc);
574 updatePacket.ParcelData.Category = (byte)parcelData.category;
575 updatePacket.ParcelData.ClaimDate = parcelData.claimDate;
576 updatePacket.ParcelData.ClaimPrice = parcelData.claimPrice;
577 updatePacket.ParcelData.GroupID = parcelData.groupID;
578 updatePacket.ParcelData.GroupPrims = parcelData.groupPrims;
579 updatePacket.ParcelData.IsGroupOwned = parcelData.isGroupOwned;
580 updatePacket.ParcelData.LandingType = (byte)parcelData.landingType;
581 updatePacket.ParcelData.LocalID = parcelData.localID;
582 updatePacket.ParcelData.MaxPrims = 1000; //unemplemented
583 updatePacket.ParcelData.MediaAutoScale = parcelData.mediaAutoScale;
584 updatePacket.ParcelData.MediaID = parcelData.mediaID;
585 updatePacket.ParcelData.MediaURL = Helpers.StringToField(parcelData.mediaURL);
586 updatePacket.ParcelData.MusicURL = Helpers.StringToField(parcelData.musicURL);
587 updatePacket.ParcelData.Name = Helpers.StringToField(parcelData.parcelName);
588 updatePacket.ParcelData.OtherCleanTime = 0; //unemplemented
589 updatePacket.ParcelData.OtherCount = 0; //unemplemented
590 updatePacket.ParcelData.OtherPrims = 0; //unemplented
591 updatePacket.ParcelData.OwnerID = parcelData.ownerID;
592 updatePacket.ParcelData.OwnerPrims = 0; //unemplemented
593 updatePacket.ParcelData.ParcelFlags = (uint)parcelData.parcelFlags; //unemplemented
594 updatePacket.ParcelData.ParcelPrimBonus = (float)1.0; //unemplemented
595 updatePacket.ParcelData.PassHours = parcelData.passHours;
596 updatePacket.ParcelData.PassPrice = parcelData.passPrice;
597 updatePacket.ParcelData.PublicCount = 0; //unemplemented
598 updatePacket.ParcelData.RegionDenyAnonymous = false; //unemplemented
599 updatePacket.ParcelData.RegionDenyIdentified = false; //unemplemented
600 updatePacket.ParcelData.RegionDenyTransacted = false; //unemplemented
601 updatePacket.ParcelData.RegionPushOverride = true; //unemplemented
602 updatePacket.ParcelData.RentPrice = 0; //??
603 updatePacket.ParcelData.RequestResult = request_result;
604 updatePacket.ParcelData.SalePrice = parcelData.salePrice; //unemplemented
605 updatePacket.ParcelData.SelectedPrims = 0; //unemeplemented
606 updatePacket.ParcelData.SelfCount = 0;//unemplemented
607 updatePacket.ParcelData.SequenceID = sequence_id;
608 updatePacket.ParcelData.SimWideMaxPrims = 15000; //unemplemented
609 updatePacket.ParcelData.SimWideTotalPrims = 0; //unemplemented
610 updatePacket.ParcelData.SnapSelection = snap_selection;
611 updatePacket.ParcelData.SnapshotID = parcelData.snapshotID;
612 updatePacket.ParcelData.Status = (byte)parcelData.parcelStatus;
613 updatePacket.ParcelData.TotalPrims = 0; //unemplemented
614 updatePacket.ParcelData.UserLocation = parcelData.userLocation;
615 updatePacket.ParcelData.UserLookAt = parcelData.userLookAt;
616 remote_client.OutPacket((Packet)updatePacket);
617 }
618
619 public void updateParcelProperties(ParcelPropertiesUpdatePacket packet, IClientAPI remote_client)
620 {
621 if (remote_client.AgentId == parcelData.ownerID)
622 {
623 //Needs later group support
624 parcelData.authBuyerID = packet.ParcelData.AuthBuyerID;
625 parcelData.category = (libsecondlife.Parcel.ParcelCategory)packet.ParcelData.Category;
626 parcelData.parcelDesc = Helpers.FieldToUTF8String(packet.ParcelData.Desc);
627 parcelData.groupID = packet.ParcelData.GroupID;
628 parcelData.landingType = packet.ParcelData.LandingType;
629 parcelData.mediaAutoScale = packet.ParcelData.MediaAutoScale;
630 parcelData.mediaID = packet.ParcelData.MediaID;
631 parcelData.mediaURL = Helpers.FieldToUTF8String(packet.ParcelData.MediaURL);
632 parcelData.musicURL = Helpers.FieldToUTF8String(packet.ParcelData.MusicURL);
633 parcelData.parcelName = Helpers.FieldToUTF8String(packet.ParcelData.Name);
634 parcelData.parcelFlags = (libsecondlife.Parcel.ParcelFlags)packet.ParcelData.ParcelFlags;
635 parcelData.passHours = packet.ParcelData.PassHours;
636 parcelData.passPrice = packet.ParcelData.PassPrice;
637 parcelData.salePrice = packet.ParcelData.SalePrice;
638 parcelData.snapshotID = packet.ParcelData.SnapshotID;
639 parcelData.userLocation = packet.ParcelData.UserLocation;
640 parcelData.userLookAt = packet.ParcelData.UserLookAt;
641
642 List<Avatar> avatars = m_world.RequestAvatarList();
643
644 for (int i = 0; i < avatars.Count; i++)
645 {
646 Parcel over = m_world.parcelManager.getParcel((int)Math.Round(avatars[i].Pos.X), (int)Math.Round(avatars[i].Pos.Y));
647 if (over == this)
648 {
649 sendParcelProperties(0, false, 0, avatars[i].ControllingClient);
650 }
651 }
652
653 }
654 }
655 #endregion
656
657
658 #region Update Functions
659 /// <summary>
660 /// Updates the AABBMin and AABBMax values after area/shape modification of parcel
661 /// </summary>
662 private void updateAABBAndAreaValues()
663 {
664 int min_x = 64;
665 int min_y = 64;
666 int max_x = 0;
667 int max_y = 0;
668 int tempArea = 0;
669 int x, y;
670 for (x = 0; x < 64; x++)
671 {
672 for (y = 0; y < 64; y++)
673 {
674 if (parcelBitmap[x, y] == true)
675 {
676 if (min_x > x) min_x = x;
677 if (min_y > y) min_y = y;
678 if (max_x < x) max_x = x;
679 if (max_y < y) max_y = y;
680 tempArea += 16; //16sqm parcel
681 }
682 }
683 }
684 parcelData.AABBMin = new LLVector3((float)(min_x * 4), (float)(min_y * 4), (float)m_world.Terrain.get((min_x * 4), (min_y * 4)));
685 parcelData.AABBMax = new LLVector3((float)(max_x * 4), (float)(max_y * 4), (float)m_world.Terrain.get((max_x * 4), (max_y * 4)));
686 parcelData.area = tempArea;
687 }
688
689 public void updateParcelBitmapByteArray()
690 {
691 parcelData.parcelBitmapByteArray = convertParcelBitmapToBytes();
692 }
693
694 /// <summary>
695 /// Update all settings in parcel such as area, bitmap byte array, etc
696 /// </summary>
697 public void forceUpdateParcelInfo()
698 {
699 this.updateAABBAndAreaValues();
700 this.updateParcelBitmapByteArray();
701 }
702
703 public void setParcelBitmapFromByteArray()
704 {
705 parcelBitmap = convertBytesToParcelBitmap();
706 }
707 #endregion
708
709
710 #region Parcel Bitmap Functions
711 /// <summary>
712 /// Sets the parcel's bitmap manually
713 /// </summary>
714 /// <param name="bitmap">64x64 block representing where this parcel is on a map</param>
715 public void setParcelBitmap(bool[,] bitmap)
716 {
717 if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
718 {
719 //Throw an exception - The bitmap is not 64x64
720 throw new Exception("Error: Invalid Parcel Bitmap");
721 }
722 else
723 {
724 //Valid: Lets set it
725 parcelBitmap = bitmap;
726 forceUpdateParcelInfo();
727
728 }
729 }
730 /// <summary>
731 /// Gets the parcels bitmap manually
732 /// </summary>
733 /// <returns></returns>
734 public bool[,] getParcelBitmap()
735 {
736 return parcelBitmap;
737 }
738 /// <summary>
739 /// Converts the parcel bitmap to a packet friendly byte array
740 /// </summary>
741 /// <returns></returns>
742 private byte[] convertParcelBitmapToBytes()
743 {
744 byte[] tempConvertArr = new byte[512];
745 byte tempByte = 0;
746 int x, y, i, byteNum = 0;
747 i = 0;
748 for (y = 0; y < 64; y++)
749 {
750 for (x = 0; x < 64; x++)
751 {
752 tempByte = Convert.ToByte(tempByte | Convert.ToByte(parcelBitmap[x, y]) << (i++ % 8));
753 if (i % 8 == 0)
754 {
755 tempConvertArr[byteNum] = tempByte;
756 tempByte = (byte)0;
757 i = 0;
758 byteNum++;
759 }
760 }
761 }
762 return tempConvertArr;
763 }
764
765 private bool[,] convertBytesToParcelBitmap()
766 {
767 bool[,] tempConvertMap = new bool[64, 64];
768 tempConvertMap.Initialize();
769 byte tempByte = 0;
770 int x = 0, y = 0, i = 0, bitNum = 0;
771 for (i = 0; i < 512; i++)
772 {
773 tempByte = parcelData.parcelBitmapByteArray[i];
774 for (bitNum = 0; bitNum < 8; bitNum++)
775 {
776 bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte)1);
777 tempConvertMap[x, y] = bit;
778 x++;
779 if (x > 63)
780 {
781 x = 0;
782 y++;
783 }
784
785 }
786
787 }
788 return tempConvertMap;
789 }
790 /// <summary>
791 /// Full sim parcel creation
792 /// </summary>
793 /// <returns></returns>
794 public static bool[,] basicFullRegionParcelBitmap()
795 {
796 return getSquareParcelBitmap(0, 0, 256, 256);
797 }
798
799 /// <summary>
800 /// Used to modify the bitmap between the x and y points. Points use 64 scale
801 /// </summary>
802 /// <param name="start_x"></param>
803 /// <param name="start_y"></param>
804 /// <param name="end_x"></param>
805 /// <param name="end_y"></param>
806 /// <returns></returns>
807 public static bool[,] getSquareParcelBitmap(int start_x, int start_y, int end_x, int end_y)
808 {
809
810 bool[,] tempBitmap = new bool[64, 64];
811 tempBitmap.Initialize();
812
813 tempBitmap = modifyParcelBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
814 return tempBitmap;
815 }
816
817 /// <summary>
818 /// Change a parcel's bitmap at within a square and set those points to a specific value
819 /// </summary>
820 /// <param name="parcel_bitmap"></param>
821 /// <param name="start_x"></param>
822 /// <param name="start_y"></param>
823 /// <param name="end_x"></param>
824 /// <param name="end_y"></param>
825 /// <param name="set_value"></param>
826 /// <returns></returns>
827 public static bool[,] modifyParcelBitmapSquare(bool[,] parcel_bitmap, int start_x, int start_y, int end_x, int end_y, bool set_value)
828 {
829 if (parcel_bitmap.GetLength(0) != 64 || parcel_bitmap.GetLength(1) != 64 || parcel_bitmap.Rank != 2)
830 {
831 //Throw an exception - The bitmap is not 64x64
832 throw new Exception("Error: Invalid Parcel Bitmap in modifyParcelBitmapSquare()");
833 }
834
835 int x, y;
836 for (y = 0; y < 64; y++)
837 {
838 for (x = 0; x < 64; x++)
839 {
840 if (x >= start_x / 4 && x < end_x / 4
841 && y >= start_y / 4 && y < end_y / 4)
842 {
843 parcel_bitmap[x, y] = set_value;
844 }
845 }
846 }
847 return parcel_bitmap;
848 }
849 /// <summary>
850 /// Join the true values of 2 bitmaps together
851 /// </summary>
852 /// <param name="bitmap_base"></param>
853 /// <param name="bitmap_add"></param>
854 /// <returns></returns>
855 public static bool[,] mergeParcelBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
856 {
857 if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
858 {
859 //Throw an exception - The bitmap is not 64x64
860 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeParcelBitmaps");
861 }
862 if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
863 {
864 //Throw an exception - The bitmap is not 64x64
865 throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeParcelBitmaps");
866
867 }
868
869 int x, y;
870 for (y = 0; y < 64; y++)
871 {
872 for (x = 0; x < 64; x++)
873 {
874 if (bitmap_add[x, y])
875 {
876 bitmap_base[x, y] = true;
877 }
878 }
879 }
880 return bitmap_base;
881 }
882 #endregion
883
884 #endregion
885
886
887 }
888 #endregion
889
890
891}
diff --git a/OpenSim/Region/Environment/RegionManager.cs b/OpenSim/Region/Environment/RegionManager.cs
new file mode 100644
index 0000000..cd67e97
--- /dev/null
+++ b/OpenSim/Region/Environment/RegionManager.cs
@@ -0,0 +1,29 @@
1using System.Collections.Generic;
2using OpenSim.Framework;
3using OpenSim.Framework.Communications;
4using OpenSim.Framework.Servers;
5using OpenSim.Region.Capabilities;
6using OpenSim.Region.Environment.Scenes;
7
8namespace OpenSim.Region.Environment
9{
10 public class RegionManager //needs renaming , but first we need to rename the namespace
11 {
12 protected AuthenticateSessionsBase authenticateHandler;
13 protected RegionCommsListener regionCommsHost;
14 protected CommunicationsManager commsManager;
15 protected List<Caps> capsHandlers = new List<Caps>();
16 protected BaseHttpServer httpListener;
17
18 protected Scene m_Scene;
19
20 public ParcelManager parcelManager;
21 public EstateManager estateManager;
22
23 public RegionManager()
24 {
25
26 }
27
28 }
29}
diff --git a/OpenSim/Region/Environment/Scenes/Entity.cs b/OpenSim/Region/Environment/Scenes/Entity.cs
new file mode 100644
index 0000000..084c9ab
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Entity.cs
@@ -0,0 +1,115 @@
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 OpenSim.Physics.Manager;
31
32namespace OpenSim.Region.Environment.Scenes
33{
34 public abstract class Entity :EntityBase //this class (Entity) will be phased out
35 {
36 protected PhysicsActor _physActor;
37
38 /// <summary>
39 ///
40 /// </summary>
41 public override LLVector3 Pos
42 {
43 get
44 {
45 if (this._physActor != null)
46 {
47 m_pos.X = _physActor.Position.X;
48 m_pos.Y = _physActor.Position.Y;
49 m_pos.Z = _physActor.Position.Z;
50 }
51
52 return m_pos;
53 }
54 set
55 {
56 if (this._physActor != null)
57 {
58 try
59 {
60 lock (this.m_world.SyncRoot)
61 {
62
63 this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
64 }
65 }
66 catch (Exception e)
67 {
68 Console.WriteLine(e.Message);
69 }
70 }
71
72 m_pos = value;
73 }
74 }
75
76
77 /// <summary>
78 ///
79 /// </summary>
80 public override LLVector3 Velocity
81 {
82 get
83 {
84 if (this._physActor != null)
85 {
86 m_velocity.X = _physActor.Velocity.X;
87 m_velocity.Y = _physActor.Velocity.Y;
88 m_velocity.Z = _physActor.Velocity.Z;
89 }
90
91 return m_velocity;
92 }
93 set
94 {
95 if (this._physActor != null)
96 {
97 try
98 {
99 lock (this.m_world.SyncRoot)
100 {
101
102 this._physActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
103 }
104 }
105 catch (Exception e)
106 {
107 Console.WriteLine(e.Message);
108 }
109 }
110
111 m_velocity = value;
112 }
113 }
114 }
115}
diff --git a/OpenSim/Region/Environment/Scenes/EntityBase.cs b/OpenSim/Region/Environment/Scenes/EntityBase.cs
new file mode 100644
index 0000000..65a0395
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/EntityBase.cs
@@ -0,0 +1,142 @@
1using System.Collections.Generic;
2using Axiom.Math;
3using libsecondlife;
4
5namespace OpenSim.Region.Environment.Scenes
6{
7 public abstract class EntityBase
8 {
9 public LLUUID uuid;
10
11 protected List<EntityBase> children;
12
13 protected Scene m_world;
14 protected string m_name;
15
16 /// <summary>
17 ///
18 /// </summary>
19 public virtual string Name
20 {
21 get { return m_name; }
22 set { m_name = value; }
23 }
24
25 protected LLVector3 m_pos;
26 /// <summary>
27 ///
28 /// </summary>
29 public virtual LLVector3 Pos
30 {
31 get
32 {
33 return m_pos;
34 }
35 set
36 {
37 m_pos = value;
38 }
39 }
40
41 public LLVector3 m_velocity;
42
43 /// <summary>
44 ///
45 /// </summary>
46 public virtual LLVector3 Velocity
47 {
48 get
49 {
50 return m_velocity;
51 }
52 set
53 {
54 m_velocity = value;
55 }
56 }
57
58 protected Quaternion m_rotation = new Quaternion(0,0,1,0);
59
60 public virtual Quaternion Rotation
61 {
62 get
63 {
64 return m_rotation;
65 }
66 set
67 {
68 m_rotation = value;
69 }
70 }
71
72 protected uint m_localId;
73
74 public uint LocalId
75 {
76 get { return m_localId; }
77 set { m_localId = value; }
78 }
79
80 /// <summary>
81 /// Creates a new Entity (should not occur on it's own)
82 /// </summary>
83 public EntityBase()
84 {
85 uuid = new LLUUID();
86
87 m_pos = new LLVector3();
88 m_velocity = new LLVector3();
89 Rotation = new Quaternion();
90 m_name = "(basic entity)";
91 children = new List<EntityBase>();
92 }
93
94 /// <summary>
95 ///
96 /// </summary>
97 public virtual void updateMovement()
98 {
99 foreach (EntityBase child in children)
100 {
101 child.updateMovement();
102 }
103 }
104
105 /// <summary>
106 /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
107 /// </summary>
108 public virtual void update()
109 {
110 // Do any per-frame updates needed that are applicable to every type of entity
111 foreach (EntityBase child in children)
112 {
113 child.update();
114 }
115 }
116
117 /// <summary>
118 /// Called at a set interval to inform entities that they should back themsleves up to the DB
119 /// </summary>
120 public virtual void BackUp()
121 {
122
123 }
124
125 /// <summary>
126 /// Copies the entity
127 /// </summary>
128 /// <returns></returns>
129 public virtual EntityBase Copy()
130 {
131 return (EntityBase)this.MemberwiseClone();
132 }
133
134 /// <summary>
135 /// Infoms the entity that the land (heightmap) has changed
136 /// </summary>
137 public virtual void LandRenegerated()
138 {
139
140 }
141 }
142}
diff --git a/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs
new file mode 100644
index 0000000..7c3a033
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs
@@ -0,0 +1,14 @@
1using libsecondlife;
2using libsecondlife.Packets;
3using OpenSim.Framework.Interfaces;
4
5namespace OpenSim.Region.Environment.Scenes
6{
7 public interface IScenePresenceBody
8 {
9 void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation);
10 void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam);
11 void SendOurAppearance(IClientAPI OurClient);
12 void SendAppearanceToOtherAgent(ScenePresence avatarInfo);
13 }
14}
diff --git a/OpenSim/Region/Environment/Scenes/Primitive.cs b/OpenSim/Region/Environment/Scenes/Primitive.cs
new file mode 100644
index 0000000..d23a569
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Primitive.cs
@@ -0,0 +1,594 @@
1using System;
2using System.Collections.Generic;
3using Axiom.Math;
4using libsecondlife;
5using libsecondlife.Packets;
6using OpenSim.Framework.Interfaces;
7using OpenSim.Framework.Inventory;
8using OpenSim.Framework.Types;
9
10namespace OpenSim.Region.Environment.Scenes
11{
12 public class Primitive : EntityBase
13 {
14 private const uint FULL_MASK_PERMISSIONS = 2147483647;
15
16 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
17 private ulong m_regionHandle;
18 private byte updateFlag = 0;
19 private uint m_flags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128;
20
21 private Dictionary<LLUUID, InventoryItem> inventoryItems;
22
23 private string m_description = "";
24
25 public string SitName = "";
26 public string TouchName = "";
27 public string Text = "";
28
29 public LLUUID CreatorID;
30 public LLUUID OwnerID;
31 public LLUUID LastOwnerID;
32 public Int32 CreationDate;
33
34 public uint ParentID = 0;
35
36 public uint OwnerMask = FULL_MASK_PERMISSIONS;
37 public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
38 public uint GroupMask = FULL_MASK_PERMISSIONS;
39 public uint EveryoneMask = FULL_MASK_PERMISSIONS;
40 public uint BaseMask = FULL_MASK_PERMISSIONS;
41
42 private PrimitiveBaseShape m_Shape;
43
44 public SceneObject m_RootParent;
45 public bool m_isRootPrim;
46 public EntityBase m_Parent;
47
48 #region Properties
49 /// <summary>
50 /// If rootprim, will return world position
51 /// otherwise will return local offset from rootprim
52 /// </summary>
53 public override LLVector3 Pos
54 {
55 get
56 {
57 if (m_isRootPrim)
58 {
59 //if we are rootprim then our offset should be zero
60 return this.m_pos + m_Parent.Pos;
61 }
62 else
63 {
64 return this.m_pos;
65 }
66 }
67 set
68 {
69 if (m_isRootPrim)
70 {
71 m_Parent.Pos = value;
72 }
73 this.m_pos = value - m_Parent.Pos;
74 }
75
76 }
77
78 public LLVector3 WorldPos
79 {
80 get
81 {
82 if (!this.m_isRootPrim)
83 {
84 Primitive parentPrim = (Primitive)this.m_Parent;
85 Axiom.Math.Vector3 offsetPos = new Vector3(this.m_pos.X, this.m_pos.Y, this.m_pos.Z);
86 offsetPos = parentPrim.Rotation * offsetPos;
87 return parentPrim.WorldPos + new LLVector3(offsetPos.x, offsetPos.y, offsetPos.z);
88 }
89 else
90 {
91 return this.Pos;
92 }
93 }
94 }
95
96 public string Description
97 {
98 get
99 {
100 return this.m_description;
101 }
102 set
103 {
104 this.m_description = value;
105 }
106 }
107
108 public LLVector3 Scale
109 {
110 set
111 {
112 this.m_Shape.Scale = value;
113 }
114 get
115 {
116 return this.m_Shape.Scale;
117 }
118 }
119 #endregion
120
121 #region Constructors
122 /// <summary>
123 ///
124 /// </summary>
125 /// <param name="regionHandle"></param>
126 /// <param name="world"></param>
127 /// <param name="addPacket"></param>
128 /// <param name="ownerID"></param>
129 /// <param name="localID"></param>
130 /// <param name="isRoot"></param>
131 /// <param name="parent"></param>
132 /// <param name="rootObject"></param>
133 public Primitive(ulong regionHandle, Scene world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID, bool isRoot, EntityBase parent, SceneObject rootObject)
134 {
135 m_regionHandle = regionHandle;
136 m_world = world;
137 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
138 this.m_Parent = parent;
139 this.m_isRootPrim = isRoot;
140 this.m_RootParent = rootObject;
141 this.CreateFromPacket(addPacket, ownerID, localID);
142 this.Rotation = Axiom.Math.Quaternion.Identity;
143 }
144
145 /// <summary>
146 ///
147 /// </summary>
148 /// <remarks>Empty constructor for duplication</remarks>
149 public Primitive()
150 {
151
152 }
153
154 #endregion
155
156 #region Duplication
157
158 public Primitive Copy(EntityBase parent, SceneObject rootParent)
159 {
160 Primitive dupe = (Primitive)this.MemberwiseClone();
161 // TODO: Copy this properly.
162 dupe.inventoryItems = this.inventoryItems;
163 dupe.m_Parent = parent;
164 dupe.m_RootParent = rootParent;
165 // TODO: Copy this properly.
166 dupe.m_Shape = this.m_Shape;
167
168 uint newLocalID = this.m_world.PrimIDAllocate();
169 dupe.LocalId = newLocalID;
170
171 dupe.Scale = new LLVector3(this.Scale.X, this.Scale.Y, this.Scale.Z);
172 dupe.Rotation = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
173 dupe.Pos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
174
175 return dupe;
176 }
177
178 #endregion
179
180
181 #region Override from EntityBase
182 /// <summary>
183 ///
184 /// </summary>
185 public override void update()
186 {
187 if (this.updateFlag == 1) // is a new prim just been created/reloaded or has major changes
188 {
189 this.SendFullUpdateToAllClients();
190 this.updateFlag = 0;
191 }
192 if (this.updateFlag == 2) //some change has been made so update the clients
193 {
194 this.SendTerseUpdateToALLClients();
195 this.updateFlag = 0;
196 }
197
198 foreach (EntityBase child in children)
199 {
200 child.update();
201 }
202 }
203 #endregion
204
205 #region Setup
206 /// <summary>
207 ///
208 /// </summary>
209 /// <param name="addPacket"></param>
210 /// <param name="ownerID"></param>
211 /// <param name="localID"></param>
212 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
213 {
214 this.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
215 this.OwnerID = ownerID;
216 this.CreatorID = this.OwnerID;
217 this.LastOwnerID = LLUUID.Zero;
218 this.Pos = addPacket.ObjectData.RayEnd;
219 this.uuid = LLUUID.Random();
220 this.m_localId = (uint)(localID);
221
222 PrimitiveBaseShape pShape = new PrimitiveBaseShape();
223 this.m_Shape = pShape;
224
225 pShape.PCode = addPacket.ObjectData.PCode;
226 pShape.PathBegin = addPacket.ObjectData.PathBegin;
227 pShape.PathEnd = addPacket.ObjectData.PathEnd;
228 pShape.PathScaleX = addPacket.ObjectData.PathScaleX;
229 pShape.PathScaleY = addPacket.ObjectData.PathScaleY;
230 pShape.PathShearX = addPacket.ObjectData.PathShearX;
231 pShape.PathShearY = addPacket.ObjectData.PathShearY;
232 pShape.PathSkew = addPacket.ObjectData.PathSkew;
233 pShape.ProfileBegin = addPacket.ObjectData.ProfileBegin;
234 pShape.ProfileEnd = addPacket.ObjectData.ProfileEnd;
235 pShape.Scale = addPacket.ObjectData.Scale;
236 pShape.PathCurve = addPacket.ObjectData.PathCurve;
237 pShape.ProfileCurve = addPacket.ObjectData.ProfileCurve;
238 pShape.ProfileHollow = addPacket.ObjectData.ProfileHollow;
239 pShape.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
240 pShape.PathRevolutions = addPacket.ObjectData.PathRevolutions;
241 pShape.PathTaperX = addPacket.ObjectData.PathTaperX;
242 pShape.PathTaperY = addPacket.ObjectData.PathTaperY;
243 pShape.PathTwist = addPacket.ObjectData.PathTwist;
244 pShape.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
245
246 this.updateFlag = 1;
247 }
248 #endregion
249
250 #region Linking / unlinking
251 /// <summary>
252 ///
253 /// </summary>
254 /// <param name="linkObject"></param>
255 public void AddNewChildren(SceneObject linkObject)
256 {
257 // Console.WriteLine("linking new prims " + linkObject.rootLocalID + " to me (" + this.LocalId + ")");
258 //TODO check permissions
259 this.children.Add(linkObject.rootPrimitive);
260 linkObject.rootPrimitive.SetNewParent(this, this.m_RootParent);
261
262 this.m_world.DeleteEntity(linkObject.rootUUID);
263 linkObject.DeleteAllChildren();
264 }
265
266 /// <summary>
267 ///
268 /// </summary>
269 /// <param name="newParent"></param>
270 /// <param name="rootParent"></param>
271 public void SetNewParent(Primitive newParent, SceneObject rootParent)
272 {
273 LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
274 this.m_isRootPrim = false;
275 this.m_Parent = newParent;
276 this.ParentID = newParent.LocalId;
277 this.m_RootParent = rootParent;
278 this.m_RootParent.AddChildToList(this);
279 this.Pos = oldPos;
280 Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
281 axPos = this.m_Parent.Rotation.Inverse() * axPos;
282 this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
283 Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
284 this.Rotation = this.m_Parent.Rotation.Inverse() * this.Rotation;
285 this.updateFlag = 1;
286
287 foreach (Primitive child in children)
288 {
289 child.SetRootParent(rootParent, newParent, oldPos, oldRot);
290 }
291 children.Clear();
292
293
294 }
295
296 /// <summary>
297 ///
298 /// </summary>
299 /// <param name="newRoot"></param>
300 public void SetRootParent(SceneObject newRoot , Primitive newParent, LLVector3 oldParentPosition, Axiom.Math.Quaternion oldParentRotation)
301 {
302 LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
303 Axiom.Math.Vector3 axOldPos = new Vector3(oldPos.X, oldPos.Y, oldPos.Z);
304 axOldPos = oldParentRotation * axOldPos;
305 oldPos = new LLVector3(axOldPos.x, axOldPos.y, axOldPos.z);
306 oldPos += oldParentPosition;
307 Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
308 this.m_isRootPrim = false;
309 this.m_Parent = newParent;
310 this.ParentID = newParent.LocalId;
311 newParent.AddToChildrenList(this);
312 this.m_RootParent = newRoot;
313 this.m_RootParent.AddChildToList(this);
314 this.Pos = oldPos;
315 Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
316 axPos = this.m_Parent.Rotation.Inverse() * axPos;
317 this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
318 this.Rotation = oldParentRotation * this.Rotation;
319 this.Rotation = this.m_Parent.Rotation.Inverse()* this.Rotation ;
320 this.updateFlag = 1;
321 foreach (Primitive child in children)
322 {
323 child.SetRootParent(newRoot, newParent, oldPos, oldRot);
324 }
325 children.Clear();
326 }
327
328 /// <summary>
329 ///
330 /// </summary>
331 /// <param name="offset"></param>
332 public void AddOffsetToChildren(LLVector3 offset)
333 {
334 foreach (Primitive prim in this.children)
335 {
336 prim.m_pos += offset;
337 prim.updateFlag = 2;
338 }
339 }
340
341 /// <summary>
342 ///
343 /// </summary>
344 /// <param name="prim"></param>
345 public void AddToChildrenList(Primitive prim)
346 {
347 this.children.Add(prim);
348 }
349 #endregion
350
351 #region Resizing/Scale
352 /// <summary>
353 ///
354 /// </summary>
355 /// <param name="scale"></param>
356 public void ResizeGoup(LLVector3 scale)
357 {
358 LLVector3 offset = (scale - this.m_Shape.Scale);
359 offset.X /= 2;
360 offset.Y /= 2;
361 offset.Z /= 2;
362 if (this.m_isRootPrim)
363 {
364 this.m_Parent.Pos += offset;
365 }
366 else
367 {
368 this.m_pos += offset;
369 }
370
371 this.AddOffsetToChildren(new LLVector3(-offset.X, -offset.Y, -offset.Z));
372 this.m_Shape.Scale = scale;
373
374 this.updateFlag = 1;
375 }
376 #endregion
377
378 #region Position
379 /// <summary>
380 ///
381 /// </summary>
382 /// <param name="pos"></param>
383 public void UpdateGroupPosition(LLVector3 pos)
384 {
385 LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
386
387 this.Pos = newPos;
388 this.updateFlag = 2;
389 }
390
391 /// <summary>
392 ///
393 /// </summary>
394 /// <param name="pos"></param>
395 public void UpdateSinglePosition(LLVector3 pos)
396 {
397 // Console.WriteLine("updating single prim position");
398 if (this.m_isRootPrim)
399 {
400 LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
401 LLVector3 oldPos = new LLVector3(Pos.X, Pos.Y, Pos.Z);
402 LLVector3 diff = oldPos - newPos;
403 Axiom.Math.Vector3 axDiff = new Vector3(diff.X, diff.Y, diff.Z);
404 axDiff = this.Rotation.Inverse() * axDiff;
405 diff.X = axDiff.x;
406 diff.Y = axDiff.y;
407 diff.Z = axDiff.z;
408 this.Pos = newPos;
409
410 foreach (Primitive prim in this.children)
411 {
412 prim.m_pos += diff;
413 prim.updateFlag = 2;
414 }
415 this.updateFlag = 2;
416 }
417 else
418 {
419 LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
420 this.m_pos = newPos;
421 this.updateFlag = 2;
422 }
423 }
424
425 #endregion
426
427 #region Rotation
428 /// <summary>
429 ///
430 /// </summary>
431 /// <param name="rot"></param>
432 public void UpdateGroupRotation(LLQuaternion rot)
433 {
434 this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
435 this.updateFlag = 2;
436
437 }
438
439 /// <summary>
440 ///
441 /// </summary>
442 /// <param name="pos"></param>
443 /// <param name="rot"></param>
444 public void UpdateGroupMouseRotation(LLVector3 pos, LLQuaternion rot)
445 {
446 this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
447 this.Pos = pos;
448 this.updateFlag = 2;
449 }
450
451 /// <summary>
452 ///
453 /// </summary>
454 /// <param name="rot"></param>
455 public void UpdateSingleRotation(LLQuaternion rot)
456 {
457 //Console.WriteLine("updating single prim rotation");
458 Axiom.Math.Quaternion axRot = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
459 Axiom.Math.Quaternion oldParentRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
460 this.Rotation = axRot;
461 foreach (Primitive prim in this.children)
462 {
463 Axiom.Math.Vector3 axPos = new Vector3(prim.m_pos.X, prim.m_pos.Y, prim.m_pos.Z);
464 axPos = oldParentRot * axPos;
465 axPos = axRot.Inverse() * axPos;
466 prim.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
467 prim.Rotation = oldParentRot * prim.Rotation ;
468 prim.Rotation = axRot.Inverse()* prim.Rotation;
469 prim.updateFlag = 2;
470 }
471 this.updateFlag = 2;
472 }
473 #endregion
474
475 #region Shape
476 /// <summary>
477 ///
478 /// </summary>
479 /// <param name="shapeBlock"></param>
480 public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
481 {
482 this.m_Shape.PathBegin = shapeBlock.PathBegin;
483 this.m_Shape.PathEnd = shapeBlock.PathEnd;
484 this.m_Shape.PathScaleX = shapeBlock.PathScaleX;
485 this.m_Shape.PathScaleY = shapeBlock.PathScaleY;
486 this.m_Shape.PathShearX = shapeBlock.PathShearX;
487 this.m_Shape.PathShearY = shapeBlock.PathShearY;
488 this.m_Shape.PathSkew = shapeBlock.PathSkew;
489 this.m_Shape.ProfileBegin = shapeBlock.ProfileBegin;
490 this.m_Shape.ProfileEnd = shapeBlock.ProfileEnd;
491 this.m_Shape.PathCurve = shapeBlock.PathCurve;
492 this.m_Shape.ProfileCurve = shapeBlock.ProfileCurve;
493 this.m_Shape.ProfileHollow = shapeBlock.ProfileHollow;
494 this.m_Shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
495 this.m_Shape.PathRevolutions = shapeBlock.PathRevolutions;
496 this.m_Shape.PathTaperX = shapeBlock.PathTaperX;
497 this.m_Shape.PathTaperY = shapeBlock.PathTaperY;
498 this.m_Shape.PathTwist = shapeBlock.PathTwist;
499 this.m_Shape.PathTwistBegin = shapeBlock.PathTwistBegin;
500 this.updateFlag = 1;
501 }
502 #endregion
503
504 #region Client Update Methods
505
506 /// <summary>
507 ///
508 /// </summary>
509 /// <param name="remoteClient"></param>
510 public void SendFullUpdateForAllChildren(IClientAPI remoteClient)
511 {
512 this.SendFullUpdateToClient(remoteClient);
513 for (int i = 0; i < this.children.Count; i++)
514 {
515 if (this.children[i] is Primitive)
516 {
517 ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient);
518 }
519 }
520 }
521
522 /// <summary>
523 ///
524 /// </summary>
525 /// <param name="remoteClient"></param>
526 public void SendFullUpdateToClient(IClientAPI remoteClient)
527 {
528 LLVector3 lPos;
529 lPos = this.Pos;
530 LLQuaternion lRot;
531 lRot = new LLQuaternion(this.Rotation.x, this.Rotation.y, this.Rotation.z, this.Rotation.w);
532
533 remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.LocalId, this.m_Shape, lPos, lRot, new LLUUID("00000000-0000-0000-9999-000000000005"), this.m_flags, this.uuid, this.OwnerID, this.Text, this.ParentID);
534 }
535
536 /// <summary>
537 ///
538 /// </summary>
539 public void SendFullUpdateToAllClients()
540 {
541 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
542 for (int i = 0; i < avatars.Count; i++)
543 {
544 this.SendFullUpdateToClient(avatars[i].ControllingClient);
545 }
546 }
547
548 /// <summary>
549 ///
550 /// </summary>
551 /// <param name="remoteClient"></param>
552 public void SendTerseUpdateForAllChildren(IClientAPI remoteClient)
553 {
554 this.SendTerseUpdateToClient(remoteClient);
555 for (int i = 0; i < this.children.Count; i++)
556 {
557 if (this.children[i] is Primitive)
558 {
559 ((Primitive)this.children[i]).SendTerseUpdateForAllChildren(remoteClient);
560 }
561 }
562 }
563
564 /// <summary>
565 ///
566 /// </summary>
567 /// <param name="RemoteClient"></param>
568 public void SendTerseUpdateToClient(IClientAPI RemoteClient)
569 {
570 LLVector3 lPos;
571 Quaternion lRot;
572
573 lPos = this.Pos;
574 lRot = this.Rotation;
575
576 LLQuaternion mRot = new LLQuaternion(lRot.x, lRot.y, lRot.z, lRot.w);
577 RemoteClient.SendPrimTerseUpdate(this.m_regionHandle, 64096, this.LocalId, lPos, mRot);
578 }
579
580 /// <summary>
581 ///
582 /// </summary>
583 public void SendTerseUpdateToALLClients()
584 {
585 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
586 for (int i = 0; i < avatars.Count; i++)
587 {
588 this.SendTerseUpdateToClient(avatars[i].ControllingClient);
589 }
590 }
591
592 #endregion
593 }
594}
diff --git a/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs b/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs
new file mode 100644
index 0000000..91a4162
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/PrimitiveOld.cs
@@ -0,0 +1,583 @@
1
2/*
3* Copyright (c) Contributors, http://www.openmetaverse.org/
4* See CONTRIBUTORS.TXT for a full list of copyright holders.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the OpenSim Project nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29using System;
30using System.Collections.Generic;
31using System.Text;
32using Axiom.Math;
33using libsecondlife;
34using libsecondlife.Packets;
35using OpenSim.Framework.Interfaces;
36using OpenSim.Framework.Inventory;
37using OpenSim.Framework.Types;
38using OpenSim.Physics.Manager;
39
40namespace OpenSim.Region.Environment.Scenes
41{
42 public class PrimitiveOld : Entity
43 {
44 internal PrimData primData;
45 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
46 // private ClientManager m_clientThreads;
47 private ulong m_regionHandle;
48 private const uint FULL_MASK_PERMISSIONS = 2147483647;
49 private bool physicsEnabled = false;
50 private byte updateFlag = 0;
51 private uint flags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128;
52
53 private Dictionary<LLUUID, InventoryItem> inventoryItems;
54
55 #region Properties
56
57 public LLVector3 Scale
58 {
59 set
60 {
61 this.primData.Scale = value;
62 //this.dirtyFlag = true;
63 }
64 get
65 {
66 return this.primData.Scale;
67 }
68 }
69
70 public PhysicsActor PhysActor
71 {
72 set
73 {
74 this._physActor = value;
75 }
76 }
77
78 public override LLVector3 Pos
79 {
80 get
81 {
82 return base.Pos;
83 }
84 set
85 {
86 base.Pos = value;
87 }
88 }
89 #endregion
90
91 /// <summary>
92 ///
93 /// </summary>
94 /// <param name="clientThreads"></param>
95 /// <param name="regionHandle"></param>
96 /// <param name="world"></param>
97 public PrimitiveOld( ulong regionHandle, Scene world)
98 {
99 // m_clientThreads = clientThreads;
100 m_regionHandle = regionHandle;
101 m_world = world;
102 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
103 }
104
105 /// <summary>
106 ///
107 /// </summary>
108 /// <param name="regionHandle"></param>
109 /// <param name="world"></param>
110 /// <param name="addPacket"></param>
111 /// <param name="ownerID"></param>
112 /// <param name="localID"></param>
113 public PrimitiveOld(ulong regionHandle, Scene world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
114 {
115 // m_clientThreads = clientThreads;
116 m_regionHandle = regionHandle;
117 m_world = world;
118 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
119 this.CreateFromPacket(addPacket, ownerID, localID);
120 }
121
122 /// <summary>
123 ///
124 /// </summary>
125 /// <param name="clientThreads"></param>
126 /// <param name="regionHandle"></param>
127 /// <param name="world"></param>
128 /// <param name="owner"></param>
129 /// <param name="fullID"></param>
130 /// <param name="localID"></param>
131 public PrimitiveOld( ulong regionHandle, Scene world, LLUUID owner, LLUUID fullID, uint localID)
132 {
133 // m_clientThreads = clientThreads;
134 m_regionHandle = regionHandle;
135 m_world = world;
136 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
137 this.primData = new PrimData();
138 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
139 this.primData.OwnerID = owner;
140 this.primData.FullID = this.uuid = fullID;
141 this.primData.LocalID = m_localId = localID;
142 }
143
144 /// <summary>
145 /// Constructor to create a default cube
146 /// </summary>
147 /// <param name="clientThreads"></param>
148 /// <param name="regionHandle"></param>
149 /// <param name="world"></param>
150 /// <param name="owner"></param>
151 /// <param name="localID"></param>
152 /// <param name="position"></param>
153 public PrimitiveOld( ulong regionHandle, Scene world, LLUUID owner, uint localID, LLVector3 position)
154 {
155 //m_clientThreads = clientThreads;
156 m_regionHandle = regionHandle;
157 m_world = world;
158 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
159 this.primData = PrimData.DefaultCube();
160 this.primData.OwnerID = owner;
161 this.primData.LocalID = m_localId = localID;
162 this.Pos = this.primData.Position = position;
163
164 this.updateFlag = 1;
165 }
166
167 /// <summary>
168 ///
169 /// </summary>
170 /// <returns></returns>
171 public byte[] GetByteArray()
172 {
173 byte[] result = null;
174 List<byte[]> dataArrays = new List<byte[]>();
175 dataArrays.Add(primData.ToBytes());
176 foreach (Entity child in children)
177 {
178 if (child is PrimitiveOld)
179 {
180 dataArrays.Add(((PrimitiveOld)child).GetByteArray());
181 }
182 }
183 byte[] primstart = Helpers.StringToField("<Prim>");
184 byte[] primend = Helpers.StringToField("</Prim>");
185 int totalLength = primstart.Length + primend.Length;
186 for (int i = 0; i < dataArrays.Count; i++)
187 {
188 totalLength += dataArrays[i].Length;
189 }
190
191 result = new byte[totalLength];
192 int arraypos = 0;
193 Array.Copy(primstart, 0, result, 0, primstart.Length);
194 arraypos += primstart.Length;
195 for (int i = 0; i < dataArrays.Count; i++)
196 {
197 Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length);
198 arraypos += dataArrays[i].Length;
199 }
200 Array.Copy(primend, 0, result, arraypos, primend.Length);
201
202 return result;
203 }
204
205 #region Overridden Methods
206
207 /// <summary>
208 ///
209 /// </summary>
210 public override void update()
211 {
212 if (this.updateFlag == 1) // is a new prim just been created/reloaded
213 {
214 this.SendFullUpdateToAllClients();
215 this.updateFlag = 0;
216 }
217 if (this.updateFlag == 2) //some change has been made so update the clients
218 {
219 this.SendTerseUpdateToALLClients();
220 this.updateFlag = 0;
221 }
222 }
223
224 /// <summary>
225 ///
226 /// </summary>
227 public override void BackUp()
228 {
229
230 }
231
232 #endregion
233
234 #region Packet handlers
235
236 /// <summary>
237 ///
238 /// </summary>
239 /// <param name="pos"></param>
240 public void UpdatePosition(LLVector3 pos)
241 {
242 this.Pos = new LLVector3(pos.X, pos.Y, pos.Z);
243 this.updateFlag = 2;
244 }
245
246 /// <summary>
247 ///
248 /// </summary>
249 /// <param name="addPacket"></param>
250 public void UpdateShape(ObjectShapePacket.ObjectDataBlock updatePacket)
251 {
252 this.primData.PathBegin = updatePacket.PathBegin;
253 this.primData.PathEnd = updatePacket.PathEnd;
254 this.primData.PathScaleX = updatePacket.PathScaleX;
255 this.primData.PathScaleY = updatePacket.PathScaleY;
256 this.primData.PathShearX = updatePacket.PathShearX;
257 this.primData.PathShearY = updatePacket.PathShearY;
258 this.primData.PathSkew = updatePacket.PathSkew;
259 this.primData.ProfileBegin = updatePacket.ProfileBegin;
260 this.primData.ProfileEnd = updatePacket.ProfileEnd;
261 this.primData.PathCurve = updatePacket.PathCurve;
262 this.primData.ProfileCurve = updatePacket.ProfileCurve;
263 this.primData.ProfileHollow = updatePacket.ProfileHollow;
264 this.primData.PathRadiusOffset = updatePacket.PathRadiusOffset;
265 this.primData.PathRevolutions = updatePacket.PathRevolutions;
266 this.primData.PathTaperX = updatePacket.PathTaperX;
267 this.primData.PathTaperY = updatePacket.PathTaperY;
268 this.primData.PathTwist = updatePacket.PathTwist;
269 this.primData.PathTwistBegin = updatePacket.PathTwistBegin;
270 }
271
272 /// <summary>
273 ///
274 /// </summary>
275 /// <param name="tex"></param>
276 public void UpdateTexture(byte[] tex)
277 {
278 this.primData.TextureEntry = tex;
279 }
280
281 /// <summary>
282 ///
283 /// </summary>
284 /// <param name="pack"></param>
285 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
286 {
287
288 }
289
290 /// <summary>
291 ///
292 /// </summary>
293 /// <param name="prim"></param>
294 public void AssignToParent(PrimitiveOld prim)
295 {
296
297 }
298
299 #endregion
300
301 # region Inventory Methods
302 /// <summary>
303 ///
304 /// </summary>
305 /// <param name="item"></param>
306 /// <returns></returns>
307 public bool AddToInventory(InventoryItem item)
308 {
309 return false;
310 }
311
312 /// <summary>
313 ///
314 /// </summary>
315 /// <param name="itemID"></param>
316 /// <returns></returns>
317 public InventoryItem RemoveFromInventory(LLUUID itemID)
318 {
319 return null;
320 }
321
322 /// <summary>
323 ///
324 /// </summary>
325 /// <param name="simClient"></param>
326 /// <param name="packet"></param>
327 public void RequestInventoryInfo(IClientAPI simClient, RequestTaskInventoryPacket packet)
328 {
329
330 }
331
332 /// <summary>
333 ///
334 /// </summary>
335 /// <param name="simClient"></param>
336 /// <param name="xferID"></param>
337 public void RequestXferInventory(IClientAPI simClient, ulong xferID)
338 {
339 //will only currently work if the total size of the inventory data array is under about 1000 bytes
340 SendXferPacketPacket send = new SendXferPacketPacket();
341
342 send.XferID.ID = xferID;
343 send.XferID.Packet = 1 + 2147483648;
344 send.DataPacket.Data = this.ConvertInventoryToBytes();
345
346 simClient.OutPacket(send);
347 }
348
349 /// <summary>
350 ///
351 /// </summary>
352 /// <returns></returns>
353 public byte[] ConvertInventoryToBytes()
354 {
355 Encoding enc = Encoding.ASCII;
356 byte[] result = new byte[0];
357 List<byte[]> inventoryData = new List<byte[]>();
358 int totallength = 0;
359 foreach (InventoryItem invItem in inventoryItems.Values)
360 {
361 byte[] data = enc.GetBytes(invItem.ExportString());
362 inventoryData.Add(data);
363 totallength += data.Length;
364 }
365 //TODO: copy arrays into the single result array
366
367 return result;
368 }
369
370 /// <summary>
371 ///
372 /// </summary>
373 /// <param name="data"></param>
374 public void CreateInventoryFromBytes(byte[] data)
375 {
376
377 }
378
379 #endregion
380
381 #region Update viewers Methods
382
383 /// <summary>
384 ///
385 /// </summary>
386 /// <param name="remoteClient"></param>
387 public void SendFullUpdateForAllChildren(IClientAPI remoteClient)
388 {
389 this.SendFullUpdateToClient(remoteClient);
390 for (int i = 0; i < this.children.Count; i++)
391 {
392 if (this.children[i] is PrimitiveOld)
393 {
394 ((PrimitiveOld)this.children[i]).SendFullUpdateForAllChildren(remoteClient);
395 }
396 }
397 }
398
399 /// <summary>
400 ///
401 /// </summary>
402 /// <param name="remoteClient"></param>
403 public void SendFullUpdateToClient(IClientAPI remoteClient)
404 {
405 LLVector3 lPos;
406 if (this._physActor != null && this.physicsEnabled)
407 {
408 PhysicsVector pPos = this._physActor.Position;
409 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
410 }
411 else
412 {
413 lPos = this.Pos;
414 }
415
416 remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.LocalId, this.primData, lPos, new LLUUID("00000000-0000-0000-9999-000000000005"), this.flags);
417 }
418
419 /// <summary>
420 ///
421 /// </summary>
422 public void SendFullUpdateToAllClients()
423 {
424 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
425 for (int i = 0; i < avatars.Count; i++)
426 {
427 this.SendFullUpdateToClient(avatars[i].ControllingClient);
428 }
429 }
430
431 /// <summary>
432 ///
433 /// </summary>
434 /// <param name="RemoteClient"></param>
435 public void SendTerseUpdateToClient(IClientAPI RemoteClient)
436 {
437 LLVector3 lPos;
438 Quaternion lRot;
439 if (this._physActor != null && this.physicsEnabled) //is this needed ? doesn't the property fields do this for us?
440 {
441 PhysicsVector pPos = this._physActor.Position;
442 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
443 lRot = this._physActor.Orientation;
444 }
445 else
446 {
447 lPos = this.Pos;
448 lRot = this.Rotation;
449 }
450 LLQuaternion mRot = new LLQuaternion(lRot.x, lRot.y, lRot.z, lRot.w);
451 RemoteClient.SendPrimTerseUpdate(this.m_regionHandle, 64096, this.LocalId, lPos, mRot);
452 }
453
454 /// <summary>
455 ///
456 /// </summary>
457 public void SendTerseUpdateToALLClients()
458 {
459 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
460 for (int i = 0; i < avatars.Count; i++)
461 {
462 this.SendTerseUpdateToClient(avatars[i].ControllingClient);
463 }
464 }
465
466 #endregion
467
468 #region Create Methods
469
470 /// <summary>
471 ///
472 /// </summary>
473 /// <param name="addPacket"></param>
474 /// <param name="ownerID"></param>
475 /// <param name="localID"></param>
476 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
477 {
478 PrimData PData = new PrimData();
479 this.primData = PData;
480 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
481
482 PData.OwnerID = ownerID;
483 PData.PCode = addPacket.ObjectData.PCode;
484 PData.PathBegin = addPacket.ObjectData.PathBegin;
485 PData.PathEnd = addPacket.ObjectData.PathEnd;
486 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
487 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
488 PData.PathShearX = addPacket.ObjectData.PathShearX;
489 PData.PathShearY = addPacket.ObjectData.PathShearY;
490 PData.PathSkew = addPacket.ObjectData.PathSkew;
491 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
492 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
493 PData.Scale = addPacket.ObjectData.Scale;
494 PData.PathCurve = addPacket.ObjectData.PathCurve;
495 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
496 PData.ParentID = 0;
497 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
498 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
499 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
500 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
501 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
502 PData.PathTwist = addPacket.ObjectData.PathTwist;
503 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
504 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
505 this.primData.FullID = this.uuid = LLUUID.Random();
506 this.primData.LocalID = m_localId = (uint)(localID);
507 this.primData.Position = this.Pos = pos1;
508
509 this.updateFlag = 1;
510 }
511
512 /// <summary>
513 ///
514 /// </summary>
515 /// <param name="data"></param>
516 public void CreateFromBytes(byte[] data)
517 {
518
519 }
520
521 /// <summary>
522 ///
523 /// </summary>
524 /// <param name="primData"></param>
525 public void CreateFromPrimData(PrimData primData)
526 {
527 this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false);
528 }
529
530 /// <summary>
531 ///
532 /// </summary>
533 /// <param name="primData"></param>
534 /// <param name="posi"></param>
535 /// <param name="localID"></param>
536 /// <param name="newprim"></param>
537 public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim)
538 {
539
540 }
541
542 public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
543 {
544 // Console.WriteLine("moving prim to new location " + pos.X + " , " + pos.Y + " , " + pos.Z);
545 this.Pos = pos;
546 this.SendTerseUpdateToALLClients();
547 }
548
549 public void GetProperites(IClientAPI client)
550 {
551 //needs changing
552 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
553 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
554 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
555 proper.ObjectData[0].ItemID = LLUUID.Zero;
556 proper.ObjectData[0].CreationDate = (ulong)primData.CreationDate;
557 proper.ObjectData[0].CreatorID = primData.OwnerID;
558 proper.ObjectData[0].FolderID = LLUUID.Zero;
559 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
560 proper.ObjectData[0].GroupID = LLUUID.Zero;
561 proper.ObjectData[0].InventorySerial = 0;
562 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
563 proper.ObjectData[0].ObjectID = this.uuid;
564 proper.ObjectData[0].OwnerID = primData.OwnerID;
565 proper.ObjectData[0].TouchName = new byte[0];
566 proper.ObjectData[0].TextureID = new byte[0];
567 proper.ObjectData[0].SitName = new byte[0];
568 proper.ObjectData[0].Name = new byte[0];
569 proper.ObjectData[0].Description = new byte[0];
570 proper.ObjectData[0].OwnerMask = primData.OwnerMask;
571 proper.ObjectData[0].NextOwnerMask = primData.NextOwnerMask;
572 proper.ObjectData[0].GroupMask = primData.GroupMask;
573 proper.ObjectData[0].EveryoneMask = primData.EveryoneMask;
574 proper.ObjectData[0].BaseMask = primData.BaseMask;
575
576 client.OutPacket(proper);
577
578 }
579
580 #endregion
581
582 }
583}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
new file mode 100644
index 0000000..69eaa75
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
@@ -0,0 +1,570 @@
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 libsecondlife;
31using libsecondlife.Packets;
32using OpenSim.Framework.Interfaces;
33using OpenSim.Framework.Types;
34
35namespace OpenSim.Region.Environment.Scenes
36{
37 public partial class Scene
38 {
39 /// <summary>
40 /// Modifies terrain using the specified information
41 /// </summary>
42 /// <param name="height">The height at which the user started modifying the terrain</param>
43 /// <param name="seconds">The number of seconds the modify button was pressed</param>
44 /// <param name="brushsize">The size of the brush used</param>
45 /// <param name="action">The action to be performed</param>
46 /// <param name="north">Distance from the north border where the cursor is located</param>
47 /// <param name="west">Distance from the west border where the cursor is located</param>
48 public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west)
49 {
50 // Shiny.
51 double size = (double)(1 << brushsize);
52
53 switch (action)
54 {
55 case 0:
56 // flatten terrain
57 Terrain.flatten(north, west, size, (double)seconds / 100.0);
58 RegenerateTerrain(true, (int)north, (int)west);
59 break;
60 case 1:
61 // raise terrain
62 Terrain.raise(north, west, size, (double)seconds / 100.0);
63 RegenerateTerrain(true, (int)north, (int)west);
64 break;
65 case 2:
66 //lower terrain
67 Terrain.lower(north, west, size, (double)seconds / 100.0);
68 RegenerateTerrain(true, (int)north, (int)west);
69 break;
70 case 3:
71 // smooth terrain
72 Terrain.smooth(north, west, size, (double)seconds / 100.0);
73 RegenerateTerrain(true, (int)north, (int)west);
74 break;
75 case 4:
76 // noise
77 Terrain.noise(north, west, size, (double)seconds / 100.0);
78 RegenerateTerrain(true, (int)north, (int)west);
79 break;
80 case 5:
81 // revert
82 Terrain.revert(north, west, size, (double)seconds / 100.0);
83 RegenerateTerrain(true, (int)north, (int)west);
84 break;
85
86 // CLIENT EXTENSIONS GO HERE
87 case 128:
88 // erode-thermal
89 break;
90 case 129:
91 // erode-aerobic
92 break;
93 case 130:
94 // erode-hydraulic
95 break;
96 }
97 return;
98 }
99
100 /// <summary>
101 ///
102 /// </summary>
103 /// <remarks>Inefficient. TODO: Fixme</remarks>
104 /// <param name="fromAgentID"></param>
105 /// <param name="toAgentID"></param>
106 /// <param name="timestamp"></param>
107 /// <param name="fromAgentName"></param>
108 /// <param name="message"></param>
109 public void InstantMessage(LLUUID fromAgentID, LLUUID toAgentID, uint timestamp, string fromAgentName, string message)
110 {
111 if (this.Avatars.ContainsKey(toAgentID))
112 {
113 if (this.Avatars.ContainsKey(fromAgentID))
114 {
115 // Local sim message
116 ScenePresence avatar = this.Avatars[fromAgentID];
117 avatar.ControllingClient.SendInstantMessage(message, toAgentID);
118 }
119 else
120 {
121 // Message came from a user outside the sim, ignore?
122 }
123 }
124 else
125 {
126 // Grid message
127 }
128 }
129
130 /// <summary>
131 ///
132 /// </summary>
133 /// <param name="message"></param>
134 /// <param name="type"></param>
135 /// <param name="fromPos"></param>
136 /// <param name="fromName"></param>
137 /// <param name="fromAgentID"></param>
138 public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
139 {
140 // Console.WriteLine("Chat message");
141 ScenePresence avatar = null;
142
143 m_clientManager.ForEachClient(delegate(IClientAPI client)
144 {
145 int dis = -1000;
146 if (this.Avatars.ContainsKey(client.AgentId))
147 {
148 avatar = this.Avatars[client.AgentId];
149 // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
150 dis = (int) avatar.Pos.GetDistanceTo(fromPos);
151 //Console.WriteLine("found avatar at " +dis);
152 }
153
154 switch (type)
155 {
156 case 0: // Whisper
157 if ((dis < 10) && (dis > -10))
158 {
159 //should change so the message is sent through the avatar rather than direct to the ClientView
160 client.SendChatMessage(message, type, fromPos, fromName,
161 fromAgentID);
162 }
163 break;
164 case 1: // Say
165 if ((dis < 30) && (dis > -30))
166 {
167 //Console.WriteLine("sending chat");
168 client.SendChatMessage(message, type, fromPos, fromName,
169 fromAgentID);
170 }
171 break;
172 case 2: // Shout
173 if ((dis < 100) && (dis > -100))
174 {
175 client.SendChatMessage(message, type, fromPos, fromName,
176 fromAgentID);
177 }
178 break;
179
180 case 0xff: // Broadcast
181 client.SendChatMessage(message, type, fromPos, fromName,
182 fromAgentID);
183 break;
184 }
185 });
186 }
187
188 /// <summary>
189 ///
190 /// </summary>
191 /// <param name="primAsset"></param>
192 /// <param name="pos"></param>
193 public void RezObject(AssetBase primAsset, LLVector3 pos)
194 {
195
196 }
197
198 /// <summary>
199 ///
200 /// </summary>
201 /// <param name="packet"></param>
202 /// <param name="simClient"></param>
203 public void DeRezObject(Packet packet, IClientAPI simClient)
204 {
205
206 }
207
208 /// <summary>
209 ///
210 /// </summary>
211 /// <param name="remoteClient"></param>
212 public void SendAvatarsToClient(IClientAPI remoteClient)
213 {
214
215 }
216
217 /// <summary>
218 ///
219 /// </summary>
220 /// <param name="originalPrim"></param>
221 /// <param name="offset"></param>
222 /// <param name="flags"></param>
223 public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags)
224 {
225 SceneObject originPrim = null;
226 foreach (EntityBase ent in Entities.Values)
227 {
228 if (ent is SceneObject)
229 {
230 if (((SceneObject)ent).rootLocalID == originalPrim)
231 {
232 originPrim = (SceneObject)ent;
233 break;
234 }
235 }
236 }
237
238 if (originPrim != null)
239 {
240 //SceneObject copy = originPrim.Copy();
241
242 }
243 else
244 {
245 OpenSim.Framework.Console.MainLog.Instance.Warn("Attempted to duplicate nonexistant prim");
246 }
247
248 }
249
250 /// <summary>
251 ///
252 /// </summary>
253 /// <param name="parentPrim"></param>
254 /// <param name="childPrims"></param>
255 public void LinkObjects(uint parentPrim, List<uint> childPrims)
256 {
257 SceneObject parenPrim = null;
258 foreach (EntityBase ent in Entities.Values)
259 {
260 if (ent is SceneObject)
261 {
262 if (((SceneObject)ent).rootLocalID == parentPrim)
263 {
264 parenPrim = (SceneObject)ent;
265 break;
266 }
267 }
268 }
269
270 List<SceneObject> children = new List<SceneObject>();
271 if (parenPrim != null)
272 {
273 for (int i = 0; i < childPrims.Count; i++)
274 {
275 foreach (EntityBase ent in Entities.Values)
276 {
277 if (ent is SceneObject)
278 {
279 if (((SceneObject)ent).rootLocalID == childPrims[i])
280 {
281 children.Add((SceneObject)ent);
282 }
283 }
284 }
285 }
286 }
287
288 foreach (SceneObject sceneObj in children)
289 {
290 parenPrim.AddNewChildPrims(sceneObj);
291 }
292 }
293
294 /// <summary>
295 ///
296 /// </summary>
297 /// <param name="primLocalID"></param>
298 /// <param name="shapeBlock"></param>
299 public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
300 {
301 Primitive prim = null;
302 foreach (EntityBase ent in Entities.Values)
303 {
304 if (ent is SceneObject)
305 {
306 prim = ((SceneObject)ent).HasChildPrim(primLocalID);
307 if (prim != null)
308 {
309 prim.UpdateShape(shapeBlock);
310 break;
311 }
312 }
313 }
314 }
315
316 /// <summary>
317 ///
318 /// </summary>
319 /// <param name="primLocalID"></param>
320 /// <param name="remoteClient"></param>
321 public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
322 {
323 foreach (EntityBase ent in Entities.Values)
324 {
325 if (ent is SceneObject)
326 {
327 if (((SceneObject)ent).rootLocalID == primLocalID)
328 {
329 ((SceneObject)ent).GetProperites(remoteClient);
330 break;
331 }
332 }
333 }
334 }
335
336 /// <summary>
337 ///
338 /// </summary>
339 /// <param name="primLocalID"></param>
340 /// <param name="description"></param>
341 public void PrimDescription(uint primLocalID, string description)
342 {
343 Primitive prim = null;
344 foreach (EntityBase ent in Entities.Values)
345 {
346 if (ent is SceneObject)
347 {
348 prim = ((SceneObject)ent).HasChildPrim(primLocalID);
349 if (prim != null)
350 {
351 prim.Description = description;
352 break;
353 }
354 }
355 }
356 }
357
358 /// <summary>
359 ///
360 /// </summary>
361 /// <param name="primLocalID"></param>
362 /// <param name="description"></param>
363 public void PrimName(uint primLocalID, string name)
364 {
365 Primitive prim = null;
366 foreach (EntityBase ent in Entities.Values)
367 {
368 if (ent is SceneObject)
369 {
370 prim = ((SceneObject)ent).HasChildPrim(primLocalID);
371 if (prim != null)
372 {
373 prim.Name = name;
374 break;
375 }
376 }
377 }
378 }
379
380 public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
381 {
382 Primitive prim = null;
383 foreach (EntityBase ent in Entities.Values)
384 {
385 if (ent is SceneObject)
386 {
387 prim = ((SceneObject)ent).HasChildPrim(objectID);
388 if (prim != null)
389 {
390 ((SceneObject)ent).GrapMovement(offset, pos, remoteClient);
391 break;
392 }
393 }
394 }
395 /*
396 if (this.Entities.ContainsKey(objectID))
397 {
398 if (this.Entities[objectID] is SceneObject)
399 {
400 ((SceneObject)this.Entities[objectID]).GrapMovement(offset, pos, remoteClient);
401 }
402 }*/
403 }
404
405 /// <summary>
406 ///
407 /// </summary>
408 /// <param name="localID"></param>
409 /// <param name="packet"></param>
410 /// <param name="remoteClient"></param>
411 public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
412 {
413
414 }
415
416 /// <summary>
417 ///
418 /// </summary>
419 /// <param name="localID"></param>
420 /// <param name="texture"></param>
421 /// <param name="remoteClient"></param>
422 public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
423 {
424
425 }
426
427 /// <summary>
428 ///
429 /// </summary>
430 /// <param name="localID"></param>
431 /// <param name="pos"></param>
432 /// <param name="remoteClient"></param>
433 public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
434 {
435 Primitive prim = null;
436 foreach (EntityBase ent in Entities.Values)
437 {
438 if (ent is SceneObject)
439 {
440 prim = ((SceneObject)ent).HasChildPrim(localID);
441 if (prim != null)
442 {
443 prim.UpdateGroupPosition(pos);
444 break;
445 }
446 }
447 }
448 }
449
450 public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
451 {
452 Primitive prim = null;
453 foreach (EntityBase ent in Entities.Values)
454 {
455 if (ent is SceneObject)
456 {
457 prim = ((SceneObject)ent).HasChildPrim(localID);
458 if (prim != null)
459 {
460 prim.UpdateSinglePosition(pos);
461 break;
462 }
463 }
464 }
465 }
466
467 /// <summary>
468 ///
469 /// </summary>
470 /// <param name="localID"></param>
471 /// <param name="pos"></param>
472 /// <param name="rot"></param>
473 /// <param name="remoteClient"></param>
474 public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
475 {
476 Primitive prim = null;
477 foreach (EntityBase ent in Entities.Values)
478 {
479 if (ent is SceneObject)
480 {
481 prim = ((SceneObject)ent).HasChildPrim(localID);
482 if (prim != null)
483 {
484 prim.UpdateGroupMouseRotation( pos, rot);
485 break;
486 }
487 }
488 }
489 }
490
491 /// <summary>
492 ///
493 /// </summary>
494 /// <param name="localID"></param>
495 /// <param name="rot"></param>
496 /// <param name="remoteClient"></param>
497 public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
498 {
499 Primitive prim = null;
500 foreach (EntityBase ent in Entities.Values)
501 {
502 if (ent is SceneObject)
503 {
504 prim = ((SceneObject)ent).HasChildPrim(localID);
505 if (prim != null)
506 {
507 prim.UpdateGroupRotation(rot);
508 break;
509 }
510 }
511 }
512 }
513
514 /// <summary>
515 ///
516 /// </summary>
517 /// <param name="localID"></param>
518 /// <param name="rot"></param>
519 /// <param name="remoteClient"></param>
520 public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
521 {
522 //Console.WriteLine("trying to update single prim rotation");
523 Primitive prim = null;
524 foreach (EntityBase ent in Entities.Values)
525 {
526 if (ent is SceneObject)
527 {
528 prim = ((SceneObject)ent).HasChildPrim(localID);
529 if (prim != null)
530 {
531 prim.UpdateSingleRotation(rot);
532 break;
533 }
534 }
535 }
536 }
537
538 /// <summary>
539 ///
540 /// </summary>
541 /// <param name="localID"></param>
542 /// <param name="scale"></param>
543 /// <param name="remoteClient"></param>
544 public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
545 {
546 Primitive prim = null;
547 foreach (EntityBase ent in Entities.Values)
548 {
549 if (ent is SceneObject)
550 {
551 prim = ((SceneObject)ent).HasChildPrim(localID);
552 if (prim != null)
553 {
554 prim.ResizeGoup(scale);
555 break;
556 }
557 }
558 }
559 }
560
561 /// <summary>
562 /// Sends prims to a client
563 /// </summary>
564 /// <param name="RemoteClient">Client to send to</param>
565 public void GetInitialPrims(IClientAPI RemoteClient)
566 {
567
568 }
569 }
570}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
new file mode 100644
index 0000000..d1f6038
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -0,0 +1,806 @@
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.Threading;
31using System.Timers;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Servers;
39using OpenSim.Framework.Types;
40using OpenSim.Physics.Manager;
41using OpenSim.Region.Caches;
42using OpenSim.Region.Environment.Scripting;
43using OpenSim.Region.Terrain;
44using Caps=OpenSim.Region.Capabilities.Caps;
45using Timer=System.Timers.Timer;
46
47namespace OpenSim.Region.Environment.Scenes
48{
49 public delegate bool FilterAvatarList(ScenePresence avatar);
50
51 public partial class Scene : SceneBase, ILocalStorageReceiver
52 {
53 protected Timer m_heartbeatTimer = new Timer();
54 protected Dictionary<LLUUID, ScenePresence> Avatars;
55 protected Dictionary<LLUUID, SceneObject> Prims;
56 private PhysicsScene phyScene;
57 private float timeStep = 0.1f;
58 private Random Rand = new Random();
59 private uint _primCount = 702000;
60 private System.Threading.Mutex _primAllocateMutex = new Mutex(false);
61 private int storageCount;
62 private Mutex updateLock;
63
64 protected AuthenticateSessionsBase authenticateHandler;
65 protected RegionCommsListener regionCommsHost;
66 protected CommunicationsManager commsManager;
67
68 protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
69 protected BaseHttpServer httpListener;
70
71 public ParcelManager parcelManager;
72 public EstateManager estateManager;
73 public EventManager eventManager;
74 public ScriptManager scriptManager;
75
76 #region Properties
77 /// <summary>
78 ///
79 /// </summary>
80 public PhysicsScene PhysScene
81 {
82 set
83 {
84 this.phyScene = value;
85 }
86 get
87 {
88 return (this.phyScene);
89 }
90 }
91
92 #endregion
93
94 #region Constructors
95 /// <summary>
96 /// Creates a new World class, and a region to go with it.
97 /// </summary>
98 /// <param name="clientThreads">Dictionary to contain client threads</param>
99 /// <param name="regionHandle">Region Handle for this region</param>
100 /// <param name="regionName">Region Name for this region</param>
101 public Scene(ClientManager clientManager, RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, BaseHttpServer httpServer)
102 {
103 updateLock = new Mutex(false);
104 this.authenticateHandler = authen;
105 this.commsManager = commsMan;
106 this.assetCache = assetCach;
107 m_clientManager = clientManager;
108 m_regInfo = regInfo;
109 m_regionHandle = m_regInfo.RegionHandle;
110 m_regionName = m_regInfo.RegionName;
111 this.m_datastore = m_regInfo.DataStore;
112 this.RegisterRegionWithComms();
113
114 parcelManager = new ParcelManager(this, this.m_regInfo);
115 estateManager = new EstateManager(this, this.m_regInfo);
116 scriptManager = new ScriptManager(this);
117 eventManager = new EventManager();
118
119 MainLog.Instance.Verbose("World.cs - creating new entitities instance");
120 Entities = new Dictionary<LLUUID, EntityBase>();
121 Avatars = new Dictionary<LLUUID, ScenePresence>();
122 Prims = new Dictionary<LLUUID, SceneObject>();
123
124 MainLog.Instance.Verbose("World.cs - creating LandMap");
125 Terrain = new TerrainEngine();
126
127 ScenePresence.LoadAnims();
128 this.httpListener = httpServer;
129 }
130 #endregion
131
132 /// <summary>
133 ///
134 /// </summary>
135 public void StartTimer()
136 {
137 m_heartbeatTimer.Enabled = true;
138 m_heartbeatTimer.Interval = 100;
139 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
140 }
141
142
143 #region Update Methods
144
145
146 /// <summary>
147 /// Performs per-frame updates regularly
148 /// </summary>
149 /// <param name="sender"></param>
150 /// <param name="e"></param>
151 void Heartbeat(object sender, EventArgs e)
152 {
153 this.Update();
154 }
155
156 /// <summary>
157 /// Performs per-frame updates on the world, this should be the central world loop
158 /// </summary>
159 public override void Update()
160 {
161 updateLock.WaitOne();
162 try
163 {
164 if (this.phyScene.IsThreaded)
165 {
166 this.phyScene.GetResults();
167
168 }
169
170 foreach (LLUUID UUID in Entities.Keys)
171 {
172 Entities[UUID].updateMovement();
173 }
174
175 lock (this.m_syncRoot)
176 {
177 this.phyScene.Simulate(timeStep);
178 }
179
180 foreach (LLUUID UUID in Entities.Keys)
181 {
182 Entities[UUID].update();
183 }
184
185 // General purpose event manager
186 eventManager.TriggerOnFrame();
187
188 //backup world data
189 this.storageCount++;
190 if (storageCount > 1200) //set to how often you want to backup
191 {
192 this.Backup();
193 storageCount = 0;
194 }
195 }
196 catch (Exception e)
197 {
198 MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString());
199 }
200 updateLock.ReleaseMutex();
201
202 }
203
204 /// <summary>
205 ///
206 /// </summary>
207 /// <returns></returns>
208 public bool Backup()
209 {
210
211 return true;
212 }
213 #endregion
214
215 #region Regenerate Terrain
216
217 /// <summary>
218 /// Rebuilds the terrain using a procedural algorithm
219 /// </summary>
220 public void RegenerateTerrain()
221 {
222 try
223 {
224 Terrain.hills();
225
226 lock (this.m_syncRoot)
227 {
228 this.phyScene.SetTerrain(Terrain.getHeights1D());
229 }
230 this.localStorage.SaveMap(this.Terrain.getHeights1D());
231
232 m_clientManager.ForEachClient(delegate(IClientAPI client)
233 {
234 this.SendLayerData(client);
235 });
236
237 foreach (LLUUID UUID in Entities.Keys)
238 {
239 Entities[UUID].LandRenegerated();
240 }
241 }
242 catch (Exception e)
243 {
244 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
245 }
246 }
247
248 /// <summary>
249 /// Rebuilds the terrain using a 2D float array
250 /// </summary>
251 /// <param name="newMap">256,256 float array containing heights</param>
252 public void RegenerateTerrain(float[,] newMap)
253 {
254 try
255 {
256 this.Terrain.setHeights2D(newMap);
257 lock (this.m_syncRoot)
258 {
259 this.phyScene.SetTerrain(this.Terrain.getHeights1D());
260 }
261 this.localStorage.SaveMap(this.Terrain.getHeights1D());
262
263 m_clientManager.ForEachClient(delegate(IClientAPI client)
264 {
265 this.SendLayerData(client);
266 });
267
268 foreach (LLUUID UUID in Entities.Keys)
269 {
270 Entities[UUID].LandRenegerated();
271 }
272 }
273 catch (Exception e)
274 {
275 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
276 }
277 }
278
279 /// <summary>
280 /// Rebuilds the terrain assuming changes occured at a specified point[?]
281 /// </summary>
282 /// <param name="changes">???</param>
283 /// <param name="pointx">???</param>
284 /// <param name="pointy">???</param>
285 public void RegenerateTerrain(bool changes, int pointx, int pointy)
286 {
287 try
288 {
289 if (changes)
290 {
291 /* Dont save here, rely on tainting system instead */
292
293 m_clientManager.ForEachClient(delegate(IClientAPI client)
294 {
295 this.SendLayerData(pointx, pointy, client);
296 });
297 }
298 }
299 catch (Exception e)
300 {
301 MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
302 }
303 }
304
305 #endregion
306
307 #region Load Terrain
308 /// <summary>
309 /// Loads the World heightmap
310 /// </summary>
311 ///
312 public override void LoadWorldMap()
313 {
314 try
315 {
316 float[] map = this.localStorage.LoadWorld();
317 if (map == null)
318 {
319 if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile))
320 {
321 Console.WriteLine("No default terrain, procedurally generating...");
322 this.Terrain.hills();
323
324 this.localStorage.SaveMap(this.Terrain.getHeights1D());
325 }
326 else
327 {
328 try
329 {
330 this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile);
331 this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier;
332 }
333 catch
334 {
335 Console.WriteLine("Unable to load default terrain, procedurally generating instead...");
336 Terrain.hills();
337 }
338 this.localStorage.SaveMap(this.Terrain.getHeights1D());
339 }
340 }
341 else
342 {
343 this.Terrain.setHeights1D(map);
344 }
345
346 CreateTerrainTexture();
347
348 }
349 catch (Exception e)
350 {
351 MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
352 }
353 }
354
355 /// <summary>
356 ///
357 /// </summary>
358 private void CreateTerrainTexture()
359 {
360 //create a texture asset of the terrain
361 byte[] data = this.Terrain.exportJpegImage("defaultstripe.png");
362 this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random();
363 AssetBase asset = new AssetBase();
364 asset.FullID = this.m_regInfo.estateSettings.terrainImageID;
365 asset.Data = data;
366 asset.Name = "terrainImage";
367 asset.Type = 0;
368 this.assetCache.AddAsset(asset);
369 }
370 #endregion
371
372 #region Primitives Methods
373
374
375 /// <summary>
376 /// Loads the World's objects
377 /// </summary>
378 public void LoadPrimsFromStorage()
379 {
380 try
381 {
382 MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives");
383 this.localStorage.LoadPrimitives(this);
384 }
385 catch (Exception e)
386 {
387 MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
388 }
389 }
390
391 /// <summary>
392 /// Loads a specific object from storage
393 /// </summary>
394 /// <param name="prim">The object to load</param>
395 public void PrimFromStorage(PrimData prim)
396 {
397
398 }
399
400 /// <summary>
401 /// Returns a new unallocated primitive ID
402 /// </summary>
403 /// <returns>A brand new primitive ID</returns>
404 public uint PrimIDAllocate()
405 {
406 uint myID;
407
408 _primAllocateMutex.WaitOne();
409 ++_primCount;
410 myID = _primCount;
411 _primAllocateMutex.ReleaseMutex();
412
413 return myID;
414 }
415
416 /// <summary>
417 ///
418 /// </summary>
419 /// <param name="addPacket"></param>
420 /// <param name="agentClient"></param>
421 public void AddNewPrim(Packet addPacket, IClientAPI agentClient)
422 {
423 AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentId);
424 }
425
426 /// <summary>
427 ///
428 /// </summary>
429 /// <param name="addPacket"></param>
430 /// <param name="ownerID"></param>
431 public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID)
432 {
433 try
434 {
435 SceneObject sceneOb = new SceneObject(m_regionHandle, this, addPacket, ownerID, this.PrimIDAllocate());
436 this.Entities.Add(sceneOb.rootUUID, sceneOb);
437
438 // Trigger event for listeners
439 // eventManager.TriggerOnNewPrimitive(prim);
440 }
441 catch (Exception e)
442 {
443 MainLog.Instance.Warn("World.cs: AddNewPrim() - Failed with exception " + e.ToString());
444 }
445 }
446
447 public override uint AddNewPrim(LLUUID ownerId, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID texture, int flags)
448 {
449 uint id = NextLocalId;
450
451 throw new NotImplementedException("Not implemented yet.");
452 }
453
454 #endregion
455
456 #region Add/Remove Avatar Methods
457
458 /// <summary>
459 ///
460 /// </summary>
461 /// <param name="remoteClient"></param
462 /// <param name="agentID"></param>
463 /// <param name="child"></param>
464 public override void AddNewClient(IClientAPI client, bool child)
465 {
466 client.OnRegionHandShakeReply += this.SendLayerData;
467 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
468 client.OnChatFromViewer += this.SimChat;
469 client.OnInstantMessage += this.InstantMessage;
470 client.OnRequestWearables += this.InformClientOfNeighbours;
471 client.OnAddPrim += this.AddNewPrim;
472 client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
473 client.OnUpdatePrimSinglePosition += this.UpdatePrimSinglePosition;
474 client.OnUpdatePrimGroupRotation += this.UpdatePrimRotation;
475 client.OnUpdatePrimGroupMouseRotation += this.UpdatePrimRotation;
476 client.OnUpdatePrimSingleRotation += this.UpdatePrimSingleRotation;
477 client.OnUpdatePrimScale += this.UpdatePrimScale;
478 client.OnUpdatePrimShape += this.UpdatePrimShape;
479 client.OnRequestMapBlocks += this.RequestMapBlocks;
480 client.OnTeleportLocationRequest += this.RequestTeleportLocation;
481 client.OnObjectSelect += this.SelectPrim;
482 client.OnGrapUpdate += this.MoveObject;
483 client.OnNameFromUUIDRequest += this.commsManager.HandleUUIDNameRequest;
484 client.OnObjectDescription += this.PrimDescription;
485 client.OnObjectName += this.PrimName;
486 client.OnLinkObjects += this.LinkObjects;
487 client.OnObjectDuplicate += this.DuplicateObject;
488
489 /* remoteClient.OnParcelPropertiesRequest += new ParcelPropertiesRequest(parcelManager.handleParcelPropertiesRequest);
490 remoteClient.OnParcelDivideRequest += new ParcelDivideRequest(parcelManager.handleParcelDivideRequest);
491 remoteClient.OnParcelJoinRequest += new ParcelJoinRequest(parcelManager.handleParcelJoinRequest);
492 remoteClient.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(parcelManager.handleParcelPropertiesUpdateRequest);
493 remoteClient.OnEstateOwnerMessage += new EstateOwnerMessageRequest(estateManager.handleEstateOwnerMessage);
494 */
495 this.estateManager.sendRegionHandshake(client);
496
497 CreateAndAddScenePresence(client);
498 return;
499 }
500
501 protected void CreateAndAddScenePresence(IClientAPI client)
502 {
503 ScenePresence newAvatar = null;
504
505 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
506 newAvatar = new ScenePresence(client, this, this.m_regInfo);
507 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Adding new avatar to world");
508 MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Starting RegionHandshake ");
509
510 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
511 lock (this.m_syncRoot)
512 {
513 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
514 }
515
516 lock (Entities)
517 {
518 if (!Entities.ContainsKey(client.AgentId))
519 {
520 this.Entities.Add(client.AgentId, newAvatar);
521 }
522 else
523 {
524 Entities[client.AgentId] = newAvatar;
525 }
526 }
527 lock (Avatars)
528 {
529 if (Avatars.ContainsKey(client.AgentId))
530 {
531 Avatars[client.AgentId] = newAvatar;
532 }
533 else
534 {
535 this.Avatars.Add(client.AgentId, newAvatar);
536 }
537 }
538 }
539
540
541 /// <summary>
542 ///
543 /// </summary>
544 /// <param name="agentID"></param>
545 public override void RemoveClient(LLUUID agentID)
546 {
547 eventManager.TriggerOnRemovePresence(agentID);
548
549 ScenePresence avatar = this.RequestAvatar(agentID);
550
551 m_clientManager.ForEachClient(
552 delegate(IClientAPI client)
553 {
554 client.SendKillObject(avatar.RegionHandle, avatar.LocalId);
555 });
556
557 lock (Avatars) {
558 if (Avatars.ContainsKey(agentID)) {
559 Avatars.Remove(agentID);
560 }
561 }
562 lock (Entities) {
563 if (Entities.ContainsKey(agentID)) {
564 Entities.Remove(agentID);
565 }
566 }
567 // TODO: Add the removal from physics ?
568
569
570
571 return;
572 }
573 #endregion
574
575 #region Request Avatars List Methods
576 //The idea is to have a group of method that return a list of avatars meeting some requirement
577 // ie it could be all Avatars within a certain range of the calling prim/avatar.
578
579 /// <summary>
580 /// Request a List of all Avatars in this World
581 /// </summary>
582 /// <returns></returns>
583 public List<ScenePresence> RequestAvatarList()
584 {
585 List<ScenePresence> result = new List<ScenePresence>();
586
587 foreach (ScenePresence avatar in Avatars.Values)
588 {
589 result.Add(avatar);
590 }
591
592 return result;
593 }
594
595 /// <summary>
596 /// Request a filtered list of Avatars in this World
597 /// </summary>
598 /// <returns></returns>
599 public List<ScenePresence> RequestAvatarList(FilterAvatarList filter)
600 {
601 List<ScenePresence> result = new List<ScenePresence>();
602
603 foreach (ScenePresence avatar in Avatars.Values)
604 {
605 if (filter(avatar))
606 {
607 result.Add(avatar);
608 }
609 }
610
611 return result;
612 }
613
614 /// <summary>
615 /// Request a Avatar by UUID
616 /// </summary>
617 /// <param name="avatarID"></param>
618 /// <returns></returns>
619 public ScenePresence RequestAvatar(LLUUID avatarID)
620 {
621 if (this.Avatars.ContainsKey(avatarID))
622 {
623 return Avatars[avatarID];
624 }
625 return null;
626 }
627 #endregion
628
629
630 /// <summary>
631 ///
632 /// </summary>
633 /// <param name="entID"></param>
634 /// <returns></returns>
635 public bool DeleteEntity(LLUUID entID)
636 {
637 if (this.Entities.ContainsKey(entID))
638 {
639 this.Entities.Remove(entID);
640 return true;
641 }
642 return false;
643 }
644
645 public void SendAllSceneObjectsToClient(IClientAPI client)
646 {
647 foreach (EntityBase ent in Entities.Values)
648 {
649 if (ent is SceneObject)
650 {
651 ((SceneObject)ent).SendAllChildPrimsToClient(client);
652 }
653 }
654 }
655
656 #region RegionCommsHost
657
658 /// <summary>
659 ///
660 /// </summary>
661 public void RegisterRegionWithComms()
662 {
663
664 this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo);
665 if (this.regionCommsHost != null)
666 {
667 this.regionCommsHost.OnExpectUser += this.NewUserConnection;
668 this.regionCommsHost.OnAvatarCrossingIntoRegion += this.AgentCrossing;
669 }
670 }
671
672 /// <summary>
673 ///
674 /// </summary>
675 /// <param name="regionHandle"></param>
676 /// <param name="agent"></param>
677 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
678 {
679 // Console.WriteLine("World.cs - add new user connection");
680 //should just check that its meant for this region
681 if (regionHandle == this.m_regInfo.RegionHandle)
682 {
683 if (agent.CapsPath != "")
684 {
685 //Console.WriteLine("new user, so creating caps handler for it");
686 Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.ExternalHostName, this.m_regInfo.ExternalEndPoint.Port, agent.CapsPath, agent.AgentID);
687 cap.RegisterHandlers();
688 this.capsHandlers.Add(agent.AgentID, cap);
689 }
690 this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
691 }
692 }
693
694 public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position)
695 {
696 if (regionHandle == this.m_regInfo.RegionHandle)
697 {
698 if (this.Avatars.ContainsKey(agentID))
699 {
700 this.Avatars[agentID].MakeAvatar(position);
701 }
702 }
703 }
704
705 /// <summary>
706 ///
707 /// </summary>
708 public void InformClientOfNeighbours(IClientAPI remoteClient)
709 {
710 List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo);
711
712 if (neighbours != null)
713 {
714 for (int i = 0; i < neighbours.Count; i++)
715 {
716 AgentCircuitData agent = remoteClient.RequestClientInfo();
717 agent.BaseFolder = LLUUID.Zero;
718 agent.InventoryFolder = LLUUID.Zero;
719 agent.startpos = new LLVector3(128, 128, 70);
720 agent.child = true;
721 this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent);
722 remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint);
723 //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort);
724 }
725 }
726 }
727
728 /// <summary>
729 ///
730 /// </summary>
731 /// <param name="regionHandle"></param>
732 /// <returns></returns>
733 public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
734 {
735 return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle);
736 }
737
738 /// <summary>
739 ///
740 /// </summary>
741 /// <param name="minX"></param>
742 /// <param name="minY"></param>
743 /// <param name="maxX"></param>
744 /// <param name="maxY"></param>
745 public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
746 {
747 List<MapBlockData> mapBlocks;
748 mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
749 remoteClient.SendMapBlock(mapBlocks);
750 }
751
752 /// <summary>
753 ///
754 /// </summary>
755 /// <param name="remoteClient"></param>
756 /// <param name="RegionHandle"></param>
757 /// <param name="position"></param>
758 /// <param name="lookAt"></param>
759 /// <param name="flags"></param>
760 public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags)
761 {
762 if (regionHandle == this.m_regionHandle)
763 {
764 if (this.Avatars.ContainsKey(remoteClient.AgentId))
765 {
766 remoteClient.SendTeleportLocationStart();
767 remoteClient.SendLocalTeleport(position, lookAt, flags);
768 this.Avatars[remoteClient.AgentId].Teleport(position);
769 }
770 }
771 else
772 {
773 RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle);
774 if (reg != null)
775 {
776 remoteClient.SendTeleportLocationStart();
777 AgentCircuitData agent = remoteClient.RequestClientInfo();
778 agent.BaseFolder = LLUUID.Zero;
779 agent.InventoryFolder = LLUUID.Zero;
780 agent.startpos = new LLVector3(128, 128, 70);
781 agent.child = true;
782 this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
783 this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position);
784
785 remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4));
786
787 }
788 //remoteClient.SendTeleportCancel();
789 }
790 }
791
792 /// <summary>
793 ///
794 /// </summary>
795 /// <param name="regionhandle"></param>
796 /// <param name="agentID"></param>
797 /// <param name="position"></param>
798 public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position)
799 {
800 return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position);
801 }
802
803 #endregion
804
805 }
806}
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs
new file mode 100644
index 0000000..811f54c
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs
@@ -0,0 +1,198 @@
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.Reflection;
31using libsecondlife;
32using OpenSim.Framework.Console;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Framework.Types;
35using OpenSim.Region.Caches;
36using OpenSim.Region.Terrain;
37using OpenSim.Framework;
38
39namespace OpenSim.Region.Environment.Scenes
40{
41 public abstract class SceneBase : IWorld
42 {
43 public Dictionary<LLUUID, EntityBase> Entities;
44 protected ClientManager m_clientManager;
45 protected ulong m_regionHandle;
46 protected string m_regionName;
47 protected RegionInfo m_regInfo;
48
49 public TerrainEngine Terrain;
50
51 public string m_datastore;
52 public ILocalStorage localStorage;
53
54 protected object m_syncRoot = new object();
55 private uint m_nextLocalId = 8880000;
56 protected AssetCache assetCache;
57
58 #region Update Methods
59 /// <summary>
60 /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
61 /// </summary>
62 public abstract void Update();
63
64 #endregion
65
66 #region Terrain Methods
67
68 /// <summary>
69 /// Loads the World heightmap
70 /// </summary>
71 public abstract void LoadWorldMap();
72
73 /// <summary>
74 /// Loads a new storage subsystem from a named library
75 /// </summary>
76 /// <param name="dllName">Storage Library</param>
77 /// <returns>Successful or not</returns>
78 public bool LoadStorageDLL(string dllName)
79 {
80 try
81 {
82 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
83 ILocalStorage store = null;
84
85 foreach (Type pluginType in pluginAssembly.GetTypes())
86 {
87 if (pluginType.IsPublic)
88 {
89 if (!pluginType.IsAbstract)
90 {
91 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
92
93 if (typeInterface != null)
94 {
95 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
96 store = plug;
97
98 store.Initialise(this.m_datastore);
99 break;
100 }
101
102 typeInterface = null;
103 }
104 }
105 }
106 pluginAssembly = null;
107 this.localStorage = store;
108 return (store == null);
109 }
110 catch (Exception e)
111 {
112 MainLog.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
113 return false;
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(IClientAPI RemoteClient)
123 {
124 RemoteClient.SendLayerData(Terrain.getHeights1D());
125 }
126
127 /// <summary>
128 /// Sends a specified patch to a client
129 /// </summary>
130 /// <param name="px">Patch coordinate (x) 0..16</param>
131 /// <param name="py">Patch coordinate (y) 0..16</param>
132 /// <param name="RemoteClient">The client to send to</param>
133 public virtual void SendLayerData(int px, int py, IClientAPI RemoteClient)
134 {
135 RemoteClient.SendLayerData(px, py, Terrain.getHeights1D());
136 }
137
138 #endregion
139
140 #region Add/Remove Agent/Avatar
141 /// <summary>
142 ///
143 /// </summary>
144 /// <param name="remoteClient"></param>
145 /// <param name="agentID"></param>
146 /// <param name="child"></param>
147 public abstract void AddNewClient(IClientAPI client, bool child);
148
149 public abstract uint AddNewPrim(LLUUID ownerId, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID texture, int flags);
150
151 /// <summary>
152 ///
153 /// </summary>
154 /// <param name="agentID"></param>
155 public abstract void RemoveClient(LLUUID agentID);
156
157 #endregion
158
159 /// <summary>
160 ///
161 /// </summary>
162 /// <returns></returns>
163 public virtual RegionInfo RegionInfo
164 {
165 get { return this.m_regInfo; }
166 }
167
168 public object SyncRoot
169 {
170 get { return m_syncRoot; }
171 }
172
173 public uint NextLocalId
174 {
175 get { return m_nextLocalId++; }
176 }
177
178 #region Shutdown
179 /// <summary>
180 /// Tidy before shutdown
181 /// </summary>
182 public virtual void Close()
183 {
184 try
185 {
186 this.localStorage.ShutDown();
187 }
188 catch (Exception e)
189 {
190 MainLog.Instance.WriteLine(LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString());
191 }
192 }
193
194 #endregion
195
196
197 }
198}
diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
new file mode 100644
index 0000000..9e383c6
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
@@ -0,0 +1,50 @@
1using libsecondlife;
2
3namespace OpenSim.Region.Environment.Scenes
4{
5 /// <summary>
6 /// A class for triggering remote scene events.
7 /// </summary>
8 public class EventManager
9 {
10 public delegate void OnFrameDelegate();
11 public event OnFrameDelegate OnFrame;
12
13 public delegate void OnNewPresenceDelegate(ScenePresence presence);
14 public event OnNewPresenceDelegate OnNewPresence;
15
16 public delegate void OnNewPrimitiveDelegate(PrimitiveOld prim);
17 public event OnNewPrimitiveDelegate OnNewPrimitive;
18
19 public delegate void OnRemovePresenceDelegate(LLUUID uuid);
20 public event OnRemovePresenceDelegate OnRemovePresence;
21
22 public void TriggerOnFrame()
23 {
24 if (OnFrame != null)
25 {
26 OnFrame();
27 }
28 }
29
30 public void TriggerOnNewPrimitive(PrimitiveOld prim)
31 {
32 if (OnNewPrimitive != null)
33 OnNewPrimitive(prim);
34 }
35
36 public void TriggerOnNewPresence(ScenePresence presence)
37 {
38 if (OnNewPresence != null)
39 OnNewPresence(presence);
40 }
41
42 public void TriggerOnRemovePresence(LLUUID uuid)
43 {
44 if (OnRemovePresence != null)
45 {
46 OnRemovePresence(uuid);
47 }
48 }
49 }
50}
diff --git a/OpenSim/Region/Environment/Scenes/SceneObject.cs b/OpenSim/Region/Environment/Scenes/SceneObject.cs
new file mode 100644
index 0000000..ecd2dee
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneObject.cs
@@ -0,0 +1,246 @@
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.Collections.Generic;
29using System.Text;
30using libsecondlife;
31using libsecondlife.Packets;
32using OpenSim.Framework.Interfaces;
33using OpenSim.Physics.Manager;
34
35namespace OpenSim.Region.Environment.Scenes
36{
37 public class SceneObject : EntityBase
38 {
39 private Encoding enc = Encoding.ASCII;
40 private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>(); //list of all primitive id's that are part of this group
41 public Primitive rootPrimitive;
42 private new Scene m_world;
43 protected ulong m_regionHandle;
44
45 private bool physicsEnabled = false;
46 private PhysicsScene m_PhysScene;
47 private PhysicsActor m_PhysActor;
48
49 public LLUUID rootUUID
50 {
51 get
52 {
53 this.uuid = this.rootPrimitive.uuid;
54 return this.uuid;
55 }
56 }
57
58 public uint rootLocalID
59 {
60 get
61 {
62 this.m_localId = this.rootPrimitive.LocalId;
63 return this.LocalId;
64 }
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 public SceneObject(ulong regionHandle, Scene world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
71 {
72 m_regionHandle = regionHandle;
73 m_world = world;
74 this.Pos = addPacket.ObjectData.RayEnd;
75 this.CreateRootFromPacket(addPacket, ownerID, localID);
76 }
77
78 /// <summary>
79 ///
80 /// </summary>
81 /// <remarks>Need a null constructor for duplication</remarks>
82 public SceneObject()
83 {
84
85 }
86
87 /// <summary>
88 ///
89 /// </summary>
90 /// <param name="addPacket"></param>
91 /// <param name="agentID"></param>
92 /// <param name="localID"></param>
93 public void CreateRootFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
94 {
95 this.rootPrimitive = new Primitive( this.m_regionHandle, this.m_world, addPacket, agentID, localID, true, this, this);
96 this.children.Add(rootPrimitive);
97 this.ChildPrimitives.Add(this.rootUUID, this.rootPrimitive);
98 }
99
100 /// <summary>
101 ///
102 /// </summary>
103 /// <param name="data"></param>
104 public void CreateFromBytes(byte[] data)
105 {
106
107 }
108
109 /// <summary>
110 ///
111 /// </summary>
112 /// <returns>A complete copy of the object</returns>
113 public SceneObject Copy()
114 {
115 SceneObject dupe = new SceneObject();
116
117 Primitive newRoot = this.rootPrimitive.Copy((EntityBase)dupe, dupe);
118
119 foreach (EntityBase child in this.children)
120 {
121 EntityBase newChild = child.Copy();
122 dupe.children.Add(newChild);
123 }
124
125 return dupe;
126 }
127
128 /// <summary>
129 ///
130 /// </summary>
131 public void DeleteAllChildren()
132 {
133 this.children.Clear();
134 this.ChildPrimitives.Clear();
135 this.rootPrimitive = null;
136 }
137
138 /// <summary>
139 ///
140 /// </summary>
141 /// <param name="primObject"></param>
142 public void AddNewChildPrims(SceneObject primObject)
143 {
144 this.rootPrimitive.AddNewChildren(primObject);
145 }
146
147 public void AddChildToList(Primitive prim)
148 {
149 if (!this.ChildPrimitives.ContainsKey(prim.uuid))
150 {
151 this.ChildPrimitives.Add(prim.uuid, prim);
152 }
153 }
154 /// <summary>
155 ///
156 /// </summary>
157 /// <param name="primID"></param>
158 /// <returns></returns>
159 public Primitive HasChildPrim(LLUUID primID)
160 {
161 if (this.ChildPrimitives.ContainsKey(primID))
162 {
163 return this.ChildPrimitives[primID];
164 }
165
166 return null;
167 }
168
169 /// <summary>
170 ///
171 /// </summary>
172 /// <param name="localID"></param>
173 /// <returns></returns>
174 public Primitive HasChildPrim(uint localID)
175 {
176 Primitive returnPrim = null;
177 foreach (Primitive prim in this.ChildPrimitives.Values)
178 {
179 if (prim.LocalId == localID)
180 {
181 returnPrim = prim;
182 break;
183 }
184 }
185 return returnPrim;
186 }
187
188 public void SendAllChildPrimsToClient(IClientAPI client)
189 {
190 this.rootPrimitive.SendFullUpdateForAllChildren(client);
191 }
192
193 /// <summary>
194 ///
195 /// </summary>
196 public override void BackUp()
197 {
198
199 }
200
201 /// <summary>
202 ///
203 /// </summary>
204 /// <param name="offset"></param>
205 /// <param name="pos"></param>
206 /// <param name="remoteClient"></param>
207 public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
208 {
209 this.rootPrimitive.Pos = pos ;
210 this.rootPrimitive.SendTerseUpdateForAllChildren(remoteClient);
211 }
212
213 /// <summary>
214 ///
215 /// </summary>
216 /// <param name="client"></param>
217 public void GetProperites(IClientAPI client)
218 {
219 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
220 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
221 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
222 proper.ObjectData[0].ItemID = LLUUID.Zero;
223 proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.CreationDate;
224 proper.ObjectData[0].CreatorID = this.rootPrimitive.CreatorID;
225 proper.ObjectData[0].FolderID = LLUUID.Zero;
226 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
227 proper.ObjectData[0].GroupID = LLUUID.Zero;
228 proper.ObjectData[0].InventorySerial = 0;
229 proper.ObjectData[0].LastOwnerID = this.rootPrimitive.LastOwnerID;
230 proper.ObjectData[0].ObjectID = this.rootUUID;
231 proper.ObjectData[0].OwnerID = this.rootPrimitive.OwnerID;
232 proper.ObjectData[0].TouchName = enc.GetBytes(this.rootPrimitive.TouchName + "\0");
233 proper.ObjectData[0].TextureID = new byte[0];
234 proper.ObjectData[0].SitName = enc.GetBytes(this.rootPrimitive.SitName +"\0") ;
235 proper.ObjectData[0].Name = enc.GetBytes(this.rootPrimitive.Name +"\0");
236 proper.ObjectData[0].Description = enc.GetBytes(this.rootPrimitive.Description +"\0");
237 proper.ObjectData[0].OwnerMask = this.rootPrimitive.OwnerMask;
238 proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.NextOwnerMask;
239 proper.ObjectData[0].GroupMask = this.rootPrimitive.GroupMask;
240 proper.ObjectData[0].EveryoneMask = this.rootPrimitive.EveryoneMask;
241 proper.ObjectData[0].BaseMask = this.rootPrimitive.BaseMask;
242
243 client.OutPacket(proper);
244 }
245 }
246}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs
new file mode 100644
index 0000000..d1f75ed
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs
@@ -0,0 +1,74 @@
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.Collections.Generic;
29using System.Xml;
30using libsecondlife;
31
32namespace OpenSim.Region.Environment.Scenes
33{
34 partial class ScenePresence
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.MainLog.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.MainLog.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)");
66
67 foreach (KeyValuePair<string, LLUUID> kp in Animations.AnimsLLUUID)
68 {
69 AnimsNames.Add(kp.Value, kp.Key);
70 }
71 }
72 }
73 }
74}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs
new file mode 100644
index 0000000..dbb5d3f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs
@@ -0,0 +1,85 @@
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 libsecondlife;
29using libsecondlife.Packets;
30using OpenSim.Framework.Interfaces;
31
32namespace OpenSim.Region.Environment.Scenes
33{
34 partial class ScenePresence
35 {
36 public class Avatar : IScenePresenceBody
37 {
38 public Avatar()
39 {
40
41 }
42
43 public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
44 {
45 }
46
47 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
48 {
49 }
50
51 public void SendOurAppearance(IClientAPI OurClient)
52 {
53 }
54
55 public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
56 {
57 }
58 }
59
60 public class ChildAgent : IScenePresenceBody //is a ghost
61 {
62 public ChildAgent()
63 {
64
65 }
66
67 public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
68 {
69 }
70
71 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
72 {
73 }
74
75 public void SendOurAppearance(IClientAPI OurClient)
76 {
77 }
78
79 public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
80 {
81 }
82 }
83 }
84
85}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
new file mode 100644
index 0000000..e65ab7c
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -0,0 +1,597 @@
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 Axiom.Math;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework.Console;
35using OpenSim.Framework.Interfaces;
36using OpenSim.Framework.Types;
37using OpenSim.Physics.Manager;
38
39namespace OpenSim.Region.Environment.Scenes
40{
41 public partial class ScenePresence : Entity
42 {
43 public static bool PhysicsEngineFlying = false;
44 public static AvatarAnimations Animations;
45 public static byte[] DefaultTexture;
46 public string firstname;
47 public string lastname;
48 public IClientAPI ControllingClient;
49 public LLUUID current_anim;
50 public int anim_seq;
51 private bool updateflag = false;
52 private byte movementflag = 0;
53 private List<NewForce> forcesList = new List<NewForce>();
54 private short _updateCount = 0;
55 private Quaternion bodyRot;
56 private LLObject.TextureEntry avatarAppearanceTexture = null;
57 private byte[] visualParams;
58 private AvatarWearable[] Wearables;
59 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
60 private ulong m_regionHandle;
61 private bool childAgent = false;
62 private bool newForce = false;
63 private bool newAvatar = false;
64 private IScenePresenceBody m_body;
65
66 protected RegionInfo m_regionInfo;
67
68 private Vector3[] Dir_Vectors = new Vector3[6];
69 private enum Dir_ControlFlags
70 {
71 DIR_CONTROL_FLAG_FOWARD = MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS,
72 DIR_CONTROL_FLAG_BACK = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG,
73 DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS,
74 DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG,
75 DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS,
76 DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG
77 }
78
79 #region Properties
80 /// <summary>
81 ///
82 /// </summary>
83 public PhysicsActor PhysActor
84 {
85 set
86 {
87 this._physActor = value;
88 }
89 get
90 {
91 return _physActor;
92 }
93 }
94
95 public ulong RegionHandle
96 {
97 get { return m_regionHandle; }
98 }
99
100 #endregion
101
102 #region Constructor(s)
103 /// <summary>
104 ///
105 /// </summary>
106 /// <param name="theClient"></param>
107 /// <param name="world"></param>
108 /// <param name="clientThreads"></param>
109 /// <param name="regionDat"></param>
110 public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo)
111 {
112
113 m_world = world;
114 this.uuid = theClient.AgentId;
115
116 m_regionInfo = reginfo;
117 m_regionHandle = reginfo.RegionHandle;
118 MainLog.Instance.Verbose("Avatar.cs ");
119 ControllingClient = theClient;
120 this.firstname = ControllingClient.FirstName;
121 this.lastname = ControllingClient.LastName;
122 m_localId = m_world.NextLocalId;
123 Pos = ControllingClient.StartPos;
124 visualParams = new byte[218];
125 for (int i = 0; i < 218; i++)
126 {
127 visualParams[i] = 100;
128 }
129
130 Wearables = AvatarWearable.DefaultWearables;
131 Animations = new ScenePresence.AvatarAnimations();
132 Animations.LoadAnims();
133
134 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
135
136 //register for events
137 ControllingClient.OnRequestWearables += this.SendOurAppearance;
138 //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
139 ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement;
140 ControllingClient.OnCompleteMovementToRegion += this.SendInitialData;
141 ControllingClient.OnAgentUpdate += this.HandleAgentUpdate;
142 // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
143 // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
144 //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
145
146 Dir_Vectors[0] = new Vector3(1, 0, 0); //FOWARD
147 Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK
148 Dir_Vectors[2] = new Vector3(0, 1, 0); //LEFT
149 Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT
150 Dir_Vectors[4] = new Vector3(0, 0, 1); //UP
151 Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN
152
153 }
154 #endregion
155
156 #region Status Methods
157 /// <summary>
158 /// Not Used, most likely can be deleted
159 /// </summary>
160 /// <param name="status"></param>
161 public void ChildStatusChange(bool status)
162 {
163 this.childAgent = status;
164
165 if (this.childAgent == true)
166 {
167 this.Velocity = new LLVector3(0, 0, 0);
168 this.Pos = new LLVector3(128, 128, 70);
169
170 }
171 }
172
173 /// <summary>
174 ///
175 /// </summary>
176 /// <param name="pos"></param>
177 public void MakeAvatar(LLVector3 pos)
178 {
179 //this.childAvatar = false;
180 this.Pos = pos;
181 this.newAvatar = true;
182 this.childAgent = false;
183 }
184
185 protected void MakeChildAgent()
186 {
187 this.Velocity = new LLVector3(0, 0, 0);
188 this.Pos = new LLVector3(128, 128, 70);
189 this.childAgent = true;
190 }
191
192 /// <summary>
193 ///
194 /// </summary>
195 /// <param name="pos"></param>
196 public void Teleport(LLVector3 pos)
197 {
198 this.Pos = pos;
199 this.SendTerseUpdateToALLClients();
200 }
201
202 /// <summary>
203 ///
204 /// </summary>
205 public void StopMovement()
206 {
207
208 }
209 #endregion
210
211 #region Event Handlers
212 /// <summary>
213 ///
214 /// </summary>
215 /// <param name="texture"></param>
216 /// <param name="visualParam"></param>
217 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
218 {
219
220 }
221
222 /// <summary>
223 /// Complete Avatar's movement into the region
224 /// </summary>
225 public void CompleteMovement()
226 {
227 LLVector3 look = this.Velocity;
228 if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
229 {
230 look = new LLVector3(0.99f, 0.042f, 0);
231 }
232 this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look);
233 if (this.childAgent)
234 {
235 this.childAgent = false;
236 }
237 }
238
239 /// <summary>
240 ///
241 /// </summary>
242 /// <param name="pack"></param>
243 public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
244 {
245 int i = 0;
246 bool update_movementflag = false;
247 bool update_rotation = false;
248 bool DCFlagKeyPressed = false;
249 Vector3 agent_control_v3 = new Vector3(0, 0, 0);
250 Quaternion q = new Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
251
252 this.PhysActor.Flying = ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0);
253
254 if (q != this.bodyRot)
255 {
256 this.bodyRot = q;
257 update_rotation = true;
258 }
259 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof(Dir_ControlFlags)))
260 {
261 if ((flags & (uint)DCF) != 0)
262 {
263 DCFlagKeyPressed = true;
264 agent_control_v3 += Dir_Vectors[i];
265 if ((movementflag & (uint)DCF) == 0)
266 {
267 movementflag += (byte)(uint)DCF;
268 update_movementflag = true;
269 }
270 }
271 else
272 {
273 if ((movementflag & (uint)DCF) != 0)
274 {
275 movementflag -= (byte)(uint)DCF;
276 update_movementflag = true;
277 }
278 }
279 i++;
280 }
281 if ((update_movementflag) || (update_rotation && DCFlagKeyPressed))
282 {
283 this.AddNewMovement(agent_control_v3, q);
284 }
285 UpdateMovementAnimations(update_movementflag);
286 }
287
288 protected void UpdateMovementAnimations(bool update_movementflag)
289 {
290 if (update_movementflag)
291 {
292 if (movementflag != 0)
293 {
294 if (this._physActor.Flying)
295 {
296 this.SendAnimPack(Animations.AnimsLLUUID["FLY"], 1);
297 }
298 else
299 {
300 this.SendAnimPack(Animations.AnimsLLUUID["WALK"], 1);
301 }
302 }
303 else
304 {
305 this.SendAnimPack(Animations.AnimsLLUUID["STAND"], 1);
306 }
307 }
308
309 }
310
311
312 protected void AddNewMovement(Vector3 vec, Quaternion rotation)
313 {
314 NewForce newVelocity = new NewForce();
315 Vector3 direc = rotation * vec;
316 direc.Normalize();
317
318 direc = direc * ((0.03f) * 128f);
319 if (this._physActor.Flying)
320 direc *= 4;
321
322 newVelocity.X = direc.x;
323 newVelocity.Y = direc.y;
324 newVelocity.Z = direc.z;
325 this.forcesList.Add(newVelocity);
326 }
327
328 #endregion
329
330 #region Overridden Methods
331 /// <summary>
332 ///
333 /// </summary>
334 public override void LandRenegerated()
335 {
336
337 }
338
339 /// <summary>
340 ///
341 /// </summary>
342 public override void update()
343 {
344 if (this.childAgent == false)
345 {
346 if (this.newForce)
347 {
348 this.SendTerseUpdateToALLClients();
349 _updateCount = 0;
350 }
351 else if (movementflag != 0)
352 {
353 _updateCount++;
354 if (_updateCount > 3)
355 {
356 this.SendTerseUpdateToALLClients();
357 _updateCount = 0;
358 }
359 }
360
361 this.CheckForBorderCrossing();
362 }
363 }
364 #endregion
365
366 #region Update Client(s)
367 /// <summary>
368 ///
369 /// </summary>
370 /// <param name="RemoteClient"></param>
371 public void SendTerseUpdateToClient(IClientAPI RemoteClient)
372 {
373 LLVector3 pos = this.Pos;
374 LLVector3 vel = this.Velocity;
375 RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z));
376 }
377
378 /// <summary>
379 ///
380 /// </summary>
381 public void SendTerseUpdateToALLClients()
382 {
383 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
384 for (int i = 0; i < avatars.Count; i++)
385 {
386 this.SendTerseUpdateToClient(avatars[i].ControllingClient);
387 }
388 }
389
390 /// <summary>
391 ///
392 /// </summary>
393 /// <param name="remoteAvatar"></param>
394 public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
395 {
396 remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
397 }
398
399 public void SendFullUpdateToALLClients()
400 {
401 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
402 foreach (ScenePresence avatar in this.m_world.RequestAvatarList())
403 {
404 this.SendFullUpdateToOtherClient(avatar);
405 avatar.SendFullUpdateToOtherClient(this);
406 }
407 }
408
409 /// <summary>
410 ///
411 /// </summary>
412 public void SendInitialData()
413 {
414 this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
415 if (this.newAvatar)
416 {
417 this.m_world.InformClientOfNeighbours(this.ControllingClient);
418 this.newAvatar = false;
419 }
420 }
421
422 /// <summary>
423 ///
424 /// </summary>
425 /// <param name="OurClient"></param>
426 public void SendOurAppearance(IClientAPI OurClient)
427 {
428 this.ControllingClient.SendWearables(this.Wearables);
429 this.SendFullUpdateToALLClients();
430 this.m_world.SendAllSceneObjectsToClient(this.ControllingClient);
431 }
432
433 /// <summary>
434 ///
435 /// </summary>
436 /// <param name="avatarInfo"></param>
437 public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
438 {
439
440 }
441
442 /// <summary>
443 ///
444 /// </summary>
445 /// <param name="animID"></param>
446 /// <param name="seq"></param>
447 public void SendAnimPack(LLUUID animID, int seq)
448 {
449 this.current_anim = animID;
450 this.anim_seq = seq;
451 List<ScenePresence> avatars = this.m_world.RequestAvatarList();
452 for (int i = 0; i < avatars.Count; i++)
453 {
454 avatars[i].ControllingClient.SendAnimation(animID, seq, this.ControllingClient.AgentId);
455 }
456 }
457
458 /// <summary>
459 ///
460 /// </summary>
461 public void SendAnimPack()
462 {
463 this.SendAnimPack(this.current_anim, this.anim_seq);
464 }
465 #endregion
466
467 #region Border Crossing Methods
468 /// <summary>
469 ///
470 /// </summary>
471 protected void CheckForBorderCrossing()
472 {
473 LLVector3 pos2 = this.Pos;
474 LLVector3 vel = this.Velocity;
475
476 float timeStep = 0.2f;
477 pos2.X = pos2.X + (vel.X * timeStep);
478 pos2.Y = pos2.Y + (vel.Y * timeStep);
479 pos2.Z = pos2.Z + (vel.Z * timeStep);
480
481 if ((pos2.X < 0) || (pos2.X > 256))
482 {
483 this.CrossToNewRegion();
484 }
485
486 if ((pos2.Y < 0) || (pos2.Y > 256))
487 {
488 this.CrossToNewRegion();
489 }
490 }
491
492 /// <summary>
493 ///
494 /// </summary>
495 protected void CrossToNewRegion()
496 {
497 LLVector3 pos = this.Pos;
498 LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z);
499 uint neighbourx = this.m_regionInfo.RegionLocX;
500 uint neighboury = this.m_regionInfo.RegionLocY;
501
502 if (pos.X < 2)
503 {
504 neighbourx -= 1;
505 newpos.X = 254;
506 }
507 if (pos.X > 253)
508 {
509 neighbourx += 1;
510 newpos.X = 1;
511 }
512 if (pos.Y < 2)
513 {
514 neighboury -= 1;
515 newpos.Y = 254;
516 }
517 if (pos.Y > 253)
518 {
519 neighboury += 1;
520 newpos.Y = 1;
521 }
522
523 LLVector3 vel = this.m_velocity;
524 ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256));
525 RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle);
526 if (neighbourRegion != null)
527 {
528 bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos);
529 if (res)
530 {
531 this.MakeChildAgent();
532 this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.InternalEndPoint);
533 }
534 }
535 }
536 #endregion
537
538 /// <summary>
539 ///
540 /// </summary>
541 public static void LoadAnims()
542 {
543
544 }
545
546 /// <summary>
547 ///
548 /// </summary>
549 public override void updateMovement()
550 {
551 newForce = false;
552 lock (this.forcesList)
553 {
554 if (this.forcesList.Count > 0)
555 {
556 for (int i = 0; i < this.forcesList.Count; i++)
557 {
558 NewForce force = this.forcesList[i];
559
560 this.updateflag = true;
561 this.Velocity = new LLVector3(force.X, force.Y, force.Z);
562 this.newForce = true;
563 }
564 for (int i = 0; i < this.forcesList.Count; i++)
565 {
566 this.forcesList.RemoveAt(0);
567 }
568 }
569 }
570 }
571
572 public static void LoadTextureFile(string name)
573 {
574 FileInfo fInfo = new FileInfo(name);
575 long numBytes = fInfo.Length;
576 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
577 BinaryReader br = new BinaryReader(fStream);
578 byte[] data1 = br.ReadBytes((int)numBytes);
579 br.Close();
580 fStream.Close();
581 DefaultTexture = data1;
582 }
583
584 public class NewForce
585 {
586 public float X;
587 public float Y;
588 public float Z;
589
590 public NewForce()
591 {
592
593 }
594 }
595 }
596
597}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
new file mode 100644
index 0000000..9cb881a
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
@@ -0,0 +1,102 @@
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.CodeDom.Compiler;
30using System.Collections.Generic;
31using Microsoft.CSharp;
32using OpenSim.Framework.Console;
33
34namespace OpenSim.Region.Environment.Scripting
35{
36 public class CSharpScriptEngine : IScriptCompiler
37 {
38 public string FileExt()
39 {
40 return ".cs";
41 }
42
43 private Dictionary<string,IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
44 {
45 CompilerParameters compilerParams = new CompilerParameters();
46 CompilerResults compilerResults;
47 compilerParams.GenerateExecutable = false;
48 compilerParams.GenerateInMemory = true;
49 compilerParams.IncludeDebugInformation = false;
50 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
51 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Enviroment.dll");
52 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
53 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
54 compilerParams.ReferencedAssemblies.Add("System.dll");
55
56 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
57
58 if (compilerResults.Errors.Count > 0)
59 {
60 MainLog.Instance.Error("Compile errors");
61 foreach (CompilerError error in compilerResults.Errors)
62 {
63 MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
64 }
65 }
66 else
67 {
68 Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
69
70 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
71 {
72 Type testInterface = pluginType.GetInterface("IScript", true);
73
74 if (testInterface != null)
75 {
76 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
77
78 string scriptName = "C#/" + script.getName();
79 Console.WriteLine("Script: " + scriptName + " loaded.");
80
81 if (!scripts.ContainsKey(scriptName))
82 {
83 scripts.Add(scriptName, script);
84 }
85 else
86 {
87 scripts[scriptName] = script;
88 }
89 }
90 }
91 return scripts;
92 }
93 return null;
94 }
95
96 public Dictionary<string,IScript> compile(string filename)
97 {
98 CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
99 return LoadDotNetScript(csharpProvider, filename);
100 }
101 }
102}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs
new file mode 100644
index 0000000..be1fe56
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs
@@ -0,0 +1,102 @@
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.CodeDom.Compiler;
30using System.Collections.Generic;
31using Microsoft.JScript;
32using OpenSim.Framework.Console;
33
34namespace OpenSim.Region.Environment.Scripting
35{
36 public class JScriptEngine : IScriptCompiler
37 {
38 public string FileExt()
39 {
40 return ".js";
41 }
42
43 private Dictionary<string, IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
44 {
45 CompilerParameters compilerParams = new CompilerParameters();
46 CompilerResults compilerResults;
47 compilerParams.GenerateExecutable = false;
48 compilerParams.GenerateInMemory = true;
49 compilerParams.IncludeDebugInformation = false;
50 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
51 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Enviroment.dll");
52 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
53 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
54 compilerParams.ReferencedAssemblies.Add("System.dll");
55
56 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
57
58 if (compilerResults.Errors.Count > 0)
59 {
60 MainLog.Instance.Error("Compile errors");
61 foreach (CompilerError error in compilerResults.Errors)
62 {
63 MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
64 }
65 }
66 else
67 {
68 Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
69
70 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
71 {
72 Type testInterface = pluginType.GetInterface("IScript", true);
73
74 if (testInterface != null)
75 {
76 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
77
78 string scriptName = "JS.NET/" + script.getName();
79 Console.WriteLine("Script: " + scriptName + " loaded.");
80
81 if (!scripts.ContainsKey(scriptName))
82 {
83 scripts.Add(scriptName, script);
84 }
85 else
86 {
87 scripts[scriptName] = script;
88 }
89 }
90 }
91 return scripts;
92 }
93 return null;
94 }
95
96 public Dictionary<string, IScript> compile(string filename)
97 {
98 JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
99 return LoadDotNetScript(jscriptProvider, filename);
100 }
101 }
102}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs
new file mode 100644
index 0000000..1d93197
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs
@@ -0,0 +1,45 @@
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.Scripting.EmbeddedJVM.Types;
32
33namespace OpenSim.Scripting.EmbeddedJVM
34{
35 public class ClassInstance : Object
36 {
37 public int size;
38 public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>();
39
40 public ClassInstance()
41 {
42
43 }
44 }
45}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs
new file mode 100644
index 0000000..f4ab1a2
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs
@@ -0,0 +1,503 @@
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.IO;
30using System.Collections.Generic;
31using System.Text;
32using OpenSim.Scripting.EmbeddedJVM.Types;
33
34namespace OpenSim.Scripting.EmbeddedJVM
35{
36 public class ClassRecord
37 {
38 private ushort _majorVersion;
39 private ushort _minorVersion;
40 private ushort _constantPoolCount;
41 private ushort _accessFlags;
42 private ushort _thisClass;
43 private ushort _supperClass;
44 private ushort _interfaceCount;
45 private ushort _fieldCount;
46 private ushort _methodCount;
47 //private ushort _attributeCount;
48 //private string _name;
49 public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>();
50 public PoolClass mClass;
51
52 public List<PoolItem> _constantsPool = new List<PoolItem>();
53 private List<MethodInfo> _methodsList = new List<MethodInfo>();
54 private List<FieldInfo> _fieldList = new List<FieldInfo>();
55
56 public ClassRecord()
57 {
58
59 }
60
61 public ClassInstance CreateNewInstance()
62 {
63 return new ClassInstance();
64 }
65
66 public void LoadClassFromFile(string fileName)
67 {
68 Console.WriteLine("loading script " + fileName);
69 FileStream fs = File.OpenRead(fileName);
70 this.LoadClassFromBytes(ReadFully(fs));
71 fs.Close();
72 }
73
74 public void LoadClassFromBytes(byte[] data)
75 {
76 int i = 0;
77 i += 4;
78 _minorVersion = (ushort)((data[i++] << 8) + data[i++] );
79 _majorVersion = (ushort)((data[i++] << 8) + data[i++] );
80 _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] );
81 // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool");
82 for (int count = 0; count < _constantPoolCount -1 ; count++)
83 {
84 //read in the constant pool
85 byte pooltype = data[i++];
86 //Console.WriteLine("#" +count +": new constant type = " +pooltype);
87 //Console.WriteLine("start position is: " + i);
88 switch (pooltype)
89 {
90 case 1: //Utf8
91 ushort uLength = (ushort)((data[i++] << 8) + data[i++] );
92
93 // Console.WriteLine("new utf8 type, length is " + uLength);
94 PoolUtf8 utf8 = new PoolUtf8();
95 utf8.readValue(data, ref i, uLength);
96 this._constantsPool.Add(utf8);
97 break;
98 case 3: //Int
99 break;
100 case 7: //Class
101 PoolClass pClass = new PoolClass(this);
102 pClass.readValue(data, ref i);
103 this._constantsPool.Add(pClass);
104 break;
105 case 10: //Method
106 PoolMethodRef pMeth = new PoolMethodRef(this);
107 pMeth.readValue(data, ref i);
108 this._constantsPool.Add(pMeth);
109 break;
110 case 12: //NamedType
111 PoolNamedType pNamed = new PoolNamedType(this);
112 pNamed.readValue(data, ref i);
113 this._constantsPool.Add(pNamed);
114 break;
115 }
116 }
117
118 _accessFlags = (ushort)((data[i++] << 8) + data[i++] );
119 _thisClass = (ushort)((data[i++] << 8) + data[i++] );
120 _supperClass = (ushort)((data[i++] << 8) + data[i++] );
121
122 if (this._constantsPool[this._thisClass - 1] is PoolClass)
123 {
124 this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]);
125 }
126
127 _interfaceCount = (ushort)((data[i++] << 8) + data[i++]);
128 //should now read in the info for each interface
129 _fieldCount = (ushort)((data[i++] << 8) + data[i++]);
130 //should now read in the info for each field
131 _methodCount = (ushort)((data[i++] << 8) + data[i++]);
132 for (int count = 0; count < _methodCount; count++)
133 {
134 MethodInfo methInf = new MethodInfo(this);
135 methInf.ReadData(data, ref i);
136 this._methodsList.Add(methInf);
137 }
138 }
139
140 public void AddMethodsToMemory(MethodMemory memory)
141 {
142 for (int count = 0; count < _methodCount; count++)
143 {
144 this._methodsList[count].AddMethodCode(memory);
145 }
146 }
147
148 public bool StartMethod(Thread thread, string methodName)
149 {
150 for (int count = 0; count < _methodCount; count++)
151 {
152 if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8)
153 {
154 if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName)
155 {
156 //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value);
157 thread.SetPC(this._methodsList[count].CodePointer);
158 return true;
159 }
160 }
161 }
162 return false;
163 }
164
165 public void PrintToConsole()
166 {
167 Console.WriteLine("Class File:");
168 Console.WriteLine("Major version: " + _majorVersion);
169 Console.WriteLine("Minor version: " + _minorVersion);
170 Console.WriteLine("Pool size: " + _constantPoolCount);
171
172 for (int i = 0; i < _constantsPool.Count; i++)
173 {
174 this._constantsPool[i].Print();
175 }
176
177 Console.WriteLine("Access flags: " + _accessFlags);
178 Console.WriteLine("This class: " + _thisClass );
179 Console.WriteLine("Super class: " + _supperClass);
180
181 for (int count = 0; count < _methodCount; count++)
182 {
183 Console.WriteLine();
184 this._methodsList[count].Print();
185 }
186
187 Console.WriteLine("class name is " + this.mClass.Name.Value);
188 }
189
190 public static byte[] ReadFully(Stream stream)
191 {
192 byte[] buffer = new byte[1024];
193 using (MemoryStream ms = new MemoryStream())
194 {
195 while (true)
196 {
197 int read = stream.Read(buffer, 0, buffer.Length);
198 if (read <= 0)
199 return ms.ToArray();
200 ms.Write(buffer, 0, read);
201 }
202 }
203 }
204
205 #region nested classes
206 public class PoolItem
207 {
208 public virtual void Print()
209 {
210
211 }
212 }
213
214 public class PoolUtf8 : PoolItem
215 {
216 public string Value = "";
217
218 public void readValue(byte[] data,ref int pointer , int length)
219 {
220 for (int i = 0; i < length; i++)
221 {
222 int a =(int) data[pointer++];
223 if ((a & 0x80) == 0)
224 {
225 Value = Value + (char)a;
226 }
227 else if ((a & 0x20) == 0)
228 {
229 int b = (int) data[pointer++];
230 Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f));
231 }
232 else
233 {
234 int b = (int)data[pointer++];
235 int c = (int)data[pointer++];
236 Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));
237 }
238 }
239 }
240
241 public override void Print()
242 {
243 Console.WriteLine("Utf8 type: " + Value);
244 }
245 }
246
247 private class PoolInt : PoolItem
248 {
249
250 }
251
252 public class PoolClass : PoolItem
253 {
254 //public string name = "";
255 public ushort namePointer = 0;
256 private ClassRecord parent;
257 public PoolUtf8 Name;
258
259 public PoolClass(ClassRecord paren)
260 {
261 parent = paren;
262 }
263
264 public void readValue(byte[] data, ref int pointer)
265 {
266 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
267 }
268
269 public override void Print()
270 {
271 this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]);
272 Console.Write("Class type: " + namePointer);
273 Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value);
274
275 }
276 }
277
278 public class PoolMethodRef : PoolItem
279 {
280 public ushort classPointer = 0;
281 public ushort nameTypePointer = 0;
282 public PoolNamedType mNameType;
283 public PoolClass mClass;
284 private ClassRecord parent;
285
286 public PoolMethodRef(ClassRecord paren)
287 {
288 parent = paren;
289 }
290
291 public void readValue(byte[] data, ref int pointer)
292 {
293 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
294 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
295 }
296
297 public override void Print()
298 {
299 this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]);
300 this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]);
301 Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer);
302 }
303 }
304
305 public class PoolNamedType : PoolItem
306 {
307 public ushort namePointer = 0;
308 public ushort typePointer = 0;
309 private ClassRecord parent;
310 public PoolUtf8 Name;
311 public PoolUtf8 Type;
312
313 public PoolNamedType(ClassRecord paren)
314 {
315 parent = paren;
316 }
317
318 public void readValue(byte[] data, ref int pointer)
319 {
320 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
321 typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
322 }
323
324 public override void Print()
325 {
326 Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]);
327 Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]);
328 Console.Write("Named type: " + namePointer + " , " + typePointer );
329 Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value);
330 }
331 }
332
333 //***********************
334 public class MethodInfo
335 {
336 public ushort AccessFlags = 0;
337 public ushort NameIndex = 0;
338 public string Name = "";
339 public ushort DescriptorIndex = 0;
340 public ushort AttributeCount = 0;
341 public List<MethodAttribute> Attributes = new List<MethodAttribute>();
342 private ClassRecord parent;
343 public int CodePointer = 0;
344
345 public MethodInfo(ClassRecord paren)
346 {
347 parent = paren;
348 }
349
350 public void AddMethodCode(MethodMemory memory)
351 {
352 Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length);
353 memory.Methodcount++;
354 this.CodePointer = memory.NextMethodPC;
355 memory.NextMethodPC += this.Attributes[0].Code.Length;
356 }
357
358 public void ReadData(byte[] data, ref int pointer)
359 {
360 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
361 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
362 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
363 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
364 for(int i =0; i< AttributeCount; i++)
365 {
366 MethodAttribute attri = new MethodAttribute(this.parent);
367 attri.ReadData(data, ref pointer);
368 this.Attributes.Add(attri);
369 }
370 }
371
372 public void Print()
373 {
374 Console.WriteLine("Method Info Struct: ");
375 Console.WriteLine("AccessFlags: " + AccessFlags);
376 Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
377 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value);
378 Console.WriteLine("Attribute Count:" + AttributeCount);
379 for (int i = 0; i < AttributeCount; i++)
380 {
381 this.Attributes[i].Print();
382 }
383 }
384
385 public class MethodAttribute
386 {
387 public ushort NameIndex = 0;
388 public string Name = "";
389 public Int32 Length = 0;
390 //for now only support code attribute
391 public ushort MaxStack = 0;
392 public ushort MaxLocals = 0;
393 public Int32 CodeLength = 0;
394 public byte[] Code;
395 public ushort ExceptionTableLength = 0;
396 public ushort SubAttributeCount = 0;
397 public List<SubAttribute> SubAttributes = new List<SubAttribute>();
398 private ClassRecord parent;
399
400 public MethodAttribute(ClassRecord paren)
401 {
402 parent = paren;
403 }
404
405 public void ReadData(byte[] data, ref int pointer)
406 {
407 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
408 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
409 MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]);
410 MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]);
411 CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
412 Code = new byte[CodeLength];
413 for (int i = 0; i < CodeLength; i++)
414 {
415 Code[i] = data[pointer++];
416 }
417 ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]);
418 SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
419 for (int i = 0; i < SubAttributeCount; i++)
420 {
421 SubAttribute subAttri = new SubAttribute(this.parent);
422 subAttri.ReadData(data, ref pointer);
423 this.SubAttributes.Add(subAttri);
424 }
425 }
426
427 public void Print()
428 {
429 Console.WriteLine("Method Attribute: ");
430 Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
431 Console.WriteLine("Length: " + Length);
432 Console.WriteLine("MaxStack: " + MaxStack);
433 Console.WriteLine("MaxLocals: " + MaxLocals);
434 Console.WriteLine("CodeLength: " + CodeLength);
435 for (int i = 0; i < Code.Length; i++)
436 {
437 Console.WriteLine("OpCode #" + i + " is: " + Code[i]);
438 }
439 Console.WriteLine("SubAttributes: " + SubAttributeCount);
440 for (int i = 0; i < SubAttributeCount; i++)
441 {
442 this.SubAttributes[i].Print();
443 }
444 }
445
446 public class SubAttribute
447 {
448 public ushort NameIndex = 0;
449 public string Name = "";
450 public Int32 Length = 0;
451 public byte[] Data;
452 private ClassRecord parent;
453
454 public SubAttribute(ClassRecord paren)
455 {
456 parent = paren;
457 }
458
459 public void ReadData(byte[] data, ref int pointer)
460 {
461 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
462 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
463 Data = new byte[Length];
464 for (int i = 0; i < Length; i++)
465 {
466 Data[i] = data[pointer++];
467 }
468 }
469
470 public void Print()
471 {
472 Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value);
473 }
474
475 }
476 }
477
478 }
479 private class InterfaceInfo
480 {
481 public void ReadData(byte[] data, ref int i)
482 {
483
484 }
485 }
486 private class FieldInfo
487 {
488 public void ReadData(byte[] data, ref int i)
489 {
490
491 }
492 }
493 private class AttributeInfo
494 {
495 public void ReadData(byte[] data, ref int i)
496 {
497
498 }
499 }
500 #endregion
501
502 }
503}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs
new file mode 100644
index 0000000..f213c36
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs
@@ -0,0 +1,43 @@
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.Scripting.EmbeddedJVM
33{
34 public class Heap
35 {
36 public List<ClassInstance> ClassObjects = new List<ClassInstance>();
37
38 public Heap()
39 {
40
41 }
42 }
43}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs
new file mode 100644
index 0000000..c5995b2
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs
@@ -0,0 +1,135 @@
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.Scripting.EmbeddedJVM.Types;
32using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33
34namespace OpenSim.Scripting.EmbeddedJVM
35{
36 partial class Thread
37 {
38 private partial class Interpreter
39 {
40 private Thread _mThread;
41
42 public Interpreter(Thread parentThread)
43 {
44 _mThread = parentThread;
45 }
46
47 public bool Excute()
48 {
49 bool run = true;
50 byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++];
51 // Console.WriteLine("opCode is: " + currentOpCode);
52 bool handled = false;
53
54 handled = this.IsLogicOpCode(currentOpCode);
55 if (!handled)
56 {
57 handled = this.IsMethodOpCode(currentOpCode);
58 }
59 if (!handled)
60 {
61 if (currentOpCode == 172)
62 {
63 if (this._mThread.stack.StackFrames.Count > 1)
64 {
65 Console.WriteLine("returning int from function");
66 int retPC1 = this._mThread.currentFrame.ReturnPC;
67 BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
68 this._mThread.stack.StackFrames.Pop();
69 this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
70 this._mThread.PC = retPC1;
71 if (bas1 is Int)
72 {
73 this._mThread.currentFrame.OpStack.Push((Int)bas1);
74 }
75 }
76 else
77 {
78 // Console.WriteLine("No parent function so ending program");
79 this._mThread.stack.StackFrames.Pop();
80 run = false;
81 }
82 handled = true;
83 }
84 if (currentOpCode == 174)
85 {
86 if (this._mThread.stack.StackFrames.Count > 1)
87 {
88 Console.WriteLine("returning float from function");
89 int retPC1 = this._mThread.currentFrame.ReturnPC;
90 BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
91 this._mThread.stack.StackFrames.Pop();
92 this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
93 this._mThread.PC = retPC1;
94 if (bas1 is Float)
95 {
96 this._mThread.currentFrame.OpStack.Push((Float)bas1);
97 }
98 }
99 else
100 {
101 // Console.WriteLine("No parent function so ending program");
102 this._mThread.stack.StackFrames.Pop();
103 run = false;
104 }
105 handled = true;
106 }
107 if (currentOpCode == 177)
108 {
109 if (this._mThread.stack.StackFrames.Count > 1)
110 {
111 Console.WriteLine("returning from function");
112 int retPC = this._mThread.currentFrame.ReturnPC;
113 this._mThread.stack.StackFrames.Pop();
114 this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
115 this._mThread.PC = retPC;
116 }
117 else
118 {
119 // Console.WriteLine("No parent function so ending program");
120 this._mThread.stack.StackFrames.Pop();
121 run = false;
122 }
123 handled = true;
124 }
125 }
126 if (!handled)
127 {
128 Console.WriteLine("opcode " + currentOpCode + " not been handled ");
129 }
130 return run;
131
132 }
133 }
134 }
135}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs
new file mode 100644
index 0000000..2a11afd
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs
@@ -0,0 +1,427 @@
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.Scripting.EmbeddedJVM.Types;
32using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33
34namespace OpenSim.Scripting.EmbeddedJVM
35{
36 partial class Thread
37 {
38 private partial class Interpreter
39 {
40 private bool IsLogicOpCode(byte opcode)
41 {
42 bool result = false;
43 switch (opcode)
44 {
45 case 2:
46 Int m_int= new Int();
47 m_int.mValue = -1;
48 this._mThread.currentFrame.OpStack.Push(m_int);
49 result = true;
50 break;
51 case 3:
52 m_int= new Int();
53 m_int.mValue = 0;
54 this._mThread.currentFrame.OpStack.Push(m_int);
55 result = true;
56 break;
57 case 4:
58 m_int = new Int();
59 m_int.mValue = 1;
60 this._mThread.currentFrame.OpStack.Push(m_int);
61 result = true;
62 break;
63 case 5:
64 m_int = new Int();
65 m_int.mValue = 2;
66 this._mThread.currentFrame.OpStack.Push(m_int);
67 result = true;
68 break;
69 case 6:
70 m_int = new Int();
71 m_int.mValue = 3;
72 this._mThread.currentFrame.OpStack.Push(m_int);
73 break;
74 case 7:
75 m_int = new Int();
76 m_int.mValue = 4;
77 this._mThread.currentFrame.OpStack.Push(m_int);
78 result = true;
79 break;
80 case 8:
81 m_int = new Int();
82 m_int.mValue = 5;
83 this._mThread.currentFrame.OpStack.Push(m_int);
84 result = true;
85 break;
86 case 11:
87 Float m_float = new Float();
88 m_float.mValue = 0.0f;
89 this._mThread.currentFrame.OpStack.Push(m_float);
90 result = true;
91 break;
92 case 12:
93 m_float = new Float();
94 m_float.mValue = 1.0f;
95 this._mThread.currentFrame.OpStack.Push(m_float);
96 result = true;
97 break;
98 case 13:
99 m_float = new Float();
100 m_float.mValue = 2.0f;
101 this._mThread.currentFrame.OpStack.Push(m_float);
102 result = true;
103 break;
104 case 16:
105 int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC];
106 Int pushInt = new Int();
107 pushInt.mValue = pushvalue;
108 this._mThread.currentFrame.OpStack.Push(pushInt);
109 this._mThread.PC++;
110 result = true;
111 break;
112 case 17:
113 short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
114 Int pushInt2 = new Int();
115 pushInt2.mValue = pushvalue2;
116 this._mThread.currentFrame.OpStack.Push(pushInt2);
117 this._mThread.PC += 2;
118 result = true;
119 break;
120 case 23:
121 short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]));
122 Float fload = new Float();
123 if (this._mThread.currentFrame.LocalVariables[findex1] != null)
124 {
125 if (this._mThread.currentFrame.LocalVariables[findex1] is Float)
126 {
127 fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue;
128 this._mThread.currentFrame.OpStack.Push(fload);
129 }
130 }
131 this._mThread.PC++;
132 result = true;
133 break;
134 case 26:
135 if (this._mThread.currentFrame.LocalVariables[0] != null)
136 {
137 if (this._mThread.currentFrame.LocalVariables[0] is Int)
138 {
139 Int newInt = new Int();
140 newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue;
141 this._mThread.currentFrame.OpStack.Push(newInt);
142 }
143 }
144 result = true;
145 break;
146 case 27:
147 if (this._mThread.currentFrame.LocalVariables[1] != null)
148 {
149 if (this._mThread.currentFrame.LocalVariables[1] is Int)
150 {
151 Int newInt = new Int();
152 newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue;
153 this._mThread.currentFrame.OpStack.Push(newInt);
154 }
155 }
156 result = true;
157 break;
158 case 34:
159 if (this._mThread.currentFrame.LocalVariables[0] != null)
160 {
161 if (this._mThread.currentFrame.LocalVariables[0] is Float)
162 {
163 Float newfloat = new Float();
164 newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue;
165 this._mThread.currentFrame.OpStack.Push(newfloat);
166 }
167 }
168 result = true;
169 break;
170 case 35:
171 if (this._mThread.currentFrame.LocalVariables[1] != null)
172 {
173 if (this._mThread.currentFrame.LocalVariables[1] is Float)
174 {
175 Float newfloat = new Float();
176 newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue;
177 this._mThread.currentFrame.OpStack.Push(newfloat);
178 }
179 }
180 result = true;
181 break;
182 case 36:
183 if (this._mThread.currentFrame.LocalVariables[2] != null)
184 {
185 if (this._mThread.currentFrame.LocalVariables[2] is Float)
186 {
187 Float newfloat = new Float();
188 newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue;
189 this._mThread.currentFrame.OpStack.Push(newfloat);
190 }
191 }
192 result = true;
193 break;
194 case 37:
195 if (this._mThread.currentFrame.LocalVariables[3] != null)
196 {
197 if (this._mThread.currentFrame.LocalVariables[3] is Float)
198 {
199 Float newfloat = new Float();
200 newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue;
201 this._mThread.currentFrame.OpStack.Push(newfloat);
202 }
203 }
204 result = true;
205 break;
206 case 56:
207 short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] ));
208 BaseType fstor = this._mThread.currentFrame.OpStack.Pop();
209 if (fstor is Float)
210 {
211 this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor;
212 }
213 this._mThread.PC++;
214 result = true;
215 break;
216 case 59:
217 BaseType baset = this._mThread.currentFrame.OpStack.Pop();
218 if (baset is Int)
219 {
220 this._mThread.currentFrame.LocalVariables[0] = (Int)baset;
221 }
222 result = true;
223 break;
224 case 60:
225 baset = this._mThread.currentFrame.OpStack.Pop();
226 if (baset is Int)
227 {
228 this._mThread.currentFrame.LocalVariables[1] = (Int)baset;
229 }
230 result = true;
231 break;
232 case 67:
233 baset = this._mThread.currentFrame.OpStack.Pop();
234 if (baset is Float)
235 {
236 this._mThread.currentFrame.LocalVariables[0] = (Float)baset;
237 }
238 result = true;
239 break;
240 case 68:
241 baset = this._mThread.currentFrame.OpStack.Pop();
242 if (baset is Float)
243 {
244 this._mThread.currentFrame.LocalVariables[1] = (Float)baset;
245 }
246 result = true;
247 break;
248 case 69:
249 baset = this._mThread.currentFrame.OpStack.Pop();
250 if (baset is Float)
251 {
252 this._mThread.currentFrame.LocalVariables[2] = (Float)baset;
253 }
254 result = true;
255 break;
256 case 70:
257 baset = this._mThread.currentFrame.OpStack.Pop();
258 if (baset is Float)
259 {
260 this._mThread.currentFrame.LocalVariables[3] = (Float)baset;
261 }
262 result = true;
263 break;
264 case 87:
265 this._mThread.currentFrame.OpStack.Pop();
266 result = true;
267 break;
268 case 98:
269 BaseType bf2 = this._mThread.currentFrame.OpStack.Pop();
270 BaseType bf1 = this._mThread.currentFrame.OpStack.Pop();
271 if (bf1 is Float && bf2 is Float)
272 {
273 Float nflt = new Float();
274 nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
275 this._mThread.currentFrame.OpStack.Push(nflt);
276 }
277 result = true;
278 break;
279 case 102:
280 BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop();
281 BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop();
282 if (bsf1 is Float && bsf2 is Float)
283 {
284 Float resf = new Float();
285 resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue;
286 this._mThread.currentFrame.OpStack.Push(resf);
287 }
288 result = true;
289 break;
290 case 104: //check the order of the two values off the stack is correct
291 BaseType bs2 = this._mThread.currentFrame.OpStack.Pop();
292 BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
293 if (bs1 is Int && bs2 is Int)
294 {
295 Int nInt = new Int();
296 nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
297 this._mThread.currentFrame.OpStack.Push(nInt);
298 }
299 result = true;
300 break;
301 case 132:
302 if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null)
303 {
304 if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int)
305 {
306 ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1];
307 }
308 }
309 this._mThread.PC += 2;
310 result = true;
311 break;
312 case 139:
313 BaseType conv1 = this._mThread.currentFrame.OpStack.Pop();
314 if (conv1 is Float)
315 {
316 Int newconv = new Int();
317 newconv.mValue = (int)((Float)conv1).mValue;
318 this._mThread.currentFrame.OpStack.Push(newconv);
319 }
320 result = true;
321 break;
322 case 149:
323 BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop();
324 BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop();
325 if (flcom1 is Float && flcom2 is Float)
326 {
327 Int compres = new Int();
328 if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
329 {
330 compres.mValue = -1;
331 }
332 else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
333 {
334 compres.mValue = 1;
335 }
336 else
337 {
338 compres.mValue = 0;
339 }
340 this._mThread.currentFrame.OpStack.Push(compres);
341 }
342 result = true;
343 break;
344 case 158:
345 short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
346 BaseType comp1 = this._mThread.currentFrame.OpStack.Pop();
347 if (comp1 is Int)
348 {
349 if (((Int)comp1).mValue <= 0)
350 {
351 this._mThread.PC += -1 + compareoffset1;
352 }
353 else
354 {
355 this._mThread.PC += 2;
356 }
357 }
358 else
359 {
360 this._mThread.PC += 2;
361 }
362 result = true;
363 break;
364 case 162:
365 short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
366 BaseType bc2 = this._mThread.currentFrame.OpStack.Pop();
367 BaseType bc1 = this._mThread.currentFrame.OpStack.Pop();
368 if (bc1 is Int && bc2 is Int)
369 {
370 //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
371 if (((Int)bc1).mValue >= ((Int)bc2).mValue)
372 {
373 // Console.WriteLine("branch compare true , offset is " +compareoffset);
374 // Console.WriteLine("current PC is " + this._mThread.PC);
375 this._mThread.PC += -1 + compareoffset;
376 //Console.WriteLine("new PC is " + this._mThread.PC);
377 }
378 else
379 {
380 //Console.WriteLine("branch compare false");
381 this._mThread.PC += 2;
382 }
383 }
384 else
385 {
386 this._mThread.PC += 2;
387 }
388 result = true;
389 break;
390 case 164:
391 short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
392 BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop();
393 BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop();
394 if (bcl1 is Int && bcl2 is Int)
395 {
396 //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
397 if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
398 {
399 // Console.WriteLine("branch compare true , offset is " + compareloffset);
400 // Console.WriteLine("current PC is " + this._mThread.PC);
401 this._mThread.PC += -1 + compareloffset;
402 // Console.WriteLine("new PC is " + this._mThread.PC);
403 }
404 else
405 {
406 //Console.WriteLine("branch compare false");
407 this._mThread.PC += 2;
408 }
409 }
410 else
411 {
412 this._mThread.PC += 2;
413 }
414 result = true;
415 break;
416 case 167:
417 short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
418 this._mThread.PC += -1 + offset;
419 result = true;
420 break;
421 }
422
423 return result;
424 }
425 }
426 }
427}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs
new file mode 100644
index 0000000..4d60559
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs
@@ -0,0 +1,96 @@
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.Scripting.EmbeddedJVM.Types;
32using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Framework;
35using OpenSim.Framework.Types;
36
37namespace OpenSim.Scripting.EmbeddedJVM
38{
39 partial class Thread
40 {
41 private partial class Interpreter
42 {
43 private bool IsMethodOpCode(byte opcode)
44 {
45 bool result = false;
46 switch (opcode)
47 {
48 case 184:
49 short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
50 if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef)
51 {
52 string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value;
53 string typeparam = "";
54 string typereturn = "";
55 int firstbrak = 0;
56 int secondbrak = 0;
57 firstbrak = typ.LastIndexOf('(');
58 secondbrak = typ.LastIndexOf(')');
59 typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1);
60 typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1);
61 if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value)
62 {
63 //calling a method in this class
64 if (typeparam.Length == 0)
65 {
66 this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2));
67 }
68 else
69 {
70 this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2));
71 }
72 }
73 else
74 {
75 //calling a method of a different class
76
77 // OpenSimAPI Class
78 if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI")
79 {
80 this._mThread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, null);
81 }
82 }
83 }
84 else
85 {
86 this._mThread.PC += 2;
87 }
88 result = true;
89 break;
90 }
91
92 return result;
93 }
94 }
95 }
96}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs
new file mode 100644
index 0000000..cbedb71
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.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;
31
32namespace OpenSim.Scripting.EmbeddedJVM
33{
34 partial class Thread
35 {
36 private partial class Interpreter
37 {
38 }
39 }
40}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs
new file mode 100644
index 0000000..1773156
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs
@@ -0,0 +1,29 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Environment.Scripting;
6using OpenSim.Scripting.EmbeddedJVM;
7
8namespace OpenSim.Region.Environment.Scripting
9{
10 public class JavaEngine : IScriptCompiler
11 {
12 public string FileExt()
13 {
14 return ".java";
15 }
16
17 public Dictionary<string, IScript> compile(string filename)
18 {
19 JVMScript script = new JVMScript();
20 Dictionary<string, IScript> returns = new Dictionary<string, IScript>();
21
22 script.LoadScript(filename);
23
24 returns.Add(filename, script);
25
26 return returns;
27 }
28 }
29}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs
new file mode 100644
index 0000000..97d9fb6
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs
@@ -0,0 +1,45 @@
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.Scripting.EmbeddedJVM
33{
34 public class MainMemory
35 {
36 public Heap HeapArea;
37 public MethodMemory MethodArea;
38
39 public MainMemory()
40 {
41 MethodArea = new MethodMemory();
42 HeapArea = new Heap();
43 }
44 }
45}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs
new file mode 100644
index 0000000..7e938b4
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.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;
31
32namespace OpenSim.Scripting.EmbeddedJVM
33{
34 public class MethodMemory
35 {
36 public byte[] MethodBuffer;
37 public List<ClassRecord> Classes = new List<ClassRecord>();
38 public int NextMethodPC = 0;
39 public int Methodcount = 0;
40
41 public MethodMemory()
42 {
43 MethodBuffer = new byte[20000];
44 }
45 }
46}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs
new file mode 100644
index 0000000..2c3bedd
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs
@@ -0,0 +1,37 @@
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.Scripting.EmbeddedJVM
33{
34 public class Object
35 {
36 }
37}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs
new file mode 100644
index 0000000..3e083cc
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs
@@ -0,0 +1,171 @@
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.Threading;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Utilities;
36using OpenSim.Region.Environment.Scripting;
37using OpenSim.Region.Environment.Scenes;
38
39namespace OpenSim.Scripting.EmbeddedJVM
40{
41 public class JVMScript : IScript
42 {
43 private List<Thread> _threads = new List<Thread>();
44 private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>();
45 private MainMemory _mainMemory;
46 private System.Threading.Thread compileThread;
47
48 ScriptInfo scriptInfo;
49
50 public void Initialise(ScriptInfo info)
51 {
52 scriptInfo = info;
53
54 _mainMemory = new MainMemory();
55 Thread.GlobalMemory = this._mainMemory;
56 Thread.World = info.world;
57 CompileScript();
58
59 scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
60 scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
61 }
62
63 void events_OnNewPresence(ScenePresence presence)
64 {
65 for (int i = 0; i < this._threads.Count; i++)
66 {
67 if (!this._threads[i].running)
68 {
69 this._threads[i].StartMethod("OnNewPresence");
70 bool run = true;
71 while (run)
72 {
73 run = this._threads[i].Excute();
74 }
75 }
76 }
77 }
78
79 void events_OnFrame()
80 {
81 for (int i = 0; i < this._threads.Count; i++)
82 {
83 if (!this._threads[i].running)
84 {
85 this._threads[i].StartMethod("OnFrame");
86 bool run = true;
87 while (run)
88 {
89 run = this._threads[i].Excute();
90 }
91 }
92 }
93 }
94
95 public string getName()
96 {
97 return "JVM Scripting Engine";
98 }
99
100 public void LoadScript(string script)
101 {
102 Console.WriteLine("OpenSimJVM - loading new script: " + script);
103 CompileInfo comp = new CompileInfo();
104 comp.script = script;
105 comp.scriptName = script;
106 this.CompileScripts.Enqueue(comp);
107 }
108
109 public void CompileScript()
110 {
111 CompileInfo comp = this.CompileScripts.Dequeue();
112 string script = comp.script;
113 string scriptName = comp.scriptName;
114 try
115 {
116 //need to compile the script into a java class file
117
118 //first save it to a java source file
119 TextWriter tw = new StreamWriter(scriptName + ".java");
120 tw.WriteLine(script);
121 tw.Close();
122
123 //now compile
124 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
125 // psi.RedirectStandardOutput = true;
126 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
127 psi.UseShellExecute = false;
128
129 System.Diagnostics.Process javacomp;
130 javacomp = System.Diagnostics.Process.Start(psi);
131 javacomp.WaitForExit();
132
133
134 //now load in class file
135 ClassRecord class1 = new ClassRecord();
136 class1.LoadClassFromFile(scriptName + ".class");
137 class1.PrintToConsole();
138 //Console.WriteLine();
139 this._mainMemory.MethodArea.Classes.Add(class1);
140 class1.AddMethodsToMemory(this._mainMemory.MethodArea);
141
142 Thread newThread = new Thread();
143 this._threads.Add(newThread);
144 newThread.currentClass = class1;
145 newThread.scriptInfo = scriptInfo;
146
147 //now delete the created files
148 System.IO.File.Delete(scriptName + ".java");
149 System.IO.File.Delete(scriptName + ".class");
150 //this.OnFrame();
151 }
152 catch (Exception e)
153 {
154 Console.WriteLine("exception");
155 Console.WriteLine(e.StackTrace);
156 Console.WriteLine(e.Message);
157 }
158 }
159
160 private class CompileInfo
161 {
162 public string script;
163 public string scriptName;
164
165 public CompileInfo()
166 {
167
168 }
169 }
170 }
171}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs
new file mode 100644
index 0000000..69a274c
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs
@@ -0,0 +1,42 @@
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.Scripting.EmbeddedJVM
33{
34 public class Stack
35 {
36 public Stack<StackFrame> StackFrames = new Stack<StackFrame>();
37
38 public Stack()
39 {
40 }
41 }
42}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs
new file mode 100644
index 0000000..3a2b58a
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs
@@ -0,0 +1,49 @@
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.Scripting.EmbeddedJVM.Types;
32
33namespace OpenSim.Scripting.EmbeddedJVM
34{
35 public class StackFrame
36 {
37 public BaseType[] LocalVariables;
38 public Stack<BaseType> OpStack = new Stack<BaseType>();
39
40 public int ReturnPC = 0;
41 public ClassRecord CallingClass = null;
42
43 public StackFrame()
44 {
45 LocalVariables = new BaseType[20];
46 }
47
48 }
49}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs
new file mode 100644
index 0000000..3993436
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs
@@ -0,0 +1,119 @@
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.Scripting.EmbeddedJVM.Types;
32using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Environment.Scripting;
37
38namespace OpenSim.Scripting.EmbeddedJVM
39{
40 public partial class Thread
41 {
42 // Is this smart?
43 public static MainMemory GlobalMemory;
44 public static Scene World;
45 private int PC = 0;
46 private Stack stack;
47 private Interpreter mInterpreter;
48 public ClassRecord currentClass;
49 public ClassInstance currentInstance;
50 private StackFrame currentFrame;
51 public int excutionCounter = 0;
52 public bool running = false;
53
54 public ScriptInfo scriptInfo;
55
56 public Thread()
57 {
58 this.mInterpreter = new Interpreter(this);
59 this.stack = new Stack();
60 }
61
62 public void SetPC(int methodpointer)
63 {
64 //Console.WriteLine("Thread PC has been set to " + methodpointer);
65 PC = methodpointer;
66 }
67
68 public void StartMethod(ClassRecord rec, string methName)
69 {
70 currentFrame = new StackFrame();
71 this.stack.StackFrames.Push(currentFrame);
72 this.currentClass = rec;
73 currentClass.StartMethod(this, methName);
74 }
75
76 public void StartMethod( string methName)
77 {
78 currentFrame = new StackFrame();
79 this.stack.StackFrames.Push(currentFrame);
80 currentClass.StartMethod(this, methName);
81 }
82
83 public void JumpToStaticVoidMethod(string methName, int returnPC)
84 {
85 currentFrame = new StackFrame();
86 currentFrame.ReturnPC = returnPC;
87 this.stack.StackFrames.Push(currentFrame);
88 currentClass.StartMethod(this, methName);
89 }
90
91 public void JumpToStaticParamMethod(string methName, string param, int returnPC)
92 {
93 if (param == "I")
94 {
95 BaseType bs1 = currentFrame.OpStack.Pop();
96 currentFrame = new StackFrame();
97 currentFrame.ReturnPC = returnPC;
98 this.stack.StackFrames.Push(currentFrame);
99 currentFrame.LocalVariables[0] = ((Int)bs1);
100 currentClass.StartMethod(this, methName);
101 }
102 if (param == "F")
103 {
104
105 }
106 }
107
108 public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC)
109 {
110
111 }
112
113 public bool Excute()
114 {
115 excutionCounter++;
116 return this.mInterpreter.Excute();
117 }
118 }
119}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs
new file mode 100644
index 0000000..2854eab
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types
6{
7 public class ArrayReference :BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs
new file mode 100644
index 0000000..270aa7b
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types
6{
7 public class BaseType : Object
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs
new file mode 100644
index 0000000..da28eaa
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types
6{
7 public class ObjectReference : BaseType
8 {
9 public ushort Reference;
10
11 public ObjectReference()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
new file mode 100644
index 0000000..1a3ecff
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Byte : BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
new file mode 100644
index 0000000..19002d4
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Char : BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
new file mode 100644
index 0000000..91f1679
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Float : BaseType
8 {
9 public float mValue = 0;
10
11 public Float()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
new file mode 100644
index 0000000..4ecd325
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Int : BaseType
8 {
9 public int mValue = 0;
10
11 public Int()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Script.cs b/OpenSim/Region/Environment/Scenes/scripting/Script.cs
new file mode 100644
index 0000000..139bdf1
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Script.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 OpenSim.Region.Environment.Scenes;
29
30namespace OpenSim.Region.Environment.Scripting
31{
32 public interface IScript
33 {
34 void Initialise(ScriptInfo scriptInfo);
35 string getName();
36 }
37
38 public class TestScript : IScript
39 {
40 ScriptInfo script;
41
42 public string getName()
43 {
44 return "TestScript 0.1";
45 }
46
47 public void Initialise(ScriptInfo scriptInfo)
48 {
49 script = scriptInfo;
50 script.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
51 script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
52 }
53
54 void events_OnNewPresence(ScenePresence presence)
55 {
56 script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
57 }
58
59 void events_OnFrame()
60 {
61 //script.logger.Verbose("Hello World!");
62 }
63 }
64}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs
new file mode 100644
index 0000000..fd601cb
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs
@@ -0,0 +1,25 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Environment.Scenes;
6
7namespace OpenSim.Region.Environment.Scripting
8{
9 // This class is to be used for engines which may not be able to access the Scene directly.
10 // Scene access is preffered, but obviously not possible on some non-.NET languages.
11 public class ScriptAPI
12 {
13 Scene scene;
14
15 public ScriptAPI(Scene world)
16 {
17 scene = world;
18 }
19
20 public Object CallMethod(String method, Object[] args)
21 {
22 return null;
23 }
24 }
25}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
new file mode 100644
index 0000000..ed6f033
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
@@ -0,0 +1,58 @@
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 OpenSim.Framework.Console;
29using OpenSim.Region.Environment.Scenes;
30
31namespace OpenSim.Region.Environment.Scripting
32{
33 /// <summary>
34 /// Class which provides access to the world
35 /// </summary>
36 public class ScriptInfo
37 {
38 // Reference to world.eventsManager provided for convenience
39 public EventManager events;
40
41 // The main world
42 public Scene world;
43
44 // The console
45 public LogBase logger;
46
47 // API Access
48 public ScriptAPI api;
49
50 public ScriptInfo(Scene scene)
51 {
52 world = scene;
53 events = world.eventManager;
54 logger = MainLog.Instance;
55 api = new ScriptAPI(scene);
56 }
57 }
58}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
new file mode 100644
index 0000000..153f4d7
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
@@ -0,0 +1,99 @@
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.Collections.Generic;
29using OpenSim.Framework.Console;
30using OpenSim.Region.Environment.Scenes;
31
32namespace OpenSim.Region.Environment.Scripting
33{
34 public class ScriptManager
35 {
36 List<IScript> scripts = new List<IScript>();
37 Scene scene;
38 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
39
40 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
41 {
42 foreach (KeyValuePair<string, IScript> script in compiledscripts)
43 {
44 ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
45 MainLog.Instance.Verbose("Loading " + script.Key);
46 script.Value.Initialise(scriptInfo);
47 scripts.Add(script.Value);
48 }
49 MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
50 }
51
52 public ScriptManager(Scene world)
53 {
54 scene = world;
55
56 // Default Engines
57 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
58 compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
59
60 JScriptEngine jscriptCompiler = new JScriptEngine();
61 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
62
63 JavaEngine javaCompiler = new JavaEngine();
64 compilers.Add(javaCompiler.FileExt(), javaCompiler);
65 }
66
67 public void Compile(string filename)
68 {
69 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
70 {
71 if (filename.EndsWith(compiler.Key))
72 {
73 LoadFromCompiler(compiler.Value.compile(filename));
74 break;
75 }
76 }
77 }
78
79 public void RunScriptCmd(string[] args)
80 {
81 switch (args[0])
82 {
83 case "load":
84 Compile(args[1]);
85 break;
86
87 default:
88 MainLog.Instance.Error("Unknown script command");
89 break;
90 }
91 }
92 }
93
94 interface IScriptCompiler
95 {
96 Dictionary<string,IScript> compile(string filename);
97 string FileExt();
98 }
99}