    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.modloader;
    014
    015import net.minecraft.entity.player.EntityPlayer;
    016import net.minecraft.network.INetworkManager;
    017import net.minecraft.network.NetLoginHandler;
    018import net.minecraft.network.packet.NetHandler;
    019import net.minecraft.network.packet.Packet1Login;
    020import net.minecraft.server.MinecraftServer;
    021import cpw.mods.fml.common.network.IConnectionHandler;
    022import cpw.mods.fml.common.network.Player;
    023
    024public class ModLoaderConnectionHandler implements IConnectionHandler
    025{
    026    private BaseModProxy mod;
    027
    028    public ModLoaderConnectionHandler(BaseModProxy mod)
    029    {
    030        this.mod = mod;
    031    }
    032
    033    @Override
    034    public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
    035    {
    036        mod.onClientLogin((EntityPlayer)player);
    037    }
    038
    039    @Override
    040    public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
    041    {
    042        return null;
    043    }
    044
    045    @Override
    046    public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
    047    {
    048        ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
    049    }
    050
    051    @Override
    052    public void connectionClosed(INetworkManager manager)
    053    {
    054        if (ModLoaderHelper.sidedHelper==null || !ModLoaderHelper.sidedHelper.clientConnectionClosed(manager, mod))
    055        {
    056            mod.serverDisconnect();
    057            mod.onClientLogout(manager);
    058        }
    059    }
    060
    061    @Override
    062    public void clientLoggedIn(NetHandler nh, INetworkManager manager, Packet1Login login)
    063    {
    064        mod.serverConnect(nh);
    065    }
    066
    067    @Override
    068    public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
    069    {
    070        ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
    071    }
    072
    073}