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