wyvern.world
Class World

java.lang.Object
  extended bywyvern.world.World
All Implemented Interfaces:
MapLoaderListener, Timed, WizTypes

public final class World
extends java.lang.Object
implements MapLoaderListener, Timed, WizTypes

The game world. It handles loading and caching maps and players.

Version:
1.0, Aug 20, 1997
Author:
Steve Yegge

Nested Class Summary
static interface World.ShoutFlags
          Flags to pass to World.shout().
 
Field Summary
 
Fields inherited from interface wyvern.lib.WizTypes
ARCH, ELDER, JUNIOR, MAX_LEVEL, MIN_LEVEL, PLAYER, SENIOR, WIZARD
 
Constructor Summary
World()
          Creates the World object.
 
Method Summary
static void addMapListener(MapLoaderListener callback, java.lang.String filename)
          Adds another listener to be notified when a map finishes loading.
static void addPlayer(Player p)
          Adds an existing player to the list of registered players.
static void autoloadMap(java.lang.String path)
          Used for autoloading the destinations of "autoload" teleporters.
static boolean ban(java.lang.String name)
          Bans a player until the next reboot.
static void bootAllPlayers()
          Boots every player off the game.
static void bootIdlePlayers()
          Goes through the player list and boots any players that have been idle for too long.
static void cancelReboot(Commandable agent)
          Cancels the current reboot, if any.
static boolean enableShouting(Commandable agent, boolean on)
          Turns all shouting on or off.
static int getAveragePlayers()
          Returns the average number of players that have been logged in during this session.
static GameMap getCreationMap()
          Returns a new instance of the map used for creating new chars.
static GameMap getMap(MapLoaderListener callback, java.lang.String name)
          Returns a reference to the specified map, loading it if necessary.
static GameMap getMap(MapLoaderListener callback, java.lang.String name, GameMapLoader loader, boolean cache)
          Loads a map in the background using a custom map loader.
static GameMap getMap(java.lang.String name)
          Returns a reference to the specified map, loading it if necessary.
static GameMap getMapNoLoad(java.lang.String name)
          Retrieves the current map if it's already loaded in memory, else returns null.
static GameMap getMapSynchronously(java.lang.String name)
          Loads a map, NOT in the background, using a custom map loader.
static GameMap getMapSynchronously(java.lang.String name, GameMapLoader loader)
          Loads a map, NOT in the background, using a custom map loader.
static int getMaxPlayers()
          Returns the highest number of players who've been logged in at once during this session.
static java.lang.String getName()
          Returns the name of this world.
static Player getPlayer(java.lang.String name)
          Returns a Player object, looking up their name.
static Player getPlayer(java.lang.String name, boolean partial)
          Returns a player from the online-players list, and you can specify only the first few characters of the player's name.
static int getPlayerCount()
          Returns the number of players currently active on this server.
static java.util.Set getPlayerList()
          Returns a Set view of the players currently in the game.
static wyvern.world.PlayerList getPlayerListInstance()
          This method is for debugging only.
static java.lang.String[] getRegisteredMaps()
          Returns a list of all currently loaded maps.
static Location getRestartLocation()
          Returns the newbie village chapel - the default restart location if we can't determine where to put the player when they die.
static java.lang.String[] getSortedPlayers()
          Returns a list of players online, sorted by their start times for this session, from first to most recent.
static long getStartTime()
          Returns the result of System.currentTimeMillis() when the server was started.
 double getSystemLoad()
          Returns the current unix system 5-minute load average.
static int getUniquePlayers()
          Returns the count of unique players who've played during this session, not including guests.
static java.lang.String getUptime()
          Returns a string saying how long the server has been up.
static java.lang.String[] getWizardList()
           
static int getWizLevel(java.lang.String name)
          Returns the AccessControl.WizLevel for this player
static boolean isAtLeast(Commandable agent, int level)
          Returns true if the passed player is at least the specified wizard level.
static boolean isAtLeast(java.lang.String name, int level)
          Returns true if the passed player name is a wizard character.
static boolean isBanished(java.lang.String name)
          Returns true if the specified name is on the banish list.
static boolean isBanned(java.lang.String name)
          Returns true if the player is banned for this session.
static boolean isElderWizard(Commandable agent)
          Returns true if the passed player is an Elder Wizard.
static boolean isElderWizard(java.lang.String name)
          Returns true if the passed player is an Elder Wizard.
static boolean isExtremelyNaughty(java.lang.String s)
          Returns true if the passed string has an obvious attempt to bypass the shout filter.
static boolean isGod(Commandable agent)
          Returns true if the passed player is a God.
static boolean isGod(java.lang.String name)
          Returns true if the passed player is a God.
static boolean isIPBanished(java.lang.String ip)
          Returns true if the specified IP address is banished.
static boolean isJuniorWizard(Commandable agent)
          Returns true if the passed player is a Junior Wizard.
static boolean isJuniorWizard(java.lang.String name)
          Returns true if the passed player is a Junior Wizard.
static boolean isNaughty(java.lang.String s)
          Returns true if the passed string contains any naughty language.
static boolean isSeniorWizard(Commandable agent)
          Returns true if the passed player is a Senior Wizard.
static boolean isSeniorWizard(java.lang.String name)
          Returns true if the passed player is a Senior Wizard.
static boolean isWizAlt(java.lang.String name)
          Returns true if the passed player name has the same email address as an existing wizard.
static boolean isWizard(Commandable agent)
          Returns true if the passed player is a mid-level Wizard.
static boolean isWizard(java.lang.String name)
          Returns true if the passed player is a mid-level Wizard.
static void mailPlayer(java.lang.String player, java.lang.String sender, java.lang.String body)
          Sends a post-office mail message to a player.
 void mapLoaded(GameMap map, java.lang.String name)
          Called when the requested map finishes loading.
 void mapLoadFailed(java.lang.String name)
          Called when the requested map couldn't be loaded.
static java.lang.String matchPlayer(java.lang.String name)
          Looks for a player matching the passed partial-name.
static boolean outranks(Commandable wizardA, Commandable wizardB)
          Returns true if the first wizard outranks the second wizard.
static boolean outranks(java.lang.String name1, java.lang.String name2)
          Returns true if the first wizard outranks the second wizard.
static boolean rebootPending()
          Returns true if the game is currently being rebooted.
static void registerMap(GameMap map)
          Adds a map to the World.
static void scheduleReboot(int delay)
          Sets a timer to schedule a reboot.
static void shout(java.lang.String msg)
          Sends a shout message to everyone on the game.
static void shout(java.lang.String msg, byte style)
          Sends a shout message to everyone on the game, in the specified RPCConstants.TextStyle.
static void shout(java.lang.String msg, byte style, int flags)
          Sends a shout message to everyone on the game, in the specified RPCConstants.TextStyle.
static boolean shoutingEnabled()
          Returns true if shouting is currently enabled.
static void shutdown()
          Shuts down the game server.
 void timerExpired()
          World timer: updates score list once an hour, checks load averages, unloads unused maps, etc.
 java.lang.String toString()
           
static boolean unban(java.lang.String name)
          Unbans a player for this session.
static int unloadMap(java.lang.String name)
          Attempts to unload a map from the game.
static void unloadMaps(boolean all)
          Tries to recover some memory for the game by unloading all maps that don't have players in them.
static void unloadUnusedMaps()
          Tries to recover some memory for the game by unloading all maps that don't have players in them.
static void unregisterPlayer(Player player)
          Removes a player from the World list.
 void updateHighScores()
          Re-generates the high score list.
static java.util.List wiztell(java.lang.String msg, java.lang.String teller)
          Sends a message to every wizard logged into the game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

World

public World()
Creates the World object. Called by main JVM startup thread. This handles bootstrapping the game - it starts the Scheduler, seeds the random-item generator, preloads maps, starts the system availability monitor, fires up the HeartbeatManager and other timers, and loads the Wizard bootstrap objects.

Method Detail

getName

public static java.lang.String getName()
Returns the name of this world.

Returns:
the (permanent) server name

getCreationMap

public static GameMap getCreationMap()
Returns a new instance of the map used for creating new chars.

Returns:
a char-creation map with nobody else in it

unregisterPlayer

public static void unregisterPlayer(Player player)
Removes a player from the World list.

Parameters:
player - the player to kick out

getPlayer

public static Player getPlayer(java.lang.String name)
Returns a Player object, looking up their name.

Parameters:
name - the player's name - no title, case is not significant
Returns:
the Player object for that name, or null if not found

getPlayer

public static Player getPlayer(java.lang.String name,
                               boolean partial)
Returns a player from the online-players list, and you can specify only the first few characters of the player's name. If there's an unambigous match, it returns that Player; otherwise it returns null.

Parameters:
name - the (partial) player name
partial - true to use partial name-matching
Returns:
the Player with that name, or null if there wasn't a match (or there was more than one match).

matchPlayer

public static java.lang.String matchPlayer(java.lang.String name)
Looks for a player matching the passed partial-name. You can pass in the first few characters of a player's name, and it'll check the players online to see if there's an unambiguous match.

Parameters:
name - the first part of a player's name
Returns:
the (lowercased) name of the matching player, or "+" if more than one player matched, or "-" if there were no matches.

getPlayerList

public static java.util.Set getPlayerList()
Returns a Set view of the players currently in the game.

Returns:
a Set of the names of the players in the game

getSortedPlayers

public static java.lang.String[] getSortedPlayers()
Returns a list of players online, sorted by their start times for this session, from first to most recent.

Returns:
a sorted list of the names of the current players

getWizardList

public static java.lang.String[] getWizardList()

getPlayerCount

public static int getPlayerCount()
Returns the number of players currently active on this server.

Returns:
the player count

addPlayer

public static void addPlayer(Player p)
Adds an existing player to the list of registered players. Only needs to be called when creating a new Player object without loading it from an existing player file.


getMaxPlayers

public static int getMaxPlayers()
Returns the highest number of players who've been logged in at once during this session.


getAveragePlayers

public static int getAveragePlayers()
Returns the average number of players that have been logged in during this session.


getRestartLocation

public static Location getRestartLocation()
Returns the newbie village chapel - the default restart location if we can't determine where to put the player when they die.

Returns:
the location to teleport them to

isBanished

public static boolean isBanished(java.lang.String name)
Returns true if the specified name is on the banish list.


isIPBanished

public static boolean isIPBanished(java.lang.String ip)
Returns true if the specified IP address is banished.

Parameters:
ip - a full IP address (4 octets) or a subnet (3 octets, e.g. 207.42.131) - formatting must be exact.
Returns:
true if this IP or subnet is banished. Normally you only need to check if the IP is banished, and it automatically checks if the subnet is banished as well.

getUniquePlayers

public static int getUniquePlayers()
Returns the count of unique players who've played during this session, not including guests.


getMap

public static GameMap getMap(MapLoaderListener callback,
                             java.lang.String name)
Returns a reference to the specified map, loading it if necessary. If the map is already loaded, it is returned. If not, the game begins loading the map on a separate thread, and the callback is added to a listener list. When the map is loaded, the listeners are notified.

Parameters:
callback - the listener to notify when the map is loaded. If the map is already loaded, no notification occurs.
name - the relative path to the map, e.g. "wiz/bowser/town/blacksmith" (for wizard maps) or "town/blacksmith" for built-in maps.
Returns:
the map, or null if it's still loading

getMap

public static GameMap getMap(MapLoaderListener callback,
                             java.lang.String name,
                             GameMapLoader loader,
                             boolean cache)
Loads a map in the background using a custom map loader. The map will be loaded to start monsters, and marked as not in the map editor.

Parameters:
name - a name by which to refer to the map
callback - the callback wanting to know when it's loaded
loader - a custom map loader, perhaps one that constructs the map dynamically without reading it from a mapfile
cache - true to cache the map in the world list, keyed on its path, after the map is loaded. You probably want to pass false
Returns:
the requested GameMap, or null if it's begun loading

getMap

public static GameMap getMap(java.lang.String name)
Returns a reference to the specified map, loading it if necessary. If the map isn't loaded, it will start loading on a separate thread, and the method returns null. Use this method if you just want to start loading the map, without caring when it finishes.

Parameters:
name - the relative path to the map
Returns:
the map, if it was already loaded, else null

getMapSynchronously

public static GameMap getMapSynchronously(java.lang.String name)
Loads a map, NOT in the background, using a custom map loader. The map will be loaded to start monsters, and marked as not in the map editor.

Make SURE you never call this method from the Kernel thread. It's OK to call it if the BackgroundMapLoader has called your GameMapLoader.loadMap() function, requesting you to load the map.

The map is not put in the World map cache. You have to do this explicitly with World.registerMap(), if you want it to show up in the World list.

Parameters:
name - path to the map
Returns:
the requested GameMap, or null if it's begun loading

getMapSynchronously

public static GameMap getMapSynchronously(java.lang.String name,
                                          GameMapLoader loader)
Loads a map, NOT in the background, using a custom map loader. The map will be loaded to start monsters, and marked as not in the map editor.

Make SURE you never call this method from the Kernel thread. It's OK to call it if the BackgroundMapLoader has called your GameMapLoader.loadMap() function, requesting you to load the map.

The map is not put in the World map cache. You have to do this explicitly with World.registerMap(), if you want it to show up in the World list.

Parameters:
name - path to the map
Returns:
the requested GameMap, or null if it's begun loading

registerMap

public static void registerMap(GameMap map)
Adds a map to the World. Required if you create a map at run-time; not required if you invoke the World object to load a map file from the disk.

Parameters:
map - the map to add; must have its name set

unloadMap

public static int unloadMap(java.lang.String name)
Attempts to unload a map from the game. Doesn't set an unload-timer - just calls dismantle() on the map, if the map is registered. Returns an error code if there are players in the map.

Parameters:
name - the map to unload
Returns:
an error code

getRegisteredMaps

public static java.lang.String[] getRegisteredMaps()
Returns a list of all currently loaded maps.

Returns:
an array listing all maps currently in memory

getMapNoLoad

public static GameMap getMapNoLoad(java.lang.String name)
Retrieves the current map if it's already loaded in memory, else returns null. Doesn't attempt to load the map.

Parameters:
name - the relative path to the map to fetch
Returns:
the map, null if not currently loaded

autoloadMap

public static void autoloadMap(java.lang.String path)
Used for autoloading the destinations of "autoload" teleporters. This can help give the game a more seamless effect - when you enter an area, any teleporters in that area that are marked "autoload" will have their destinations begin loading silently in the background. Autoloaded maps have shorter unload-delay timers, in case nobody ever goes in them.

Parameters:
path - the relative map path

addMapListener

public static void addMapListener(MapLoaderListener callback,
                                  java.lang.String filename)
Adds another listener to be notified when a map finishes loading. If the map is already loaded, the listener will be notified immediately. Used by custom map loaders whose map loading was triggered by a player, where both the map loader and the player need to be notified when the map finishes loading.

Parameters:
callback - the listener to notify
filename - the unique name of the map being loaded

mapLoaded

public void mapLoaded(GameMap map,
                      java.lang.String name)
Called when the requested map finishes loading.

Specified by:
mapLoaded in interface MapLoaderListener
Parameters:
map - the map reference
name - the name of the map

mapLoadFailed

public void mapLoadFailed(java.lang.String name)
Called when the requested map couldn't be loaded.

Specified by:
mapLoadFailed in interface MapLoaderListener
Parameters:
name - the name of the map that failed.

unloadUnusedMaps

public static void unloadUnusedMaps()
Tries to recover some memory for the game by unloading all maps that don't have players in them. Skips maps with the "no-reset" flag, since they usually need to stay in memory for one reason or another.


unloadMaps

public static void unloadMaps(boolean all)
Tries to recover some memory for the game by unloading all maps that don't have players in them. Skips maps with the "no-reset" flag, since they usually need to stay in memory for one reason or another.

Parameters:
all - true to unload all maps, false to skip maps that have the "no-reset" property

shutdown

public static void shutdown()
Shuts down the game server.


bootAllPlayers

public static void bootAllPlayers()
Boots every player off the game. Used during shutdown, or when the game becomes incredibly wedged and nobody can move. Wizards should *NOT* call this method - it's grounds for banishment.


shout

public static void shout(java.lang.String msg)
Sends a shout message to everyone on the game.

Parameters:
msg - any message to send

shout

public static void shout(java.lang.String msg,
                         byte style)
Sends a shout message to everyone on the game, in the specified RPCConstants.TextStyle.

Parameters:
msg - any message to send
style - the wyvern.common.net.RPCConstants.TextStyle

shout

public static void shout(java.lang.String msg,
                         byte style,
                         int flags)
Sends a shout message to everyone on the game, in the specified RPCConstants.TextStyle.

Parameters:
msg - any message to send
style - the wyvern.common.net.RPCConstants.TextStyle
flags - an int consisting of or'ed-together World.ShoutFlags constants.

mailPlayer

public static void mailPlayer(java.lang.String player,
                              java.lang.String sender,
                              java.lang.String body)
                       throws java.lang.Exception
Sends a post-office mail message to a player. This is often used by system routines when they need to make a change to the player's stats, inventory, or other attributes. Just calls PostOffice.sendMessage().

Parameters:
player - the name of the player to send the mail to.
sender - who to say the mail is from
body - the message
Throws:
any - Exception if it fails to be delivered
java.lang.Exception

isGod

public static boolean isGod(java.lang.String name)
Returns true if the passed player is a God.


isGod

public static boolean isGod(Commandable agent)
Returns true if the passed player is a God.


isElderWizard

public static boolean isElderWizard(java.lang.String name)
Returns true if the passed player is an Elder Wizard.


isElderWizard

public static boolean isElderWizard(Commandable agent)
Returns true if the passed player is an Elder Wizard.


isSeniorWizard

public static boolean isSeniorWizard(java.lang.String name)
Returns true if the passed player is a Senior Wizard.


isSeniorWizard

public static boolean isSeniorWizard(Commandable agent)
Returns true if the passed player is a Senior Wizard.


isWizard

public static boolean isWizard(java.lang.String name)
Returns true if the passed player is a mid-level Wizard.


isWizard

public static boolean isWizard(Commandable agent)
Returns true if the passed player is a mid-level Wizard.


isJuniorWizard

public static boolean isJuniorWizard(java.lang.String name)
Returns true if the passed player is a Junior Wizard.


isJuniorWizard

public static boolean isJuniorWizard(Commandable agent)
Returns true if the passed player is a Junior Wizard.


isAtLeast

public static boolean isAtLeast(Commandable agent,
                                int level)
Returns true if the passed player is at least the specified wizard level.


isAtLeast

public static boolean isAtLeast(java.lang.String name,
                                int level)
Returns true if the passed player name is a wizard character.


getWizLevel

public static int getWizLevel(java.lang.String name)
Returns the AccessControl.WizLevel for this player

Parameters:
name - the player name
Returns:
the WizLevel (1-5) or zero if it's not a wizard.

outranks

public static boolean outranks(java.lang.String name1,
                               java.lang.String name2)
Returns true if the first wizard outranks the second wizard.

Parameters:
name1 - the first wizard's name
name2 - the second wizard's name
Returns:
true if the first wizard is higher-level than the second wizard

outranks

public static boolean outranks(Commandable wizardA,
                               Commandable wizardB)
Returns true if the first wizard outranks the second wizard.

Parameters:
wizardA - the first wizard
wizardB - the second wizard
Returns:
true if the first wizard is higher-level than the second wizard

isWizAlt

public static boolean isWizAlt(java.lang.String name)
Returns true if the passed player name has the same email address as an existing wizard. Works even if player is offline. Don't call it a bunch of times, since it hits the database. Call it once at the top of your function or class, and save the result in a boolean variable.

Parameters:
name - the name of a player
Returns:
true if it's a wiz alt

isNaughty

public static boolean isNaughty(java.lang.String s)
Returns true if the passed string contains any naughty language.

Returns:
true if it has any off-limits words or phrases.

isExtremelyNaughty

public static boolean isExtremelyNaughty(java.lang.String s)
Returns true if the passed string has an obvious attempt to bypass the shout filter.

Parameters:
s - the message
Returns:
true if it has the f-word with punctuation in it, or whatever.

wiztell

public static java.util.List wiztell(java.lang.String msg,
                                     java.lang.String teller)
Sends a message to every wizard logged into the game.

Parameters:
teller - the wizard to skip (if a wizard is doing it)
Returns:
a list of the Wizards who heard the wiztell (can be null)

getStartTime

public static long getStartTime()
Returns the result of System.currentTimeMillis() when the server was started. Used by the "uptime" wiz command.

Returns:
the time when the server was started

timerExpired

public void timerExpired()
World timer: updates score list once an hour, checks load averages, unloads unused maps, etc.

Specified by:
timerExpired in interface Timed

updateHighScores

public void updateHighScores()
Re-generates the high score list. Gets run on a separate thread so it doesn't hold up the game.


bootIdlePlayers

public static void bootIdlePlayers()
Goes through the player list and boots any players that have been idle for too long.


scheduleReboot

public static void scheduleReboot(int delay)
Sets a timer to schedule a reboot.

Parameters:
delay - minutes to reboot

cancelReboot

public static void cancelReboot(Commandable agent)
Cancels the current reboot, if any.


rebootPending

public static boolean rebootPending()
Returns true if the game is currently being rebooted.


getUptime

public static java.lang.String getUptime()
Returns a string saying how long the server has been up.


getSystemLoad

public double getSystemLoad()
Returns the current unix system 5-minute load average.


enableShouting

public static boolean enableShouting(Commandable agent,
                                     boolean on)
Turns all shouting on or off.

Parameters:
on - true to turn shouting on, false to turn it off
Returns:
true if we changed something, false if no change was made (i.e. it was already in the state you're asking for)

shoutingEnabled

public static boolean shoutingEnabled()
Returns true if shouting is currently enabled.

Returns:
true if enabled, false if not

ban

public static boolean ban(java.lang.String name)
Bans a player until the next reboot.

Returns:
true if they were already banned, false if they're being banned for the first time.

isBanned

public static boolean isBanned(java.lang.String name)
Returns true if the player is banned for this session.

Parameters:
name - a player name - no partial matches accepted
Returns:
true if they've been temporarily banned

unban

public static boolean unban(java.lang.String name)
Unbans a player for this session.

Parameters:
name - the name of a player.
Returns:
true if the name was successfully unbanned; false if it wasn't in the list to begin with.

toString

public java.lang.String toString()

getPlayerListInstance

public static wyvern.world.PlayerList getPlayerListInstance()
This method is for debugging only.