aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer
diff options
context:
space:
mode:
authorMW2007-04-01 10:19:21 +0000
committerMW2007-04-01 10:19:21 +0000
commitdef7335b6c0b88ee2b7b15194ec7fae30bd476da (patch)
tree50a86e6ece21bde1577cb5c8983941e64ee07d0e /OpenSim.RegionServer
parentAdded Packet handlers to SimClient (diff)
downloadopensim-SC_OLD-def7335b6c0b88ee2b7b15194ec7fae30bd476da.zip
opensim-SC_OLD-def7335b6c0b88ee2b7b15194ec7fae30bd476da.tar.gz
opensim-SC_OLD-def7335b6c0b88ee2b7b15194ec7fae30bd476da.tar.bz2
opensim-SC_OLD-def7335b6c0b88ee2b7b15194ec7fae30bd476da.tar.xz
More work on adding Packets handlers and tested the first handler.
Diffstat (limited to '')
-rw-r--r--OpenSim.RegionServer/OpenSimMain.cs7
-rw-r--r--OpenSim.RegionServer/SimClient.cs141
-rw-r--r--OpenSim.RegionServer/world/World.cs45
3 files changed, 115 insertions, 78 deletions
diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs
index 9d0e6ae..21f4878 100644
--- a/OpenSim.RegionServer/OpenSimMain.cs
+++ b/OpenSim.RegionServer/OpenSimMain.cs
@@ -152,6 +152,8 @@ namespace OpenSim
152 AssetCache.LoadDefaultTextureSet(); 152 AssetCache.LoadDefaultTextureSet();
153 } 153 }
154 154
155 RegisterClientPacketHandlers();
156
155 m_console.WriteLine("Main.cs:Startup() - Initialising HTTP server"); 157 m_console.WriteLine("Main.cs:Startup() - Initialising HTTP server");
156 // HttpServer = new SimCAPSHTTPServer(GridServers.GridServer, Cfg.IPListenPort); 158 // HttpServer = new SimCAPSHTTPServer(GridServers.GridServer, Cfg.IPListenPort);
157 HttpServer = new BaseHttpServer(Cfg.IPListenPort); 159 HttpServer = new BaseHttpServer(Cfg.IPListenPort);
@@ -348,6 +350,11 @@ namespace OpenSim
348 LocalWorld.Update(); 350 LocalWorld.Update();
349 } 351 }
350 352
353 protected virtual void RegisterClientPacketHandlers()
354 {
355 SimClient.AddPacketHandler(PacketType.ModifyLand, LocalWorld.ModifyTerrain);
356 }
357
351 public void RunCmd(string command, string[] cmdparams) 358 public void RunCmd(string command, string[] cmdparams)
352 { 359 {
353 switch (command) 360 switch (command)
diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs
index 94c5767..5bc5e43 100644
--- a/OpenSim.RegionServer/SimClient.cs
+++ b/OpenSim.RegionServer/SimClient.cs
@@ -82,13 +82,10 @@ namespace OpenSim
82 private bool m_sandboxMode; 82 private bool m_sandboxMode;
83 private int cachedtextureserial = 0; 83 private int cachedtextureserial = 0;
84 84
85 // local packet handler list not currently used but is here so each client could have a different handler for a packet to another client 85 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
86 // 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
87 // maybe not a very practicle example but there are various other things it could be used for.
88 // protected Dictionary<string, PacketMethod> m_packetHandlers = new Dictionary<string, PacketMethod>();
89
90 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>();
91 86
87 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>(); //local handlers for this instance
88
92 public IUserServer UserServer 89 public IUserServer UserServer
93 { 90 {
94 set 91 set
@@ -97,6 +94,38 @@ namespace OpenSim
97 } 94 }
98 } 95 }
99 96
97 public SimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, World world, Dictionary<uint, SimClient> clientThreads, AssetCache assetCache, IGridServer gridServer, OpenSimNetworkHandler application, InventoryCache inventoryCache, bool sandboxMode)
98 {
99 m_world = world;
100 m_clientThreads = clientThreads;
101 m_assetCache = assetCache;
102 m_gridServer = gridServer;
103 m_application = application;
104 m_inventoryCache = inventoryCache;
105 m_sandboxMode = sandboxMode;
106
107 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request");
108 cirpack = initialcirpack;
109 userEP = remoteEP;
110 PacketQueue = new BlockingQueue<QueItem>();
111
112 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
113 AckTimer = new System.Timers.Timer(500);
114 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
115 AckTimer.Start();
116
117 this.RegisterLocalPacketHandlers();
118
119 ClientThread = new Thread(new ThreadStart(AuthUser));
120 ClientThread.IsBackground = true;
121 ClientThread.Start();
122 }
123
124 protected virtual void RegisterLocalPacketHandlers()
125 {
126
127 }
128
100 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler) 129 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
101 { 130 {
102 bool result = false; 131 bool result = false;
@@ -111,20 +140,42 @@ namespace OpenSim
111 return result; 140 return result;
112 } 141 }
113 142
143 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
144 {
145 bool result = false;
146 lock (m_packetHandlers)
147 {
148 if (!m_packetHandlers.ContainsKey(packetType))
149 {
150 m_packetHandlers.Add(packetType, handler);
151 result = true;
152 }
153 }
154 return result;
155 }
156
114 protected virtual bool ProcessPacketMethod(Packet packet) 157 protected virtual bool ProcessPacketMethod(Packet packet)
115 { 158 {
116 bool result = false; 159 bool result = false;
117 bool found = false; 160 bool found = false;
118 PacketMethod method; 161 PacketMethod method;
119 lock (PacketHandlers) 162 if (m_packetHandlers.TryGetValue(packet.Type, out method))
120 { 163 {
121 found = PacketHandlers.TryGetValue(packet.Type, out method); 164 //there is a local handler for this packet type
165 result = method(this, packet);
122 } 166 }
123 if (found) 167 else
124 { 168 {
125 result = method(this, packet); 169 //there is not a local handler so see if there is a Global handler
170 lock (PacketHandlers)
171 {
172 found = PacketHandlers.TryGetValue(packet.Type, out method);
173 }
174 if (found)
175 {
176 result = method(this, packet);
177 }
126 } 178 }
127
128 return result; 179 return result;
129 } 180 }
130 181
@@ -161,6 +212,7 @@ namespace OpenSim
161 212
162 if (this.ProcessPacketMethod(Pack)) 213 if (this.ProcessPacketMethod(Pack))
163 { 214 {
215 //there is a handler registered that handled this packet type
164 return; 216 return;
165 } 217 }
166 else 218 else
@@ -476,46 +528,6 @@ namespace OpenSim
476 //Console.WriteLine(Pack.ToString()); 528 //Console.WriteLine(Pack.ToString());
477 m_world.RezObject(this, (RezObjectPacket)Pack); 529 m_world.RezObject(this, (RezObjectPacket)Pack);
478 break; 530 break;
479 case PacketType.ModifyLand:
480 ModifyLandPacket modify = (ModifyLandPacket)Pack;
481 //Console.WriteLine("terraform: number of parcel data blocks" + modify.ParcelData.Length);
482
483 switch (modify.ModifyBlock.Action)
484 {
485 case 1:
486 if (modify.ParcelData.Length > 0)
487 {
488 int mody = (int)modify.ParcelData[0].North;
489 int modx = (int)modify.ParcelData[0].West;
490 // Console.WriteLine("height in packet is " + modify.ModifyBlock.Height.ToString());
491 // Console.WriteLine("current height at that point is " + this.m_world.LandMap[(mody * 256) + modx].ToString());
492
493 this.m_world.LandMap[(mody * 256) + modx - 1] += 0.05f;
494 this.m_world.LandMap[(mody * 256) + modx] += 0.1f;
495 this.m_world.LandMap[(mody * 256) + modx + 1] += 0.05f;
496 this.m_world.LandMap[((mody + 1) * 256) + modx] += 0.05f;
497 this.m_world.LandMap[((mody - 1) * 256) + modx] += 0.05f;
498 m_world.RegenerateTerrain(true, modx, mody);
499 }
500 break;
501 case 2:
502 if (modify.ParcelData.Length > 0)
503 {
504 int mody = (int)modify.ParcelData[0].North;
505 int modx = (int)modify.ParcelData[0].West;
506 // Console.WriteLine("height in packet is " + modify.ModifyBlock.Height.ToString());
507 // Console.WriteLine("current height at that point is " + this.m_world.LandMap[(mody * 256) + modx].ToString());
508
509 this.m_world.LandMap[(mody * 256) + modx - 1] -= 0.05f;
510 this.m_world.LandMap[(mody * 256) + modx] -= 0.1f;
511 this.m_world.LandMap[(mody * 256) + modx + 1] -= 0.05f;
512 this.m_world.LandMap[((mody + 1) * 256) + modx] -= 0.05f;
513 this.m_world.LandMap[((mody - 1) * 256) + modx] -= 0.05f;
514 m_world.RegenerateTerrain(true, modx, mody);
515 }
516 break;
517 }
518 break;
519 case PacketType.RequestTaskInventory: 531 case PacketType.RequestTaskInventory:
520 // Console.WriteLine(Pack.ToString()); 532 // Console.WriteLine(Pack.ToString());
521 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack; 533 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
@@ -569,8 +581,6 @@ namespace OpenSim
569 } 581 }
570 } 582 }
571 break; 583 break;
572
573
574 } 584 }
575 } 585 }
576 } 586 }
@@ -777,31 +787,6 @@ namespace OpenSim
777 this.PacketQueue.Enqueue(item); 787 this.PacketQueue.Enqueue(item);
778 } 788 }
779 789
780 public SimClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, World world, Dictionary<uint, SimClient> clientThreads, AssetCache assetCache, IGridServer gridServer, OpenSimNetworkHandler application, InventoryCache inventoryCache, bool sandboxMode)
781 {
782 m_world = world;
783 m_clientThreads = clientThreads;
784 m_assetCache = assetCache;
785 m_gridServer = gridServer;
786 m_application = application;
787 m_inventoryCache = inventoryCache;
788 m_sandboxMode = sandboxMode;
789
790 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs - Started up new client thread to handle incoming request");
791 cirpack = initialcirpack;
792 userEP = remoteEP;
793 PacketQueue = new BlockingQueue<QueItem>();
794
795 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
796 AckTimer = new System.Timers.Timer(500);
797 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
798 AckTimer.Start();
799
800 ClientThread = new Thread(new ThreadStart(AuthUser));
801 ClientThread.IsBackground = true;
802 ClientThread.Start();
803 }
804
805 protected virtual void ClientLoop() 790 protected virtual void ClientLoop()
806 { 791 {
807 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("OpenSimClient.cs:ClientLoop() - Entered loop"); 792 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 82e8b8d..66247a2 100644
--- a/OpenSim.RegionServer/world/World.cs
+++ b/OpenSim.RegionServer/world/World.cs
@@ -426,5 +426,50 @@ namespace OpenSim.world
426 return true; 426 return true;
427 } 427 }
428 428
429 #region Packet Handlers
430 public bool ModifyTerrain(SimClient simClient, Packet packet)
431 {
432 ModifyLandPacket modify = (ModifyLandPacket)packet;
433
434 switch (modify.ModifyBlock.Action)
435 {
436 case 1:
437 // raise terrain
438 if (modify.ParcelData.Length > 0)
439 {
440 int mody = (int)modify.ParcelData[0].North;
441 int modx = (int)modify.ParcelData[0].West;
442 lock (LandMap)
443 {
444 LandMap[(mody * 256) + modx - 1] += 0.05f;
445 LandMap[(mody * 256) + modx] += 0.1f;
446 LandMap[(mody * 256) + modx + 1] += 0.05f;
447 LandMap[((mody + 1) * 256) + modx] += 0.05f;
448 LandMap[((mody - 1) * 256) + modx] += 0.05f;
449 }
450 RegenerateTerrain(true, modx, mody);
451 }
452 break;
453 case 2:
454 //lower terrain
455 if (modify.ParcelData.Length > 0)
456 {
457 int mody = (int)modify.ParcelData[0].North;
458 int modx = (int)modify.ParcelData[0].West;
459 lock (LandMap)
460 {
461 LandMap[(mody * 256) + modx - 1] -= 0.05f;
462 LandMap[(mody * 256) + modx] -= 0.1f;
463 LandMap[(mody * 256) + modx + 1] -= 0.05f;
464 LandMap[((mody + 1) * 256) + modx] -= 0.05f;
465 LandMap[((mody - 1) * 256) + modx] -= 0.05f;
466 }
467 RegenerateTerrain(true, modx, mody);
468 }
469 break;
470 }
471 return true;
472 }
473 #endregion
429 } 474 }
430} 475}