001/* 002 * The FML Forge Mod Loader suite. Copyright (C) 2012 cpw 003 * 004 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free 005 * Software Foundation; either version 2.1 of the License, or any later version. 006 * 007 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 008 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 009 * 010 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 011 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 012 */ 013package cpw.mods.fml.server; 014 015import java.util.List; 016 017import com.google.common.collect.ImmutableList; 018import com.google.common.collect.MapDifference; 019 020import net.minecraft.entity.Entity; 021import net.minecraft.network.INetworkManager; 022import net.minecraft.network.packet.NetHandler; 023import net.minecraft.network.packet.Packet; 024import net.minecraft.network.packet.Packet131MapData; 025import net.minecraft.server.MinecraftServer; 026import net.minecraft.world.World; 027import cpw.mods.fml.common.FMLCommonHandler; 028import cpw.mods.fml.common.IFMLSidedHandler; 029import cpw.mods.fml.common.Loader; 030import cpw.mods.fml.common.ObfuscationReflectionHelper; 031import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; 032import cpw.mods.fml.common.network.EntitySpawnPacket; 033import cpw.mods.fml.common.network.ModMissingPacket; 034import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; 035import cpw.mods.fml.common.registry.GameData; 036import cpw.mods.fml.common.registry.GameRegistry; 037import cpw.mods.fml.common.registry.ItemData; 038import cpw.mods.fml.common.registry.LanguageRegistry; 039import cpw.mods.fml.relauncher.Side; 040 041/** 042 * Handles primary communication from hooked code into the system 043 * 044 * The FML entry point is {@link #beginServerLoading(MinecraftServer)} called from 045 * {@link net.minecraft.server.dedicated.DedicatedServer} 046 * 047 * Obfuscated code should focus on this class and other members of the "server" 048 * (or "client") code 049 * 050 * The actual mod loading is handled at arms length by {@link Loader} 051 * 052 * It is expected that a similar class will exist for each target environment: 053 * Bukkit and Client side. 054 * 055 * It should not be directly modified. 056 * 057 * @author cpw 058 * 059 */ 060public class FMLServerHandler implements IFMLSidedHandler 061{ 062 /** 063 * The singleton 064 */ 065 private static final FMLServerHandler INSTANCE = new FMLServerHandler(); 066 067 /** 068 * A reference to the server itself 069 */ 070 private MinecraftServer server; 071 072 private FMLServerHandler() 073 { 074 FMLCommonHandler.instance().beginLoading(this); 075 } 076 /** 077 * Called to start the whole game off from 078 * {@link MinecraftServer#startServer} 079 * 080 * @param minecraftServer 081 */ 082 public void beginServerLoading(MinecraftServer minecraftServer) 083 { 084 server = minecraftServer; 085 Loader.instance().loadMods(); 086 } 087 088 /** 089 * Called a bit later on during server initialization to finish loading mods 090 */ 091 public void finishServerLoading() 092 { 093 Loader.instance().initializeMods(); 094 LanguageRegistry.reloadLanguageTable(); 095 GameData.initializeServerGate(1); 096 } 097 098 @Override 099 public void haltGame(String message, Throwable exception) 100 { 101 throw new RuntimeException(message, exception); 102 } 103 104 /** 105 * Get the server instance 106 */ 107 public MinecraftServer getServer() 108 { 109 return server; 110 } 111 112 /** 113 * @return the instance 114 */ 115 public static FMLServerHandler instance() 116 { 117 return INSTANCE; 118 } 119 120 /* (non-Javadoc) 121 * @see cpw.mods.fml.common.IFMLSidedHandler#getAdditionalBrandingInformation() 122 */ 123 @Override 124 public List<String> getAdditionalBrandingInformation() 125 { 126 return ImmutableList.<String>of(); 127 } 128 129 /* (non-Javadoc) 130 * @see cpw.mods.fml.common.IFMLSidedHandler#getSide() 131 */ 132 @Override 133 public Side getSide() 134 { 135 return Side.SERVER; 136 } 137 138 @Override 139 public void showGuiScreen(Object clientGuiElement) 140 { 141 142 } 143 144 @Override 145 public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet) 146 { 147 // NOOP 148 return null; 149 } 150 151 @Override 152 public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket) 153 { 154 // NOOP 155 } 156 @Override 157 public void sendPacket(Packet packet) 158 { 159 throw new RuntimeException("You cannot send a bare packet without a target on the server!"); 160 } 161 @Override 162 public void displayMissingMods(ModMissingPacket modMissingPacket) 163 { 164 // NOOP on server 165 } 166 @Override 167 public void handleTinyPacket(NetHandler handler, Packet131MapData mapData) 168 { 169 // NOOP on server 170 } 171 @Override 172 public void setClientCompatibilityLevel(byte compatibilityLevel) 173 { 174 // NOOP on server 175 } 176 @Override 177 public byte getClientCompatibilityLevel() 178 { 179 return 0; 180 } 181 182 @Override 183 public boolean shouldServerShouldBeKilledQuietly() 184 { 185 return false; 186 } 187 @Override 188 public void disconnectIDMismatch(MapDifference<Integer, ItemData> s, NetHandler handler, INetworkManager mgr) 189 { 190 191 } 192}