From def7335b6c0b88ee2b7b15194ec7fae30bd476da Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 1 Apr 2007 10:19:21 +0000 Subject: [PATCH] More work on adding Packets handlers and tested the first handler. --- OpenSim.RegionServer/OpenSimMain.cs | 7 ++ OpenSim.RegionServer/SimClient.cs | 143 +++++++++++++--------------- OpenSim.RegionServer/world/World.cs | 45 +++++++++ 3 files changed, 116 insertions(+), 79 deletions(-) diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs index 9d0e6ae19d..21f487825d 100644 --- a/OpenSim.RegionServer/OpenSimMain.cs +++ b/OpenSim.RegionServer/OpenSimMain.cs @@ -152,6 +152,8 @@ namespace OpenSim AssetCache.LoadDefaultTextureSet(); } + RegisterClientPacketHandlers(); + m_console.WriteLine("Main.cs:Startup() - Initialising HTTP server"); // HttpServer = new SimCAPSHTTPServer(GridServers.GridServer, Cfg.IPListenPort); HttpServer = new BaseHttpServer(Cfg.IPListenPort); @@ -348,6 +350,11 @@ namespace OpenSim LocalWorld.Update(); } + protected virtual void RegisterClientPacketHandlers() + { + SimClient.AddPacketHandler(PacketType.ModifyLand, LocalWorld.ModifyTerrain); + } + public void RunCmd(string command, string[] cmdparams) { switch (command) diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs index 94c5767739..5bc5e4357a 100644 --- a/OpenSim.RegionServer/SimClient.cs +++ b/OpenSim.RegionServer/SimClient.cs @@ -82,13 +82,10 @@ namespace OpenSim private bool m_sandboxMode; 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 m_packetHandlers = new Dictionary(); - - protected static Dictionary PacketHandlers = new Dictionary(); + protected static Dictionary PacketHandlers = new Dictionary(); //Global/static handlers for all clients + protected Dictionary m_packetHandlers = new Dictionary(); //local handlers for this instance + public IUserServer UserServer { set @@ -97,6 +94,38 @@ namespace OpenSim } } + public SimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, World world, Dictionary clientThreads, AssetCache assetCache, IGridServer gridServer, OpenSimNetworkHandler application, InventoryCache inventoryCache, bool sandboxMode) + { + m_world = world; + m_clientThreads = clientThreads; + m_assetCache = assetCache; + m_gridServer = gridServer; + m_application = application; + m_inventoryCache = inventoryCache; + m_sandboxMode = sandboxMode; + + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); + cirpack = initialcirpack; + userEP = remoteEP; + PacketQueue = new BlockingQueue(); + + this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache); + AckTimer = new System.Timers.Timer(500); + AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); + AckTimer.Start(); + + this.RegisterLocalPacketHandlers(); + + ClientThread = new Thread(new ThreadStart(AuthUser)); + ClientThread.IsBackground = true; + ClientThread.Start(); + } + + protected virtual void RegisterLocalPacketHandlers() + { + + } + public static bool AddPacketHandler(PacketType packetType, PacketMethod handler) { bool result = false; @@ -111,20 +140,42 @@ namespace OpenSim return result; } + public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler) + { + bool result = false; + lock (m_packetHandlers) + { + if (!m_packetHandlers.ContainsKey(packetType)) + { + m_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) + if (m_packetHandlers.TryGetValue(packet.Type, out method)) { + //there is a local handler for this packet type result = method(this, packet); } - + else + { + //there is not a local handler so see if there is a Global handler + lock (PacketHandlers) + { + found = PacketHandlers.TryGetValue(packet.Type, out method); + } + if (found) + { + result = method(this, packet); + } + } return result; } @@ -161,6 +212,7 @@ namespace OpenSim if (this.ProcessPacketMethod(Pack)) { + //there is a handler registered that handled this packet type return; } else @@ -476,46 +528,6 @@ namespace OpenSim //Console.WriteLine(Pack.ToString()); m_world.RezObject(this, (RezObjectPacket)Pack); break; - case PacketType.ModifyLand: - ModifyLandPacket modify = (ModifyLandPacket)Pack; - //Console.WriteLine("terraform: number of parcel data blocks" + modify.ParcelData.Length); - - switch (modify.ModifyBlock.Action) - { - case 1: - if (modify.ParcelData.Length > 0) - { - int mody = (int)modify.ParcelData[0].North; - int modx = (int)modify.ParcelData[0].West; - // 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()); - - 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 + 1] += 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); - } - break; - case 2: - if (modify.ParcelData.Length > 0) - { - int mody = (int)modify.ParcelData[0].North; - int modx = (int)modify.ParcelData[0].West; - // 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()); - - 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 + 1] -= 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); - } - break; - } - break; case PacketType.RequestTaskInventory: // Console.WriteLine(Pack.ToString()); RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack; @@ -569,8 +581,6 @@ namespace OpenSim } } break; - - } } } @@ -777,31 +787,6 @@ namespace OpenSim this.PacketQueue.Enqueue(item); } - public SimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, World world, Dictionary clientThreads, AssetCache assetCache, IGridServer gridServer, OpenSimNetworkHandler application, InventoryCache inventoryCache, bool sandboxMode) - { - m_world = world; - m_clientThreads = clientThreads; - m_assetCache = assetCache; - m_gridServer = gridServer; - m_application = application; - m_inventoryCache = inventoryCache; - m_sandboxMode = sandboxMode; - - OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request"); - cirpack = initialcirpack; - userEP = remoteEP; - PacketQueue = new BlockingQueue(); - - this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache); - AckTimer = new System.Timers.Timer(500); - AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); - AckTimer.Start(); - - ClientThread = new Thread(new ThreadStart(AuthUser)); - ClientThread.IsBackground = true; - ClientThread.Start(); - } - protected virtual void ClientLoop() { OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 82e8b8dfd7..66247a23f2 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -426,5 +426,50 @@ namespace OpenSim.world return true; } + #region Packet Handlers + public bool ModifyTerrain(SimClient simClient, Packet packet) + { + ModifyLandPacket modify = (ModifyLandPacket)packet; + + switch (modify.ModifyBlock.Action) + { + case 1: + // raise terrain + if (modify.ParcelData.Length > 0) + { + int mody = (int)modify.ParcelData[0].North; + int modx = (int)modify.ParcelData[0].West; + lock (LandMap) + { + LandMap[(mody * 256) + modx - 1] += 0.05f; + LandMap[(mody * 256) + modx] += 0.1f; + LandMap[(mody * 256) + modx + 1] += 0.05f; + LandMap[((mody + 1) * 256) + modx] += 0.05f; + LandMap[((mody - 1) * 256) + modx] += 0.05f; + } + RegenerateTerrain(true, modx, mody); + } + break; + case 2: + //lower terrain + if (modify.ParcelData.Length > 0) + { + int mody = (int)modify.ParcelData[0].North; + int modx = (int)modify.ParcelData[0].West; + lock (LandMap) + { + LandMap[(mody * 256) + modx - 1] -= 0.05f; + LandMap[(mody * 256) + modx] -= 0.1f; + LandMap[(mody * 256) + modx + 1] -= 0.05f; + LandMap[((mody + 1) * 256) + modx] -= 0.05f; + LandMap[((mody - 1) * 256) + modx] -= 0.05f; + } + RegenerateTerrain(true, modx, mody); + } + break; + } + return true; + } + #endregion } }