source
Source for my MapleSolaxiaV2 (v83 MapleStory).
This commit is contained in:
230
src/net/server/guild/MapleAlliance.java
Normal file
230
src/net/server/guild/MapleAlliance.java
Normal file
@@ -0,0 +1,230 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.guild;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import tools.DatabaseConnection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory.
|
||||
*/
|
||||
public class MapleAlliance {
|
||||
private int[] guilds = new int[5];
|
||||
private int allianceId = -1;
|
||||
private int capacity;
|
||||
private String name;
|
||||
private String notice = "";
|
||||
private String rankTitles[] = new String[5];
|
||||
|
||||
public MapleAlliance(String name, int id, int guild1, int guild2) {
|
||||
this.name = name;
|
||||
allianceId = id;
|
||||
int[] guild = {guild1, guild2, -1, -1, -1};
|
||||
String[] ranks = {"Master", "Jr.Master", "Member", "Member", "Member"};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
guilds[i] = guild[i];
|
||||
rankTitles[i] = ranks[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static MapleAlliance loadAlliance(int id) {
|
||||
if (id <= 0) {
|
||||
return null;
|
||||
}
|
||||
MapleAlliance alliance = new MapleAlliance(null, -1, -1, -1);
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
return null;
|
||||
}
|
||||
alliance.allianceId = id;
|
||||
alliance.capacity = rs.getInt("capacity");
|
||||
alliance.name = rs.getString("name");
|
||||
alliance.notice = rs.getString("notice");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
alliance.rankTitles[i - 1] = rs.getString("rank_title" + i);
|
||||
}
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
alliance.guilds[i - 1] = rs.getInt("guild" + i);
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
return alliance;
|
||||
}
|
||||
|
||||
public void saveToDB() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("capacity = ?, ");
|
||||
sb.append("notice = ?, ");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
sb.append("rank_title").append(i).append(" = ?, ");
|
||||
}
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
sb.append("guild").append(i).append(" = ?, ");
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE `alliance` SET " + sb.toString() + " WHERE id = ?");
|
||||
ps.setInt(1, this.capacity);
|
||||
ps.setString(2, this.notice);
|
||||
for (int i = 0; i < rankTitles.length; i++) {
|
||||
ps.setString(i + 3, rankTitles[i]);
|
||||
}
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
ps.setInt(i + 8, guilds[i]);
|
||||
}
|
||||
ps.setInt(13, this.allianceId);
|
||||
ps.executeQuery();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addRemGuildFromDB(int gid, boolean add) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
boolean ret = false;
|
||||
try {
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
ps.setInt(1, this.allianceId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
int avail = -1;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
int guildId = rs.getInt("guild" + i);
|
||||
if (add) {
|
||||
if (guildId == -1) {
|
||||
avail = i;
|
||||
break;
|
||||
}
|
||||
} else if (guildId == gid) {
|
||||
avail = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
if (avail != -1) { // empty slot
|
||||
ps = con.prepareStatement("UPDATE alliance SET guild" + avail + " = ? WHERE id = ?");
|
||||
if (add) {
|
||||
ps.setInt(1, gid);
|
||||
} else {
|
||||
ps.setInt(1, -1);
|
||||
}
|
||||
ps.setInt(2, this.allianceId);
|
||||
ps.executeUpdate();
|
||||
ret = true;
|
||||
}
|
||||
ps.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean removeGuild(int gid) {
|
||||
synchronized (guilds) {
|
||||
int gIndex = getGuildIndex(gid);
|
||||
if (gIndex != -1) {
|
||||
guilds[gIndex] = -1;
|
||||
}
|
||||
return addRemGuildFromDB(gid, false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addGuild(int gid) {
|
||||
synchronized (guilds) {
|
||||
if (getGuildIndex(gid) == -1) {
|
||||
int emptyIndex = getGuildIndex(-1);
|
||||
if (emptyIndex != -1) {
|
||||
guilds[emptyIndex] = gid;
|
||||
return addRemGuildFromDB(gid, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getGuildIndex(int gid) {
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
if (guilds[i] == gid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void setRankTitle(String[] ranks) {
|
||||
rankTitles = ranks;
|
||||
}
|
||||
|
||||
public void setNotice(String notice) {
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return allianceId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRankTitle(int rank) {
|
||||
return rankTitles[rank - 1];
|
||||
}
|
||||
|
||||
public String getAllianceNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public List<Integer> getGuilds() {
|
||||
List<Integer> guilds_ = new LinkedList<Integer>();
|
||||
for (int guild : guilds) {
|
||||
if (guild != -1) {
|
||||
guilds_.add(guild);
|
||||
}
|
||||
}
|
||||
return guilds_;
|
||||
}
|
||||
|
||||
public String getNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public void increaseCapacity(int inc) {
|
||||
capacity += inc;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
557
src/net/server/guild/MapleGuild.java
Normal file
557
src/net/server/guild/MapleGuild.java
Normal file
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.guild;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import tools.LogHelper;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
public class MapleGuild {
|
||||
public final static int CREATE_GUILD_COST = 1500000;
|
||||
public final static int CHANGE_EMBLEM_COST = 5000000;
|
||||
|
||||
private enum BCOp {
|
||||
NONE, DISBAND, EMBELMCHANGE
|
||||
}
|
||||
private List<MapleGuildCharacter> members;
|
||||
private String rankTitles[] = new String[5]; // 1 = master, 2 = jr, 5 = lowest member
|
||||
private String name, notice;
|
||||
private int id, gp, logo, logoColor, leader, capacity, logoBG, logoBGColor, signature, allianceId;
|
||||
private int world;
|
||||
private Map<Integer, List<Integer>> notifications = new LinkedHashMap<>();
|
||||
private boolean bDirty = true;
|
||||
|
||||
|
||||
|
||||
public MapleGuild(int guildid, int world) {
|
||||
this.world = world;
|
||||
members = new ArrayList<>();
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
try {
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM guilds WHERE guildid = " + guildid);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.first()) {
|
||||
id = -1;
|
||||
ps.close();
|
||||
rs.close();
|
||||
return;
|
||||
}
|
||||
id = guildid;
|
||||
name = rs.getString("name");
|
||||
gp = rs.getInt("GP");
|
||||
logo = rs.getInt("logo");
|
||||
logoColor = rs.getInt("logoColor");
|
||||
logoBG = rs.getInt("logoBG");
|
||||
logoBGColor = rs.getInt("logoBGColor");
|
||||
capacity = rs.getInt("capacity");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
rankTitles[i - 1] = rs.getString("rank" + i + "title");
|
||||
}
|
||||
leader = rs.getInt("leader");
|
||||
notice = rs.getString("notice");
|
||||
signature = rs.getInt("signature");
|
||||
allianceId = rs.getInt("allianceId");
|
||||
ps.close();
|
||||
rs.close();
|
||||
ps = con.prepareStatement("SELECT id, name, level, job, guildrank, allianceRank FROM characters WHERE guildid = ? ORDER BY guildrank ASC, name ASC");
|
||||
ps.setInt(1, guildid);
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.first()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
return;
|
||||
}
|
||||
do {
|
||||
members.add(new MapleGuildCharacter(rs.getInt("id"), rs.getInt("level"), rs.getString("name"), (byte) -1, world, rs.getInt("job"), rs.getInt("guildrank"), guildid, false, rs.getInt("allianceRank")));
|
||||
} while (rs.next());
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
} catch (SQLException se) {
|
||||
System.out.println("unable to read guild information from sql" + se);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildNotifications() {
|
||||
if (!bDirty) {
|
||||
return;
|
||||
}
|
||||
Set<Integer> chs = Server.getInstance().getChannelServer(world);
|
||||
if (notifications.keySet().size() != chs.size()) {
|
||||
notifications.clear();
|
||||
for (Integer ch : chs) {
|
||||
notifications.put(ch, new LinkedList<Integer>());
|
||||
}
|
||||
} else {
|
||||
for (List<Integer> l : notifications.values()) {
|
||||
l.clear();
|
||||
}
|
||||
}
|
||||
synchronized (members) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
if (!mgc.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
List<Integer> ch = notifications.get(mgc.getChannel());
|
||||
if (ch != null) ch.add(mgc.getId());
|
||||
//Unable to connect to Channel... error was here
|
||||
}
|
||||
}
|
||||
bDirty = false;
|
||||
}
|
||||
|
||||
public void writeToDB(boolean bDisband) {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
if (!bDisband) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("UPDATE guilds SET GP = ?, logo = ?, logoColor = ?, logoBG = ?, logoBGColor = ?, ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
builder.append("rank").append(i + 1).append("title = ?, ");
|
||||
}
|
||||
builder.append("capacity = ?, notice = ? WHERE guildid = ?");
|
||||
try (PreparedStatement ps = con.prepareStatement(builder.toString())) {
|
||||
ps.setInt(1, gp);
|
||||
ps.setInt(2, logo);
|
||||
ps.setInt(3, logoColor);
|
||||
ps.setInt(4, logoBG);
|
||||
ps.setInt(5, logoBGColor);
|
||||
for (int i = 6; i < 11; i++) {
|
||||
ps.setString(i, rankTitles[i - 6]);
|
||||
}
|
||||
ps.setInt(11, capacity);
|
||||
ps.setString(12, notice);
|
||||
ps.setInt(13, this.id);
|
||||
ps.execute();
|
||||
}
|
||||
} else {
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = 0, guildrank = 5 WHERE guildid = ?");
|
||||
ps.setInt(1, this.id);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
ps = con.prepareStatement("DELETE FROM guilds WHERE guildid = ?");
|
||||
ps.setInt(1, this.id);
|
||||
ps.execute();
|
||||
ps.close();
|
||||
this.broadcast(MaplePacketCreator.guildDisband(this.id));
|
||||
}
|
||||
} catch (SQLException se) {
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getLeaderId() {
|
||||
return leader;
|
||||
}
|
||||
|
||||
public int getGP() {
|
||||
return gp;
|
||||
}
|
||||
|
||||
public int getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(int l) {
|
||||
logo = l;
|
||||
}
|
||||
|
||||
public int getLogoColor() {
|
||||
return logoColor;
|
||||
}
|
||||
|
||||
public void setLogoColor(int c) {
|
||||
logoColor = c;
|
||||
}
|
||||
|
||||
public int getLogoBG() {
|
||||
return logoBG;
|
||||
}
|
||||
|
||||
public void setLogoBG(int bg) {
|
||||
logoBG = bg;
|
||||
}
|
||||
|
||||
public int getLogoBGColor() {
|
||||
return logoBGColor;
|
||||
}
|
||||
|
||||
public void setLogoBGColor(int c) {
|
||||
logoBGColor = c;
|
||||
}
|
||||
|
||||
public String getNotice() {
|
||||
if (notice == null) {
|
||||
return "";
|
||||
}
|
||||
return notice;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public java.util.Collection<MapleGuildCharacter> getMembers() {
|
||||
return java.util.Collections.unmodifiableCollection(members);
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public int getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void broadcast(final byte[] packet) {
|
||||
broadcast(packet, -1, BCOp.NONE);
|
||||
}
|
||||
|
||||
public void broadcast(final byte[] packet, int exception) {
|
||||
broadcast(packet, exception, BCOp.NONE);
|
||||
}
|
||||
|
||||
public void broadcast(final byte[] packet, int exceptionId, BCOp bcop) {
|
||||
synchronized (notifications) {
|
||||
if (bDirty) {
|
||||
buildNotifications();
|
||||
}
|
||||
try {
|
||||
for (Integer b : Server.getInstance().getChannelServer(world)) {
|
||||
if (notifications.get(b).size() > 0) {
|
||||
if (bcop == BCOp.DISBAND) {
|
||||
Server.getInstance().getWorld(world).setGuildAndRank(notifications.get(b), 0, 5, exceptionId);
|
||||
} else if (bcop == BCOp.EMBELMCHANGE) {
|
||||
Server.getInstance().getWorld(world).changeEmblem(this.id, notifications.get(b), new MapleGuildSummary(this));
|
||||
} else {
|
||||
Server.getInstance().getWorld(world).sendPacket(notifications.get(b), packet, exceptionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception re) {
|
||||
System.out.println("Failed to contact channel(s) for broadcast.");//fu?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void guildMessage(final byte[] serverNotice) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
for (Channel cs : Server.getInstance().getChannelsFromWorld(world)) {
|
||||
if (cs.getPlayerStorage().getCharacterById(mgc.getId()) != null) {
|
||||
cs.getPlayerStorage().getCharacterById(mgc.getId()).getClient().announce(serverNotice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void setOnline(int cid, boolean online, int channel) {
|
||||
boolean bBroadcast = true;
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
if (mgc.getId() == cid) {
|
||||
if (mgc.isOnline() && online) {
|
||||
bBroadcast = false;
|
||||
}
|
||||
mgc.setOnline(online);
|
||||
mgc.setChannel(channel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bBroadcast) {
|
||||
this.broadcast(MaplePacketCreator.guildMemberOnline(id, cid, online), cid);
|
||||
}
|
||||
bDirty = true;
|
||||
}
|
||||
|
||||
public void guildChat(String name, int cid, String message) {
|
||||
this.broadcast(MaplePacketCreator.multiChat(name, message, 2), cid);
|
||||
}
|
||||
|
||||
public String getRankTitle(int rank) {
|
||||
return rankTitles[rank - 1];
|
||||
}
|
||||
|
||||
public static int createGuild(int leaderId, String name) {
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT guildid FROM guilds WHERE name = ?");
|
||||
ps.setString(1, name);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.first()) {
|
||||
ps.close();
|
||||
rs.close();
|
||||
return 0;
|
||||
}
|
||||
ps.close();
|
||||
rs.close();
|
||||
ps = con.prepareStatement("INSERT INTO guilds (`leader`, `name`, `signature`) VALUES (?, ?, ?)");
|
||||
ps.setInt(1, leaderId);
|
||||
ps.setString(2, name);
|
||||
ps.setInt(3, (int) System.currentTimeMillis());
|
||||
ps.execute();
|
||||
ps.close();
|
||||
ps = con.prepareStatement("SELECT guildid FROM guilds WHERE leader = ?");
|
||||
ps.setInt(1, leaderId);
|
||||
rs = ps.executeQuery();
|
||||
rs.first();
|
||||
int guildid = rs.getInt("guildid");
|
||||
rs.close();
|
||||
ps.close();
|
||||
return guildid;
|
||||
} catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int addGuildMember(MapleGuildCharacter mgc) {
|
||||
synchronized (members) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.broadcast(MaplePacketCreator.newGuildMember(mgc));
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void leaveGuild(MapleGuildCharacter mgc) {
|
||||
this.broadcast(MaplePacketCreator.memberLeft(mgc, false));
|
||||
synchronized (members) {
|
||||
members.remove(mgc);
|
||||
bDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void expelMember(MapleGuildCharacter initiator, String name, int cid) {
|
||||
synchronized (members) {
|
||||
java.util.Iterator<MapleGuildCharacter> itr = members.iterator();
|
||||
MapleGuildCharacter mgc;
|
||||
while (itr.hasNext()) {
|
||||
mgc = itr.next();
|
||||
if (mgc.getId() == cid && initiator.getGuildRank() < mgc.getGuildRank()) {
|
||||
this.broadcast(MaplePacketCreator.memberLeft(mgc, true));
|
||||
itr.remove();
|
||||
bDirty = true;
|
||||
try {
|
||||
if (mgc.isOnline()) {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(cid, 0, 5);
|
||||
} else {
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().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();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
System.out.println("expelMember - MapleGuild " + e);
|
||||
}
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setOfflineGuildStatus((short) 0, (byte) 5, cid);
|
||||
}
|
||||
} catch (Exception re) {
|
||||
re.printStackTrace();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("Unable to find member with name " + name + " and id " + cid);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeRank(int cid, int newRank) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
if (cid == mgc.getId()) {
|
||||
try {
|
||||
if (mgc.isOnline()) {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(cid, this.id, newRank);
|
||||
} else {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setOfflineGuildStatus((short) this.id, (byte) newRank, cid);
|
||||
}
|
||||
} catch (Exception re) {
|
||||
re.printStackTrace();
|
||||
return;
|
||||
}
|
||||
mgc.setGuildRank(newRank);
|
||||
this.broadcast(MaplePacketCreator.changeRank(mgc));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setGuildNotice(String notice) {
|
||||
this.notice = notice;
|
||||
writeToDB(false);
|
||||
this.broadcast(MaplePacketCreator.guildNotice(this.id, notice));
|
||||
}
|
||||
|
||||
public void memberLevelJobUpdate(MapleGuildCharacter mgc) {
|
||||
for (MapleGuildCharacter member : members) {
|
||||
if (mgc.equals(member)) {
|
||||
member.setJobId(mgc.getJobId());
|
||||
member.setLevel(mgc.getLevel());
|
||||
this.broadcast(MaplePacketCreator.guildMemberLevelJobUpdate(mgc));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof MapleGuildCharacter)) {
|
||||
return false;
|
||||
}
|
||||
MapleGuildCharacter o = (MapleGuildCharacter) other;
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
hash = 89 * hash + this.id;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public void changeRankTitle(String[] ranks) {
|
||||
System.arraycopy(ranks, 0, rankTitles, 0, 5);
|
||||
this.broadcast(MaplePacketCreator.rankTitleChange(this.id, ranks));
|
||||
this.writeToDB(false);
|
||||
}
|
||||
|
||||
public void disbandGuild() {
|
||||
this.writeToDB(true);
|
||||
this.broadcast(null, -1, BCOp.DISBAND);
|
||||
}
|
||||
|
||||
public void setGuildEmblem(short bg, byte bgcolor, short logo, byte logocolor) {
|
||||
this.logoBG = bg;
|
||||
this.logoBGColor = bgcolor;
|
||||
this.logo = logo;
|
||||
this.logoColor = logocolor;
|
||||
this.writeToDB(false);
|
||||
this.broadcast(null, -1, BCOp.EMBELMCHANGE);
|
||||
}
|
||||
|
||||
public MapleGuildCharacter getMGC(int cid) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
if (mgc.getId() == cid) {
|
||||
return mgc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean increaseCapacity() {
|
||||
if (capacity > 99) {
|
||||
return false;
|
||||
}
|
||||
capacity += 5;
|
||||
this.writeToDB(false);
|
||||
this.broadcast(MaplePacketCreator.guildCapacityChange(this.id, this.capacity));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void gainGP(int amount) {
|
||||
this.gp += amount;
|
||||
this.writeToDB(false);
|
||||
this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));
|
||||
this.guildMessage(MaplePacketCreator.getGPMessage(amount));
|
||||
}
|
||||
|
||||
public void removeGP(int amount){
|
||||
this.gp -= amount;
|
||||
this.writeToDB(false);
|
||||
this.guildMessage(MaplePacketCreator.updateGP(this.id, this.gp));
|
||||
}
|
||||
|
||||
public static MapleGuildResponse sendInvite(MapleClient c, String targetName) {
|
||||
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().announce(MaplePacketCreator.guildInvite(c.getPlayer().getGuildId(), c.getPlayer().getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void displayGuildRanks(MapleClient c, int npcid) {
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT `name`, `GP`, `logoBG`, `logoBGColor`, `logo`, `logoColor` FROM guilds WHERE NOT `guildid` = '1' ORDER BY `GP` DESC LIMIT 50")) {
|
||||
rs = ps.executeQuery();
|
||||
c.announce(MaplePacketCreator.showGuildRanks(npcid, rs));
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
System.out.println("failed to display guild ranks. " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAllianceId() {
|
||||
return allianceId;
|
||||
}
|
||||
|
||||
public void setAllianceId(int aid) {
|
||||
this.allianceId = aid;
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE guilds SET allianceId = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, aid);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public int getIncreaseGuildCost(int size) {
|
||||
return 500000 * (size - 6) / 6;
|
||||
}
|
||||
}
|
||||
149
src/net/server/guild/MapleGuildCharacter.java
Normal file
149
src/net/server/guild/MapleGuildCharacter.java
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.guild;
|
||||
|
||||
import client.MapleCharacter;
|
||||
|
||||
public class MapleGuildCharacter {
|
||||
private int level;
|
||||
private int id;
|
||||
private int world, channel;
|
||||
private int jobid;
|
||||
private int guildrank;
|
||||
private int guildid;
|
||||
private int allianceRank;
|
||||
private boolean online;
|
||||
private String name;
|
||||
|
||||
public MapleGuildCharacter(MapleCharacter c) {
|
||||
this.name = c.getName();
|
||||
this.level = c.getLevel();
|
||||
this.id = c.getId();
|
||||
this.channel = c.getClient().getChannel();
|
||||
this.world = c.getWorld();
|
||||
this.jobid = c.getJob().getId();
|
||||
this.guildrank = c.getGuildRank();
|
||||
this.guildid = c.getGuildId();
|
||||
this.online = true;
|
||||
this.allianceRank = c.getAllianceRank();
|
||||
}
|
||||
|
||||
public MapleGuildCharacter(int _id, int _lv, String _name, int _channel, int _world, int _job, int _rank, int _gid, boolean _on, int _allianceRank) {
|
||||
this.level = _lv;
|
||||
this.id = _id;
|
||||
this.name = _name;
|
||||
if (_on) {
|
||||
this.channel = _channel;
|
||||
this.world = _world;
|
||||
}
|
||||
this.jobid = _job;
|
||||
this.online = _on;
|
||||
this.guildrank = _rank;
|
||||
this.guildid = _gid;
|
||||
this.allianceRank = _allianceRank;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int l) {
|
||||
level = l;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setChannel(int ch) {
|
||||
channel = ch;
|
||||
}
|
||||
|
||||
public int getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public int getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public int getJobId() {
|
||||
return jobid;
|
||||
}
|
||||
|
||||
public void setJobId(int job) {
|
||||
jobid = job;
|
||||
}
|
||||
|
||||
public int getGuildId() {
|
||||
return guildid;
|
||||
}
|
||||
|
||||
public void setGuildId(int gid) {
|
||||
guildid = gid;
|
||||
}
|
||||
|
||||
public void setGuildRank(int rank) {
|
||||
guildrank = rank;
|
||||
}
|
||||
|
||||
public int getGuildRank() {
|
||||
return guildrank;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
|
||||
public void setOnline(boolean f) {
|
||||
online = f;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setAllianceRank(int rank) {
|
||||
allianceRank = rank;
|
||||
}
|
||||
|
||||
public int getAllianceRank() {
|
||||
return allianceRank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof MapleGuildCharacter)) {
|
||||
return false;
|
||||
}
|
||||
MapleGuildCharacter o = (MapleGuildCharacter) other;
|
||||
return (o.getId() == id && o.getName().equals(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 19 * hash + this.id;
|
||||
hash = 19 * hash + (this.name != null ? this.name.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
39
src/net/server/guild/MapleGuildResponse.java
Normal file
39
src/net/server/guild/MapleGuildResponse.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.guild;
|
||||
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
public enum MapleGuildResponse {
|
||||
NOT_IN_CHANNEL(0x2a),
|
||||
ALREADY_IN_GUILD(0x28),
|
||||
NOT_IN_GUILD(0x2d);
|
||||
private int value;
|
||||
|
||||
private MapleGuildResponse(int val) {
|
||||
value = val;
|
||||
}
|
||||
|
||||
public final byte[] getPacket() {
|
||||
return MaplePacketCreator.genericGuildMessage((byte) value);
|
||||
}
|
||||
}
|
||||
64
src/net/server/guild/MapleGuildSummary.java
Normal file
64
src/net/server/guild/MapleGuildSummary.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation version 3 as published by
|
||||
the Free Software Foundation. You may not use, modify or distribute
|
||||
this program under any other version of the GNU Affero General Public
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.server.guild;
|
||||
|
||||
public class MapleGuildSummary {
|
||||
private String name;
|
||||
private short logoBG;
|
||||
private byte logoBGColor;
|
||||
private short logo;
|
||||
private byte logoColor;
|
||||
private int allianceId;
|
||||
|
||||
public MapleGuildSummary(MapleGuild g) {
|
||||
this.name = g.getName();
|
||||
this.logoBG = (short) g.getLogoBG();
|
||||
this.logoBGColor = (byte) g.getLogoBGColor();
|
||||
this.logo = (short) g.getLogo();
|
||||
this.logoColor = (byte) g.getLogoColor();
|
||||
this.allianceId = g.getAllianceId();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public short getLogoBG() {
|
||||
return logoBG;
|
||||
}
|
||||
|
||||
public byte getLogoBGColor() {
|
||||
return logoBGColor;
|
||||
}
|
||||
|
||||
public short getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public byte getLogoColor() {
|
||||
return logoColor;
|
||||
}
|
||||
|
||||
public int getAllianceId() {
|
||||
return allianceId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user