Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.com.cursed;
- import java.net.Socket;
- import java.util.Locale;
- import org.apache.commons.logging.Log;
- import org.com.cursed.DBAccess.OnlineTypes;
- import org.opencms.file.CmsObject;
- import org.opencms.main.CmsException;
- import org.opencms.main.CmsLog;
- import org.opencms.xml.CmsXmlException;
- import org.opencms.xml.content.CmsXmlContent;
- import org.opencms.xml.content.CmsXmlContentFactory;
- public class Realm {
- final String NODE_ID ="id";
- final String NODE_NAME ="name";
- final String NODE_TYPE ="type";
- final String NODE_RATES ="rates";
- final String NODE_CHARDB ="chardb";
- final String NODE_LOGONDB ="logondb";
- final String NODE_SERVERPORT ="serverport";
- final String NODE_SOAP_USER = "soap_user";
- final String NODE_SOAP_PASS = "soap_password";
- final String NODE_SOAP_PORT = "soap_port";
- /**
- * Logging-Object
- */
- private static final Log LOG = CmsLog.getLog(Realm.class);
- private int id;
- private String name;
- private String type;
- private String rates;
- private String soap_user;
- private String soap_pass;
- private String soap_port;
- private String char_pool;
- private String logon_pool;
- private int server_port;
- private String uptime;
- private int chars_online;
- private int horde_online;
- private int ally_online;
- final long DAY = 86400;
- final long HOUR = 3600;
- final long MINUTE = 60;
- private boolean server_online;
- public Realm(String configUri, CmsObject cms, Locale locale, String host)
- {
- try {
- CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms,cms.readFile(configUri));
- Locale usedLocale = locale;
- if (!content.hasLocale(locale))
- usedLocale = content.getLocales().get(0);
- this.id = Integer.parseInt(content.getStringValue(cms, NODE_ID, usedLocale));
- this.name = content.getStringValue(cms, NODE_NAME, usedLocale);
- this.rates = content.getStringValue(cms, NODE_TYPE, usedLocale);
- this.type = content.getStringValue(cms, NODE_RATES, usedLocale);
- this.char_pool = content.getStringValue(cms, NODE_CHARDB, usedLocale);
- this.logon_pool = content.getStringValue(cms, NODE_LOGONDB, usedLocale);
- this.server_port = Integer.parseInt(content.getStringValue(cms, NODE_SERVERPORT, usedLocale));
- this.soap_user = content.getStringValue(cms, NODE_SOAP_USER, usedLocale);
- this.soap_pass = content.getStringValue(cms, NODE_SOAP_PASS, usedLocale);
- this.soap_port = content.getStringValue(cms, NODE_SOAP_PORT, usedLocale);
- } catch (CmsXmlException e) {
- LOG.fatal("Failed to unmarshall XML-File: " + e.getLocalizedMessage());
- } catch (CmsException e) {
- LOG.fatal("Failed to read resource: " + e.getLocalizedMessage());
- } catch (NumberFormatException e){
- LOG.fatal("Failed to parse integer" + e.getLocalizedMessage());
- }
- DBAccess db = DBAccess.getInstance();
- this.chars_online = db.getCharsOnline(this.char_pool, OnlineTypes.GENERIC);
- this.ally_online = db.getCharsOnline(this.char_pool, OnlineTypes.ALLY);
- this.horde_online = db.getCharsOnline(this.char_pool, OnlineTypes.HORDE);
- this.uptime = calculateUptime(db.getUptime(this.logon_pool, this.id));
- try {
- Socket testSocket = new Socket(host, server_port);
- this.server_online = true;
- testSocket.close();
- }
- catch(Exception ex)
- {
- this.server_online = false;
- }
- this.lockAccount();
- }
- public int getId()
- {
- return this.id;
- }
- public String calculateUptime(long timestamp)
- {
- long days = 0, hours = 0, minutes = 0;
- while (timestamp >= DAY)
- {
- days++;
- timestamp-=DAY;
- }
- while (timestamp >= HOUR)
- {
- hours++;
- timestamp-=HOUR;
- }
- minutes = timestamp / MINUTE;
- return (days + " Days " + hours + " Hours " + minutes + " Minutes");
- }
- public String getName()
- {
- return this.name;
- }
- private void lockAccount()
- {
- DBAccess db = DBAccess.getInstance();
- db.lockAccount(this.getLogonPool(), this.getSOAPUser());
- }
- public String getUptime()
- {
- return this.uptime;
- }
- public String getCharPool()
- {
- return this.char_pool;
- }
- public String getLogonPool()
- {
- return this.logon_pool;
- }
- public boolean isOnline()
- {
- return this.server_online;
- }
- public String getSOAPUser()
- {
- return this.soap_user;
- }
- public String getSOAPPass()
- {
- return this.soap_pass;
- }
- public String getSOAPPort()
- {
- return this.soap_port;
- }
- public int getCharsOnline()
- {
- return this.chars_online;
- }
- public int getAllyOnline()
- {
- return this.ally_online;
- }
- public int getHordeOnline()
- {
- return this.horde_online;
- }
- public String getType()
- {
- return this.type;
- }
- public String getRates()
- {
- return this.rates;
- }
- }
Add Comment
Please, Sign In to add comment