From 3d93d390485075345442b9b5ea35eed88a9cab49 Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 16 May 2007 12:44:58 +0000 Subject: started to refactor startup code and to move udp server code out to its own class (currently not being used though) so that a single instance can handle multiple regions (each will need to be listening on a separate udp port) --- OpenSim.RegionServer/world/Avatar.Client.cs | 33 ++ OpenSim.RegionServer/world/Avatar.Update.cs | 331 +++++++++++++++++++++ OpenSim.RegionServer/world/AvatarClient.cs | 33 -- OpenSim.RegionServer/world/AvatarUpdate.cs | 331 --------------------- OpenSim.RegionServer/world/World.PacketHandlers.cs | 229 ++++++++++++++ OpenSim.RegionServer/world/World.Scripting.cs | 124 ++++++++ OpenSim.RegionServer/world/WorldPacketHandlers.cs | 229 -------------- OpenSim.RegionServer/world/WorldScripting.cs | 124 -------- 8 files changed, 717 insertions(+), 717 deletions(-) create mode 100644 OpenSim.RegionServer/world/Avatar.Client.cs create mode 100644 OpenSim.RegionServer/world/Avatar.Update.cs delete mode 100644 OpenSim.RegionServer/world/AvatarClient.cs delete mode 100644 OpenSim.RegionServer/world/AvatarUpdate.cs create mode 100644 OpenSim.RegionServer/world/World.PacketHandlers.cs create mode 100644 OpenSim.RegionServer/world/World.Scripting.cs delete mode 100644 OpenSim.RegionServer/world/WorldPacketHandlers.cs delete mode 100644 OpenSim.RegionServer/world/WorldScripting.cs (limited to 'OpenSim.RegionServer/world') diff --git a/OpenSim.RegionServer/world/Avatar.Client.cs b/OpenSim.RegionServer/world/Avatar.Client.cs new file mode 100644 index 0000000..7656a89 --- /dev/null +++ b/OpenSim.RegionServer/world/Avatar.Client.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife.Packets; + +namespace OpenSim.world +{ + partial class Avatar + { + private List updateList = new List(); + private List interestList = new List(); + + public void SendPacketToViewer(Packet packet) + { + this.ControllingClient.OutPacket(packet); + } + + public void AddTerseUpdateToViewersList(ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock) + { + + } + + public void SendUpdateListToViewer() + { + + } + + private void UpdateInterestList() + { + + } + } +} diff --git a/OpenSim.RegionServer/world/Avatar.Update.cs b/OpenSim.RegionServer/world/Avatar.Update.cs new file mode 100644 index 0000000..ba2965d --- /dev/null +++ b/OpenSim.RegionServer/world/Avatar.Update.cs @@ -0,0 +1,331 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; + +namespace OpenSim.world +{ + partial class Avatar + { + public override void update() + { + if (this._physActor == null) + { + //HACKHACK: Note to work out why this entity does not have a physics actor + // and prehaps create one. + return; + } + libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); + if (this.updateflag) + { + //need to send movement info + //so create the improvedterseobjectupdate packet + //use CreateTerseBlock() + ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = m_regionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(terse); + } + + updateflag = false; + //this._updateCount = 0; + } + else + { + + if ((pos2 != this.positionLastFrame) || (this.movementflag == 16)) + { + _updateCount++; + if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0)) + { + //It has been a while since last update was sent so lets send one. + ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); + ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); + terse.RegionData.RegionHandle = m_regionHandle; // FIXME + terse.RegionData.TimeDilation = 64096; + terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; + terse.ObjectData[0] = terseBlock; + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(terse); + } + _updateCount = 0; + } + + if (this.movementflag == 16) + { + movementflag = 0; + } + } + + } + this.positionLastFrame = pos2; + + if (!this.ControllingClient.m_sandboxMode) + { + if (pos2.X < 0) + { + ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); + } + + if (pos2.Y < 0) + { + ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); + } + + if (pos2.X > 255) + { + ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); + } + + if (pos2.Y > 255) + { + ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); + } + } + + } + + public ObjectUpdatePacket CreateUpdatePacket() + { + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + //send a objectupdate packet with information about the clients avatar + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = m_regionHandle; + objupdate.RegionData.TimeDilation = 64096; + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + + objupdate.ObjectData[0] = AvatarTemplate; + //give this avatar object a local id and assign the user a name + objupdate.ObjectData[0].ID = this.localid; + objupdate.ObjectData[0].FullID = ControllingClient.AgentID; + objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); + + libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z); + + byte[] pb = pos2.GetBytes(); + + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); + return objupdate; + } + + public void SendInitialPosition() + { + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + //send a objectupdate packet with information about the clients avatar + + ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); + objupdate.RegionData.RegionHandle = m_regionHandle; + objupdate.RegionData.TimeDilation = 64096; + objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; + objupdate.ObjectData[0] = AvatarTemplate; + //give this avatar object a local id and assign the user a name + + objupdate.ObjectData[0].ID = this.localid; + this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID; + objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); + libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z); + byte[] pb = pos2.GetBytes(); + Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); + m_world._localNumber++; + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(objupdate); + if (client.AgentID != ControllingClient.AgentID) + { + //the below line is already in Simclient.cs at line number 245 , directly below the call to this method + //if there is a problem/bug with that , then lets fix it there rather than duplicating it here + //client.ClientAvatar.SendAppearanceToOtherAgent(this.ControllingClient); + + SendAppearanceToOtherAgent(client); + } + } + } + + public void SendInitialAppearance() + { + AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); + aw.AgentData.AgentID = this.ControllingClient.AgentID; + aw.AgentData.SerialNum = 0; + aw.AgentData.SessionID = ControllingClient.SessionID; + + aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; + AgentWearablesUpdatePacket.WearableDataBlock awb; + for (int i = 0; i < 13; i++) + { + awb = new AgentWearablesUpdatePacket.WearableDataBlock(); + awb.WearableType = (byte)i; + awb.AssetID = this.Wearables[i].AssetID; + awb.ItemID = this.Wearables[i].ItemID; + aw.WearableData[i] = awb; + } + + ControllingClient.OutPacket(aw); + } + + public void SendAppearanceToOtherAgent(SimClient userInfo) + { + AvatarAppearancePacket avp = new AvatarAppearancePacket(); + avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218]; + avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes(); + + //a wearable update packets should only be sent about the viewers/agents own avatar not for other avatars + //but it seems that the following code only created the packets and never actually sent them anyway + /*AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); + aw.AgentData.AgentID = this.ControllingClient.AgentID; + aw.AgentData.SessionID = userInfo.SessionID; + aw.AgentData.SerialNum = 0; //removed the use of a random number as a random number could be less than the last number, should have a counter variable for this + + aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; + AgentWearablesUpdatePacket.WearableDataBlock awb; + for (int i = 0; i < 13; i++) + { + awb = new AgentWearablesUpdatePacket.WearableDataBlock(); + awb.WearableType = (byte)i; + awb.AssetID = this.Wearables[i].AssetID; + awb.ItemID = this.Wearables[i].ItemID; + aw.WearableData[i] = awb; + }*/ + + AvatarAppearancePacket.VisualParamBlock avblock = null; + for (int i = 0; i < 218; i++) + { + avblock = new AvatarAppearancePacket.VisualParamBlock(); + avblock.ParamValue = visualParams[i]; + avp.VisualParam[i] = avblock; + } + + avp.Sender.IsTrial = false; + avp.Sender.ID = ControllingClient.AgentID; + userInfo.OutPacket(avp); + } + + public void SetAppearance(AgentSetAppearancePacket appear) + { + LLObject.TextureEntry tex = new LLObject.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); + this.avatarAppearanceTexture = tex; + for (int i = 0; i < appear.VisualParam.Length; i++) + { + this.visualParams[i] = appear.VisualParam[i].ParamValue; + } + foreach (SimClient client in m_clientThreads.Values) + { + if (client.AgentID != ControllingClient.AgentID) + { + SendAppearanceToOtherAgent(client); + } + } + } + + public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() + { + byte[] bytes = new byte[60]; + int i = 0; + ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); + + dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; + libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0); + lock (m_world.LockPhysicsEngine) + { + pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); + } + + uint ID = this.localid; + + bytes[i++] = (byte)(ID % 256); + bytes[i++] = (byte)((ID >> 8) % 256); + bytes[i++] = (byte)((ID >> 16) % 256); + bytes[i++] = (byte)((ID >> 24) % 256); + bytes[i++] = 0; + bytes[i++] = 1; + i += 14; + bytes[i++] = 128; + bytes[i++] = 63; + + byte[] pb = pos2.GetBytes(); + Array.Copy(pb, 0, bytes, i, pb.Length); + i += 12; + ushort InternVelocityX; + ushort InternVelocityY; + ushort InternVelocityZ; + Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0); + lock (m_world.LockPhysicsEngine) + { + internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z); + } + internDirec = internDirec / 128.0f; + internDirec.x += 1; + internDirec.y += 1; + internDirec.z += 1; + + InternVelocityX = (ushort)(32768 * internDirec.x); + InternVelocityY = (ushort)(32768 * internDirec.y); + InternVelocityZ = (ushort)(32768 * internDirec.z); + + ushort ac = 32767; + bytes[i++] = (byte)(InternVelocityX % 256); + bytes[i++] = (byte)((InternVelocityX >> 8) % 256); + bytes[i++] = (byte)(InternVelocityY % 256); + bytes[i++] = (byte)((InternVelocityY >> 8) % 256); + bytes[i++] = (byte)(InternVelocityZ % 256); + bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); + + //accel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rot + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + //rotation vel + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + bytes[i++] = (byte)(ac % 256); + bytes[i++] = (byte)((ac >> 8) % 256); + + dat.Data = bytes; + return (dat); + } + + // Sends animation update + public void SendAnimPack() + { + AvatarAnimationPacket ani = new AvatarAnimationPacket(); + ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1]; + ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock(); + ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID; + ani.Sender = new AvatarAnimationPacket.SenderBlock(); + ani.Sender.ID = ControllingClient.AgentID; + ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1]; + ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock(); + ani.AnimationList[0].AnimID = this.current_anim; + ani.AnimationList[0].AnimSequenceID = this.anim_seq; + + //ControllingClient.OutPacket(ani); + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(ani); + } + } + + } +} diff --git a/OpenSim.RegionServer/world/AvatarClient.cs b/OpenSim.RegionServer/world/AvatarClient.cs deleted file mode 100644 index 7656a89..0000000 --- a/OpenSim.RegionServer/world/AvatarClient.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using libsecondlife.Packets; - -namespace OpenSim.world -{ - partial class Avatar - { - private List updateList = new List(); - private List interestList = new List(); - - public void SendPacketToViewer(Packet packet) - { - this.ControllingClient.OutPacket(packet); - } - - public void AddTerseUpdateToViewersList(ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock) - { - - } - - public void SendUpdateListToViewer() - { - - } - - private void UpdateInterestList() - { - - } - } -} diff --git a/OpenSim.RegionServer/world/AvatarUpdate.cs b/OpenSim.RegionServer/world/AvatarUpdate.cs deleted file mode 100644 index ba2965d..0000000 --- a/OpenSim.RegionServer/world/AvatarUpdate.cs +++ /dev/null @@ -1,331 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using libsecondlife; -using libsecondlife.Packets; - -namespace OpenSim.world -{ - partial class Avatar - { - public override void update() - { - if (this._physActor == null) - { - //HACKHACK: Note to work out why this entity does not have a physics actor - // and prehaps create one. - return; - } - libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); - if (this.updateflag) - { - //need to send movement info - //so create the improvedterseobjectupdate packet - //use CreateTerseBlock() - ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); - ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); - terse.RegionData.RegionHandle = m_regionHandle; // FIXME - terse.RegionData.TimeDilation = 64096; - terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; - terse.ObjectData[0] = terseBlock; - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(terse); - } - - updateflag = false; - //this._updateCount = 0; - } - else - { - - if ((pos2 != this.positionLastFrame) || (this.movementflag == 16)) - { - _updateCount++; - if (((!PhysicsEngineFlying) && (_updateCount > 3)) || (PhysicsEngineFlying) && (_updateCount > 0)) - { - //It has been a while since last update was sent so lets send one. - ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock(); - ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); - terse.RegionData.RegionHandle = m_regionHandle; // FIXME - terse.RegionData.TimeDilation = 64096; - terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; - terse.ObjectData[0] = terseBlock; - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(terse); - } - _updateCount = 0; - } - - if (this.movementflag == 16) - { - movementflag = 0; - } - } - - } - this.positionLastFrame = pos2; - - if (!this.ControllingClient.m_sandboxMode) - { - if (pos2.X < 0) - { - ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); - } - - if (pos2.Y < 0) - { - ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); - } - - if (pos2.X > 255) - { - ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); - } - - if (pos2.Y > 255) - { - ControllingClient.CrossSimBorder(new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z)); - } - } - - } - - public ObjectUpdatePacket CreateUpdatePacket() - { - System.Text.Encoding _enc = System.Text.Encoding.ASCII; - //send a objectupdate packet with information about the clients avatar - ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); - objupdate.RegionData.RegionHandle = m_regionHandle; - objupdate.RegionData.TimeDilation = 64096; - objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; - - objupdate.ObjectData[0] = AvatarTemplate; - //give this avatar object a local id and assign the user a name - objupdate.ObjectData[0].ID = this.localid; - objupdate.ObjectData[0].FullID = ControllingClient.AgentID; - objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); - - libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z); - - byte[] pb = pos2.GetBytes(); - - Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); - return objupdate; - } - - public void SendInitialPosition() - { - System.Text.Encoding _enc = System.Text.Encoding.ASCII; - //send a objectupdate packet with information about the clients avatar - - ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); - objupdate.RegionData.RegionHandle = m_regionHandle; - objupdate.RegionData.TimeDilation = 64096; - objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; - objupdate.ObjectData[0] = AvatarTemplate; - //give this avatar object a local id and assign the user a name - - objupdate.ObjectData[0].ID = this.localid; - this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID; - objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); - libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z); - byte[] pb = pos2.GetBytes(); - Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); - m_world._localNumber++; - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(objupdate); - if (client.AgentID != ControllingClient.AgentID) - { - //the below line is already in Simclient.cs at line number 245 , directly below the call to this method - //if there is a problem/bug with that , then lets fix it there rather than duplicating it here - //client.ClientAvatar.SendAppearanceToOtherAgent(this.ControllingClient); - - SendAppearanceToOtherAgent(client); - } - } - } - - public void SendInitialAppearance() - { - AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); - aw.AgentData.AgentID = this.ControllingClient.AgentID; - aw.AgentData.SerialNum = 0; - aw.AgentData.SessionID = ControllingClient.SessionID; - - aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; - AgentWearablesUpdatePacket.WearableDataBlock awb; - for (int i = 0; i < 13; i++) - { - awb = new AgentWearablesUpdatePacket.WearableDataBlock(); - awb.WearableType = (byte)i; - awb.AssetID = this.Wearables[i].AssetID; - awb.ItemID = this.Wearables[i].ItemID; - aw.WearableData[i] = awb; - } - - ControllingClient.OutPacket(aw); - } - - public void SendAppearanceToOtherAgent(SimClient userInfo) - { - AvatarAppearancePacket avp = new AvatarAppearancePacket(); - avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218]; - avp.ObjectData.TextureEntry = this.avatarAppearanceTexture.ToBytes(); - - //a wearable update packets should only be sent about the viewers/agents own avatar not for other avatars - //but it seems that the following code only created the packets and never actually sent them anyway - /*AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); - aw.AgentData.AgentID = this.ControllingClient.AgentID; - aw.AgentData.SessionID = userInfo.SessionID; - aw.AgentData.SerialNum = 0; //removed the use of a random number as a random number could be less than the last number, should have a counter variable for this - - aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13]; - AgentWearablesUpdatePacket.WearableDataBlock awb; - for (int i = 0; i < 13; i++) - { - awb = new AgentWearablesUpdatePacket.WearableDataBlock(); - awb.WearableType = (byte)i; - awb.AssetID = this.Wearables[i].AssetID; - awb.ItemID = this.Wearables[i].ItemID; - aw.WearableData[i] = awb; - }*/ - - AvatarAppearancePacket.VisualParamBlock avblock = null; - for (int i = 0; i < 218; i++) - { - avblock = new AvatarAppearancePacket.VisualParamBlock(); - avblock.ParamValue = visualParams[i]; - avp.VisualParam[i] = avblock; - } - - avp.Sender.IsTrial = false; - avp.Sender.ID = ControllingClient.AgentID; - userInfo.OutPacket(avp); - } - - public void SetAppearance(AgentSetAppearancePacket appear) - { - LLObject.TextureEntry tex = new LLObject.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); - this.avatarAppearanceTexture = tex; - for (int i = 0; i < appear.VisualParam.Length; i++) - { - this.visualParams[i] = appear.VisualParam[i].ParamValue; - } - foreach (SimClient client in m_clientThreads.Values) - { - if (client.AgentID != ControllingClient.AgentID) - { - SendAppearanceToOtherAgent(client); - } - } - } - - public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() - { - byte[] bytes = new byte[60]; - int i = 0; - ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); - - dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; - libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0); - lock (m_world.LockPhysicsEngine) - { - pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); - } - - uint ID = this.localid; - - bytes[i++] = (byte)(ID % 256); - bytes[i++] = (byte)((ID >> 8) % 256); - bytes[i++] = (byte)((ID >> 16) % 256); - bytes[i++] = (byte)((ID >> 24) % 256); - bytes[i++] = 0; - bytes[i++] = 1; - i += 14; - bytes[i++] = 128; - bytes[i++] = 63; - - byte[] pb = pos2.GetBytes(); - Array.Copy(pb, 0, bytes, i, pb.Length); - i += 12; - ushort InternVelocityX; - ushort InternVelocityY; - ushort InternVelocityZ; - Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0); - lock (m_world.LockPhysicsEngine) - { - internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z); - } - internDirec = internDirec / 128.0f; - internDirec.x += 1; - internDirec.y += 1; - internDirec.z += 1; - - InternVelocityX = (ushort)(32768 * internDirec.x); - InternVelocityY = (ushort)(32768 * internDirec.y); - InternVelocityZ = (ushort)(32768 * internDirec.z); - - ushort ac = 32767; - bytes[i++] = (byte)(InternVelocityX % 256); - bytes[i++] = (byte)((InternVelocityX >> 8) % 256); - bytes[i++] = (byte)(InternVelocityY % 256); - bytes[i++] = (byte)((InternVelocityY >> 8) % 256); - bytes[i++] = (byte)(InternVelocityZ % 256); - bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); - - //accel - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - - //rot - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - - //rotation vel - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - bytes[i++] = (byte)(ac % 256); - bytes[i++] = (byte)((ac >> 8) % 256); - - dat.Data = bytes; - return (dat); - } - - // Sends animation update - public void SendAnimPack() - { - AvatarAnimationPacket ani = new AvatarAnimationPacket(); - ani.AnimationSourceList = new AvatarAnimationPacket.AnimationSourceListBlock[1]; - ani.AnimationSourceList[0] = new AvatarAnimationPacket.AnimationSourceListBlock(); - ani.AnimationSourceList[0].ObjectID = ControllingClient.AgentID; - ani.Sender = new AvatarAnimationPacket.SenderBlock(); - ani.Sender.ID = ControllingClient.AgentID; - ani.AnimationList = new AvatarAnimationPacket.AnimationListBlock[1]; - ani.AnimationList[0] = new AvatarAnimationPacket.AnimationListBlock(); - ani.AnimationList[0].AnimID = this.current_anim; - ani.AnimationList[0].AnimSequenceID = this.anim_seq; - - //ControllingClient.OutPacket(ani); - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(ani); - } - } - - } -} diff --git a/OpenSim.RegionServer/world/World.PacketHandlers.cs b/OpenSim.RegionServer/world/World.PacketHandlers.cs new file mode 100644 index 0000000..2036bc6 --- /dev/null +++ b/OpenSim.RegionServer/world/World.PacketHandlers.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; +using OpenSim.Physics.Manager; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Types; +using OpenSim.Framework.Terrain; +using OpenSim.Framework.Inventory; +using OpenSim.Framework.Utilities; +using OpenSim.Assets; + +namespace OpenSim.world +{ + partial class World + { + public bool ModifyTerrain(SimClient simClient, Packet packet) + { + ModifyLandPacket modify = (ModifyLandPacket)packet; + + switch (modify.ModifyBlock.Action) + { + case 1: + // raise terrain + if (modify.ParcelData.Length > 0) + { + Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); + RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); + } + break; + case 2: + //lower terrain + if (modify.ParcelData.Length > 0) + { + Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); + RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); + } + break; + } + return true; + } + + public bool SimChat(SimClient simClient, Packet packet) + { + System.Text.Encoding enc = System.Text.Encoding.ASCII; + ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)packet; + if (Util.FieldToString(inchatpack.ChatData.Message) == "") + { + //empty message so don't bother with it + return true; + } + + libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); + reply.ChatData.Audible = 1; + reply.ChatData.Message = inchatpack.ChatData.Message; + reply.ChatData.ChatType = inchatpack.ChatData.Type; + reply.ChatData.SourceType = 1; + reply.ChatData.Position = simClient.ClientAvatar.Pos; + reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0"); + reply.ChatData.OwnerID = simClient.AgentID; + reply.ChatData.SourceID = simClient.AgentID; + foreach (SimClient client in m_clientThreads.Values) + { + switch (inchatpack.ChatData.Type) + { + case 0: + int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); + if ((dis < 10) && (dis > -10)) + { + client.OutPacket(reply); + } + break; + case 1: + dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); + if ((dis < 30) && (dis > -30)) + { + client.OutPacket(reply); + } + break; + case 2: + dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); + if ((dis < 100) && (dis > -100)) + { + client.OutPacket(reply); + } + break; + } + + } + return true; + } + + public bool RezObject(SimClient simClient, Packet packet) + { + RezObjectPacket rezPacket = (RezObjectPacket)packet; + AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID); + if (inven != null) + { + if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID)) + { + AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID); + if (asset != null) + { + PrimData primd = new PrimData(asset.Data); + Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); + nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true); + this.Entities.Add(nPrim.uuid, nPrim); + this._primCount++; + this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID); + } + } + } + return true; + } + + public bool DeRezObject(SimClient simClient, Packet packet) + { + DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; + + //Needs to delete object from physics at a later date + if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) + { + //currently following code not used (or don't know of any case of destination being zero + libsecondlife.LLUUID[] DeRezEnts; + DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length]; + int i = 0; + foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) + { + + //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); + foreach (Entity ent in this.Entities.Values) + { + if (ent.localid == Data.ObjectLocalID) + { + DeRezEnts[i++] = ent.uuid; + this.localStorage.RemovePrim(ent.uuid); + KillObjectPacket kill = new KillObjectPacket(); + kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; + kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); + kill.ObjectData[0].ID = ent.localid; + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(kill); + } + //Uncommenting this means an old UUID will be re-used, thus crashing the asset server + //Uncomment when prim/object UUIDs are random or such + //2007-03-22 - Randomskk + //this._primCount--; + OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Deleted UUID " + ent.uuid); + } + } + } + foreach (libsecondlife.LLUUID uuid in DeRezEnts) + { + lock (Entities) + { + Entities.Remove(uuid); + } + } + } + else + { + foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) + { + Entity selectedEnt = null; + //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); + foreach (Entity ent in this.Entities.Values) + { + if (ent.localid == Data.ObjectLocalID) + { + AssetBase primAsset = new AssetBase(); + primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid + primAsset.InvType = 6; + primAsset.Type = 6; + primAsset.Name = "Prim"; + primAsset.Description = ""; + primAsset.Data = ((Primitive)ent).GetByteArray(); + this._assetCache.AddAsset(primAsset); + this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset); + selectedEnt = ent; + break; + } + } + if (selectedEnt != null) + { + this.localStorage.RemovePrim(selectedEnt.uuid); + KillObjectPacket kill = new KillObjectPacket(); + kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; + kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); + kill.ObjectData[0].ID = selectedEnt.localid; + foreach (SimClient client in m_clientThreads.Values) + { + client.OutPacket(kill); + } + lock (Entities) + { + Entities.Remove(selectedEnt.uuid); + } + } + } + } + return true; + } + + public void RequestMapBlock(SimClient simClient, int minX, int minY, int maxX, int maxY) + { + System.Text.Encoding _enc = System.Text.Encoding.ASCII; + if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY))) + { + MapBlockReplyPacket mapReply = new MapBlockReplyPacket(); + mapReply.AgentData.AgentID = simClient.AgentID; + mapReply.AgentData.Flags = 0; + mapReply.Data = new MapBlockReplyPacket.DataBlock[1]; + mapReply.Data[0] = new MapBlockReplyPacket.DataBlock(); + mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007"); + mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX; + mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY; + mapReply.Data[0].WaterHeight =(byte) m_regInfo.RegionWaterHeight; + mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName); + mapReply.Data[0].RegionFlags = 72458694; + mapReply.Data[0].Access = 13; + mapReply.Data[0].Agents = 1; //should send number of clients connected + simClient.OutPacket(mapReply); + } + } + + } +} diff --git a/OpenSim.RegionServer/world/World.Scripting.cs b/OpenSim.RegionServer/world/World.Scripting.cs new file mode 100644 index 0000000..44ef05a --- /dev/null +++ b/OpenSim.RegionServer/world/World.Scripting.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Reflection; +using OpenSim.Framework; +using OpenSim.Framework.Interfaces; +using OpenSim.Framework.Types; +using libsecondlife; + +namespace OpenSim.world +{ + public partial class World + { + private Dictionary scriptEngines = new Dictionary(); + + private void LoadScriptEngines() + { + this.LoadScriptPlugins(); + } + + public void LoadScriptPlugins() + { + string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines"); + string[] pluginFiles = Directory.GetFiles(path, "*.dll"); + + + for (int i = 0; i < pluginFiles.Length; i++) + { + this.AddPlugin(pluginFiles[i]); + } + } + + private void AddPlugin(string FileName) + { + Assembly pluginAssembly = Assembly.LoadFrom(FileName); + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IScriptEngine", true); + + if (typeInterface != null) + { + IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + plug.Init(this); + this.scriptEngines.Add(plug.GetName(), plug); + + } + + typeInterface = null; + } + } + } + + pluginAssembly = null; + } + + public void LoadScript(string scriptType, string scriptName, string script, Entity ent) + { + if(this.scriptEngines.ContainsKey(scriptType)) + { + this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid); + } + } + + #region IScriptAPI Methods + + public OSVector3 GetEntityPosition(uint localID) + { + OSVector3 res = new OSVector3(); + // Console.WriteLine("script- getting entity " + localID + " position"); + foreach (Entity entity in this.Entities.Values) + { + if (entity.localid == localID) + { + res.X = entity.Pos.X; + res.Y = entity.Pos.Y; + res.Z = entity.Pos.Z; + } + } + return res; + } + + public void SetEntityPosition(uint localID, float x , float y, float z) + { + foreach (Entity entity in this.Entities.Values) + { + if (entity.localid == localID && entity is Primitive) + { + LLVector3 pos = entity.Pos; + pos.X = x; + pos.Y = y; + Primitive prim = entity as Primitive; + // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. + prim.UpdatePosition(pos); + // Console.WriteLine("script- setting entity " + localID + " positon"); + } + } + + } + + public uint GetRandomAvatarID() + { + //Console.WriteLine("script- getting random avatar id"); + uint res = 0; + foreach (Entity entity in this.Entities.Values) + { + if (entity is Avatar) + { + res = entity.localid; + } + } + return res; + } + + #endregion + + + } +} diff --git a/OpenSim.RegionServer/world/WorldPacketHandlers.cs b/OpenSim.RegionServer/world/WorldPacketHandlers.cs deleted file mode 100644 index 2036bc6..0000000 --- a/OpenSim.RegionServer/world/WorldPacketHandlers.cs +++ /dev/null @@ -1,229 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using libsecondlife; -using libsecondlife.Packets; -using OpenSim.Physics.Manager; -using OpenSim.Framework.Interfaces; -using OpenSim.Framework.Types; -using OpenSim.Framework.Terrain; -using OpenSim.Framework.Inventory; -using OpenSim.Framework.Utilities; -using OpenSim.Assets; - -namespace OpenSim.world -{ - partial class World - { - public bool ModifyTerrain(SimClient simClient, Packet packet) - { - ModifyLandPacket modify = (ModifyLandPacket)packet; - - switch (modify.ModifyBlock.Action) - { - case 1: - // raise terrain - if (modify.ParcelData.Length > 0) - { - Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); - RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); - } - break; - case 2: - //lower terrain - if (modify.ParcelData.Length > 0) - { - Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); - RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); - } - break; - } - return true; - } - - public bool SimChat(SimClient simClient, Packet packet) - { - System.Text.Encoding enc = System.Text.Encoding.ASCII; - ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)packet; - if (Util.FieldToString(inchatpack.ChatData.Message) == "") - { - //empty message so don't bother with it - return true; - } - - libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); - reply.ChatData.Audible = 1; - reply.ChatData.Message = inchatpack.ChatData.Message; - reply.ChatData.ChatType = inchatpack.ChatData.Type; - reply.ChatData.SourceType = 1; - reply.ChatData.Position = simClient.ClientAvatar.Pos; - reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0"); - reply.ChatData.OwnerID = simClient.AgentID; - reply.ChatData.SourceID = simClient.AgentID; - foreach (SimClient client in m_clientThreads.Values) - { - switch (inchatpack.ChatData.Type) - { - case 0: - int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); - if ((dis < 10) && (dis > -10)) - { - client.OutPacket(reply); - } - break; - case 1: - dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); - if ((dis < 30) && (dis > -30)) - { - client.OutPacket(reply); - } - break; - case 2: - dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); - if ((dis < 100) && (dis > -100)) - { - client.OutPacket(reply); - } - break; - } - - } - return true; - } - - public bool RezObject(SimClient simClient, Packet packet) - { - RezObjectPacket rezPacket = (RezObjectPacket)packet; - AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID); - if (inven != null) - { - if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID)) - { - AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID); - if (asset != null) - { - PrimData primd = new PrimData(asset.Data); - Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); - nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true); - this.Entities.Add(nPrim.uuid, nPrim); - this._primCount++; - this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID); - } - } - } - return true; - } - - public bool DeRezObject(SimClient simClient, Packet packet) - { - DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; - - //Needs to delete object from physics at a later date - if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) - { - //currently following code not used (or don't know of any case of destination being zero - libsecondlife.LLUUID[] DeRezEnts; - DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length]; - int i = 0; - foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) - { - - //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); - foreach (Entity ent in this.Entities.Values) - { - if (ent.localid == Data.ObjectLocalID) - { - DeRezEnts[i++] = ent.uuid; - this.localStorage.RemovePrim(ent.uuid); - KillObjectPacket kill = new KillObjectPacket(); - kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; - kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); - kill.ObjectData[0].ID = ent.localid; - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(kill); - } - //Uncommenting this means an old UUID will be re-used, thus crashing the asset server - //Uncomment when prim/object UUIDs are random or such - //2007-03-22 - Randomskk - //this._primCount--; - OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Deleted UUID " + ent.uuid); - } - } - } - foreach (libsecondlife.LLUUID uuid in DeRezEnts) - { - lock (Entities) - { - Entities.Remove(uuid); - } - } - } - else - { - foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) - { - Entity selectedEnt = null; - //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); - foreach (Entity ent in this.Entities.Values) - { - if (ent.localid == Data.ObjectLocalID) - { - AssetBase primAsset = new AssetBase(); - primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid - primAsset.InvType = 6; - primAsset.Type = 6; - primAsset.Name = "Prim"; - primAsset.Description = ""; - primAsset.Data = ((Primitive)ent).GetByteArray(); - this._assetCache.AddAsset(primAsset); - this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset); - selectedEnt = ent; - break; - } - } - if (selectedEnt != null) - { - this.localStorage.RemovePrim(selectedEnt.uuid); - KillObjectPacket kill = new KillObjectPacket(); - kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; - kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); - kill.ObjectData[0].ID = selectedEnt.localid; - foreach (SimClient client in m_clientThreads.Values) - { - client.OutPacket(kill); - } - lock (Entities) - { - Entities.Remove(selectedEnt.uuid); - } - } - } - } - return true; - } - - public void RequestMapBlock(SimClient simClient, int minX, int minY, int maxX, int maxY) - { - System.Text.Encoding _enc = System.Text.Encoding.ASCII; - if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY))) - { - MapBlockReplyPacket mapReply = new MapBlockReplyPacket(); - mapReply.AgentData.AgentID = simClient.AgentID; - mapReply.AgentData.Flags = 0; - mapReply.Data = new MapBlockReplyPacket.DataBlock[1]; - mapReply.Data[0] = new MapBlockReplyPacket.DataBlock(); - mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007"); - mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX; - mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY; - mapReply.Data[0].WaterHeight =(byte) m_regInfo.RegionWaterHeight; - mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName); - mapReply.Data[0].RegionFlags = 72458694; - mapReply.Data[0].Access = 13; - mapReply.Data[0].Agents = 1; //should send number of clients connected - simClient.OutPacket(mapReply); - } - } - - } -} diff --git a/OpenSim.RegionServer/world/WorldScripting.cs b/OpenSim.RegionServer/world/WorldScripting.cs deleted file mode 100644 index 44ef05a..0000000 --- a/OpenSim.RegionServer/world/WorldScripting.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.IO; -using System.Reflection; -using OpenSim.Framework; -using OpenSim.Framework.Interfaces; -using OpenSim.Framework.Types; -using libsecondlife; - -namespace OpenSim.world -{ - public partial class World - { - private Dictionary scriptEngines = new Dictionary(); - - private void LoadScriptEngines() - { - this.LoadScriptPlugins(); - } - - public void LoadScriptPlugins() - { - string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "ScriptEngines"); - string[] pluginFiles = Directory.GetFiles(path, "*.dll"); - - - for (int i = 0; i < pluginFiles.Length; i++) - { - this.AddPlugin(pluginFiles[i]); - } - } - - private void AddPlugin(string FileName) - { - Assembly pluginAssembly = Assembly.LoadFrom(FileName); - - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (pluginType.IsPublic) - { - if (!pluginType.IsAbstract) - { - Type typeInterface = pluginType.GetInterface("IScriptEngine", true); - - if (typeInterface != null) - { - IScriptEngine plug = (IScriptEngine)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Init(this); - this.scriptEngines.Add(plug.GetName(), plug); - - } - - typeInterface = null; - } - } - } - - pluginAssembly = null; - } - - public void LoadScript(string scriptType, string scriptName, string script, Entity ent) - { - if(this.scriptEngines.ContainsKey(scriptType)) - { - this.scriptEngines[scriptType].LoadScript(script, scriptName, ent.localid); - } - } - - #region IScriptAPI Methods - - public OSVector3 GetEntityPosition(uint localID) - { - OSVector3 res = new OSVector3(); - // Console.WriteLine("script- getting entity " + localID + " position"); - foreach (Entity entity in this.Entities.Values) - { - if (entity.localid == localID) - { - res.X = entity.Pos.X; - res.Y = entity.Pos.Y; - res.Z = entity.Pos.Z; - } - } - return res; - } - - public void SetEntityPosition(uint localID, float x , float y, float z) - { - foreach (Entity entity in this.Entities.Values) - { - if (entity.localid == localID && entity is Primitive) - { - LLVector3 pos = entity.Pos; - pos.X = x; - pos.Y = y; - Primitive prim = entity as Primitive; - // Of course, we really should have asked the physEngine if this is possible, and if not, returned false. - prim.UpdatePosition(pos); - // Console.WriteLine("script- setting entity " + localID + " positon"); - } - } - - } - - public uint GetRandomAvatarID() - { - //Console.WriteLine("script- getting random avatar id"); - uint res = 0; - foreach (Entity entity in this.Entities.Values) - { - if (entity is Avatar) - { - res = entity.localid; - } - } - return res; - } - - #endregion - - - } -} -- cgit v1.1