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 019 import net.minecraft.server.MinecraftServer; 020 import net.minecraft.src.Entity; 021 import net.minecraft.src.NetClientHandler; 022 import net.minecraft.src.NetHandler; 023 import net.minecraft.src.Packet; 024 import net.minecraft.src.Packet131MapData; 025 import net.minecraft.src.World; 026 import cpw.mods.fml.common.FMLCommonHandler; 027 import cpw.mods.fml.common.IFMLSidedHandler; 028 import cpw.mods.fml.common.Loader; 029 import cpw.mods.fml.common.ObfuscationReflectionHelper; 030 import cpw.mods.fml.common.Side; 031 import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; 032 import cpw.mods.fml.common.network.EntitySpawnPacket; 033 import cpw.mods.fml.common.network.ModMissingPacket; 034 import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; 035 import cpw.mods.fml.common.registry.LanguageRegistry; 036 037 /** 038 * Handles primary communication from hooked code into the system 039 * 040 * The FML entry point is {@link #beginServerLoading(MinecraftServer)} called from 041 * {@link net.minecraft.src.DedicatedServer} 042 * 043 * Obfuscated code should focus on this class and other members of the "server" 044 * (or "client") code 045 * 046 * The actual mod loading is handled at arms length by {@link Loader} 047 * 048 * It is expected that a similar class will exist for each target environment: 049 * Bukkit and Client side. 050 * 051 * It should not be directly modified. 052 * 053 * @author cpw 054 * 055 */ 056 public class FMLServerHandler implements IFMLSidedHandler 057 { 058 /** 059 * The singleton 060 */ 061 private static final FMLServerHandler INSTANCE = new FMLServerHandler(); 062 063 /** 064 * A reference to the server itself 065 */ 066 private MinecraftServer server; 067 068 private FMLServerHandler() 069 { 070 FMLCommonHandler.instance().beginLoading(this); 071 } 072 /** 073 * Called to start the whole game off from 074 * {@link MinecraftServer#startServer} 075 * 076 * @param minecraftServer 077 */ 078 public void beginServerLoading(MinecraftServer minecraftServer) 079 { 080 server = minecraftServer; 081 ObfuscationReflectionHelper.detectObfuscation(World.class); 082 Loader.instance().loadMods(); 083 } 084 085 /** 086 * Called a bit later on during server initialization to finish loading mods 087 */ 088 public void finishServerLoading() 089 { 090 Loader.instance().initializeMods(); 091 LanguageRegistry.reloadLanguageTable(); 092 } 093 094 @Override 095 public void haltGame(String message, Throwable exception) 096 { 097 throw new RuntimeException(message, exception); 098 } 099 100 /** 101 * Get the server instance 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 ImmutableList.<String>of(); 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 }