JDK and Channel Server

Results 1 to 6 of 6
  1. #1
    Novice HowtoCode is offline
    MemberRank
    Feb 2015 Join Date
    2Posts

    JDK and Channel Server

    Anyone know whats up with my channel server CMD?
    Spoiler:




    I see nothing wrong with my JDK(7) files, nor my channelserver.java. When I'm on log-in screen my client just crashes after i type in account information.

    Code:
    /*
     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 communication.channel;
    
    
    import java.io.File;
    import java.io.FileNotFoundException;
    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.util.Collection;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import javax.management.InstanceAlreadyExistsException;
    import javax.management.MalformedObjectNameException;
    import javax.rmi.ssl.SslRMIClientSocketFactory;
    import character.MapleCharacter;
    import java.util.ArrayList;
    import java.util.Map.Entry;
    import communication.world.MapleParty;
    import communication.DatabaseConnection;
    import communication.MapleServerHandler;
    import communication.PacketProcessor;
    import communication.ServerMode;
    import communication.ServerMode.Mode;
    import communication.mina.MapleCodecFactory;
    import communication.world.MaplePartyCharacter;
    import communication.world.guild.MapleGuild;
    import communication.world.guild.MapleGuildCharacter;
    import communication.world.guild.MapleGuildSummary;
    import communication.world.WorldChannelInterface;
    import communication.world.WorldRegistry;
    import provider.MapleDataProviderInfo;
    import scripting.event.EventScriptManager;
    import communication.ShutdownServer;
    import communication.TimerManager;
    import server.MapleMapData;
    import packet.MaplePacketCreator;
    import org.apache.mina.filter.codec.ProtocolCodecFilter;
    import server.CashItemData;
    import constants.ServerConstants;
    import java.util.ConcurrentModificationException;
    import java.util.concurrent.ScheduledFuture;
    import org.apache.mina.common.ByteBuffer;
    import org.apache.mina.common.IoAcceptor;
    import org.apache.mina.common.SimpleByteBufferAllocator;
    import org.apache.mina.transport.socket.nio.SocketAcceptor;
    import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
    import server.maps.MapleMap;
    
    
    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 MapleMapData mapFactory;
        private EventScriptManager eventSM;
        private static Map<Integer, ChannelServer> instances = new HashMap<>();
        private static Map<String, ChannelServer> pendingInstances = new HashMap<>();
        private Map<Integer, MapleGuildSummary> gsStore = new HashMap<>();
        private Boolean worldReady = true;
        private int instanceId = 0;
        private static int world = 0;
        private int itemStatMultiplier = ServerConstants.ITEM_STAT_MULTIPLIER;
        private int godlyItemRate = ServerConstants.GODLY_ITEMS;
        public int eventMap = 0;
        public boolean godlyItems = ServerConstants.GODLY_ITEMS_ENABLE;
        public static boolean autoMsgTriggered = false;
        public boolean eventOn = false;
        public boolean eventOpen = false;
        public static long serverStartTime;
        public static long lastEventTime;
        public ScheduledFuture<?> respawnTimer = null;
    
    
        private ChannelServer(String key) {
            mapFactory = new MapleMapData(MapleDataProviderInfo.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderInfo.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 reconnectWorld() {
            try {
                wci.isAvailable();
            } catch (RemoteException ex) {
                System.out.println("Reconnecting to world server on channel " + this.channel);
                synchronized (worldReady) {
                    worldReady = false;
                }
                synchronized (cwi) {
                    synchronized (worldReady) {
                        if (worldReady) {
                            return;
                        }
                    }
                    synchronized (wci) {
                        try {
                            Registry registry = LocateRegistry.getRegistry(ServerConstants.HOST, Registry.REGISTRY_PORT, new SslRMIClientSocketFactory());
                            worldRegistry = (WorldRegistry) registry.lookup("WorldRegistry");
                            cwi = new ChannelWorldInterfaceImpl(this, world);
                            wci = worldRegistry.registerChannelServer(key, cwi, world);
                            DatabaseConnection.getConnection();
                            wci.serverReady(world);
                        } catch (RemoteException | NotBoundException e) {
                            e.printStackTrace();
                        }
                        worldReady = true;
                    }
                }
                synchronized (worldReady) {
                    worldReady.notifyAll();
                }
                new Exception().printStackTrace();
            }
        }
    
    
        @Override
        public void run() {
            try {
                cwi = new ChannelWorldInterfaceImpl(this, world);
                wci = worldRegistry.registerChannelServer(key, cwi, world);
                eventSM = new EventScriptManager(this, ServerConstants.EVENTS.split(" "));
                port = 7575 + this.channel;
                ip = ServerConstants.HOST + ":" + port;
                ByteBuffer.setUseDirectBuffers(false);
                ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
                acceptor = new SocketAcceptor();
                SocketAcceptorConfig cfg = new SocketAcceptorConfig();
                cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
                cfg.getSessionConfig().setTcpNoDelay(true);
                TimerManager tMan = TimerManager.getInstance();
                tMan.start();
                CashItemData.getInstance();
                new Purger().run();
                new Spawner().run();
                MapleServerHandler serverHandler = new MapleServerHandler(PacketProcessor.getProcessor(PacketProcessor.Mode.CHANNELSERVER), channel);
                acceptor.bind(new InetSocketAddress(port), serverHandler, cfg);
                System.out.println("Channel " + getChannel() + ": Listening on port " + port);
                System.out.println("[Channel Server initialized in " + ((System.currentTimeMillis() - ServerConstants.LOAD_TIME) / 1000) + " seconds]");
                wci.serverReady(world);
                eventSM.init();
                serverStartTime = System.currentTimeMillis();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    
        public void shutdown() {
            shutdown = true;
            boolean error = true;
            while (error) {
                try {
                    for (MapleCharacter chr : players.getAllCharacters()) {
                        synchronized (chr) {
                            if (chr.getHiredMerchant().isOpen()) {
                                chr.getHiredMerchant().saveItems();
                            }
                            chr.getClient().disconnect("Disconnect Reason: Server restart");
                            System.out.println("[Disconnect]Disconnected, Reason: Server Restart");
                        }
                        error = false;
                    }
                } catch (Exception e) {
                    error = true;
                }
            }
            finishedShutdown = true;
            wci = null;
            cwi = null;
        }
    
    
        public void shutdownWorld(int time) {
            try {
                getWorldInterface().shutdown(time);
            } catch (RemoteException e) {
                reconnectWorld();
            }
        }
    
    
        public void unbind() {
            acceptor.unbindAll();
        }
    
    
        public void broadcastSMega(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                if (chr.wantsToViewSmega()) {
                    chr.getClient().getSession().write(data);
                }
            }
        }
    
    
        public void broadcastDonorNotice(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                if (chr.wantsToViewDonorNotice()) {
                    chr.getClient().getSession().write(data);
                }
            }
        }
    
    
        public boolean hasFinishedShutdown() {
            return finishedShutdown;
        }
    
    
        public MapleMapData 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(ServerConstants.SERVER_MESSAGE));
        }
    
    
        public IPlayerStorage getPlayerStorage() {
            return players;
        }
    
    
        public void removePlayer(MapleCharacter chr) {
            players.deregisterPlayer(chr);
        }
    
    
        public int getConnectedClients() {
            return players.getAllCharacters().size();
        }
    
    
        public void setServerMessage(String newMessage) {
            ServerConstants.SERVER_MESSAGE = newMessage;
            broadcastPacket(MaplePacketCreator.serverMessage(ServerConstants.SERVER_MESSAGE));
        }
    
    
        public void broadcastPacket(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                chr.getClient().getSession().write(data);
            }
        }
    
    
        public void broadcastRedPacket(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                if (chr.getRBTeam() == 0) {
                    chr.getClient().getSession().write(data);
                }
            }
        }
    
    
        public void broadcastBluePacket(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                if (chr.getRBTeam() == 1) {
                    chr.getClient().getSession().write(data);
                }
            }
        }
    
    
        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);
                reconnectWorld();
                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(), getWorld()), time);
        }
    
    
        public EventScriptManager getEventSM() {
            return eventSM;
        }
    
    
        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);
                reconnectWorld();
                re.printStackTrace();
                return null;
            }
            if (gsStore.get(gid) == null) {
                gsStore.put(gid, new MapleGuildSummary(g));
            }
            return g;
        }
    
    
        public void saveAll() {
            for (MapleCharacter chr : players.getAllCharacters()) {
                chr.saveToDB(true);
            }
        }
    
    
        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) {
                    reconnectWorld();
                    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);
                this.reconnectWorld();
            }
        }
    
    
        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 < ServerConstants.CHANNEL_NUMBER; i++) {
                newInstance("release" + (i + 1)).run();
            }
        }
    
    
        public boolean isGodlyItems() {
            return godlyItems;
        }
    
    
        public void setGodlyItems(boolean Cool) {
            this.godlyItems = ServerConstants.GODLY_ITEMS_ENABLE;
        }
    
    
        public int getItemMultiplier() {
            return itemStatMultiplier;
        }
    
    
        public void setItemMultiplier(Short cool) {
            this.itemStatMultiplier = cool;
        }
    
    
        public int getGodlyItemRate() {
            return godlyItemRate;
        }
    
    
        public void setGodlyItemRate(Short godly) {
            this.godlyItemRate = godly;
        }
    
    
        public void broadcastGMPacket(byte[] data) {
            for (MapleCharacter chr : players.getAllCharacters()) {
                if (chr.isGM()) {
                    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, int map) {
            List<MapleCharacter> partym = new ArrayList<>(6);
            for (MaplePartyCharacter partychar : party.getMembers()) {
                if (partychar.getChannel() == getChannel()) {
                    if (map > 0 && partychar.getMapid() != map) {
                        continue;
                    }
                    MapleCharacter chr = getPlayerStorage().getCharacterByName(partychar.getName());
                    if (chr != null) {
                        partym.add(chr);
                    }
                }
            }
            return partym;
        }
    
    
        public class Spawner implements Runnable {
    
    
            public void run() {
                try {
                    for (Entry<Integer, MapleMap> map : mapFactory.getMaps().entrySet()) {
                        map.getValue().respawn();
                    }
                } catch (ConcurrentModificationException e) {
                    System.out.println("ConcurrentModificationException in spawner");
                    e.printStackTrace();
                } finally {
                    respawnTimer = TimerManager.getInstance().schedule(new Spawner(), 10000);
                }
            }
        }
    
    
        public class Purger implements Runnable {
    
    
            public void run() {
                try {
                    TimerManager.getInstance().purgeTM();
                } catch (Exception e) {
                    System.out.println("Purged.");
                    e.printStackTrace();
                } finally {
                    TimerManager.getInstance().schedule(new Purger(), 180000);
                }
            }
        }
    
    
        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 static MapleCharacter getCharacterFromAllServers(String id) {
            for (ChannelServer cserv_ : ChannelServer.getAllInstances()) {
                MapleCharacter ret = cserv_.getPlayerStorage().getCharacterByName(id);
                if (ret != null) {
                    return ret;
                }
            }
            return null;
        }
    
    
        public int getWorld() {
            return world;
        }
    
    
        public void reloadEvents() {
            eventSM.cancel();
            eventSM = new EventScriptManager(this, ServerConstants.EVENTS.split(" "));
            eventSM.init();
        }
    }
    Last edited by HowtoCode; 22-02-15 at 02:37 PM.


  2. #2
    Enthusiast Navi is offline
    MemberRank
    Sep 2014 Join Date
    38Posts

    Re: JDK and Channel Server

    You sure you have Java 7? I think Nashorn is the scripting engine for Java 8. I'm not really familiar with Java 8, but I know there were changes to importPackage which is why the exception was triggered:

    see if this is of any help: http://forum.ragezone.com/f427/tweak...a-8-a-1008662/

  3. #3
    Novice HowtoCode is offline
    MemberRank
    Feb 2015 Join Date
    2Posts

    Re: JDK and Channel Server

    Quote Originally Posted by Navi View Post
    You sure you have Java 7? I think Nashorn is the scripting engine for Java 8. I'm not really familiar with Java 8, but I know there were changes to importPackage which is why the exception was triggered:

    see if this is of any help: http://forum.ragezone.com/f427/tweak...a-8-a-1008662/
    Ya man, I have JDK 7 and Netbeans 7.4. Now i got this problem thu, if I download java8 won't it cause more errors?

    Last edited by HowtoCode; 22-02-15 at 07:49 PM.

  4. #4
    Enthusiast Kittyjessika is offline
    MemberRank
    Feb 2015 Join Date
    36Posts

    Re: JDK and Channel Server

    I know that having the standard java8 (not talking about your JDK) caused a lot of issues for me. I had to remove anything java related from my computer and only reinstall java7

    As for the new error, is your path properly set in windows variables?

  5. #5
    C++ TheIceBreaker is offline
    MemberRank
    Jan 2013 Join Date
    SwordArtOnlineLocation
    598Posts

    Re: JDK and Channel Server

    uninstall ur current JDK/JRE in control panel

    (C:) > windows > system 32 > delete all Java files

    reinstall Java

  6. #6
    Account Upgraded | Title Enabled! jon5477 is offline
    MemberRank
    Aug 2010 Join Date
    USALocation
    414Posts

    Re: JDK and Channel Server

    Since Java 8 and JSR-223, Mozilla Rhino (The JavaScript engine in Java6/7) has been replaced with Oracle Nashorn (Java 8). You have 2 options right now, either stick with Java 7 or switch to Java 8 and replace the JS engine. If you want to switch to Java 8, I have a small guide which you might find useful in your migration over to Java 8: http://forum.ragezone.com/f428/odinm...fixes-1055778/



Advertisement