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