GridServerConnectionManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 OpenSimulator 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. using Nwc.XmlRpc;
  28. using System;
  29. using System.Net;
  30. using System.IO;
  31. using System.Xml;
  32. using System.Collections;
  33. using System.Collections.Generic;
  34. using libsecondlife;
  35. namespace OpenGridServices.Manager
  36. {
  37. public class GridServerConnectionManager
  38. {
  39. private string ServerURL;
  40. public LLUUID SessionID;
  41. public bool connected=false;
  42. public RegionBlock[][] WorldMap;
  43. public bool Connect(string GridServerURL, string username, string password)
  44. {
  45. try
  46. {
  47. this.ServerURL=GridServerURL;
  48. Hashtable LoginParamsHT = new Hashtable();
  49. LoginParamsHT["username"]=username;
  50. LoginParamsHT["password"]=password;
  51. ArrayList LoginParams = new ArrayList();
  52. LoginParams.Add(LoginParamsHT);
  53. XmlRpcRequest GridLoginReq = new XmlRpcRequest("manager_login",LoginParams);
  54. XmlRpcResponse GridResp = GridLoginReq.Send(ServerURL,3000);
  55. if (GridResp.IsFault)
  56. {
  57. connected=false;
  58. return false;
  59. }
  60. else
  61. {
  62. Hashtable gridrespData = (Hashtable)GridResp.Value;
  63. this.SessionID = new LLUUID((string)gridrespData["session_id"]);
  64. connected=true;
  65. return true;
  66. }
  67. }
  68. catch(Exception e)
  69. {
  70. Console.WriteLine(e.ToString());
  71. connected=false;
  72. return false;
  73. }
  74. }
  75. public void DownloadMap()
  76. {
  77. System.Net.WebClient mapdownloader = new WebClient();
  78. Stream regionliststream = mapdownloader.OpenRead(ServerURL + "/regionlist");
  79. RegionBlock TempRegionData;
  80. XmlDocument doc = new XmlDocument();
  81. doc.Load(regionliststream);
  82. regionliststream.Close();
  83. XmlNode rootnode = doc.FirstChild;
  84. if (rootnode.Name != "regions")
  85. {
  86. // TODO - ERROR!
  87. }
  88. for (int i = 0; i <= rootnode.ChildNodes.Count; i++)
  89. {
  90. if (rootnode.ChildNodes.Item(i).Name != "region")
  91. {
  92. // TODO - ERROR!
  93. }
  94. else
  95. {
  96. TempRegionData = new RegionBlock();
  97. }
  98. }
  99. }
  100. public bool RestartServer()
  101. {
  102. return true;
  103. }
  104. public bool ShutdownServer()
  105. {
  106. try
  107. {
  108. Hashtable ShutdownParamsHT = new Hashtable();
  109. ArrayList ShutdownParams = new ArrayList();
  110. ShutdownParamsHT["session_id"]=this.SessionID.ToString();
  111. ShutdownParams.Add(ShutdownParamsHT);
  112. XmlRpcRequest GridShutdownReq = new XmlRpcRequest("shutdown",ShutdownParams);
  113. XmlRpcResponse GridResp = GridShutdownReq.Send(this.ServerURL, 3000);
  114. if (GridResp.IsFault)
  115. {
  116. return false;
  117. }
  118. else
  119. {
  120. connected=false;
  121. return true;
  122. }
  123. }
  124. catch(Exception e)
  125. {
  126. Console.WriteLine(e.ToString());
  127. return false;
  128. }
  129. }
  130. public void DisconnectServer()
  131. {
  132. this.connected=false;
  133. }
  134. }
  135. }