Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Add-On][v75+] Custom Fishing System

Joined
Feb 23, 2008
Messages
507
Reaction score
361
Due to a forum bug, the thread was deleted, so here, I just reposted it. Thanks to Shawn for finding my thread.

Made this a few months ago. I just wanted to give to the community a bit, I'm in a release mood.

Remember to give proper credits if you repost this thread anywhere else, no help will be given. Also, remember to 'thank' me if this helped you!



server.Fishing.java
PHP:
/**
 *
 * @author FateJiki of RaGeZONE
 */
public class Fishing {
    public static void doFishing(client.MapleCharacter chr){
        int mesoMultiplier = 1;
        int expMultiplier = 1;
        switch(chr.getWorld()){
            case 0:
                mesoMultiplier = constants.ServerConstants.MESO_RATE;
                expMultiplier = constants.ServerConstants.EXP_RATE;
                break;
            case 1: // if you have bera
                mesoMultiplier = constants.ServerConstants.WORLD_1_MESORATE;
                expMultiplier = constants.ServerConstants.WORLD_1_EXPRATE;
                break;
            case 2: // if you have broa
                mesoMultiplier = constants.ServerConstants.WORLD_2_MESORATE;
                expMultiplier = constants.ServerConstants.WORLD_2_EXPRATE;
                break;
        }
        int mesoAward = (int)(1400.0 * Math.random() + 1201) * mesoMultiplier + (15 * chr.getLevel() / 5);
        int expAward = (int)(645.0 * Math.random()) * expMultiplier + (15 * chr.getLevel() / 2) / 6;
        if(chr.getLevel() >= 30 && chr.getMapId() == 251000100){
            int rand = (int)(3.0 * Math.random());
            switch(rand){
                case 0:
                    chr.gainMeso(mesoAward, true, true, true);
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;
                case 1:
                    chr.gainExp(expAward, true, true);
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;
                case 2:
                    chr.gainItem(getRandomItem(), (short)1, true);
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;
                case 3: // if you have occupations
                    chr.gainOccEXP((int)((rand + (5.0 * Math.random())) * Math.random()));
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;
            }
          
        } else {
            chr.dropMessage("You must be above level 30 to fish!");
        }
    }
    public static int getRandomItem(){
        int finalID = 0;
        int rand = (int)(100.0 * Math.random());
        int[] commons = {1002851, 2002020, 2002020, 2000006, 2000018, 2002018, 2002024, 2002027, 2002027, 2000018, 2000018, 2000018 , 2000018, 2002030, 2002018, 2000016}; // filler' up
        int[] uncommons = {1000025, 1002662, 1002812, 1002850, 1002881, 1002880, 1012072, 4020009, 2043220, 2043022, 2040543, 2044420, 2040943, 2043713, 2044220, 2044120, 2040429, 2043220, 2040943}; // filler' uptoo
        int[] rares = {1002859, 1002553, 01002762, 01002763, 01002764, 01002765, 01002766, 01002663, 1002788, 1002949, 2049100, 2340000, 2040822,2040822,2040822,2040822,2040822,2040822,2040822,2040822}; // filler' uplast
        if(rand >= 25){
            return commons[(int)(commons.length * Math.random())];
        } else if(rand <= 7 && rand >= 5){
            return uncommons[(int)(uncommons.length * Math.random())];
        } else if(rand <= 3){
            return rares[(int)(rares.length * Math.random())];
        }

        return finalID;
    }
}
Replace net.channel.handler.useChairHandler.java with this :
PHP:
package net.channel.handler;

import client.MapleClient;
import client.MapleInventoryType;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
import server.TimerManager;
import java.util.concurrent.ScheduledFuture;

public final class UseChairHandler extends AbstractMaplePacketHandler {
    public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
        int itemId = slea.readInt();
        if (c.getPlayer().getInventory(MapleInventoryType.SETUP).findById(itemId) == null) {
            return;
        }
        if(c.getPlayer().getMapId() == 251000100 && itemId == 3011000 && !c.getPlayer().isFishing){
        c.getPlayer().isFishing = true;
        }
        c.getPlayer().setChair(itemId);
        c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showChair(c.getPlayer().getId(), itemId), false);
        c.getSession().write(MaplePacketCreator.enableActions());
    }
}
Replace net.channel.handler.cancelChairHandler.java with this :
PHP:
package net.channel.handler;

import client.MapleClient;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;

public final class CancelChairHandler extends AbstractMaplePacketHandler {
    public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
        int id = slea.readShort();
        if (id == -1) { // Cancel Chair
            c.getPlayer().setChair(0);
            c.getPlayer().isFishing = false;
            c.getSession().write(MaplePacketCreator.cancelChair(-1));
            c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showChair(c.getPlayer().getId(), 0), false);
        } else { // Use In-Map Chair
            c.getPlayer().setChair(id);
            c.getSession().write(MaplePacketCreator.cancelChair(id));
        }
    }
}
And finally, go in ChannelServer.java and add this :
PHP:
            @Override
            public void run(){
                for(MapleCharacter chr : getPlayerStorage().getAllCharacters()){
                    if(chr.isFishing && chr.getMapId() == 251000100){
                        server.Events.Fishing.doFishing(chr);
                    }
                }
            }
            }, 30000);
under tMan.register , (in the run method.)
 
Last edited by a moderator:
Legendary Battlemage
Loyal Member
Joined
Sep 28, 2008
Messages
600
Reaction score
291
Re: [v75+] Custom Fishing System

Eh, umm, could I ask why when i use the catch function, the catch effect won't show?..o_O
 
Junior Spellweaver
Joined
Jul 20, 2008
Messages
147
Reaction score
5
Re: [v75+] Custom Fishing System

Ooo its finally unbugged.

Just wandering. Do you actually catch fish? Cause i catch mesos only...

I had to make a function in maplecharacter for cm.gainitem and cm.gainOccEXP

so respectively they look like this :

cm.gainitem:
PHP:
    public void gainItem(int randomItem, short s, boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

cm.gainoccexp:
PHP:
    public void gainOccEXP(int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

What do i replace instead of these 2 functions?
 
Last edited:
may web.very maple.pls.
Loyal Member
Joined
Aug 12, 2009
Messages
1,810
Reaction score
606
Re: [v75+] Custom Fishing System

Ooo its finally unbugged.

Just wandering. Do you actually catch fish? Cause i catch mesos only...

I had to make a function in maplecharacter for cm.gainitem and cm.gainOccEXP

so respectively they look like this :

cm.gainitem:
PHP:
    public void gainItem(int randomItem, short s, boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

cm.gainoccexp:
PHP:
    public void gainOccEXP(int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

What do i replace instead of these 2 functions?
Remove this from Fishing.java:
PHP:
                case 3: // if you have occupations
                    chr.gainOccEXP((int)((rand + (5.0 * Math.random())) * Math.random()));
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;

Remove this as well in MapleCharacter.java
PHP:
public void gainOccEXP(int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
those are if you have Occupation system, guessing you don't have it.. also the gainItem not sure yet you should have it in MapleCharacter.java o.o
 
Last edited:
may web.very maple.pls.
Loyal Member
Joined
Aug 12, 2009
Messages
1,810
Reaction score
606
Re: [v75+] Custom Fishing System

wait quick question, wouldn't this make the srv slow by reading that function in channelserver alot and check all character over and over o_O? idk not sure on how the servers works xD
 
Newbie Spellweaver
Joined
Oct 10, 2010
Messages
41
Reaction score
75
Re: [v75+] Custom Fishing System

I'd like you to elaborate yourself a bit more.


What can I do to improve my code?

The main bottleneck here is that you're iterating over the WHOLE server. I know that if you had like 10 players that wouldn't be a problem, but try 900 and you'll see what I mean...

To speed it up, create a separate HashMap<Integer, Player> somewhere else. When somebody requests fishing or whatever, insert them into the hash map. Then in your timer method, iterate through this HashMap.

This means that if you have 900 players and only 10 of them chose fishing, the iterator would only have to iterate 10 times instead of 900. This greatly speeds it up by a ratio of 1:90.

This is only part of the performance problems.

- David
 
Junior Spellweaver
Joined
Jul 20, 2008
Messages
147
Reaction score
5
Re: [v75+] Custom Fishing System

Remove this from Fishing.java:
PHP:
                case 3: // if you have occupations
                    chr.gainOccEXP((int)((rand + (5.0 * Math.random())) * Math.random()));
                    chr.getClient().getSession().write(MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1));
                    chr.getMap().broadcastMessage(chr, MaplePacketCreator.catchMonster(9500336, 2000017, (byte)1), false);
                    break;

Remove this as well in MapleCharacter.java
PHP:
public void gainOccEXP(int i) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
those are if you have Occupation system, guessing you don't have it.. also the gainItem not sure yet you should have it in MapleCharacter.java o.o


I'm using MapleBlade and it doesn't seem to have the function :S thats why its not picking it up.
 
Custom Title Activated
Loyal Member
Joined
Mar 17, 2009
Messages
1,911
Reaction score
538
Re: [v75+] Custom Fishing System

Lol at above,

Release Multi Worlds :p
 
Newbie Spellweaver
Joined
Oct 14, 2007
Messages
18
Reaction score
0
Re: [v75+] Custom Fishing System

can u also release the isFishing thingy under maplecharacter.java ?
 
may web.very maple.pls.
Loyal Member
Joined
Aug 12, 2009
Messages
1,810
Reaction score
606
Re: [v75+] Custom Fishing System

MapleCharacter.java:
PHP:
 public boolean isFishing;

that might do it for you ;)
 
Newbie Spellweaver
Joined
May 16, 2009
Messages
22
Reaction score
3
Re: [v75+] Custom Fishing System

MapleCharacter.java:
PHP:
 public boolean isFishing;

that might do it for you ;)

iAkira can you please do it for me? I don't know anything about adding functions and stuff. i did all the steps but am stuck at the last one..

PHP:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.channel;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MalformedObjectNameException;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import client.MapleCharacter;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map.Entry;
import net.world.MapleParty;
import tools.DatabaseConnection;
import net.MaplePacket;
import net.MapleServerHandler;
import net.PacketProcessor;
import net.ServerMode;
import net.ServerMode.Mode;
import net.mina.MapleCodecFactory;
import net.world.MaplePartyCharacter;
import net.world.guild.MapleGuild;
import net.world.guild.MapleGuildCharacter;
import net.world.guild.MapleGuildSummary;
import net.world.remote.WorldChannelInterface;
import net.world.remote.WorldRegistry;
import provider.MapleDataProviderFactory;
import scripting.event.EventScriptManager;
import server.ShutdownServer;
import server.TimerManager;
import server.maps.MapleMapFactory;
import tools.MaplePacketCreator;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.buffer.SimpleBufferAllocator;
import org.apache.mina.core.filterchain.IoFilter;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.SocketSessionConfig;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import server.MapleSquad;
import server.MapleSquadType;
import server.maps.HiredMerchant;
import server.maps.MapleMap;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import server.maps.FakeCharacter;
import server.maps.HiredMerchant;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;

public class ChannelServer implements Runnable {

    private int port = 7575;
    private static WorldRegistry worldRegistry;
    private PlayerStorage players = new PlayerStorage();
    private int channel;
    private String key;
    private ChannelWorldInterface cwi;
    private WorldChannelInterface wci = null;
    private IoAcceptor acceptor;
    private String ip;
    private boolean shutdown = false;
    private boolean finishedShutdown = false;
    private boolean NonGmsCommands;
    private MapleMapFactory mapFactory;
    private EventScriptManager eventSM;
    private static Map<Integer, ChannelServer> instances = new HashMap<Integer, ChannelServer>();
    private static Map<String, ChannelServer> pendingInstances = new HashMap<String, ChannelServer>();
    private Map<Integer, MapleGuildSummary> gsStore = new HashMap<Integer, MapleGuildSummary>();
    private Boolean worldReady = true;
    private int instanceId = 0;
    public String president = "None";
    private Map<MapleSquadType, MapleSquad> mapleSquads = new HashMap<MapleSquadType, MapleSquad>();
    private static Properties initialProp;
    private Properties props = new Properties();
    private int expRate;
    private int mesoRate;
    private int dropRate;
    private static int RespawnRate;
    private int bossDropRate;
    public static final int channelLoad = 50;
    private String serverMessage;
    private static byte channels = 2;
    private boolean allDrop;
    private boolean moreThanOne;
    private int explorerLC;
    private int cygnusLC;
    private boolean multiLevel;
    private boolean CStoFM;
    private boolean MTStoFM;
    public boolean eventOn = false;
    public int eventMap;
    private Collection<FakeCharacter> clones = new LinkedList<FakeCharacter>();
    private int PvPis;

    private ChannelServer(String key) {
        mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")));
        this.key = key;
    }

    public static WorldRegistry getWorldRegistry() {
        return worldRegistry;
    }

    public int getInstanceId() {
        return instanceId;
    }

    public void addInstanceId() {
        instanceId++;
    }

        public void addClone(FakeCharacter fc) {
        clones.add(fc);
    }

    public void removeClone(FakeCharacter fc) {
        clones.remove(fc);
    }

    public Collection<FakeCharacter> getAllClones() {
        return clones;
    }

    public int PvPis() {
        if (PvPis > 0 && PvPis < 21 || PvPis >= 100000000 && PvPis <=990000000) {
            return PvPis;
        } else {
            return 4;
        }
    }

    public void reconnectWorld() {
        try {
            wci.isAvailable();
        } catch (RemoteException ex) {
            synchronized (worldReady) {
                worldReady = false;
            }
            synchronized (cwi) {
                synchronized (worldReady) {
                    if (worldReady) {
                        return;
                    }
                }
                System.out.println("Reconnecting to world server");
                synchronized (wci) {
                    try {
                        Registry registry = LocateRegistry.getRegistry(initialProp.getProperty("SilentSource.server.channel.net.interface"), Registry.REGISTRY_PORT, new SslRMIClientSocketFactory());
                        worldRegistry = (WorldRegistry) registry.lookup("WorldRegistry");
                        cwi = new ChannelWorldInterfaceImpl(this);
                        wci = worldRegistry.registerChannelServer(key, cwi);
                        props = wci.getGameProperties();
                        channels = Byte.parseByte(props.getProperty("SilentSource.server.channel.count"));
                        expRate = Integer.parseInt(props.getProperty("SilentSource.server.world.exp"));
                        mesoRate = Integer.parseInt(props.getProperty("SilentSource.server.world.meso"));
                        dropRate = Integer.parseInt(props.getProperty("SilentSource.server.world.drop"));
                        RespawnRate = Integer.parseInt(props.getProperty("SilentSource.server.world.RespawnRate"));
                        bossDropRate = Integer.parseInt(props.getProperty("SilentSource.server.world.bossdrop"));
                        NonGmsCommands = Boolean.parseBoolean(props.getProperty("SilentSource.world.NonGmsCommands", "true"));
                        serverMessage = props.getProperty("SilentSource.server.world.serverMessage");
                        eventSM = new EventScriptManager(this, props.getProperty("SilentSource.server.channel.events").split(","));
                        allDrop = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.allDrop", "false"));
                        moreThanOne = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.moreThanOne", "false"));
                        explorerLC = Integer.parseInt(props.getProperty("SilentSource.server.world.explorerLC"));
                        cygnusLC = Integer.parseInt(props.getProperty("SilentSource.server.world.cygnusLC"));
                        multiLevel = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.multiLevel", "false"));
                        CStoFM = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.CStoFM", "false"));
                        MTStoFM = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.MTStoFM", "false"));
                        PvPis = Integer.parseInt(props.getProperty("SilentSource.server.world.PvPis", "4"));
                        Properties dbProp = new Properties();
                        FileReader fr = new FileReader("db.properties");
                        dbProp.load(fr);
                        fr.close();
                        DatabaseConnection.initialize(dbProp);
                        DatabaseConnection.getConnection();
                        wci.serverReady();
                    } catch (Exception e) {
                    }
                    worldReady = true;
                }
            }
            synchronized (worldReady) {
                worldReady.notifyAll();
            }
        }
    }

    @Override
    public void run() {
        try {
            cwi = new ChannelWorldInterfaceImpl(this);
            wci = worldRegistry.registerChannelServer(key, cwi);
            props = wci.getGameProperties();
            channels = Byte.parseByte(props.getProperty("SilentSource.server.channel.count"));
            expRate = Integer.parseInt(props.getProperty("SilentSource.server.world.exp"));
            mesoRate = Integer.parseInt(props.getProperty("SilentSource.server.world.meso"));
            dropRate = Integer.parseInt(props.getProperty("SilentSource.server.world.drop"));
            RespawnRate = Integer.parseInt(props.getProperty("SilentSource.server.world.RespawnRate"));
            NonGmsCommands = Boolean.parseBoolean(props.getProperty("SilentSource.world.NonGmsCommands", "true"));
            bossDropRate = Integer.parseInt(props.getProperty("SilentSource.server.world.bossdrop"));
            serverMessage = props.getProperty("SilentSource.server.world.serverMessage");
            eventSM = new EventScriptManager(this, props.getProperty("SilentSource.server.channel.events").split(","));
            allDrop = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.allDrop", "false"));
            moreThanOne = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.moreThanOne", "false"));
            explorerLC = Integer.parseInt(props.getProperty("SilentSource.server.world.explorerLC"));
            cygnusLC = Integer.parseInt(props.getProperty("SilentSource.server.world.cygnusLC"));
            multiLevel = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.multiLevel", "false"));
            CStoFM = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.CStoFM", "false"));
            MTStoFM = Boolean.parseBoolean(props.getProperty("SilentSource.server.world.MTStoFM", "false"));
            PvPis = Integer.parseInt(props.getProperty("SilentSource.server.world.PvPis", "4"));
            Properties dbProp = new Properties();
            FileReader fileReader = new FileReader("db.properties");
            dbProp.load(fileReader);
            fileReader.close();
            DatabaseConnection.initialize(dbProp);
            Connection c = DatabaseConnection.getConnection();
            PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
            ps.executeUpdate();
            ps.close();
            ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
            ps.executeUpdate();
            ps.close();
            port = 7575 + this.channel - 1;
            ip = props.getProperty("SilentSource.server.channel.net.interface") + ":" + port;
            IoBuffer.setUseDirectBuffer(false);
            IoBuffer.setAllocator(new SimpleBufferAllocator());
            acceptor = new NioSocketAcceptor();
            TimerManager tMan = TimerManager.getInstance();
            tMan.start();
            tMan.register(new respawnMaps(), 10000);
            acceptor.setHandler(new MapleServerHandler(PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER), channel));
            acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
            acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
            acceptor.bind(new InetSocketAddress(port));
            ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
            System.out.println("Channel " + getChannel() + ": Listening on port " + port);
            wci.serverReady();
            eventSM.init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void shutdown() {
        shutdown = true;
        boolean error = true;
        while (error) {
            try {
                for (ChannelServer ch : getAllInstances()) {
                    for (int i = 910000001; i <= 910000022; i++) {
                        for (MapleMapObject obj : ch.getMapFactory().getMap(i).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.HIRED_MERCHANT))) {
                            HiredMerchant hm = (HiredMerchant) obj;
                            hm.closeShop(true);
                        }
                    }
                    for (MapleCharacter mc : ch.getPlayerStorage().getAllCharacters()) {
                        mc.saveToDB(true);
                    }
                }
            } catch (Exception e) {
                error = true;
            }
        }
        finishedShutdown = true;
        wci = null;
        cwi = null;
    }  

    public void unbind() {
        acceptor.unbind();
    }

    public boolean hasFinishedShutdown() {
        return finishedShutdown;
    }

    public MapleMapFactory getMapFactory() {
        return mapFactory;
    }

    private static ChannelServer newInstance(String key) throws InstanceAlreadyExistsException, MalformedObjectNameException {
        ChannelServer instance = new ChannelServer(key);
        pendingInstances.put(key, instance);
        return instance;
    }

    public static ChannelServer getInstance(int channel) {
        return instances.get(channel);
    }

    public void addPlayer(MapleCharacter chr) {
        players.registerPlayer(chr);
        chr.getClient().getSession().write(MaplePacketCreator.serverMessage(serverMessage));
    }

    public IPlayerStorage getPlayerStorage() {
        return players;
    }

    public void removePlayer(MapleCharacter chr) {
        players.deregisterPlayer(chr);
    }

    public int getConnectedClients() {
        return players.getAllCharacters().size();
    }

    public int getChannel() {
        return channel;
    }

    public void setChannel(int channel) {
        if (pendingInstances.containsKey(key)) {
            pendingInstances.remove(key);
        }
        if (instances.containsKey(channel)) {
            instances.remove(channel);
        }
        instances.put(channel, this);
        this.channel = channel;
        this.mapFactory.setChannel(channel);
    }

    public static Collection<ChannelServer> getAllInstances() {
        return Collections.unmodifiableCollection(instances.values());
    }

    public String getIP() {
        return ip;
    }

    public String getIP(int channel) {
        try {
            return getWorldInterface().getIP(channel);
        } catch (RemoteException e) {
            System.out.println("Lost connection to world server " + e);
            throw new RuntimeException("Lost connection to world server");
        }
    }

    public WorldChannelInterface getWorldInterface() {
        synchronized (worldReady) {
            while (!worldReady) {
                try {
                    worldReady.wait();
                } catch (InterruptedException e) {
                }
            }
        }
        return wci;
    }

    public boolean isShutdown() {
        return shutdown;
    }

    public void shutdown(int time) {
        TimerManager.getInstance().schedule(new ShutdownServer(getChannel()), time);
    }

    public void shutdownWorld(int time) {
        try {
            getWorldInterface().shutdown(time);
        } catch (RemoteException e) {
            reconnectWorld();
        }
    }

    public MapleGuild getGuild(MapleGuildCharacter mgc) {
        int gid = mgc.getGuildId();
        MapleGuild g = null;
        try {
            g = this.getWorldInterface().getGuild(gid, mgc);
        } catch (RemoteException re) {
            System.out.println("RemoteException while fetching MapleGuild. " + re);
            return null;
        }
        if (gsStore.get(gid) == null) {
            gsStore.put(gid, new MapleGuildSummary(g));
        }
        return g;
    }

    public MapleGuildSummary getGuildSummary(int gid) {
        if (gsStore.containsKey(gid)) {
            return gsStore.get(gid);
        } else {
            try {
                MapleGuild g = this.getWorldInterface().getGuild(gid, null);
                if (g != null) {
                    gsStore.put(gid, new MapleGuildSummary(g));
                }
                return gsStore.get(gid);
            } catch (RemoteException re) {
                System.out.println("RemoteException while fetching GuildSummary. " + re);
                return null;
            }
        }
    }

    public void updateGuildSummary(int gid, MapleGuildSummary mgs) {
        gsStore.put(gid, mgs);
    }

    public void reloadGuildSummary() {
        try {
            MapleGuild g;
            for (int i : gsStore.keySet()) {
                g = this.getWorldInterface().getGuild(i, null);
                if (g != null) {
                    gsStore.put(i, new MapleGuildSummary(g));
                } else {
                    gsStore.remove(i);
                }
            }
        } catch (RemoteException re) {
            System.out.println("RemoteException while reloading GuildSummary." + re);
        }
    }

    public static void main(String args[]) throws FileNotFoundException, IOException, NotBoundException, InstanceAlreadyExistsException, MalformedObjectNameException {
        ServerMode.setServerMode(Mode.CHANNEL);
        Registry registry = LocateRegistry.getRegistry("localhost", Registry.REGISTRY_PORT, new SslRMIClientSocketFactory());
        worldRegistry = (WorldRegistry) registry.lookup("WorldRegistry");
        for (int i = 0; i < channels; i++) {
            newInstance("release" + (i + 1)).run();
        }
        DatabaseConnection.getConnection();
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                for (ChannelServer channel : getAllInstances()) {
                    for (int i = 910000001; i <= 910000022; i++) {
                        for (MapleMapObject obj : channel.getMapFactory().getMap(i).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.HIRED_MERCHANT))) {
                            HiredMerchant hm = (HiredMerchant) obj;
                            hm.closeShop(true);
                        }
                    }
                    for (MapleCharacter mc : channel.getPlayerStorage().getAllCharacters()) {
                        mc.saveToDB(true);
                    }
                }
            }
        });
    }

    public void broadcastGMPacket(MaplePacket data) {
        for (MapleCharacter chr : players.getAllCharacters()) {
            if (chr.isGM()) {
                chr.getClient().getSession().write(data);
            }
        }
    }

    public void broadcastPacket(MaplePacket data) {
        for (MapleCharacter chr : players.getAllCharacters()) {
            chr.getClient().getSession().write(data);
        }
    }

    public void yellowWorldMessage(String msg) {
        for (MapleCharacter mc : getPlayerStorage().getAllCharacters()) {
            mc.getClient().getSession().write(MaplePacketCreator.sendYellowTip(msg));
        }
    }

    public void worldMessage(String msg) {
        for (MapleCharacter mc : getPlayerStorage().getAllCharacters()) {
            mc.dropMessage(msg);
        }
    }

    public List<MapleCharacter> getPartyMembers(MapleParty party) {
        List<MapleCharacter> partym = new ArrayList<MapleCharacter>(8);
        for (MaplePartyCharacter partychar : party.getMembers()) {
            if (partychar.getChannel() == getChannel()) {
                MapleCharacter chr = getPlayerStorage().getCharacterByName(partychar.getName());
                if (chr != null) {
                    partym.add(chr);
                }
            }
        }
        return partym;
    }

    public class respawnMaps implements Runnable {

        @Override
        public void run() {
            for (Entry<Integer, MapleMap> map : mapFactory.getMaps().entrySet()) {
                map.getValue().respawn();
            }
        }
    }

    public static MapleCharacter getCharacterFromAllServers(int id) {
        for (ChannelServer cserv_ : ChannelServer.getAllInstances()) {
            MapleCharacter ret = cserv_.getPlayerStorage().getCharacterById(id);
            if (ret != null) {
                return ret;
            }
        }
        return null;
    }

    public MapleSquad getMapleSquad(MapleSquadType type) {
        return mapleSquads.get(type);
    }

    public boolean addMapleSquad(MapleSquad squad, MapleSquadType type) {
        if (mapleSquads.get(type) == null) {
            mapleSquads.remove(type);
            mapleSquads.put(type, squad);
            return true;
        } else {
            return false;
        }
    }
//
//    public void weddingMessage(String husband, String wife) {
//        for (ChannelServer cserv : ChannelServer.getAllInstances()) {
//            for (MapleCharacter mc : cserv.getPlayerStorage().getAllCharacters())
//                mc.message(husband+"'s and " + wife + "'s marriage will start in "+ channel +" at the Cathedral.");
//        }
//    }

    public boolean allowMTStoFM() {
        return MTStoFM;
    }
	
    public int getExpRate() {
        return expRate;
    }

    public void setExpRate(int newExp) {
        this.expRate = newExp;
    }

    public int getMesoRate() {
        return mesoRate;
    }

    public void setMesoRate(int newMeso) {
        this.mesoRate = newMeso;
    }

    public int getDropRate() {
        return dropRate;
    }

    public void setDropRate(int newDrop) {
        this.dropRate = newDrop;
    }

    public int getBossDropRate() {
        return bossDropRate;
    }

    public void setBossDropRate(int newBossDrop) {
        this.bossDropRate = newBossDrop;
    }

    public String getServerMessage() {
        return serverMessage;
    }

    public void setServerMessage(String newMessage) {
        serverMessage = newMessage;
        broadcastPacket(MaplePacketCreator.serverMessage(serverMessage));
    }

    public EventScriptManager getEventSM() {
        return eventSM;
    }

    public void reloadEvents() {
        eventSM.cancel();
        eventSM = new EventScriptManager(this, props.getProperty("SilentSource.server.channel.events").split(","));
        eventSM.init();
    }

    public boolean allowAllDrop() {
        return allDrop;
    }

    public static int RespawnRate() {
        return RespawnRate;
    }

    public boolean allowMoreThanOne() {
        return moreThanOne;
    }

    public int getExplorerLC() {
        return explorerLC;
    }

    public int getCygnusLC() {
        return cygnusLC;
    }

    public boolean allowMultiLevel() {
        return multiLevel;
    }

    public boolean allowCStoFM() {
        return CStoFM;
    }
}
 
Back
Top