aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/world
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Avatar.Client.cs33
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs338
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Avatar.cs438
-rw-r--r--OpenSim/OpenSim.RegionServer/world/AvatarAnimations.cs163
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Entity.cs124
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Primitive.cs570
-rw-r--r--OpenSim/OpenSim.RegionServer/world/Primitive2.cs491
-rw-r--r--OpenSim/OpenSim.RegionServer/world/SceneObject.cs77
-rw-r--r--OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs368
-rw-r--r--OpenSim/OpenSim.RegionServer/world/World.Scripting.cs124
-rw-r--r--OpenSim/OpenSim.RegionServer/world/World.cs657
-rw-r--r--OpenSim/OpenSim.RegionServer/world/WorldBase.cs176
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/IScriptContext.cs13
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/IScriptEntity.cs19
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/IScriptHandler.cs98
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/Script.cs26
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/ScriptFactory.cs8
-rw-r--r--OpenSim/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs37
18 files changed, 3760 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/world/Avatar.Client.cs b/OpenSim/OpenSim.RegionServer/world/Avatar.Client.cs
new file mode 100644
index 0000000..7656a89
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Avatar.Client.cs
@@ -0,0 +1,33 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife.Packets;
5
6namespace OpenSim.world
7{
8 partial class Avatar
9 {
10 private List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock> updateList = new List<ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
11 private List<Entity> interestList = new List<Entity>();
12
13 public void SendPacketToViewer(Packet packet)
14 {
15 this.ControllingClient.OutPacket(packet);
16 }
17
18 public void AddTerseUpdateToViewersList(ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock)
19 {
20
21 }
22
23 public void SendUpdateListToViewer()
24 {
25
26 }
27
28 private void UpdateInterestList()
29 {
30
31 }
32 }
33}
diff --git a/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs b/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
new file mode 100644
index 0000000..67eab24
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Avatar.Update.cs
@@ -0,0 +1,338 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using libsecondlife.Packets;
6using OpenSim.Physics.Manager;
7
8namespace OpenSim.world
9{
10 partial class Avatar
11 {
12 public override void update()
13 {
14 if (!this.childAvatar)
15 {
16 if (this._physActor == null)
17 {
18 //HACKHACK: Note to work out why this entity does not have a physics actor
19 // and prehaps create one.
20 return;
21 }
22 libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
23 if (this.updateflag)
24 {
25 //need to send movement info
26 //so create the improvedterseobjectupdate packet
27 //use CreateTerseBlock()
28 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
29 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
30 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
31 terse.RegionData.TimeDilation = 64096;
32 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
33 terse.ObjectData[0] = terseBlock;
34 List<Avatar> avList = this.m_world.RequestAvatarList();
35 foreach (Avatar client in avList)
36 {
37 client.SendPacketToViewer(terse);
38 }
39
40 updateflag = false;
41 //this._updateCount = 0;
42 }
43 else
44 {
45
46 if ((pos2 != this.positionLastFrame) || (this.movementflag == 16))
47 {
48 _updateCount++;
49 if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0))
50 {
51 //It has been a while since last update was sent so lets send one.
52 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
53 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
54 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
55 terse.RegionData.TimeDilation = 64096;
56 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
57 terse.ObjectData[0] = terseBlock;
58 List<Avatar> avList = this.m_world.RequestAvatarList();
59 foreach (Avatar client in avList)
60 {
61 client.SendPacketToViewer(terse);
62 }
63 _updateCount = 0;
64 }
65
66 if (this.movementflag == 16)
67 {
68 movementflag = 0;
69 }
70 }
71
72 }
73 this.positionLastFrame = pos2;
74
75 if (!this.ControllingClient.m_sandboxMode)
76 {
77 if (pos2.X < 0)
78 {
79 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
80 }
81
82 if (pos2.Y < 0)
83 {
84 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
85 }
86
87 if (pos2.X > 255)
88 {
89 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
90 }
91
92 if (pos2.Y > 255)
93 {
94 ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z));
95 }
96 }
97 }
98
99 }
100
101 public void SendUpdateToOtherClient(Avatar remoteAvatar)
102 {
103 ObjectUpdatePacket objupdate = CreateUpdatePacket();
104 remoteAvatar.SendPacketToViewer(objupdate);
105 }
106
107 public ObjectUpdatePacket CreateUpdatePacket()
108 {
109 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
110 //send a objectupdate packet with information about the clients avatar
111 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
112 objupdate.RegionData.RegionHandle = m_regionHandle;
113 objupdate.RegionData.TimeDilation = 64096;
114 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
115
116 objupdate.ObjectData[0] = AvatarTemplate;
117 //give this avatar object a local id and assign the user a name
118 objupdate.ObjectData[0].ID = this.localid;
119 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
120 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
121
122 libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z);
123
124 byte[] pb = pos2.GetBytes();
125
126 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
127 return objupdate;
128 }
129
130 public void SendInitialPosition()
131 {
132 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
133 //send a objectupdate packet with information about the clients avatar
134
135 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
136 objupdate.RegionData.RegionHandle = m_regionHandle;
137 objupdate.RegionData.TimeDilation = 64096;
138 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
139 objupdate.ObjectData[0] = AvatarTemplate;
140 //give this avatar object a local id and assign the user a name
141
142 objupdate.ObjectData[0].ID = this.localid;
143 this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
144 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
145 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z);
146 byte[] pb = pos2.GetBytes();
147 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
148 m_world._localNumber++;
149
150 List<Avatar> avList = this.m_world.RequestAvatarList();
151 foreach (Avatar client in avList)
152 {
153 client.SendPacketToViewer(objupdate);
154 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
155 {
156 SendAppearanceToOtherAgent(client);
157 }
158 }
159 }
160
161 public void SendOurAppearance()
162 {
163 ControllingClient.SendAppearance(this.Wearables);
164 }
165
166 public void SendOurAppearance(ClientView OurClient)
167 {
168 //event handler for wearables request
169 this.SendOurAppearance();
170 }
171
172 public void SendAppearanceToOtherAgent(Avatar avatarInfo)
173 {
174 AvatarAppearancePacket avp = new AvatarAppearancePacket();
175 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
176 avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes();
177
178 AvatarAppearancePacket.VisualParamBlock avblock = null;
179 for (int i = 0; i < 218; i++)
180 {
181 avblock = new AvatarAppearancePacket.VisualParamBlock();
182 avblock.ParamValue = visualParams[i];
183 avp.VisualParam[i] = avblock;
184 }
185
186 avp.Sender.IsTrial = false;
187 avp.Sender.ID = ControllingClient.AgentID;
188 avatarInfo.SendPacketToViewer(avp);
189 }
190
191 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
192 {
193 LLObject.TextureEntry tex = new LLObject.TextureEntry(texture, 0, texture.Length);
194 this.avatarAppearanceTexture = tex;
195
196 for (int i = 0; i < visualParam.Length; i++)
197 {
198 this.visualParams[i] = visualParam[i].ParamValue;
199 }
200
201 List<Avatar> avList = this.m_world.RequestAvatarList();
202 foreach (Avatar client in avList)
203 {
204 if (client.ControllingClient.AgentID != this.ControllingClient.AgentID)
205 {
206 SendAppearanceToOtherAgent(client);
207 }
208 }
209 }
210
211 public void StopMovement()
212 {
213 this._physActor.Velocity = new PhysicsVector(0, 0, 0);
214 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
215 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
216 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
217 terse.RegionData.TimeDilation = 64096;
218 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
219 terse.ObjectData[0] = terseBlock;
220 List<Avatar> avList = this.m_world.RequestAvatarList();
221 foreach (Avatar client in avList)
222 {
223 client.SendPacketToViewer(terse);
224 }
225 }
226
227 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
228 {
229 byte[] bytes = new byte[60];
230 int i = 0;
231 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
232
233 dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry;
234 libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0);
235 lock (m_world.LockPhysicsEngine)
236 {
237 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
238 }
239
240 uint ID = this.localid;
241
242 bytes[i++] = (byte)(ID % 256);
243 bytes[i++] = (byte)((ID >> 8) % 256);
244 bytes[i++] = (byte)((ID >> 16) % 256);
245 bytes[i++] = (byte)((ID >> 24) % 256);
246 bytes[i++] = 0;
247 bytes[i++] = 1;
248 i += 14;
249 bytes[i++] = 128;
250 bytes[i++] = 63;
251
252 byte[] pb = pos2.GetBytes();
253 Array.Copy(pb, 0, bytes, i, pb.Length);
254 i += 12;
255 ushort InternVelocityX;
256 ushort InternVelocityY;
257 ushort InternVelocityZ;
258 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0);
259 lock (m_world.LockPhysicsEngine)
260 {
261 internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z);
262 }
263 internDirec = internDirec / 128.0f;
264 internDirec.x += 1;
265 internDirec.y += 1;
266 internDirec.z += 1;
267
268 InternVelocityX = (ushort)(32768 * internDirec.x);
269 InternVelocityY = (ushort)(32768 * internDirec.y);
270 InternVelocityZ = (ushort)(32768 * internDirec.z);
271
272 ushort ac = 32767;
273 bytes[i++] = (byte)(InternVelocityX % 256);
274 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
275 bytes[i++] = (byte)(InternVelocityY % 256);
276 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
277 bytes[i++] = (byte)(InternVelocityZ % 256);
278 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
279
280 //accel
281 bytes[i++] = (byte)(ac % 256);
282 bytes[i++] = (byte)((ac >> 8) % 256);
283 bytes[i++] = (byte)(ac % 256);
284 bytes[i++] = (byte)((ac >> 8) % 256);
285 bytes[i++] = (byte)(ac % 256);
286 bytes[i++] = (byte)((ac >> 8) % 256);
287
288 //rot
289 bytes[i++] = (byte)(ac % 256);
290 bytes[i++] = (byte)((ac >> 8) % 256);
291 bytes[i++] = (byte)(ac % 256);
292 bytes[i++] = (byte)((ac >> 8) % 256);
293 bytes[i++] = (byte)(ac % 256);
294 bytes[i++] = (byte)((ac >> 8) % 256);
295 bytes[i++] = (byte)(ac % 256);
296 bytes[i++] = (byte)((ac >> 8) % 256);
297
298 //rotation vel
299 bytes[i++] = (byte)(ac % 256);
300 bytes[i++] = (byte)((ac >> 8) % 256);
301 bytes[i++] = (byte)(ac % 256);
302 bytes[i++] = (byte)((ac >> 8) % 256);
303 bytes[i++] = (byte)(ac % 256);
304 bytes[i++] = (byte)((ac >> 8) % 256);
305
306 dat.Data = bytes;
307 return (dat);
308 }
309
310 // Sends animation update
311 public void SendAnimPack(LLUUID animID, int seq)
312 {
313 AvatarAnimationPacket ani = new AvatarAnimationPacket();
314 ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1];
315 ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock();
316 ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID;
317 ani.Sender = new AvatarAnimationPacket.SenderBlock();
318 ani.Sender.ID = ControllingClient.AgentID;
319 ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1];
320 ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock();
321 ani.AnimationList[0].AnimID = this.current_anim = animID;
322 ani.AnimationList[0].AnimSequenceID = this.anim_seq = seq;
323
324 List<Avatar> avList = this.m_world.RequestAvatarList();
325 foreach (Avatar client in avList)
326 {
327 client.SendPacketToViewer(ani);
328 }
329
330 }
331
332 public void SendAnimPack()
333 {
334 this.SendAnimPack(this.current_anim, this.anim_seq);
335 }
336
337 }
338}
diff --git a/OpenSim/OpenSim.RegionServer/world/Avatar.cs b/OpenSim/OpenSim.RegionServer/world/Avatar.cs
new file mode 100644
index 0000000..9401036
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Avatar.cs
@@ -0,0 +1,438 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Text;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Physics.Manager;
8using OpenSim.Framework.Inventory;
9using OpenSim.Framework.Interfaces;
10using Axiom.MathLib;
11
12namespace OpenSim.world
13{
14 public partial class Avatar : Entity
15 {
16 public static bool PhysicsEngineFlying = false;
17 public static AvatarAnimations Animations;
18 public string firstname;
19 public string lastname;
20 public ClientView ControllingClient;
21 public LLUUID current_anim;
22 public int anim_seq;
23 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
24 private bool updateflag = false;
25 private byte movementflag = 0;
26 private List<NewForce> forcesList = new List<NewForce>();
27 private short _updateCount = 0;
28 private Axiom.MathLib.Quaternion bodyRot;
29 private LLObject.TextureEntry avatarAppearanceTexture = null;
30 private byte[] visualParams;
31 private AvatarWearable[] Wearables;
32 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
33 private ulong m_regionHandle;
34 //private Dictionary<uint, ClientView> m_clientThreads;
35 private string m_regionName;
36 private ushort m_regionWaterHeight;
37 private bool m_regionTerraform;
38 private bool childAvatar = false;
39
40 public Avatar(ClientView TheClient, World world, string regionName, Dictionary<uint, ClientView> clientThreads, ulong regionHandle, bool regionTerraform, ushort regionWater)
41 {
42 m_world = world;
43 // m_clientThreads = clientThreads;
44 m_regionName = regionName;
45 m_regionHandle = regionHandle;
46 m_regionTerraform = regionTerraform;
47 m_regionWaterHeight = regionWater;
48
49 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Avatar.cs - Loading details from grid (DUMMY)");
50 ControllingClient = TheClient;
51 localid = 8880000 + (this.m_world._localNumber++);
52 Pos = ControllingClient.startpos;
53 visualParams = new byte[218];
54 for (int i = 0; i < 218; i++)
55 {
56 visualParams[i] = 100;
57 }
58 Wearables = new AvatarWearable[13]; //should be 13 of these
59 for (int i = 0; i < 13; i++)
60 {
61 Wearables[i] = new AvatarWearable();
62 }
63 this.Wearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
64 this.Wearables[0].ItemID = LLUUID.Random();
65
66 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
67
68 //register for events
69 ControllingClient.OnRequestWearables += new ClientView.GenericCall(this.SendOurAppearance);
70 ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
71 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.CompleteMovement);
72 ControllingClient.OnCompleteMovementToRegion += new ClientView.GenericCall2(this.SendInitialPosition);
73 ControllingClient.OnAgentUpdate += new ClientView.GenericCall3(this.HandleAgentUpdate);
74 ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
75 ControllingClient.OnChildAgentStatus += new ClientView.StatusChange(this.ChildStatusChange);
76 ControllingClient.OnStopMovement += new ClientView.GenericCall2(this.StopMovement);
77 }
78
79 public PhysicsActor PhysActor
80 {
81 set
82 {
83 this._physActor = value;
84 }
85 get
86 {
87 return _physActor;
88 }
89 }
90
91 public void ChildStatusChange(bool status)
92 {
93 Console.WriteLine("child agent status change");
94 this.childAvatar = status;
95
96 if (this.childAvatar == true)
97 {
98 this.StopMovement();
99 }
100 else
101 {
102 LLVector3 startp = ControllingClient.StartPos;
103 lock (m_world.LockPhysicsEngine)
104 {
105 this._physActor.Position = new PhysicsVector(startp.X, startp.Y, startp.Z);
106 }
107 }
108 }
109
110 public override void addForces()
111 {
112 lock (this.forcesList)
113 {
114 if (this.forcesList.Count > 0)
115 {
116 for (int i = 0; i < this.forcesList.Count; i++)
117 {
118 NewForce force = this.forcesList[i];
119 PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
120 lock (m_world.LockPhysicsEngine)
121 {
122 this._physActor.Velocity = phyVector;
123 }
124 this.updateflag = true;
125 this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
126 // but as we are setting the velocity (rather than using real forces) at the moment it is okay.
127 }
128 for (int i = 0; i < this.forcesList.Count; i++)
129 {
130 this.forcesList.RemoveAt(0);
131 }
132 }
133 }
134 }
135
136 public static void SetupTemplate(string name)
137 {
138 FileInfo fInfo = new FileInfo(name);
139 long numBytes = fInfo.Length;
140 FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
141 BinaryReader br = new BinaryReader(fStream);
142 byte[] data1 = br.ReadBytes((int)numBytes);
143 br.Close();
144 fStream.Close();
145
146 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
147
148 SetDefaultPacketValues(objdata);
149 objdata.TextureEntry = data1;
150 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
151 objdata.PathCurve = 16;
152 objdata.ProfileCurve = 1;
153 objdata.PathScaleX = 100;
154 objdata.PathScaleY = 100;
155 objdata.ParentID = 0;
156 objdata.OwnerID = LLUUID.Zero;
157 objdata.Scale = new LLVector3(1, 1, 1);
158 objdata.PCode = 47;
159 System.Text.Encoding enc = System.Text.Encoding.ASCII;
160 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
161 pos.X = 100f;
162 objdata.ID = 8880000;
163 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
164 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
165 //objdata.FullID=user.AgentID;
166 byte[] pb = pos.GetBytes();
167 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
168
169 Avatar.AvatarTemplate = objdata;
170 }
171
172 protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
173 {
174 objdata.PSBlock = new byte[0];
175 objdata.ExtraParams = new byte[1];
176 objdata.MediaURL = new byte[0];
177 objdata.NameValue = new byte[0];
178 objdata.Text = new byte[0];
179 objdata.TextColor = new byte[4];
180 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
181 objdata.JointPivot = new LLVector3(0, 0, 0);
182 objdata.Material = 4;
183 objdata.TextureAnim = new byte[0];
184 objdata.Sound = LLUUID.Zero;
185 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
186 objdata.TextureEntry = ntex.ToBytes();
187 objdata.State = 0;
188 objdata.Data = new byte[0];
189
190 objdata.ObjectData = new byte[76];
191 objdata.ObjectData[15] = 128;
192 objdata.ObjectData[16] = 63;
193 objdata.ObjectData[56] = 128;
194 objdata.ObjectData[61] = 102;
195 objdata.ObjectData[62] = 40;
196 objdata.ObjectData[63] = 61;
197 objdata.ObjectData[64] = 189;
198
199
200 }
201
202 public void CompleteMovement()
203 {
204 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Avatar.cs:CompleteMovement() - Constructing AgentMovementComplete packet");
205 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
206 mov.AgentData.SessionID = this.ControllingClient.SessionID;
207 mov.AgentData.AgentID = this.ControllingClient.AgentID;
208 mov.Data.RegionHandle = this.m_regionHandle;
209 // TODO - dynamicalise this stuff
210 mov.Data.Timestamp = 1172750370;
211 mov.Data.Position = this.ControllingClient.startpos;
212 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
213
214 ControllingClient.OutPacket(mov);
215 }
216
217 public void HandleAgentUpdate(Packet pack)
218 {
219 this.HandleUpdate((AgentUpdatePacket)pack);
220 }
221
222 public void HandleUpdate(AgentUpdatePacket pack)
223 {
224 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0)
225 {
226 if (this._physActor.Flying == false)
227 {
228 this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_FLY"];
229 this.anim_seq = 1;
230 this.SendAnimPack();
231 }
232 this._physActor.Flying = true;
233
234 }
235 else
236 {
237 if (this._physActor.Flying == true)
238 {
239 this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"];
240 this.anim_seq = 1;
241 this.SendAnimPack();
242 }
243 this._physActor.Flying = false;
244 }
245 if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS) != 0)
246 {
247 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
248 if (((movementflag & 1) == 0) || (q != this.bodyRot))
249 {
250
251 if (((movementflag & 1) == 0) && (!this._physActor.Flying))
252 {
253 this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_WALK"];
254 this.anim_seq = 1;
255 this.SendAnimPack();
256 }
257
258
259 //we should add a new force to the list
260 // but for now we will deal with velocities
261 NewForce newVelocity = new NewForce();
262 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
263 Axiom.MathLib.Vector3 direc = q * v3;
264 direc.Normalize();
265
266 //work out velocity for sim physics system
267 direc = direc * ((0.03f) * 128f);
268 if (this._physActor.Flying)
269 direc *= 4;
270
271 newVelocity.X = direc.x;
272 newVelocity.Y = direc.y;
273 newVelocity.Z = direc.z;
274 this.forcesList.Add(newVelocity);
275 movementflag = 1;
276 this.bodyRot = q;
277 }
278 }
279 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS) != 0) && (PhysicsEngineFlying))
280 {
281 if (((movementflag & 2) == 0) && this._physActor.Flying)
282 {
283 //we should add a new force to the list
284 // but for now we will deal with velocities
285 NewForce newVelocity = new NewForce();
286 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, 1);
287 Axiom.MathLib.Vector3 direc = v3;
288 direc.Normalize();
289
290 //work out velocity for sim physics system
291 direc = direc * ((0.03f) * 128f * 2);
292 newVelocity.X = direc.x;
293 newVelocity.Y = direc.y;
294 newVelocity.Z = direc.z;
295 this.forcesList.Add(newVelocity);
296 movementflag = 2;
297 }
298 }
299 else if ((((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) && (PhysicsEngineFlying))
300 {
301 if (((movementflag & 4) == 0) && this._physActor.Flying)
302 {
303 //we should add a new force to the list
304 // but for now we will deal with velocities
305 NewForce newVelocity = new NewForce();
306 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(0, 0, -1);
307 //Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
308 Axiom.MathLib.Vector3 direc = v3;
309 direc.Normalize();
310
311 //work out velocity for sim physics system
312 direc = direc * ((0.03f) * 128f * 2);
313 newVelocity.X = direc.x;
314 newVelocity.Y = direc.y;
315 newVelocity.Z = direc.z;
316 this.forcesList.Add(newVelocity);
317 movementflag = 4;
318 }
319 }
320 else if (((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG) != 0)
321 {
322 Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
323 if (((movementflag & 8) == 0) || (q != this.bodyRot))
324 {
325 //we should add a new force to the list
326 // but for now we will deal with velocities
327 NewForce newVelocity = new NewForce();
328 Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(-1, 0, 0);
329 Axiom.MathLib.Vector3 direc = q * v3;
330 direc.Normalize();
331
332 //work out velocity for sim physics system
333 direc = direc * ((0.03f) * 128f);
334 if (this._physActor.Flying)
335 direc *= 2;
336
337 newVelocity.X = direc.x;
338 newVelocity.Y = direc.y;
339 newVelocity.Z = direc.z;
340 this.forcesList.Add(newVelocity);
341 movementflag = 8;
342 this.bodyRot = q;
343 }
344 }
345 else
346 {
347 if (movementflag == 16)
348 {
349 movementflag = 0;
350 }
351 if ((movementflag) != 0)
352 {
353 NewForce newVelocity = new NewForce();
354 newVelocity.X = 0;
355 newVelocity.Y = 0;
356 newVelocity.Z = 0;
357 this.forcesList.Add(newVelocity);
358 movementflag = 0;
359 // We're standing still, so make it show!
360 if (this._physActor.Flying == false)
361 {
362 this.current_anim = Animations.AnimsLLUUID["ANIM_AGENT_STAND"];
363 this.anim_seq = 1;
364 this.SendAnimPack();
365 }
366 this.movementflag = 16;
367
368 }
369 }
370 }
371
372 //really really should be moved somewhere else (RegionInfo.cs ?)
373 public void SendRegionHandshake(World regionInfo)
374 {
375 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
376 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
377 RegionHandshakePacket handshake = new RegionHandshakePacket();
378
379 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
380 handshake.RegionInfo.BillableFactor = 0;
381 handshake.RegionInfo.IsEstateManager = false;
382 handshake.RegionInfo.TerrainHeightRange00 = 60;
383 handshake.RegionInfo.TerrainHeightRange01 = 60;
384 handshake.RegionInfo.TerrainHeightRange10 = 60;
385 handshake.RegionInfo.TerrainHeightRange11 = 60;
386 handshake.RegionInfo.TerrainStartHeight00 = 10;
387 handshake.RegionInfo.TerrainStartHeight01 = 10;
388 handshake.RegionInfo.TerrainStartHeight10 = 10;
389 handshake.RegionInfo.TerrainStartHeight11 = 10;
390 handshake.RegionInfo.SimAccess = 13;
391 handshake.RegionInfo.WaterHeight = m_regionWaterHeight;
392 uint regionFlags = 72458694;
393 if (this.m_regionTerraform)
394 {
395 regionFlags -= 64;
396 }
397 handshake.RegionInfo.RegionFlags = regionFlags;
398 handshake.RegionInfo.SimName = _enc.GetBytes(m_regionName + "\0");
399 handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
400 handshake.RegionInfo.TerrainBase0 = new LLUUID("b8d3965a-ad78-bf43-699b-bff8eca6c975");
401 handshake.RegionInfo.TerrainBase1 = new LLUUID("abb783e6-3e93-26c0-248a-247666855da3");
402 handshake.RegionInfo.TerrainBase2 = new LLUUID("179cdabd-398a-9b6b-1391-4dc333ba321f");
403 handshake.RegionInfo.TerrainBase3 = new LLUUID("beb169c7-11ea-fff2-efe5-0f24dc881df2");
404 handshake.RegionInfo.TerrainDetail0 = new LLUUID("00000000-0000-0000-0000-000000000000");
405 handshake.RegionInfo.TerrainDetail1 = new LLUUID("00000000-0000-0000-0000-000000000000");
406 handshake.RegionInfo.TerrainDetail2 = new LLUUID("00000000-0000-0000-0000-000000000000");
407 handshake.RegionInfo.TerrainDetail3 = new LLUUID("00000000-0000-0000-0000-000000000000");
408 handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
409
410 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
411 this.ControllingClient.OutPacket(handshake);
412 }
413
414 public static void LoadAnims()
415 {
416 Avatar.Animations = new AvatarAnimations();
417 Avatar.Animations.LoadAnims();
418 }
419
420 public override void LandRenegerated()
421 {
422 Pos = new LLVector3(100.0f, 100.0f, m_world.Terrain[(int)Pos.X, (int)Pos.Y] + 50.0f);
423 }
424 }
425
426 public class NewForce
427 {
428 public float X;
429 public float Y;
430 public float Z;
431
432 public NewForce()
433 {
434
435 }
436 }
437
438}
diff --git a/OpenSim/OpenSim.RegionServer/world/AvatarAnimations.cs b/OpenSim/OpenSim.RegionServer/world/AvatarAnimations.cs
new file mode 100644
index 0000000..b554af8
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/AvatarAnimations.cs
@@ -0,0 +1,163 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.world
7{
8 public class AvatarAnimations
9 {
10
11 public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>();
12 public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>();
13
14 public AvatarAnimations()
15 {
16 }
17
18 public void LoadAnims()
19 {
20 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Avatar.cs:LoadAnims() - Loading avatar animations");
21 AnimsLLUUID.Add("ANIM_AGENT_AFRAID", new LLUUID("6b61c8e8-4747-0d75-12d7-e49ff207a4ca"));
22 AnimsLLUUID.Add("ANIM_AGENT_AIM_BAZOOKA_R", new LLUUID("b5b4a67d-0aee-30d2-72cd-77b333e932ef"));
23 AnimsLLUUID.Add("ANIM_AGENT_AIM_BOW_L", new LLUUID("46bb4359-de38-4ed8-6a22-f1f52fe8f506"));
24 AnimsLLUUID.Add("ANIM_AGENT_AIM_HANDGUN_R", new LLUUID("3147d815-6338-b932-f011-16b56d9ac18b"));
25 AnimsLLUUID.Add("ANIM_AGENT_AIM_RIFLE_R", new LLUUID("ea633413-8006-180a-c3ba-96dd1d756720"));
26 AnimsLLUUID.Add("ANIM_AGENT_ANGRY", new LLUUID("5747a48e-073e-c331-f6f3-7c2149613d3e"));
27 AnimsLLUUID.Add("ANIM_AGENT_AWAY", new LLUUID("fd037134-85d4-f241-72c6-4f42164fedee"));
28 AnimsLLUUID.Add("ANIM_AGENT_BACKFLIP", new LLUUID("c4ca6188-9127-4f31-0158-23c4e2f93304"));
29 AnimsLLUUID.Add("ANIM_AGENT_BELLY_LAUGH", new LLUUID("18b3a4b5-b463-bd48-e4b6-71eaac76c515"));
30 AnimsLLUUID.Add("ANIM_AGENT_BLOW_KISS", new LLUUID("db84829b-462c-ee83-1e27-9bbee66bd624"));
31 AnimsLLUUID.Add("ANIM_AGENT_BORED", new LLUUID("b906c4ba-703b-1940-32a3-0c7f7d791510"));
32 AnimsLLUUID.Add("ANIM_AGENT_BOW", new LLUUID("82e99230-c906-1403-4d9c-3889dd98daba"));
33 AnimsLLUUID.Add("ANIM_AGENT_BRUSH", new LLUUID("349a3801-54f9-bf2c-3bd0-1ac89772af01"));
34 AnimsLLUUID.Add("ANIM_AGENT_BUSY", new LLUUID("efcf670c-2d18-8128-973a-034ebc806b67"));
35 AnimsLLUUID.Add("ANIM_AGENT_CLAP", new LLUUID("9b0c1c4e-8ac7-7969-1494-28c874c4f668"));
36 AnimsLLUUID.Add("ANIM_AGENT_COURTBOW", new LLUUID("9ba1c942-08be-e43a-fb29-16ad440efc50"));
37 AnimsLLUUID.Add("ANIM_AGENT_CROUCH", new LLUUID("201f3fdf-cb1f-dbec-201f-7333e328ae7c"));
38 AnimsLLUUID.Add("ANIM_AGENT_CROUCHWALK", new LLUUID("47f5f6fb-22e5-ae44-f871-73aaaf4a6022"));
39 AnimsLLUUID.Add("ANIM_AGENT_CRY", new LLUUID("92624d3e-1068-f1aa-a5ec-8244585193ed"));
40 AnimsLLUUID.Add("ANIM_AGENT_CUSTOMIZE", new LLUUID("038fcec9-5ebd-8a8e-0e2e-6e71a0a1ac53"));
41 AnimsLLUUID.Add("ANIM_AGENT_CUSTOMIZE_DONE", new LLUUID("6883a61a-b27b-5914-a61e-dda118a9ee2c"));
42 AnimsLLUUID.Add("ANIM_AGENT_DANCE1", new LLUUID("b68a3d7c-de9e-fc87-eec8-543d787e5b0d"));
43 AnimsLLUUID.Add("ANIM_AGENT_DANCE2", new LLUUID("928cae18-e31d-76fd-9cc9-2f55160ff818"));
44 AnimsLLUUID.Add("ANIM_AGENT_DANCE3", new LLUUID("30047778-10ea-1af7-6881-4db7a3a5a114"));
45 AnimsLLUUID.Add("ANIM_AGENT_DANCE4", new LLUUID("951469f4-c7b2-c818-9dee-ad7eea8c30b7"));
46 AnimsLLUUID.Add("ANIM_AGENT_DANCE5", new LLUUID("4bd69a1d-1114-a0b4-625f-84e0a5237155"));
47 AnimsLLUUID.Add("ANIM_AGENT_DANCE6", new LLUUID("cd28b69b-9c95-bb78-3f94-8d605ff1bb12"));
48 AnimsLLUUID.Add("ANIM_AGENT_DANCE7", new LLUUID("a54d8ee2-28bb-80a9-7f0c-7afbbe24a5d6"));
49 AnimsLLUUID.Add("ANIM_AGENT_DANCE8", new LLUUID("b0dc417c-1f11-af36-2e80-7e7489fa7cdc"));
50 AnimsLLUUID.Add("ANIM_AGENT_DEAD", new LLUUID("57abaae6-1d17-7b1b-5f98-6d11a6411276"));
51 AnimsLLUUID.Add("ANIM_AGENT_DRINK", new LLUUID("0f86e355-dd31-a61c-fdb0-3a96b9aad05f"));
52 AnimsLLUUID.Add("ANIM_AGENT_EMBARRASSED", new LLUUID("514af488-9051-044a-b3fc-d4dbf76377c6"));
53 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_AFRAID", new LLUUID("aa2df84d-cf8f-7218-527b-424a52de766e"));
54 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_ANGER", new LLUUID("1a03b575-9634-b62a-5767-3a679e81f4de"));
55 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_BORED", new LLUUID("214aa6c1-ba6a-4578-f27c-ce7688f61d0d"));
56 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_CRY", new LLUUID("d535471b-85bf-3b4d-a542-93bea4f59d33"));
57 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_DISDAIN", new LLUUID("d4416ff1-09d3-300f-4183-1b68a19b9fc1"));
58 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_EMBARRASSED", new LLUUID("0b8c8211-d78c-33e8-fa28-c51a9594e424"));
59 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_FROWN", new LLUUID("fee3df48-fa3d-1015-1e26-a205810e3001"));
60 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_KISS", new LLUUID("1e8d90cc-a84e-e135-884c-7c82c8b03a14"));
61 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_LAUGH", new LLUUID("62570842-0950-96f8-341c-809e65110823"));
62 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_OPEN_MOUTH", new LLUUID("d63bc1f9-fc81-9625-a0c6-007176d82eb7"));
63 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_REPULSED", new LLUUID("f76cda94-41d4-a229-2872-e0296e58afe1"));
64 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_SAD", new LLUUID("eb6ebfb2-a4b3-a19c-d388-4dd5c03823f7"));
65 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_SHRUG", new LLUUID("a351b1bc-cc94-aac2-7bea-a7e6ebad15ef"));
66 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_SMILE", new LLUUID("b7c7c833-e3d3-c4e3-9fc0-131237446312"));
67 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_SURPRISE", new LLUUID("728646d9-cc79-08b2-32d6-937f0a835c24"));
68 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_TONGUE_OUT", new LLUUID("835965c6-7f2f-bda2-5deb-2478737f91bf"));
69 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_TOOTHSMILE", new LLUUID("b92ec1a5-e7ce-a76b-2b05-bcdb9311417e"));
70 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_WINK", new LLUUID("da020525-4d94-59d6-23d7-81fdebf33148"));
71 AnimsLLUUID.Add("ANIM_AGENT_EXPRESS_WORRY", new LLUUID("9c05e5c7-6f07-6ca4-ed5a-b230390c3950"));
72 AnimsLLUUID.Add("ANIM_AGENT_FALLDOWN", new LLUUID("666307d9-a860-572d-6fd4-c3ab8865c094"));
73 AnimsLLUUID.Add("ANIM_AGENT_FEMALE_WALK", new LLUUID("f5fc7433-043d-e819-8298-f519a119b688"));
74 AnimsLLUUID.Add("ANIM_AGENT_FINGER_WAG", new LLUUID("c1bc7f36-3ba0-d844-f93c-93be945d644f"));
75 AnimsLLUUID.Add("ANIM_AGENT_FIST_PUMP", new LLUUID("7db00ccd-f380-f3ee-439d-61968ec69c8a"));
76 AnimsLLUUID.Add("ANIM_AGENT_FLY", new LLUUID("aec4610c-757f-bc4e-c092-c6e9caf18daf"));
77 AnimsLLUUID.Add("ANIM_AGENT_FLYSLOW", new LLUUID("2b5a38b2-5e00-3a97-a495-4c826bc443e6"));
78 AnimsLLUUID.Add("ANIM_AGENT_HELLO", new LLUUID("9b29cd61-c45b-5689-ded2-91756b8d76a9"));
79 AnimsLLUUID.Add("ANIM_AGENT_HOLD_BAZOOKA_R", new LLUUID("ef62d355-c815-4816-2474-b1acc21094a6"));
80 AnimsLLUUID.Add("ANIM_AGENT_HOLD_BOW_L", new LLUUID("8b102617-bcba-037b-86c1-b76219f90c88"));
81 AnimsLLUUID.Add("ANIM_AGENT_HOLD_HANDGUN_R", new LLUUID("efdc1727-8b8a-c800-4077-975fc27ee2f2"));
82 AnimsLLUUID.Add("ANIM_AGENT_HOLD_RIFLE_R", new LLUUID("3d94bad0-c55b-7dcc-8763-033c59405d33"));
83 AnimsLLUUID.Add("ANIM_AGENT_HOLD_THROW_R", new LLUUID("7570c7b5-1f22-56dd-56ef-a9168241bbb6"));
84 AnimsLLUUID.Add("ANIM_AGENT_HOVER", new LLUUID("4ae8016b-31b9-03bb-c401-b1ea941db41d"));
85 AnimsLLUUID.Add("ANIM_AGENT_HOVER_DOWN", new LLUUID("20f063ea-8306-2562-0b07-5c853b37b31e"));
86 AnimsLLUUID.Add("ANIM_AGENT_HOVER_UP", new LLUUID("62c5de58-cb33-5743-3d07-9e4cd4352864"));
87 AnimsLLUUID.Add("ANIM_AGENT_IMPATIENT", new LLUUID("5ea3991f-c293-392e-6860-91dfa01278a3"));
88 AnimsLLUUID.Add("ANIM_AGENT_JUMP", new LLUUID("2305bd75-1ca9-b03b-1faa-b176b8a8c49e"));
89 AnimsLLUUID.Add("ANIM_AGENT_JUMP_FOR_JOY", new LLUUID("709ea28e-1573-c023-8bf8-520c8bc637fa"));
90 AnimsLLUUID.Add("ANIM_AGENT_KISS_MY_BUTT", new LLUUID("19999406-3a3a-d58c-a2ac-d72e555dcf51"));
91 AnimsLLUUID.Add("ANIM_AGENT_LAND", new LLUUID("7a17b059-12b2-41b1-570a-186368b6aa6f"));
92 AnimsLLUUID.Add("ANIM_AGENT_LAUGH_SHORT", new LLUUID("ca5b3f14-3194-7a2b-c894-aa699b718d1f"));
93 AnimsLLUUID.Add("ANIM_AGENT_MEDIUM_LAND", new LLUUID("f4f00d6e-b9fe-9292-f4cb-0ae06ea58d57"));
94 AnimsLLUUID.Add("ANIM_AGENT_MOTORCYCLE_SIT", new LLUUID("08464f78-3a8e-2944-cba5-0c94aff3af29"));
95 AnimsLLUUID.Add("ANIM_AGENT_MUSCLE_BEACH", new LLUUID("315c3a41-a5f3-0ba4-27da-f893f769e69b"));
96 AnimsLLUUID.Add("ANIM_AGENT_NO", new LLUUID("5a977ed9-7f72-44e9-4c4c-6e913df8ae74"));
97 AnimsLLUUID.Add("ANIM_AGENT_NO_UNHAPPY", new LLUUID("d83fa0e5-97ed-7eb2-e798-7bd006215cb4"));
98 AnimsLLUUID.Add("ANIM_AGENT_NYAH_NYAH", new LLUUID("f061723d-0a18-754f-66ee-29a44795a32f"));
99 AnimsLLUUID.Add("ANIM_AGENT_ONETWO_PUNCH", new LLUUID("eefc79be-daae-a239-8c04-890f5d23654a"));
100 AnimsLLUUID.Add("ANIM_AGENT_PEACE", new LLUUID("b312b10e-65ab-a0a4-8b3c-1326ea8e3ed9"));
101 AnimsLLUUID.Add("ANIM_AGENT_POINT_ME", new LLUUID("17c024cc-eef2-f6a0-3527-9869876d7752"));
102 AnimsLLUUID.Add("ANIM_AGENT_POINT_YOU", new LLUUID("ec952cca-61ef-aa3b-2789-4d1344f016de"));
103 AnimsLLUUID.Add("ANIM_AGENT_PRE_JUMP", new LLUUID("7a4e87fe-de39-6fcb-6223-024b00893244"));
104 AnimsLLUUID.Add("ANIM_AGENT_PUNCH_LEFT", new LLUUID("f3300ad9-3462-1d07-2044-0fef80062da0"));
105 AnimsLLUUID.Add("ANIM_AGENT_PUNCH_RIGHT", new LLUUID("c8e42d32-7310-6906-c903-cab5d4a34656"));
106 AnimsLLUUID.Add("ANIM_AGENT_REPULSED", new LLUUID("36f81a92-f076-5893-dc4b-7c3795e487cf"));
107 AnimsLLUUID.Add("ANIM_AGENT_ROUNDHOUSE_KICK", new LLUUID("49aea43b-5ac3-8a44-b595-96100af0beda"));
108 AnimsLLUUID.Add("ANIM_AGENT_RPS_COUNTDOWN", new LLUUID("35db4f7e-28c2-6679-cea9-3ee108f7fc7f"));
109 AnimsLLUUID.Add("ANIM_AGENT_RPS_PAPER", new LLUUID("0836b67f-7f7b-f37b-c00a-460dc1521f5a"));
110 AnimsLLUUID.Add("ANIM_AGENT_RPS_ROCK", new LLUUID("42dd95d5-0bc6-6392-f650-777304946c0f"));
111 AnimsLLUUID.Add("ANIM_AGENT_RPS_SCISSORS", new LLUUID("16803a9f-5140-e042-4d7b-d28ba247c325"));
112 AnimsLLUUID.Add("ANIM_AGENT_RUN", new LLUUID("05ddbff8-aaa9-92a1-2b74-8fe77a29b445"));
113 AnimsLLUUID.Add("ANIM_AGENT_SAD", new LLUUID("0eb702e2-cc5a-9a88-56a5-661a55c0676a"));
114 AnimsLLUUID.Add("ANIM_AGENT_SALUTE", new LLUUID("cd7668a6-7011-d7e2-ead8-fc69eff1a104"));
115 AnimsLLUUID.Add("ANIM_AGENT_SHOOT_BOW_L", new LLUUID("e04d450d-fdb5-0432-fd68-818aaf5935f8"));
116 AnimsLLUUID.Add("ANIM_AGENT_SHOUT", new LLUUID("6bd01860-4ebd-127a-bb3d-d1427e8e0c42"));
117 AnimsLLUUID.Add("ANIM_AGENT_SHRUG", new LLUUID("70ea714f-3a97-d742-1b01-590a8fcd1db5"));
118 AnimsLLUUID.Add("ANIM_AGENT_SIT", new LLUUID("1a5fe8ac-a804-8a5d-7cbd-56bd83184568"));
119 AnimsLLUUID.Add("ANIM_AGENT_SIT_FEMALE", new LLUUID("b1709c8d-ecd3-54a1-4f28-d55ac0840782"));
120 AnimsLLUUID.Add("ANIM_AGENT_SIT_GENERIC", new LLUUID("245f3c54-f1c0-bf2e-811f-46d8eeb386e7"));
121 AnimsLLUUID.Add("ANIM_AGENT_SIT_GROUND", new LLUUID("1c7600d6-661f-b87b-efe2-d7421eb93c86"));
122 AnimsLLUUID.Add("ANIM_AGENT_SIT_GROUND_CONSTRAINED", new LLUUID("1a2bd58e-87ff-0df8-0b4c-53e047b0bb6e"));
123 AnimsLLUUID.Add("ANIM_AGENT_SIT_TO_STAND", new LLUUID("a8dee56f-2eae-9e7a-05a2-6fb92b97e21e"));
124 AnimsLLUUID.Add("ANIM_AGENT_SLEEP", new LLUUID("f2bed5f9-9d44-39af-b0cd-257b2a17fe40"));
125 AnimsLLUUID.Add("ANIM_AGENT_SMOKE_IDLE", new LLUUID("d2f2ee58-8ad1-06c9-d8d3-3827ba31567a"));
126 AnimsLLUUID.Add("ANIM_AGENT_SMOKE_INHALE", new LLUUID("6802d553-49da-0778-9f85-1599a2266526"));
127 AnimsLLUUID.Add("ANIM_AGENT_SMOKE_THROW_DOWN", new LLUUID("0a9fb970-8b44-9114-d3a9-bf69cfe804d6"));
128 AnimsLLUUID.Add("ANIM_AGENT_SNAPSHOT", new LLUUID("eae8905b-271a-99e2-4c0e-31106afd100c"));
129 AnimsLLUUID.Add("ANIM_AGENT_STAND", new LLUUID("2408fe9e-df1d-1d7d-f4ff-1384fa7b350f"));
130 AnimsLLUUID.Add("ANIM_AGENT_STANDUP", new LLUUID("3da1d753-028a-5446-24f3-9c9b856d9422"));
131 AnimsLLUUID.Add("ANIM_AGENT_STAND_1", new LLUUID("15468e00-3400-bb66-cecc-646d7c14458e"));
132 AnimsLLUUID.Add("ANIM_AGENT_STAND_2", new LLUUID("370f3a20-6ca6-9971-848c-9a01bc42ae3c"));
133 AnimsLLUUID.Add("ANIM_AGENT_STAND_3", new LLUUID("42b46214-4b44-79ae-deb8-0df61424ff4b"));
134 AnimsLLUUID.Add("ANIM_AGENT_STAND_4", new LLUUID("f22fed8b-a5ed-2c93-64d5-bdd8b93c889f"));
135 AnimsLLUUID.Add("ANIM_AGENT_STRETCH", new LLUUID("80700431-74ec-a008-14f8-77575e73693f"));
136 AnimsLLUUID.Add("ANIM_AGENT_STRIDE", new LLUUID("1cb562b0-ba21-2202-efb3-30f82cdf9595"));
137 AnimsLLUUID.Add("ANIM_AGENT_SURF", new LLUUID("41426836-7437-7e89-025d-0aa4d10f1d69"));
138 AnimsLLUUID.Add("ANIM_AGENT_SURPRISE", new LLUUID("313b9881-4302-73c0-c7d0-0e7a36b6c224"));
139 AnimsLLUUID.Add("ANIM_AGENT_SWORD_STRIKE", new LLUUID("85428680-6bf9-3e64-b489-6f81087c24bd"));
140 AnimsLLUUID.Add("ANIM_AGENT_TALK", new LLUUID("5c682a95-6da4-a463-0bf6-0f5b7be129d1"));
141 AnimsLLUUID.Add("ANIM_AGENT_TANTRUM", new LLUUID("11000694-3f41-adc2-606b-eee1d66f3724"));
142 AnimsLLUUID.Add("ANIM_AGENT_THROW_R", new LLUUID("aa134404-7dac-7aca-2cba-435f9db875ca"));
143 AnimsLLUUID.Add("ANIM_AGENT_TRYON_SHIRT", new LLUUID("83ff59fe-2346-f236-9009-4e3608af64c1"));
144 AnimsLLUUID.Add("ANIM_AGENT_TURNLEFT", new LLUUID("56e0ba0d-4a9f-7f27-6117-32f2ebbf6135"));
145 AnimsLLUUID.Add("ANIM_AGENT_TURNRIGHT", new LLUUID("2d6daa51-3192-6794-8e2e-a15f8338ec30"));
146 AnimsLLUUID.Add("ANIM_AGENT_TYPE", new LLUUID("c541c47f-e0c0-058b-ad1a-d6ae3a4584d9"));
147 AnimsLLUUID.Add("ANIM_AGENT_WALK", new LLUUID("6ed24bd8-91aa-4b12-ccc7-c97c857ab4e0"));
148 AnimsLLUUID.Add("ANIM_AGENT_WHISPER", new LLUUID("7693f268-06c7-ea71-fa21-2b30d6533f8f"));
149 AnimsLLUUID.Add("ANIM_AGENT_WHISTLE", new LLUUID("b1ed7982-c68e-a982-7561-52a88a5298c0"));
150 AnimsLLUUID.Add("ANIM_AGENT_WINK", new LLUUID("869ecdad-a44b-671e-3266-56aef2e3ac2e"));
151 AnimsLLUUID.Add("ANIM_AGENT_WINK_HOLLYWOOD", new LLUUID("c0c4030f-c02b-49de-24ba-2331f43fe41c"));
152 AnimsLLUUID.Add("ANIM_AGENT_WORRY", new LLUUID("9f496bd2-589a-709f-16cc-69bf7df1d36c"));
153 AnimsLLUUID.Add("ANIM_AGENT_YES", new LLUUID("15dd911d-be82-2856-26db-27659b142875"));
154 AnimsLLUUID.Add("ANIM_AGENT_YES_HAPPY", new LLUUID("b8c8b2a3-9008-1771-3bfc-90924955ab2d"));
155 AnimsLLUUID.Add("ANIM_AGENT_YOGA_FLOAT", new LLUUID("42ecd00b-9947-a97c-400a-bbc9174c7aeb"));
156
157 foreach (KeyValuePair<string, LLUUID> kp in OpenSim.world.Avatar.Animations.AnimsLLUUID)
158 {
159 AnimsNames.Add(kp.Value, kp.Key);
160 }
161 }
162 }
163}
diff --git a/OpenSim/OpenSim.RegionServer/world/Entity.cs b/OpenSim/OpenSim.RegionServer/world/Entity.cs
new file mode 100644
index 0000000..96e039a
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Entity.cs
@@ -0,0 +1,124 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Axiom.MathLib;
5using OpenSim.Physics.Manager;
6using OpenSim.types;
7using libsecondlife;
8using OpenSim.RegionServer.world.scripting;
9
10namespace OpenSim.world
11{
12 public abstract class Entity : IScriptReadonlyEntity
13 {
14 public libsecondlife.LLUUID uuid;
15 public uint localid;
16 public LLVector3 velocity;
17 public Quaternion rotation;
18 protected List<Entity> children;
19
20 protected string m_name;
21 public virtual string Name
22 {
23 get { return m_name; }
24 }
25
26 protected LLVector3 m_pos;
27 protected PhysicsActor _physActor;
28 protected World m_world;
29
30 public virtual LLVector3 Pos
31 {
32 get
33 {
34 if (this._physActor != null)
35 {
36 m_pos.X = _physActor.Position.X;
37 m_pos.Y = _physActor.Position.Y;
38 m_pos.Z = _physActor.Position.Z;
39 }
40
41 return m_pos;
42 }
43 set
44 {
45 if (this._physActor != null)
46 {
47 try
48 {
49 lock (this.m_world.LockPhysicsEngine)
50 {
51
52 this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
53 }
54 }
55 catch (Exception e)
56 {
57 Console.WriteLine(e.Message);
58 }
59 }
60
61 m_pos = value;
62 }
63 }
64
65 /// <summary>
66 /// Creates a new Entity (should not occur on it's own)
67 /// </summary>
68 public Entity()
69 {
70 uuid = new libsecondlife.LLUUID();
71 localid = 0;
72 m_pos = new LLVector3();
73 velocity = new LLVector3();
74 rotation = new Quaternion();
75 m_name = "(basic entity)";
76 children = new List<Entity>();
77 }
78
79 public virtual void addForces()
80 {
81 foreach (Entity child in children)
82 {
83 child.addForces();
84 }
85 }
86
87 /// <summary>
88 /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
89 /// </summary>
90 public virtual void update() {
91 // Do any per-frame updates needed that are applicable to every type of entity
92 foreach (Entity child in children)
93 {
94 child.update();
95 }
96 }
97
98 /// <summary>
99 /// Returns a mesh for this object and any dependents
100 /// </summary>
101 /// <returns>The mesh of this entity tree</returns>
102 public virtual Mesh getMesh()
103 {
104 Mesh mesh = new Mesh();
105
106 foreach (Entity child in children)
107 {
108 mesh += child.getMesh();
109 }
110
111 return mesh;
112 }
113
114 public virtual void BackUp()
115 {
116
117 }
118
119 public virtual void LandRenegerated()
120 {
121
122 }
123 }
124}
diff --git a/OpenSim/OpenSim.RegionServer/world/Primitive.cs b/OpenSim/OpenSim.RegionServer/world/Primitive.cs
new file mode 100644
index 0000000..e048a9e
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Primitive.cs
@@ -0,0 +1,570 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.types;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Types;
10
11namespace OpenSim.world
12{
13 public class Primitive : Entity
14 {
15 protected float mesh_cutbegin;
16 protected float mesh_cutend;
17 protected PrimData primData;
18 protected bool newPrimFlag = false;
19 protected bool updateFlag = false;
20 protected bool dirtyFlag = false;
21 private ObjectUpdatePacket OurPacket;
22 private bool physicsEnabled = false;
23 private bool physicstest = false;
24 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
25 private Dictionary<uint, ClientView> m_clientThreads;
26 private ulong m_regionHandle;
27 private const uint FULL_MASK_PERMISSIONS = 2147483647;
28
29 public bool PhysicsEnabled
30 {
31 get
32 {
33 return physicsEnabled;
34 }
35 set
36 {
37 physicsEnabled = value;
38 }
39 }
40 public bool UpdateFlag
41 {
42 get
43 {
44 return updateFlag;
45 }
46 set
47 {
48 updateFlag = value;
49 }
50 }
51 public LLVector3 Scale
52 {
53 set
54 {
55 LLVector3 offset = (value - primData.Scale);
56 offset.X /= 2;
57 offset.Y /= 2;
58 offset.Z /= 2;
59
60 this.primData.Position += offset;
61 this.primData.Scale = value;
62
63 this.dirtyFlag = true;
64 }
65 get
66 {
67 return this.primData.Scale;
68 }
69 }
70 public PhysicsActor PhysActor
71 {
72 set
73 {
74 this._physActor = value;
75 }
76 }
77
78 public Primitive(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world)
79 {
80 mesh_cutbegin = 0.0f;
81 mesh_cutend = 1.0f;
82
83 m_clientThreads = clientThreads;
84 m_regionHandle = regionHandle;
85 m_world = world;
86 }
87
88 public override Mesh getMesh()
89 {
90 Mesh mesh = new Mesh();
91 Triangle tri = new Triangle(
92 new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f),
93 new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f),
94 new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f));
95
96 mesh.AddTri(tri);
97 mesh += base.getMesh();
98
99 return mesh;
100 }
101
102 public byte[] GetByteArray()
103 {
104 return this.primData.ToBytes();
105 }
106
107 public void GetProperites(ClientView client)
108 {
109 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
110 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
111 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
112 proper.ObjectData[0].ItemID = LLUUID.Zero; // this.uuid;
113 proper.ObjectData[0].CreationDate = (ulong) this.primData.CreationDate;
114 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
115 proper.ObjectData[0].FolderID = LLUUID.Zero;
116 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
117 proper.ObjectData[0].GroupID = LLUUID.Zero;
118 proper.ObjectData[0].InventorySerial = 0;
119 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
120 proper.ObjectData[0].ObjectID = this.uuid;
121 proper.ObjectData[0].OwnerID = primData.OwnerID;
122 proper.ObjectData[0].TouchName = new byte[0];
123 proper.ObjectData[0].TextureID = new byte[0];
124 proper.ObjectData[0].SitName = new byte[0];
125 proper.ObjectData[0].Name = new byte[0];
126 proper.ObjectData[0].Description = new byte[0];
127 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
128 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
129 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
130 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
131 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
132
133 client.OutPacket(proper);
134 }
135
136 public void UpdatePosition(LLVector3 pos)
137 {
138 this.Pos = pos;
139 if (this._physActor != null) // && this.physicsEnabled)
140 {
141 try
142 {
143 lock (m_world.LockPhysicsEngine)
144 {
145 this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z);
146 }
147 }
148 catch (Exception e)
149 {
150 Console.WriteLine(e.Message);
151 }
152 }
153 this.updateFlag = true;
154 }
155
156 public override void update()
157 {
158 LLVector3 pos2 = new LLVector3(0, 0, 0);
159 if (this._physActor != null && this.physicsEnabled)
160 {
161
162 PhysicsVector pPos = this._physActor.Position;
163 pos2 = new LLVector3(pPos.X, pPos.Y, pPos.Z);
164 }
165 if (this.newPrimFlag)
166 {
167 foreach (ClientView client in m_clientThreads.Values)
168 {
169 client.OutPacket(OurPacket);
170 }
171 this.newPrimFlag = false;
172 }
173 else if (this.updateFlag)
174 {
175 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
176 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
177 terse.RegionData.TimeDilation = 64096;
178 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
179 terse.ObjectData[0] = this.CreateImprovedBlock();
180 foreach (ClientView client in m_clientThreads.Values)
181 {
182 client.OutPacket(terse);
183 }
184 this.updateFlag = false;
185 }
186 else if (this.dirtyFlag)
187 {
188 foreach (ClientView client in m_clientThreads.Values)
189 {
190 UpdateClient(client);
191 }
192 this.dirtyFlag = false;
193 }
194 else
195 {
196 if (this._physActor != null && this.physicsEnabled)
197 {
198 if (pos2 != this.positionLastFrame)
199 {
200 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
201 terse.RegionData.RegionHandle = m_regionHandle; // FIXME
202 terse.RegionData.TimeDilation = 64096;
203 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
204 terse.ObjectData[0] = this.CreateImprovedBlock();
205 foreach (ClientView client in m_clientThreads.Values)
206 {
207 client.OutPacket(terse);
208 }
209 }
210 this.positionLastFrame = pos2;
211 }
212 }
213
214 if (this.physicstest)
215 {
216 LLVector3 pos = this.Pos;
217 pos.Z += 0.0001f;
218 this.UpdatePosition(pos);
219 this.physicstest = false;
220 }
221 }
222
223 public void UpdateClient(ClientView RemoteClient)
224 {
225
226 LLVector3 lPos;
227 if (this._physActor != null && this.physicsEnabled)
228 {
229 PhysicsVector pPos = this._physActor.Position;
230 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
231 }
232 else
233 {
234 lPos = this.Pos;
235 }
236 byte[] pb = lPos.GetBytes();
237 Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
238
239 // OurPacket should be update with the follwing in updateShape() rather than having to do it here
240 OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
241 OurPacket.ObjectData[0].PCode = this.primData.PCode;
242 OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
243 OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
244 OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
245 OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
246 OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
247 OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
248 OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
249 OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
250 OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
251 OurPacket.ObjectData[0].Scale = this.primData.Scale;
252 OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
253 OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
254 OurPacket.ObjectData[0].ParentID = this.primData.ParentID ;
255 OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
256 //finish off copying rest of shape data
257 OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
258 OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
259 OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
260 OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
261 OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
262 OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
263
264 RemoteClient.OutPacket(OurPacket);
265 }
266
267 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
268 {
269 this.primData.PathBegin = addPacket.PathBegin;
270 this.primData.PathEnd = addPacket.PathEnd;
271 this.primData.PathScaleX = addPacket.PathScaleX;
272 this.primData.PathScaleY = addPacket.PathScaleY;
273 this.primData.PathShearX = addPacket.PathShearX;
274 this.primData.PathShearY = addPacket.PathShearY;
275 this.primData.PathSkew = addPacket.PathSkew;
276 this.primData.ProfileBegin = addPacket.ProfileBegin;
277 this.primData.ProfileEnd = addPacket.ProfileEnd;
278 this.primData.PathCurve = addPacket.PathCurve;
279 this.primData.ProfileCurve = addPacket.ProfileCurve;
280 this.primData.ProfileHollow = addPacket.ProfileHollow;
281 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
282 this.primData.PathRevolutions = addPacket.PathRevolutions;
283 this.primData.PathTaperX = addPacket.PathTaperX;
284 this.primData.PathTaperY = addPacket.PathTaperY;
285 this.primData.PathTwist = addPacket.PathTwist;
286 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
287 this.dirtyFlag = true;
288 }
289
290 public void UpdateTexture(byte[] tex)
291 {
292 this.OurPacket.ObjectData[0].TextureEntry = tex;
293 this.primData.Texture = tex;
294 this.dirtyFlag = true;
295 }
296
297 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
298 {
299 if (this._physActor != null)
300 {
301 if (this._physActor.Kinematic == pack.AgentData.UsePhysics)
302 {
303 this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false
304 }
305 this.physicsEnabled = pack.AgentData.UsePhysics;
306 if (this._physActor.Kinematic == false)
307 {
308 LLVector3 pos = this.Pos;
309 this.UpdatePosition(pos);
310 pos.Z += 0.000001f;
311 this.UpdatePosition(pos);
312 this.physicstest = true;
313 }
314 else
315 {
316 PhysicsVector vec = this._physActor.Position;
317 LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
318 this.Pos = pos;
319 this.updateFlag = true;
320 }
321 }
322 }
323
324 public void MakeParent(Primitive prim)
325 {
326 this.primData.ParentID = prim.localid;
327 this.Pos -= prim.Pos;
328 this.dirtyFlag = true;
329 }
330
331 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
332 {
333 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
334 objupdate.RegionData.RegionHandle = m_regionHandle;
335 objupdate.RegionData.TimeDilation = 64096;
336
337 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
338 PrimData PData = new PrimData();
339 this.primData = PData;
340 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
341
342 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
343 objupdate.ObjectData[0].PSBlock = new byte[0];
344 objupdate.ObjectData[0].ExtraParams = new byte[1];
345 objupdate.ObjectData[0].MediaURL = new byte[0];
346 objupdate.ObjectData[0].NameValue = new byte[0];
347 objupdate.ObjectData[0].Text = new byte[0];
348 objupdate.ObjectData[0].TextColor = new byte[4];
349 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
350 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
351 objupdate.ObjectData[0].Material = 3;
352 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
353 objupdate.ObjectData[0].TextureAnim = new byte[0];
354 objupdate.ObjectData[0].Sound = LLUUID.Zero;
355 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
356 this.primData.Texture = objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
357 objupdate.ObjectData[0].State = 0;
358 objupdate.ObjectData[0].Data = new byte[0];
359 PData.OwnerID = objupdate.ObjectData[0].OwnerID = ownerID;
360 PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode;
361 PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin;
362 PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd;
363 PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX;
364 PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY;
365 PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX;
366 PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY;
367 PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew;
368 PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin;
369 PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd;
370 PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale;
371 PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve;
372 PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve;
373 PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
374 PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
375 PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
376 PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
377 PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
378 PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
379 PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
380 PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
381 objupdate.ObjectData[0].ID = (uint)(localID);
382 objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000"));
383 objupdate.ObjectData[0].ObjectData = new byte[60];
384 objupdate.ObjectData[0].ObjectData[46] = 128;
385 objupdate.ObjectData[0].ObjectData[47] = 63;
386 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
387 //update position
388 byte[] pb = pos1.GetBytes();
389 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
390 this.newPrimFlag = true;
391 this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID;
392 this.localid = objupdate.ObjectData[0].ID;
393 this.primData.Position = this.Pos = pos1;
394 this.OurPacket = objupdate;
395 }
396
397 public void CreateFromStorage(PrimData store)
398 {
399 this.CreateFromStorage(store, store.Position, store.LocalID, false);
400 }
401
402 public void CreateFromStorage(PrimData store, LLVector3 posi, uint localID, bool newprim)
403 {
404 //need to clean this up as it shares a lot of code with CreateFromPacket()
405 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
406 objupdate.RegionData.RegionHandle = m_regionHandle;
407 objupdate.RegionData.TimeDilation = 64096;
408 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
409
410 this.primData = store;
411 objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
412 objupdate.ObjectData[0].PSBlock = new byte[0];
413 objupdate.ObjectData[0].ExtraParams = new byte[1];
414 objupdate.ObjectData[0].MediaURL = new byte[0];
415 objupdate.ObjectData[0].NameValue = new byte[0];
416 objupdate.ObjectData[0].Text = new byte[0];
417 objupdate.ObjectData[0].TextColor = new byte[4];
418 objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
419 objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
420 objupdate.ObjectData[0].Material = 3;
421 objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
422 objupdate.ObjectData[0].TextureAnim = new byte[0];
423 objupdate.ObjectData[0].Sound = LLUUID.Zero;
424
425 if (store.Texture == null)
426 {
427 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
428 objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
429 }
430 else
431 {
432 objupdate.ObjectData[0].TextureEntry = store.Texture;
433 }
434
435 objupdate.ObjectData[0].State = 0;
436 objupdate.ObjectData[0].Data = new byte[0];
437 objupdate.ObjectData[0].OwnerID = this.primData.OwnerID;
438 objupdate.ObjectData[0].PCode = this.primData.PCode;
439 objupdate.ObjectData[0].PathBegin = this.primData.PathBegin;
440 objupdate.ObjectData[0].PathEnd = this.primData.PathEnd;
441 objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX;
442 objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY;
443 objupdate.ObjectData[0].PathShearX = this.primData.PathShearX;
444 objupdate.ObjectData[0].PathShearY = this.primData.PathShearY;
445 objupdate.ObjectData[0].PathSkew = this.primData.PathSkew;
446 objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
447 objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
448 objupdate.ObjectData[0].Scale = this.primData.Scale;
449 objupdate.ObjectData[0].PathCurve = this.primData.PathCurve;
450 objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
451 objupdate.ObjectData[0].ParentID = 0;
452 objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
453 //finish off copying rest of shape data
454 objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
455 objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
456 objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
457 objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
458 objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
459 objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
460
461 objupdate.ObjectData[0].ID = localID; // (uint)store.LocalID;
462 objupdate.ObjectData[0].FullID = store.FullID;
463
464 objupdate.ObjectData[0].ObjectData = new byte[60];
465 objupdate.ObjectData[0].ObjectData[46] = 128;
466 objupdate.ObjectData[0].ObjectData[47] = 63;
467 LLVector3 pos1 = posi; // store.Position;
468 //update position
469 byte[] pb = pos1.GetBytes();
470 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
471
472 this.uuid = objupdate.ObjectData[0].FullID;
473 this.localid = objupdate.ObjectData[0].ID;
474 this.Pos = pos1;
475 this.OurPacket = objupdate;
476 if (newprim)
477 {
478 this.newPrimFlag = true;
479 }
480 }
481
482 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
483 {
484 uint ID = this.localid;
485 byte[] bytes = new byte[60];
486
487 int i = 0;
488 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
489 //dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
490 dat.TextureEntry = new byte[0];
491 //Console.WriteLine("texture-entry length in improvedterse block is " + this.OurPacket.ObjectData[0].TextureEntry.Length);
492 bytes[i++] = (byte)(ID % 256);
493 bytes[i++] = (byte)((ID >> 8) % 256);
494 bytes[i++] = (byte)((ID >> 16) % 256);
495 bytes[i++] = (byte)((ID >> 24) % 256);
496 bytes[i++] = 0;
497 bytes[i++] = 0;
498
499 LLVector3 lPos;
500 Axiom.MathLib.Quaternion lRot;
501 if (this._physActor != null && this.physicsEnabled)
502 {
503 PhysicsVector pPos = this._physActor.Position;
504 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
505 lRot = this._physActor.Orientation;
506 }
507 else
508 {
509 lPos = this.Pos;
510 lRot = this.rotation;
511 }
512 byte[] pb = lPos.GetBytes();
513 Array.Copy(pb, 0, bytes, i, pb.Length);
514 i += 12;
515 ushort ac = 32767;
516
517 //vel
518 bytes[i++] = (byte)(ac % 256);
519 bytes[i++] = (byte)((ac >> 8) % 256);
520 bytes[i++] = (byte)(ac % 256);
521 bytes[i++] = (byte)((ac >> 8) % 256);
522 bytes[i++] = (byte)(ac % 256);
523 bytes[i++] = (byte)((ac >> 8) % 256);
524
525 //accel
526 bytes[i++] = (byte)(ac % 256);
527 bytes[i++] = (byte)((ac >> 8) % 256);
528 bytes[i++] = (byte)(ac % 256);
529 bytes[i++] = (byte)((ac >> 8) % 256);
530 bytes[i++] = (byte)(ac % 256);
531 bytes[i++] = (byte)((ac >> 8) % 256);
532
533 ushort rw, rx, ry, rz;
534 rw = (ushort)(32768 * (lRot.w + 1));
535 rx = (ushort)(32768 * (lRot.x + 1));
536 ry = (ushort)(32768 * (lRot.y + 1));
537 rz = (ushort)(32768 * (lRot.z + 1));
538
539 //rot
540 bytes[i++] = (byte)(rx % 256);
541 bytes[i++] = (byte)((rx >> 8) % 256);
542 bytes[i++] = (byte)(ry % 256);
543 bytes[i++] = (byte)((ry >> 8) % 256);
544 bytes[i++] = (byte)(rz % 256);
545 bytes[i++] = (byte)((rz >> 8) % 256);
546 bytes[i++] = (byte)(rw % 256);
547 bytes[i++] = (byte)((rw >> 8) % 256);
548
549 //rotation vel
550 bytes[i++] = (byte)(ac % 256);
551 bytes[i++] = (byte)((ac >> 8) % 256);
552 bytes[i++] = (byte)(ac % 256);
553 bytes[i++] = (byte)((ac >> 8) % 256);
554 bytes[i++] = (byte)(ac % 256);
555 bytes[i++] = (byte)((ac >> 8) % 256);
556
557 dat.Data = bytes;
558 return dat;
559 }
560
561 public override void BackUp()
562 {
563 this.primData.FullID = this.uuid;
564 this.primData.LocalID = this.localid;
565 this.primData.Position = this.Pos;
566 this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
567 this.m_world.localStorage.StorePrim(this.primData);
568 }
569 }
570}
diff --git a/OpenSim/OpenSim.RegionServer/world/Primitive2.cs b/OpenSim/OpenSim.RegionServer/world/Primitive2.cs
new file mode 100644
index 0000000..6d071d4
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/Primitive2.cs
@@ -0,0 +1,491 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.types;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Types;
10using OpenSim.Framework.Inventory;
11
12namespace OpenSim.world
13{
14 public class Primitive2 : Entity
15 {
16 protected PrimData primData;
17 //private ObjectUpdatePacket OurPacket;
18 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
19 private Dictionary<uint, ClientView> m_clientThreads;
20 private ulong m_regionHandle;
21 private const uint FULL_MASK_PERMISSIONS = 2147483647;
22 private bool physicsEnabled = false;
23
24 private Dictionary<LLUUID, InventoryItem> inventoryItems;
25
26 #region Properties
27
28 public LLVector3 Scale
29 {
30 set
31 {
32 this.primData.Scale = value;
33 //this.dirtyFlag = true;
34 }
35 get
36 {
37 return this.primData.Scale;
38 }
39 }
40
41 public PhysicsActor PhysActor
42 {
43 set
44 {
45 this._physActor = value;
46 }
47 }
48 public override LLVector3 Pos
49 {
50 get
51 {
52 return base.Pos;
53 }
54 set
55 {
56 base.Pos = value;
57 }
58 }
59 #endregion
60
61 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world)
62 {
63 m_clientThreads = clientThreads;
64 m_regionHandle = regionHandle;
65 m_world = world;
66 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
67 }
68
69 public Primitive2(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world, LLUUID owner)
70 {
71 m_clientThreads = clientThreads;
72 m_regionHandle = regionHandle;
73 m_world = world;
74 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
75 this.primData = new PrimData();
76 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
77 this.primData.OwnerID = owner;
78 }
79
80 public byte[] GetByteArray()
81 {
82 byte[] result = null;
83 List<byte[]> dataArrays = new List<byte[]>();
84 dataArrays.Add(primData.ToBytes());
85 foreach (Entity child in children)
86 {
87 if (child is OpenSim.world.Primitive2)
88 {
89 dataArrays.Add(((OpenSim.world.Primitive2)child).GetByteArray());
90 }
91 }
92 byte[] primstart = Helpers.StringToField("<Prim>");
93 byte[] primend = Helpers.StringToField("</Prim>");
94 int totalLength = primstart.Length + primend.Length;
95 for (int i = 0; i < dataArrays.Count; i++)
96 {
97 totalLength += dataArrays[i].Length;
98 }
99
100 result = new byte[totalLength];
101 int arraypos = 0;
102 Array.Copy(primstart, 0, result, 0, primstart.Length);
103 arraypos += primstart.Length;
104 for (int i = 0; i < dataArrays.Count; i++)
105 {
106 Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length);
107 arraypos += dataArrays[i].Length;
108 }
109 Array.Copy(primend, 0, result, arraypos, primend.Length);
110
111 return result;
112 }
113
114 #region Overridden Methods
115
116 public override void update()
117 {
118 LLVector3 pos2 = new LLVector3(0, 0, 0);
119 }
120
121 public override void BackUp()
122 {
123
124 }
125
126 #endregion
127
128 #region Packet handlers
129
130 public void UpdatePosition(LLVector3 pos)
131 {
132
133 }
134
135 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
136 {
137 this.primData.PathBegin = addPacket.PathBegin;
138 this.primData.PathEnd = addPacket.PathEnd;
139 this.primData.PathScaleX = addPacket.PathScaleX;
140 this.primData.PathScaleY = addPacket.PathScaleY;
141 this.primData.PathShearX = addPacket.PathShearX;
142 this.primData.PathShearY = addPacket.PathShearY;
143 this.primData.PathSkew = addPacket.PathSkew;
144 this.primData.ProfileBegin = addPacket.ProfileBegin;
145 this.primData.ProfileEnd = addPacket.ProfileEnd;
146 this.primData.PathCurve = addPacket.PathCurve;
147 this.primData.ProfileCurve = addPacket.ProfileCurve;
148 this.primData.ProfileHollow = addPacket.ProfileHollow;
149 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
150 this.primData.PathRevolutions = addPacket.PathRevolutions;
151 this.primData.PathTaperX = addPacket.PathTaperX;
152 this.primData.PathTaperY = addPacket.PathTaperY;
153 this.primData.PathTwist = addPacket.PathTwist;
154 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
155 }
156
157 public void UpdateTexture(byte[] tex)
158 {
159 this.primData.Texture = tex;
160 //this.dirtyFlag = true;
161 }
162
163 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
164 {
165
166 }
167
168 public void AssignToParent(Primitive prim)
169 {
170
171 }
172
173 public void GetProperites(ClientView client)
174 {
175 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
176 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
177 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
178 proper.ObjectData[0].ItemID = LLUUID.Zero;
179 proper.ObjectData[0].CreationDate = (ulong)this.primData.CreationDate;
180 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
181 proper.ObjectData[0].FolderID = LLUUID.Zero;
182 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
183 proper.ObjectData[0].GroupID = LLUUID.Zero;
184 proper.ObjectData[0].InventorySerial = 0;
185 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
186 proper.ObjectData[0].ObjectID = this.uuid;
187 proper.ObjectData[0].OwnerID = primData.OwnerID;
188 proper.ObjectData[0].TouchName = new byte[0];
189 proper.ObjectData[0].TextureID = new byte[0];
190 proper.ObjectData[0].SitName = new byte[0];
191 proper.ObjectData[0].Name = new byte[0];
192 proper.ObjectData[0].Description = new byte[0];
193 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
194 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
195 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
196 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
197 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
198
199 client.OutPacket(proper);
200 }
201
202 #endregion
203
204 # region Inventory Methods
205
206 public bool AddToInventory(InventoryItem item)
207 {
208 return false;
209 }
210
211 public InventoryItem RemoveFromInventory(LLUUID itemID)
212 {
213 return null;
214 }
215
216 public void RequestInventoryInfo(ClientView simClient, RequestTaskInventoryPacket packet)
217 {
218
219 }
220
221 public void RequestXferInventory(ClientView simClient, ulong xferID)
222 {
223 //will only currently work if the total size of the inventory data array is under about 1000 bytes
224 SendXferPacketPacket send = new SendXferPacketPacket();
225
226 send.XferID.ID = xferID;
227 send.XferID.Packet = 1 + 2147483648;
228 send.DataPacket.Data = this.ConvertInventoryToBytes();
229
230 simClient.OutPacket(send);
231 }
232
233 public byte[] ConvertInventoryToBytes()
234 {
235 System.Text.Encoding enc = System.Text.Encoding.ASCII;
236 byte[] result = new byte[0];
237 List<byte[]> inventoryData = new List<byte[]>();
238 int totallength = 0;
239 foreach (InventoryItem invItem in inventoryItems.Values)
240 {
241 byte[] data = enc.GetBytes(invItem.ExportString());
242 inventoryData.Add(data);
243 totallength += data.Length;
244 }
245 //TODO: copy arrays into the single result array
246
247 return result;
248 }
249
250 public void CreateInventoryFromBytes(byte[] data)
251 {
252
253 }
254
255 #endregion
256
257 #region Update viewers Methods
258
259 //should change these mehtods, so that outgoing packets are sent through the avatar class
260 public void SendFullUpdateToClient(ClientView remoteClient)
261 {
262 LLVector3 lPos;
263 if (this._physActor != null && this.physicsEnabled)
264 {
265 PhysicsVector pPos = this._physActor.Position;
266 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
267 }
268 else
269 {
270 lPos = this.Pos;
271 }
272
273 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
274 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
275 outPacket.ObjectData[0] = this.CreateUpdateBlock();
276 byte[] pb = lPos.GetBytes();
277 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
278
279 remoteClient.OutPacket(outPacket);
280 }
281
282 public void SendFullUpdateToAllClients()
283 {
284
285 }
286
287 public void SendTerseUpdateToClient(ClientView RemoteClient)
288 {
289
290 }
291
292 public void SendTerseUpdateToALLClients()
293 {
294
295 }
296
297 #endregion
298
299 #region Create Methods
300
301 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
302 {
303 PrimData PData = new PrimData();
304 this.primData = PData;
305 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
306
307 PData.OwnerID = ownerID;
308 PData.PCode = addPacket.ObjectData.PCode;
309 PData.PathBegin = addPacket.ObjectData.PathBegin;
310 PData.PathEnd = addPacket.ObjectData.PathEnd;
311 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
312 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
313 PData.PathShearX = addPacket.ObjectData.PathShearX;
314 PData.PathShearY = addPacket.ObjectData.PathShearY;
315 PData.PathSkew = addPacket.ObjectData.PathSkew;
316 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
317 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
318 PData.Scale = addPacket.ObjectData.Scale;
319 PData.PathCurve = addPacket.ObjectData.PathCurve;
320 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
321 PData.ParentID = 0;
322 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
323 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
324 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
325 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
326 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
327 PData.PathTwist = addPacket.ObjectData.PathTwist;
328 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
329 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
330 this.primData.FullID = this.uuid = LLUUID.Random();
331 this.localid = (uint)(localID);
332 this.primData.Position = this.Pos = pos1;
333 }
334
335 public void CreateFromBytes(byte[] data)
336 {
337
338 }
339
340 public void CreateFromPrimData(PrimData primData)
341 {
342 this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false);
343 }
344
345 public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim)
346 {
347
348 }
349
350 #endregion
351
352 #region Packet Update Methods
353 protected void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
354 {
355 objdata.PSBlock = new byte[0];
356 objdata.ExtraParams = new byte[1];
357 objdata.MediaURL = new byte[0];
358 objdata.NameValue = new byte[0];
359 objdata.Text = new byte[0];
360 objdata.TextColor = new byte[4];
361 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
362 objdata.JointPivot = new LLVector3(0, 0, 0);
363 objdata.Material = 3;
364 objdata.TextureAnim = new byte[0];
365 objdata.Sound = LLUUID.Zero;
366 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
367 this.primData.Texture = objdata.TextureEntry = ntex.ToBytes();
368 objdata.State = 0;
369 objdata.Data = new byte[0];
370
371 objdata.ObjectData = new byte[60];
372 objdata.ObjectData[46] = 128;
373 objdata.ObjectData[47] = 63;
374 }
375
376 protected void SetPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData)
377 {
378 objectData.OwnerID = this.primData.OwnerID;
379 objectData.PCode = this.primData.PCode;
380 objectData.PathBegin = this.primData.PathBegin;
381 objectData.PathEnd = this.primData.PathEnd;
382 objectData.PathScaleX = this.primData.PathScaleX;
383 objectData.PathScaleY = this.primData.PathScaleY;
384 objectData.PathShearX = this.primData.PathShearX;
385 objectData.PathShearY = this.primData.PathShearY;
386 objectData.PathSkew = this.primData.PathSkew;
387 objectData.ProfileBegin = this.primData.ProfileBegin;
388 objectData.ProfileEnd = this.primData.ProfileEnd;
389 objectData.Scale = this.primData.Scale;
390 objectData.PathCurve = this.primData.PathCurve;
391 objectData.ProfileCurve = this.primData.ProfileCurve;
392 objectData.ParentID = this.primData.ParentID;
393 objectData.ProfileHollow = this.primData.ProfileHollow;
394 objectData.PathRadiusOffset = this.primData.PathRadiusOffset;
395 objectData.PathRevolutions = this.primData.PathRevolutions;
396 objectData.PathTaperX = this.primData.PathTaperX;
397 objectData.PathTaperY = this.primData.PathTaperY;
398 objectData.PathTwist = this.primData.PathTwist;
399 objectData.PathTwistBegin = this.primData.PathTwistBegin;
400 }
401
402 #endregion
403 protected ObjectUpdatePacket.ObjectDataBlock CreateUpdateBlock()
404 {
405 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
406 this.SetDefaultPacketValues(objupdate);
407 objupdate.UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
408 this.SetPacketShapeData(objupdate);
409 byte[] pb = this.Pos.GetBytes();
410 Array.Copy(pb, 0, objupdate.ObjectData, 0, pb.Length);
411 return objupdate;
412 }
413
414 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
415 {
416 uint ID = this.localid;
417 byte[] bytes = new byte[60];
418
419 int i = 0;
420 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
421 dat.TextureEntry = new byte[0];
422 bytes[i++] = (byte)(ID % 256);
423 bytes[i++] = (byte)((ID >> 8) % 256);
424 bytes[i++] = (byte)((ID >> 16) % 256);
425 bytes[i++] = (byte)((ID >> 24) % 256);
426 bytes[i++] = 0;
427 bytes[i++] = 0;
428
429 LLVector3 lPos;
430 Axiom.MathLib.Quaternion lRot;
431 if (this._physActor != null && this.physicsEnabled)
432 {
433 PhysicsVector pPos = this._physActor.Position;
434 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
435 lRot = this._physActor.Orientation;
436 }
437 else
438 {
439 lPos = this.Pos;
440 lRot = this.rotation;
441 }
442 byte[] pb = lPos.GetBytes();
443 Array.Copy(pb, 0, bytes, i, pb.Length);
444 i += 12;
445 ushort ac = 32767;
446
447 //vel
448 bytes[i++] = (byte)(ac % 256);
449 bytes[i++] = (byte)((ac >> 8) % 256);
450 bytes[i++] = (byte)(ac % 256);
451 bytes[i++] = (byte)((ac >> 8) % 256);
452 bytes[i++] = (byte)(ac % 256);
453 bytes[i++] = (byte)((ac >> 8) % 256);
454
455 //accel
456 bytes[i++] = (byte)(ac % 256);
457 bytes[i++] = (byte)((ac >> 8) % 256);
458 bytes[i++] = (byte)(ac % 256);
459 bytes[i++] = (byte)((ac >> 8) % 256);
460 bytes[i++] = (byte)(ac % 256);
461 bytes[i++] = (byte)((ac >> 8) % 256);
462
463 ushort rw, rx, ry, rz;
464 rw = (ushort)(32768 * (lRot.w + 1));
465 rx = (ushort)(32768 * (lRot.x + 1));
466 ry = (ushort)(32768 * (lRot.y + 1));
467 rz = (ushort)(32768 * (lRot.z + 1));
468
469 //rot
470 bytes[i++] = (byte)(rx % 256);
471 bytes[i++] = (byte)((rx >> 8) % 256);
472 bytes[i++] = (byte)(ry % 256);
473 bytes[i++] = (byte)((ry >> 8) % 256);
474 bytes[i++] = (byte)(rz % 256);
475 bytes[i++] = (byte)((rz >> 8) % 256);
476 bytes[i++] = (byte)(rw % 256);
477 bytes[i++] = (byte)((rw >> 8) % 256);
478
479 //rotation vel
480 bytes[i++] = (byte)(ac % 256);
481 bytes[i++] = (byte)((ac >> 8) % 256);
482 bytes[i++] = (byte)(ac % 256);
483 bytes[i++] = (byte)((ac >> 8) % 256);
484 bytes[i++] = (byte)(ac % 256);
485 bytes[i++] = (byte)((ac >> 8) % 256);
486
487 dat.Data = bytes;
488 return dat;
489 }
490 }
491}
diff --git a/OpenSim/OpenSim.RegionServer/world/SceneObject.cs b/OpenSim/OpenSim.RegionServer/world/SceneObject.cs
new file mode 100644
index 0000000..a846fb5
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/SceneObject.cs
@@ -0,0 +1,77 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.types;
5using libsecondlife;
6using libsecondlife.Packets;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Physics.Manager;
9using OpenSim.Framework.Types;
10using OpenSim.Framework.Inventory;
11
12namespace OpenSim.world
13{
14 public class SceneObject : Entity
15 {
16 private LLUUID rootUUID;
17 private Dictionary<LLUUID, Primitive2> ChildPrimitives = new Dictionary<LLUUID, Primitive2>();
18 private Dictionary<uint, ClientView> m_clientThreads;
19 private World m_world;
20
21 public SceneObject()
22 {
23
24 }
25
26 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
27 {
28 }
29
30 public void CreateFromBytes(byte[] data)
31 {
32
33 }
34
35 public override void update()
36 {
37
38 }
39
40 public override void BackUp()
41 {
42
43 }
44
45 public void GetProperites(ClientView client)
46 {
47 /*
48 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
49 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
50 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
51 proper.ObjectData[0].ItemID = LLUUID.Zero;
52 proper.ObjectData[0].CreationDate = (ulong)this.primData.CreationDate;
53 proper.ObjectData[0].CreatorID = this.primData.OwnerID;
54 proper.ObjectData[0].FolderID = LLUUID.Zero;
55 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
56 proper.ObjectData[0].GroupID = LLUUID.Zero;
57 proper.ObjectData[0].InventorySerial = 0;
58 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
59 proper.ObjectData[0].ObjectID = this.uuid;
60 proper.ObjectData[0].OwnerID = primData.OwnerID;
61 proper.ObjectData[0].TouchName = new byte[0];
62 proper.ObjectData[0].TextureID = new byte[0];
63 proper.ObjectData[0].SitName = new byte[0];
64 proper.ObjectData[0].Name = new byte[0];
65 proper.ObjectData[0].Description = new byte[0];
66 proper.ObjectData[0].OwnerMask = this.primData.OwnerMask;
67 proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask;
68 proper.ObjectData[0].GroupMask = this.primData.GroupMask;
69 proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask;
70 proper.ObjectData[0].BaseMask = this.primData.BaseMask;
71
72 client.OutPacket(proper);
73 * */
74 }
75
76 }
77}
diff --git a/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs b/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs
new file mode 100644
index 0000000..4f32335
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs
@@ -0,0 +1,368 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using libsecondlife.Packets;
6using OpenSim.Physics.Manager;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Types;
9using OpenSim.Framework.Terrain;
10using OpenSim.Framework.Inventory;
11using OpenSim.Framework.Utilities;
12using OpenSim.Assets;
13
14namespace OpenSim.world
15{
16 public partial class World
17 {
18 public void ModifyTerrain(byte action, float north, float west)
19 {
20 switch (action)
21 {
22 case 1:
23 // raise terrain
24 Terrain.raise(north, west, 10.0, 0.001);
25 RegenerateTerrain(true, (int)north, (int)west);
26 break;
27 case 2:
28 //lower terrain
29 Terrain.lower(north, west, 10.0, 0.001);
30 RegenerateTerrain(true, (int)north, (int)west);
31 break;
32 }
33 return;
34 }
35
36 public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
37 {
38 foreach (ClientView client in m_clientThreads.Values)
39 {
40 // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
41 int dis = (int)client.ClientAvatar.Pos.GetDistanceTo(fromPos);
42
43 switch (type)
44 {
45 case 0: // Whisper
46 if ((dis < 10) && (dis > -10))
47 {
48 //should change so the message is sent through the avatar rather than direct to the ClientView
49 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
50 }
51 break;
52 case 1: // Say
53 if ((dis < 30) && (dis > -30))
54 {
55 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
56 }
57 break;
58 case 2: // Shout
59 if ((dis < 100) && (dis > -100))
60 {
61 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
62 }
63 break;
64
65 case 0xff: // Broadcast
66 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
67 break;
68 }
69
70 }
71 }
72
73 public void RezObject(AssetBase primAsset, LLVector3 pos)
74 {
75 PrimData primd = new PrimData(primAsset.Data);
76 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
77 nPrim.CreateFromStorage(primd, pos, this._primCount, true);
78 this.Entities.Add(nPrim.uuid, nPrim);
79 this._primCount++;
80 }
81
82 public void DeRezObject(Packet packet, ClientView simClient)
83 {
84 DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet;
85
86 //Needs to delete object from physics at a later date
87 if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
88 {
89 //currently following code not used (or don't know of any case of destination being zero
90 libsecondlife.LLUUID[] DeRezEnts;
91 DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length];
92 int i = 0;
93 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
94 {
95
96 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
97 foreach (Entity ent in this.Entities.Values)
98 {
99 if (ent.localid == Data.ObjectLocalID)
100 {
101 DeRezEnts[i++] = ent.uuid;
102 this.localStorage.RemovePrim(ent.uuid);
103 KillObjectPacket kill = new KillObjectPacket();
104 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
105 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
106 kill.ObjectData[0].ID = ent.localid;
107 foreach (ClientView client in m_clientThreads.Values)
108 {
109 client.OutPacket(kill);
110 }
111 //Uncommenting this means an old UUID will be re-used, thus crashing the asset server
112 //Uncomment when prim/object UUIDs are random or such
113 //2007-03-22 - Randomskk
114 //this._primCount--;
115 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE, "Deleted UUID " + ent.uuid);
116 }
117 }
118 }
119 foreach (libsecondlife.LLUUID uuid in DeRezEnts)
120 {
121 lock (Entities)
122 {
123 Entities.Remove(uuid);
124 }
125 }
126 }
127 else
128 {
129 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
130 {
131 Entity selectedEnt = null;
132 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
133 foreach (Entity ent in this.Entities.Values)
134 {
135 if (ent.localid == Data.ObjectLocalID)
136 {
137 AssetBase primAsset = new AssetBase();
138 primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid
139 primAsset.InvType = 6;
140 primAsset.Type = 6;
141 primAsset.Name = "Prim";
142 primAsset.Description = "";
143 primAsset.Data = ((Primitive)ent).GetByteArray();
144 this._assetCache.AddAsset(primAsset);
145 this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset);
146 selectedEnt = ent;
147 break;
148 }
149 }
150 if (selectedEnt != null)
151 {
152 this.localStorage.RemovePrim(selectedEnt.uuid);
153 KillObjectPacket kill = new KillObjectPacket();
154 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
155 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
156 kill.ObjectData[0].ID = selectedEnt.localid;
157 foreach (ClientView client in m_clientThreads.Values)
158 {
159 client.OutPacket(kill);
160 }
161 lock (Entities)
162 {
163 Entities.Remove(selectedEnt.uuid);
164 }
165 }
166 }
167 }
168
169 }
170
171 public void SendAvatarsToClient(ClientView remoteClient)
172 {
173 foreach (ClientView client in m_clientThreads.Values)
174 {
175 if (client.AgentID != remoteClient.AgentID)
176 {
177 // ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket();
178 // RemoteClient.OutPacket(objupdate);
179 client.ClientAvatar.SendUpdateToOtherClient(remoteClient.ClientAvatar);
180 client.ClientAvatar.SendAppearanceToOtherAgent(remoteClient.ClientAvatar);
181 }
182 }
183 }
184
185 public void LinkObjects(uint parentPrim, List<uint> childPrims)
186 {
187 Primitive parentprim = null;
188 foreach (Entity ent in Entities.Values)
189 {
190 if (ent.localid == parentPrim)
191 {
192 parentprim = (OpenSim.world.Primitive)ent;
193
194 }
195 }
196
197 for (int i = 0; i < childPrims.Count; i++)
198 {
199 uint childId = childPrims[i];
200 foreach (Entity ent in Entities.Values)
201 {
202 if (ent.localid == childId)
203 {
204 ((OpenSim.world.Primitive)ent).MakeParent(parentprim);
205 }
206 }
207 }
208
209 }
210
211 public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
212 {
213 foreach (Entity ent in Entities.Values)
214 {
215 if (ent.localid == primLocalID)
216 {
217 ((OpenSim.world.Primitive)ent).UpdateShape(shapeBlock);
218 break;
219 }
220 }
221 }
222
223 public void SelectPrim(uint primLocalID, ClientView remoteClient)
224 {
225 foreach (Entity ent in Entities.Values)
226 {
227 if (ent.localid == primLocalID)
228 {
229 ((OpenSim.world.Primitive)ent).GetProperites(remoteClient);
230 break;
231 }
232 }
233 }
234
235 public void UpdatePrimFlags(uint localID, Packet packet, ClientView remoteClient)
236 {
237 foreach (Entity ent in Entities.Values)
238 {
239 if (ent.localid == localID)
240 {
241 ((OpenSim.world.Primitive)ent).UpdateObjectFlags((ObjectFlagUpdatePacket) packet);
242 break;
243 }
244 }
245 }
246
247 public void UpdatePrimTexture(uint localID, byte[] texture, ClientView remoteClient)
248 {
249 foreach (Entity ent in Entities.Values)
250 {
251 if (ent.localid == localID)
252 {
253 ((OpenSim.world.Primitive)ent).UpdateTexture(texture);
254 break;
255 }
256 }
257 }
258
259 public void UpdatePrimPosition(uint localID, LLVector3 pos, ClientView remoteClient)
260 {
261 foreach (Entity ent in Entities.Values)
262 {
263 if (ent.localid == localID)
264 {
265 ((OpenSim.world.Primitive)ent).UpdatePosition(pos);
266 break;
267 }
268 }
269 }
270
271 public void UpdatePrimRotation(uint localID, LLQuaternion rot, ClientView remoteClient)
272 {
273 foreach (Entity ent in Entities.Values)
274 {
275 if (ent.localid == localID)
276 {
277 ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
278 ((OpenSim.world.Primitive)ent).UpdateFlag = true;
279 break;
280 }
281 }
282 }
283
284 public void UpdatePrimScale(uint localID, LLVector3 scale, ClientView remoteClient)
285 {
286 foreach (Entity ent in Entities.Values)
287 {
288 if (ent.localid == localID)
289 {
290 ((OpenSim.world.Primitive)ent).Scale = scale;
291 break;
292 }
293 }
294 }
295
296 /*
297 public void RequestMapBlock(ClientView simClient, int minX, int minY, int maxX, int maxY)
298 {
299 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
300 if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY)))
301 {
302 MapBlockReplyPacket mapReply = new MapBlockReplyPacket();
303 mapReply.AgentData.AgentID = simClient.AgentID;
304 mapReply.AgentData.Flags = 0;
305 mapReply.Data = new MapBlockReplyPacket.DataBlock[1];
306 mapReply.Data[0] = new MapBlockReplyPacket.DataBlock();
307 mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007");
308 mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX;
309 mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY;
310 mapReply.Data[0].WaterHeight = (byte)m_regInfo.RegionWaterHeight;
311 mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName);
312 mapReply.Data[0].RegionFlags = 72458694;
313 mapReply.Data[0].Access = 13;
314 mapReply.Data[0].Agents = 1; //should send number of clients connected
315 simClient.OutPacket(mapReply);
316 }
317 }
318 public bool RezObjectHandler(ClientView simClient, Packet packet)
319 {
320 RezObjectPacket rezPacket = (RezObjectPacket)packet;
321 AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID);
322 if (inven != null)
323 {
324 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
325 {
326 AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
327 if (asset != null)
328 {
329 PrimData primd = new PrimData(asset.Data);
330 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
331 nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true);
332 this.Entities.Add(nPrim.uuid, nPrim);
333 this._primCount++;
334 this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID);
335 }
336 }
337 }
338 return true;
339 }
340 public bool ModifyTerrain(ClientView simClient, Packet packet)
341 {
342 ModifyLandPacket modify = (ModifyLandPacket)packet;
343
344 switch (modify.ModifyBlock.Action)
345 {
346 case 1:
347 // raise terrain
348 if (modify.ParcelData.Length > 0)
349 {
350 Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
351 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
352 }
353 break;
354 case 2:
355 //lower terrain
356 if (modify.ParcelData.Length > 0)
357 {
358 Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
359 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
360 }
361 break;
362 }
363 return true;
364 }
365 */
366
367 }
368}
diff --git a/OpenSim/OpenSim.RegionServer/world/World.Scripting.cs b/OpenSim/OpenSim.RegionServer/world/World.Scripting.cs
new file mode 100644
index 0000000..44ef05a
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/World.Scripting.cs
@@ -0,0 +1,124 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using System.Reflection;
6using OpenSim.Framework;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Types;
9using libsecondlife;
10
11namespace OpenSim.world
12{
13 public partial class World
14 {
15 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
16
17 private void LoadScriptEngines()
18 {
19 this.LoadScriptPlugins();
20 }
21
22 public void LoadScriptPlugins()
23 {
24 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
25 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
26
27
28 for (int i = 0; i < pluginFiles.Length; i++)
29 {
30 this.AddPlugin(pluginFiles[i]);
31 }
32 }
33
34 private void AddPlugin(string FileName)
35 {
36 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
37
38 foreach (Type pluginType in pluginAssembly.GetTypes())
39 {
40 if (pluginType.IsPublic)
41 {
42 if (!pluginType.IsAbstract)
43 {
44 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
45
46 if (typeInterface != null)
47 {
48 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
49 plug.Init(this);
50 this.scriptEngines.Add(plug.GetName(), plug);
51
52 }
53
54 typeInterface = null;
55 }
56 }
57 }
58
59 pluginAssembly = null;
60 }
61
62 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
63 {
64 if(this.scriptEngines.ContainsKey(scriptType))
65 {
66 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
67 }
68 }
69
70 #region IScriptAPI Methods
71
72 public OSVector3 GetEntityPosition(uint localID)
73 {
74 OSVector3 res = new OSVector3();
75 // Console.WriteLine("script- getting entity " + localID + " position");
76 foreach (Entity entity in this.Entities.Values)
77 {
78 if (entity.localid == localID)
79 {
80 res.X = entity.Pos.X;
81 res.Y = entity.Pos.Y;
82 res.Z = entity.Pos.Z;
83 }
84 }
85 return res;
86 }
87
88 public void SetEntityPosition(uint localID, float x , float y, float z)
89 {
90 foreach (Entity entity in this.Entities.Values)
91 {
92 if (entity.localid == localID && entity is Primitive)
93 {
94 LLVector3 pos = entity.Pos;
95 pos.X = x;
96 pos.Y = y;
97 Primitive prim = entity as Primitive;
98 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
99 prim.UpdatePosition(pos);
100 // Console.WriteLine("script- setting entity " + localID + " positon");
101 }
102 }
103
104 }
105
106 public uint GetRandomAvatarID()
107 {
108 //Console.WriteLine("script- getting random avatar id");
109 uint res = 0;
110 foreach (Entity entity in this.Entities.Values)
111 {
112 if (entity is Avatar)
113 {
114 res = entity.localid;
115 }
116 }
117 return res;
118 }
119
120 #endregion
121
122
123 }
124}
diff --git a/OpenSim/OpenSim.RegionServer/world/World.cs b/OpenSim/OpenSim.RegionServer/world/World.cs
new file mode 100644
index 0000000..bb24011
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/World.cs
@@ -0,0 +1,657 @@
1using System;
2using libsecondlife;
3using libsecondlife.Packets;
4using System.Collections.Generic;
5using System.Text;
6using System.Reflection;
7using System.IO;
8using System.Threading;
9using OpenSim.Physics.Manager;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Types;
12using OpenSim.Framework.Terrain;
13using OpenSim.Framework.Inventory;
14using OpenSim.Assets;
15//using OpenSim.world.scripting;
16using OpenSim.RegionServer.world.scripting;
17using OpenSim.Terrain;
18
19namespace OpenSim.world
20{
21 public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI
22 {
23 public object LockPhysicsEngine = new object();
24 public Dictionary<libsecondlife.LLUUID, Avatar> Avatars;
25 public Dictionary<libsecondlife.LLUUID, Primitive> Prims;
26 //public ScriptEngine Scripts;
27 public uint _localNumber = 0;
28 private PhysicsScene phyScene;
29 private float timeStep = 0.1f;
30 public ILocalStorage localStorage;
31 private Random Rand = new Random();
32 private uint _primCount = 702000;
33 private int storageCount;
34 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
35 private Dictionary<string, ScriptFactory> m_scripts;
36 private Mutex updateLock;
37 public string m_datastore;
38
39 #region Properties
40 public PhysicsScene PhysScene
41 {
42 set
43 {
44 this.phyScene = value;
45 }
46 get
47 {
48 return (this.phyScene);
49 }
50 }
51 #endregion
52
53 #region Constructors
54 /// <summary>
55 /// Creates a new World class, and a region to go with it.
56 /// </summary>
57 /// <param name="clientThreads">Dictionary to contain client threads</param>
58 /// <param name="regionHandle">Region Handle for this region</param>
59 /// <param name="regionName">Region Name for this region</param>
60 public World(Dictionary<uint, ClientView> clientThreads, RegionInfo regInfo, ulong regionHandle, string regionName)
61 {
62 try
63 {
64 updateLock = new Mutex(false);
65 m_clientThreads = clientThreads;
66 m_regionHandle = regionHandle;
67 m_regionName = regionName;
68 m_regInfo = regInfo;
69
70 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
71 m_scripts = new Dictionary<string, ScriptFactory>();
72
73 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating new entitities instance");
74 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
75 Avatars = new Dictionary<LLUUID, Avatar>();
76 Prims = new Dictionary<LLUUID, Primitive>();
77
78 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating LandMap");
79 TerrainManager = new TerrainManager(new SecondLife());
80 Terrain = new TerrainEngine();
81 Avatar.SetupTemplate("avatar-texture.dat");
82 // MainConsole.Instance.WriteLine("World.cs - Creating script engine instance");
83 // Initialise this only after the world has loaded
84 // Scripts = new ScriptEngine(this);
85 Avatar.LoadAnims();
86 this.SetDefaultScripts();
87 this.LoadScriptEngines();
88 }
89 catch (Exception e)
90 {
91 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL, "World.cs: Constructor failed with exception " + e.ToString());
92 }
93 }
94 #endregion
95
96 #region Script Methods
97 /// <summary>
98 /// Loads a new script into the specified entity
99 /// </summary>
100 /// <param name="entity">Entity to be scripted</param>
101 /// <param name="script">The script to load</param>
102 public void AddScript(Entity entity, Script script)
103 {
104 try
105 {
106 ScriptHandler scriptHandler = new ScriptHandler(script, entity, this);
107 m_scriptHandlers.Add(scriptHandler.ScriptId, scriptHandler);
108 }
109 catch (Exception e)
110 {
111 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddScript() - Failed with exception " + e.ToString());
112 }
113 }
114
115 /// <summary>
116 /// Loads a new script into the specified entity, using a script loaded from a string.
117 /// </summary>
118 /// <param name="entity">The entity to be scripted</param>
119 /// <param name="scriptData">The string containing the script</param>
120 public void AddScript(Entity entity, string scriptData)
121 {
122 try
123 {
124 int scriptstart = 0;
125 int scriptend = 0;
126 string substring;
127 scriptstart = scriptData.LastIndexOf("<Script>");
128 scriptend = scriptData.LastIndexOf("</Script>");
129 substring = scriptData.Substring(scriptstart + 8, scriptend - scriptstart - 8);
130 substring = substring.Trim();
131 //Console.WriteLine("searching for script to add: " + substring);
132
133 ScriptFactory scriptFactory;
134 //Console.WriteLine("script string is " + substring);
135 if (substring.StartsWith("<ScriptEngine:"))
136 {
137 string substring1 = "";
138 string script = "";
139 // Console.WriteLine("searching for script engine");
140 substring1 = substring.Remove(0, 14);
141 int dev = substring1.IndexOf(',');
142 string sEngine = substring1.Substring(0, dev);
143 substring1 = substring1.Remove(0, dev + 1);
144 int end = substring1.IndexOf('>');
145 string sName = substring1.Substring(0, end);
146 //Console.WriteLine(" script info : " + sEngine + " , " + sName);
147 int startscript = substring.IndexOf('>');
148 script = substring.Remove(0, startscript + 1);
149 // Console.WriteLine("script data is " + script);
150 if (this.scriptEngines.ContainsKey(sEngine))
151 {
152 this.scriptEngines[sEngine].LoadScript(script, sName, entity.localid);
153 }
154 }
155 else if (this.m_scripts.TryGetValue(substring, out scriptFactory))
156 {
157 //Console.WriteLine("added script");
158 this.AddScript(entity, scriptFactory());
159 }
160 }
161 catch (Exception e)
162 {
163 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddScript() - Failed with exception " + e.ToString());
164 }
165 }
166
167 #endregion
168
169 #region Update Methods
170 /// <summary>
171 /// Performs per-frame updates on the world, this should be the central world loop
172 /// </summary>
173 public override void Update()
174 {
175 updateLock.WaitOne();
176 try
177 {
178 if (this.phyScene.IsThreaded)
179 {
180 this.phyScene.GetResults();
181
182 }
183
184 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
185 {
186 Entities[UUID].addForces();
187 }
188
189 lock (this.LockPhysicsEngine)
190 {
191 this.phyScene.Simulate(timeStep);
192 }
193
194 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
195 {
196 Entities[UUID].update();
197 }
198
199 foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
200 {
201 scriptHandler.OnFrame();
202 }
203 foreach (IScriptEngine scripteng in this.scriptEngines.Values)
204 {
205 scripteng.OnFrame();
206 }
207 //backup world data
208 this.storageCount++;
209 if (storageCount > 1200) //set to how often you want to backup
210 {
211 this.Backup();
212 storageCount = 0;
213 }
214 }
215 catch (Exception e)
216 {
217 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: Update() - Failed with exception " + e.ToString());
218 }
219 updateLock.ReleaseMutex();
220 }
221
222 public bool Backup()
223 {
224 try
225 {
226 // Terrain backup routines
227 if (Terrain.tainted > 0)
228 {
229 Terrain.tainted = 0;
230 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain tainted, saving.");
231 localStorage.SaveMap(Terrain.getHeights1D());
232 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain saved, informing Physics.");
233 lock (this.LockPhysicsEngine)
234 {
235 phyScene.SetTerrain(Terrain.getHeights1D());
236 }
237 }
238
239 // Primitive backup routines
240 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Backing up Primitives");
241 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
242 {
243 Entities[UUID].BackUp();
244 }
245
246 // Backup successful
247 return true;
248 }
249 catch (Exception e)
250 {
251 // Backup failed
252 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Backup() - Backup Failed with exception " + e.ToString());
253 return false;
254 }
255 }
256 #endregion
257
258 #region Setup Methods
259 /// <summary>
260 /// Loads a new storage subsystem from a named library
261 /// </summary>
262 /// <param name="dllName">Storage Library</param>
263 /// <returns>Successful or not</returns>
264 public bool LoadStorageDLL(string dllName)
265 {
266 try
267 {
268 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
269 ILocalStorage store = null;
270
271 foreach (Type pluginType in pluginAssembly.GetTypes())
272 {
273 if (pluginType.IsPublic)
274 {
275 if (!pluginType.IsAbstract)
276 {
277 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
278
279 if (typeInterface != null)
280 {
281 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
282 store = plug;
283
284 store.Initialise(this.m_datastore);
285 break;
286 }
287
288 typeInterface = null;
289 }
290 }
291 }
292 pluginAssembly = null;
293 this.localStorage = store;
294 return (store == null);
295 }
296 catch (Exception e)
297 {
298 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
299 return false;
300 }
301 }
302
303 public void SetDefaultScripts()
304 {
305 this.m_scripts.Add("FollowRandomAvatar", delegate()
306 {
307 return new OpenSim.RegionServer.world.scripting.FollowRandomAvatar();
308 });
309 }
310
311 #endregion
312
313 #region Regenerate Terrain
314
315 /// <summary>
316 /// Rebuilds the terrain using a procedural algorithm
317 /// </summary>
318 public void RegenerateTerrain()
319 {
320 try
321 {
322 Terrain.hills();
323
324 lock (this.LockPhysicsEngine)
325 {
326 this.phyScene.SetTerrain(Terrain.getHeights1D());
327 }
328 this.localStorage.SaveMap(this.Terrain.getHeights1D());
329
330 foreach (ClientView client in m_clientThreads.Values)
331 {
332 this.SendLayerData(client);
333 }
334
335 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
336 {
337 Entities[UUID].LandRenegerated();
338 }
339 }
340 catch (Exception e)
341 {
342 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
343 }
344 }
345
346 /// <summary>
347 /// Rebuilds the terrain using a 2D float array
348 /// </summary>
349 /// <param name="newMap">256,256 float array containing heights</param>
350 public void RegenerateTerrain(float[,] newMap)
351 {
352 try
353 {
354 this.Terrain.setHeights2D(newMap);
355 lock (this.LockPhysicsEngine)
356 {
357 this.phyScene.SetTerrain(this.Terrain.getHeights1D());
358 }
359 this.localStorage.SaveMap(this.Terrain.getHeights1D());
360
361 foreach (ClientView client in m_clientThreads.Values)
362 {
363 this.SendLayerData(client);
364 }
365
366 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
367 {
368 Entities[UUID].LandRenegerated();
369 }
370 }
371 catch (Exception e)
372 {
373 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
374 }
375 }
376
377 /// <summary>
378 /// Rebuilds the terrain assuming changes occured at a specified point[?]
379 /// </summary>
380 /// <param name="changes">???</param>
381 /// <param name="pointx">???</param>
382 /// <param name="pointy">???</param>
383 public void RegenerateTerrain(bool changes, int pointx, int pointy)
384 {
385 try
386 {
387 if (changes)
388 {
389 /* Dont save here, rely on tainting system instead */
390
391 foreach (ClientView client in m_clientThreads.Values)
392 {
393 this.SendLayerData(pointx, pointy, client);
394 }
395 }
396 }
397 catch (Exception e)
398 {
399 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
400 }
401 }
402
403 #endregion
404
405 #region Load Terrain
406 /// <summary>
407 /// Loads the World heightmap
408 /// </summary>
409 public override void LoadWorldMap()
410 {
411 try
412 {
413 float[] map = this.localStorage.LoadWorld();
414 if (map == null)
415 {
416 Console.WriteLine("creating new terrain");
417 this.Terrain.hills();
418
419 this.localStorage.SaveMap(this.Terrain.getHeights1D());
420 }
421 else
422 {
423 this.Terrain.setHeights1D(map);
424 }
425 }
426 catch (Exception e)
427 {
428 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
429 }
430 }
431 #endregion
432
433 #region Primitives Methods
434
435 /// <summary>
436 /// Sends prims to a client
437 /// </summary>
438 /// <param name="RemoteClient">Client to send to</param>
439 public void GetInitialPrims(ClientView RemoteClient)
440 {
441 try
442 {
443 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
444 {
445 if (Entities[UUID] is Primitive)
446 {
447 Primitive primitive = Entities[UUID] as Primitive;
448 primitive.UpdateClient(RemoteClient);
449 }
450 }
451 }
452 catch (Exception e)
453 {
454 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: GetInitialPrims() - Failed with exception " + e.ToString());
455 }
456 }
457
458 /// <summary>
459 /// Loads the World's objects
460 /// </summary>
461 public void LoadPrimsFromStorage()
462 {
463 try
464 {
465 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: LoadPrimsFromStorage() - Loading primitives");
466 this.localStorage.LoadPrimitives(this);
467 }
468 catch (Exception e)
469 {
470 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
471 }
472 }
473
474 /// <summary>
475 /// Loads a specific object from storage
476 /// </summary>
477 /// <param name="prim">The object to load</param>
478 public void PrimFromStorage(PrimData prim)
479 {
480 try
481 {
482 if (prim.LocalID >= this._primCount)
483 {
484 _primCount = prim.LocalID + 1;
485 }
486 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: PrimFromStorage() - Reloading prim (localId " + prim.LocalID + " ) from storage");
487 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
488 nPrim.CreateFromStorage(prim);
489 this.Entities.Add(nPrim.uuid, nPrim);
490 }
491 catch (Exception e)
492 {
493 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: PrimFromStorage() - Failed with exception " + e.ToString());
494 }
495 }
496
497 public void AddNewPrim(Packet addPacket, ClientView agentClient)
498 {
499 AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentID);
500 }
501
502 public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID)
503 {
504 try
505 {
506 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: AddNewPrim() - Creating new prim");
507 Primitive prim = new Primitive(m_clientThreads, m_regionHandle, this);
508 prim.CreateFromPacket(addPacket, ownerID, this._primCount);
509 PhysicsVector pVec = new PhysicsVector(prim.Pos.X, prim.Pos.Y, prim.Pos.Z);
510 PhysicsVector pSize = new PhysicsVector(0.255f, 0.255f, 0.255f);
511 if (OpenSim.world.Avatar.PhysicsEngineFlying)
512 {
513 lock (this.LockPhysicsEngine)
514 {
515 prim.PhysActor = this.phyScene.AddPrim(pVec, pSize);
516 }
517 }
518
519 this.Entities.Add(prim.uuid, prim);
520 this._primCount++;
521 }
522 catch (Exception e)
523 {
524 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddNewPrim() - Failed with exception " + e.ToString());
525 }
526 }
527
528 #endregion
529
530 #region Add/Remove Avatar Methods
531
532 public override Avatar AddViewerAgent(ClientView agentClient)
533 {
534 //register for events
535 agentClient.OnChatFromViewer += new ChatFromViewer(this.SimChat);
536 agentClient.OnRezObject += new RezObject(this.RezObject);
537 agentClient.OnModifyTerrain += new ModifyTerrain(this.ModifyTerrain);
538 agentClient.OnRegionHandShakeReply += new ClientView.GenericCall(this.SendLayerData);
539 agentClient.OnRequestWearables += new ClientView.GenericCall(this.GetInitialPrims);
540 agentClient.OnRequestAvatarsData += new ClientView.GenericCall(this.SendAvatarsToClient);
541 agentClient.OnLinkObjects += new LinkObjects(this.LinkObjects);
542 agentClient.OnAddPrim += new ClientView.GenericCall4(this.AddNewPrim);
543 agentClient.OnUpdatePrimShape += new ClientView.UpdateShape(this.UpdatePrimShape);
544 agentClient.OnObjectSelect += new ClientView.ObjectSelect(this.SelectPrim);
545 agentClient.OnUpdatePrimFlags += new ClientView.UpdatePrimFlags(this.UpdatePrimFlags);
546 agentClient.OnUpdatePrimTexture += new ClientView.UpdatePrimTexture(this.UpdatePrimTexture);
547 agentClient.OnUpdatePrimPosition += new ClientView.UpdatePrimVector(this.UpdatePrimPosition);
548 agentClient.OnUpdatePrimRotation += new ClientView.UpdatePrimRotation(this.UpdatePrimRotation);
549 agentClient.OnUpdatePrimScale += new ClientView.UpdatePrimVector(this.UpdatePrimScale);
550 agentClient.OnDeRezObject += new ClientView.GenericCall4(this.DeRezObject);
551 Avatar newAvatar = null;
552 try
553 {
554 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
555 newAvatar = new Avatar(agentClient, this, m_regionName, m_clientThreads, m_regionHandle, true, 20);
556 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Adding new avatar to world");
557 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Starting RegionHandshake ");
558 newAvatar.SendRegionHandshake(this);
559 //if (!agentClient.m_child)
560 //{
561
562 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
563 lock (this.LockPhysicsEngine)
564 {
565 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
566 }
567 // }
568 lock (Entities)
569 {
570 if (!Entities.ContainsKey(agentClient.AgentID))
571 {
572 this.Entities.Add(agentClient.AgentID, newAvatar);
573 }
574 else
575 {
576 Entities[agentClient.AgentID] = newAvatar;
577 }
578 }
579 lock (Avatars)
580 {
581 if (Avatars.ContainsKey(agentClient.AgentID))
582 {
583 Avatars[agentClient.AgentID] = newAvatar;
584 }
585 else
586 {
587 this.Avatars.Add(agentClient.AgentID, newAvatar);
588 }
589 }
590 }
591 catch (Exception e)
592 {
593 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddViewerAgent() - Failed with exception " + e.ToString());
594 }
595 return newAvatar;
596 }
597
598 public override void RemoveViewerAgent(ClientView agentClient)
599 {
600 try
601 {
602 lock (Entities)
603 {
604 Entities.Remove(agentClient.AgentID);
605 }
606 lock (Avatars)
607 {
608 Avatars.Remove(agentClient.AgentID);
609 }
610 if (agentClient.ClientAvatar.PhysActor != null)
611 {
612 this.phyScene.RemoveAvatar(agentClient.ClientAvatar.PhysActor);
613 }
614 }
615 catch (Exception e)
616 {
617 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RemoveViewerAgent() - Failed with exception " + e.ToString());
618 }
619 }
620 #endregion
621
622 #region Request Avatars List Methods
623 //The idea is to have a group of method that return a list of avatars meeting some requirement
624 // ie it could be all Avatars within a certain range of the calling prim/avatar.
625
626 public List<Avatar> RequestAvatarList()
627 {
628 List<Avatar> result = new List<Avatar>();
629
630 foreach (Avatar avatar in Avatars.Values)
631 {
632 result.Add(avatar);
633 }
634
635 return result;
636 }
637 #endregion
638
639 #region ShutDown
640 /// <summary>
641 /// Tidy before shutdown
642 /// </summary>
643 public override void Close()
644 {
645 try
646 {
647 this.localStorage.ShutDown();
648 }
649 catch (Exception e)
650 {
651 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString());
652 }
653 }
654 #endregion
655
656 }
657}
diff --git a/OpenSim/OpenSim.RegionServer/world/WorldBase.cs b/OpenSim/OpenSim.RegionServer/world/WorldBase.cs
new file mode 100644
index 0000000..ea71411
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/WorldBase.cs
@@ -0,0 +1,176 @@
1using System;
2using libsecondlife;
3using libsecondlife.Packets;
4using System.Collections.Generic;
5using System.Text;
6using System.Reflection;
7using System.IO;
8using System.Threading;
9using OpenSim.Physics.Manager;
10using OpenSim.Framework.Interfaces;
11using OpenSim.Framework.Types;
12using OpenSim.Framework.Terrain;
13using OpenSim.Framework.Inventory;
14using OpenSim.Assets;
15using OpenSim.RegionServer.world.scripting;
16using OpenSim.Terrain;
17
18namespace OpenSim.world
19{
20 public class WorldBase
21 {
22 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
23 protected Dictionary<uint, ClientView> m_clientThreads;
24 protected ulong m_regionHandle;
25 protected string m_regionName;
26 protected InventoryCache _inventoryCache;
27 protected AssetCache _assetCache;
28 protected RegionInfo m_regInfo;
29
30 public TerrainEngine Terrain; //TODO: Replace TerrainManager with this.
31 protected libsecondlife.TerrainManager TerrainManager; // To be referenced via TerrainEngine
32
33 #region Properties
34 public InventoryCache InventoryCache
35 {
36 set
37 {
38 this._inventoryCache = value;
39 }
40 }
41
42 public AssetCache AssetCache
43 {
44 set
45 {
46 this._assetCache = value;
47 }
48 }
49 #endregion
50
51 #region Constructors
52 public WorldBase()
53 {
54
55 }
56 #endregion
57
58 #region Setup Methods
59 /// <summary>
60 /// Register Packet handler Methods with the packet server (which will register them with the SimClient)
61 /// </summary>
62 /// <param name="packetServer"></param>
63 public virtual void RegisterPacketHandlers(PacketServer packetServer)
64 {
65
66 }
67 #endregion
68
69 #region Update Methods
70 /// <summary>
71 /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
72 /// </summary>
73 public virtual void Update()
74 {
75
76 }
77 #endregion
78
79 #region Terrain Methods
80
81 /// <summary>
82 /// Loads the World heightmap
83 /// </summary>
84 public virtual void LoadWorldMap()
85 {
86
87 }
88
89 /// <summary>
90 /// Send the region heightmap to the client
91 /// </summary>
92 /// <param name="RemoteClient">Client to send to</param>
93 public virtual void SendLayerData(ClientView RemoteClient)
94 {
95 try
96 {
97 int[] patches = new int[4];
98
99 for (int y = 0; y < 16; y++)
100 {
101 for (int x = 0; x < 16; x = x + 4)
102 {
103 patches[0] = x + 0 + y * 16;
104 patches[1] = x + 1 + y * 16;
105 patches[2] = x + 2 + y * 16;
106 patches[3] = x + 3 + y * 16;
107
108 Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches);
109 RemoteClient.OutPacket(layerpack);
110 }
111 }
112 }
113 catch (Exception e)
114 {
115 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: SendLayerData() - Failed with exception " + e.ToString());
116 }
117 }
118
119 /// <summary>
120 /// Sends a specified patch to a client
121 /// </summary>
122 /// <param name="px">Patch coordinate (x) 0..16</param>
123 /// <param name="py">Patch coordinate (y) 0..16</param>
124 /// <param name="RemoteClient">The client to send to</param>
125 public void SendLayerData(int px, int py, ClientView RemoteClient)
126 {
127 try
128 {
129 int[] patches = new int[1];
130 int patchx, patchy;
131 patchx = px / 16;
132 patchy = py / 16;
133
134 patches[0] = patchx + 0 + patchy * 16;
135
136 Packet layerpack = TerrainManager.CreateLandPacket(Terrain.getHeights1D(), patches);
137 RemoteClient.OutPacket(layerpack);
138 }
139 catch (Exception e)
140 {
141 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: SendLayerData() - Failed with exception " + e.ToString());
142 }
143 }
144 #endregion
145
146 #region Add/Remove Agent/Avatar
147 /// <summary>
148 /// Add a new Agent's avatar
149 /// </summary>
150 /// <param name="agentClient"></param>
151 public virtual Avatar AddViewerAgent(ClientView agentClient)
152 {
153 return null;
154 }
155
156 /// <summary>
157 /// Remove a Agent's avatar
158 /// </summary>
159 /// <param name="agentClient"></param>
160 public virtual void RemoveViewerAgent(ClientView agentClient)
161 {
162
163 }
164 #endregion
165
166 #region Shutdown
167 /// <summary>
168 /// Tidy before shutdown
169 /// </summary>
170 public virtual void Close()
171 {
172
173 }
174 #endregion
175 }
176}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/IScriptContext.cs b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptContext.cs
new file mode 100644
index 0000000..465c23b
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptContext.cs
@@ -0,0 +1,13 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting
7{
8 public interface IScriptContext
9 {
10 IScriptEntity Entity { get; }
11 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
12 }
13}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/IScriptEntity.cs b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptEntity.cs
new file mode 100644
index 0000000..2ef16a4
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptEntity.cs
@@ -0,0 +1,19 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting
7{
8 public interface IScriptReadonlyEntity
9 {
10 LLVector3 Pos { get; }
11 string Name { get; }
12 }
13
14 public interface IScriptEntity
15 {
16 LLVector3 Pos { get; set; }
17 string Name { get; }
18 }
19}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/IScriptHandler.cs b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptHandler.cs
new file mode 100644
index 0000000..15efc49
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/IScriptHandler.cs
@@ -0,0 +1,98 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using OpenSim.Physics.Manager;
6using OpenSim.world;
7using Avatar=OpenSim.world.Avatar;
8using Primitive = OpenSim.world.Primitive;
9
10namespace OpenSim.RegionServer.world.scripting
11{
12 public delegate void ScriptEventHandler(IScriptContext context);
13
14 public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
15 {
16 private World m_world;
17 private Script m_script;
18 private Entity m_entity;
19
20 public LLUUID ScriptId
21 {
22 get
23 {
24 return m_script.ScriptId;
25 }
26 }
27
28 public void OnFrame()
29 {
30 m_script.OnFrame(this);
31 }
32
33 public ScriptHandler(Script script, Entity entity, World world)
34 {
35 m_script = script;
36 m_entity = entity;
37 m_world = world;
38 }
39
40 #region IScriptContext Members
41
42 IScriptEntity IScriptContext.Entity
43 {
44 get
45 {
46 return this;
47 }
48 }
49
50 bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
51 {
52 foreach (Entity entity in m_world.Entities.Values )
53 {
54 if( entity is Avatar )
55 {
56 avatar = entity;
57 return true;
58 }
59 }
60
61 avatar = null;
62 return false;
63 }
64
65 #endregion
66
67 #region IScriptEntity and IScriptReadonlyEntity Members
68
69 public string Name
70 {
71 get
72 {
73 return m_entity.Name;
74 }
75 }
76
77 public LLVector3 Pos
78 {
79 get
80 {
81 return m_entity.Pos;
82 }
83
84 set
85 {
86 if (m_entity is Primitive)
87 {
88 Primitive prim = m_entity as Primitive;
89 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
90 prim.UpdatePosition( value );
91 }
92 }
93 }
94
95 #endregion
96 }
97
98}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/Script.cs b/OpenSim/OpenSim.RegionServer/world/scripting/Script.cs
new file mode 100644
index 0000000..48c18ff
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/Script.cs
@@ -0,0 +1,26 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting
7{
8 public class Script
9 {
10 private LLUUID m_scriptId;
11 public virtual LLUUID ScriptId
12 {
13 get
14 {
15 return m_scriptId;
16 }
17 }
18
19 public Script( LLUUID scriptId )
20 {
21 m_scriptId = scriptId;
22 }
23
24 public ScriptEventHandler OnFrame;
25 }
26}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/ScriptFactory.cs b/OpenSim/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
new file mode 100644
index 0000000..4c6d373
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/ScriptFactory.cs
@@ -0,0 +1,8 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.RegionServer.world.scripting
6{
7 public delegate Script ScriptFactory();
8}
diff --git a/OpenSim/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..6a689ab
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,37 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5
6namespace OpenSim.RegionServer.world.scripting
7{
8 public class FollowRandomAvatar : Script
9 {
10 public FollowRandomAvatar()
11 : base(LLUUID.Random())
12 {
13 OnFrame += MyOnFrame;
14 }
15
16 private void MyOnFrame(IScriptContext context)
17 {
18 LLVector3 pos = context.Entity.Pos;
19
20 IScriptReadonlyEntity avatar;
21
22 if (context.TryGetRandomAvatar(out avatar))
23 {
24 LLVector3 avatarPos = avatar.Pos;
25
26 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
27 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
28
29 LLVector3 newPos = new LLVector3(x, y, pos.Z);
30
31 context.Entity.Pos = newPos;
32 }
33 }
34 }
35
36
37}