IGridServer.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 System.Net;
  30. using System.Net.Sockets;
  31. using System.IO;
  32. using libsecondlife;
  33. namespace OpenSim.GridServers
  34. {
  35. /// <summary>
  36. /// Handles connection to Grid Servers.
  37. /// also Sim to Sim connections?
  38. /// </summary>
  39. public class LocalGridServer :IGridServer
  40. {
  41. public List<Login> Sessions = new List<Login>();
  42. public LocalGridServer()
  43. {
  44. Sessions = new List<Login>();
  45. }
  46. public bool RequestConnection()
  47. {
  48. return true;
  49. }
  50. public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
  51. {
  52. //For Grid use:
  53. //should check to see if it is a teleportation, if so then we should be expecting this session, agent. (?)
  54. //if not check with User server/ login server that it is authorised.
  55. //but for now we are running local
  56. AuthenticateResponse user = new AuthenticateResponse();
  57. lock(this.Sessions)
  58. {
  59. for(int i = 0; i < Sessions.Count; i++)
  60. {
  61. if((Sessions[i].Agent == agentID) && (Sessions[i].Session == sessionID))
  62. {
  63. user.Authorised = true;
  64. user.LoginInfo = Sessions[i];
  65. }
  66. }
  67. }
  68. return(user);
  69. }
  70. public UUIDBlock RequestUUIDBlock()
  71. {
  72. UUIDBlock uuidBlock = new UUIDBlock();
  73. return(uuidBlock);
  74. }
  75. public void RequestNeighbours()
  76. {
  77. return;
  78. }
  79. /// <summary>
  80. /// used by the local login server to inform us of new sessions
  81. /// </summary>
  82. /// <param name="session"></param>
  83. public void AddNewSession(Login session)
  84. {
  85. lock(this.Sessions)
  86. {
  87. this.Sessions.Add(session);
  88. }
  89. }
  90. }
  91. public class RemoteGridServer :IGridServer
  92. {
  93. public RemoteGridServer()
  94. {
  95. }
  96. public bool RequestConnection()
  97. {
  98. return true;
  99. }
  100. public AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
  101. {
  102. AuthenticateResponse user = new AuthenticateResponse();
  103. WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + agentID.ToString() + "/" + circuitCode.ToString() + "/exists");
  104. WebResponse GridResponse = CheckSession.GetResponse();
  105. StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
  106. String grTest = sr.ReadLine();
  107. sr.Close();
  108. GridResponse.Close();
  109. if(String.IsNullOrEmpty(grTest) || grTest.Equals("1"))
  110. {
  111. // YAY! Valid login
  112. user.Authorised = true;
  113. user.LoginInfo = new Login();
  114. user.LoginInfo.Agent = agentID;
  115. user.LoginInfo.Session = sessionID;
  116. user.LoginInfo.First = "";
  117. user.LoginInfo.Last = "";
  118. }
  119. else
  120. {
  121. // Invalid
  122. user.Authorised = false;
  123. }
  124. return(user);
  125. }
  126. public UUIDBlock RequestUUIDBlock()
  127. {
  128. UUIDBlock uuidBlock = new UUIDBlock();
  129. return(uuidBlock);
  130. }
  131. public void RequestNeighbours()
  132. {
  133. return;
  134. }
  135. }
  136. public interface IGridServer
  137. {
  138. bool RequestConnection();
  139. UUIDBlock RequestUUIDBlock();
  140. void RequestNeighbours(); //should return a array of neighbouring regions
  141. AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitCode);
  142. }
  143. public struct UUIDBlock
  144. {
  145. public LLUUID BlockStart;
  146. public LLUUID BlockEnd;
  147. }
  148. public class AuthenticateResponse
  149. {
  150. public bool Authorised;
  151. public Login LoginInfo;
  152. public AuthenticateResponse()
  153. {
  154. }
  155. }
  156. public class Login
  157. {
  158. public string First = "Test";
  159. public string Last = "User";
  160. public LLUUID Agent;
  161. public LLUUID Session;
  162. public LLUUID InventoryFolder;
  163. public LLUUID BaseFolder;
  164. public Login()
  165. {
  166. }
  167. }
  168. }