aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/SimClient.cs
diff options
context:
space:
mode:
authorMW2007-04-01 10:19:21 +0000
committerMW2007-04-01 10:19:21 +0000
commitdef7335b6c0b88ee2b7b15194ec7fae30bd476da (patch)
tree50a86e6ece21bde1577cb5c8983941e64ee07d0e /OpenSim.RegionServer/SimClient.cs
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 'OpenSim.RegionServer/SimClient.cs')
-rw-r--r--OpenSim.RegionServer/SimClient.cs141
1 files changed, 63 insertions, 78 deletions
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");