Search in sources :

Example 1 with Server

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

use of net.server.Server in project HeavenMS by ronancpl.

the class Commands method executeSolaxiaPlayerCommand.

public static boolean executeSolaxiaPlayerCommand(MapleClient c, String[] sub, char heading) {
    Channel cserv = c.getChannelServer();
    Server srv = Server.getInstance();
    return executeHeavenMsCommand(cserv, srv, c, sub, c.getPlayer().gmLevel());
}
Also used : Server(net.server.Server) Channel(net.server.channel.Channel)

Example 3 with Server

use of net.server.Server in project HeavenMS by ronancpl.

the class Commands method executeHeavenMsCommandLv6.

public static boolean executeHeavenMsCommandLv6(Channel cserv, Server srv, MapleClient c, String[] sub) {
    // Admin
    MapleCharacter player = c.getPlayer();
    MapleCharacter victim;
    switch(sub[0]) {
        case "setgmlevel":
            if (sub.length < 3) {
                player.yellowMessage("Syntax: !setgmlevel <playername> <newlevel>");
                break;
            }
            int newLevel = Integer.parseInt(sub[2]);
            MapleCharacter target = cserv.getPlayerStorage().getCharacterByName(sub[1]);
            if (target != null) {
                target.setGMLevel(newLevel);
                target.getClient().setGMLevel(newLevel);
                target.dropMessage("You are now a level " + newLevel + " GM. See @commands for a list of available commands.");
                player.dropMessage(target + " is now a level " + newLevel + " GM.");
            } else {
                player.dropMessage("Player '" + sub[1] + "' was not found on this channel.");
            }
            break;
        case "warpworld":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !warpworld <worldid>");
                break;
            }
            Server server = Server.getInstance();
            byte worldb = Byte.parseByte(sub[1]);
            if (worldb <= (server.getWorlds().size() - 1)) {
                try {
                    String[] socket = server.getIP(worldb, c.getChannel()).split(":");
                    c.getWorldServer().removePlayer(player);
                    // LOL FORGOT THIS ><
                    player.getMap().removePlayer(player);
                    c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
                    player.setWorld(worldb);
                    // To set the new world :O (true because else 2 player instances are created, one in both worlds)
                    player.saveToDB();
                    c.announce(MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
                } catch (UnknownHostException | NumberFormatException ex) {
                    ex.printStackTrace();
                    player.message("Error when trying to change worlds, are you sure the world you are trying to warp to has the same amount of channels?");
                }
            } else {
                player.message("Invalid world; highest number available: " + (server.getWorlds().size() - 1));
            }
            break;
        case "saveall":
            for (World world : Server.getInstance().getWorlds()) {
                for (MapleCharacter chr : world.getPlayerStorage().getAllCharacters()) {
                    chr.saveToDB();
                }
            }
            String message = player.getName() + " used !saveall.";
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.serverNotice(5, message));
            player.message("All players saved successfully.");
            break;
        case "dcall":
            for (World world : Server.getInstance().getWorlds()) {
                for (MapleCharacter chr : world.getPlayerStorage().getAllCharacters()) {
                    if (!chr.isGM()) {
                        chr.getClient().disconnect(false, false);
                    }
                }
            }
            player.message("All players successfully disconnected.");
            break;
        case "mapplayers":
            String names = "";
            int map = player.getMapId();
            for (World world : Server.getInstance().getWorlds()) {
                for (MapleCharacter chr : world.getPlayerStorage().getAllCharacters()) {
                    int curMap = chr.getMapId();
                    String hp = Integer.toString(chr.getHp());
                    String maxhp = Integer.toString(chr.getMaxHp());
                    String name = chr.getName() + ": " + hp + "/" + maxhp;
                    if (map == curMap) {
                        names = names.equals("") ? name : (names + ", " + name);
                    }
                }
            }
            player.message("These b lurkin: " + names);
            break;
        case "getacc":
            if (sub.length < 2) {
                player.yellowMessage("Syntax: !getacc <playername>");
                break;
            }
            victim = c.getWorldServer().getPlayerStorage().getCharacterByName(sub[1]);
            if (victim != null) {
                player.message(victim.getName() + "'s account name is " + victim.getClient().getAccountName() + ".");
            } else {
                player.message("Player '" + sub[1] + "' could not be found on this world.");
            }
            break;
        case "shutdown":
        case "shutdownnow":
            int time = 60000;
            if (sub[0].equals("shutdownnow")) {
                time = 1;
            } else if (sub.length > 1) {
                time *= Integer.parseInt(sub[1]);
            }
            if (time > 1) {
                int seconds = (int) (time / 1000) % 60;
                int minutes = (int) ((time / (1000 * 60)) % 60);
                int hours = (int) ((time / (1000 * 60 * 60)) % 24);
                int days = (int) ((time / (1000 * 60 * 60 * 24)));
                String strTime = "";
                if (days > 0)
                    strTime += days + " days, ";
                if (hours > 0)
                    strTime += hours + " hours, ";
                strTime += minutes + " minutes, ";
                strTime += seconds + " seconds";
                for (World w : Server.getInstance().getWorlds()) {
                    for (MapleCharacter chr : w.getPlayerStorage().getAllCharacters()) {
                        chr.dropMessage("Server is undergoing maintenance process, and will be shutdown in " + strTime + ". Prepare yourself to quit safely in the mean time.");
                    }
                }
            }
            TimerManager.getInstance().schedule(Server.getInstance().shutdown(false), time);
            break;
        case "clearquestcache":
            MapleQuest.clearCache();
            player.dropMessage(5, "Quest Cache Cleared.");
            break;
        case "clearquest":
            if (sub.length < 1) {
                player.dropMessage(5, "Please include a quest ID.");
                break;
            }
            MapleQuest.clearCache(Integer.parseInt(sub[1]));
            player.dropMessage(5, "Quest Cache for quest " + sub[1] + " cleared.");
            break;
        case "fred":
            c.announce(MaplePacketCreator.fredrickMessage(Byte.valueOf(sub[1])));
            break;
        default:
            return false;
    }
    return true;
}
Also used : MapleCharacter(client.MapleCharacter) Server(net.server.Server) UnknownHostException(java.net.UnknownHostException) World(net.server.world.World) Point(java.awt.Point) SpawnPoint(server.life.SpawnPoint)

Example 4 with Server

use of net.server.Server in project HeavenMS by ronancpl.

the class MapleClient method changeChannel.

public void changeChannel(int channel) {
    Server server = Server.getInstance();
    if (player.isBanned()) {
        disconnect(false, false);
        return;
    }
    if (!player.isAlive() || FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) {
        announce(MaplePacketCreator.enableActions());
        return;
    } else if (MapleMiniDungeonInfo.isDungeonMap(player.getMapId())) {
        announce(MaplePacketCreator.serverNotice(5, "Changing channels or entering Cash Shop or MTS are disabled when inside a Mini-Dungeon."));
        announce(MaplePacketCreator.enableActions());
        return;
    }
    String[] socket = Server.getInstance().getIP(getWorld(), channel).split(":");
    if (player.getTrade() != null) {
        MapleTrade.cancelTrade(getPlayer());
    }
    MapleHiredMerchant merchant = player.getHiredMerchant();
    if (merchant != null) {
        if (merchant.isOwner(getPlayer())) {
            merchant.setOpen(true);
        } else {
            merchant.removeVisitor(getPlayer());
        }
    }
    player.unregisterChairBuff();
    server.getPlayerBuffStorage().addBuffsToStorage(player.getId(), player.getAllBuffs());
    player.setAwayFromWorld(true);
    player.cancelAllBuffs(true);
    player.cancelBuffExpireTask();
    player.cancelDiseaseExpireTask();
    player.cancelSkillCooldownTask();
    player.cancelQuestExpirationTask();
    // Cancelling mounts? Noty
    if (player.getBuffedValue(MapleBuffStat.PUPPET) != null) {
        player.cancelEffectFromBuffStat(MapleBuffStat.PUPPET);
    }
    if (player.getBuffedValue(MapleBuffStat.COMBO) != null) {
        player.cancelEffectFromBuffStat(MapleBuffStat.COMBO);
    }
    // test
    player.getInventory(MapleInventoryType.EQUIPPED).checked(false);
    player.getMap().removePlayer(player);
    player.clearBanishPlayerData();
    player.getClient().getChannelServer().removePlayer(player);
    player.getClient().updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);
    try {
        announce(MaplePacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Server(net.server.Server)

Example 5 with Server

use of net.server.Server in project HeavenMS by ronancpl.

the class PlayerLoggedinHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final int cid = slea.readInt();
    final Server server = Server.getInstance();
    MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(cid);
    boolean newcomer = false;
    if (player == null) {
        try {
            player = MapleCharacter.loadCharFromDB(cid, c, true);
            newcomer = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
    } else {
        player.newClient(c);
    }
    if (player == null) {
        // If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
        c.disconnect(true, false);
        return;
    }
    c.setPlayer(player);
    c.setAccID(player.getAccountID());
    int state = c.getLoginState();
    boolean allowLogin = true;
    Channel cserv = c.getChannelServer();
    if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
        for (String charName : c.loadCharacterNames(c.getWorld())) {
            for (Channel ch : c.getWorldServer().getChannels()) {
                if (ch.isConnected(charName)) {
                    allowLogin = false;
                }
            }
            break;
        }
    }
    if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
        c.setPlayer(null);
        c.announce(MaplePacketCreator.getAfterLoginError(7));
        return;
    }
    c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
    cserv.addPlayer(player);
    List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
    if (buffs != null) {
        List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
        player.silentGiveBuffs(timedBuffs);
    }
    c.announce(MaplePacketCreator.getCharInfo(player));
    if (!player.isHidden()) {
        player.toggleHide(true);
    }
    player.sendKeymap();
    player.sendMacros();
    if (player.getKeymap().get(91) != null)
        player.announce(MaplePacketCreator.sendAutoHpPot(player.getKeymap().get(91).getAction()));
    if (player.getKeymap().get(92) != null)
        player.announce(MaplePacketCreator.sendAutoMpPot(player.getKeymap().get(92).getAction()));
    player.getMap().addPlayer(player);
    World world = server.getWorld(c.getWorld());
    world.getPlayerStorage().addPlayer(player);
    player.setAwayFromWorld(false);
    int[] buddyIds = player.getBuddylist().getBuddyIds();
    world.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
    for (CharacterIdChannelPair onlineBuddy : server.getWorld(c.getWorld()).multiBuddyFind(player.getId(), buddyIds)) {
        BuddylistEntry ble = player.getBuddylist().get(onlineBuddy.getCharacterId());
        ble.setChannel(onlineBuddy.getChannel());
        player.getBuddylist().put(ble);
    }
    c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
    c.announce(MaplePacketCreator.loadFamily(player));
    if (player.getFamilyId() > 0) {
        MapleFamily f = world.getFamily(player.getFamilyId());
        if (f == null) {
            f = new MapleFamily(player.getId());
            world.addFamily(player.getFamilyId(), f);
        }
        player.setFamily(f);
        c.announce(MaplePacketCreator.getFamilyInfo(f.getMember(player.getId())));
    }
    if (player.getGuildId() > 0) {
        MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
        if (playerGuild == null) {
            player.deleteGuild(player.getGuildId());
            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();
            if (allianceId > 0) {
                MapleAlliance newAlliance = server.getAlliance(allianceId);
                if (newAlliance == null) {
                    newAlliance = MapleAlliance.loadAlliance(allianceId);
                    if (newAlliance != null) {
                        server.addAlliance(allianceId, newAlliance);
                    } else {
                        player.getGuild().setAllianceId(0);
                    }
                }
                if (newAlliance != null) {
                    c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c));
                    c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
                    if (newcomer) {
                        server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
                    }
                }
            }
        }
    }
    player.showNote();
    if (player.getParty() != null) {
        MaplePartyCharacter pchar = player.getMPC();
        // Use this in case of enabling party HPbar HUD when logging in, however "you created a party" will appear on chat.
        // c.announce(MaplePacketCreator.partyCreated(pchar));
        pchar.setChannel(c.getChannel());
        pchar.setMapId(player.getMapId());
        pchar.setOnline(true);
        world.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
        player.updatePartyMemberHP();
    }
    if (player.getInventory(MapleInventoryType.EQUIPPED).findById(1122017) != null) {
        player.equipPendantOfSpirit();
    }
    c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
    CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
    if (pendingBuddyRequest != null) {
        c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
    }
    if (newcomer) {
        for (MaplePet pet : player.getPets()) {
            if (pet != null)
                world.registerPetHunger(player, player.getPetIndex(pet));
        }
        player.reloadQuestExpirations();
    }
    c.announce(MaplePacketCreator.updateGender(player));
    player.checkMessenger();
    c.announce(MaplePacketCreator.enableReport());
    player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
    player.checkBerserk(player.isHidden());
    player.buffExpireTask();
    player.diseaseExpireTask();
    player.skillCooldownTask();
    player.expirationTask();
    player.questExpirationTask();
    if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
        player.createDragon();
    }
    player.commitExcludedItems();
    if (newcomer) {
        /*
            if (!c.hasVotedAlready()){
            	player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
            }
                    */
        if (player.isGM()) {
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
        }
    }
    showDueyNotification(c, player);
    if (player.getMap().getHPDec() > 0)
        player.resetHpDecreaseTask();
    player.resetPlayerRates();
    if (ServerConstants.USE_ADD_RATES_BY_LEVEL == true)
        player.setPlayerRates();
    player.setWorldRates();
    player.updateCouponRates();
    player.receivePartyMemberHP();
}
Also used : MapleCharacter(client.MapleCharacter) PlayerBuffValueHolder(net.server.PlayerBuffValueHolder) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Server(net.server.Server) SQLException(java.sql.SQLException) MapleFamily(client.MapleFamily) Channel(net.server.channel.Channel) World(net.server.world.World) BuddylistEntry(client.BuddylistEntry) MapleGuild(net.server.guild.MapleGuild) MapleAlliance(net.server.guild.MapleAlliance) MaplePet(client.inventory.MaplePet) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Pair(tools.Pair) MaplePartyCharacter(net.server.world.MaplePartyCharacter) CharacterNameAndId(client.CharacterNameAndId)

Aggregations

Server (net.server.Server)8 World (net.server.world.World)4 MapleGuild (net.server.guild.MapleGuild)3 MapleCharacter (client.MapleCharacter)2 SQLException (java.sql.SQLException)2 Channel (net.server.channel.Channel)2 MaplePartyCharacter (net.server.world.MaplePartyCharacter)2 BuddylistEntry (client.BuddylistEntry)1 CharacterNameAndId (client.CharacterNameAndId)1 MapleFamily (client.MapleFamily)1 MaplePet (client.inventory.MaplePet)1 Point (java.awt.Point)1 UnknownHostException (java.net.UnknownHostException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 PlayerBuffValueHolder (net.server.PlayerBuffValueHolder)1 CharacterIdChannelPair (net.server.channel.CharacterIdChannelPair)1 MapleAlliance (net.server.guild.MapleAlliance)1 MapleGuildCharacter (net.server.guild.MapleGuildCharacter)1 MapleGuildSummary (net.server.guild.MapleGuildSummary)1 MapleMessengerCharacter (net.server.world.MapleMessengerCharacter)1