use of net.server.guild.MapleAlliance in project HeavenMS by ronancpl.
the class Server method removeGuildFromAlliance.
public boolean removeGuildFromAlliance(int aId, int guildId) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.removeGuild(guildId);
guilds.get(guildId).setAllianceId(0);
return true;
}
return false;
}
use of net.server.guild.MapleAlliance in project HeavenMS by ronancpl.
the class Server method addGuildtoAlliance.
public boolean addGuildtoAlliance(int aId, int guildId) {
MapleAlliance alliance = alliances.get(aId);
if (alliance != null) {
alliance.addGuild(guildId);
guilds.get(guildId).setAllianceId(aId);
return true;
}
return false;
}
use of net.server.guild.MapleAlliance in project HeavenMS by ronancpl.
the class AllianceOperationHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
MapleAlliance alliance = null;
MapleCharacter chr = c.getPlayer();
if (chr.getGuild() == null) {
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getGuild().getAllianceId() > 0) {
alliance = chr.getAlliance();
}
byte b = slea.readByte();
if (alliance == null) {
if (b != 4) {
c.announce(MaplePacketCreator.enableActions());
return;
}
} else {
if (b == 4) {
chr.dropMessage("Your guild is already registered on a Guild Alliance.");
c.announce(MaplePacketCreator.enableActions());
return;
}
if (chr.getMGC().getAllianceRank() > 2 || !alliance.getGuilds().contains(chr.getGuildId())) {
c.announce(MaplePacketCreator.enableActions());
return;
}
}
// "alliance" is only null at case 0x04
switch(b) {
case 0x01:
Server.getInstance().allianceMessage(alliance.getId(), sendShowInfo(chr.getGuild().getAllianceId(), chr.getId()), -1, -1);
break;
case 0x02:
{
// Leave Alliance
if (chr.getGuild().getAllianceId() == 0 || chr.getGuildId() < 1 || chr.getGuildRank() != 1) {
return;
}
MapleAlliance.removeGuildFromAlliance(chr.getGuild().getAllianceId(), chr.getGuildId(), chr.getWorld());
break;
}
case // Send Invite
0x03:
String guildName = slea.readMapleAsciiString();
if (alliance.getGuilds().size() == alliance.getCapacity()) {
chr.dropMessage("Your alliance cannot comport any more guilds at the moment.");
} else {
MapleGuild mg = Server.getInstance().getGuildByName(guildName);
if (mg == null) {
chr.dropMessage("The entered guild does not exist.");
} else {
MapleCharacter victim = mg.getMGC(mg.getLeaderId()).getCharacter();
if (victim == null) {
chr.dropMessage("The master of the guild that you offered an invitation is currently not online.");
} else {
victim.getClient().announce(MaplePacketCreator.sendAllianceInvitation(alliance.getId(), chr));
}
}
}
break;
case 0x04:
{
// Accept Invite
if (chr.getGuild().getAllianceId() != 0 || chr.getGuildRank() != 1 || chr.getGuildId() < 1) {
return;
}
int allianceid = slea.readInt();
// slea.readMapleAsciiString(); //recruiter's guild name
alliance = Server.getInstance().getAlliance(allianceid);
if (alliance == null) {
return;
}
int guildid = chr.getGuildId();
Server.getInstance().addGuildtoAlliance(alliance.getId(), guildid);
Server.getInstance().resetAllianceGuildPlayersRank(guildid);
chr.getMGC().setAllianceRank(2);
Server.getInstance().getGuild(chr.getGuildId()).getMGC(chr.getId()).setAllianceRank(2);
chr.saveGuildStatus();
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);
chr.getGuild().dropMessage("Your guild has joined the [" + alliance.getName() + "] union.");
break;
}
case 0x06:
{
// Expel Guild
int guildid = slea.readInt();
int allianceid = slea.readInt();
if (chr.getGuild().getAllianceId() == 0 || chr.getGuild().getAllianceId() != allianceid) {
return;
}
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.removeGuildFromAlliance(alliance, guildid, c.getWorld()), -1, -1);
Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c.getWorld()), -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
if (chr.getGuild().getAllianceId() == 0 || chr.getGuildId() < 1) {
return;
}
int victimid = slea.readInt();
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(victimid);
if (player.getAllianceRank() != 2) {
return;
}
// Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(chr.getGuild().getAllianceId(), chr.getId(), slea.readInt()), -1, -1);
changeLeaderAllianceRank(alliance, player);
break;
}
case 0x08:
String[] ranks = new String[5];
for (int i = 0; i < 5; i++) {
ranks[i] = slea.readMapleAsciiString();
}
Server.getInstance().setAllianceRanks(alliance.getId(), ranks);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.changeAllianceRankTitle(alliance.getId(), ranks), -1, -1);
break;
case 0x09:
{
int int1 = slea.readInt();
byte byte1 = slea.readByte();
// Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(chr.getGuild().getAllianceId(), chr.getId(), int1, byte1), -1, -1);
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(int1);
changePlayerAllianceRank(alliance, player, (byte1 > 0));
break;
}
case 0x0A:
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:
chr.dropMessage("Feature not available");
}
alliance.saveToDB();
}
use of net.server.guild.MapleAlliance in project HeavenMS by ronancpl.
the class NPCConversationManager method upgradeAlliance.
public void upgradeAlliance() {
MapleAlliance alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId());
alliance.increaseCapacity(1);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c.getWorld()), -1, -1);
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), alliance.getNotice()), -1, -1);
}
use of net.server.guild.MapleAlliance in project HeavenMS by ronancpl.
the class GuildOperationHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
if (System.currentTimeMillis() >= nextPruneTime) {
Iterator<Invited> itr = invited.iterator();
Invited inv;
while (itr.hasNext()) {
inv = itr.next();
if (System.currentTimeMillis() >= inv.expiration) {
itr.remove();
}
}
nextPruneTime = System.currentTimeMillis() + 20 * 60 * 1000;
}
MapleCharacter mc = c.getPlayer();
byte type = slea.readByte();
int allianceId = -1;
switch(type) {
case 0x00:
// c.announce(MaplePacketCreator.showGuildInfo(mc));
break;
case 0x02:
if (mc.getGuildId() > 0 || mc.getMapId() != 200000301) {
c.getPlayer().dropMessage(1, "You cannot create a new Guild while in one.");
return;
}
if (mc.getMeso() < MapleGuild.CREATE_GUILD_COST) {
c.getPlayer().dropMessage(1, "You do not have enough mesos to create a Guild.");
return;
}
String guildName = slea.readMapleAsciiString();
if (!isGuildNameAcceptable(guildName)) {
c.getPlayer().dropMessage(1, "The Guild name you have chosen is not accepted.");
return;
}
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);
mc.getMGC().setGuildId(gid);
// initialize guild structure
Server.getInstance().getGuild(mc.getGuildId(), mc.getWorld(), mc);
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) {
return;
}
String name = slea.readMapleAsciiString();
MapleGuildResponse mgr = MapleGuild.sendInvite(c, name);
if (mgr != null) {
c.announce(mgr.getPacket());
} else {
Invited inv = new Invited(name, mc.getGuildId());
if (!invited.contains(inv)) {
invited.add(inv);
}
}
break;
case 0x06:
if (mc.getGuildId() > 0) {
System.out.println("[hax] " + mc.getName() + " attempted to join a guild when s/he is already in one.");
return;
}
gid = slea.readInt();
int cid = slea.readInt();
if (cid != mc.getId()) {
System.out.println("[hax] " + mc.getName() + " attempted to join a guild with a different character id.");
return;
}
name = mc.getName().toLowerCase();
Iterator<Invited> itr = invited.iterator();
boolean bOnList = false;
while (itr.hasNext()) {
Invited inv = itr.next();
if (gid == inv.gid && name.equals(inv.name)) {
bOnList = true;
itr.remove();
break;
}
}
if (!bOnList) {
System.out.println("[hax] " + mc.getName() + " is trying to join a guild that never invited him/her (or that the invitation has expired)");
return;
}
// joins the guild
mc.getMGC().setGuildId(gid);
// start at lowest rank
mc.getMGC().setGuildRank(5);
mc.getMGC().setAllianceRank(5);
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.getMGC().setGuildId(0);
return;
}
c.announce(MaplePacketCreator.showGuildInfo(mc));
allianceId = mc.getGuild().getAllianceId();
if (allianceId > 0)
Server.getInstance().getAlliance(allianceId).updateAlliancePackets(mc);
// update database
mc.saveGuildStatus();
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) {
System.out.println("[hax] " + mc.getName() + " tried to quit guild under the name \"" + name + "\" and current guild id of " + mc.getGuildId() + ".");
return;
}
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.getMGC().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) {
System.out.println("[hax] " + mc.getName() + " is trying to expel without rank 1 or 2.");
return;
}
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) {
System.out.println("[hax] " + mc.getName() + " tried to change guild rank titles when s/he does not have permission.");
return;
}
String[] ranks = new String[5];
for (int i = 0; i < 5; i++) {
ranks[i] = slea.readMapleAsciiString();
}
Server.getInstance().changeRankTitle(mc.getGuildId(), ranks);
break;
case 0x0e:
cid = slea.readInt();
byte newRank = slea.readByte();
if (mc.getGuildRank() > 2 || (newRank <= 2 && mc.getGuildRank() != 1) || mc.getGuildId() <= 0) {
System.out.println("[hax] " + mc.getName() + " is trying to change rank outside of his/her permissions.");
return;
}
if (newRank <= 1 || newRank > 5) {
return;
}
Server.getInstance().changeRank(mc.getGuildId(), cid, newRank);
break;
case 0x0f:
if (mc.getGuildId() <= 0 || mc.getGuildRank() != 1 || mc.getMapId() != 200000301) {
System.out.println("[hax] " + mc.getName() + " tried to change guild emblem without being the guild leader.");
return;
}
if (mc.getMeso() < MapleGuild.CHANGE_EMBLEM_COST) {
c.announce(MaplePacketCreator.serverNotice(1, "You do not have enough mesos to change the Guild emblem."));
return;
}
short bg = slea.readShort();
byte bgcolor = slea.readByte();
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) {
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();
if (notice.length() > 100) {
return;
}
Server.getInstance().setGuildNotice(mc.getGuildId(), notice);
break;
default:
System.out.println("Unhandled GUILD_OPERATION packet: \n" + slea.toString());
}
}
Aggregations