aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs368
1 files changed, 368 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs b/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs
new file mode 100644
index 0000000..348cd30
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/world/World.PacketHandlers.cs
@@ -0,0 +1,368 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using libsecondlife;
5using libsecondlife.Packets;
6using OpenSim.Physics.Manager;
7using OpenSim.Framework.Interfaces;
8using OpenSim.Framework.Types;
9using OpenSim.Framework.Terrain;
10using OpenSim.Framework.Inventory;
11using OpenSim.Framework.Utilities;
12using OpenSim.Assets;
13
14namespace OpenSim.world
15{
16 public partial class World
17 {
18 public void ModifyTerrain(byte action, float north, float west)
19 {
20 switch (action)
21 {
22 case 1:
23 // raise terrain
24 Terrain.raise(north, west, 10.0, 0.1);
25 RegenerateTerrain(true, (int)north, (int)west);
26 break;
27 case 2:
28 //lower terrain
29 Terrain.lower(north, west, 10.0, 0.1);
30 RegenerateTerrain(true, (int)north, (int)west);
31 break;
32 }
33 return;
34 }
35
36 public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
37 {
38 foreach (ClientView client in m_clientThreads.Values)
39 {
40 // int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y));
41 int dis = (int)client.ClientAvatar.Pos.GetDistanceTo(fromPos);
42
43 switch (type)
44 {
45 case 0: // Whisper
46 if ((dis < 10) && (dis > -10))
47 {
48 //should change so the message is sent through the avatar rather than direct to the ClientView
49 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
50 }
51 break;
52 case 1: // Say
53 if ((dis < 30) && (dis > -30))
54 {
55 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
56 }
57 break;
58 case 2: // Shout
59 if ((dis < 100) && (dis > -100))
60 {
61 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
62 }
63 break;
64
65 case 0xff: // Broadcast
66 client.SendChatMessage(message, type, fromPos, fromName, fromAgentID);
67 break;
68 }
69
70 }
71 }
72
73 public void RezObject(AssetBase primAsset, LLVector3 pos)
74 {
75 PrimData primd = new PrimData(primAsset.Data);
76 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
77 nPrim.CreateFromStorage(primd, pos, this._primCount, true);
78 this.Entities.Add(nPrim.uuid, nPrim);
79 this._primCount++;
80 }
81
82 public void DeRezObject(Packet packet, ClientView simClient)
83 {
84 DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet;
85
86 //Needs to delete object from physics at a later date
87 if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero)
88 {
89 //currently following code not used (or don't know of any case of destination being zero
90 libsecondlife.LLUUID[] DeRezEnts;
91 DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length];
92 int i = 0;
93 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
94 {
95
96 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
97 foreach (Entity ent in this.Entities.Values)
98 {
99 if (ent.localid == Data.ObjectLocalID)
100 {
101 DeRezEnts[i++] = ent.uuid;
102 this.localStorage.RemovePrim(ent.uuid);
103 KillObjectPacket kill = new KillObjectPacket();
104 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
105 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
106 kill.ObjectData[0].ID = ent.localid;
107 foreach (ClientView client in m_clientThreads.Values)
108 {
109 client.OutPacket(kill);
110 }
111 //Uncommenting this means an old UUID will be re-used, thus crashing the asset server
112 //Uncomment when prim/object UUIDs are random or such
113 //2007-03-22 - Randomskk
114 //this._primCount--;
115 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE, "Deleted UUID " + ent.uuid);
116 }
117 }
118 }
119 foreach (libsecondlife.LLUUID uuid in DeRezEnts)
120 {
121 lock (Entities)
122 {
123 Entities.Remove(uuid);
124 }
125 }
126 }
127 else
128 {
129 foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData)
130 {
131 Entity selectedEnt = null;
132 //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString());
133 foreach (Entity ent in this.Entities.Values)
134 {
135 if (ent.localid == Data.ObjectLocalID)
136 {
137 AssetBase primAsset = new AssetBase();
138 primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid
139 primAsset.InvType = 6;
140 primAsset.Type = 6;
141 primAsset.Name = "Prim";
142 primAsset.Description = "";
143 primAsset.Data = ((Primitive)ent).GetByteArray();
144 this._assetCache.AddAsset(primAsset);
145 this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset);
146 selectedEnt = ent;
147 break;
148 }
149 }
150 if (selectedEnt != null)
151 {
152 this.localStorage.RemovePrim(selectedEnt.uuid);
153 KillObjectPacket kill = new KillObjectPacket();
154 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
155 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
156 kill.ObjectData[0].ID = selectedEnt.localid;
157 foreach (ClientView client in m_clientThreads.Values)
158 {
159 client.OutPacket(kill);
160 }
161 lock (Entities)
162 {
163 Entities.Remove(selectedEnt.uuid);
164 }
165 }
166 }
167 }
168
169 }
170
171 public void SendAvatarsToClient(ClientView remoteClient)
172 {
173 foreach (ClientView client in m_clientThreads.Values)
174 {
175 if (client.AgentID != remoteClient.AgentID)
176 {
177 // ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket();
178 // RemoteClient.OutPacket(objupdate);
179 client.ClientAvatar.SendUpdateToOtherClient(remoteClient.ClientAvatar);
180 client.ClientAvatar.SendAppearanceToOtherAgent(remoteClient.ClientAvatar);
181 }
182 }
183 }
184
185 public void LinkObjects(uint parentPrim, List<uint> childPrims)
186 {
187 Primitive parentprim = null;
188 foreach (Entity ent in Entities.Values)
189 {
190 if (ent.localid == parentPrim)
191 {
192 parentprim = (OpenSim.world.Primitive)ent;
193
194 }
195 }
196
197 for (int i = 0; i < childPrims.Count; i++)
198 {
199 uint childId = childPrims[i];
200 foreach (Entity ent in Entities.Values)
201 {
202 if (ent.localid == childId)
203 {
204 ((OpenSim.world.Primitive)ent).MakeParent(parentprim);
205 }
206 }
207 }
208
209 }
210
211 public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
212 {
213 foreach (Entity ent in Entities.Values)
214 {
215 if (ent.localid == primLocalID)
216 {
217 ((OpenSim.world.Primitive)ent).UpdateShape(shapeBlock);
218 break;
219 }
220 }
221 }
222
223 public void SelectPrim(uint primLocalID, ClientView remoteClient)
224 {
225 foreach (Entity ent in Entities.Values)
226 {
227 if (ent.localid == primLocalID)
228 {
229 ((OpenSim.world.Primitive)ent).GetProperites(remoteClient);
230 break;
231 }
232 }
233 }
234
235 public void UpdatePrimFlags(uint localID, Packet packet, ClientView remoteClient)
236 {
237 foreach (Entity ent in Entities.Values)
238 {
239 if (ent.localid == localID)
240 {
241 ((OpenSim.world.Primitive)ent).UpdateObjectFlags((ObjectFlagUpdatePacket) packet);
242 break;
243 }
244 }
245 }
246
247 public void UpdatePrimTexture(uint localID, byte[] texture, ClientView remoteClient)
248 {
249 foreach (Entity ent in Entities.Values)
250 {
251 if (ent.localid == localID)
252 {
253 ((OpenSim.world.Primitive)ent).UpdateTexture(texture);
254 break;
255 }
256 }
257 }
258
259 public void UpdatePrimPosition(uint localID, LLVector3 pos, ClientView remoteClient)
260 {
261 foreach (Entity ent in Entities.Values)
262 {
263 if (ent.localid == localID)
264 {
265 ((OpenSim.world.Primitive)ent).UpdatePosition(pos);
266 break;
267 }
268 }
269 }
270
271 public void UpdatePrimRotation(uint localID, LLQuaternion rot, ClientView remoteClient)
272 {
273 foreach (Entity ent in Entities.Values)
274 {
275 if (ent.localid == localID)
276 {
277 ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
278 ((OpenSim.world.Primitive)ent).UpdateFlag = true;
279 break;
280 }
281 }
282 }
283
284 public void UpdatePrimScale(uint localID, LLVector3 scale, ClientView remoteClient)
285 {
286 foreach (Entity ent in Entities.Values)
287 {
288 if (ent.localid == localID)
289 {
290 ((OpenSim.world.Primitive)ent).Scale = scale;
291 break;
292 }
293 }
294 }
295
296 /*
297 public void RequestMapBlock(ClientView simClient, int minX, int minY, int maxX, int maxY)
298 {
299 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
300 if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY)))
301 {
302 MapBlockReplyPacket mapReply = new MapBlockReplyPacket();
303 mapReply.AgentData.AgentID = simClient.AgentID;
304 mapReply.AgentData.Flags = 0;
305 mapReply.Data = new MapBlockReplyPacket.DataBlock[1];
306 mapReply.Data[0] = new MapBlockReplyPacket.DataBlock();
307 mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007");
308 mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX;
309 mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY;
310 mapReply.Data[0].WaterHeight = (byte)m_regInfo.RegionWaterHeight;
311 mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName);
312 mapReply.Data[0].RegionFlags = 72458694;
313 mapReply.Data[0].Access = 13;
314 mapReply.Data[0].Agents = 1; //should send number of clients connected
315 simClient.OutPacket(mapReply);
316 }
317 }
318 public bool RezObjectHandler(ClientView simClient, Packet packet)
319 {
320 RezObjectPacket rezPacket = (RezObjectPacket)packet;
321 AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID);
322 if (inven != null)
323 {
324 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
325 {
326 AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
327 if (asset != null)
328 {
329 PrimData primd = new PrimData(asset.Data);
330 Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this);
331 nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true);
332 this.Entities.Add(nPrim.uuid, nPrim);
333 this._primCount++;
334 this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID);
335 }
336 }
337 }
338 return true;
339 }
340 public bool ModifyTerrain(ClientView simClient, Packet packet)
341 {
342 ModifyLandPacket modify = (ModifyLandPacket)packet;
343
344 switch (modify.ModifyBlock.Action)
345 {
346 case 1:
347 // raise terrain
348 if (modify.ParcelData.Length > 0)
349 {
350 Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
351 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
352 }
353 break;
354 case 2:
355 //lower terrain
356 if (modify.ParcelData.Length > 0)
357 {
358 Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1);
359 RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West);
360 }
361 break;
362 }
363 return true;
364 }
365 */
366
367 }
368}