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