Example #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 + "})");
 }
Example #2
0
  private final void writeToDB(final boolean bDisband) {
    try {
      Connection con = DatabaseConnection.getConnection();
      if (!bDisband) {
        StringBuilder buf =
            new StringBuilder(
                "UPDATE guilds SET GP = ?, logo = ?, logoColor = ?, logoBG = ?, logoBGColor = ?, ");
        for (int i = 1; i < 6; i++) {
          buf.append("rank" + i + "title = ?, ");
        }
        buf.append("capacity = ?, " + "notice = ?, alliance = ? WHERE guildid = ?");

        PreparedStatement ps = con.prepareStatement(buf.toString());
        ps.setInt(1, gp);
        ps.setInt(2, logo);
        ps.setInt(3, logoColor);
        ps.setInt(4, logoBG);
        ps.setInt(5, logoBGColor);
        ps.setString(6, rankTitles[0]);
        ps.setString(7, rankTitles[1]);
        ps.setString(8, rankTitles[2]);
        ps.setString(9, rankTitles[3]);
        ps.setString(10, rankTitles[4]);
        ps.setInt(11, capacity);
        ps.setString(12, notice);
        ps.setInt(13, allianceid);
        ps.setInt(14, id);
        ps.execute();
        ps.close();
      } else {
        PreparedStatement ps =
            con.prepareStatement(
                "UPDATE characters SET guildid = 0, guildrank = 5 WHERE guildid = ?");
        ps.setInt(1, id);
        ps.execute();
        ps.close();

        // delete the alliance
        if (allianceid > 0) {
          if (getAlliance(null).getGuilds().get(0).getLeaderId() == getLeaderId()) {
            ps = con.prepareStatement("DELETE FROM alliances WHERE id = ?");
            ps.setInt(1, allianceid);
            ps.execute();
            ps.close();
          }
        }

        ps = con.prepareStatement("DELETE FROM guilds WHERE guildid = ?");
        ps.setInt(1, id);
        ps.execute();
        ps.close();

        broadcast(GuildPacket.guildDisband(id));
      }
    } catch (SQLException se) {
      System.err.println("Error saving guild to SQL" + se);
    }
  }
Example #3
0
 public final void memberLevelJobUpdate(final MapleGuildCharacter mgc) {
   for (final MapleGuildCharacter member : members) {
     if (member.getId() == mgc.getId()) {
       member.setJobId(mgc.getJobId());
       member.setReborns((short) mgc.getReborns());
       broadcast(GuildPacket.guildMemberLevelJobUpdate(mgc));
       break;
     }
   }
 }
Example #4
0
  public final void leaveGuild(final MapleGuildCharacter mgc) {
    broadcast(GuildPacket.memberLeft(mgc, false));

    lock.lock();
    try {
      members.remove(mgc);
      bDirty = true;
    } finally {
      lock.unlock();
    }
  }
Example #5
0
 // null indicates successful invitation being sent
 // keep in mind that this will be called by a handler most of the time
 // so this will be running mostly on a channel server, unlike the rest
 // of the class
 public static final MapleGuildResponse sendInvite(final MapleClient c, final String targetName) {
   final MapleCharacter mc =
       c.getChannelServer().getPlayerStorage().getCharacterByName(targetName);
   if (mc == null) {
     return MapleGuildResponse.NOT_IN_CHANNEL;
   }
   if (mc.getGuildId() > 0) {
     return MapleGuildResponse.ALREADY_IN_GUILD;
   }
   mc.getClient()
       .getSession()
       .write(GuildPacket.guildInvite(c.getPlayer().getGuildId(), c.getPlayer().getName()));
   return null;
 }
Example #6
0
  public final void gainGP(final int amount) {
    gp += amount;
    guildMessage(GuildPacket.updateGP(id, gp));

    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps = con.prepareStatement("UPDATE guilds SET gp = ? WHERE guildid = ?");
      ps.setInt(1, this.gp);
      ps.setInt(2, this.id);
      ps.execute();
      ps.close();
    } catch (SQLException e) {
      System.err.println("Saving guild point ERROR" + e);
    }
  }
Example #7
0
  public final void setGuildNotice(final String notice) {
    this.notice = notice;
    broadcast(GuildPacket.guildNotice(id, notice));

    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps = con.prepareStatement("UPDATE guilds SET notice = ? WHERE guildid = ?");
      ps.setString(1, notice);
      ps.setInt(2, id);
      ps.execute();
      ps.close();
    } catch (SQLException e) {
      System.err.println("Saving notice ERROR" + e);
    }
  }
Example #8
0
  public final void setOnline(final int cid, final boolean online, final int channel) {
    boolean bBroadcast = true;

    for (final MapleGuildCharacter mgc : members) {
      if (mgc.getId() == cid) {
        if (mgc.isOnline() && online) {
          bBroadcast = false;
        }
        mgc.setOnline(online);
        mgc.setChannel((byte) channel);
        break;
      }
    }
    if (bBroadcast) {
      broadcast(GuildPacket.guildMemberOnline(id, cid, online), cid);
    }
    bDirty = true; // member formation has changed, update notifications
  }
Example #9
0
  public final boolean increaseCapacity() {
    if (capacity >= 100 || ((capacity + 5) > 100)) {
      return false;
    }
    capacity += 5;
    broadcast(GuildPacket.guildCapacityChange(this.id, this.capacity));

    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps =
          con.prepareStatement("UPDATE guilds SET capacity = ? WHERE guildid = ?");
      ps.setInt(1, this.capacity);
      ps.setInt(2, this.id);
      ps.execute();
      ps.close();
    } catch (SQLException e) {
      System.err.println("Saving guild capacity ERROR" + e);
    }
    return true;
  }
Example #10
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;
        }
      }
    }
  }
Example #11
0
  public final void changeRankTitle(final String[] ranks) {
    for (int i = 0; i < 5; i++) {
      rankTitles[i] = ranks[i];
    }
    broadcast(GuildPacket.rankTitleChange(id, ranks));

    try {
      Connection con = DatabaseConnection.getConnection();
      PreparedStatement ps =
          con.prepareStatement(
              "UPDATE guilds SET rank1title = ?, rank2title = ?, rank3title = ?, rank4title = ?, rank5title = ? WHERE guildid = ?");
      for (int i = 0; i < 5; i++) {
        ps.setString(i + 1, rankTitles[i]);
      }
      ps.setInt(6, id);
      ps.execute();
      ps.close();
    } catch (SQLException e) {
      System.err.println("Saving rankTitle ERROR" + e);
    }
  }
Example #12
0
 public final int addGuildMember(final MapleGuildCharacter mgc) {
   // first of all, insert it into the members keeping alphabetical order of lowest ranks ;)
   lock.lock();
   try {
     if (members.size() >= capacity) {
       return 0;
     }
     for (int i = members.size() - 1; i >= 0; i--) {
       if (members.get(i).getGuildRank() < 5
           || members.get(i).getName().compareTo(mgc.getName()) < 0) {
         members.add(i + 1, mgc);
         bDirty = true;
         break;
       }
     }
   } finally {
     lock.unlock();
   }
   broadcast(GuildPacket.newGuildMember(mgc));
   return 1;
 }