ClientView.API.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using OpenSim.Framework.Interfaces;
  5. using OpenSim.Framework.Inventory;
  6. using OpenSim.Framework.Types;
  7. using libsecondlife;
  8. using libsecondlife.Packets;
  9. namespace OpenSim
  10. {
  11. partial class ClientView
  12. {
  13. public event ChatFromViewer OnChatFromViewer;
  14. public event RezObject OnRezObject;
  15. public event GenericCall4 OnDeRezObject;
  16. public event ModifyTerrain OnModifyTerrain;
  17. public event GenericCall OnRegionHandShakeReply;
  18. public event GenericCall OnRequestWearables;
  19. public event SetAppearance OnSetAppearance;
  20. public event GenericCall2 OnCompleteMovementToRegion;
  21. public event GenericCall3 OnAgentUpdate;
  22. public event StartAnim OnStartAnim;
  23. public event GenericCall OnRequestAvatarsData;
  24. public event LinkObjects OnLinkObjects;
  25. public event GenericCall4 OnAddPrim;
  26. public event UpdateShape OnUpdatePrimShape;
  27. public event ObjectSelect OnObjectSelect;
  28. public event UpdatePrimFlags OnUpdatePrimFlags;
  29. public event UpdatePrimTexture OnUpdatePrimTexture;
  30. public event UpdatePrimVector OnUpdatePrimPosition;
  31. public event UpdatePrimRotation OnUpdatePrimRotation;
  32. public event UpdatePrimVector OnUpdatePrimScale;
  33. public event StatusChange OnChildAgentStatus;
  34. public event GenericCall2 OnStopMovement;
  35. public event NewAvatar OnNewAvatar;
  36. public event GenericCall6 OnRemoveAvatar;
  37. /// <summary>
  38. ///
  39. /// </summary>
  40. public LLVector3 StartPos
  41. {
  42. get
  43. {
  44. return startpos;
  45. }
  46. set
  47. {
  48. startpos = value;
  49. }
  50. }
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. public LLUUID AgentId
  55. {
  56. get
  57. {
  58. return this.AgentID;
  59. }
  60. }
  61. /// <summary>
  62. ///
  63. /// </summary>
  64. public string FirstName
  65. {
  66. get
  67. {
  68. return this.firstName;
  69. }
  70. }
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. public string LastName
  75. {
  76. get
  77. {
  78. return this.lastName;
  79. }
  80. }
  81. #region World/Avatar to Client
  82. /// <summary>
  83. ///
  84. /// </summary>
  85. /// <param name="regInfo"></param>
  86. public void MoveAgentIntoRegion(RegionInfo regInfo)
  87. {
  88. AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
  89. mov.AgentData.SessionID = this.SessionID;
  90. mov.AgentData.AgentID = this.AgentID;
  91. mov.Data.RegionHandle = regInfo.RegionHandle;
  92. // TODO - dynamicalise this stuff
  93. mov.Data.Timestamp = 1172750370;
  94. mov.Data.Position = this.startpos;
  95. mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
  96. OutPacket(mov);
  97. }
  98. /// <summary>
  99. ///
  100. /// </summary>
  101. /// <param name="message"></param>
  102. /// <param name="type"></param>
  103. /// <param name="fromPos"></param>
  104. /// <param name="fromName"></param>
  105. /// <param name="fromAgentID"></param>
  106. public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
  107. {
  108. System.Text.Encoding enc = System.Text.Encoding.ASCII;
  109. libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
  110. reply.ChatData.Audible = 1;
  111. reply.ChatData.Message = message;
  112. reply.ChatData.ChatType = type;
  113. reply.ChatData.SourceType = 1;
  114. reply.ChatData.Position = fromPos;
  115. reply.ChatData.FromName = enc.GetBytes(fromName + "\0");
  116. reply.ChatData.OwnerID = fromAgentID;
  117. reply.ChatData.SourceID = fromAgentID;
  118. this.OutPacket(reply);
  119. }
  120. /// <summary>
  121. ///
  122. /// </summary>
  123. /// <param name="wearables"></param>
  124. public void SendWearables(AvatarWearable[] wearables)
  125. {
  126. AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
  127. aw.AgentData.AgentID = this.AgentID;
  128. aw.AgentData.SerialNum = 0;
  129. aw.AgentData.SessionID = this.SessionID;
  130. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
  131. AgentWearablesUpdatePacket.WearableDataBlock awb;
  132. for (int i = 0; i < wearables.Length; i++)
  133. {
  134. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  135. awb.WearableType = (byte)i;
  136. awb.AssetID = wearables[i].AssetID;
  137. awb.ItemID = wearables[i].ItemID;
  138. aw.WearableData[i] = awb;
  139. }
  140. this.OutPacket(aw);
  141. }
  142. /// <summary>
  143. ///
  144. /// </summary>
  145. /// <param name="agentID"></param>
  146. /// <param name="visualParams"></param>
  147. /// <param name="textureEntry"></param>
  148. public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
  149. {
  150. AvatarAppearancePacket avp = new AvatarAppearancePacket();
  151. avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
  152. avp.ObjectData.TextureEntry = textureEntry;
  153. AvatarAppearancePacket.VisualParamBlock avblock = null;
  154. for (int i = 0; i < visualParams.Length; i++)
  155. {
  156. avblock = new AvatarAppearancePacket.VisualParamBlock();
  157. avblock.ParamValue = visualParams[i];
  158. avp.VisualParam[i] = avblock;
  159. }
  160. avp.Sender.IsTrial = false;
  161. avp.Sender.ID = agentID;
  162. OutPacket(avp);
  163. }
  164. /// <summary>
  165. /// Send the region heightmap to the client
  166. /// </summary>
  167. /// <param name="map">heightmap</param>
  168. public virtual void SendLayerData(float[] map)
  169. {
  170. try
  171. {
  172. int[] patches = new int[4];
  173. for (int y = 0; y < 16; y++)
  174. {
  175. for (int x = 0; x < 16; x = x + 4)
  176. {
  177. patches[0] = x + 0 + y * 16;
  178. patches[1] = x + 1 + y * 16;
  179. patches[2] = x + 2 + y * 16;
  180. patches[3] = x + 3 + y * 16;
  181. Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
  182. OutPacket(layerpack);
  183. }
  184. }
  185. }
  186. catch (Exception e)
  187. {
  188. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "ClientView API.cs: SendLayerData() - Failed with exception " + e.ToString());
  189. }
  190. }
  191. /// <summary>
  192. /// Sends a specified patch to a client
  193. /// </summary>
  194. /// <param name="px">Patch coordinate (x) 0..16</param>
  195. /// <param name="py">Patch coordinate (y) 0..16</param>
  196. /// <param name="map">heightmap</param>
  197. public void SendLayerData(int px, int py, float[] map)
  198. {
  199. try
  200. {
  201. int[] patches = new int[1];
  202. int patchx, patchy;
  203. patchx = px / 16;
  204. patchy = py / 16;
  205. patches[0] = patchx + 0 + patchy * 16;
  206. Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
  207. OutPacket(layerpack);
  208. }
  209. catch (Exception e)
  210. {
  211. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.MEDIUM, "ClientView API .cs: SendLayerData() - Failed with exception " + e.ToString());
  212. }
  213. }
  214. /// <summary>
  215. ///
  216. /// </summary>
  217. /// <param name="regionInfo"></param>
  218. public void SendRegionHandshake(RegionInfo regionInfo)
  219. {
  220. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE, "Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
  221. System.Text.Encoding _enc = System.Text.Encoding.ASCII;
  222. RegionHandshakePacket handshake = new RegionHandshakePacket();
  223. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.VERBOSE, "Avatar.cs:SendRegionhandshake() - Filling in RegionHandshake details");
  224. handshake.RegionInfo.BillableFactor = 0;
  225. handshake.RegionInfo.IsEstateManager = false;
  226. handshake.RegionInfo.TerrainHeightRange00 = regionInfo.TerrainHeightRange00;
  227. handshake.RegionInfo.TerrainHeightRange01 = regionInfo.TerrainHeightRange01;
  228. handshake.RegionInfo.TerrainHeightRange10 = regionInfo.TerrainHeightRange10;
  229. handshake.RegionInfo.TerrainHeightRange11 = regionInfo.TerrainHeightRange11;
  230. handshake.RegionInfo.TerrainStartHeight00 = regionInfo.TerrainStartHeight00;
  231. handshake.RegionInfo.TerrainStartHeight01 = regionInfo.TerrainStartHeight01;
  232. handshake.RegionInfo.TerrainStartHeight10 = regionInfo.TerrainStartHeight10;
  233. handshake.RegionInfo.TerrainStartHeight11 = regionInfo.TerrainStartHeight11;
  234. handshake.RegionInfo.SimAccess = 13;
  235. handshake.RegionInfo.WaterHeight = regionInfo.RegionWaterHeight;
  236. uint regionFlags = 72458694;
  237. if (regionInfo.RegionTerraform)
  238. {
  239. regionFlags -= 64;
  240. }
  241. handshake.RegionInfo.RegionFlags = regionFlags;
  242. handshake.RegionInfo.SimName = _enc.GetBytes(regionInfo.RegionName + "\0");
  243. handshake.RegionInfo.SimOwner = new LLUUID("00000000-0000-0000-0000-000000000000");
  244. handshake.RegionInfo.TerrainBase0 = regionInfo.TerrainBase0;
  245. handshake.RegionInfo.TerrainBase1 = regionInfo.TerrainBase1;
  246. handshake.RegionInfo.TerrainBase2 = regionInfo.TerrainBase2;
  247. handshake.RegionInfo.TerrainBase3 = regionInfo.TerrainBase3;
  248. handshake.RegionInfo.TerrainDetail0 = regionInfo.TerrainDetail0;
  249. handshake.RegionInfo.TerrainDetail1 = regionInfo.TerrainDetail1;
  250. handshake.RegionInfo.TerrainDetail2 = regionInfo.TerrainDetail2;
  251. handshake.RegionInfo.TerrainDetail3 = regionInfo.TerrainDetail3;
  252. handshake.RegionInfo.CacheID = new LLUUID("545ec0a5-5751-1026-8a0b-216e38a7ab37");
  253. OutPacket(handshake);
  254. }
  255. /// <summary>
  256. ///
  257. /// </summary>
  258. /// <param name="regionInfo"></param>
  259. /// <param name="firstName"></param>
  260. /// <param name="lastName"></param>
  261. /// <param name="avatarID"></param>
  262. /// <param name="avatarLocalID"></param>
  263. /// <param name="Pos"></param>
  264. public void SendAvatarData(RegionInfo regionInfo, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos)
  265. {
  266. System.Text.Encoding _enc = System.Text.Encoding.ASCII;
  267. //send a objectupdate packet with information about the clients avatar
  268. ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
  269. objupdate.RegionData.RegionHandle = regionInfo.RegionHandle;
  270. objupdate.RegionData.TimeDilation = 64096;
  271. objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
  272. objupdate.ObjectData[0] = this.CreateDefaultAvatarPacket();
  273. //give this avatar object a local id and assign the user a name
  274. objupdate.ObjectData[0].ID = avatarLocalID;
  275. objupdate.ObjectData[0].FullID = avatarID;
  276. objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName + " \0");
  277. libsecondlife.LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
  278. byte[] pb = pos2.GetBytes();
  279. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
  280. OutPacket(objupdate);
  281. }
  282. /// <summary>
  283. ///
  284. /// </summary>
  285. /// <param name="objdata"></param>
  286. protected void SetDefaultPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
  287. {
  288. objdata.PSBlock = new byte[0];
  289. objdata.ExtraParams = new byte[1];
  290. objdata.MediaURL = new byte[0];
  291. objdata.NameValue = new byte[0];
  292. objdata.Text = new byte[0];
  293. objdata.TextColor = new byte[4];
  294. objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
  295. objdata.JointPivot = new LLVector3(0, 0, 0);
  296. objdata.Material = 4;
  297. objdata.TextureAnim = new byte[0];
  298. objdata.Sound = LLUUID.Zero;
  299. LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
  300. objdata.TextureEntry = ntex.ToBytes();
  301. objdata.State = 0;
  302. objdata.Data = new byte[0];
  303. objdata.ObjectData = new byte[76];
  304. objdata.ObjectData[15] = 128;
  305. objdata.ObjectData[16] = 63;
  306. objdata.ObjectData[56] = 128;
  307. objdata.ObjectData[61] = 102;
  308. objdata.ObjectData[62] = 40;
  309. objdata.ObjectData[63] = 61;
  310. objdata.ObjectData[64] = 189;
  311. }
  312. /// <summary>
  313. ///
  314. /// </summary>
  315. /// <returns></returns>
  316. protected ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket()
  317. {
  318. libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
  319. SetDefaultPacketValues(ref objdata);
  320. objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
  321. objdata.PathCurve = 16;
  322. objdata.ProfileCurve = 1;
  323. objdata.PathScaleX = 100;
  324. objdata.PathScaleY = 100;
  325. objdata.ParentID = 0;
  326. objdata.OwnerID = LLUUID.Zero;
  327. objdata.Scale = new LLVector3(1, 1, 1);
  328. objdata.PCode = 47;
  329. System.Text.Encoding enc = System.Text.Encoding.ASCII;
  330. libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
  331. pos.X = 100f;
  332. objdata.ID = 8880000;
  333. objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
  334. libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
  335. //objdata.FullID=user.AgentID;
  336. byte[] pb = pos.GetBytes();
  337. Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
  338. return objdata;
  339. }
  340. public void InformClientOfNeighbour(ulong neighbourHandle, System.Net.IPAddress neighbourIP, ushort neighbourPort)
  341. {
  342. EnableSimulatorPacket enablesimpacket = new EnableSimulatorPacket();
  343. enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
  344. enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
  345. byte[] byteIP = neighbourIP.GetAddressBytes();
  346. enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
  347. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
  348. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
  349. enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
  350. enablesimpacket.SimulatorInfo.Port = neighbourPort;
  351. OutPacket(enablesimpacket);
  352. }
  353. public AgentCircuitData RequestClientInfo()
  354. {
  355. AgentCircuitData agentData = new AgentCircuitData();
  356. agentData.AgentID = this.AgentId;
  357. agentData.SessionID = this.SessionID;
  358. agentData.SecureSessionID = this.SecureSessionID;
  359. agentData.circuitcode = this.CircuitCode;
  360. agentData.child = false;
  361. agentData.firstname = this.firstName;
  362. agentData.lastname = this.lastName;
  363. return agentData;
  364. }
  365. #endregion
  366. }
  367. }