diff options
Diffstat (limited to 'OpenSim.RegionServer/world/WorldPacketHandlers.cs')
-rw-r--r-- | OpenSim.RegionServer/world/WorldPacketHandlers.cs | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/WorldPacketHandlers.cs b/OpenSim.RegionServer/world/WorldPacketHandlers.cs new file mode 100644 index 0000000..a155ffe --- /dev/null +++ b/OpenSim.RegionServer/world/WorldPacketHandlers.cs | |||
@@ -0,0 +1,200 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using libsecondlife; | ||
5 | using libsecondlife.Packets; | ||
6 | using OpenSim.Physics.Manager; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Assets; | ||
9 | using OpenSim.Framework.Terrain; | ||
10 | using OpenSim.Framework.Inventory; | ||
11 | using OpenSim.Assets; | ||
12 | |||
13 | namespace OpenSim.world | ||
14 | { | ||
15 | partial class World | ||
16 | { | ||
17 | public bool ModifyTerrain(SimClient simClient, Packet packet) | ||
18 | { | ||
19 | ModifyLandPacket modify = (ModifyLandPacket)packet; | ||
20 | |||
21 | switch (modify.ModifyBlock.Action) | ||
22 | { | ||
23 | case 1: | ||
24 | // raise terrain | ||
25 | if (modify.ParcelData.Length > 0) | ||
26 | { | ||
27 | int mody = (int)modify.ParcelData[0].North; | ||
28 | int modx = (int)modify.ParcelData[0].West; | ||
29 | lock (LandMap) | ||
30 | { | ||
31 | LandMap[(mody * 256) + modx - 1] += 0.05f; | ||
32 | LandMap[(mody * 256) + modx] += 0.1f; | ||
33 | LandMap[(mody * 256) + modx + 1] += 0.05f; | ||
34 | LandMap[((mody + 1) * 256) + modx] += 0.05f; | ||
35 | LandMap[((mody - 1) * 256) + modx] += 0.05f; | ||
36 | } | ||
37 | RegenerateTerrain(true, modx, mody); | ||
38 | } | ||
39 | break; | ||
40 | case 2: | ||
41 | //lower terrain | ||
42 | if (modify.ParcelData.Length > 0) | ||
43 | { | ||
44 | int mody = (int)modify.ParcelData[0].North; | ||
45 | int modx = (int)modify.ParcelData[0].West; | ||
46 | lock (LandMap) | ||
47 | { | ||
48 | LandMap[(mody * 256) + modx - 1] -= 0.05f; | ||
49 | LandMap[(mody * 256) + modx] -= 0.1f; | ||
50 | LandMap[(mody * 256) + modx + 1] -= 0.05f; | ||
51 | LandMap[((mody + 1) * 256) + modx] -= 0.05f; | ||
52 | LandMap[((mody - 1) * 256) + modx] -= 0.05f; | ||
53 | } | ||
54 | RegenerateTerrain(true, modx, mody); | ||
55 | } | ||
56 | break; | ||
57 | } | ||
58 | return true; | ||
59 | } | ||
60 | |||
61 | public bool SimChat(SimClient simClient, Packet packet) | ||
62 | { | ||
63 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
64 | ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)packet; | ||
65 | if (Helpers.FieldToString(inchatpack.ChatData.Message) == "") | ||
66 | { | ||
67 | //empty message so don't bother with it | ||
68 | return true; | ||
69 | } | ||
70 | |||
71 | libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); | ||
72 | reply.ChatData.Audible = 1; | ||
73 | reply.ChatData.Message = inchatpack.ChatData.Message; | ||
74 | reply.ChatData.ChatType = 1; | ||
75 | reply.ChatData.SourceType = 1; | ||
76 | reply.ChatData.Position = simClient.ClientAvatar.Pos; | ||
77 | reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0"); | ||
78 | reply.ChatData.OwnerID = simClient.AgentID; | ||
79 | reply.ChatData.SourceID = simClient.AgentID; | ||
80 | foreach (SimClient client in m_clientThreads.Values) | ||
81 | { | ||
82 | client.OutPacket(reply); | ||
83 | } | ||
84 | return true; | ||
85 | } | ||
86 | |||
87 | public bool RezObject(SimClient simClient, Packet packet) | ||
88 | { | ||
89 | RezObjectPacket rezPacket = (RezObjectPacket)packet; | ||
90 | AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID); | ||
91 | if (inven != null) | ||
92 | { | ||
93 | if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID)) | ||
94 | { | ||
95 | AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID); | ||
96 | if (asset != null) | ||
97 | { | ||
98 | PrimData primd = new PrimData(asset.Data); | ||
99 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
100 | nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true); | ||
101 | this.Entities.Add(nPrim.uuid, nPrim); | ||
102 | this._primCount++; | ||
103 | this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | return true; | ||
108 | } | ||
109 | |||
110 | public bool DeRezObject(SimClient simClient, Packet packet) | ||
111 | { | ||
112 | DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; | ||
113 | |||
114 | //Needs to delete object from physics at a later date | ||
115 | if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) | ||
116 | { | ||
117 | //currently following code not used (or don't know of any case of destination being zero | ||
118 | libsecondlife.LLUUID[] DeRezEnts; | ||
119 | DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length]; | ||
120 | int i = 0; | ||
121 | foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) | ||
122 | { | ||
123 | |||
124 | //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); | ||
125 | foreach (Entity ent in this.Entities.Values) | ||
126 | { | ||
127 | if (ent.localid == Data.ObjectLocalID) | ||
128 | { | ||
129 | DeRezEnts[i++] = ent.uuid; | ||
130 | this.localStorage.RemovePrim(ent.uuid); | ||
131 | KillObjectPacket kill = new KillObjectPacket(); | ||
132 | kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; | ||
133 | kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); | ||
134 | kill.ObjectData[0].ID = ent.localid; | ||
135 | foreach (SimClient client in m_clientThreads.Values) | ||
136 | { | ||
137 | client.OutPacket(kill); | ||
138 | } | ||
139 | //Uncommenting this means an old UUID will be re-used, thus crashing the asset server | ||
140 | //Uncomment when prim/object UUIDs are random or such | ||
141 | //2007-03-22 - Randomskk | ||
142 | //this._primCount--; | ||
143 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Deleted UUID " + ent.uuid); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | foreach (libsecondlife.LLUUID uuid in DeRezEnts) | ||
148 | { | ||
149 | lock (Entities) | ||
150 | { | ||
151 | Entities.Remove(uuid); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) | ||
158 | { | ||
159 | Entity selectedEnt = null; | ||
160 | //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); | ||
161 | foreach (Entity ent in this.Entities.Values) | ||
162 | { | ||
163 | if (ent.localid == Data.ObjectLocalID) | ||
164 | { | ||
165 | AssetBase primAsset = new AssetBase(); | ||
166 | primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid | ||
167 | primAsset.InvType = 6; | ||
168 | primAsset.Type = 6; | ||
169 | primAsset.Name = "Prim"; | ||
170 | primAsset.Description = ""; | ||
171 | primAsset.Data = ((Primitive)ent).GetByteArray(); | ||
172 | this._assetCache.AddAsset(primAsset); | ||
173 | this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset); | ||
174 | selectedEnt = ent; | ||
175 | break; | ||
176 | } | ||
177 | } | ||
178 | if (selectedEnt != null) | ||
179 | { | ||
180 | this.localStorage.RemovePrim(selectedEnt.uuid); | ||
181 | KillObjectPacket kill = new KillObjectPacket(); | ||
182 | kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; | ||
183 | kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); | ||
184 | kill.ObjectData[0].ID = selectedEnt.localid; | ||
185 | foreach (SimClient client in m_clientThreads.Values) | ||
186 | { | ||
187 | client.OutPacket(kill); | ||
188 | } | ||
189 | lock (Entities) | ||
190 | { | ||
191 | Entities.Remove(selectedEnt.uuid); | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | return true; | ||
197 | } | ||
198 | |||
199 | } | ||
200 | } | ||