GridServerConnectionManager.cs 5.0 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. 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. this.ServerURL=GridServerURL;
  47. Hashtable LoginParamsHT = new Hashtable();
  48. LoginParamsHT["username"]=username;
  49. LoginParamsHT["password"]=password;
  50. ArrayList LoginParams = new ArrayList();
  51. LoginParams.Add(LoginParamsHT);
  52. XmlRpcRequest GridLoginReq = new XmlRpcRequest("manager_login",LoginParams);
  53. XmlRpcResponse GridResp = GridLoginReq.Send(ServerURL,3000);
  54. if(GridResp.IsFault) {
  55. connected=false;
  56. return false;
  57. } else {
  58. Hashtable gridrespData = (Hashtable)GridResp.Value;
  59. this.SessionID = new LLUUID((string)gridrespData["session_id"]);
  60. connected=true;
  61. return true;
  62. }
  63. } catch(Exception e) {
  64. Console.WriteLine(e.ToString());
  65. connected=false;
  66. return false;
  67. }
  68. }
  69. public void DownloadMap()
  70. {
  71. System.Net.WebClient mapdownloader = new WebClient();
  72. Stream regionliststream = mapdownloader.OpenRead(ServerURL + "/regionlist");
  73. RegionBlock TempRegionData;
  74. XmlDocument doc = new XmlDocument();
  75. doc.Load(regionliststream);
  76. regionliststream.Close();
  77. XmlNode rootnode = doc.FirstChild;
  78. if (rootnode.Name != "regions")
  79. {
  80. // TODO - ERROR!
  81. }
  82. for(int i=0; i<=rootnode.ChildNodes.Count; i++)
  83. {
  84. if(rootnode.ChildNodes.Item(i).Name != "region") {
  85. // TODO - ERROR!
  86. } else {
  87. TempRegionData = new RegionBlock();
  88. }
  89. }
  90. }
  91. public bool RestartServer()
  92. {
  93. return true;
  94. }
  95. public bool ShutdownServer()
  96. {
  97. try {
  98. Hashtable ShutdownParamsHT = new Hashtable();
  99. ArrayList ShutdownParams = new ArrayList();
  100. ShutdownParamsHT["session_id"]=this.SessionID.ToString();
  101. ShutdownParams.Add(ShutdownParamsHT);
  102. XmlRpcRequest GridShutdownReq = new XmlRpcRequest("shutdown",ShutdownParams);
  103. XmlRpcResponse GridResp = GridShutdownReq.Send(this.ServerURL,3000);
  104. if(GridResp.IsFault) {
  105. return false;
  106. } else {
  107. connected=false;
  108. return true;
  109. }
  110. } catch(Exception e) {
  111. Console.WriteLine(e.ToString());
  112. return false;
  113. }
  114. }
  115. public void DisconnectServer()
  116. {
  117. this.connected=false;
  118. }
  119. }
  120. }