AgentManager.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * Copyright (c) OpenSim project, http://sim.opensecondlife.org/
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the <organization> nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  16. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using libsecondlife;
  30. using libsecondlife.Packets;
  31. namespace OpenSim
  32. {
  33. /// <summary>
  34. /// Manages Agent details.
  35. /// </summary>
  36. public class AgentManager
  37. {
  38. public Dictionary<libsecondlife.LLUUID,AgentProfile> AgentList;
  39. private uint _localAvatarNumber=0;
  40. private Server _server;
  41. public AgentManager(Server server)
  42. {
  43. _server=server;
  44. this.AgentList = new Dictionary<LLUUID, AgentProfile>();
  45. }
  46. public AgentName GetAgentName(LLUUID AgentID)
  47. {
  48. AgentName name;
  49. lock(AgentList)
  50. {
  51. if(AgentList.ContainsKey(AgentID))
  52. {
  53. name=AgentList[AgentID].Name;
  54. }
  55. else
  56. {
  57. name = new AgentName();
  58. }
  59. }
  60. return(name);
  61. }
  62. public AgentProfile GetAgent(LLUUID id)
  63. {
  64. lock(AgentList)
  65. {
  66. if(!this.AgentList.ContainsKey(id))
  67. {
  68. return null;
  69. }
  70. else
  71. {
  72. AgentProfile avatar = this.AgentList[id];
  73. return avatar;
  74. }
  75. }
  76. }
  77. /// <summary>
  78. ///
  79. /// </summary>
  80. /// <param name="agent"></param>
  81. public void AddAgent(AgentProfile agent)
  82. {
  83. this.AgentList.Add(agent.Avatar.FullID, agent);
  84. }
  85. /// <summary>
  86. ///
  87. /// </summary>
  88. /// <param name="userInfo"></param>
  89. /// <param name="first"></param>
  90. /// <param name="last"></param>
  91. /// <param name="baseFolder"></param>
  92. /// <param name="inventoryFolder"></param>
  93. /// <returns></returns>
  94. public bool NewAgent(NetworkInfo userInfo, string first, string last, LLUUID baseFolder, LLUUID inventoryFolder)
  95. {
  96. Console.WriteLine("new agent called");
  97. AgentProfile agent = new AgentProfile();
  98. agent.Avatar.FullID = userInfo.User.AgentID;
  99. agent.Avatar.NetInfo = userInfo;
  100. agent.Avatar.NetInfo.User.FirstName =first;
  101. agent.Avatar.NetInfo.User.LastName = last;
  102. agent.Avatar.Position = new LLVector3(100, 100, 22);
  103. agent.Avatar.BaseFolder = baseFolder;
  104. agent.Avatar.InventoryFolder = inventoryFolder;
  105. agent.Avatar.LocalID = 8880000 + this._localAvatarNumber;
  106. this._localAvatarNumber++;
  107. this.AgentList.Add(agent.Avatar.FullID, agent);
  108. //Create new Wearable Assets and place in Inventory
  109. //this.assetManager.CreateNewInventorySet(ref agent, userInfo);
  110. return(true);
  111. }
  112. /// <summary>
  113. ///
  114. /// </summary>
  115. /// <param name="UserInfo"></param>
  116. public void RemoveAgent(NetworkInfo userInfo)
  117. {
  118. this.AgentList.Remove(userInfo.User.AgentID);
  119. //tell other clients to delete this avatar
  120. }
  121. /// <summary>
  122. ///
  123. /// </summary>
  124. /// <param name="userInfo"></param>
  125. public void AgentJoin(NetworkInfo userInfo)
  126. {
  127. //inform client of join comlete
  128. libsecondlife.Packets.AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
  129. mov.AgentData.SessionID = userInfo.User.SessionID;
  130. mov.AgentData.AgentID = userInfo.User.AgentID;
  131. mov.Data.RegionHandle = Globals.Instance.RegionHandle;
  132. mov.Data.Timestamp = 1169838966;
  133. mov.Data.Position = new LLVector3(100f, 100f, 22f);
  134. mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
  135. _server.SendPacket(mov, true, userInfo);
  136. }
  137. public void RequestWearables(NetworkInfo userInfo)
  138. {
  139. AgentProfile Agent = this.AgentList[userInfo.User.AgentID];
  140. AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
  141. aw.AgentData.AgentID = userInfo.User.AgentID;
  142. aw.AgentData.SerialNum = 0;
  143. aw.AgentData.SessionID = userInfo.User.SessionID;
  144. aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
  145. AgentWearablesUpdatePacket.WearableDataBlock awb = null;
  146. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  147. awb.WearableType = (byte)0;
  148. awb.AssetID = Agent.Avatar.Wearables[0].AssetID;
  149. awb.ItemID = Agent.Avatar.Wearables[0].ItemID;
  150. aw.WearableData[0] = awb;
  151. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  152. awb.WearableType =(byte)1;
  153. awb.AssetID = Agent.Avatar.Wearables[1].AssetID;
  154. awb.ItemID = Agent.Avatar.Wearables[1].ItemID;
  155. aw.WearableData[1] = awb;
  156. for(int i=2; i<13; i++)
  157. {
  158. awb = new AgentWearablesUpdatePacket.WearableDataBlock();
  159. awb.WearableType = (byte)i;
  160. awb.AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
  161. awb.ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
  162. aw.WearableData[i] = awb;
  163. }
  164. _server.SendPacket(aw, true, userInfo);
  165. }
  166. public void SendPacketToAllExcept(Packet packet, LLUUID exceptAgent)
  167. {
  168. foreach (KeyValuePair<libsecondlife.LLUUID, AgentProfile> kp in this.AgentList)
  169. {
  170. if(kp.Value.Avatar.NetInfo.User.AgentID != exceptAgent)
  171. {
  172. _server.SendPacket(packet, true, kp.Value.Avatar.NetInfo);
  173. }
  174. }
  175. }
  176. public void SendPacketToALL(Packet packet)
  177. {
  178. foreach (KeyValuePair<libsecondlife.LLUUID, AgentProfile> kp in this.AgentList)
  179. {
  180. _server.SendPacket(packet, true, kp.Value.Avatar.NetInfo);
  181. }
  182. }
  183. public void SendTerseUpdateLists()
  184. {
  185. foreach (KeyValuePair<libsecondlife.LLUUID, AgentProfile> kp in this.AgentList)
  186. {
  187. if(kp.Value.Avatar.TerseUpdateList.Count > 0)
  188. {
  189. ImprovedTerseObjectUpdatePacket im = new ImprovedTerseObjectUpdatePacket();
  190. im.RegionData.RegionHandle = Globals.Instance.RegionHandle;;
  191. im.RegionData.TimeDilation = 64096;
  192. im.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[kp.Value.Avatar.TerseUpdateList.Count];
  193. for(int i = 0; i < kp.Value.Avatar.TerseUpdateList.Count; i++)
  194. {
  195. im.ObjectData[i] = kp.Value.Avatar.TerseUpdateList[i];
  196. }
  197. _server.SendPacket(im, true, kp.Value.Avatar.NetInfo);
  198. kp.Value.Avatar.TerseUpdateList.Clear();
  199. }
  200. }
  201. }
  202. }
  203. public struct AgentName
  204. {
  205. public string First;
  206. public string Last;
  207. }
  208. public class AgentProfile
  209. {
  210. public AgentName Name;
  211. public AvatarData Avatar;
  212. //public AgentInventory Inventory;
  213. public AgentProfile()
  214. {
  215. Name = new AgentName();
  216. Avatar = new AvatarData();
  217. }
  218. }
  219. public class AvatarData : Node
  220. {
  221. public NetworkInfo NetInfo;
  222. public LLUUID FullID;
  223. public uint LocalID;
  224. public LLQuaternion BodyRotation;
  225. public bool Walk = false;
  226. public bool Started = false;
  227. //public TextureEntry TextureEntry;
  228. public AvatarWearable[] Wearables;
  229. public LLUUID InventoryFolder;
  230. public LLUUID BaseFolder;
  231. public AvatarParams VisParams;
  232. public List<libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock> ObjectUpdateList;
  233. public List<libsecondlife.Packets.ImprovedTerseObjectUpdatePacket.ObjectDataBlock> TerseUpdateList;
  234. public AvatarData()
  235. {
  236. Wearables=new AvatarWearable[2]; //should be 13
  237. for(int i = 0; i < 2; i++)
  238. {
  239. Wearables[i] = new AvatarWearable();
  240. }
  241. this.SceneType = 1; //Avatar type
  242. this.ObjectUpdateList = new List<libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock>();
  243. this.TerseUpdateList = new List<libsecondlife.Packets.ImprovedTerseObjectUpdatePacket.ObjectDataBlock>();
  244. VisParams = new AvatarParams();
  245. }
  246. }
  247. public class AvatarWearable
  248. {
  249. public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000");
  250. public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000");
  251. public AvatarWearable()
  252. {
  253. }
  254. }
  255. public class AvatarParams
  256. {
  257. public byte[] Params;
  258. public AvatarParams()
  259. {
  260. Params = new byte [ 218];
  261. for(int i = 0; i < 218; i++)
  262. {
  263. Params[i] = 100;
  264. }
  265. }
  266. }
  267. }