    001package cpw.mods.fml.common.modloader;
    002
    003import net.minecraft.entity.player.EntityPlayer;
    004import net.minecraft.network.INetworkManager;
    005import net.minecraft.network.NetLoginHandler;
    006import net.minecraft.network.packet.NetHandler;
    007import net.minecraft.network.packet.Packet1Login;
    008import net.minecraft.server.MinecraftServer;
    009import cpw.mods.fml.common.network.IConnectionHandler;
    010import cpw.mods.fml.common.network.Player;
    011
    012public class ModLoaderConnectionHandler implements IConnectionHandler
    013{
    014    private BaseModProxy mod;
    015
    016    public ModLoaderConnectionHandler(BaseModProxy mod)
    017    {
    018        this.mod = mod;
    019    }
    020
    021    @Override
    022    public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
    023    {
    024        mod.onClientLogin((EntityPlayer)player);
    025    }
    026
    027    @Override
    028    public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
    029    {
    030        return null;
    031    }
    032
    033    @Override
    034    public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
    035    {
    036        ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
    037    }
    038
    039    @Override
    040    public void connectionClosed(INetworkManager manager)
    041    {
    042        if (ModLoaderHelper.sidedHelper==null || !ModLoaderHelper.sidedHelper.clientConnectionClosed(manager, mod))
    043        {
    044            mod.serverDisconnect();
    045            mod.onClientLogout(manager);
    046        }
    047    }
    048
    049    @Override
    050    public void clientLoggedIn(NetHandler nh, INetworkManager manager, Packet1Login login)
    051    {
    052        mod.serverConnect(nh);
    053    }
    054
    055    @Override
    056    public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
    057    {
    058        ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
    059    }
    060
    061}