Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Xml;
  7. using LoginServer.services.MessageUtilities;
  8.  
  9. namespace LoginServer.network.PropertiesLoader
  10. {
  11. class Properties
  12. {
  13. //NetWorkSettings
  14. static public string port = null;
  15. static public string ip = null;
  16. //DataBase Settings
  17. static public string dbhost = null;
  18. static public string dbport = null;
  19. static public string dbuser = null;
  20. static public string dbpass = null;
  21. static public string dbname = null;
  22.  
  23. public static bool loader()
  24. {
  25. if (NetworkProperties() && DatabaseProperties()) return true;
  26. return false;
  27.  
  28. }
  29.  
  30. public static bool NetworkProperties()
  31. {
  32. if (!File.Exists("settings/NetworkSettings.xml"))
  33. {
  34. ConsoleUtilities.consolerror("settings/NetworkSettings.xml NOT EXIST!!!");
  35. return false;
  36. }
  37.  
  38. XmlReader reader = XmlReader.Create("settings/NetworkSettings.xml");
  39. while (reader.Read())
  40. {
  41. if (reader.Name == "ip")
  42. {
  43. ip = reader.ReadInnerXml();
  44. }
  45.  
  46. if (reader.Name == "port")
  47. {
  48. port = reader.ReadInnerXml();
  49. }
  50. }
  51. if (port.Length > 0 && ip.Length > 0)
  52. {
  53. ConsoleUtilities.consoleinfo("settings/NetworkSettings.xml successfully loaded");
  54. ConsoleUtilities.consoleinfo("Server use this ip: " + ip);
  55. ConsoleUtilities.consoleinfo("Server use this port: " + port);
  56. return true;
  57. }
  58. else
  59. {
  60. ConsoleUtilities.consolerror("settings/NetworkSettings.xml ERROR WHEN LOADING");
  61. return false;
  62. }
  63. }
  64.  
  65. public static bool DatabaseProperties()
  66. {
  67. if (!File.Exists("settings/DatabaseSettings.xml"))
  68. {
  69. ConsoleUtilities.consolerror("settings/DatabaseSettings.xml NOT EXIST!!!");
  70. return false;
  71. }
  72.  
  73. XmlReader reader = XmlReader.Create("settings/DatabaseSettings.xml");
  74. while (reader.Read())
  75. {
  76. if (reader.Name == "host")
  77. {
  78. dbhost = reader.ReadInnerXml();
  79. }
  80.  
  81. if (reader.Name == "port")
  82. {
  83. dbport = reader.ReadInnerXml();
  84. }
  85.  
  86. if (reader.Name == "user")
  87. {
  88. dbuser = reader.ReadInnerXml();
  89. }
  90.  
  91. if (reader.Name == "pass")
  92. {
  93. dbpass = reader.ReadInnerXml();
  94. }
  95.  
  96. if (reader.Name == "name")
  97. {
  98. dbname = reader.ReadInnerXml();
  99. }
  100. }
  101. if (dbhost.Length > 0 && dbport.Length > 0 && dbuser.Length > 0 && dbname.Length > 0)
  102. {
  103. ConsoleUtilities.consoleinfo("settings/DatabaseSettings.xml successfully loaded");
  104. ConsoleUtilities.consoleinfo("DataBase host: " + dbhost);
  105. ConsoleUtilities.consoleinfo("Database port: " + dbport);
  106. ConsoleUtilities.consoleinfo("Database user: " + dbuser);
  107. ConsoleUtilities.consoleinfo("Database name: " + dbname);
  108. return true;
  109. }
  110. else
  111. {
  112. ConsoleUtilities.consolerror("settings/DatabaseSettings.xml ERROR WHEN LOADING");
  113. return false;
  114. }
  115. }
  116.  
  117. public static string ipadd()
  118. {
  119. return ip;
  120. }
  121.  
  122. public static string portadd()
  123. {
  124. return port;
  125. }
  126.  
  127. public static string dbnamev()
  128. {
  129. return dbname;
  130. }
  131.  
  132. public static string dbuserv()
  133. {
  134. return dbuser;
  135. }
  136.  
  137. public static string dbhostv()
  138. {
  139. return dbhost;
  140. }
  141.  
  142. public static string dbportv()
  143. {
  144. return dbport;
  145. }
  146.  
  147. public static string dbpassv()
  148. {
  149. return dbpass;
  150. }
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement