Hijacked simpleApp again (sorry lbsa71, guess I should create my own simpleApp), to try out a basic test npc character(/class).

afrisby
MW 2007-07-15 21:10:05 +00:00
parent 6510aea0ed
commit bf2f3ea29a
7 changed files with 350 additions and 15 deletions

View File

@ -0,0 +1,125 @@
using System.Collections.Generic;
using System.Net;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Types;
using OpenSim.Framework.Data;
using libsecondlife;
using libsecondlife.Packets;
namespace OpenSim.Framework
{
public class NpcClientBase :IClientAPI
{
public event ImprovedInstantMessage OnInstantMessage;
public event ChatFromViewer OnChatFromViewer;
public event RezObject OnRezObject;
public event ModifyTerrain OnModifyTerrain;
public event SetAppearance OnSetAppearance;
public event StartAnim OnStartAnim;
public event LinkObjects OnLinkObjects;
public event RequestMapBlocks OnRequestMapBlocks;
public event TeleportLocationRequest OnTeleportLocationRequest;
public event GenericCall4 OnDeRezObject;
public event GenericCall OnRegionHandShakeReply;
public event GenericCall OnRequestWearables;
public event GenericCall2 OnCompleteMovementToRegion;
public event UpdateAgent OnAgentUpdate;
public event GenericCall OnRequestAvatarsData;
public event AddNewPrim OnAddPrim;
public event ObjectDuplicate OnObjectDuplicate;
public event UpdateVector OnGrapObject;
public event ObjectSelect OnDeGrapObject;
public event MoveObject OnGrapUpdate;
public event UpdateShape OnUpdatePrimShape;
public event ObjectSelect OnObjectSelect;
public event GenericCall7 OnObjectDescription;
public event GenericCall7 OnObjectName;
public event UpdatePrimFlags OnUpdatePrimFlags;
public event UpdatePrimTexture OnUpdatePrimTexture;
public event UpdateVector OnUpdatePrimGroupPosition;
public event UpdateVector OnUpdatePrimSinglePosition;
public event UpdatePrimRotation OnUpdatePrimGroupRotation;
public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
public event UpdateVector OnUpdatePrimScale;
public event StatusChange OnChildAgentStatus;
public event GenericCall2 OnStopMovement;
public event NewAvatar OnNewAvatar;
public event GenericCall6 OnRemoveAvatar;
public event UUIDNameRequest OnNameFromUUIDRequest;
public event ParcelPropertiesRequest OnParcelPropertiesRequest;
public event ParcelDivideRequest OnParcelDivideRequest;
public event ParcelJoinRequest OnParcelJoinRequest;
public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
public event ParcelSelectObjects OnParcelSelectObjects;
public event EstateOwnerMessageRequest OnEstateOwnerMessage;
public virtual LLVector3 StartPos
{
get { return new LLVector3(); }
set { }
}
public virtual LLUUID AgentId
{
get { return LLUUID.Random(); }
}
public virtual string FirstName
{
get { return ""; }
}
public virtual string LastName
{
get { return ""; }
}
public NpcClientBase()
{
}
public virtual void OutPacket(Packet newPack){}
public virtual void SendWearables(AvatarWearable[] wearables){}
public virtual void SendStartPingCheck(byte seq){}
public virtual void SendKillObject(ulong regionHandle, uint avatarLocalID){}
public virtual void SendAnimation(LLUUID animID, int seq, LLUUID sourceAgentId){}
public virtual void SendRegionHandshake(RegionInfo regionInfo){}
public virtual void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID){}
public virtual void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID){}
public virtual void SendInstantMessage(string message, LLUUID target, string fromName){}
public virtual void SendLayerData(float[] map){}
public virtual void SendLayerData(int px, int py, float[] map){}
public virtual void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look){}
public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint){}
public virtual AgentCircuitData RequestClientInfo() { return new AgentCircuitData(); }
public virtual void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint newRegionExternalEndPoint){}
public virtual void SendMapBlock(List<MapBlockData> mapBlocks){}
public virtual void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags){}
public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags){}
public virtual void SendTeleportCancel(){}
public virtual void SendTeleportLocationStart(){}
public virtual void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance){}
public virtual void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos, byte[] textureEntry){}
public virtual void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity){}
public virtual void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint){}
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags){}
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID, uint flags){}
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLQuaternion rotation, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID){}
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID){}
public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation){}
public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items){}
public virtual void SendInventoryItemDetails(LLUUID ownerID, LLUUID folderID, InventoryItemBase item){}
public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname){}
}
}

View File

@ -139,8 +139,7 @@ namespace OpenSim.Region.Environment.Scenes
/// <param name="fromAgentID"></param> /// <param name="fromAgentID"></param>
public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
{ {
// Console.WriteLine("Chat message"); ScenePresence avatar = null;
ScenePresence avatar = null;
if (this.Avatars.ContainsKey(fromAgentID)) if (this.Avatars.ContainsKey(fromAgentID))
{ {
avatar = this.Avatars[fromAgentID]; avatar = this.Avatars[fromAgentID];

View File

@ -55,8 +55,8 @@ namespace OpenSim.Region.Environment.Scenes
protected Timer m_heartbeatTimer = new Timer(); protected Timer m_heartbeatTimer = new Timer();
protected Dictionary<LLUUID, ScenePresence> Avatars; protected Dictionary<LLUUID, ScenePresence> Avatars;
protected Dictionary<LLUUID, SceneObject> Prims; protected Dictionary<LLUUID, SceneObject> Prims;
private PhysicsScene phyScene; protected PhysicsScene phyScene;
private float timeStep = 0.1f; protected float timeStep = 0.1f;
private Random Rand = new Random(); private Random Rand = new Random();
private uint _primCount = 702000; private uint _primCount = 702000;
private System.Threading.Mutex _primAllocateMutex = new Mutex(false); private System.Threading.Mutex _primAllocateMutex = new Mutex(false);

View File

@ -57,7 +57,10 @@ namespace OpenSim.Region.Environment.Scenes
private byte[] visualParams; private byte[] visualParams;
private AvatarWearable[] Wearables; private AvatarWearable[] Wearables;
private ulong m_regionHandle; private ulong m_regionHandle;
private bool childAgent = false;
public bool childAgent = false;
public bool IsRestrictedToRegion = false;
private bool newForce = false; private bool newForce = false;
private bool newAvatar = false; private bool newAvatar = false;
private IScenePresenceBody m_body; private IScenePresenceBody m_body;
@ -72,7 +75,7 @@ namespace OpenSim.Region.Environment.Scenes
DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS, DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS,
DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG, DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG,
DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS, DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS,
DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG
} }
/// <summary> /// <summary>
/// Position at which a significant movement was made /// Position at which a significant movement was made

View File

@ -0,0 +1,174 @@
using System.Collections.Generic;
using System.Net;
using System.Timers;
using System;
using System.Text;
using libsecondlife;
using libsecondlife.Packets;
using OpenSim.Framework;
using OpenSim.Framework.Interfaces;
using OpenSim.Framework.Types;
using OpenSim.Framework.Data;
using OpenSim.Framework.Utilities;
namespace SimpleApp
{
public class MyNpcCharacter : IClientAPI
{
private uint movementDirection = 0;
private bool fly = true;
private LLQuaternion bodyDirection = LLQuaternion.Identity;
public event ImprovedInstantMessage OnInstantMessage;
public event ChatFromViewer OnChatFromViewer;
public event RezObject OnRezObject;
public event ModifyTerrain OnModifyTerrain;
public event SetAppearance OnSetAppearance;
public event StartAnim OnStartAnim;
public event LinkObjects OnLinkObjects;
public event RequestMapBlocks OnRequestMapBlocks;
public event TeleportLocationRequest OnTeleportLocationRequest;
public event GenericCall4 OnDeRezObject;
public event GenericCall OnRegionHandShakeReply;
public event GenericCall OnRequestWearables;
public event GenericCall2 OnCompleteMovementToRegion;
public event UpdateAgent OnAgentUpdate;
public event GenericCall OnRequestAvatarsData;
public event AddNewPrim OnAddPrim;
public event ObjectDuplicate OnObjectDuplicate;
public event UpdateVector OnGrapObject;
public event ObjectSelect OnDeGrapObject;
public event MoveObject OnGrapUpdate;
public event UpdateShape OnUpdatePrimShape;
public event ObjectSelect OnObjectSelect;
public event GenericCall7 OnObjectDescription;
public event GenericCall7 OnObjectName;
public event UpdatePrimFlags OnUpdatePrimFlags;
public event UpdatePrimTexture OnUpdatePrimTexture;
public event UpdateVector OnUpdatePrimGroupPosition;
public event UpdateVector OnUpdatePrimSinglePosition;
public event UpdatePrimRotation OnUpdatePrimGroupRotation;
public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation;
public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation;
public event UpdateVector OnUpdatePrimScale;
public event StatusChange OnChildAgentStatus;
public event GenericCall2 OnStopMovement;
public event NewAvatar OnNewAvatar;
public event GenericCall6 OnRemoveAvatar;
public event UUIDNameRequest OnNameFromUUIDRequest;
public event ParcelPropertiesRequest OnParcelPropertiesRequest;
public event ParcelDivideRequest OnParcelDivideRequest;
public event ParcelJoinRequest OnParcelJoinRequest;
public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
public event ParcelSelectObjects OnParcelSelectObjects;
public event EstateOwnerMessageRequest OnEstateOwnerMessage;
private LLUUID myID = LLUUID.Random();
public MyNpcCharacter()
{
}
public virtual LLVector3 StartPos
{
get { return new LLVector3(128, 100, 2); }
set { }
}
public virtual LLUUID AgentId
{
get { return myID; }
}
public virtual string FirstName
{
get { return "Annoying"; }
}
public virtual string LastName
{
get { return "NPC"; }
}
public virtual void OutPacket(Packet newPack) { }
public virtual void SendWearables(AvatarWearable[] wearables) { }
public virtual void SendStartPingCheck(byte seq) { }
public virtual void SendKillObject(ulong regionHandle, uint avatarLocalID) { }
public virtual void SendAnimation(LLUUID animID, int seq, LLUUID sourceAgentId) { }
public virtual void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) { }
public virtual void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) { }
public virtual void SendInstantMessage(string message, LLUUID target, string fromName) { }
public virtual void SendLayerData(float[] map) { }
public virtual void SendLayerData(int px, int py, float[] map) { }
public virtual void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look) { }
public virtual void InformClientOfNeighbour(ulong neighbourHandle, IPEndPoint neighbourExternalEndPoint) { }
public virtual AgentCircuitData RequestClientInfo() { return new AgentCircuitData(); }
public virtual void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, IPEndPoint newRegionExternalEndPoint) { }
public virtual void SendMapBlock(List<MapBlockData> mapBlocks) { }
public virtual void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags) { }
public virtual void SendRegionTeleport(ulong regionHandle, byte simAccess, IPEndPoint regionExternalEndPoint, uint locationID, uint flags) { }
public virtual void SendTeleportCancel() { }
public virtual void SendTeleportLocationStart() { }
public virtual void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance) { }
public virtual void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos, byte[] textureEntry) { }
public virtual void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity) { }
public virtual void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint) { }
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags) { }
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID, uint flags) { }
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLQuaternion rotation, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) { }
public virtual void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID) { }
public virtual void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation) { }
public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List<InventoryItemBase> items) { }
public virtual void SendInventoryItemDetails(LLUUID ownerID, LLUUID folderID, InventoryItemBase item) { }
public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname) { }
public virtual void SendRegionHandshake(RegionInfo regionInfo)
{
this.OnRegionHandShakeReply(this);
this.OnCompleteMovementToRegion();
this.StartMovement();
}
public void StartMovement()
{
Timer timer = new Timer();
timer.Enabled = true;
timer.Interval = 10000;
timer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
}
public void Heartbeat(object sender, EventArgs e)
{
Encoding enc = Encoding.ASCII;
this.OnAgentUpdate(this, movementDirection, bodyDirection);
if (this.fly)
{
movementDirection = (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY | (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG;
fly = false;
}
else
{
movementDirection = (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY | (uint)MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS;
fly = true;
}
this.OnChatFromViewer(enc.GetBytes("Kind of quiet around here isn't it! \0"), 2, new LLVector3(128, 128, 26), this.FirstName + " " + this.LastName, this.AgentId);
}
}
}

View File

@ -47,14 +47,15 @@ namespace SimpleApp
LLVector3 pos = new LLVector3(128, 128, 128); LLVector3 pos = new LLVector3(128, 128, 128);
client.OnRegionHandShakeReply += SendLayerData; client.OnRegionHandShakeReply += SendLayerData;
client.OnChatFromViewer += /*client.OnChatFromViewer +=
delegate(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID) delegate(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
{ {
// Echo it (so you know what you typed) // Echo it (so you know what you typed)
client.SendChatMessage(message, type, fromPos, fromName, fromAgentID); client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
client.SendChatMessage("Ready.", 1, pos, "System", LLUUID.Zero ); client.SendChatMessage("Ready.", 1, pos, "System", LLUUID.Zero );
}; };
*/
client.OnChatFromViewer += this.SimChat;
client.OnAddPrim += AddNewPrim; client.OnAddPrim += AddNewPrim;
client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition; client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
client.OnRequestMapBlocks += this.RequestMapBlocks; client.OnRequestMapBlocks += this.RequestMapBlocks;
@ -73,6 +74,24 @@ namespace SimpleApp
avatar.Pos = new LLVector3(128, 128, 26); avatar.Pos = new LLVector3(128, 128, 26);
} }
public override void Update()
{
foreach (LLUUID UUID in Entities.Keys)
{
Entities[UUID].updateMovement();
}
lock (this.m_syncRoot)
{
this.phyScene.Simulate(timeStep);
}
foreach (LLUUID UUID in Entities.Keys)
{
Entities[UUID].update();
}
}
#endregion #endregion
} }
} }

View File

@ -15,6 +15,7 @@ using OpenSim.Region.Communications.Local;
using OpenSim.Region.GridInterfaces.Local; using OpenSim.Region.GridInterfaces.Local;
using System.Timers; using System.Timers;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
using OpenSim.Framework.Data;
namespace SimpleApp namespace SimpleApp
{ {
@ -25,6 +26,7 @@ namespace SimpleApp
uint m_localId; uint m_localId;
public MyWorld world; public MyWorld world;
private SceneObject m_sceneObject; private SceneObject m_sceneObject;
public MyNpcCharacter m_character;
private void Run() private void Run()
{ {
@ -65,22 +67,35 @@ namespace SimpleApp
world.PhysScene = physManager.GetPhysicsScene("basicphysics"); //PhysicsScene.Null; world.PhysScene = physManager.GetPhysicsScene("basicphysics"); //PhysicsScene.Null;
world.LoadWorldMap(); world.LoadWorldMap();
world.ParcelManager.NoParcelDataFromStorage(); world.PhysScene.SetTerrain(world.Terrain.getHeights1D());
udpServer.LocalWorld = world; udpServer.LocalWorld = world;
httpServer.Start(); httpServer.Start();
udpServer.ServerListener(); udpServer.ServerListener();
UserProfileData masterAvatar = communicationsManager.UserServer.SetupMasterUser("Test", "User", "test");
if (masterAvatar != null)
{
world.RegionInfo.MasterAvatarAssignedUUID = masterAvatar.UUID;
world.ParcelManager.NoParcelDataFromStorage();
}
PrimitiveBaseShape shape = PrimitiveBaseShape.DefaultBox(); PrimitiveBaseShape shape = PrimitiveBaseShape.DefaultBox();
shape.Scale = new LLVector3(0.5f, 0.5f, 0.5f); shape.Scale = new LLVector3(0.5f, 0.5f, 0.5f);
LLVector3 pos = new LLVector3(129, 129, 27); LLVector3 pos = new LLVector3(138, 129, 27);
m_sceneObject = new MySceneObject(world,world.EventManager, LLUUID.Zero, world.PrimIDAllocate(), pos, shape); m_sceneObject = new MySceneObject(world, world.EventManager, LLUUID.Zero, world.PrimIDAllocate(), pos, shape);
world.AddNewEntity(m_sceneObject); world.AddNewEntity(m_sceneObject);
m_character = new MyNpcCharacter();
world.AddNewClient(m_character, false);
world.StartTimer();
m_log.WriteLine(LogPriority.NORMAL, "Press enter to quit."); m_log.WriteLine(LogPriority.NORMAL, "Press enter to quit.");
m_log.ReadLine(); m_log.ReadLine();
} }
#region conscmd_callback Members #region conscmd_callback Members