AgentCircuitManager.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System.Collections.Generic;
  29. using libsecondlife;
  30. namespace OpenSim.Framework
  31. {
  32. public class AgentCircuitManager
  33. {
  34. public Dictionary<uint, AgentCircuitData> AgentCircuits = new Dictionary<uint, AgentCircuitData>();
  35. // here be dragons
  36. public delegate void CircuitAddedCallback(uint circuitCode, AgentCircuitData agentData);
  37. public event CircuitAddedCallback onCircuitAdded;
  38. public AgentCircuitManager()
  39. {
  40. }
  41. public virtual AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode)
  42. {
  43. AgentCircuitData validcircuit = null;
  44. if (AgentCircuits.ContainsKey(circuitcode))
  45. {
  46. validcircuit = AgentCircuits[circuitcode];
  47. }
  48. AuthenticateResponse user = new AuthenticateResponse();
  49. if (validcircuit == null)
  50. {
  51. //don't have this circuit code in our list
  52. user.Authorised = false;
  53. return (user);
  54. }
  55. if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID))
  56. {
  57. user.Authorised = true;
  58. user.LoginInfo = new Login();
  59. user.LoginInfo.Agent = agentID;
  60. user.LoginInfo.Session = sessionID;
  61. user.LoginInfo.SecureSession = validcircuit.SecureSessionID;
  62. user.LoginInfo.First = validcircuit.firstname;
  63. user.LoginInfo.Last = validcircuit.lastname;
  64. user.LoginInfo.InventoryFolder = validcircuit.InventoryFolder;
  65. user.LoginInfo.BaseFolder = validcircuit.BaseFolder;
  66. }
  67. else
  68. {
  69. // Invalid
  70. user.Authorised = false;
  71. }
  72. return (user);
  73. }
  74. public virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData)
  75. {
  76. if (AgentCircuits.ContainsKey(circuitCode))
  77. {
  78. AgentCircuits[circuitCode] = agentData;
  79. }
  80. else
  81. {
  82. AgentCircuits.Add(circuitCode, agentData);
  83. if (null != onCircuitAdded)
  84. onCircuitAdded(circuitCode, agentData);
  85. }
  86. }
  87. public LLVector3 GetPosition(uint circuitCode)
  88. {
  89. LLVector3 vec = new LLVector3();
  90. if (AgentCircuits.ContainsKey(circuitCode))
  91. {
  92. vec = AgentCircuits[circuitCode].startpos;
  93. }
  94. return vec;
  95. }
  96. public void UpdateAgentData(AgentCircuitData agentData)
  97. {
  98. if (AgentCircuits.ContainsKey((uint) agentData.circuitcode))
  99. {
  100. AgentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname;
  101. AgentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname;
  102. AgentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos;
  103. // Console.WriteLine("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z);
  104. }
  105. }
  106. public void UpdateAgentChildStatus(uint circuitcode, bool childstatus)
  107. {
  108. if (AgentCircuits.ContainsKey(circuitcode))
  109. {
  110. AgentCircuits[circuitcode].child = childstatus;
  111. }
  112. }
  113. public bool GetAgentChildStatus(uint circuitcode)
  114. {
  115. if (AgentCircuits.ContainsKey(circuitcode))
  116. {
  117. return AgentCircuits[circuitcode].child;
  118. }
  119. return false;
  120. }
  121. }
  122. }