Guest User

Untitled

a guest
Jul 31st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. package org.com.cursed;
  2.  
  3. import java.net.Socket;
  4. import java.util.Locale;
  5. import org.apache.commons.logging.Log;
  6. import org.com.cursed.DBAccess.OnlineTypes;
  7. import org.opencms.file.CmsObject;
  8. import org.opencms.main.CmsException;
  9. import org.opencms.main.CmsLog;
  10. import org.opencms.xml.CmsXmlException;
  11. import org.opencms.xml.content.CmsXmlContent;
  12. import org.opencms.xml.content.CmsXmlContentFactory;
  13.  
  14. public class Realm {
  15. final String NODE_ID ="id";
  16. final String NODE_NAME ="name";
  17. final String NODE_TYPE ="type";
  18. final String NODE_RATES ="rates";
  19. final String NODE_CHARDB ="chardb";
  20. final String NODE_LOGONDB ="logondb";
  21. final String NODE_SERVERPORT ="serverport";
  22. final String NODE_SOAP_USER = "soap_user";
  23. final String NODE_SOAP_PASS = "soap_password";
  24. final String NODE_SOAP_PORT = "soap_port";
  25.  
  26. /**
  27. * Logging-Object
  28. */
  29. private static final Log LOG = CmsLog.getLog(Realm.class);
  30.  
  31. private int id;
  32. private String name;
  33. private String type;
  34. private String rates;
  35.  
  36. private String soap_user;
  37. private String soap_pass;
  38. private String soap_port;
  39.  
  40.  
  41. private String char_pool;
  42. private String logon_pool;
  43.  
  44. private int server_port;
  45. private String uptime;
  46.  
  47. private int chars_online;
  48. private int horde_online;
  49. private int ally_online;
  50.  
  51. final long DAY = 86400;
  52. final long HOUR = 3600;
  53. final long MINUTE = 60;
  54.  
  55. private boolean server_online;
  56.  
  57. public Realm(String configUri, CmsObject cms, Locale locale, String host)
  58. {
  59.  
  60. try {
  61. CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms,cms.readFile(configUri));
  62. Locale usedLocale = locale;
  63. if (!content.hasLocale(locale))
  64. usedLocale = content.getLocales().get(0);
  65.  
  66. this.id = Integer.parseInt(content.getStringValue(cms, NODE_ID, usedLocale));
  67. this.name = content.getStringValue(cms, NODE_NAME, usedLocale);
  68. this.rates = content.getStringValue(cms, NODE_TYPE, usedLocale);
  69. this.type = content.getStringValue(cms, NODE_RATES, usedLocale);
  70. this.char_pool = content.getStringValue(cms, NODE_CHARDB, usedLocale);
  71. this.logon_pool = content.getStringValue(cms, NODE_LOGONDB, usedLocale);
  72. this.server_port = Integer.parseInt(content.getStringValue(cms, NODE_SERVERPORT, usedLocale));
  73. this.soap_user = content.getStringValue(cms, NODE_SOAP_USER, usedLocale);
  74. this.soap_pass = content.getStringValue(cms, NODE_SOAP_PASS, usedLocale);
  75. this.soap_port = content.getStringValue(cms, NODE_SOAP_PORT, usedLocale);
  76.  
  77.  
  78. } catch (CmsXmlException e) {
  79. LOG.fatal("Failed to unmarshall XML-File: " + e.getLocalizedMessage());
  80. } catch (CmsException e) {
  81. LOG.fatal("Failed to read resource: " + e.getLocalizedMessage());
  82. } catch (NumberFormatException e){
  83. LOG.fatal("Failed to parse integer" + e.getLocalizedMessage());
  84. }
  85. DBAccess db = DBAccess.getInstance();
  86. this.chars_online = db.getCharsOnline(this.char_pool, OnlineTypes.GENERIC);
  87. this.ally_online = db.getCharsOnline(this.char_pool, OnlineTypes.ALLY);
  88. this.horde_online = db.getCharsOnline(this.char_pool, OnlineTypes.HORDE);
  89. this.uptime = calculateUptime(db.getUptime(this.logon_pool, this.id));
  90.  
  91. try {
  92. Socket testSocket = new Socket(host, server_port);
  93. this.server_online = true;
  94. testSocket.close();
  95. }
  96. catch(Exception ex)
  97. {
  98. this.server_online = false;
  99. }
  100. this.lockAccount();
  101. }
  102.  
  103. public int getId()
  104. {
  105. return this.id;
  106. }
  107.  
  108. public String calculateUptime(long timestamp)
  109. {
  110. long days = 0, hours = 0, minutes = 0;
  111. while (timestamp >= DAY)
  112. {
  113. days++;
  114. timestamp-=DAY;
  115. }
  116. while (timestamp >= HOUR)
  117. {
  118. hours++;
  119. timestamp-=HOUR;
  120. }
  121. minutes = timestamp / MINUTE;
  122.  
  123. return (days + " Days " + hours + " Hours " + minutes + " Minutes");
  124. }
  125.  
  126. public String getName()
  127. {
  128. return this.name;
  129. }
  130.  
  131. private void lockAccount()
  132. {
  133. DBAccess db = DBAccess.getInstance();
  134. db.lockAccount(this.getLogonPool(), this.getSOAPUser());
  135. }
  136.  
  137. public String getUptime()
  138. {
  139. return this.uptime;
  140. }
  141.  
  142. public String getCharPool()
  143. {
  144. return this.char_pool;
  145. }
  146.  
  147. public String getLogonPool()
  148. {
  149. return this.logon_pool;
  150. }
  151.  
  152. public boolean isOnline()
  153. {
  154. return this.server_online;
  155. }
  156.  
  157. public String getSOAPUser()
  158. {
  159. return this.soap_user;
  160. }
  161.  
  162. public String getSOAPPass()
  163. {
  164. return this.soap_pass;
  165. }
  166.  
  167. public String getSOAPPort()
  168. {
  169. return this.soap_port;
  170. }
  171.  
  172. public int getCharsOnline()
  173. {
  174. return this.chars_online;
  175. }
  176.  
  177. public int getAllyOnline()
  178. {
  179. return this.ally_online;
  180. }
  181.  
  182. public int getHordeOnline()
  183. {
  184. return this.horde_online;
  185. }
  186.  
  187. public String getType()
  188. {
  189. return this.type;
  190. }
  191.  
  192. public String getRates()
  193. {
  194. return this.rates;
  195. }
  196. }
Add Comment
Please, Sign In to add comment