From 702c69897b21de4472b103a183118c7d1ca15645 Mon Sep 17 00:00:00 2001 From: ronancpl Date: Fri, 26 May 2017 01:21:54 -0300 Subject: [PATCH] Fixed Guild Alliances + minor Guild rework All Guild Alliances system is now functional. Tweaked guilds in order to sync MapleGuildCharacter objects that were supposed to be the same when being accessed from both MapleGuild and MapleCharacter classes. --- mychanges_ptbr.txt | 6 +- nbproject/private/private.xml | 24 +++--- scripts/npc/world0/2010009.js | 13 +-- sql/db_database.sql | 8 +- src/client/MapleCharacter.java | 25 +++--- src/client/MapleClient.java | 2 +- src/net/server/Server.java | 51 +++++++++--- .../handlers/AllianceOperationHandler.java | 74 +++++++++-------- .../handlers/GuildOperationHandler.java | 24 +++++- .../handlers/PlayerLoggedinHandler.java | 13 +-- src/net/server/guild/MapleAlliance.java | 79 ++++++++++++++++--- src/net/server/guild/MapleGuild.java | 31 ++++++-- src/net/server/guild/MapleGuildCharacter.java | 1 + src/net/server/world/World.java | 2 +- src/scripting/npc/NPCConversationManager.java | 21 +---- src/tools/MaplePacketCreator.java | 13 ++- 16 files changed, 260 insertions(+), 127 deletions(-) diff --git a/mychanges_ptbr.txt b/mychanges_ptbr.txt index 96280cc0c1..4d411b2540 100644 --- a/mychanges_ptbr.txt +++ b/mychanges_ptbr.txt @@ -246,4 +246,8 @@ Consertado quest-evento Dollhouse. 23 - 24 Maio 2017, Revamp na DB referente às Alliances. -Solução parcial ao problema das Guild Alliances. Pode-se criar uma, sair, expulsar e trocar ranks de jogadores. \ No newline at end of file +Solução parcial ao problema das Guild Alliances. Pode-se criar uma, sair, expulsar e trocar ranks de jogadores. + +25 Maio 2017, +Solução final ao problema das Guild Alliances. Todas as funcionalidades implementadas. +Registros de objetos MapleGuildCharacter agora esta sincronizado entre MapleCharacter's e MapleGuild's. \ No newline at end of file diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 1252af1b6b..6d8d3ad834 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,18 +1,16 @@ - + + + src/tools/MaplePacketCreator.java + + + 5939 + + + + - - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/AllianceOperationHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleGuild.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleAlliance.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleGuildCharacter.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/Server.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/world/World.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/scripting/npc/NPCConversationManager.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/MapleCharacter.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/handlers/login/GuestLoginHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/tools/MaplePacketCreator.java - + diff --git a/scripts/npc/world0/2010009.js b/scripts/npc/world0/2010009.js index de3d358424..4ba70595bb 100644 --- a/scripts/npc/world0/2010009.js +++ b/scripts/npc/world0/2010009.js @@ -47,11 +47,6 @@ function action(mode, type, selection) { cm.dispose(); return; } - if(!cm.isLeader()) { - cm.sendNext("Hello there! I'm #bLenario#k. If you want to form a guild, please tell your party leader to talk to me. He/She will be assigned as the Leader of the Guild Union."); - cm.dispose(); - return; - } cm.sendSimple("Hello there! I'm #bLenario#k.\r\n#b#L0#Can you please tell me what Guild Union is all about?#l\r\n#L1#How do I make a Guild Union?#l\r\n#L2#I want to make a Guild Union.#l\r\n#L3#I want to add more guilds for the Guild Union.#l\r\n#L4#I want to break up the Guild Union.#l"); } @@ -64,6 +59,11 @@ function action(mode, type, selection) { cm.sendNext("To make a Guild Union, two and only two Guild Masters need to be in a party and both must be present on this room on the same channel. The leader of this party will be assigned as the Guild Union Master."); cm.dispose(); } else if(selection == 2) { + if(!cm.isLeader()) { + cm.sendNext("If you want to form a guild union, please tell your party leader to talk to me. He/She will be assigned as the Leader of the Guild Union."); + cm.dispose(); + return; + } if(cm.getPlayer().getGuild().getAllianceId() > 0) { cm.sendOk("You can not create a Guild Union while your guild is already registered in another."); cm.dispose(); @@ -111,6 +111,7 @@ function action(mode, type, selection) { cm.upgradeAlliance(); cm.gainMeso(-increaseCost); cm.sendOk("Your alliance can now accept one more guild."); + cm.dispose(); } else if (choice == 4) { if (cm.getPlayer().getGuild() == null || cm.getPlayer().getGuild().getAllianceId() <= 0) { cm.sendNext("You cannot disband a non-existant Guild Union."); @@ -131,7 +132,7 @@ function action(mode, type, selection) { choice = 2; } else { if (cm.createAlliance(guildName) == null) - cm.sendOk("Please check if you and the other one guild leader in your party are both here on this room right now. No other guild leaders should be present with you 2 on this process."); + cm.sendOk("Please check if you and the other one guild leader in your party are both here on this room right now, and make sure both guilds are currently unregistered on unions. No other guild leaders should be present with you 2 on this process."); else { cm.gainMeso(-allianceCost); cm.sendOk("You have successfully formed a Guild Union."); diff --git a/sql/db_database.sql b/sql/db_database.sql index bd8b8e4e70..69176c2346 100644 --- a/sql/db_database.sql +++ b/sql/db_database.sql @@ -50,8 +50,14 @@ CREATE TABLE IF NOT EXISTS `accounts` ( CREATE TABLE IF NOT EXISTS `alliance` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(13) NOT NULL, - `notice` varchar(128) NOT NULL DEFAULT '', `capacity` int(10) unsigned NOT NULL DEFAULT '2', + `notice` varchar(20) NOT NULL DEFAULT '', + + `rank1` varchar(11) NOT NULL DEFAULT '', + `rank2` varchar(11) NOT NULL DEFAULT '', + `rank3` varchar(11) NOT NULL DEFAULT '', + `rank4` varchar(11) NOT NULL DEFAULT '', + `rank5` varchar(11) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; diff --git a/src/client/MapleCharacter.java b/src/client/MapleCharacter.java index 4b7092fd4c..f16b2199d7 100644 --- a/src/client/MapleCharacter.java +++ b/src/client/MapleCharacter.java @@ -1961,7 +1961,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { } public int getAllianceRank() { - return this.allianceRank; + return allianceRank; } public int getAllowWarpToId() { @@ -2200,7 +2200,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { public MapleGuild getGuild() { try { - return Server.getInstance().getGuild(getGuildId(), getWorld(), null); + return Server.getInstance().getGuild(getGuildId(), getWorld(), this); } catch (Exception ex) { ex.printStackTrace(); return null; @@ -2445,6 +2445,10 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { public MapleGuildCharacter getMGC() { return mgc; } + + public void setMGC(MapleGuildCharacter mgc) { + this.mgc = mgc; + } public MaplePartyCharacter getMPC() { if (mpc == null) { @@ -2549,6 +2553,16 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { return list; } + + public boolean isPartyMember(MapleCharacter chr) { + for(MapleCharacter mpc: getPartyMembers()) { + if(mpc.getId() == chr.getId()) { + return true; + } + } + + return false; + } public MaplePlayerShop getPlayerShop() { return playerShop; @@ -4160,10 +4174,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { } } - public void resetMGC(MapleGuildCharacter mgc) { - this.mgc = mgc; - } - public synchronized void saveCooldowns() { if (getAllCooldowns().size() > 0) { try { @@ -4636,9 +4646,6 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject { public void setAllianceRank(int rank) { allianceRank = rank; - if (mgc != null) { - mgc.setAllianceRank(rank); - } } public void setAllowWarpToId(int id) { diff --git a/src/client/MapleClient.java b/src/client/MapleClient.java index 4b71878196..42b9b45ea6 100644 --- a/src/client/MapleClient.java +++ b/src/client/MapleClient.java @@ -821,7 +821,7 @@ public class MapleClient { } if (guild != null) { final Server server = Server.getInstance(); - server.setGuildMemberOnline(chrg, false, player.getClient().getChannel()); + server.setGuildMemberOnline(player, false, player.getClient().getChannel()); player.getClient().announce(MaplePacketCreator.showGuildInfo(player)); } if (party != null) { diff --git a/src/net/server/Server.java b/src/net/server/Server.java index fa24e67c88..d30ecb7847 100644 --- a/src/net/server/Server.java +++ b/src/net/server/Server.java @@ -69,12 +69,12 @@ public class Server implements Runnable { private IoAcceptor acceptor; private List> channels = new LinkedList<>(); private List worlds = new ArrayList<>(); - private Properties subnetInfo = new Properties(); + private final Properties subnetInfo = new Properties(); private static Server instance = null; private List> worldRecommendedList = new LinkedList<>(); - private Map guilds = new LinkedHashMap<>(); - private PlayerBuffStorage buffStorage = new PlayerBuffStorage(); - private Map alliances = new LinkedHashMap<>(); + private final Map guilds = new LinkedHashMap<>(); + private final PlayerBuffStorage buffStorage = new PlayerBuffStorage(); + private final Map alliances = new LinkedHashMap<>(); private boolean online = false; public static long uptime = System.currentTimeMillis(); @@ -349,6 +349,18 @@ public class Server implements Runnable { return MapleGuild.createGuild(leaderId, name); } + public MapleGuild getGuildByName(String name) { + synchronized (guilds) { + for(MapleGuild mg: guilds.values()) { + if(mg.getName().equalsIgnoreCase(name)) { + return mg; + } + } + + return null; + } + } + public MapleGuild getGuild(int id) { synchronized (guilds) { if (guilds.get(id) != null) { @@ -359,7 +371,7 @@ public class Server implements Runnable { } } - public MapleGuild getGuild(int id, int world, MapleGuildCharacter mgc) { + public MapleGuild getGuild(int id, int world, MapleCharacter mc) { synchronized (guilds) { if (guilds.get(id) != null) { return guilds.get(id); @@ -368,9 +380,15 @@ public class Server implements Runnable { if (g.getId() == -1) { return null; } - if (mgc != null) { - g.setOnline(mgc.getId(), true, mgc.getChannel()); + + if(mc != null) { + MapleGuildCharacter mgc = mc.getMGC(); + if (mgc != null) { + g.setOnline(mgc.getId(), true, mgc.getChannel()); + mc.setMGC(g.getMGC(mc.getId())); // i really REALLY must make player MGC the same as the guild MGC + } } + guilds.put(id, g); return g; } @@ -384,9 +402,9 @@ public class Server implements Runnable { //reloadGuildCharacters(); } - public void setGuildMemberOnline(MapleGuildCharacter mgc, boolean bOnline, int channel) { - MapleGuild g = getGuild(mgc.getGuildId(), mgc.getWorld(), mgc); - g.setOnline(mgc.getId(), bOnline, channel); + public void setGuildMemberOnline(MapleCharacter mc, boolean bOnline, int channel) { + MapleGuild g = getGuild(mc.getGuildId(), mc.getWorld(), mc); + g.setOnline(mc.getId(), bOnline, channel); } public int addGuildMember(MapleGuildCharacter mgc) { @@ -504,8 +522,17 @@ public class Server implements Runnable { return buffStorage; } + public void deleteGuildCharacter(MapleCharacter mc) { + setGuildMemberOnline(mc, false, (byte) -1); + if (mc.getMGC().getGuildRank() > 1) { + leaveGuild(mc.getMGC()); + } else { + disbandGuild(mc.getMGC().getGuildId()); + } + } + public void deleteGuildCharacter(MapleGuildCharacter mgc) { - setGuildMemberOnline(mgc, false, (byte) -1); + if(mgc.getCharacter() != null) setGuildMemberOnline(mgc.getCharacter(), false, (byte) -1); if (mgc.getGuildRank() > 1) { leaveGuild(mgc); } else { @@ -517,7 +544,7 @@ public class Server implements Runnable { World worlda = getWorld(world); for (MapleCharacter mc : worlda.getPlayerStorage().getAllCharacters()) { if (mc.getGuildId() > 0) { - setGuildMemberOnline(mc.getMGC(), true, worlda.getId()); + setGuildMemberOnline(mc, true, worlda.getId()); memberLevelJobUpdate(mc.getMGC()); } } diff --git a/src/net/server/channel/handlers/AllianceOperationHandler.java b/src/net/server/channel/handlers/AllianceOperationHandler.java index 9e18c3d25d..86a0089583 100644 --- a/src/net/server/channel/handlers/AllianceOperationHandler.java +++ b/src/net/server/channel/handlers/AllianceOperationHandler.java @@ -26,6 +26,7 @@ import client.MapleClient; import net.AbstractMaplePacketHandler; import net.SendOpcode; import net.server.Server; +import net.server.guild.MapleGuild; import net.server.guild.MapleGuildCharacter; import net.server.guild.MapleAlliance; import tools.MaplePacketCreator; @@ -40,8 +41,6 @@ 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 = c.getPlayer().getAlliance(); @@ -55,14 +54,11 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { } 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; } @@ -72,35 +68,52 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid); Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1); + Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1); Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(alliance.getId())); + + alliance.dropMessage("[" + c.getPlayer().getGuild().getName() + "] guild has left the union."); break; } - case 0x03: // send alliance invite - System.out.print(" case 3 avail is " + slea.available()); - String charName = slea.readMapleAsciiString(); + case 0x03: // send alliance invite... or at least it would be this way if i could find the right way to call it! + String guildName = slea.readMapleAsciiString(); if(alliance.getGuilds().size() == alliance.getCapacity()) { c.getPlayer().dropMessage("Your alliance can not comport any more guild at the moment."); } else { - int channel; - channel = c.getWorldServer().find(charName); - if (channel == -1) { - c.getPlayer().dropMessage("The player is not online."); - } 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."); + MapleGuild mg = Server.getInstance().getGuildByName(guildName); + if(mg == null) { + c.getPlayer().dropMessage("The entered guild does not exist."); + } + else { + MapleCharacter victim = mg.getMGC(mg.getLeaderId()).getCharacter(); + + if (victim == null) { + c.getPlayer().dropMessage("The master of the guild that you offered an invitation is currently not online."); } else { - Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), charName), -1, -1); + // this doesn't seem to work... + //Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), victim.getId(), guildName), -1, -1); + //victim.getClient().announce(sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), guildName)); + + if(!c.getPlayer().isPartyMember(victim)) { + c.getPlayer().dropMessage("The master of the guild that you offered a invitation must be in the same party as yours."); + } + else { + int guildid = victim.getGuildId(); + + Server.getInstance().addGuildtoAlliance(alliance.getId(), guildid); + Server.getInstance().resetAllianceGuildPlayersRank(guildid); + + Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.addGuildToAlliance(alliance, guildid, c), -1, -1); + Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.updateAllianceInfo(alliance, c), -1, -1); + Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1); + victim.getGuild().dropMessage("Your guild has joined in the [" + alliance.getName() + "] union."); + } } } } 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) { @@ -110,7 +123,6 @@ 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) { @@ -121,13 +133,13 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid); Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1); + Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1); Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(allianceid)); - + alliance.dropMessage("[" + Server.getInstance().getGuild(guildid).getName() + "] guild has been expelled from the union."); break; } case 0x07: { // Change Alliance Leader - System.out.print(" case 7"); if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1) { return; } @@ -139,7 +151,6 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { break; } case 0x08: - System.out.print(" case 8"); String ranks[] = new String[5]; for (int i = 0; i < 5; i++) { ranks[i] = slea.readMapleAsciiString(); @@ -148,7 +159,6 @@ 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(); @@ -159,7 +169,6 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { 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); @@ -167,7 +176,6 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { default: c.getPlayer().dropMessage("Feature not available"); } - System.out.println("end"); alliance.saveToDB(); } @@ -175,25 +183,25 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler { 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.getMGC().setAllianceRank(2); leader.saveGuildStatus(); - newLeader.setAllianceRank(1); + newLeader.getMGC().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."); + alliance.dropMessage("'" + 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; + if(newRank < 3 || newRank > 5) return; - chr.setAllianceRank(newRank); + chr.getMGC().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."); + alliance.dropMessage("'" + chr.getName() + "' has been reassigned as '" + alliance.getRankTitle(newRank) + "' in this Alliance."); } private static byte[] sendShowInfo(int allianceid, int playerid) { diff --git a/src/net/server/channel/handlers/GuildOperationHandler.java b/src/net/server/channel/handlers/GuildOperationHandler.java index d41efd7548..dda5268203 100644 --- a/src/net/server/channel/handlers/GuildOperationHandler.java +++ b/src/net/server/channel/handlers/GuildOperationHandler.java @@ -30,6 +30,7 @@ import java.util.Iterator; import tools.MaplePacketCreator; import client.MapleCharacter; import net.server.Server; +import net.server.guild.MapleAlliance; public final class GuildOperationHandler extends AbstractMaplePacketHandler { private boolean isGuildNameAcceptable(String name) { @@ -95,6 +96,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { } MapleCharacter mc = c.getPlayer(); byte type = slea.readByte(); + int allianceId = -1; switch (type) { case 0x00: //c.announce(MaplePacketCreator.showGuildInfo(mc)); @@ -123,8 +125,12 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { mc.gainMeso(-MapleGuild.CREATE_GUILD_COST, true, false, true); mc.setGuildId(gid); mc.setGuildRank(1); - mc.saveGuildStatus(); + mc.setAllianceRank(5); + + MapleGuild guild = Server.getInstance().getGuild(mc.getGuildId(), c.getWorld(), mc); // initialize guild structure + guild.getMGC(guild.getLeaderId()).setCharacter(mc); c.announce(MaplePacketCreator.showGuildInfo(mc)); + c.getPlayer().dropMessage(1, "You have successfully created a Guild."); respawnPlayer(mc); break; @@ -171,6 +177,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { } mc.setGuildId(gid); // joins the guild mc.setGuildRank(5); // start at lowest rank + mc.setAllianceRank(5); int s; s = Server.getInstance().addGuildMember(mc.getMGC()); @@ -179,11 +186,18 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { mc.setGuildId(0); return; } + c.announce(MaplePacketCreator.showGuildInfo(mc)); + + allianceId = mc.getGuild().getAllianceId(); + if(allianceId > 0) Server.getInstance().getAlliance(allianceId).updateAlliancePackets(mc); + mc.saveGuildStatus(); // update database respawnPlayer(mc); break; case 0x07: + allianceId = mc.getGuild().getAllianceId(); + cid = slea.readInt(); name = slea.readMapleAsciiString(); if (cid != mc.getId() || !name.equals(mc.getName()) || mc.getGuildId() <= 0) { @@ -192,12 +206,17 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { } c.announce(MaplePacketCreator.updateGP(mc.getGuildId(), 0)); Server.getInstance().leaveGuild(mc.getMGC()); + c.announce(MaplePacketCreator.showGuildInfo(null)); + if(allianceId > 0) Server.getInstance().getAlliance(allianceId).updateAlliancePackets(mc); + mc.setGuildId(0); mc.saveGuildStatus(); respawnPlayer(mc); break; case 0x08: + allianceId = mc.getGuild().getAllianceId(); + cid = slea.readInt(); name = slea.readMapleAsciiString(); if (mc.getGuildRank() > 2 || mc.getGuildId() <= 0) { @@ -206,6 +225,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { } Server.getInstance().expelMember(mc.getMGC(), name, cid); + if(allianceId > 0) Server.getInstance().getAlliance(allianceId).updateAlliancePackets(mc); break; case 0x0d: if (mc.getGuildId() <= 0 || mc.getGuildRank() != 1) { @@ -237,7 +257,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler { return; } if (mc.getMeso() < MapleGuild.CHANGE_EMBLEM_COST) { - c.announce(MaplePacketCreator.serverNotice(1, "You do not have enough mesos to create a Guild.")); + c.announce(MaplePacketCreator.serverNotice(1, "You do not have enough mesos to change the Guild emblem.")); return; } short bg = slea.readShort(); diff --git a/src/net/server/channel/handlers/PlayerLoggedinHandler.java b/src/net/server/channel/handlers/PlayerLoggedinHandler.java index 6236aa2a28..8cf8bf3b72 100644 --- a/src/net/server/channel/handlers/PlayerLoggedinHandler.java +++ b/src/net/server/channel/handlers/PlayerLoggedinHandler.java @@ -183,15 +183,15 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler { c.announce(MaplePacketCreator.getFamilyInfo(f.getMember(player.getId()))); } if (player.getGuildId() > 0) { - MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player.getMGC()); + MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player); if (playerGuild == null) { player.deleteGuild(player.getGuildId()); - player.resetMGC(null); + player.setMGC(null); player.setGuildId(0); } else { playerGuild.getMGC(player.getId()).setCharacter(player); - player.resetMGC(playerGuild.getMGC(player.getId())); - server.setGuildMemberOnline(player.getMGC(), true, c.getChannel()); + player.setMGC(playerGuild.getMGC(player.getId())); + server.setGuildMemberOnline(player, true, c.getChannel()); c.announce(MaplePacketCreator.showGuildInfo(player)); int allianceId = player.getGuild().getAllianceId(); if (allianceId > 0) { @@ -205,8 +205,9 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler { } } if (newAlliance != null) { - c.announce(MaplePacketCreator.getAllianceInfo(newAlliance)); - c.announce(MaplePacketCreator.getGuildAlliances(newAlliance, c)); + c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c)); + c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice())); + server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1); } } diff --git a/src/net/server/guild/MapleAlliance.java b/src/net/server/guild/MapleAlliance.java index bdcbe9362e..2bdf04a03c 100644 --- a/src/net/server/guild/MapleAlliance.java +++ b/src/net/server/guild/MapleAlliance.java @@ -32,8 +32,6 @@ 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; @@ -122,12 +120,12 @@ public class MapleAlliance { Server.getInstance().resetAllianceGuildPlayersRank(guilds.get(i)); MapleCharacter chr = guildMasters.get(i); - chr.setAllianceRank((i == 0) ? 1 : 2); + chr.getMGC().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); + Server.getInstance().allianceMessage(id, MaplePacketCreator.updateAllianceInfo(alliance, guildMasters.get(0).getClient()), -1, -1); } catch (Exception e) { e.printStackTrace(); return null; @@ -194,6 +192,14 @@ public class MapleAlliance { alliance.name = rs.getString("name"); alliance.notice = rs.getString("notice"); + String ranks[] = new String[5]; + ranks[0] = rs.getString("rank1"); + ranks[1] = rs.getString("rank2"); + ranks[2] = rs.getString("rank3"); + ranks[3] = rs.getString("rank4"); + ranks[4] = rs.getString("rank5"); + alliance.rankTitles = ranks; + ps.close(); rs.close(); @@ -218,10 +224,17 @@ public class MapleAlliance { public void saveToDB() { try { Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE `alliance` SET capacity = ?, notice = ? WHERE id = ?"); + PreparedStatement ps = con.prepareStatement("UPDATE `alliance` SET capacity = ?, notice = ?, rank1 = ?, rank2 = ?, rank3 = ?, rank4 = ?, rank5 = ? WHERE id = ?"); ps.setInt(1, this.capacity); ps.setString(2, this.notice); - ps.setInt(3, this.allianceId); + + ps.setString(3, this.rankTitles[0]); + ps.setString(4, this.rankTitles[1]); + ps.setString(5, this.rankTitles[2]); + ps.setString(6, this.rankTitles[3]); + ps.setString(7, this.rankTitles[4]); + + ps.setInt(8, this.allianceId); ps.executeUpdate(); ps.close(); @@ -246,6 +259,48 @@ public class MapleAlliance { } } + public static void disbandAlliance(int allianceId) { + PreparedStatement ps = null; + Connection con = null; + try { + con = DatabaseConnection.getConnection(); + + ps = con.prepareStatement("DELETE FROM `alliance` WHERE id = ?"); + ps.setInt(1, allianceId); + ps.executeUpdate(); + ps.close(); + + ps = con.prepareStatement("DELETE FROM `allianceguilds` WHERE allianceid = ?"); + ps.setInt(1, allianceId); + ps.executeUpdate(); + ps.close(); + + con.close(); + Server.getInstance().allianceMessage(allianceId, MaplePacketCreator.disbandAlliance(allianceId), -1, -1); + Server.getInstance().disbandAlliance(allianceId); + } catch (SQLException sqle) { + sqle.printStackTrace(); + } finally { + try { + if (ps != null && !ps.isClosed()) { + ps.close(); + } + if (con != null && !con.isClosed()) { + con.close(); + } + } catch (SQLException ex) { + ex.printStackTrace(); + } + } + } + + public void updateAlliancePackets(MapleCharacter chr) { + if (allianceId > 0) { + this.broadcastMessage(MaplePacketCreator.updateAllianceInfo(this, chr.getClient())); + this.broadcastMessage(MaplePacketCreator.allianceNotice(this.getId(), this.getNotice())); + } + } + public boolean removeGuild(int gid) { synchronized (guilds) { int index = getGuildIndex(gid); @@ -334,14 +389,18 @@ public class MapleAlliance { return null; } - public void dropAllianceMessage(String message) { - dropAllianceMessage(5, message); + public void dropMessage(String message) { + dropMessage(5, message); } - public void dropAllianceMessage(int type, String message) { + public void dropMessage(int type, String message) { for(Integer gId: guilds) { MapleGuild guild = Server.getInstance().getGuild(gId); - guild.dropGuildMessage(type, message); + guild.dropMessage(type, message); } } + + public void broadcastMessage(byte[] packet) { + Server.getInstance().allianceMessage(allianceId, packet, -1, -1); + } } diff --git a/src/net/server/guild/MapleGuild.java b/src/net/server/guild/MapleGuild.java index 6cd04b04d6..d9fa2aaf1e 100644 --- a/src/net/server/guild/MapleGuild.java +++ b/src/net/server/guild/MapleGuild.java @@ -180,6 +180,10 @@ public class MapleGuild { public int getLeaderId() { return leader; } + + public int setLeaderId(int charId) { + return leader = charId; + } public int getGP() { return gp; @@ -283,15 +287,20 @@ public class MapleGuild { } } - public void dropGuildMessage(String message) { - dropGuildMessage(5, message); + public void dropMessage(String message) { + dropMessage(5, message); } - public void dropGuildMessage(int type, String message) { + public void dropMessage(int type, String message) { for (MapleGuildCharacter mgc : members) { - mgc.getCharacter().dropMessage(type, message); + if(mgc.getCharacter() != null) + mgc.getCharacter().dropMessage(type, message); } } + + public void broadcastMessage(byte[] packet) { + Server.getInstance().guildMessage(id, packet); + } public final void setOnline(int cid, boolean online, int channel) { boolean bBroadcast = true; @@ -332,20 +341,30 @@ public class MapleGuild { } 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"); + int guildId = rs.getInt("guildid"); rs.close(); ps.close(); - return guildid; + + ps = con.prepareStatement("UPDATE characters SET guildid = ? WHERE id = ?"); + ps.setInt(1, guildId); + ps.setInt(2, leaderId); + ps.executeUpdate(); + ps.close(); + + con.close(); + return guildId; } catch (Exception e) { e.printStackTrace(); return 0; diff --git a/src/net/server/guild/MapleGuildCharacter.java b/src/net/server/guild/MapleGuildCharacter.java index e38e04eae5..ce79f188ff 100644 --- a/src/net/server/guild/MapleGuildCharacter.java +++ b/src/net/server/guild/MapleGuildCharacter.java @@ -135,6 +135,7 @@ public class MapleGuildCharacter { public void setAllianceRank(int rank) { allianceRank = rank; + if(character != null) character.setAllianceRank(rank); } public int getAllianceRank() { diff --git a/src/net/server/world/World.java b/src/net/server/world/World.java index 5b21549a77..f067dfaff6 100644 --- a/src/net/server/world/World.java +++ b/src/net/server/world/World.java @@ -196,7 +196,7 @@ public class World { public MapleGuild getGuild(MapleGuildCharacter mgc) { int gid = mgc.getGuildId(); MapleGuild g; - g = Server.getInstance().getGuild(gid, mgc.getWorld(), mgc); + g = Server.getInstance().getGuild(gid, mgc.getWorld(), mgc.getCharacter()); if (gsStore.get(gid) == null) { gsStore.put(gid, new MapleGuildSummary(g)); } diff --git a/src/scripting/npc/NPCConversationManager.java b/src/scripting/npc/NPCConversationManager.java index 26a1979b8e..28d9cfa305 100644 --- a/src/scripting/npc/NPCConversationManager.java +++ b/src/scripting/npc/NPCConversationManager.java @@ -350,28 +350,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction { public void upgradeAlliance() { MapleAlliance alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId()); alliance.increaseCapacity(1); + c.announce(MaplePacketCreator.updateAllianceInfo(alliance, c)); } public void disbandAlliance(MapleClient c, int allianceId) { - PreparedStatement ps = null; - try { - ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM `alliance` WHERE id = ?"); - ps.setInt(1, allianceId); - ps.executeUpdate(); - ps.close(); - Server.getInstance().allianceMessage(c.getPlayer().getGuild().getAllianceId(), MaplePacketCreator.disbandAlliance(allianceId), -1, -1); - Server.getInstance().disbandAlliance(allianceId); - } catch (SQLException sqle) { - sqle.printStackTrace(); - } finally { - try { - if (ps != null && !ps.isClosed()) { - ps.close(); - } - } catch (SQLException ex) { - ex.printStackTrace(); - } - } + MapleAlliance.disbandAlliance(allianceId); } public boolean canBeUsedAllianceName(String name) { diff --git a/src/tools/MaplePacketCreator.java b/src/tools/MaplePacketCreator.java index 70b54af610..ee284ce2ab 100644 --- a/src/tools/MaplePacketCreator.java +++ b/src/tools/MaplePacketCreator.java @@ -5891,7 +5891,6 @@ public class MaplePacketCreator { mplew.writeInt(mgc.isOnline() ? 1 : 0); mplew.writeInt(guild.getSignature()); mplew.writeInt(mgc.getAllianceRank()); - System.out.println("alliance rank found " + mgc.getAllianceRank()); } mplew.writeInt(guild.getCapacity()); mplew.writeShort(guild.getLogoBG()); @@ -5914,7 +5913,7 @@ public class MaplePacketCreator { mplew.writeMapleAsciiString(alliance.getRankTitle(i)); } mplew.write(alliance.getGuilds().size()); - mplew.writeInt(2); // probably capacity + mplew.writeInt(alliance.getCapacity()); // probably capacity for (Integer guild : alliance.getGuilds()) { mplew.writeInt(guild); } @@ -5922,7 +5921,7 @@ public class MaplePacketCreator { return mplew.getPacket(); } - public static byte[] makeNewAlliance(MapleAlliance alliance, MapleClient c) { + public static byte[] updateAllianceInfo(MapleAlliance alliance, MapleClient c) { final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.ALLIANCE_OPERATION.getValue()); mplew.write(0x0F); @@ -5935,10 +5934,10 @@ public class MaplePacketCreator { for (Integer guild : alliance.getGuilds()) { mplew.writeInt(guild); } - mplew.writeInt(2); // probably capacity + mplew.writeInt(alliance.getCapacity()); // probably capacity mplew.writeShort(0); for (Integer guildd : alliance.getGuilds()) { - getGuildInfo(mplew, Server.getInstance().getGuild(guildd, c.getWorld(), c.getPlayer().getMGC())); + getGuildInfo(mplew, Server.getInstance().getGuild(guildd, c.getWorld(), c.getPlayer())); } return mplew.getPacket(); } @@ -5967,7 +5966,7 @@ public class MaplePacketCreator { for (Integer guild : alliance.getGuilds()) { mplew.writeInt(guild); } - mplew.writeInt(2); + mplew.writeInt(alliance.getCapacity()); mplew.writeMapleAsciiString(alliance.getNotice()); mplew.writeInt(newGuild); getGuildInfo(mplew, Server.getInstance().getGuild(newGuild, c.getWorld(), null)); @@ -6030,7 +6029,7 @@ public class MaplePacketCreator { for (Integer guild : alliance.getGuilds()) { mplew.writeInt(guild); } - mplew.writeInt(2); + mplew.writeInt(alliance.getCapacity()); mplew.writeMapleAsciiString(alliance.getNotice()); mplew.writeInt(expelledGuild); getGuildInfo(mplew, Server.getInstance().getGuild(expelledGuild, c.getWorld(), null));