Partial solution on Guild Alliances
Revamped DB tables and enabled some functionalities on Guild Alliances, such as create one, expel/quit one and rank players.
This commit is contained in:
@@ -287,6 +287,7 @@ public class Server implements Runnable {
|
||||
MapleAlliance alliance = alliances.get(aId);
|
||||
if (alliance != null) {
|
||||
alliance.addGuild(guildId);
|
||||
guilds.get(guildId).setAllianceId(aId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -296,6 +297,7 @@ public class Server implements Runnable {
|
||||
MapleAlliance alliance = alliances.get(aId);
|
||||
if (alliance != null) {
|
||||
alliance.removeGuild(guildId);
|
||||
guilds.get(guildId).setAllianceId(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -346,6 +348,16 @@ public class Server implements Runnable {
|
||||
public int createGuild(int leaderId, String name) {
|
||||
return MapleGuild.createGuild(leaderId, name);
|
||||
}
|
||||
|
||||
public MapleGuild getGuild(int id) {
|
||||
synchronized (guilds) {
|
||||
if (guilds.get(id) != null) {
|
||||
return guilds.get(id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MapleGuild getGuild(int id, int world, MapleGuildCharacter mgc) {
|
||||
synchronized (guilds) {
|
||||
@@ -393,6 +405,10 @@ public class Server implements Runnable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetAllianceGuildPlayersRank(int gId) {
|
||||
guilds.get(gId).resetAllianceGuildPlayersRank();
|
||||
}
|
||||
|
||||
public void leaveGuild(MapleGuildCharacter mgc) {
|
||||
MapleGuild g = guilds.get(mgc.getGuildId());
|
||||
@@ -473,16 +489,16 @@ public class Server implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void guildMessage(int gid, byte[] packet) {
|
||||
guildMessage(gid, packet, -1);
|
||||
}
|
||||
public void guildMessage(int gid, byte[] packet) {
|
||||
guildMessage(gid, packet, -1);
|
||||
}
|
||||
|
||||
public void guildMessage(int gid, byte[] packet, int exception) {
|
||||
MapleGuild g = guilds.get(gid);
|
||||
if(g != null) {
|
||||
g.broadcast(packet, exception);
|
||||
}
|
||||
}
|
||||
public void guildMessage(int gid, byte[] packet, int exception) {
|
||||
MapleGuild g = guilds.get(gid);
|
||||
if(g != null) {
|
||||
g.broadcast(packet, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerBuffStorage getPlayerBuffStorage() {
|
||||
return buffStorage;
|
||||
|
||||
@@ -26,6 +26,7 @@ import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.SendOpcode;
|
||||
import net.server.Server;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
@@ -39,47 +40,67 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
System.out.print("aop ");
|
||||
|
||||
MapleAlliance alliance = null;
|
||||
if (c.getPlayer().getGuild() != null && c.getPlayer().getGuild().getAllianceId() > 0) {
|
||||
alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId());
|
||||
alliance = c.getPlayer().getAlliance();
|
||||
}
|
||||
if (alliance == null) {
|
||||
c.getPlayer().dropMessage("You are not in an alliance.");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
} else if (c.getPlayer().getMGC().getAllianceRank() > 2 || !alliance.getGuilds().contains(c.getPlayer().getGuildId())) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
switch (slea.readByte()) {
|
||||
|
||||
byte b = slea.readByte();
|
||||
System.out.print(b);
|
||||
switch (b) {
|
||||
case 0x01:
|
||||
System.out.print(" case 1");
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendShowInfo(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId()), -1, -1);
|
||||
break;
|
||||
case 0x02: { // Leave Alliance
|
||||
System.out.print(" case 2");
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1 || c.getPlayer().getGuildRank() != 1) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(c.getPlayer().getGuildId(), c.getPlayer().getId(), c.getPlayer().getGuildId(), 2), -1, -1);
|
||||
int guildid = c.getPlayer().getGuildId();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.removeGuildFromAlliance(alliance, guildid, c), -1, -1);
|
||||
Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1);
|
||||
Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(alliance.getId()));
|
||||
break;
|
||||
}
|
||||
case 0x03: // send alliance invite
|
||||
System.out.print(" case 3 avail is " + slea.available());
|
||||
String charName = slea.readMapleAsciiString();
|
||||
int channel;
|
||||
channel = c.getWorldServer().find(charName);
|
||||
if (channel == -1) {
|
||||
c.getPlayer().dropMessage("The player is not online.");
|
||||
|
||||
if(alliance.getGuilds().size() == alliance.getCapacity()) {
|
||||
c.getPlayer().dropMessage("Your alliance can not comport any more guild at the moment.");
|
||||
} else {
|
||||
MapleCharacter victim = Server.getInstance().getChannel(c.getWorld(), channel).getPlayerStorage().getCharacterByName(charName);
|
||||
if (victim.getGuildId() == 0) {
|
||||
c.getPlayer().dropMessage("The person you are trying to invite does not have a guild.");
|
||||
} else if (victim.getGuildRank() != 1) {
|
||||
c.getPlayer().dropMessage("The player is not the leader of his/her guild.");
|
||||
int channel;
|
||||
channel = c.getWorldServer().find(charName);
|
||||
if (channel == -1) {
|
||||
c.getPlayer().dropMessage("The player is not online.");
|
||||
} else {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readMapleAsciiString()), -1, -1);
|
||||
MapleCharacter victim = Server.getInstance().getChannel(c.getWorld(), channel).getPlayerStorage().getCharacterByName(charName);
|
||||
if (victim.getGuildId() == 0) {
|
||||
c.getPlayer().dropMessage("The person you are trying to invite does not have a guild.");
|
||||
} else if (victim.getGuildRank() != 1) {
|
||||
c.getPlayer().dropMessage("The player is not the leader of his/her guild.");
|
||||
} else {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), charName), -1, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 0x04: {
|
||||
System.out.print(" case 4");
|
||||
int guildid = slea.readInt();
|
||||
// slea.readMapleAsciiString();//guild name
|
||||
if (c.getPlayer().getGuild().getAllianceId() != 0 || c.getPlayer().getGuildRank() != 1 || c.getPlayer().getGuildId() < 1) {
|
||||
@@ -89,22 +110,36 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
break;
|
||||
}
|
||||
case 0x06: { // Expel Guild
|
||||
System.out.print(" case 6");
|
||||
int guildid = slea.readInt();
|
||||
int allianceid = slea.readInt();
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuild().getAllianceId() != allianceid) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(allianceid, c.getPlayer().getId(), guildid, 1), -1, -1);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.removeGuildFromAlliance(alliance, guildid, c), -1, -1);
|
||||
Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1);
|
||||
Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(allianceid));
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x07: { // Change Alliance Leader
|
||||
System.out.print(" case 7");
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readInt()), -1, -1);
|
||||
int victimid = slea.readInt();
|
||||
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(victimid);
|
||||
|
||||
//Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readInt()), -1, -1);
|
||||
changeLeaderAllianceRank(alliance, player);
|
||||
break;
|
||||
}
|
||||
case 0x08:
|
||||
System.out.print(" case 8");
|
||||
String ranks[] = new String[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ranks[i] = slea.readMapleAsciiString();
|
||||
@@ -113,12 +148,18 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.changeAllianceRankTitle(alliance.getId(), ranks), -1, -1);
|
||||
break;
|
||||
case 0x09: {
|
||||
System.out.print(" case 9");
|
||||
int int1 = slea.readInt();
|
||||
byte byte1 = slea.readByte();
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), int1, byte1), -1, -1);
|
||||
|
||||
//Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), int1, byte1), -1, -1);
|
||||
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(int1);
|
||||
changePlayerAllianceRank(alliance, player, (byte1 > 0));
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x0A:
|
||||
System.out.print(" case A");
|
||||
String notice = slea.readMapleAsciiString();
|
||||
Server.getInstance().setAllianceNotice(alliance.getId(), notice);
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), notice), -1, -1);
|
||||
@@ -126,9 +167,34 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
default:
|
||||
c.getPlayer().dropMessage("Feature not available");
|
||||
}
|
||||
System.out.println("end");
|
||||
|
||||
alliance.saveToDB();
|
||||
}
|
||||
|
||||
private void changeLeaderAllianceRank(MapleAlliance alliance, MapleCharacter newLeader) {
|
||||
MapleGuildCharacter lmgc = alliance.getLeader();
|
||||
MapleCharacter leader = Server.getInstance().getWorld(newLeader.getWorld()).getPlayerStorage().getCharacterById(lmgc.getId());
|
||||
leader.setAllianceRank(2);
|
||||
leader.saveGuildStatus();
|
||||
|
||||
newLeader.setAllianceRank(1);
|
||||
newLeader.saveGuildStatus();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, newLeader.getClient()), -1, -1);
|
||||
alliance.dropAllianceMessage("'" + newLeader.getName() + "' has been appointed as the new head of this Alliance.");
|
||||
}
|
||||
|
||||
private void changePlayerAllianceRank(MapleAlliance alliance, MapleCharacter chr, boolean raise) {
|
||||
int newRank = chr.getAllianceRank() + (raise ? -1 : 1);
|
||||
if(newRank < 2 || newRank > 5) return;
|
||||
|
||||
chr.setAllianceRank(newRank);
|
||||
chr.saveGuildStatus();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, chr.getClient()), -1, -1);
|
||||
alliance.dropAllianceMessage("'" + chr.getName() + "' has moved ranks to '" + alliance.getRankTitle(newRank) + "' in this Alliance.");
|
||||
}
|
||||
|
||||
private static byte[] sendShowInfo(int allianceid, int playerid) {
|
||||
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
|
||||
|
||||
@@ -186,9 +186,11 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player.getMGC());
|
||||
if (playerGuild == null) {
|
||||
player.deleteGuild(player.getGuildId());
|
||||
player.resetMGC();
|
||||
player.resetMGC(null);
|
||||
player.setGuildId(0);
|
||||
} else {
|
||||
playerGuild.getMGC(player.getId()).setCharacter(player);
|
||||
player.resetMGC(playerGuild.getMGC(player.getId()));
|
||||
server.setGuildMemberOnline(player.getMGC(), true, c.getChannel());
|
||||
c.announce(MaplePacketCreator.showGuildInfo(player));
|
||||
int allianceId = player.getGuild().getAllianceId();
|
||||
|
||||
@@ -27,57 +27,188 @@ import java.sql.SQLException;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import net.server.Server;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory.
|
||||
* @author XoticStory, Ronan.
|
||||
*/
|
||||
public class MapleAlliance {
|
||||
private int[] guilds = new int[5];
|
||||
final private List<Integer> guilds = new LinkedList<>();
|
||||
|
||||
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) {
|
||||
public MapleAlliance(String name, int id) {
|
||||
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 boolean canBeUsedAllianceName(String name) {
|
||||
if (name.contains(" ") || name.length() > 12) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
ps.close();
|
||||
rs.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<MapleCharacter> getPartyGuildMasters(MapleParty party) {
|
||||
List<MapleCharacter> mcl = new LinkedList<>();
|
||||
|
||||
for(MaplePartyCharacter mpc: party.getMembers()) {
|
||||
if(mpc.getPlayer().getGuildRank() == 1 && mpc.getPlayer().getMapId() == party.getLeader().getPlayer().getMapId())
|
||||
mcl.add(mpc.getPlayer());
|
||||
}
|
||||
|
||||
if(!mcl.isEmpty() && !mcl.get(0).isPartyLeader()) {
|
||||
for(int i = 1; i < mcl.size(); i++) {
|
||||
if(mcl.get(i).isPartyLeader()) {
|
||||
MapleCharacter temp = mcl.get(0);
|
||||
mcl.set(0, mcl.get(i));
|
||||
mcl.set(i, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mcl;
|
||||
}
|
||||
|
||||
public static MapleAlliance createAlliance(MapleParty party, String name) {
|
||||
List<MapleCharacter> guildMasters = getPartyGuildMasters(party);
|
||||
if(guildMasters.size() != 2) return null;
|
||||
|
||||
List<Integer> guilds = new LinkedList<>();
|
||||
for(MapleCharacter mc: guildMasters) guilds.add(mc.getGuildId());
|
||||
MapleAlliance alliance = MapleAlliance.createAllianceOnDb(guilds, name);
|
||||
if(alliance != null) {
|
||||
alliance.setCapacity(guilds.size());
|
||||
for(Integer g: guilds)
|
||||
alliance.addGuild(g);
|
||||
|
||||
int id = alliance.getId();
|
||||
try {
|
||||
for(int i = 0; i < guildMasters.size(); i++) {
|
||||
Server.getInstance().setGuildAllianceId(guilds.get(i), id);
|
||||
Server.getInstance().resetAllianceGuildPlayersRank(guilds.get(i));
|
||||
|
||||
MapleCharacter chr = guildMasters.get(i);
|
||||
chr.setAllianceRank((i == 0) ? 1 : 2);
|
||||
chr.saveGuildStatus();
|
||||
}
|
||||
|
||||
Server.getInstance().addAlliance(id, alliance);
|
||||
Server.getInstance().allianceMessage(id, MaplePacketCreator.makeNewAlliance(alliance, guildMasters.get(0).getClient()), -1, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return alliance;
|
||||
}
|
||||
|
||||
public static MapleAlliance createAllianceOnDb(List<Integer> guilds, String name) {
|
||||
// will create an alliance, where the first guild listed is the leader and the alliance name MUST BE already checked for unicity.
|
||||
|
||||
int id = -1;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO `alliance` (`name`) VALUES (?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
|
||||
ps.setString(1, name);
|
||||
ps.executeUpdate();
|
||||
try (ResultSet rs = ps.getGeneratedKeys()) {
|
||||
rs.next();
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
|
||||
for(int i = 0; i < guilds.size(); i++) {
|
||||
int guild = guilds.get(i);
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO `allianceguilds` (`allianceid`, `guildid`) VALUES (?, ?)");
|
||||
ps.setInt(1, id);
|
||||
ps.setInt(2, guild);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new MapleAlliance(name, id));
|
||||
}
|
||||
|
||||
public static MapleAlliance loadAlliance(int id) {
|
||||
if (id <= 0) {
|
||||
return null;
|
||||
}
|
||||
MapleAlliance alliance = new MapleAlliance(null, -1, -1, -1);
|
||||
MapleAlliance alliance = new MapleAlliance(null, -1);
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.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();
|
||||
|
||||
ps = con.prepareStatement("SELECT * FROM allianceguilds WHERE allianceid = ?");
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
alliance.addGuild(rs.getInt("guildid"));
|
||||
}
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -85,132 +216,73 @@ public class MapleAlliance {
|
||||
}
|
||||
|
||||
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 = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE `alliance` SET capacity = ?, notice = ? 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.setInt(3, this.allianceId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
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 = con.prepareStatement("DELETE FROM `allianceguilds` WHERE allianceid = ?");
|
||||
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.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
for(int i = 0; i < guilds.size(); i++) {
|
||||
int guild = guilds.get(i);
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO `allianceguilds` (`allianceid`, `guildid`) VALUES (?, ?)");
|
||||
ps.setInt(1, this.allianceId);
|
||||
ps.setInt(2, guild);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public boolean removeGuild(int gid) {
|
||||
synchronized (guilds) {
|
||||
int gIndex = getGuildIndex(gid);
|
||||
if (gIndex != -1) {
|
||||
guilds[gIndex] = -1;
|
||||
}
|
||||
return addRemGuildFromDB(gid, false);
|
||||
int index = getGuildIndex(gid);
|
||||
if(index == -1) return false;
|
||||
|
||||
guilds.remove(index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
if(guilds.size() == capacity || getGuildIndex(gid) > -1) return false;
|
||||
guilds.add(gid);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getGuildIndex(int gid) {
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
if (guilds[i] == gid) {
|
||||
for (int i = 0; i < guilds.size(); i++) {
|
||||
if (guilds.get(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>();
|
||||
List<Integer> guilds_ = new LinkedList<>();
|
||||
for (int guild : guilds) {
|
||||
if (guild != -1) {
|
||||
guilds_.add(guild);
|
||||
@@ -218,16 +290,58 @@ public class MapleAlliance {
|
||||
}
|
||||
return guilds_;
|
||||
}
|
||||
|
||||
public String getAllianceNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public String getNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public void setNotice(String notice) {
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public void increaseCapacity(int inc) {
|
||||
capacity += inc;
|
||||
this.capacity += inc;
|
||||
}
|
||||
|
||||
public void setCapacity(int newCapacity) {
|
||||
this.capacity = newCapacity;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return allianceId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MapleGuildCharacter getLeader() {
|
||||
for(Integer gId: guilds) {
|
||||
MapleGuild guild = Server.getInstance().getGuild(gId);
|
||||
MapleGuildCharacter mgc = guild.getMGC(guild.getLeaderId());
|
||||
|
||||
if(mgc.getAllianceRank() == 1) return mgc;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dropAllianceMessage(String message) {
|
||||
dropAllianceMessage(5, message);
|
||||
}
|
||||
|
||||
public void dropAllianceMessage(int type, String message) {
|
||||
for(Integer gId: guilds) {
|
||||
MapleGuild guild = Server.getInstance().getGuild(gId);
|
||||
guild.dropGuildMessage(type, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.util.Set;
|
||||
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import tools.LogHelper;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class MapleGuild {
|
||||
public final static int CHANGE_EMBLEM_COST = 5000000;
|
||||
|
||||
private enum BCOp {
|
||||
NONE, DISBAND, EMBELMCHANGE
|
||||
NONE, DISBAND, EMBLEMCHANGE
|
||||
}
|
||||
private List<MapleGuildCharacter> members;
|
||||
private String rankTitles[] = new String[5]; // 1 = master, 2 = jr, 5 = lowest member
|
||||
@@ -56,8 +55,6 @@ public class MapleGuild {
|
||||
private Map<Integer, List<Integer>> notifications = new LinkedHashMap<>();
|
||||
private boolean bDirty = true;
|
||||
|
||||
|
||||
|
||||
public MapleGuild(int guildid, int world) {
|
||||
this.world = world;
|
||||
members = new ArrayList<>();
|
||||
@@ -97,14 +94,14 @@ public class MapleGuild {
|
||||
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")));
|
||||
members.add(new MapleGuildCharacter(null, 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) {
|
||||
se.printStackTrace();
|
||||
System.out.println("unable to read guild information from sql" + se);
|
||||
System.out.println("Unable to read guild information from sql" + se);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +258,7 @@ public class MapleGuild {
|
||||
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) {
|
||||
} else if (bcop == BCOp.EMBLEMCHANGE) {
|
||||
Server.getInstance().getWorld(world).changeEmblem(this.id, notifications.get(b), new MapleGuildSummary(this));
|
||||
} else {
|
||||
Server.getInstance().getWorld(world).sendPacket(notifications.get(b), packet, exceptionId);
|
||||
@@ -285,6 +282,16 @@ public class MapleGuild {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dropGuildMessage(String message) {
|
||||
dropGuildMessage(5, message);
|
||||
}
|
||||
|
||||
public void dropGuildMessage(int type, String message) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
mgc.getCharacter().dropMessage(type, message);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setOnline(int cid, boolean online, int channel) {
|
||||
boolean bBroadcast = true;
|
||||
@@ -480,7 +487,7 @@ public class MapleGuild {
|
||||
this.logo = logo;
|
||||
this.logoColor = logocolor;
|
||||
this.writeToDB(false);
|
||||
this.broadcast(null, -1, BCOp.EMBELMCHANGE);
|
||||
this.broadcast(null, -1, BCOp.EMBLEMCHANGE);
|
||||
}
|
||||
|
||||
public MapleGuildCharacter getMGC(int cid) {
|
||||
@@ -557,6 +564,20 @@ public class MapleGuild {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void resetAllianceGuildPlayersRank() {
|
||||
try {
|
||||
for(MapleGuildCharacter mgc: members) mgc.setAllianceRank(5);
|
||||
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET allianceRank = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, 5);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getIncreaseGuildCost(int size) {
|
||||
return 500000 * (size - 6) / 6;
|
||||
|
||||
@@ -24,6 +24,7 @@ package net.server.guild;
|
||||
import client.MapleCharacter;
|
||||
|
||||
public class MapleGuildCharacter {
|
||||
private MapleCharacter character;
|
||||
private int level;
|
||||
private int id;
|
||||
private int world, channel;
|
||||
@@ -35,6 +36,7 @@ public class MapleGuildCharacter {
|
||||
private String name;
|
||||
|
||||
public MapleGuildCharacter(MapleCharacter c) {
|
||||
this.character = c;
|
||||
this.name = c.getName();
|
||||
this.level = c.getLevel();
|
||||
this.id = c.getId();
|
||||
@@ -47,7 +49,8 @@ public class MapleGuildCharacter {
|
||||
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) {
|
||||
public MapleGuildCharacter(MapleCharacter c, int _id, int _lv, String _name, int _channel, int _world, int _job, int _rank, int _gid, boolean _on, int _allianceRank) {
|
||||
this.character = c;
|
||||
this.level = _lv;
|
||||
this.id = _id;
|
||||
this.name = _name;
|
||||
@@ -61,6 +64,14 @@ public class MapleGuildCharacter {
|
||||
this.guildid = _gid;
|
||||
this.allianceRank = _allianceRank;
|
||||
}
|
||||
|
||||
public void setCharacter(MapleCharacter ch) {
|
||||
this.character = ch;
|
||||
}
|
||||
|
||||
public MapleCharacter getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
|
||||
@@ -152,6 +152,16 @@ public class World {
|
||||
public int getBossDropRate() {
|
||||
return bossdroprate;
|
||||
}
|
||||
|
||||
public void setBossDropRate(int bossdrop) {
|
||||
for(MapleCharacter chr : getPlayerStorage().getAllCharacters()) {
|
||||
chr.revertRates(false);
|
||||
}
|
||||
this.bossdroprate = bossdrop;
|
||||
for(MapleCharacter chr : getPlayerStorage().getAllCharacters()) {
|
||||
chr.setRates();
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerStorage getPlayerStorage() {
|
||||
return players;
|
||||
|
||||
Reference in New Issue
Block a user