aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Region/Scene
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.Region/Scene')
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/Avatar.Animations.cs76
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/Avatar.Update.cs148
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/Avatar.cs225
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/Entity.cs148
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/Primitive.cs541
-rw-r--r--OpenSim/OpenSim.Region/Scene/Entities/SceneObject.cs128
-rw-r--r--OpenSim/OpenSim.Region/Scene/World.PacketHandlers.cs253
-rw-r--r--OpenSim/OpenSim.Region/Scene/World.Scripting.cs184
-rw-r--r--OpenSim/OpenSim.Region/Scene/World.cs711
-rw-r--r--OpenSim/OpenSim.Region/Scene/WorldBase.cs138
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/IScriptContext.cs40
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/IScriptEntity.cs46
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/IScriptHandler.cs125
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/Script.cs53
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/ScriptFactory.cs35
-rw-r--r--OpenSim/OpenSim.Region/Scene/scripting/Scripts/FollowRandomAvatar.cs64
16 files changed, 2915 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Animations.cs b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Animations.cs
new file mode 100644
index 0000000..5f24cd4
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Animations.cs
@@ -0,0 +1,76 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using System.Xml;
33
34namespace OpenSim.Region
35{
36 partial class Avatar
37 {
38 public class AvatarAnimations
39 {
40
41 public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>();
42 public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>();
43
44 public AvatarAnimations()
45 {
46 }
47
48 public void LoadAnims()
49 {
50 //OpenSim.Framework.Console.MainConsole.Instance.Verbose("Avatar.cs:LoadAnims() - Loading avatar animations");
51 XmlTextReader reader = new XmlTextReader("data/avataranimations.xml");
52
53 XmlDocument doc = new XmlDocument();
54 doc.Load(reader);
55 foreach (XmlNode nod in doc.DocumentElement.ChildNodes)
56 {
57
58 if (nod.Attributes["name"] != null)
59 {
60 AnimsLLUUID.Add(nod.Attributes["name"].Value, nod.InnerText);
61 }
62
63 }
64
65 reader.Close();
66
67 // OpenSim.Framework.Console.MainConsole.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)");
68
69 foreach (KeyValuePair<string, LLUUID> kp in OpenSim.Region.Avatar.Animations.AnimsLLUUID)
70 {
71 AnimsNames.Add(kp.Value, kp.Key);
72 }
73 }
74 }
75 }
76}
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Update.cs b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Update.cs
new file mode 100644
index 0000000..d373fdb
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.Update.cs
@@ -0,0 +1,148 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Physics.Manager;
34using OpenSim.Framework.Interfaces;
35
36namespace OpenSim.Region
37{
38 partial class Avatar
39 {
40 /// <summary>
41 ///
42 /// </summary>
43 public override void update()
44 {
45
46
47 }
48
49 /// <summary>
50 ///
51 /// </summary>
52 /// <param name="remoteAvatar"></param>
53 public void SendUpdateToOtherClient(Avatar remoteAvatar)
54 {
55
56 }
57
58 /// <summary>
59 ///
60 /// </summary>
61 /// <returns></returns>
62 public ObjectUpdatePacket CreateUpdatePacket()
63 {
64 return null;
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 public void SendInitialPosition()
71 {
72 this.ControllingClient.SendAvatarData(m_regionInfo, this.firstname, this.lastname, this.uuid, this.localid, new LLVector3(128, 128, 60));
73 }
74
75 /// <summary>
76 ///
77 /// </summary>
78 public void SendOurAppearance()
79 {
80
81 }
82
83 /// <summary>
84 ///
85 /// </summary>
86 /// <param name="OurClient"></param>
87 public void SendOurAppearance(IClientAPI OurClient)
88 {
89 this.ControllingClient.SendWearables(this.Wearables);
90 }
91
92 /// <summary>
93 ///
94 /// </summary>
95 /// <param name="avatarInfo"></param>
96 public void SendAppearanceToOtherAgent(Avatar avatarInfo)
97 {
98
99 }
100
101 /// <summary>
102 ///
103 /// </summary>
104 /// <param name="texture"></param>
105 /// <param name="visualParam"></param>
106 public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
107 {
108
109 }
110
111 /// <summary>
112 ///
113 /// </summary>
114 public void StopMovement()
115 {
116
117 }
118
119 /// <summary>
120 /// Very likely to be deleted soon!
121 /// </summary>
122 /// <returns></returns>
123 public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
124 {
125 return null;
126 }
127
128 /// <summary>
129 ///
130 /// </summary>
131 /// <param name="animID"></param>
132 /// <param name="seq"></param>
133 public void SendAnimPack(LLUUID animID, int seq)
134 {
135
136
137 }
138
139 /// <summary>
140 ///
141 /// </summary>
142 public void SendAnimPack()
143 {
144
145 }
146
147 }
148}
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/Avatar.cs b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.cs
new file mode 100644
index 0000000..c88e0cc
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/Avatar.cs
@@ -0,0 +1,225 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Text;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Physics.Manager;
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework.Types;
38using Axiom.MathLib;
39
40namespace OpenSim.Region
41{
42 public partial class Avatar : Entity
43 {
44 public static bool PhysicsEngineFlying = false;
45 public static AvatarAnimations Animations;
46 public string firstname;
47 public string lastname;
48 public IClientAPI ControllingClient;
49 public LLUUID current_anim;
50 public int anim_seq;
51 private static libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
52 private bool updateflag = false;
53 private byte movementflag = 0;
54 private List<NewForce> forcesList = new List<NewForce>();
55 private short _updateCount = 0;
56 private Axiom.MathLib.Quaternion bodyRot;
57 private LLObject.TextureEntry avatarAppearanceTexture = null;
58 private byte[] visualParams;
59 private AvatarWearable[] Wearables;
60 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
61 private ulong m_regionHandle;
62 private Dictionary<uint, IClientAPI> m_clientThreads;
63 private bool childAvatar = false;
64
65 protected RegionInfo m_regionInfo;
66 /// <summary>
67 ///
68 /// </summary>
69 /// <param name="theClient"></param>
70 /// <param name="world"></param>
71 /// <param name="clientThreads"></param>
72 /// <param name="regionDat"></param>
73 public Avatar(IClientAPI theClient, World world, Dictionary<uint, IClientAPI> clientThreads, RegionInfo reginfo)
74 {
75
76 m_world = world;
77 m_clientThreads = clientThreads;
78 this.uuid = theClient.AgentId;
79
80 m_regionInfo = reginfo;
81 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Avatar.cs - Loading details from grid (DUMMY)");
82 ControllingClient = theClient;
83 this.firstname = ControllingClient.FirstName;
84 this.lastname = ControllingClient.LastName;
85 localid = this.m_world.NextLocalId;
86 Pos = ControllingClient.StartPos;
87 visualParams = new byte[218];
88 for (int i = 0; i < 218; i++)
89 {
90 visualParams[i] = 100;
91 }
92
93 Wearables = AvatarWearable.DefaultWearables;
94
95 this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
96
97 //register for events
98 ControllingClient.OnRequestWearables += new GenericCall(this.SendOurAppearance);
99 //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
100 ControllingClient.OnCompleteMovementToRegion += new GenericCall2(this.CompleteMovement);
101 ControllingClient.OnCompleteMovementToRegion += new GenericCall2(this.SendInitialPosition);
102 /* ControllingClient.OnAgentUpdate += new GenericCall3(this.HandleAgentUpdate);
103 ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
104 ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
105 ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
106 */
107 }
108
109 /// <summary>
110 ///
111 /// </summary>
112 public PhysicsActor PhysActor
113 {
114 set
115 {
116 this._physActor = value;
117 }
118 get
119 {
120 return _physActor;
121 }
122 }
123
124 /// <summary>
125 ///
126 /// </summary>
127 /// <param name="status"></param>
128 public void ChildStatusChange(bool status)
129 {
130
131 }
132
133 /// <summary>
134 ///
135 /// </summary>
136 public override void addForces()
137 {
138
139 }
140
141 /// <summary>
142 /// likely to removed very soon
143 /// </summary>
144 /// <param name="name"></param>
145 public static void SetupTemplate(string name)
146 {
147
148 }
149
150 /// <summary>
151 /// likely to removed very soon
152 /// </summary>
153 /// <param name="objdata"></param>
154 protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
155 {
156
157
158
159 }
160
161 /// <summary>
162 ///
163 /// </summary>
164 public void CompleteMovement()
165 {
166 this.ControllingClient.MoveAgentIntoRegion(m_regionInfo);
167 }
168
169 /// <summary>
170 ///
171 /// </summary>
172 /// <param name="pack"></param>
173 public void HandleAgentUpdate(Packet pack)
174 {
175 this.HandleUpdate((AgentUpdatePacket)pack);
176 }
177
178 /// <summary>
179 ///
180 /// </summary>
181 /// <param name="pack"></param>
182 public void HandleUpdate(AgentUpdatePacket pack)
183 {
184
185 }
186
187 /// <summary>
188 ///
189 /// </summary>
190 public void SendRegionHandshake()
191 {
192
193 }
194
195 /// <summary>
196 ///
197 /// </summary>
198 public static void LoadAnims()
199 {
200
201 }
202
203 /// <summary>
204 ///
205 /// </summary>
206 public override void LandRenegerated()
207 {
208
209 }
210
211
212 public class NewForce
213 {
214 public float X;
215 public float Y;
216 public float Z;
217
218 public NewForce()
219 {
220
221 }
222 }
223 }
224
225}
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/Entity.cs b/OpenSim/OpenSim.Region/Scene/Entities/Entity.cs
new file mode 100644
index 0000000..3d6ba64
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/Entity.cs
@@ -0,0 +1,148 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using Axiom.MathLib;
32using OpenSim.Physics.Manager;
33using libsecondlife;
34using OpenSim.Region.Scripting;
35
36namespace OpenSim.Region
37{
38 public abstract class Entity : IScriptReadonlyEntity
39 {
40 public libsecondlife.LLUUID uuid;
41 public uint localid;
42 public LLVector3 velocity;
43 public Quaternion rotation;
44 protected List<Entity> children;
45 protected LLVector3 m_pos;
46 protected PhysicsActor _physActor;
47 protected World m_world;
48 protected string m_name;
49
50 /// <summary>
51 ///
52 /// </summary>
53 public virtual string Name
54 {
55 get { return m_name; }
56 }
57
58 /// <summary>
59 ///
60 /// </summary>
61 public virtual LLVector3 Pos
62 {
63 get
64 {
65 if (this._physActor != null)
66 {
67 m_pos.X = _physActor.Position.X;
68 m_pos.Y = _physActor.Position.Y;
69 m_pos.Z = _physActor.Position.Z;
70 }
71
72 return m_pos;
73 }
74 set
75 {
76 if (this._physActor != null)
77 {
78 try
79 {
80 lock (this.m_world.SyncRoot)
81 {
82
83 this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
84 }
85 }
86 catch (Exception e)
87 {
88 Console.WriteLine(e.Message);
89 }
90 }
91
92 m_pos = value;
93 }
94 }
95
96 /// <summary>
97 /// Creates a new Entity (should not occur on it's own)
98 /// </summary>
99 public Entity()
100 {
101 uuid = new libsecondlife.LLUUID();
102 localid = 0;
103 m_pos = new LLVector3();
104 velocity = new LLVector3();
105 rotation = new Quaternion();
106 m_name = "(basic entity)";
107 children = new List<Entity>();
108 }
109
110 /// <summary>
111 ///
112 /// </summary>
113 public virtual void addForces()
114 {
115 foreach (Entity child in children)
116 {
117 child.addForces();
118 }
119 }
120
121 /// <summary>
122 /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
123 /// </summary>
124 public virtual void update() {
125 // Do any per-frame updates needed that are applicable to every type of entity
126 foreach (Entity child in children)
127 {
128 child.update();
129 }
130 }
131
132 /// <summary>
133 /// Called at a set interval to inform entities that they should back themsleves up to the DB
134 /// </summary>
135 public virtual void BackUp()
136 {
137
138 }
139
140 /// <summary>
141 /// Infoms the entity that the land (heightmap) has changed
142 /// </summary>
143 public virtual void LandRenegerated()
144 {
145
146 }
147 }
148}
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/Primitive.cs b/OpenSim/OpenSim.Region/Scene/Entities/Primitive.cs
new file mode 100644
index 0000000..6efdd66
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/Primitive.cs
@@ -0,0 +1,541 @@
1
2/*
3* Copyright (c) Contributors, http://www.openmetaverse.org/
4* See CONTRIBUTORS.TXT for a full list of copyright holders.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the OpenSim Project nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29using System;
30using System.Collections.Generic;
31using System.Text;
32using libsecondlife;
33using libsecondlife.Packets;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Physics.Manager;
36using OpenSim.Framework.Types;
37using OpenSim.Framework.Inventory;
38
39namespace OpenSim.Region
40{
41 public class Primitive : Entity
42 {
43 internal PrimData primData;
44 private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
45 // private Dictionary<uint, IClientAPI> m_clientThreads;
46 private ulong m_regionHandle;
47 private const uint FULL_MASK_PERMISSIONS = 2147483647;
48 private bool physicsEnabled = false;
49 private byte updateFlag = 0;
50
51 private Dictionary<LLUUID, InventoryItem> inventoryItems;
52
53 #region Properties
54
55 public LLVector3 Scale
56 {
57 set
58 {
59 this.primData.Scale = value;
60 //this.dirtyFlag = true;
61 }
62 get
63 {
64 return this.primData.Scale;
65 }
66 }
67
68 public PhysicsActor PhysActor
69 {
70 set
71 {
72 this._physActor = value;
73 }
74 }
75
76 public override LLVector3 Pos
77 {
78 get
79 {
80 return base.Pos;
81 }
82 set
83 {
84 base.Pos = value;
85 }
86 }
87 #endregion
88
89 /// <summary>
90 ///
91 /// </summary>
92 /// <param name="clientThreads"></param>
93 /// <param name="regionHandle"></param>
94 /// <param name="world"></param>
95 public Primitive( ulong regionHandle, World world)
96 {
97 // m_clientThreads = clientThreads;
98 m_regionHandle = regionHandle;
99 m_world = world;
100 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
101 }
102
103 /// <summary>
104 ///
105 /// </summary>
106 /// <param name="regionHandle"></param>
107 /// <param name="world"></param>
108 /// <param name="addPacket"></param>
109 /// <param name="ownerID"></param>
110 /// <param name="localID"></param>
111 public Primitive(ulong regionHandle, World world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
112 {
113 // m_clientThreads = clientThreads;
114 m_regionHandle = regionHandle;
115 m_world = world;
116 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
117 this.CreateFromPacket(addPacket, ownerID, localID);
118 }
119
120 /// <summary>
121 ///
122 /// </summary>
123 /// <param name="clientThreads"></param>
124 /// <param name="regionHandle"></param>
125 /// <param name="world"></param>
126 /// <param name="owner"></param>
127 /// <param name="fullID"></param>
128 /// <param name="localID"></param>
129 public Primitive( ulong regionHandle, World world, LLUUID owner, LLUUID fullID, uint localID)
130 {
131 // m_clientThreads = clientThreads;
132 m_regionHandle = regionHandle;
133 m_world = world;
134 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
135 this.primData = new PrimData();
136 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
137 this.primData.OwnerID = owner;
138 this.primData.FullID = this.uuid = fullID;
139 this.primData.LocalID = this.localid = localID;
140 }
141
142 /// <summary>
143 /// Constructor to create a default cube
144 /// </summary>
145 /// <param name="clientThreads"></param>
146 /// <param name="regionHandle"></param>
147 /// <param name="world"></param>
148 /// <param name="owner"></param>
149 /// <param name="localID"></param>
150 /// <param name="position"></param>
151 public Primitive( ulong regionHandle, World world, LLUUID owner, uint localID, LLVector3 position)
152 {
153 //m_clientThreads = clientThreads;
154 m_regionHandle = regionHandle;
155 m_world = world;
156 inventoryItems = new Dictionary<LLUUID, InventoryItem>();
157 this.primData = PrimData.DefaultCube();
158 this.primData.OwnerID = owner;
159 this.primData.LocalID = this.localid = localID;
160 this.Pos = this.primData.Position = position;
161
162 this.updateFlag = 1;
163 }
164
165 /// <summary>
166 ///
167 /// </summary>
168 /// <returns></returns>
169 public byte[] GetByteArray()
170 {
171 byte[] result = null;
172 List<byte[]> dataArrays = new List<byte[]>();
173 dataArrays.Add(primData.ToBytes());
174 foreach (Entity child in children)
175 {
176 if (child is OpenSim.Region.Primitive)
177 {
178 dataArrays.Add(((OpenSim.Region.Primitive)child).GetByteArray());
179 }
180 }
181 byte[] primstart = Helpers.StringToField("<Prim>");
182 byte[] primend = Helpers.StringToField("</Prim>");
183 int totalLength = primstart.Length + primend.Length;
184 for (int i = 0; i < dataArrays.Count; i++)
185 {
186 totalLength += dataArrays[i].Length;
187 }
188
189 result = new byte[totalLength];
190 int arraypos = 0;
191 Array.Copy(primstart, 0, result, 0, primstart.Length);
192 arraypos += primstart.Length;
193 for (int i = 0; i < dataArrays.Count; i++)
194 {
195 Array.Copy(dataArrays[i], 0, result, arraypos, dataArrays[i].Length);
196 arraypos += dataArrays[i].Length;
197 }
198 Array.Copy(primend, 0, result, arraypos, primend.Length);
199
200 return result;
201 }
202
203 #region Overridden Methods
204
205 /// <summary>
206 ///
207 /// </summary>
208 public override void update()
209 {
210 if (this.updateFlag == 1) // is a new prim just been created/reloaded
211 {
212 this.SendFullUpdateToAllClients();
213 this.updateFlag = 0;
214 }
215 if (this.updateFlag == 2) //some change has been made so update the clients
216 {
217 this.SendTerseUpdateToALLClients();
218 this.updateFlag = 0;
219 }
220 }
221
222 /// <summary>
223 ///
224 /// </summary>
225 public override void BackUp()
226 {
227
228 }
229
230 #endregion
231
232 #region Packet handlers
233
234 /// <summary>
235 ///
236 /// </summary>
237 /// <param name="pos"></param>
238 public void UpdatePosition(LLVector3 pos)
239 {
240 this.Pos = new LLVector3(pos.X, pos.Y, pos.Z);
241 this.updateFlag = 2;
242 }
243
244 /// <summary>
245 ///
246 /// </summary>
247 /// <param name="addPacket"></param>
248 public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
249 {
250 this.primData.PathBegin = addPacket.PathBegin;
251 this.primData.PathEnd = addPacket.PathEnd;
252 this.primData.PathScaleX = addPacket.PathScaleX;
253 this.primData.PathScaleY = addPacket.PathScaleY;
254 this.primData.PathShearX = addPacket.PathShearX;
255 this.primData.PathShearY = addPacket.PathShearY;
256 this.primData.PathSkew = addPacket.PathSkew;
257 this.primData.ProfileBegin = addPacket.ProfileBegin;
258 this.primData.ProfileEnd = addPacket.ProfileEnd;
259 this.primData.PathCurve = addPacket.PathCurve;
260 this.primData.ProfileCurve = addPacket.ProfileCurve;
261 this.primData.ProfileHollow = addPacket.ProfileHollow;
262 this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
263 this.primData.PathRevolutions = addPacket.PathRevolutions;
264 this.primData.PathTaperX = addPacket.PathTaperX;
265 this.primData.PathTaperY = addPacket.PathTaperY;
266 this.primData.PathTwist = addPacket.PathTwist;
267 this.primData.PathTwistBegin = addPacket.PathTwistBegin;
268 }
269
270 /// <summary>
271 ///
272 /// </summary>
273 /// <param name="tex"></param>
274 public void UpdateTexture(byte[] tex)
275 {
276 this.primData.Texture = tex;
277 }
278
279 /// <summary>
280 ///
281 /// </summary>
282 /// <param name="pack"></param>
283 public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
284 {
285
286 }
287
288 /// <summary>
289 ///
290 /// </summary>
291 /// <param name="prim"></param>
292 public void AssignToParent(Primitive prim)
293 {
294
295 }
296
297 #endregion
298
299 # region Inventory Methods
300 /// <summary>
301 ///
302 /// </summary>
303 /// <param name="item"></param>
304 /// <returns></returns>
305 public bool AddToInventory(InventoryItem item)
306 {
307 return false;
308 }
309
310 /// <summary>
311 ///
312 /// </summary>
313 /// <param name="itemID"></param>
314 /// <returns></returns>
315 public InventoryItem RemoveFromInventory(LLUUID itemID)
316 {
317 return null;
318 }
319
320 /// <summary>
321 ///
322 /// </summary>
323 /// <param name="simClient"></param>
324 /// <param name="packet"></param>
325 public void RequestInventoryInfo(IClientAPI simClient, RequestTaskInventoryPacket packet)
326 {
327
328 }
329
330 /// <summary>
331 ///
332 /// </summary>
333 /// <param name="simClient"></param>
334 /// <param name="xferID"></param>
335 public void RequestXferInventory(IClientAPI simClient, ulong xferID)
336 {
337 //will only currently work if the total size of the inventory data array is under about 1000 bytes
338 SendXferPacketPacket send = new SendXferPacketPacket();
339
340 send.XferID.ID = xferID;
341 send.XferID.Packet = 1 + 2147483648;
342 send.DataPacket.Data = this.ConvertInventoryToBytes();
343
344 simClient.OutPacket(send);
345 }
346
347 /// <summary>
348 ///
349 /// </summary>
350 /// <returns></returns>
351 public byte[] ConvertInventoryToBytes()
352 {
353 System.Text.Encoding enc = System.Text.Encoding.ASCII;
354 byte[] result = new byte[0];
355 List<byte[]> inventoryData = new List<byte[]>();
356 int totallength = 0;
357 foreach (InventoryItem invItem in inventoryItems.Values)
358 {
359 byte[] data = enc.GetBytes(invItem.ExportString());
360 inventoryData.Add(data);
361 totallength += data.Length;
362 }
363 //TODO: copy arrays into the single result array
364
365 return result;
366 }
367
368 /// <summary>
369 ///
370 /// </summary>
371 /// <param name="data"></param>
372 public void CreateInventoryFromBytes(byte[] data)
373 {
374
375 }
376
377 #endregion
378
379 #region Update viewers Methods
380
381 /// <summary>
382 ///
383 /// </summary>
384 /// <param name="remoteClient"></param>
385 public void SendFullUpdateForAllChildren(IClientAPI remoteClient)
386 {
387 this.SendFullUpdateToClient(remoteClient);
388 for (int i = 0; i < this.children.Count; i++)
389 {
390 if (this.children[i] is Primitive)
391 {
392 ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient);
393 }
394 }
395 }
396
397 /// <summary>
398 ///
399 /// </summary>
400 /// <param name="remoteClient"></param>
401 public void SendFullUpdateToClient(IClientAPI remoteClient)
402 {
403 LLVector3 lPos;
404 if (this._physActor != null && this.physicsEnabled)
405 {
406 PhysicsVector pPos = this._physActor.Position;
407 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
408 }
409 else
410 {
411 lPos = this.Pos;
412 }
413
414 remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.localid, this.primData, lPos, new LLUUID("00000000-0000-0000-5005-000000000005"));
415 }
416
417 /// <summary>
418 ///
419 /// </summary>
420 public void SendFullUpdateToAllClients()
421 {
422 List<Avatar> avatars = this.m_world.RequestAvatarList();
423 for (int i = 0; i < avatars.Count; i++)
424 {
425 this.SendFullUpdateToClient(avatars[i].ControllingClient);
426 }
427 }
428
429 /// <summary>
430 ///
431 /// </summary>
432 /// <param name="RemoteClient"></param>
433 public void SendTerseUpdateToClient(IClientAPI RemoteClient)
434 {
435 LLVector3 lPos;
436 Axiom.MathLib.Quaternion lRot;
437 if (this._physActor != null && this.physicsEnabled)
438 {
439 PhysicsVector pPos = this._physActor.Position;
440 lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
441 lRot = this._physActor.Orientation;
442 }
443 else
444 {
445 lPos = this.Pos;
446 lRot = this.rotation;
447 }
448 }
449
450 /// <summary>
451 ///
452 /// </summary>
453 public void SendTerseUpdateToALLClients()
454 {
455 List<Avatar> avatars = this.m_world.RequestAvatarList();
456 for (int i = 0; i < avatars.Count; i++)
457 {
458 this.SendTerseUpdateToClient(avatars[i].ControllingClient);
459 }
460 }
461
462 #endregion
463
464 #region Create Methods
465
466 /// <summary>
467 ///
468 /// </summary>
469 /// <param name="addPacket"></param>
470 /// <param name="ownerID"></param>
471 /// <param name="localID"></param>
472 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
473 {
474 PrimData PData = new PrimData();
475 this.primData = PData;
476 this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
477
478 PData.OwnerID = ownerID;
479 PData.PCode = addPacket.ObjectData.PCode;
480 PData.PathBegin = addPacket.ObjectData.PathBegin;
481 PData.PathEnd = addPacket.ObjectData.PathEnd;
482 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
483 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
484 PData.PathShearX = addPacket.ObjectData.PathShearX;
485 PData.PathShearY = addPacket.ObjectData.PathShearY;
486 PData.PathSkew = addPacket.ObjectData.PathSkew;
487 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
488 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
489 PData.Scale = addPacket.ObjectData.Scale;
490 PData.PathCurve = addPacket.ObjectData.PathCurve;
491 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
492 PData.ParentID = 0;
493 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
494 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
495 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
496 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
497 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
498 PData.PathTwist = addPacket.ObjectData.PathTwist;
499 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
500 LLVector3 pos1 = addPacket.ObjectData.RayEnd;
501 this.primData.FullID = this.uuid = LLUUID.Random();
502 this.primData.LocalID = this.localid = (uint)(localID);
503 this.primData.Position = this.Pos = pos1;
504
505 this.updateFlag = 1;
506 }
507
508 /// <summary>
509 ///
510 /// </summary>
511 /// <param name="data"></param>
512 public void CreateFromBytes(byte[] data)
513 {
514
515 }
516
517 /// <summary>
518 ///
519 /// </summary>
520 /// <param name="primData"></param>
521 public void CreateFromPrimData(PrimData primData)
522 {
523 this.CreateFromPrimData(primData, primData.Position, primData.LocalID, false);
524 }
525
526 /// <summary>
527 ///
528 /// </summary>
529 /// <param name="primData"></param>
530 /// <param name="posi"></param>
531 /// <param name="localID"></param>
532 /// <param name="newprim"></param>
533 public void CreateFromPrimData(PrimData primData, LLVector3 posi, uint localID, bool newprim)
534 {
535
536 }
537
538 #endregion
539
540 }
541}
diff --git a/OpenSim/OpenSim.Region/Scene/Entities/SceneObject.cs b/OpenSim/OpenSim.Region/Scene/Entities/SceneObject.cs
new file mode 100644
index 0000000..7284b73
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/Entities/SceneObject.cs
@@ -0,0 +1,128 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Physics.Manager;
35using OpenSim.Framework.Types;
36using OpenSim.Framework.Inventory;
37
38namespace OpenSim.Region
39{
40 public class SceneObject : Entity
41 {
42 private LLUUID rootUUID;
43 //private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>();
44 protected Primitive rootPrimitive;
45 private World m_world;
46 protected ulong regionHandle;
47
48 /// <summary>
49 ///
50 /// </summary>
51 public SceneObject()
52 {
53
54 }
55
56 /// <summary>
57 ///
58 /// </summary>
59 /// <param name="addPacket"></param>
60 /// <param name="agentID"></param>
61 /// <param name="localID"></param>
62 public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
63 {
64 this.rootPrimitive = new Primitive( this.regionHandle, this.m_world, addPacket, agentID, localID);
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 /// <param name="data"></param>
71 public void CreateFromBytes(byte[] data)
72 {
73
74 }
75
76 /// <summary>
77 ///
78 /// </summary>
79 public override void update()
80 {
81
82 }
83
84 /// <summary>
85 ///
86 /// </summary>
87 public override void BackUp()
88 {
89
90 }
91
92 /// <summary>
93 ///
94 /// </summary>
95 /// <param name="client"></param>
96 public void GetProperites(IClientAPI client)
97 {
98 //needs changing
99 ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
100 proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
101 proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
102 proper.ObjectData[0].ItemID = LLUUID.Zero;
103 proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.primData.CreationDate;
104 proper.ObjectData[0].CreatorID = this.rootPrimitive.primData.OwnerID;
105 proper.ObjectData[0].FolderID = LLUUID.Zero;
106 proper.ObjectData[0].FromTaskID = LLUUID.Zero;
107 proper.ObjectData[0].GroupID = LLUUID.Zero;
108 proper.ObjectData[0].InventorySerial = 0;
109 proper.ObjectData[0].LastOwnerID = LLUUID.Zero;
110 proper.ObjectData[0].ObjectID = this.uuid;
111 proper.ObjectData[0].OwnerID = this.rootPrimitive.primData.OwnerID;
112 proper.ObjectData[0].TouchName = new byte[0];
113 proper.ObjectData[0].TextureID = new byte[0];
114 proper.ObjectData[0].SitName = new byte[0];
115 proper.ObjectData[0].Name = new byte[0];
116 proper.ObjectData[0].Description = new byte[0];
117 proper.ObjectData[0].OwnerMask = this.rootPrimitive.primData.OwnerMask;
118 proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.primData.NextOwnerMask;
119 proper.ObjectData[0].GroupMask = this.rootPrimitive.primData.GroupMask;
120 proper.ObjectData[0].EveryoneMask = this.rootPrimitive.primData.EveryoneMask;
121 proper.ObjectData[0].BaseMask = this.rootPrimitive.primData.BaseMask;
122
123 client.OutPacket(proper);
124
125 }
126
127 }
128}
diff --git a/OpenSim/OpenSim.Region/Scene/World.PacketHandlers.cs b/OpenSim/OpenSim.Region/Scene/World.PacketHandlers.cs
new file mode 100644
index 0000000..85ca247
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/World.PacketHandlers.cs
@@ -0,0 +1,253 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using libsecondlife.Packets;
33using OpenSim.Physics.Manager;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using OpenSim.Framework.Inventory;
37using OpenSim.Framework.Utilities;
38
39namespace OpenSim.Region
40{
41 public partial class World
42 {
43 /// <summary>
44 ///
45 /// </summary>
46 /// <param name="action"></param>
47 /// <param name="north"></param>
48 /// <param name="west"></param>
49 public void ModifyTerrain(byte action, float north, float west)
50 {
51 switch (action)
52 {
53 case 1:
54 // raise terrain
55 Terrain.raise(north, west, 10.0, 0.001);
56 RegenerateTerrain(true, (int)north, (int)west);
57 break;
58 case 2:
59 //lower terrain
60 Terrain.lower(north, west, 10.0, 0.001);
61 RegenerateTerrain(true, (int)north, (int)west);
62 break;
63 }
64 return;
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 /// <param name="message"></param>
71 /// <param name="type"></param>
72 /// <param name="fromPos"></param>
73 /// <param name="fromName"></param>
74 /// <param name="fromAgentID"></param>
75 public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
76 {
77 Console.WriteLine("Chat message");
78 Avatar avatar = null;
79 foreach (IClientAPI client in m_clientThreads.Values)
80 {
81 int dis = -1000;
82 if (this.Avatars.ContainsKey(client.AgentId))
83 {
84
85 avatar = this.Avatars[client.AgentId];
86 // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
87 dis= (int)avatar.Pos.GetDistanceTo(fromPos);
88 Console.WriteLine("found avatar at " +dis);
89
90 }
91
92 switch (type)
93 {
94 case 0: // Whisper
95 if ((dis < 10) && (dis > -10))
96 {
97 //should change so the message is sent through the avatar rather than direct to the ClientView
98 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
99 }
100 break;
101 case 1: // Say
102 if ((dis < 30) && (dis > -30))
103 {
104 Console.WriteLine("sending chat");
105 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
106 }
107 break;
108 case 2: // Shout
109 if ((dis < 100) && (dis > -100))
110 {
111 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
112 }
113 break;
114
115 case 0xff: // Broadcast
116 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
117 break;
118 }
119
120 }
121 }
122
123 /// <summary>
124 ///
125 /// </summary>
126 /// <param name="primAsset"></param>
127 /// <param name="pos"></param>
128 public void RezObject(AssetBase primAsset, LLVector3 pos)
129 {
130
131 }
132
133 /// <summary>
134 ///
135 /// </summary>
136 /// <param name="packet"></param>
137 /// <param name="simClient"></param>
138 public void DeRezObject(Packet packet, IClientAPI simClient)
139 {
140
141 }
142
143 /// <summary>
144 ///
145 /// </summary>
146 /// <param name="remoteClient"></param>
147 public void SendAvatarsToClient(IClientAPI remoteClient)
148 {
149
150 }
151
152 /// <summary>
153 ///
154 /// </summary>
155 /// <param name="parentPrim"></param>
156 /// <param name="childPrims"></param>
157 public void LinkObjects(uint parentPrim, List<uint> childPrims)
158 {
159
160
161 }
162
163 /// <summary>
164 ///
165 /// </summary>
166 /// <param name="primLocalID"></param>
167 /// <param name="shapeBlock"></param>
168 public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
169 {
170
171 }
172
173 /// <summary>
174 ///
175 /// </summary>
176 /// <param name="primLocalID"></param>
177 /// <param name="remoteClient"></param>
178 public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
179 {
180
181 }
182
183 /// <summary>
184 ///
185 /// </summary>
186 /// <param name="localID"></param>
187 /// <param name="packet"></param>
188 /// <param name="remoteClient"></param>
189 public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
190 {
191
192 }
193
194 /// <summary>
195 ///
196 /// </summary>
197 /// <param name="localID"></param>
198 /// <param name="texture"></param>
199 /// <param name="remoteClient"></param>
200 public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
201 {
202
203 }
204
205 /// <summary>
206 ///
207 /// </summary>
208 /// <param name="localID"></param>
209 /// <param name="pos"></param>
210 /// <param name="remoteClient"></param>
211 public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
212 {
213 foreach (Entity ent in Entities.Values)
214 {
215 if (ent.localid == localID)
216 {
217 ((OpenSim.Region.Primitive)ent).UpdatePosition(pos);
218 break;
219 }
220 }
221 }
222
223 /// <summary>
224 ///
225 /// </summary>
226 /// <param name="localID"></param>
227 /// <param name="rot"></param>
228 /// <param name="remoteClient"></param>
229 public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
230 {
231
232 }
233
234 /// <summary>
235 ///
236 /// </summary>
237 /// <param name="localID"></param>
238 /// <param name="scale"></param>
239 /// <param name="remoteClient"></param>
240 public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
241 {
242 }
243
244 /// <summary>
245 /// Sends prims to a client
246 /// </summary>
247 /// <param name="RemoteClient">Client to send to</param>
248 public void GetInitialPrims(IClientAPI RemoteClient)
249 {
250
251 }
252 }
253}
diff --git a/OpenSim/OpenSim.Region/Scene/World.Scripting.cs b/OpenSim/OpenSim.Region/Scene/World.Scripting.cs
new file mode 100644
index 0000000..e4b5d02
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/World.Scripting.cs
@@ -0,0 +1,184 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.IO;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Types;
36using libsecondlife;
37
38namespace OpenSim.Region
39{
40 public partial class World
41 {
42 private Dictionary<string, IScriptEngine> scriptEngines = new Dictionary<string, IScriptEngine>();
43
44 /// <summary>
45 ///
46 /// </summary>
47 private void LoadScriptEngines()
48 {
49 this.LoadScriptPlugins();
50 }
51
52 /// <summary>
53 ///
54 /// </summary>
55 public void LoadScriptPlugins()
56 {
57 string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines");
58 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
59
60
61 for (int i = 0; i < pluginFiles.Length; i++)
62 {
63 this.AddPlugin(pluginFiles[i]);
64 }
65 }
66
67 /// <summary>
68 ///
69 /// </summary>
70 /// <param name="FileName"></param>
71 private void AddPlugin(string FileName)
72 {
73 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
74
75 foreach (Type pluginType in pluginAssembly.GetTypes())
76 {
77 if (pluginType.IsPublic)
78 {
79 if (!pluginType.IsAbstract)
80 {
81 Type typeInterface = pluginType.GetInterface("IScriptEngine", true);
82
83 if (typeInterface != null)
84 {
85 IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
86 plug.Init(this);
87 this.scriptEngines.Add(plug.GetName(), plug);
88
89 }
90
91 typeInterface = null;
92 }
93 }
94 }
95
96 pluginAssembly = null;
97 }
98
99 /// <summary>
100 ///
101 /// </summary>
102 /// <param name="scriptType"></param>
103 /// <param name="scriptName"></param>
104 /// <param name="script"></param>
105 /// <param name="ent"></param>
106 public void LoadScript(string scriptType, string scriptName, string script, Entity ent)
107 {
108 if(this.scriptEngines.ContainsKey(scriptType))
109 {
110 this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid);
111 }
112 }
113
114 #region IScriptAPI Methods
115
116 /// <summary>
117 ///
118 /// </summary>
119 /// <param name="localID"></param>
120 /// <returns></returns>
121 public LLVector3 GetEntityPosition(uint localID)
122 {
123 LLVector3 res = new LLVector3();
124 // Console.WriteLine("script- getting entity " + localID + " position");
125 foreach (Entity entity in this.Entities.Values)
126 {
127 if (entity.localid == localID)
128 {
129 res.X = entity.Pos.X;
130 res.Y = entity.Pos.Y;
131 res.Z = entity.Pos.Z;
132 }
133 }
134 return res;
135 }
136
137 /// <summary>
138 ///
139 /// </summary>
140 /// <param name="localID"></param>
141 /// <param name="x"></param>
142 /// <param name="y"></param>
143 /// <param name="z"></param>
144 public void SetEntityPosition(uint localID, float x , float y, float z)
145 {
146 foreach (Entity entity in this.Entities.Values)
147 {
148 if (entity.localid == localID && entity is Primitive)
149 {
150 LLVector3 pos = entity.Pos;
151 pos.X = x;
152 pos.Y = y;
153 Primitive prim = entity as Primitive;
154 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
155 //prim.UpdatePosition(pos);
156 // Console.WriteLine("script- setting entity " + localID + " positon");
157 }
158 }
159
160 }
161
162 /// <summary>
163 ///
164 /// </summary>
165 /// <returns></returns>
166 public uint GetRandomAvatarID()
167 {
168 //Console.WriteLine("script- getting random avatar id");
169 uint res = 0;
170 foreach (Entity entity in this.Entities.Values)
171 {
172 if (entity is Avatar)
173 {
174 res = entity.localid;
175 }
176 }
177 return res;
178 }
179
180 #endregion
181
182
183 }
184}
diff --git a/OpenSim/OpenSim.Region/Scene/World.cs b/OpenSim/OpenSim.Region/Scene/World.cs
new file mode 100644
index 0000000..40eb7ef
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/World.cs
@@ -0,0 +1,711 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using libsecondlife;
30using libsecondlife.Packets;
31using System.Collections.Generic;
32using System.Text;
33using System.Reflection;
34using System.IO;
35using System.Threading;
36using System.Timers;
37using OpenSim.Physics.Manager;
38using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Types;
40using OpenSim.Framework.Inventory;
41using OpenSim.Framework;
42using OpenSim.Region.Scripting;
43using OpenSim.Terrain;
44using OpenGrid.Framework.Communications;
45using OpenSim.Region.Estate;
46
47
48namespace OpenSim.Region
49{
50 public delegate bool FilterAvatarList(Avatar avatar);
51
52 public partial class World : WorldBase, ILocalStorageReceiver, IScriptAPI
53 {
54 protected System.Timers.Timer m_heartbeatTimer = new System.Timers.Timer();
55 protected Dictionary<libsecondlife.LLUUID, Avatar> Avatars;
56 protected Dictionary<libsecondlife.LLUUID, Primitive> Prims;
57 private PhysicsScene phyScene;
58 private float timeStep = 0.1f;
59 public ILocalStorage localStorage;
60 private Random Rand = new Random();
61 private uint _primCount = 702000;
62 private int storageCount;
63 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
64 private Dictionary<string, ScriptFactory> m_scripts;
65 private Mutex updateLock;
66 public string m_datastore;
67 protected AuthenticateSessionsBase authenticateHandler;
68 protected RegionCommsHostBase regionCommsHost;
69 protected RegionServerCommsManager commsManager;
70
71 public ParcelManager parcelManager;
72 public EstateManager estateManager;
73
74 #region Properties
75 /// <summary>
76 ///
77 /// </summary>
78 public PhysicsScene PhysScene
79 {
80 set
81 {
82 this.phyScene = value;
83 }
84 get
85 {
86 return (this.phyScene);
87 }
88 }
89
90 #endregion
91
92 #region Constructors
93 /// <summary>
94 /// Creates a new World class, and a region to go with it.
95 /// </summary>
96 /// <param name="clientThreads">Dictionary to contain client threads</param>
97 /// <param name="regionHandle">Region Handle for this region</param>
98 /// <param name="regionName">Region Name for this region</param>
99 public World(Dictionary<uint, IClientAPI> clientThreads, RegionInfo regInfo, AuthenticateSessionsBase authen, RegionServerCommsManager commsMan)
100 {
101 try
102 {
103 updateLock = new Mutex(false);
104 this.authenticateHandler = authen;
105 this.commsManager = commsMan;
106 m_clientThreads = clientThreads;
107 m_regInfo = regInfo;
108 m_regionHandle = m_regInfo.RegionHandle;
109 m_regionName = m_regInfo.RegionName;
110 this.m_datastore = m_regInfo.DataStore;
111 this.RegisterRegionWithComms();
112
113 parcelManager = new ParcelManager(this, this.m_regInfo);
114 estateManager = new EstateManager(this, this.m_regInfo);
115
116 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
117 m_scripts = new Dictionary<string, ScriptFactory>();
118
119 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating new entitities instance");
120 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
121 Avatars = new Dictionary<LLUUID, Avatar>();
122 Prims = new Dictionary<LLUUID, Primitive>();
123
124 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs - creating LandMap");
125 TerrainManager = new TerrainManager(new SecondLife());
126 Terrain = new TerrainEngine();
127 Avatar.SetupTemplate("avatar-texture.dat");
128
129 Avatar.LoadAnims();
130
131 //this.SetDefaultScripts();
132 //this.LoadScriptEngines();
133
134
135 }
136 catch (Exception e)
137 {
138 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.CRITICAL, "World.cs: Constructor failed with exception " + e.ToString());
139 }
140 }
141 #endregion
142
143 /// <summary>
144 ///
145 /// </summary>
146 public void StartTimer()
147 {
148 m_heartbeatTimer.Enabled = true;
149 m_heartbeatTimer.Interval = 100;
150 m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
151 }
152
153
154 #region Update Methods
155
156
157 /// <summary>
158 /// Performs per-frame updates regularly
159 /// </summary>
160 /// <param name="sender"></param>
161 /// <param name="e"></param>
162 void Heartbeat(object sender, System.EventArgs e)
163 {
164 this.Update();
165 }
166
167 /// <summary>
168 /// Performs per-frame updates on the world, this should be the central world loop
169 /// </summary>
170 public override void Update()
171 {
172 updateLock.WaitOne();
173 try
174 {
175 if (this.phyScene.IsThreaded)
176 {
177 this.phyScene.GetResults();
178
179 }
180
181 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
182 {
183 Entities[UUID].addForces();
184 }
185
186 lock (this.m_syncRoot)
187 {
188 this.phyScene.Simulate(timeStep);
189 }
190
191 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
192 {
193 Entities[UUID].update();
194 }
195
196 foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
197 {
198 scriptHandler.OnFrame();
199 }
200 foreach (IScriptEngine scripteng in this.scriptEngines.Values)
201 {
202 scripteng.OnFrame();
203 }
204 //backup world data
205 this.storageCount++;
206 if (storageCount > 1200) //set to how often you want to backup
207 {
208 this.Backup();
209 storageCount = 0;
210 }
211 }
212 catch (Exception e)
213 {
214 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: Update() - Failed with exception " + e.ToString());
215 }
216 updateLock.ReleaseMutex();
217 }
218
219 /// <summary>
220 ///
221 /// </summary>
222 /// <returns></returns>
223 public bool Backup()
224 {
225 try
226 {
227 // Terrain backup routines
228 if (Terrain.tainted > 0)
229 {
230 Terrain.tainted = 0;
231 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain tainted, saving.");
232 localStorage.SaveMap(Terrain.getHeights1D());
233 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Terrain saved, informing Physics.");
234 lock (this.m_syncRoot)
235 {
236 phyScene.SetTerrain(Terrain.getHeights1D());
237 }
238 }
239
240 // Primitive backup routines
241 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: Backup() - Backing up Primitives");
242 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
243 {
244 Entities[UUID].BackUp();
245 }
246
247 //Parcel backup routines
248 ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count];
249 int i = 0;
250 foreach (OpenSim.Region.Parcel parcel in parcelManager.parcelList.Values)
251 {
252 parcels[i] = parcel.parcelData;
253 i++;
254 }
255 localStorage.SaveParcels(parcels);
256
257 // Backup successful
258 return true;
259 }
260 catch (Exception e)
261 {
262 // Backup failed
263 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Backup() - Backup Failed with exception " + e.ToString());
264 return false;
265 }
266 }
267 #endregion
268
269 #region Setup Methods
270 /// <summary>
271 /// Loads a new storage subsystem from a named library
272 /// </summary>
273 /// <param name="dllName">Storage Library</param>
274 /// <returns>Successful or not</returns>
275 public bool LoadStorageDLL(string dllName)
276 {
277 try
278 {
279 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
280 ILocalStorage store = null;
281
282 foreach (Type pluginType in pluginAssembly.GetTypes())
283 {
284 if (pluginType.IsPublic)
285 {
286 if (!pluginType.IsAbstract)
287 {
288 Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
289
290 if (typeInterface != null)
291 {
292 ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
293 store = plug;
294
295 store.Initialise(this.m_datastore);
296 break;
297 }
298
299 typeInterface = null;
300 }
301 }
302 }
303 pluginAssembly = null;
304 this.localStorage = store;
305 return (store == null);
306 }
307 catch (Exception e)
308 {
309 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
310 return false;
311 }
312 }
313
314 #endregion
315
316
317 #region Regenerate Terrain
318
319 /// <summary>
320 /// Rebuilds the terrain using a procedural algorithm
321 /// </summary>
322 public void RegenerateTerrain()
323 {
324 try
325 {
326 Terrain.hills();
327
328 lock (this.m_syncRoot)
329 {
330 this.phyScene.SetTerrain(Terrain.getHeights1D());
331 }
332 this.localStorage.SaveMap(this.Terrain.getHeights1D());
333
334 foreach (IClientAPI client in m_clientThreads.Values)
335 {
336 this.SendLayerData(client);
337 }
338
339 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
340 {
341 Entities[UUID].LandRenegerated();
342 }
343 }
344 catch (Exception e)
345 {
346 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
347 }
348 }
349
350 /// <summary>
351 /// Rebuilds the terrain using a 2D float array
352 /// </summary>
353 /// <param name="newMap">256,256 float array containing heights</param>
354 public void RegenerateTerrain(float[,] newMap)
355 {
356 try
357 {
358 this.Terrain.setHeights2D(newMap);
359 lock (this.m_syncRoot)
360 {
361 this.phyScene.SetTerrain(this.Terrain.getHeights1D());
362 }
363 this.localStorage.SaveMap(this.Terrain.getHeights1D());
364
365 foreach (IClientAPI client in m_clientThreads.Values)
366 {
367 this.SendLayerData(client);
368 }
369
370 foreach (libsecondlife.LLUUID UUID in Entities.Keys)
371 {
372 Entities[UUID].LandRenegerated();
373 }
374 }
375 catch (Exception e)
376 {
377 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
378 }
379 }
380
381 /// <summary>
382 /// Rebuilds the terrain assuming changes occured at a specified point[?]
383 /// </summary>
384 /// <param name="changes">???</param>
385 /// <param name="pointx">???</param>
386 /// <param name="pointy">???</param>
387 public void RegenerateTerrain(bool changes, int pointx, int pointy)
388 {
389 try
390 {
391 if (changes)
392 {
393 /* Dont save here, rely on tainting system instead */
394
395 foreach (IClientAPI client in m_clientThreads.Values)
396 {
397 this.SendLayerData(pointx, pointy, client);
398 }
399 }
400 }
401 catch (Exception e)
402 {
403 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
404 }
405 }
406
407 #endregion
408
409 #region Load Terrain
410 /// <summary>
411 /// Loads the World heightmap
412 /// </summary>
413 public override void LoadWorldMap()
414 {
415 try
416 {
417 float[] map = this.localStorage.LoadWorld();
418 if (map == null)
419 {
420 Console.WriteLine("creating new terrain");
421 this.Terrain.hills();
422
423 this.localStorage.SaveMap(this.Terrain.getHeights1D());
424 }
425 else
426 {
427 this.Terrain.setHeights1D(map);
428 }
429 }
430 catch (Exception e)
431 {
432 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
433 }
434 }
435 #endregion
436
437 #region Primitives Methods
438
439
440 /// <summary>
441 /// Loads the World's objects
442 /// </summary>
443 public void LoadPrimsFromStorage()
444 {
445 try
446 {
447 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs: LoadPrimsFromStorage() - Loading primitives");
448 this.localStorage.LoadPrimitives(this);
449 }
450 catch (Exception e)
451 {
452 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
453 }
454 }
455
456 /// <summary>
457 /// Loads a specific object from storage
458 /// </summary>
459 /// <param name="prim">The object to load</param>
460 public void PrimFromStorage(PrimData prim)
461 {
462
463 }
464
465 /// <summary>
466 ///
467 /// </summary>
468 /// <param name="addPacket"></param>
469 /// <param name="agentClient"></param>
470 public void AddNewPrim(Packet addPacket, IClientAPI agentClient)
471 {
472 AddNewPrim((ObjectAddPacket)addPacket, agentClient.AgentId);
473 }
474
475 /// <summary>
476 ///
477 /// </summary>
478 /// <param name="addPacket"></param>
479 /// <param name="ownerID"></param>
480 public void AddNewPrim(ObjectAddPacket addPacket, LLUUID ownerID)
481 {
482 try
483 {
484 // MainConsole.Instance.Notice("World.cs: AddNewPrim() - Creating new prim");
485 Primitive prim = new Primitive(m_regionHandle, this, addPacket, ownerID, this._primCount);
486
487 this.Entities.Add(prim.uuid, prim);
488 this._primCount++;
489 }
490 catch (Exception e)
491 {
492 // MainConsole.Instance.Warn("World.cs: AddNewPrim() - Failed with exception " + e.ToString());
493 }
494 }
495
496 #endregion
497
498 #region Add/Remove Avatar Methods
499
500 /// <summary>
501 ///
502 /// </summary>
503 /// <param name="remoteClient"></param
504 /// <param name="agentID"></param>
505 /// <param name="child"></param>
506 public override void AddNewAvatar(IClientAPI remoteClient, LLUUID agentID, bool child)
507 {
508 remoteClient.OnRegionHandShakeReply += new GenericCall(this.SendLayerData);
509 //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
510 remoteClient.OnChatFromViewer += new ChatFromViewer(this.SimChat);
511 remoteClient.OnRequestWearables += new GenericCall(this.InformClientOfNeighbours);
512 remoteClient.OnAddPrim += new GenericCall4(this.AddNewPrim);
513 remoteClient.OnUpdatePrimPosition += new UpdatePrimVector(this.UpdatePrimPosition);
514
515 /* remoteClient.OnParcelPropertiesRequest += new ParcelPropertiesRequest(parcelManager.handleParcelPropertiesRequest);
516 remoteClient.OnParcelDivideRequest += new ParcelDivideRequest(parcelManager.handleParcelDivideRequest);
517 remoteClient.OnParcelJoinRequest += new ParcelJoinRequest(parcelManager.handleParcelJoinRequest);
518 remoteClient.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(parcelManager.handleParcelPropertiesUpdateRequest);
519 remoteClient.OnEstateOwnerMessage += new EstateOwnerMessageRequest(estateManager.handleEstateOwnerMessage);
520 */
521
522 Avatar newAvatar = null;
523 try
524 {
525 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
526 newAvatar = new Avatar(remoteClient, this, m_clientThreads, this.m_regInfo);
527 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Adding new avatar to world");
528 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "World.cs:AddViewerAgent() - Starting RegionHandshake ");
529
530 //newAvatar.SendRegionHandshake();
531 this.estateManager.sendRegionHandshake(remoteClient);
532
533 PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
534 lock (this.m_syncRoot)
535 {
536 newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
537 }
538
539 lock (Entities)
540 {
541 if (!Entities.ContainsKey(agentID))
542 {
543 this.Entities.Add(agentID, newAvatar);
544 }
545 else
546 {
547 Entities[agentID] = newAvatar;
548 }
549 }
550 lock (Avatars)
551 {
552 if (Avatars.ContainsKey(agentID))
553 {
554 Avatars[agentID] = newAvatar;
555 }
556 else
557 {
558 this.Avatars.Add(agentID, newAvatar);
559 }
560 }
561 }
562 catch (Exception e)
563 {
564 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "World.cs: AddViewerAgent() - Failed with exception " + e.ToString());
565 }
566 return;
567 }
568
569 /// <summary>
570 ///
571 /// </summary>
572 protected void InformClientOfNeighbours(IClientAPI remoteClient)
573 {
574 // Console.WriteLine("informing client of neighbouring regions");
575 List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo);
576
577 //Console.WriteLine("we have " + neighbours.Count + " neighbouring regions");
578 if (neighbours != null)
579 {
580 for (int i = 0; i < neighbours.Count; i++)
581 {
582 // Console.WriteLine("sending neighbours data");
583 AgentCircuitData agent = remoteClient.RequestClientInfo();
584 agent.BaseFolder = LLUUID.Zero;
585 agent.InventoryFolder = LLUUID.Zero;
586 agent.startpos = new LLVector3(128, 128, 70);
587 this.commsManager.InterSims.InformNeighbourOfChildAgent(neighbours[i].RegionHandle, agent);
588 remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, System.Net.IPAddress.Parse(neighbours[i].IPListenAddr), (ushort)neighbours[i].IPListenPort);
589 }
590 }
591 }
592
593 /// <summary>
594 ///
595 /// </summary>
596 /// <param name="agentID"></param>
597 public override void RemoveAvatar(LLUUID agentID)
598 {
599 return;
600 }
601 #endregion
602
603 #region Request Avatars List Methods
604 //The idea is to have a group of method that return a list of avatars meeting some requirement
605 // ie it could be all Avatars within a certain range of the calling prim/avatar.
606
607 /// <summary>
608 /// Request a List of all Avatars in this World
609 /// </summary>
610 /// <returns></returns>
611 public List<Avatar> RequestAvatarList()
612 {
613 List<Avatar> result = new List<Avatar>();
614
615 foreach (Avatar avatar in Avatars.Values)
616 {
617 result.Add(avatar);
618 }
619
620 return result;
621 }
622
623 /// <summary>
624 /// Request a filtered list of Avatars in this World
625 /// </summary>
626 /// <returns></returns>
627 public List<Avatar> RequestAvatarList(FilterAvatarList filter)
628 {
629 List<Avatar> result = new List<Avatar>();
630
631 foreach (Avatar avatar in Avatars.Values)
632 {
633 if (filter(avatar))
634 {
635 result.Add(avatar);
636 }
637 }
638
639 return result;
640 }
641
642 public Avatar RequestAvatar(LLUUID avatarID)
643 {
644 if (this.Avatars.ContainsKey(avatarID))
645 {
646 return Avatars[avatarID];
647 }
648 return null;
649 }
650 #endregion
651
652 #region ShutDown
653 /// <summary>
654 /// Tidy before shutdown
655 /// </summary>
656 public override void Close()
657 {
658 try
659 {
660 this.localStorage.ShutDown();
661 }
662 catch (Exception e)
663 {
664 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString());
665 }
666 }
667 #endregion
668
669 #region RegionCommsHost
670
671 /// <summary>
672 ///
673 /// </summary>
674 public void RegisterRegionWithComms()
675 {
676 this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo);
677 if (this.regionCommsHost != null)
678 {
679 this.regionCommsHost.OnExpectUser += new ExpectUserDelegate(this.NewUserConnection);
680 }
681 }
682
683 /// <summary>
684 ///
685 /// </summary>
686 /// <param name="regionHandle"></param>
687 /// <param name="agent"></param>
688 public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
689 {
690 // Console.WriteLine("World.cs - add new user connection");
691 //should just check that its meant for this region
692 if (regionHandle == this.m_regInfo.RegionHandle)
693 {
694 this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
695 }
696 }
697
698 #endregion
699
700 /// <summary>
701 ///
702 /// </summary>
703 /// <param name="px"></param>
704 /// <param name="py"></param>
705 /// <param name="RemoteClient"></param>
706 public override void SendLayerData(int px, int py, IClientAPI RemoteClient)
707 {
708 RemoteClient.SendLayerData( Terrain.getHeights1D() );
709 }
710 }
711}
diff --git a/OpenSim/OpenSim.Region/Scene/WorldBase.cs b/OpenSim/OpenSim.Region/Scene/WorldBase.cs
new file mode 100644
index 0000000..d77d2cf
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/WorldBase.cs
@@ -0,0 +1,138 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using libsecondlife;
30using libsecondlife.Packets;
31using System.Collections.Generic;
32using System.Text;
33using System.Reflection;
34using System.IO;
35using System.Threading;
36using OpenSim.Physics.Manager;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Types;
39using OpenSim.Framework.Inventory;
40using OpenSim.Region.Scripting;
41using OpenSim.Terrain;
42
43namespace OpenSim.Region
44{
45 public abstract class WorldBase : IWorld
46 {
47 public Dictionary<libsecondlife.LLUUID, Entity> Entities;
48 protected Dictionary<uint, IClientAPI> m_clientThreads;
49 protected ulong m_regionHandle;
50 protected string m_regionName;
51 protected RegionInfo m_regInfo;
52
53 public TerrainEngine Terrain; //TODO: Replace TerrainManager with this.
54 protected libsecondlife.TerrainManager TerrainManager; // To be referenced via TerrainEngine
55 protected object m_syncRoot = new object();
56 private uint m_nextLocalId = 8880000;
57
58 #region Update Methods
59 /// <summary>
60 /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
61 /// </summary>
62 public abstract void Update();
63
64 #endregion
65
66 #region Terrain Methods
67
68 /// <summary>
69 /// Loads the World heightmap
70 /// </summary>
71 public abstract void LoadWorldMap();
72
73 /// <summary>
74 /// Send the region heightmap to the client
75 /// </summary>
76 /// <param name="RemoteClient">Client to send to</param>
77 public virtual void SendLayerData(IClientAPI RemoteClient)
78 {
79 RemoteClient.SendLayerData(Terrain.getHeights1D());
80 }
81
82 /// <summary>
83 /// Sends a specified patch to a client
84 /// </summary>
85 /// <param name="px">Patch coordinate (x) 0..16</param>
86 /// <param name="py">Patch coordinate (y) 0..16</param>
87 /// <param name="RemoteClient">The client to send to</param>
88 public abstract void SendLayerData(int px, int py, IClientAPI RemoteClient);
89
90 #endregion
91
92 #region Add/Remove Agent/Avatar
93 /// <summary>
94 ///
95 /// </summary>
96 /// <param name="remoteClient"></param>
97 /// <param name="agentID"></param>
98 /// <param name="child"></param>
99 public abstract void AddNewAvatar(IClientAPI remoteClient, LLUUID agentID, bool child);
100
101 /// <summary>
102 ///
103 /// </summary>
104 /// <param name="agentID"></param>
105 public abstract void RemoveAvatar(LLUUID agentID);
106
107 #endregion
108
109 /// <summary>
110 ///
111 /// </summary>
112 /// <returns></returns>
113 public virtual RegionInfo RegionInfo
114 {
115 get { return null; }
116 }
117
118 public object SyncRoot
119 {
120 get { return m_syncRoot; }
121 }
122
123 public uint NextLocalId
124 {
125 get { return m_nextLocalId++; }
126 }
127
128 #region Shutdown
129 /// <summary>
130 /// Tidy before shutdown
131 /// </summary>
132 public abstract void Close();
133
134 #endregion
135
136
137 }
138}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/IScriptContext.cs b/OpenSim/OpenSim.Region/Scene/scripting/IScriptContext.cs
new file mode 100644
index 0000000..daa1b92
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/IScriptContext.cs
@@ -0,0 +1,40 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Scripting
34{
35 public interface IScriptContext
36 {
37 IScriptEntity Entity { get; }
38 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
39 }
40}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/IScriptEntity.cs b/OpenSim/OpenSim.Region/Scene/scripting/IScriptEntity.cs
new file mode 100644
index 0000000..44b886f
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/IScriptEntity.cs
@@ -0,0 +1,46 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Scripting
34{
35 public interface IScriptReadonlyEntity
36 {
37 LLVector3 Pos { get; }
38 string Name { get; }
39 }
40
41 public interface IScriptEntity
42 {
43 LLVector3 Pos { get; set; }
44 string Name { get; }
45 }
46}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/IScriptHandler.cs b/OpenSim/OpenSim.Region/Scene/scripting/IScriptHandler.cs
new file mode 100644
index 0000000..f1a236f
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/IScriptHandler.cs
@@ -0,0 +1,125 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using OpenSim.Physics.Manager;
33using OpenSim.Region;
34using Avatar=OpenSim.Region.Avatar;
35using Primitive = OpenSim.Region.Primitive;
36
37namespace OpenSim.Region.Scripting
38{
39 public delegate void ScriptEventHandler(IScriptContext context);
40
41 public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
42 {
43 private World m_world;
44 private Script m_script;
45 private Entity m_entity;
46
47 public LLUUID ScriptId
48 {
49 get
50 {
51 return m_script.ScriptId;
52 }
53 }
54
55 public void OnFrame()
56 {
57 m_script.OnFrame(this);
58 }
59
60 public ScriptHandler(Script script, Entity entity, World world)
61 {
62 m_script = script;
63 m_entity = entity;
64 m_world = world;
65 }
66
67 #region IScriptContext Members
68
69 IScriptEntity IScriptContext.Entity
70 {
71 get
72 {
73 return this;
74 }
75 }
76
77 bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
78 {
79 foreach (Entity entity in m_world.Entities.Values )
80 {
81 if( entity is Avatar )
82 {
83 avatar = entity;
84 return true;
85 }
86 }
87
88 avatar = null;
89 return false;
90 }
91
92 #endregion
93
94 #region IScriptEntity and IScriptReadonlyEntity Members
95
96 public string Name
97 {
98 get
99 {
100 return m_entity.Name;
101 }
102 }
103
104 public LLVector3 Pos
105 {
106 get
107 {
108 return m_entity.Pos;
109 }
110
111 set
112 {
113 if (m_entity is Primitive)
114 {
115 Primitive prim = m_entity as Primitive;
116 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
117 // prim.UpdatePosition( value );
118 }
119 }
120 }
121
122 #endregion
123 }
124
125}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/Script.cs b/OpenSim/OpenSim.Region/Scene/scripting/Script.cs
new file mode 100644
index 0000000..1d01f3c
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/Script.cs
@@ -0,0 +1,53 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Scripting
34{
35 public class Script
36 {
37 private LLUUID m_scriptId;
38 public virtual LLUUID ScriptId
39 {
40 get
41 {
42 return m_scriptId;
43 }
44 }
45
46 public Script( LLUUID scriptId )
47 {
48 m_scriptId = scriptId;
49 }
50
51 public ScriptEventHandler OnFrame;
52 }
53}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/ScriptFactory.cs b/OpenSim/OpenSim.Region/Scene/scripting/ScriptFactory.cs
new file mode 100644
index 0000000..32ef046
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/ScriptFactory.cs
@@ -0,0 +1,35 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting
33{
34 public delegate Script ScriptFactory();
35}
diff --git a/OpenSim/OpenSim.Region/Scene/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/OpenSim.Region/Scene/scripting/Scripts/FollowRandomAvatar.cs
new file mode 100644
index 0000000..21f07a8
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scene/scripting/Scripts/FollowRandomAvatar.cs
@@ -0,0 +1,64 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Scripting
34{
35 public class FollowRandomAvatar : Script
36 {
37 public FollowRandomAvatar()
38 : base(LLUUID.Random())
39 {
40 OnFrame += MyOnFrame;
41 }
42
43 private void MyOnFrame(IScriptContext context)
44 {
45 LLVector3 pos = context.Entity.Pos;
46
47 IScriptReadonlyEntity avatar;
48
49 if (context.TryGetRandomAvatar(out avatar))
50 {
51 LLVector3 avatarPos = avatar.Pos;
52
53 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
54 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
55
56 LLVector3 newPos = new LLVector3(x, y, pos.Z);
57
58 context.Entity.Pos = newPos;
59 }
60 }
61 }
62
63
64}