Added Packet handlers to SimClient

0.1-prestable
MW 2007-03-31 21:18:05 +00:00
parent af93263a3b
commit 548b125b7c
2 changed files with 437 additions and 388 deletions

View File

@ -50,6 +50,7 @@ using OpenSim.Servers;
namespace OpenSim namespace OpenSim
{ {
public class OpenSimMain : OpenSimNetworkHandler, conscmd_callback public class OpenSimMain : OpenSimNetworkHandler, conscmd_callback
{ {
private PhysicsManager physManager; private PhysicsManager physManager;

View File

@ -43,6 +43,8 @@ using OpenSim.Assets;
namespace OpenSim namespace OpenSim
{ {
public delegate bool PacketMethod(SimClient simClient, Packet packet);
/// <summary> /// <summary>
/// Handles new client connections /// Handles new client connections
/// Constructor takes a single Packet and authenticates everything /// Constructor takes a single Packet and authenticates everything
@ -80,6 +82,12 @@ namespace OpenSim
private bool m_sandboxMode; private bool m_sandboxMode;
private int cachedtextureserial = 0; private int cachedtextureserial = 0;
// local packet handler list not currently used but is here so each client could have a different handler for a packet to another client
// this is so we could do such things as have multiple world objects in a sim (or multiple "sims" handled by one server and different clients in different worlds
// maybe not a very practicle example but there are various other things it could be used for.
// protected Dictionary<string, PacketMethod> m_packetHandlers = new Dictionary<string, PacketMethod>();
protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>();
public IUserServer UserServer public IUserServer UserServer
{ {
@ -89,6 +97,37 @@ namespace OpenSim
} }
} }
public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
{
bool result = false;
lock (PacketHandlers)
{
if (!PacketHandlers.ContainsKey(packetType))
{
PacketHandlers.Add(packetType, handler);
result = true;
}
}
return result;
}
protected virtual bool ProcessPacketMethod(Packet packet)
{
bool result = false;
bool found = false;
PacketMethod method;
lock (PacketHandlers)
{
found = PacketHandlers.TryGetValue(packet.Type, out method);
}
if (found)
{
result = method(this, packet);
}
return result;
}
private void ack_pack(Packet Pack) private void ack_pack(Packet Pack)
{ {
//libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket(); //libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket();
@ -112,7 +151,6 @@ namespace OpenSim
protected virtual void ProcessInPacket(Packet Pack) protected virtual void ProcessInPacket(Packet Pack)
{ {
ack_pack(Pack); ack_pack(Pack);
System.Text.Encoding _enc = System.Text.Encoding.ASCII;
if (debug) if (debug)
{ {
if (Pack.Type != PacketType.AgentUpdate) if (Pack.Type != PacketType.AgentUpdate)
@ -120,6 +158,15 @@ namespace OpenSim
Console.WriteLine(Pack.Type.ToString()); Console.WriteLine(Pack.Type.ToString());
} }
} }
if (this.ProcessPacketMethod(Pack))
{
return;
}
else
{
System.Text.Encoding _enc = System.Text.Encoding.ASCII;
switch (Pack.Type) switch (Pack.Type)
{ {
case PacketType.CompleteAgentMovement: case PacketType.CompleteAgentMovement:
@ -438,16 +485,16 @@ namespace OpenSim
case 1: case 1:
if (modify.ParcelData.Length > 0) if (modify.ParcelData.Length > 0)
{ {
int mody = (int) modify.ParcelData[0].North; int mody = (int)modify.ParcelData[0].North;
int modx = (int) modify.ParcelData[0].West; int modx = (int)modify.ParcelData[0].West;
// Console.WriteLine("height in packet is " + modify.ModifyBlock.Height.ToString()); // Console.WriteLine("height in packet is " + modify.ModifyBlock.Height.ToString());
// Console.WriteLine("current height at that point is " + this.m_world.LandMap[(mody * 256) + modx].ToString()); // Console.WriteLine("current height at that point is " + this.m_world.LandMap[(mody * 256) + modx].ToString());
this.m_world.LandMap[(mody * 256) + modx -1 ] += 0.05f; this.m_world.LandMap[(mody * 256) + modx - 1] += 0.05f;
this.m_world.LandMap[(mody * 256) + modx] += 0.1f; this.m_world.LandMap[(mody * 256) + modx] += 0.1f;
this.m_world.LandMap[(mody * 256) + modx + 1] += 0.05f; this.m_world.LandMap[(mody * 256) + modx + 1] += 0.05f;
this.m_world.LandMap[((mody+1) * 256) + modx] += 0.05f; this.m_world.LandMap[((mody + 1) * 256) + modx] += 0.05f;
this.m_world.LandMap[((mody -1) * 256) + modx] += 0.05f; this.m_world.LandMap[((mody - 1) * 256) + modx] += 0.05f;
m_world.RegenerateTerrain(true, modx, mody); m_world.RegenerateTerrain(true, modx, mody);
} }
break; break;
@ -526,6 +573,7 @@ namespace OpenSim
} }
} }
}
private void ResendUnacked() private void ResendUnacked()
{ {
@ -744,7 +792,7 @@ namespace OpenSim
userEP = remoteEP; userEP = remoteEP;
PacketQueue = new BlockingQueue<QueItem>(); PacketQueue = new BlockingQueue<QueItem>();
this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache ); this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
AckTimer = new System.Timers.Timer(500); AckTimer = new System.Timers.Timer(500);
AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
AckTimer.Start(); AckTimer.Start();