Exemple #1
0
 public final void changeRank(final int cid, final int newRank) {
   for (final MapleGuildCharacter mgc : members) {
     if (cid == mgc.getId()) {
       try {
         if (mgc.isOnline()) {
           WorldRegistryImpl.getInstance()
               .getChannel(mgc.getChannel())
               .setGuildAndRank(cid, this.id, newRank);
         } else {
           WorldRegistryImpl.getInstance()
               .getChannel(1)
               .setOfflineGuildStatus((short) this.id, (byte) newRank, cid);
         }
       } catch (RemoteException re) {
         re.printStackTrace();
         return;
       }
       mgc.setGuildRank(newRank);
       broadcast(GuildPacket.changeRank(mgc));
       return;
     }
   }
   // it should never get to this point unless cid was incorrect o_O
   System.err.println(
       "INFO: unable to find the correct id for changeRank({" + cid + "}, {" + newRank + "})");
 }
Exemple #2
0
  private final void buildNotifications() {
    // any function that calls this should be wrapped in synchronized(notifications) to make sure
    // that it doesn't change before that function finishes with the updated notifications
    if (!bDirty) {
      return;
    }
    final Set<Integer> chs = WorldRegistryImpl.getInstance().getChannelServer();

    if (notifications.keySet().size() != chs.size()) {
      notifications.clear();
      for (final Integer ch : chs) {
        notifications.put(ch, new java.util.LinkedList<Integer>());
      }
    } else {
      for (List<Integer> l : notifications.values()) {
        l.clear();
      }
    }
    for (final MapleGuildCharacter mgc : members) {
      if (!mgc.isOnline()) {
        continue;
      }
      final List<Integer> ch = notifications.get(mgc.getChannel());
      if (ch == null) {
        System.err.println("Unable to connect to channel " + mgc.getChannel());
      } else {
        ch.add(mgc.getId());
      }
    }
    bDirty = false;
  }
Exemple #3
0
  // multi-purpose function that reaches every member of guild (except the character with
  // exceptionId) in all channels with as little access to rmi as possible
  public final void broadcast(final MaplePacket packet, final int exceptionId, final BCOp bcop) {
    final WorldRegistryImpl wr = WorldRegistryImpl.getInstance();
    final Set<Integer> chs = wr.getChannelServer();

    lock.lock();
    try {
      buildNotifications();

      try { // now call the channelworldinterface
        for (final Integer ch : chs) {
          final ChannelWorldInterface cwi = wr.getChannel(ch);
          if (notifications.get(ch).size() > 0) {
            if (bcop == BCOp.DISBAND) {
              cwi.setGuildAndRank(notifications.get(ch), 0, 5, exceptionId);
            } else if (bcop == BCOp.EMBLEMCHANGE) {
              cwi.changeEmblem(id, notifications.get(ch), new MapleGuildSummary(this));
            } else {
              cwi.sendPacket(notifications.get(ch), packet, exceptionId);
            }
          }
        }
      } catch (RemoteException re) {
        System.err.println("Failed to contact channel(s) for broadcast." + re);
      }
    } finally {
      lock.unlock();
    }
  }
Exemple #4
0
  public final void expelMember(
      final MapleGuildCharacter initiator, final String name, final int cid) {
    final Iterator<MapleGuildCharacter> itr = members.iterator();
    while (itr.hasNext()) {
      final MapleGuildCharacter mgc = itr.next();

      if (mgc.getId() == cid && initiator.getGuildRank() < mgc.getGuildRank()) {
        broadcast(GuildPacket.memberLeft(mgc, true));

        bDirty = true;
        members.remove(mgc);

        try {
          if (mgc.isOnline()) {
            WorldRegistryImpl.getInstance().getChannel(mgc.getChannel()).setGuildAndRank(cid, 0, 5);
          } else {
            try {
              Connection con = DatabaseConnection.getConnection();
              PreparedStatement ps =
                  con.prepareStatement(
                      "INSERT INTO notes (`to`, `from`, `message`, `timestamp`) VALUES (?, ?, ?, ?)");
              ps.setString(1, mgc.getName());
              ps.setString(2, initiator.getName());
              ps.setString(3, "You have been expelled from the guild.");
              ps.setLong(4, System.currentTimeMillis());
              ps.executeUpdate();
              ps.close();
            } catch (SQLException e) {
              System.err.println("Error sending guild msg 'expelled'." + e);
            }
            WorldRegistryImpl.getInstance()
                .getChannel(1)
                .setOfflineGuildStatus((short) 0, (byte) 5, cid);
          }
        } catch (RemoteException re) {
          re.printStackTrace();
          return;
        }
      }
    }
  }