RemoteGridServer.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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;
  29. using System.Collections.Generic;
  30. using System.Threading;
  31. using System.Net;
  32. using System.Net.Sockets;
  33. using System.IO;
  34. using libsecondlife;
  35. using Nwc.XmlRpc;
  36. using OpenSim.Framework.Interfaces;
  37. using OpenSim.Framework.Assets;
  38. namespace OpenSim.GridInterfaces.Remote
  39. {
  40. public class RemoteGridServer : RemoteGridBase
  41. {
  42. private string GridServerUrl;
  43. private string GridSendKey;
  44. private string GridRecvKey;
  45. private Dictionary<uint, AgentCircuitData> AgentCircuits = new Dictionary<uint, AgentCircuitData>();
  46. public override Dictionary<uint, AgentCircuitData> agentcircuits
  47. {
  48. get { return AgentCircuits; }
  49. set { AgentCircuits = value; }
  50. }
  51. public RemoteGridServer()
  52. {
  53. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Remote Grid Server class created");
  54. }
  55. public override bool RequestConnection(LLUUID SimUUID, string sim_ip, uint sim_port)
  56. {
  57. Hashtable GridParams = new Hashtable();
  58. GridParams["authkey"]=GridSendKey;
  59. GridParams["UUID"]=SimUUID.ToString();
  60. GridParams["sim_ip"]=sim_ip;
  61. GridParams["sim_port"]=sim_port.ToString();
  62. ArrayList SendParams = new ArrayList();
  63. SendParams.Add(GridParams);
  64. XmlRpcRequest GridReq = new XmlRpcRequest("simulator_login", SendParams);
  65. XmlRpcResponse GridResp = GridReq.Send(this.GridServerUrl, 3000);
  66. Hashtable GridRespData = (Hashtable)GridResp.Value;
  67. if(GridRespData.ContainsKey("error")) {
  68. string errorstring = (string)GridRespData["error"];
  69. OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Error connecting to grid:");
  70. OpenSim.Framework.Console.MainConsole.Instance.WriteLine(errorstring);
  71. return false;
  72. }
  73. return true;
  74. }
  75. public override AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode)
  76. {
  77. AgentCircuitData validcircuit = null;
  78. if (this.AgentCircuits.ContainsKey(circuitcode))
  79. {
  80. validcircuit = this.AgentCircuits[circuitcode];
  81. }
  82. AuthenticateResponse user = new AuthenticateResponse();
  83. if (validcircuit == null)
  84. {
  85. //don't have this circuit code in our list
  86. user.Authorised = false;
  87. return (user);
  88. }
  89. if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID))
  90. {
  91. // YAY! Valid login
  92. user.Authorised = true;
  93. user.LoginInfo = new Login();
  94. user.LoginInfo.Agent = agentID;
  95. user.LoginInfo.Session = sessionID;
  96. user.LoginInfo.SecureSession = validcircuit.SecureSessionID;
  97. user.LoginInfo.First = validcircuit.firstname;
  98. user.LoginInfo.Last = validcircuit.lastname;
  99. }
  100. else
  101. {
  102. // Invalid
  103. user.Authorised = false;
  104. }
  105. return (user);
  106. }
  107. public override bool LogoutSession(LLUUID sessionID, LLUUID agentID, uint circuitCode)
  108. {
  109. WebRequest DeleteSession = WebRequest.Create(GridServerUrl + "/usersessions/" + sessionID.ToString());
  110. DeleteSession.Method = "DELETE";
  111. DeleteSession.ContentType = "text/plaintext";
  112. DeleteSession.ContentLength = 0;
  113. StreamWriter stOut = new StreamWriter(DeleteSession.GetRequestStream(), System.Text.Encoding.ASCII);
  114. stOut.Write("");
  115. stOut.Close();
  116. StreamReader stIn = new StreamReader(DeleteSession.GetResponse().GetResponseStream());
  117. string GridResponse = stIn.ReadToEnd();
  118. stIn.Close();
  119. return (true);
  120. }
  121. public override UUIDBlock RequestUUIDBlock()
  122. {
  123. UUIDBlock uuidBlock = new UUIDBlock();
  124. return (uuidBlock);
  125. }
  126. public override NeighbourInfo[] RequestNeighbours()
  127. {
  128. return null;
  129. }
  130. public override void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
  131. {
  132. this.GridServerUrl = ServerUrl;
  133. this.GridSendKey = SendKey;
  134. this.GridRecvKey = RecvKey;
  135. }
  136. public override string GetName()
  137. {
  138. return "Remote";
  139. }
  140. public override void Close()
  141. {
  142. }
  143. }
  144. public class RemoteGridPlugin : IGridPlugin
  145. {
  146. public RemoteGridPlugin()
  147. {
  148. }
  149. public IGridServer GetGridServer()
  150. {
  151. return (new RemoteGridServer());
  152. }
  153. }
  154. }