/* Copyright (C) 2007 This File is part of Core3. This program 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 Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Linking Engine3 statically or dynamically with other modules is making a combined work based on Engine3. Thus, the terms and conditions of the GNU Lesser General Public License cover the whole combination. In addition, as a special exception, the copyright holders of Engine3 give you permission to combine Engine3 program with free software programs or libraries that are released under the GNU LGPL and with code included in the standard release of Core3 under the GNU LGPL license (or modified versions of such code, with unchanged license). You may copy and distribute such a system following the terms of the GNU LGPL for Engine3 and the licenses of the other code concerned, provided that you include the source code of that other code when and as the GNU LGPL requires distribution of source code. Note that people who make modified versions of Engine3 are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception. */ package server.zone; import server.zone.objects.scene.SceneObject; import engine.service.proto.BasePacketHandler; import engine.service.DatagramServiceThread; import engine.service.ServiceHandler; import engine.service.ServiceClient; import engine.service.Message; import engine.core.ManagedService; import engine.core.TaskManager; import engine.log.Logger; import system.lang.Exception; import system.lang.Time; import system.lang.ref.Reference; import system.util.Vector; import system.util.VectorMap; import system.net.Socket; import system.net.SocketAddress; import system.net.Packet; import system.thread.atomic.AtomicInteger; import server.login.account.Account; import server.zone.ZoneProcessServer; import server.zone.ZoneClientSession; import server.zone.ZoneHandler; import server.zone.Zone; import server.chat.ChatManager; import server.conf.ConfigManager; import server.zone.managers.object.ObjectManager; import server.zone.managers.player.PlayerManager; import server.zone.managers.objectcontroller.ObjectController; import server.zone.managers.radial.RadialManager; import server.zone.managers.skill.SkillManager; import server.zone.managers.resource.ResourceManager; import server.zone.managers.crafting.CraftingManager; import server.zone.managers.loot.LootManager; import server.zone.managers.auction.AuctionManager; import server.zone.managers.minigames.FishingManager; import server.zone.managers.mission.MissionManager; import server.zone.managers.minigames.GamblingManager; import server.zone.managers.minigames.ForageManager; import server.zone.managers.stringid.StringIdManager; import server.zone.managers.creature.CreatureTemplateManager; import server.zone.managers.guild.GuildManager; import server.zone.managers.city.CityManager; class ZoneServer extends ManagedService implements Logger { private transient DatagramServiceThread datagramService; private transient BasePacketHandler phandler; private transient ConfigManager configManager; private transient ZoneHandler zoneHandler; private transient ZoneProcessServer processor; private VectorMap zones; private transient ObjectManager objectManager; private PlayerManager playerManager; private ChatManager chatManager; private RadialManager radialManager; private CityManager cityManager; private ResourceManager resourceManager; private CraftingManager craftingManager; private LootManager lootManager; private AuctionManager auctionManager; private MissionManager missionManager; private GuildManager guildManager; private transient StringIdManager stringIdManager; private transient CreatureTemplateManager creatureTemplateManager; private int totalSentPackets; private int serverCap; private int totalResentPackets; @dereferenced private AtomicInteger currentPlayers; @dereferenced private AtomicInteger maximumPlayers; @dereferenced private AtomicInteger totalPlayers; @dereferenced private AtomicInteger totalDeletedPlayers; private int serverState; private string galaxyName; private string loginMessage; private int galaxyID; @dereferenced private Time startTimestamp; public static final int OFFLINE = 0; public static final int LOADING = 1; public static final int ONLINE = 2; public static final int LOCKED = 3; public native ZoneServer(ConfigManager config); public native void initializeTransientMembers(); @local @dirty public native ZoneClientSession createConnection(Socket sock, @dereferenced SocketAddress addr); private native void loadGalaxyName(); public native void initialize(); public native void shutdown(); public native void startManagers(); public native void startZones(); public native void stopManagers(); public native void start(int p, int mconn = 10); public native void stop(); public native void timedShutdown(int minutes); @local @dirty public native void handleMessage(ZoneClientSession client, Packet message); @local @dirty public native void processMessage(Message message); @local @dirty public native boolean handleError(ZoneClientSession client, @dereferenced Exception e); @dirty public native void addTotalSentPacket(int count); @dirty public native void addTotalResentPacket(int count); @dirty public native void printInfo(); @dirty public native string getInfo(); @dirty public native void printEvents(); @dirty public native SceneObject getObject(unsigned long objectID, boolean doLock = true); @dirty public native SceneObject createObject(unsigned int templateCRC, int persistenceLevel = 2, unsigned long objectID = 0); @dirty public native SceneObject createClientObject(unsigned int templateCRC, unsigned long objectID = 0); @dirty public native void updateObjectToDatabase(SceneObject object); @dirty public native void updateObjectToStaticDatabase(SceneObject object); @dirty public native void destroyObjectFromDatabase(unsigned long objectID); public native void lock(boolean doLock = true); public native void unlock(boolean doLock = true); public void fixScheduler() { //scheduler.fixQueue(); } public native void changeUserCap(int amount = 50); @dirty public native int getConnectionCount(); @dirty public native void increaseOnlinePlayers(); @dirty public native void decreaseOnlinePlayers(); @dirty public native void increaseTotalDeletedPlayers(); @dirty public int getGalaxyID() { return galaxyID; } @dirty public string getGalaxyName() { return galaxyName; } public void setGalaxyName(final string name) { galaxyName = name; } @dirty public boolean isServerLocked() { return serverState == LOCKED; } @dirty public boolean isServerOnline() { return serverState == ONLINE; } @dirty public boolean isServerOffline() { return serverState == OFFLINE; } @dirty public boolean isServerLoading() { return serverState == LOADING; } public int getServerCap() { return serverCap; } @dirty public int getServerState() { return serverState; } @dirty public Zone getZone(final string terrainName) { return zones.get(terrainName); } /** * Gets a note based on it's position in the zone map. * NOTE: This idx is not to be considered consistent. * @param idx The index in the map to get the zone. */ @dirty public Zone getZone(int idx) { return zones.get(idx); } @dirty public int getZoneCount() { return zones.size(); } @dirty public int getMaxPlayers() { return maximumPlayers.get(); } @dirty public int getTotalPlayers() { return totalPlayers.get(); } @dirty public int getDeletedPlayers() { return totalDeletedPlayers.get(); } @local @dirty public ObjectManager getObjectManager() { return objectManager; } @dirty public PlayerManager getPlayerManager() { return playerManager; } @dirty public ChatManager getChatManager() { return chatManager; } @dirty public CityManager getCityManager() { return cityManager; } @dirty public ObjectController getObjectController() { return processor.getObjectController(); } @dirty public MissionManager getMissionManager() { return missionManager; } @dirty public RadialManager getRadialManager() { return radialManager; } @dirty public GuildManager getGuildManager() { return guildManager; } @dirty public ResourceManager getResourceManager() { return resourceManager; } @dirty public CraftingManager getCraftingManager() { return craftingManager; } @dirty public LootManager getLootManager() { return lootManager; } @dirty public AuctionManager getAuctionManager() { return auctionManager; } //public native Account getAccount(unsigned int accountID); @local @dirty public SkillManager getSkillManager() { return processor.getSkillManager(); } @local @dirty public Time getStartTimestamp() { return startTimestamp; } public void setGalaxyID(int galaxyid) { galaxyID = galaxyid; } public void setServerState(int state) { serverState = state; } public native void setServerStateLocked(); public native void setServerStateOnline(); public native void loadLoginMessage(); public native void changeLoginMessage(final string motd); @dirty public native string getLoginMessage(); }