Search in sources :

Example 1 with MapleMessengerCharacter

use of net.server.world.MapleMessengerCharacter 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 MapleMessengerCharacter

use of net.server.world.MapleMessengerCharacter in project HeavenMS by ronancpl.

the class MapleCharacter method closePlayerMessenger.

public void closePlayerMessenger() {
    MapleMessenger m = this.getMessenger();
    if (m == null)
        return;
    World w = client.getWorldServer();
    MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(this, this.getMessengerPosition());
    w.leaveMessenger(m.getId(), messengerplayer);
    this.setMessenger(null);
    this.setMessengerPosition(4);
}
Also used : MapleMessengerCharacter(net.server.world.MapleMessengerCharacter) World(net.server.world.World) MapleMessenger(net.server.world.MapleMessenger)

Example 3 with MapleMessengerCharacter

use of net.server.world.MapleMessengerCharacter in project HeavenMS by ronancpl.

the class MapleCharacter method checkMessenger.

public void checkMessenger() {
    if (messenger != null && messengerposition < 4 && messengerposition > -1) {
        World worldz = Server.getInstance().getWorld(world);
        worldz.silentJoinMessenger(messenger.getId(), new MapleMessengerCharacter(this, messengerposition), messengerposition);
        worldz.updateMessenger(getMessenger().getId(), name, client.getChannel());
    }
}
Also used : MapleMessengerCharacter(net.server.world.MapleMessengerCharacter) World(net.server.world.World)

Example 4 with MapleMessengerCharacter

use of net.server.world.MapleMessengerCharacter in project HeavenMS by ronancpl.

the class MessengerHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    String input;
    byte mode = slea.readByte();
    MapleCharacter player = c.getPlayer();
    World world = c.getWorldServer();
    MapleMessenger messenger = player.getMessenger();
    switch(mode) {
        case 0x00:
            if (messenger == null) {
                int messengerid = slea.readInt();
                if (messengerid == 0) {
                    MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, 0);
                    messenger = world.createMessenger(messengerplayer);
                    player.setMessenger(messenger);
                    player.setMessengerPosition(0);
                } else {
                    messenger = world.getMessenger(messengerid);
                    int position = messenger.getLowestPosition();
                    MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, position);
                    if (messenger.getMembers().size() < 3) {
                        player.setMessenger(messenger);
                        player.setMessengerPosition(position);
                        world.joinMessenger(messenger.getId(), messengerplayer, player.getName(), messengerplayer.getChannel());
                    }
                }
            }
            break;
        case 0x02:
            player.closePlayerMessenger();
            break;
        case 0x03:
            if (messenger.getMembers().size() < 3) {
                input = slea.readMapleAsciiString();
                MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(input);
                if (target != null) {
                    if (target.getMessenger() == null) {
                        target.getClient().announce(MaplePacketCreator.messengerInvite(c.getPlayer().getName(), messenger.getId()));
                        c.announce(MaplePacketCreator.messengerNote(input, 4, 1));
                    } else {
                        c.announce(MaplePacketCreator.messengerChat(player.getName() + " : " + input + " is already using Maple Messenger"));
                    }
                } else {
                    if (world.find(input) > -1) {
                        world.messengerInvite(c.getPlayer().getName(), messenger.getId(), input, c.getChannel());
                    } else {
                        c.announce(MaplePacketCreator.messengerNote(input, 4, 0));
                    }
                }
            } else {
                c.announce(MaplePacketCreator.messengerChat(player.getName() + " : You cannot have more than 3 people in the Maple Messenger"));
            }
            break;
        case 0x05:
            String targeted = slea.readMapleAsciiString();
            MapleCharacter target = c.getChannelServer().getPlayerStorage().getCharacterByName(targeted);
            if (target != null) {
                if (target.getMessenger() != null) {
                    target.getClient().announce(MaplePacketCreator.messengerNote(player.getName(), 5, 0));
                }
            } else {
                world.declineChat(targeted, player.getName());
            }
            break;
        case 0x06:
            if (messenger != null) {
                MapleMessengerCharacter messengerplayer = new MapleMessengerCharacter(player, player.getMessengerPosition());
                input = slea.readMapleAsciiString();
                world.messengerChat(messenger, input, messengerplayer.getName());
            }
            break;
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleMessengerCharacter(net.server.world.MapleMessengerCharacter) World(net.server.world.World) MapleMessenger(net.server.world.MapleMessenger)

Aggregations

MapleMessengerCharacter (net.server.world.MapleMessengerCharacter)4 World (net.server.world.World)4 MapleMessenger (net.server.world.MapleMessenger)2 MapleCharacter (client.MapleCharacter)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1 Server (net.server.Server)1 MapleGuild (net.server.guild.MapleGuild)1 MapleGuildCharacter (net.server.guild.MapleGuildCharacter)1 MapleParty (net.server.world.MapleParty)1 MaplePartyCharacter (net.server.world.MaplePartyCharacter)1 MapleQuest (server.quest.MapleQuest)1