Search in sources :

Example 1 with MapleGuild

use of net.server.guild.MapleGuild in project HeavenMS by ronancpl.

the class MapleClient method disconnect.

public final synchronized void disconnect(boolean shutdown, boolean cashshop) {
    // once per MapleClient instance
    if (disconnecting) {
        return;
    }
    disconnecting = true;
    if (player != null && player.isLoggedin() && player.getClient() != null) {
        MapleMap map = player.getMap();
        final MapleParty party = player.getParty();
        final int idz = player.getId();
        final int messengerid = player.getMessenger() == null ? 0 : player.getMessenger().getId();
        // final int fid = player.getFamilyId();
        final BuddyList bl = player.getBuddylist();
        final MaplePartyCharacter chrp = new MaplePartyCharacter(player);
        final MapleMessengerCharacter chrm = new MapleMessengerCharacter(player, 0);
        final MapleGuildCharacter chrg = player.getMGC();
        final MapleGuild guild = player.getGuild();
        player.cancelMagicDoor();
        if (channel == -1 || shutdown) {
            if (chrg != null)
                chrg.setCharacter(null);
            removePlayer();
            player.saveCooldowns();
            player.saveToDB(true);
            player = null;
            return;
        }
        removePlayer();
        final World worlda = getWorldServer();
        try {
            if (!cashshop) {
                if (!this.serverTransition) {
                    // meaning not changing channels
                    if (messengerid > 0) {
                        worlda.leaveMessenger(messengerid, chrm);
                    }
                    /*      
						if (fid > 0) {
                                                        final MapleFamily family = worlda.getFamily(fid);
                                                        family.
                                                }
                                                */
                    for (MapleQuestStatus status : player.getStartedQuests()) {
                        // This is for those quests that you have to stay logged in for a certain amount of time
                        MapleQuest quest = status.getQuest();
                        if (quest.getTimeLimit() > 0) {
                            MapleQuestStatus newStatus = new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
                            newStatus.setForfeited(player.getQuest(quest).getForfeited() + 1);
                            player.updateQuest(newStatus);
                        }
                    }
                    if (guild != null) {
                        final Server server = Server.getInstance();
                        server.setGuildMemberOnline(player, false, player.getClient().getChannel());
                        player.getClient().announce(MaplePacketCreator.showGuildInfo(player));
                    }
                    if (party != null) {
                        chrp.setOnline(false);
                        worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
                        if (map != null && party.getLeader().getId() == idz) {
                            MaplePartyCharacter lchr = null;
                            for (MaplePartyCharacter pchr : party.getMembers()) {
                                if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
                                    lchr = pchr;
                                }
                            }
                            if (lchr != null) {
                                worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
                            }
                        }
                    }
                    if (bl != null) {
                        worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
                    }
                }
            } else {
                if (!this.serverTransition) {
                    // if dc inside of cash shop.
                    if (party != null) {
                        chrp.setOnline(false);
                        worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
                        if (map != null && party.getLeader().getId() == idz) {
                            MaplePartyCharacter lchr = null;
                            for (MaplePartyCharacter pchr : party.getMembers()) {
                                if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
                                    lchr = pchr;
                                }
                            }
                            if (lchr != null) {
                                worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
                            }
                        }
                    }
                    if (bl != null) {
                        worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
                    }
                }
            }
        } catch (final Exception e) {
            FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, e);
        } finally {
            getChannelServer().removePlayer(player);
            if (!this.serverTransition) {
                worlda.removePlayer(player);
                player.saveCooldowns();
                player.saveToDB(true);
                if (player != null) {
                    // no idea, occur :(
                    player.empty(false);
                }
                player.logOff();
            } else {
                player.saveCooldowns();
                player.saveToDB();
            }
            player = null;
        }
    }
    if (!serverTransition && isLoggedIn()) {
        updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
        // prevents double dcing during login
        session.removeAttribute(MapleClient.CLIENT_KEY);
        session.close(false);
    }
    engines.clear();
}
Also used : MapleQuest(server.quest.MapleQuest) Server(net.server.Server) MapleGuildCharacter(net.server.guild.MapleGuildCharacter) MapleParty(net.server.world.MapleParty) MapleMessengerCharacter(net.server.world.MapleMessengerCharacter) World(net.server.world.World) SQLException(java.sql.SQLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MapleGuild(net.server.guild.MapleGuild) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 2 with MapleGuild

use of net.server.guild.MapleGuild in project HeavenMS by ronancpl.

the class Server method getGuild.

public MapleGuild getGuild(int id, int world, MapleCharacter mc) {
    synchronized (guilds) {
        if (guilds.get(id) != null) {
            return guilds.get(id);
        }
        MapleGuild g = new MapleGuild(id, world);
        if (g.getId() == -1) {
            return null;
        }
        if (mc != null) {
            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());
        }
        guilds.put(id, g);
        return g;
    }
}
Also used : MapleGuild(net.server.guild.MapleGuild)

Example 3 with MapleGuild

use of net.server.guild.MapleGuild 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();
}
Also used : MapleCharacter(client.MapleCharacter) MapleAlliance(net.server.guild.MapleAlliance) MapleGuild(net.server.guild.MapleGuild)

Example 4 with MapleGuild

use of net.server.guild.MapleGuild in project HeavenMS by ronancpl.

the class EventManager method exportReadyGuild.

private void exportReadyGuild(Integer guildId) {
    MapleGuild mg = server.getGuild(guildId);
    String callout = "[Guild Quest] Your guild has been registered to attend to the Sharenian Guild Quest at channel " + this.getChannelServer().getId() + " and HAS JUST STARTED THE STRATEGY PHASE. After 3 minutes, no more guild members will be allowed to join the effort." + " Check out Shuang at the excavation site in Perion for more info.";
    mg.dropMessage(6, callout);
}
Also used : MapleGuild(net.server.guild.MapleGuild)

Example 5 with MapleGuild

use of net.server.guild.MapleGuild in project HeavenMS by ronancpl.

the class MaplePacketCreator method showGuildInfo.

public static byte[] showGuildInfo(MapleCharacter c) {
    final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
    mplew.writeShort(SendOpcode.GUILD_OPERATION.getValue());
    // signature for showing guild info
    mplew.write(0x1A);
    if (c == null) {
        // show empty guild (used for leaving, expelled)
        mplew.write(0);
        return mplew.getPacket();
    }
    MapleGuild g = c.getClient().getWorldServer().getGuild(c.getMGC());
    if (g == null) {
        // failed to read from DB - don't show a guild
        mplew.write(0);
        return mplew.getPacket();
    }
    // bInGuild
    mplew.write(1);
    mplew.writeInt(g.getId());
    mplew.writeMapleAsciiString(g.getName());
    for (int i = 1; i <= 5; i++) {
        mplew.writeMapleAsciiString(g.getRankTitle(i));
    }
    Collection<MapleGuildCharacter> members = g.getMembers();
    // then it is the size of all the members
    mplew.write(members.size());
    for (MapleGuildCharacter mgc : members) {
        // and each of their character ids o_O
        mplew.writeInt(mgc.getId());
    }
    for (MapleGuildCharacter mgc : members) {
        mplew.writeAsciiString(getRightPaddedStr(mgc.getName(), '\0', 13));
        mplew.writeInt(mgc.getJobId());
        mplew.writeInt(mgc.getLevel());
        mplew.writeInt(mgc.getGuildRank());
        mplew.writeInt(mgc.isOnline() ? 1 : 0);
        mplew.writeInt(g.getSignature());
        mplew.writeInt(mgc.getAllianceRank());
    }
    mplew.writeInt(g.getCapacity());
    mplew.writeShort(g.getLogoBG());
    mplew.write(g.getLogoBGColor());
    mplew.writeShort(g.getLogo());
    mplew.write(g.getLogoColor());
    mplew.writeMapleAsciiString(g.getNotice());
    mplew.writeInt(g.getGP());
    mplew.writeInt(g.getAllianceId());
    return mplew.getPacket();
}
Also used : MaplePacketLittleEndianWriter(tools.data.output.MaplePacketLittleEndianWriter) MapleGuildCharacter(net.server.guild.MapleGuildCharacter) MapleGuild(net.server.guild.MapleGuild) Point(java.awt.Point)

Aggregations

MapleGuild (net.server.guild.MapleGuild)12 Server (net.server.Server)3 MapleAlliance (net.server.guild.MapleAlliance)3 MapleCharacter (client.MapleCharacter)2 MaplePet (client.inventory.MaplePet)2 Point (java.awt.Point)2 SQLException (java.sql.SQLException)2 MapleGuildCharacter (net.server.guild.MapleGuildCharacter)2 MapleGuildSummary (net.server.guild.MapleGuildSummary)2 MaplePartyCharacter (net.server.world.MaplePartyCharacter)2 World (net.server.world.World)2 MaplePacketLittleEndianWriter (tools.data.output.MaplePacketLittleEndianWriter)2 BuddylistEntry (client.BuddylistEntry)1 CharacterNameAndId (client.CharacterNameAndId)1 MapleFamily (client.MapleFamily)1 MapleQuestStatus (client.MapleQuestStatus)1 Item (client.inventory.Item)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 PlayerBuffValueHolder (net.server.PlayerBuffValueHolder)1