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 #beginServerLoading(MinecraftServer)} called from 039 * {@link DedicatedServer} 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 public MinecraftServer getServer() 102 { 103 return server; 104 } 105 106 /** 107 * @return the instance 108 */ 109 public static FMLServerHandler instance() 110 { 111 return INSTANCE; 112 } 113 114 /* (non-Javadoc) 115 * @see cpw.mods.fml.common.IFMLSidedHandler#getAdditionalBrandingInformation() 116 */ 117 @Override 118 public List<String> getAdditionalBrandingInformation() 119 { 120 return null; 121 } 122 123 /* (non-Javadoc) 124 * @see cpw.mods.fml.common.IFMLSidedHandler#getSide() 125 */ 126 @Override 127 public Side getSide() 128 { 129 return Side.SERVER; 130 } 131 132 @Override 133 public void showGuiScreen(Object clientGuiElement) 134 { 135 136 } 137 138 @Override 139 public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet) 140 { 141 // NOOP 142 return null; 143 } 144 145 @Override 146 public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket) 147 { 148 // NOOP 149 } 150 @Override 151 public void sendPacket(Packet packet) 152 { 153 throw new RuntimeException("You cannot send a bare packet without a target on the server!"); 154 } 155 @Override 156 public void displayMissingMods(ModMissingPacket modMissingPacket) 157 { 158 // NOOP on server 159 } 160 @Override 161 public void handleTinyPacket(NetHandler handler, Packet131MapData mapData) 162 { 163 // NOOP on server 164 } 165 @Override 166 public void setClientCompatibilityLevel(byte compatibilityLevel) 167 { 168 // NOOP on server 169 } 170 @Override 171 public byte getClientCompatibilityLevel() 172 { 173 return 0; 174 } 175 }