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