Guild & Alliances Patches
As reported by J0k3r613, patched guild system not recognizing properly the guild leader just after creation. Patched many more issues related to guilds and alliances.
This commit is contained in:
@@ -498,7 +498,9 @@ public class Server implements Runnable {
|
||||
}
|
||||
|
||||
if(mc != null) {
|
||||
g.addGuildMember(mc.getMGC()); // i really REALLY must make player MGC the same as the guild MGC
|
||||
mc.setMGC(g.getMGC(mc.getId()));
|
||||
if(g.getMGC(mc.getId()) == null) System.out.println("null for " + mc.getName() + " when loading " + id);
|
||||
g.getMGC(mc.getId()).setCharacter(mc);
|
||||
g.setOnline(mc.getId(), true, mc.getClient().getChannel());
|
||||
}
|
||||
|
||||
@@ -520,10 +522,10 @@ public class Server implements Runnable {
|
||||
g.setOnline(mc.getId(), bOnline, channel);
|
||||
}
|
||||
|
||||
public int addGuildMember(MapleGuildCharacter mgc) {
|
||||
public int addGuildMember(MapleGuildCharacter mgc, MapleCharacter chr) {
|
||||
MapleGuild g = guilds.get(mgc.getGuildId());
|
||||
if (g != null) {
|
||||
return g.addGuildMember(mgc);
|
||||
return g.addGuildMember(mgc, chr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
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.");
|
||||
victim.getGuild().dropMessage("Your guild has joined the [" + alliance.getName() + "] union.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,6 +164,8 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
String notice = slea.readMapleAsciiString();
|
||||
Server.getInstance().setAllianceNotice(alliance.getId(), notice);
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), notice), -1, -1);
|
||||
|
||||
alliance.dropMessage(5, "* Alliance Notice : " + notice);
|
||||
break;
|
||||
default:
|
||||
c.getPlayer().dropMessage("Feature not available");
|
||||
|
||||
@@ -31,6 +31,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) {
|
||||
@@ -115,21 +116,22 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
|
||||
c.getPlayer().dropMessage(1, "The Guild name you have chosen is not accepted.");
|
||||
return;
|
||||
}
|
||||
int gid;
|
||||
|
||||
gid = Server.getInstance().createGuild(mc.getId(), guildName);
|
||||
int gid = Server.getInstance().createGuild(mc.getId(), guildName);
|
||||
if (gid == 0) {
|
||||
c.announce(MaplePacketCreator.genericGuildMessage((byte) 0x1c));
|
||||
return;
|
||||
}
|
||||
mc.gainMeso(-MapleGuild.CREATE_GUILD_COST, true, false, true);
|
||||
|
||||
Server.getInstance().getWorld(mc.getWorld()).setGuildAndRank(mc.getId(), gid, 1);
|
||||
Server.getInstance().setGuildMemberOnline(mc, true, mc.getClient().getChannel());
|
||||
mc.getMGC().setGuildId(gid);
|
||||
Server.getInstance().getGuild(mc.getGuildId(), mc.getWorld(), mc); // initialize guild structure
|
||||
Server.getInstance().changeRank(gid, mc.getId(), 1);
|
||||
|
||||
c.announce(MaplePacketCreator.showGuildInfo(mc));
|
||||
|
||||
c.getPlayer().dropMessage(1, "You have successfully created a Guild.");
|
||||
respawnPlayer(mc);
|
||||
break;
|
||||
case 0x05:
|
||||
if (mc.getGuildId() <= 0 || mc.getGuildRank() > 2) {
|
||||
@@ -172,15 +174,14 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
|
||||
System.out.println("[hax] " + mc.getName() + " is trying to join a guild that never invited him/her (or that the invitation has expired)");
|
||||
return;
|
||||
}
|
||||
mc.setGuildId(gid); // joins the guild
|
||||
mc.setGuildRank(5); // start at lowest rank
|
||||
mc.setAllianceRank(5);
|
||||
int s;
|
||||
mc.getMGC().setGuildId(gid); // joins the guild
|
||||
mc.getMGC().setGuildRank(5); // start at lowest rank
|
||||
mc.getMGC().setAllianceRank(5);
|
||||
|
||||
s = Server.getInstance().addGuildMember(mc.getMGC());
|
||||
int s = Server.getInstance().addGuildMember(mc.getMGC(), mc);
|
||||
if (s == 0) {
|
||||
c.getPlayer().dropMessage(1, "The Guild you are trying to join is already full.");
|
||||
mc.setGuildId(0);
|
||||
mc.getMGC().setGuildId(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -207,7 +208,7 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
|
||||
c.announce(MaplePacketCreator.showGuildInfo(null));
|
||||
if(allianceId > 0) Server.getInstance().getAlliance(allianceId).updateAlliancePackets(mc);
|
||||
|
||||
mc.setGuildId(0);
|
||||
mc.getMGC().setGuildId(0);
|
||||
mc.saveGuildStatus();
|
||||
respawnPlayer(mc);
|
||||
break;
|
||||
@@ -262,12 +263,18 @@ public final class GuildOperationHandler extends AbstractMaplePacketHandler {
|
||||
short logo = slea.readShort();
|
||||
byte logocolor = slea.readByte();
|
||||
Server.getInstance().setGuildEmblem(mc.getGuildId(), bg, bgcolor, logo, logocolor);
|
||||
|
||||
if (mc.getGuild() != null && mc.getGuild().getAllianceId() > 0) {
|
||||
MapleAlliance alliance = mc.getAlliance();
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c.getWorld()), -1, -1);
|
||||
}
|
||||
|
||||
mc.gainMeso(-MapleGuild.CHANGE_EMBLEM_COST, true, false, true);
|
||||
respawnPlayer(mc);
|
||||
break;
|
||||
case 0x10:
|
||||
if (mc.getGuildId() <= 0 || mc.getGuildRank() > 2) {
|
||||
System.out.println("[hax] " + mc.getName() + " tried to change guild notice while not in a guild.");
|
||||
if(mc.getGuildId() <= 0) System.out.println("[hax] " + mc.getName() + " tried to change guild notice while not in a guild.");
|
||||
return;
|
||||
}
|
||||
String notice = slea.readMapleAsciiString();
|
||||
|
||||
@@ -51,6 +51,7 @@ import client.inventory.MaplePet;
|
||||
import client.inventory.PetDataFactory;
|
||||
import constants.GameConstants;
|
||||
import constants.ServerConstants;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import server.TimerManager;
|
||||
|
||||
@@ -187,12 +188,10 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
|
||||
if (playerGuild == null) {
|
||||
player.deleteGuild(player.getGuildId());
|
||||
player.setMGC(null);
|
||||
player.setGuildId(0);
|
||||
player.getMGC().setGuildId(0);
|
||||
} else {
|
||||
playerGuild.getMGC(player.getId()).setCharacter(player);
|
||||
player.setMGC(playerGuild.getMGC(player.getId()));
|
||||
|
||||
server.setGuildMemberOnline(player, true, c.getChannel());
|
||||
c.announce(MaplePacketCreator.showGuildInfo(player));
|
||||
int allianceId = player.getGuild().getAllianceId();
|
||||
@@ -206,12 +205,13 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
player.getGuild().setAllianceId(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (newAlliance != null) {
|
||||
c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c));
|
||||
c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
|
||||
|
||||
server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
|
||||
if (newcomer) {
|
||||
server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,10 +121,13 @@ public class MapleAlliance {
|
||||
|
||||
MapleCharacter chr = guildMasters.get(i);
|
||||
chr.getMGC().setAllianceRank((i == 0) ? 1 : 2);
|
||||
Server.getInstance().getGuild(chr.getGuildId()).getMGC(chr.getId()).setAllianceRank((i == 0) ? 1 : 2);
|
||||
chr.saveGuildStatus();
|
||||
}
|
||||
|
||||
Server.getInstance().addAlliance(id, alliance);
|
||||
|
||||
System.out.println("\n\n\n\n----");
|
||||
Server.getInstance().allianceMessage(id, MaplePacketCreator.updateAllianceInfo(alliance, guildMasters.get(0).getClient()), -1, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -304,7 +307,7 @@ public class MapleAlliance {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1);
|
||||
Server.getInstance().guildMessage(guildId, MaplePacketCreator.disbandAlliance(alliance.getId()));
|
||||
|
||||
alliance.dropMessage("[" + Server.getInstance().getGuild(guildId, worldId) + "] guild has left the union.");
|
||||
alliance.dropMessage("[" + Server.getInstance().getGuild(guildId, worldId).getName() + "] guild has left the union.");
|
||||
}
|
||||
|
||||
public void updateAlliancePackets(MapleCharacter chr) {
|
||||
|
||||
@@ -372,13 +372,14 @@ public class MapleGuild {
|
||||
}
|
||||
}
|
||||
|
||||
public int addGuildMember(MapleGuildCharacter mgc) {
|
||||
public int addGuildMember(MapleGuildCharacter mgc, MapleCharacter chr) {
|
||||
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) {
|
||||
mgc.setCharacter(chr);
|
||||
members.add(i + 1, mgc);
|
||||
bDirty = true;
|
||||
break;
|
||||
@@ -439,23 +440,30 @@ public class MapleGuild {
|
||||
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));
|
||||
changeRank(mgc, newRank);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void changeRank(MapleGuildCharacter mgc, int newRank) {
|
||||
try {
|
||||
if (mgc.isOnline()) {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setGuildAndRank(mgc.getId(), this.id, newRank);
|
||||
mgc.setGuildRank(newRank);
|
||||
} else {
|
||||
Server.getInstance().getWorld(mgc.getWorld()).setOfflineGuildStatus((short) this.id, (byte) newRank, mgc.getId());
|
||||
mgc.setOfflineGuildRank(newRank);
|
||||
}
|
||||
} catch (Exception re) {
|
||||
re.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
this.broadcast(MaplePacketCreator.changeRank(mgc));
|
||||
return;
|
||||
}
|
||||
|
||||
public void setGuildNotice(String notice) {
|
||||
this.notice = notice;
|
||||
writeToDB(false);
|
||||
@@ -594,7 +602,11 @@ public class MapleGuild {
|
||||
|
||||
public void resetAllianceGuildPlayersRank() {
|
||||
try {
|
||||
for(MapleGuildCharacter mgc: members) mgc.setAllianceRank(5);
|
||||
for(MapleGuildCharacter mgc: members) {
|
||||
if(mgc.isOnline()) {
|
||||
mgc.setAllianceRank(5);
|
||||
}
|
||||
}
|
||||
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET allianceRank = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, 5);
|
||||
|
||||
@@ -111,15 +111,20 @@ public class MapleGuildCharacter {
|
||||
|
||||
public void setGuildId(int gid) {
|
||||
guildid = gid;
|
||||
character.setGuildId(gid);
|
||||
}
|
||||
|
||||
public int getGuildRank() {
|
||||
return guildrank;
|
||||
}
|
||||
|
||||
public void setOfflineGuildRank(int rank) {
|
||||
guildrank = rank;
|
||||
}
|
||||
|
||||
public void setGuildRank(int rank) {
|
||||
guildrank = rank;
|
||||
if(character != null) character.setGuildRank(rank);
|
||||
character.setGuildRank(rank);
|
||||
}
|
||||
|
||||
public int getAllianceRank() {
|
||||
@@ -128,7 +133,7 @@ public class MapleGuildCharacter {
|
||||
|
||||
public void setAllianceRank(int rank) {
|
||||
allianceRank = rank;
|
||||
if(character != null) character.setAllianceRank(rank);
|
||||
character.setAllianceRank(rank);
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
|
||||
@@ -206,8 +206,7 @@ public class World {
|
||||
if(mgc == null) return null;
|
||||
|
||||
int gid = mgc.getGuildId();
|
||||
MapleGuild g;
|
||||
g = Server.getInstance().getGuild(gid, mgc.getWorld(), mgc.getCharacter());
|
||||
MapleGuild g = Server.getInstance().getGuild(gid, mgc.getWorld(), mgc.getCharacter());
|
||||
if (gsStore.get(gid) == null) {
|
||||
gsStore.put(gid, new MapleGuildSummary(g));
|
||||
}
|
||||
@@ -274,13 +273,10 @@ public class World {
|
||||
bDifferentGuild = true;
|
||||
} else {
|
||||
bDifferentGuild = guildid != mc.getGuildId();
|
||||
mc.setGuildId(guildid);
|
||||
mc.getMGC().setGuildId(guildid);
|
||||
mc.getMGC().setGuildRank(rank);
|
||||
|
||||
MapleGuildCharacter mgc = mc.getMGC();
|
||||
if(mgc != null) {
|
||||
mgc.setGuildRank(rank);
|
||||
if(bDifferentGuild) mgc.setAllianceRank(5);
|
||||
}
|
||||
if(bDifferentGuild) mc.getMGC().setAllianceRank(5);
|
||||
|
||||
mc.saveGuildStatus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user