Package net.bnubot.db

Examples of net.bnubot.db.Rank


    return createAccount(accountName, createAccess, commanderAccount, subject);
  }

  public static void setAccountAccess(BNetUser commander, Account commanderAccount, Account subjectAccount, int targetAccess, boolean superUser, boolean whisperBack)
  throws InsufficientAccessException, CommandFailedWithDetailsException {
    Rank originalRank = subjectAccount.getRank();
    int originalAccess = originalRank.getAccess();
    if(targetAccess == originalAccess)
      throw new CommandFailedWithDetailsException("That would have no effect");

    Rank targetRank = Rank.get(targetAccess);
    if(targetRank == null)
      throw new CommandFailedWithDetailsException("Invalid rank: " + targetAccess);

    if(!superUser) {
      if(subjectAccount.equals(commanderAccount))
        throw new InsufficientAccessException("to modify your self", true);

      int commanderAccess = 0;
      if(commanderAccount != null)
        commanderAccess = commanderAccount.getAccess();
      // TODO: get addMax from the database
      int addMax = commanderAccess - 1;
      if(targetAccess > addMax)
        throw new InsufficientAccessException("to add users beyond " + addMax, true);
      if(originalAccess >= commanderAccess)
        throw new InsufficientAccessException("to add users ranked above " + (commanderAccess - 1), true);
    }

    subjectAccount.setRank(targetRank);
    subjectAccount.setLastRankChange(new Date(System.currentTimeMillis()));
    try {
      subjectAccount.updateRow();
      commander.sendChat(subjectAccount.getName() + "'s rank has changed from "
          + originalRank.getPrefix() + " (" + originalAccess + ") to "
          + targetRank.getPrefix() + " (" + targetAccess + ")", whisperBack);
    } catch(Exception e) {
      throw new CommandFailedWithDetailsException(e);
    }
  }
View Full Code Here


      } catch(Exception e) {
        Out.exception(e);
      }

      Account rsAccount = Account.get(user);
      Rank rsRank = (rsAccount == null) ? Rank.get(0) : rsAccount.getRank();

      if(rsRank != null) {
        // Autopromotions
        Integer apDays = rsRank.getApDays();
        // Check that they meet the days requirement
        apBlock: if((apDays != null) && (apDays != 0)) {
          double timeElapsed = 0;
          if(rsAccount == null) {
            timeElapsed = rsUser.getCreated().getTime();
          } else if(rsAccount.getLastRankChange() != null) {
            timeElapsed = rsAccount.getLastRankChange().getTime();
          }

          timeElapsed = System.currentTimeMillis() - timeElapsed;
          timeElapsed /= 1000 * 60 * 60 * 24;
          if(timeElapsed < apDays)
            break apBlock;

          if((rsRank.getApWins() == null)
          || (rsRank.getApD2Level() == null)
          || (rsRank.getApW3Level() == null))
            break apBlock;
          int apWins = rsRank.getApWins().intValue();
          int apD2Level = rsRank.getApD2Level().intValue();
          int apW3Level = rsRank.getApW3Level().intValue();
          long wins[];
          if(rsAccount == null)
            wins = new long[] {0, 0, 0};
          else
            wins = rsAccount.getWinsLevels(GlobalSettings.recruitTagPrefix, GlobalSettings.recruitTagSuffix);

          boolean hasEnoughWins = false;
          hasEnoughWins |= ((apWins > 0) && (wins[0] >= apWins));
          hasEnoughWins |= ((apD2Level > 0) && (wins[1] >= apD2Level));
          hasEnoughWins |= ((apW3Level > 0) && (wins[2] >= apW3Level));
          hasEnoughWins |= ((apWins == 0) && (apD2Level == 0) && (apW3Level == 0));

          if(hasEnoughWins) {
            // Check RS
            long rs = 0;
            if(rsAccount != null)
              rs = rsAccount.getRecruitScore(GlobalSettings.recruitAccess);
            Integer apRS = rsRank.getApRecruitScore();
            if((apRS == null) || (apRS == 0) || (rs >= apRS)) {
              int rank = 0;
              if(rsAccount != null)
                rank = rsAccount.getAccess();
              else {
                String name = user.getFullAccountName();
                name = name.substring(0, name.indexOf('@'));
                try {
                  Account recoverAccount = Account.get(name);
                  if((recoverAccount != null)
                  && (recoverAccount.getAccess() <= 1)
                  && (recoverAccount.getBnLogins().size() == 0)) {
                    rsAccount = recoverAccount;
                    // Reset the account to rank zero, just in case
                    rsAccount.setRank(Rank.get(0));
                    rsUser.setAccount(rsAccount);
                    rsUser.updateRow();
                  } else {
                    rsAccount = createAccount(name, 0, null, rsUser);
                  }
                } catch(Exception e) {
                  Out.exception(e);
                  user.sendChat("I couldn't make an account for you: " + e.getMessage(), true);
                  break apBlock;
                }
              }

              // Store the old AP mail message
              String apMail = rsRank.getApMail();

              // Give them a promotion
              rsRank = Rank.get(++rank);
              rsAccount.setRank(rsRank);
              rsAccount.setLastRankChange(new Date(System.currentTimeMillis()));
              try {
                rsAccount.updateRow();
              } catch(Exception e) {
                Out.exception(e);
                break apBlock;
              }
              user.resetPrettyName()//Reset the presentable name
              source.sendChat("Congratulations " + user.toString(GlobalSettings.bnUserToStringCommandResponse) + ", you've recieved a promotion! Your rank is now " + rsRank.getPrefix() + " (" + rank + ").");
              if((apMail != null) && (apMail.length() > 0))
                Mail.send(null, rsAccount, apMail);
            } else {
              user.sendChat("You need " + Long.toString(apRS - rs) + " more recruitment points to recieve a promotion!", true);
            }
          } else {
            String msg = "You need ";
            switch(user.getStatString().getProduct()) {
            case STAR:
            case SEXP:
            case W2BN:
              msg += Long.toString(apWins - wins[0]) + " more win";
              if(apWins - wins[0] > 1)
                msg += "s";
              break;
            case D2DV:
            case D2XP:
              msg += "to reach Diablo 2 level " + apD2Level;
              break;
            case WAR3:
            case W3XP:
              msg += "to reach Warcraft 3 level " + apW3Level;
              break;
            default:
              break apBlock;
            }
            msg += " to recieve a promotion!";
            user.sendChat(msg, true);
          }
        }

        // Greetings
        String greeting = rsRank.getGreeting();
        if(greeting != null) {
          try {
            greeting = String.format(greeting, user.toString(), user.getPing(), user.getFullLogonName());
            source.sendChat(greeting);
          } catch(NoSuchMethodError e) {
View Full Code Here

  public static void registerCommand(String name, CommandRunnable action) {
    if(commands.get(name) != null)
      throw new IllegalArgumentException("The command " + name + " is already registered");

    if(Command.get(name) == null) {
      Rank max = Rank.getMax();

      Command c = DatabaseContext.getContext().newObject(Command.class);
      c.setRank(max);
      c.setCmdgroup(null);
      c.setDescription(null);
      c.setName(name);
      try {
        c.updateRow();
      } catch (Exception e) {
        throw new IllegalStateException(e);
      }

      String message = "Created command " + name + " with access " + max.getAccess() + "; to change, use %trigger%setauth " + name + " <access>";
      for(Account a : max.getAccountArray())
        try {
          Mail.send(null, a, message);
        } catch (Exception e) {
          throw new IllegalStateException(e);
        }
View Full Code Here

      if(account != null) {
        String name = account.getName();
        if(name != null)
          shortPrettyName = name;

        Rank rank = account.getRank();
        if(rank != null) {
          String prefix = rank.getShortPrefix();
          if(prefix == null)
            prefix = rank.getPrefix();
          if(prefix != null)
            shortPrettyName = prefix + " " + shortPrettyName;
        }
      }
    } catch(Exception e) {
View Full Code Here

      if(account != null) {
        String name = account.getName();
        if(name != null)
          prettyName = name + " (" + prettyName + ")";

        Rank rank = account.getRank();
        if(rank != null) {
          String prefix = rank.getPrefix();
          if(prefix != null)
            prettyName = prefix + " " + prettyName;
        }
      }
    } catch(Exception e) {
View Full Code Here

        throw new CommandFailedWithDetailsException("That command does not exist!");

      try {
        int oldAccess = rsCommand.getAccess();
        int access = Integer.parseInt(params[1]);
        Rank rank = Rank.get(access);
        if(rank == null)
          throw new CommandFailedWithDetailsException("That access level does not exist!");
        rsCommand.setRank(rank);
        rsCommand.updateRow();
View Full Code Here

      }

      List<String> clauses = new LinkedList<String>();

      // Access
      Rank rsSubjectRank = rsSubjectAccount.getRank();
      if(rsSubjectRank != null) {
        String prefix = rsSubjectRank.getShortPrefix();
        String prefix2 = rsSubjectRank.getPrefix();
        if(prefix == null)
          prefix = prefix2;

        if(prefix == null)
          prefix = "";
        else
          prefix += " ";

        String result = prefix + rsSubjectAccount.getName();
        if(rsSubjectRank.getVerbstr() != null)
          result += " " + rsSubjectRank.getVerbstr();
        else {
          switch(prefix.charAt(0)) {
          case 'a': case 'e': case 'i': case 'o': case 'u':
          case 'A': case 'E': case 'I': case 'O': case 'U':
            result += " is an ";
View Full Code Here

        }

      String out = "Accounts found: ";
      boolean first = true;
      for(int i = access; i <= accessUpper; i++) {
        Rank rank = Rank.get(i);
        if(rank == null)
          continue;
        for(Account account : rank.getAccountArray()) {
          if(!first)
            out += ", ";
          first = false;
          out += account.getName();
          out += " {" + i + "}";
View Full Code Here

        timeElapsed = (long)Math.floor(te) + "." + timeElapsed;
      } else {
        timeElapsed = "?";
      }

      Rank rsRank = subject.getRank();
      if(rsRank == null) {
        String result = "Rank does not exist! ";
        result += subject.getName() + "'s current status is: ";
        result += timeElapsed + " days, ";
        result += wins[0] + " wins, ";
        result += wins[1] + " D2 level, ";
        result += wins[2] + " W3 level";

        throw new CommandFailedWithDetailsException(result);
      }

      Integer apDays = rsRank.getApDays();
      Integer apWins = rsRank.getApWins();
      Integer apD2Level = rsRank.getApD2Level();
      Integer apW3Level = rsRank.getApW3Level();
      Integer apRecruitScore = rsRank.getApRecruitScore();

      // Check if any fields are null
      boolean condition = false;
      condition |= (apDays == null);
      condition |= (apWins == null);
View Full Code Here

  @SuppressWarnings("unchecked")
  private static void flush(ObjectContext context) {
    long defaultMaxAge = 90;
    {
      Rank rank = Rank.get(0);
      if(rank != null)
        defaultMaxAge = rank.getExpireDays();
    }

    boolean debugEnabled = Out.isDebug(DatabaseContext.class);

    for(BNLogin login : (List<BNLogin>)context.performQuery(new SelectQuery(BNLogin.class))) {
      long age = login.getLastSeen().getTime();
      age = System.currentTimeMillis() - age;
      age /= 86400000l; // convert to days

      long maxAge = defaultMaxAge;
      Account account = login.getAccount();
      if(account != null) {
        Rank rank = account.getRank();
        if(rank != null)
          maxAge = rank.getExpireDays();
      }

      if(maxAge == 0)
        continue;
      if(age <= maxAge)
View Full Code Here

TOP

Related Classes of net.bnubot.db.Rank

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.