diff options
author | MW | 2007-05-16 12:44:58 +0000 |
---|---|---|
committer | MW | 2007-05-16 12:44:58 +0000 |
commit | 3d93d390485075345442b9b5ea35eed88a9cab49 (patch) | |
tree | a51cdb72cd310ae3f579650886836ddc0211d986 /OpenSim.RegionServer/world/World.PacketHandlers.cs | |
parent | made QueItem a nested class in SimClient. (diff) | |
download | opensim-SC-3d93d390485075345442b9b5ea35eed88a9cab49.zip opensim-SC-3d93d390485075345442b9b5ea35eed88a9cab49.tar.gz opensim-SC-3d93d390485075345442b9b5ea35eed88a9cab49.tar.bz2 opensim-SC-3d93d390485075345442b9b5ea35eed88a9cab49.tar.xz |
started to refactor startup code and to move udp server code out to its own class (currently not being used though) so that a single instance can handle multiple regions (each will need to be listening on a separate udp port)
Diffstat (limited to 'OpenSim.RegionServer/world/World.PacketHandlers.cs')
-rw-r--r-- | OpenSim.RegionServer/world/World.PacketHandlers.cs | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/world/World.PacketHandlers.cs b/OpenSim.RegionServer/world/World.PacketHandlers.cs new file mode 100644 index 0000000..2036bc6 --- /dev/null +++ b/OpenSim.RegionServer/world/World.PacketHandlers.cs | |||
@@ -0,0 +1,229 @@ | |||
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.Types; | ||
9 | using OpenSim.Framework.Terrain; | ||
10 | using OpenSim.Framework.Inventory; | ||
11 | using OpenSim.Framework.Utilities; | ||
12 | using OpenSim.Assets; | ||
13 | |||
14 | namespace OpenSim.world | ||
15 | { | ||
16 | partial class World | ||
17 | { | ||
18 | public bool ModifyTerrain(SimClient simClient, Packet packet) | ||
19 | { | ||
20 | ModifyLandPacket modify = (ModifyLandPacket)packet; | ||
21 | |||
22 | switch (modify.ModifyBlock.Action) | ||
23 | { | ||
24 | case 1: | ||
25 | // raise terrain | ||
26 | if (modify.ParcelData.Length > 0) | ||
27 | { | ||
28 | Terrain.raise(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); | ||
29 | RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); | ||
30 | } | ||
31 | break; | ||
32 | case 2: | ||
33 | //lower terrain | ||
34 | if (modify.ParcelData.Length > 0) | ||
35 | { | ||
36 | Terrain.lower(modify.ParcelData[0].North, modify.ParcelData[0].West, 10.0, 0.1); | ||
37 | RegenerateTerrain(true, (int)modify.ParcelData[0].North, (int)modify.ParcelData[0].West); | ||
38 | } | ||
39 | break; | ||
40 | } | ||
41 | return true; | ||
42 | } | ||
43 | |||
44 | public bool SimChat(SimClient simClient, Packet packet) | ||
45 | { | ||
46 | System.Text.Encoding enc = System.Text.Encoding.ASCII; | ||
47 | ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)packet; | ||
48 | if (Util.FieldToString(inchatpack.ChatData.Message) == "") | ||
49 | { | ||
50 | //empty message so don't bother with it | ||
51 | return true; | ||
52 | } | ||
53 | |||
54 | libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket(); | ||
55 | reply.ChatData.Audible = 1; | ||
56 | reply.ChatData.Message = inchatpack.ChatData.Message; | ||
57 | reply.ChatData.ChatType = inchatpack.ChatData.Type; | ||
58 | reply.ChatData.SourceType = 1; | ||
59 | reply.ChatData.Position = simClient.ClientAvatar.Pos; | ||
60 | reply.ChatData.FromName = enc.GetBytes(simClient.ClientAvatar.firstname + " " + simClient.ClientAvatar.lastname + "\0"); | ||
61 | reply.ChatData.OwnerID = simClient.AgentID; | ||
62 | reply.ChatData.SourceID = simClient.AgentID; | ||
63 | foreach (SimClient client in m_clientThreads.Values) | ||
64 | { | ||
65 | switch (inchatpack.ChatData.Type) | ||
66 | { | ||
67 | case 0: | ||
68 | int dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); | ||
69 | if ((dis < 10) && (dis > -10)) | ||
70 | { | ||
71 | client.OutPacket(reply); | ||
72 | } | ||
73 | break; | ||
74 | case 1: | ||
75 | dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); | ||
76 | if ((dis < 30) && (dis > -30)) | ||
77 | { | ||
78 | client.OutPacket(reply); | ||
79 | } | ||
80 | break; | ||
81 | case 2: | ||
82 | dis = Util.fast_distance2d((int)(client.ClientAvatar.Pos.X - simClient.ClientAvatar.Pos.X), (int)(client.ClientAvatar.Pos.Y - simClient.ClientAvatar.Pos.Y)); | ||
83 | if ((dis < 100) && (dis > -100)) | ||
84 | { | ||
85 | client.OutPacket(reply); | ||
86 | } | ||
87 | break; | ||
88 | } | ||
89 | |||
90 | } | ||
91 | return true; | ||
92 | } | ||
93 | |||
94 | public bool RezObject(SimClient simClient, Packet packet) | ||
95 | { | ||
96 | RezObjectPacket rezPacket = (RezObjectPacket)packet; | ||
97 | AgentInventory inven = this._inventoryCache.GetAgentsInventory(simClient.AgentID); | ||
98 | if (inven != null) | ||
99 | { | ||
100 | if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID)) | ||
101 | { | ||
102 | AssetBase asset = this._assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID); | ||
103 | if (asset != null) | ||
104 | { | ||
105 | PrimData primd = new PrimData(asset.Data); | ||
106 | Primitive nPrim = new Primitive(m_clientThreads, m_regionHandle, this); | ||
107 | nPrim.CreateFromStorage(primd, rezPacket.RezData.RayEnd, this._primCount, true); | ||
108 | this.Entities.Add(nPrim.uuid, nPrim); | ||
109 | this._primCount++; | ||
110 | this._inventoryCache.DeleteInventoryItem(simClient, rezPacket.InventoryData.ItemID); | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | return true; | ||
115 | } | ||
116 | |||
117 | public bool DeRezObject(SimClient simClient, Packet packet) | ||
118 | { | ||
119 | DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; | ||
120 | |||
121 | //Needs to delete object from physics at a later date | ||
122 | if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) | ||
123 | { | ||
124 | //currently following code not used (or don't know of any case of destination being zero | ||
125 | libsecondlife.LLUUID[] DeRezEnts; | ||
126 | DeRezEnts = new libsecondlife.LLUUID[DeRezPacket.ObjectData.Length]; | ||
127 | int i = 0; | ||
128 | foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) | ||
129 | { | ||
130 | |||
131 | //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); | ||
132 | foreach (Entity ent in this.Entities.Values) | ||
133 | { | ||
134 | if (ent.localid == Data.ObjectLocalID) | ||
135 | { | ||
136 | DeRezEnts[i++] = ent.uuid; | ||
137 | this.localStorage.RemovePrim(ent.uuid); | ||
138 | KillObjectPacket kill = new KillObjectPacket(); | ||
139 | kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; | ||
140 | kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); | ||
141 | kill.ObjectData[0].ID = ent.localid; | ||
142 | foreach (SimClient client in m_clientThreads.Values) | ||
143 | { | ||
144 | client.OutPacket(kill); | ||
145 | } | ||
146 | //Uncommenting this means an old UUID will be re-used, thus crashing the asset server | ||
147 | //Uncomment when prim/object UUIDs are random or such | ||
148 | //2007-03-22 - Randomskk | ||
149 | //this._primCount--; | ||
150 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE,"Deleted UUID " + ent.uuid); | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | foreach (libsecondlife.LLUUID uuid in DeRezEnts) | ||
155 | { | ||
156 | lock (Entities) | ||
157 | { | ||
158 | Entities.Remove(uuid); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | foreach (DeRezObjectPacket.ObjectDataBlock Data in DeRezPacket.ObjectData) | ||
165 | { | ||
166 | Entity selectedEnt = null; | ||
167 | //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("LocalID:" + Data.ObjectLocalID.ToString()); | ||
168 | foreach (Entity ent in this.Entities.Values) | ||
169 | { | ||
170 | if (ent.localid == Data.ObjectLocalID) | ||
171 | { | ||
172 | AssetBase primAsset = new AssetBase(); | ||
173 | primAsset.FullID = LLUUID.Random();//DeRezPacket.AgentBlock.TransactionID.Combine(LLUUID.Zero); //should be combining with securesessionid | ||
174 | primAsset.InvType = 6; | ||
175 | primAsset.Type = 6; | ||
176 | primAsset.Name = "Prim"; | ||
177 | primAsset.Description = ""; | ||
178 | primAsset.Data = ((Primitive)ent).GetByteArray(); | ||
179 | this._assetCache.AddAsset(primAsset); | ||
180 | this._inventoryCache.AddNewInventoryItem(simClient, DeRezPacket.AgentBlock.DestinationID, primAsset); | ||
181 | selectedEnt = ent; | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | if (selectedEnt != null) | ||
186 | { | ||
187 | this.localStorage.RemovePrim(selectedEnt.uuid); | ||
188 | KillObjectPacket kill = new KillObjectPacket(); | ||
189 | kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1]; | ||
190 | kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock(); | ||
191 | kill.ObjectData[0].ID = selectedEnt.localid; | ||
192 | foreach (SimClient client in m_clientThreads.Values) | ||
193 | { | ||
194 | client.OutPacket(kill); | ||
195 | } | ||
196 | lock (Entities) | ||
197 | { | ||
198 | Entities.Remove(selectedEnt.uuid); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | return true; | ||
204 | } | ||
205 | |||
206 | public void RequestMapBlock(SimClient simClient, int minX, int minY, int maxX, int maxY) | ||
207 | { | ||
208 | System.Text.Encoding _enc = System.Text.Encoding.ASCII; | ||
209 | if (((m_regInfo.RegionLocX > minX) && (m_regInfo.RegionLocX < maxX)) && ((m_regInfo.RegionLocY > minY) && (m_regInfo.RegionLocY < maxY))) | ||
210 | { | ||
211 | MapBlockReplyPacket mapReply = new MapBlockReplyPacket(); | ||
212 | mapReply.AgentData.AgentID = simClient.AgentID; | ||
213 | mapReply.AgentData.Flags = 0; | ||
214 | mapReply.Data = new MapBlockReplyPacket.DataBlock[1]; | ||
215 | mapReply.Data[0] = new MapBlockReplyPacket.DataBlock(); | ||
216 | mapReply.Data[0].MapImageID = new LLUUID("00000000-0000-0000-9999-000000000007"); | ||
217 | mapReply.Data[0].X = (ushort)m_regInfo.RegionLocX; | ||
218 | mapReply.Data[0].Y = (ushort)m_regInfo.RegionLocY; | ||
219 | mapReply.Data[0].WaterHeight =(byte) m_regInfo.RegionWaterHeight; | ||
220 | mapReply.Data[0].Name = _enc.GetBytes(this.m_regionName); | ||
221 | mapReply.Data[0].RegionFlags = 72458694; | ||
222 | mapReply.Data[0].Access = 13; | ||
223 | mapReply.Data[0].Agents = 1; //should send number of clients connected | ||
224 | simClient.OutPacket(mapReply); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | } | ||
229 | } | ||