fCraft  0.638
Custom Minecraft Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events
fCraft.Server Class Reference

Core of an fCraft server. Manages startup/shutdown, online player sessions, global events and scheduled tasks. More...

Static Public Member Functions

static string GetArg (ArgKey key)
 Returns value of a given command-line argument (if present). Use HasArg to check flag arguments.
 
static bool HasArg (ArgKey key)
 Checks whether a command-line argument was set.
 
static string GetArgString ()
 Produces a string containing all recognized arguments that wereset/passed to this instance of fCraft.
 
static string[] GetArgList ()
 Produces a list of arguments that were passed to this instance of fCraft.
 
static void InitLibrary ([NotNull] IEnumerable< string > rawArgs)
 Reads command-line switches and sets up paths and logging. This should be called before any other library function. Note to frontend devs: Subscribe to log-related events before calling this. Does not raise any events besides Logger.Logged. Throws exceptions on failure.
 
static void InitServer ()
 Initialized various server subsystems. This should be called after InitLibrary and before StartServer. Loads config, PlayerDB, IP bans, AutoRank settings, builds a list of commands, and prepares the IRC bot. Raises Server.Initializing and Server.Initialized events, and possibly Logger.Logged events. Throws exceptions on failure.
 
static bool StartServer ()
 Starts the server: Creates Console pseudoplayer, loads the world list, starts listening for incoming connections, sets up scheduled tasks and starts the scheduler, starts the heartbeat, and connects to IRC. Raises Server.Starting and Server.Started events. May throw an exception on hard failure.
 
static void Shutdown ([NotNull] ShutdownParams shutdownParams, bool waitForShutdown)
 Initiates the server shutdown with given parameters.
 
static bool CancelShutdown ()
 Attempts to cancel the shutdown timer.
 
static void Message ([NotNull] string message,[NotNull] params object[] formatArgs)
 Broadcasts a message to all online players. Shorthand for Server.Players.Message
 
static void Message ([CanBeNull] Player except,[NotNull] string message,[NotNull] params object[] formatArgs)
 Broadcasts a message to all online players except one. Shorthand for Server.Players.Except(except).Message
 
static void RequestGC ()
 Informs the server that garbage collection should be performed. Actual collection is done on the background task thread, asynchronously, as needed.
 
static void BackupData ()
 
static string GetRandomString (int chars)
 Returns a cryptographically secure random string of given length.
 
static IPEndPoint BindIPEndPointCallback (ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
 
static string MakePlayerConnectedMessage ([NotNull] Player player, bool firstTime,[NotNull] World world)
 
static Player[] FindPlayers ([NotNull] string name, bool raiseEvent)
 Finds a player by name, using autocompletion. Returns ALL matching players, including hidden ones.
 
static Player[] FindPlayers ([NotNull] Player player,[NotNull] string name, bool includeSelf, bool includeHidden, bool raiseEvent)
 Finds a player by name, using autocompletion. Does not include hidden players.
 
static Player FindPlayerExact ([NotNull] Player player,[NotNull] string name, bool includeHidden)
 Finds player by name without autocompletion. Returns null if no player with the given name is online.
 
static Player FindPlayerOrPrintMatches ([NotNull] Player player,[NotNull] string partialName, bool includeSelf, bool includeHidden, bool raiseEvent)
 Find player by name using autocompletion. Returns null and prints message if none or multiple players matched. Raises Player.SearchingForPlayer event, which may modify search results.
 
static int CountPlayers (bool includeHiddenPlayers)
 Counts online players, optionally including hidden ones.
 
static int CountVisiblePlayers ([NotNull] Player observer)
 Counts online players whom the given observer can see.
 

Static Public Attributes

static volatile bool IsShuttingDown
 Whether the server is currently being shut down.
 

Properties

static DateTime StartTime [get, set]
 Time when the server started (UTC). Used to check uptime.
 
static IPAddress InternalIP [get, set]
 Internal IP address that the server's bound to (0.0.0.0 if not explicitly specified by the user).
 
static IPAddress ExternalIP [get, set]
 External IP address of this machine, as reported by checkip.dyndns.org Same as InternalIP, if dyndns check was not carried out or has failed.
 
static int Port [get, set]
 Number of the local listening port.
 
static Uri Uri [get, set]
 Minecraft.net connection URL. May be null (if heartbeat is disabled, or first heartbeat has not been sent yet).
 
static bool IsRunning [get, set]
 Whether the server is currently running (true between Started and ShutdownEnded events).
 
static TimeSpan CheckConnectionsInterval [get, set]
 Interval at which Server checks for incoming connections. One player may be accepted per check. Default is 250ms.
 
static TimeSpan CheckIdlesInterval [get, set]
 Interval at which Server checks for idle players (to kick idlers). Default is 30 seconds.
 
static TimeSpan GCInterval [get, set]
 Interval at which Server checks whether forced garbage collection is needed. Default is 60 seconds.
 
static bool IsMonitoringCPUUsage [get, set]
 
static double CPUUsageTotal [get, set]
 
static double CPUUsageLastMinute [get, set]
 
static Player[] Players [get, set]
 List of online players. This property is volatile and can change when players connect/disconnect, so cache a reference if you need to refer to the same snapshot of the playerlist more than once.
 

Events

static EventHandler Initializing
 Occurs when the server is about to be initialized.
 
static EventHandler Initialized
 Occurs when the server has been initialized.
 
static EventHandler Starting
 Occurs when the server is about to start.
 
static EventHandler Started
 Occurs when the server has just started.
 
static EventHandler
< ShutdownEventArgs
ShutdownBegan
 Occurs when the server is about to start shutting down.
 
static EventHandler
< ShutdownEventArgs
ShutdownEnded
 Occurs when the server finished shutting down.
 
static EventHandler PlayerListChanged
 Occurs when the player list has just changed (any time players connected or disconnected).
 
static EventHandler
< SearchingForPlayerEventArgs
SearchingForPlayer
 Occurs when a player is searching for players (with autocompletion). The list of players in the search results may be replaced.
 
static EventHandler
< SessionConnectingEventArgs
SessionConnecting
 Occurs any time the server receives an incoming connection (cancelable).
 
static EventHandler
< PlayerEventArgs
SessionConnected
 Occurs any time a new session has connected, but before any communication is done.
 
static EventHandler
< SessionDisconnectedEventArgs
SessionDisconnected
 Occurs when a connection is closed or lost.
 

Detailed Description

Core of an fCraft server. Manages startup/shutdown, online player sessions, global events and scheduled tasks.

Member Function Documentation

static void fCraft.Server.BackupData ( )
static
static IPEndPoint fCraft.Server.BindIPEndPointCallback ( ServicePoint  servicePoint,
IPEndPoint  remoteEndPoint,
int  retryCount 
)
static
static bool fCraft.Server.CancelShutdown ( )
static

Attempts to cancel the shutdown timer.

Returns
True if a shutdown timer was cancelled, false if no shutdown is in progress. Also returns false if it's too late to cancel (shutdown has begun).
static int fCraft.Server.CountPlayers ( bool  includeHiddenPlayers)
static

Counts online players, optionally including hidden ones.

static int fCraft.Server.CountVisiblePlayers ( [NotNull] Player  observer)
static

Counts online players whom the given observer can see.

static Player fCraft.Server.FindPlayerExact ( [NotNull] Player  player,
[NotNull] string  name,
bool  includeHidden 
)
static

Finds player by name without autocompletion. Returns null if no player with the given name is online.

Parameters
playerPlayer from whose perspective search is performed. Used to determine whether others are hidden.
nameFull player name. Case-insensitive.
includeHiddenWhether hidden players should be considered in the search.
Returns
Player object if player was found online; otherwise null.
static Player fCraft.Server.FindPlayerOrPrintMatches ( [NotNull] Player  player,
[NotNull] string  partialName,
bool  includeSelf,
bool  includeHidden,
bool  raiseEvent 
)
static

Find player by name using autocompletion. Returns null and prints message if none or multiple players matched. Raises Player.SearchingForPlayer event, which may modify search results.

Parameters
playerPlayer who initiated the search. This is where messages are sent.
partialNameFull or partial name of the search target.
includeSelfWhether player themself should be considered in the results.
includeHiddenWhether to include hidden players in the search.
raiseEventWhether to raise Server.SearchingForPlayer event.
Returns
Player object, or null if no player was found.
static Player [] fCraft.Server.FindPlayers ( [NotNull] string  name,
bool  raiseEvent 
)
static

Finds a player by name, using autocompletion. Returns ALL matching players, including hidden ones.

Returns
An array of matches. List length of 0 means "no matches"; 1 is an exact match; over 1 for multiple matches.
static Player [] fCraft.Server.FindPlayers ( [NotNull] Player  player,
[NotNull] string  name,
bool  includeSelf,
bool  includeHidden,
bool  raiseEvent 
)
static

Finds a player by name, using autocompletion. Does not include hidden players.

Parameters
playerPlayer who initiated the search. Used to determine whether others are hidden or not.
nameFull or partial name of the search target.
includeSelfWhether player themself should be considered in the results.
includeHiddenWhether hidden players should be considered in the search.
raiseEventWhether to raise Server.SearchingForPlayer event.
Returns
An array of matches. List length of 0 means "no matches"; 1 is an exact match; over 1 for multiple matches.
static string fCraft.Server.GetArg ( ArgKey  key)
static

Returns value of a given command-line argument (if present). Use HasArg to check flag arguments.

Parameters
keyCommand-line argument name (enumerated)
Returns
Value of the command-line argument, or null if this argument was not set or argument is a flag.
static string [] fCraft.Server.GetArgList ( )
static

Produces a list of arguments that were passed to this instance of fCraft.

Returns
An array of strings, formatted as –key="value" (or, for flag arguments, –key). Returns an empty string array if no arguments were set.
static string fCraft.Server.GetArgString ( )
static

Produces a string containing all recognized arguments that wereset/passed to this instance of fCraft.

Returns
A string containing all given arguments, or an empty string if none were set.
static string fCraft.Server.GetRandomString ( int  chars)
static

Returns a cryptographically secure random string of given length.

static bool fCraft.Server.HasArg ( ArgKey  key)
static

Checks whether a command-line argument was set.

Parameters
keyCommand-line argument name (enumerated)
Returns
True if given argument was given. Otherwise false.
static void fCraft.Server.InitLibrary ( [NotNull] IEnumerable< string >  rawArgs)
static

Reads command-line switches and sets up paths and logging. This should be called before any other library function. Note to frontend devs: Subscribe to log-related events before calling this. Does not raise any events besides Logger.Logged. Throws exceptions on failure.

Parameters
rawArgsstring arguments passed to the frontend (if any).
Exceptions
System.InvalidOperationExceptionLibrary is already initialized.
System.IO.IOExceptionWorking path, log path, or map path cannot be set.
static void fCraft.Server.InitServer ( )
static

Initialized various server subsystems. This should be called after InitLibrary and before StartServer. Loads config, PlayerDB, IP bans, AutoRank settings, builds a list of commands, and prepares the IRC bot. Raises Server.Initializing and Server.Initialized events, and possibly Logger.Logged events. Throws exceptions on failure.

Exceptions
System.InvalidOperationExceptionLibrary is not initialized, or server is already initialzied.
static string fCraft.Server.MakePlayerConnectedMessage ( [NotNull] Player  player,
bool  firstTime,
[NotNull] World  world 
)
static
static void fCraft.Server.Message ( [NotNull] string  message,
[NotNull] params object[]  formatArgs 
)
static

Broadcasts a message to all online players. Shorthand for Server.Players.Message

static void fCraft.Server.Message ( [CanBeNull] Player  except,
[NotNull] string  message,
[NotNull] params object[]  formatArgs 
)
static

Broadcasts a message to all online players except one. Shorthand for Server.Players.Except(except).Message

static void fCraft.Server.RequestGC ( )
static

Informs the server that garbage collection should be performed. Actual collection is done on the background task thread, asynchronously, as needed.

static void fCraft.Server.Shutdown ( [NotNull] ShutdownParams  shutdownParams,
bool  waitForShutdown 
)
static

Initiates the server shutdown with given parameters.

Parameters
shutdownParamsShutdown parameters
waitForShutdownIf true, blocks the calling thread until shutdown is complete or cancelled.
static bool fCraft.Server.StartServer ( )
static

Starts the server: Creates Console pseudoplayer, loads the world list, starts listening for incoming connections, sets up scheduled tasks and starts the scheduler, starts the heartbeat, and connects to IRC. Raises Server.Starting and Server.Started events. May throw an exception on hard failure.

Returns
True if server started normally, false on soft failure.
Exceptions
System.InvalidOperationExceptionServer is already running, or server/library have not been initailized.

Member Data Documentation

volatile bool fCraft.Server.IsShuttingDown
static

Whether the server is currently being shut down.

Property Documentation

TimeSpan fCraft.Server.CheckConnectionsInterval
staticgetset

Interval at which Server checks for incoming connections. One player may be accepted per check. Default is 250ms.

TimeSpan fCraft.Server.CheckIdlesInterval
staticgetset

Interval at which Server checks for idle players (to kick idlers). Default is 30 seconds.

double fCraft.Server.CPUUsageLastMinute
staticgetset
double fCraft.Server.CPUUsageTotal
staticgetset
IPAddress fCraft.Server.ExternalIP
staticgetset

External IP address of this machine, as reported by checkip.dyndns.org Same as InternalIP, if dyndns check was not carried out or has failed.

TimeSpan fCraft.Server.GCInterval
staticgetset

Interval at which Server checks whether forced garbage collection is needed. Default is 60 seconds.

IPAddress fCraft.Server.InternalIP
staticgetset

Internal IP address that the server's bound to (0.0.0.0 if not explicitly specified by the user).

bool fCraft.Server.IsMonitoringCPUUsage
staticgetset
bool fCraft.Server.IsRunning
staticgetset

Whether the server is currently running (true between Started and ShutdownEnded events).

Player [] fCraft.Server.Players
staticgetset

List of online players. This property is volatile and can change when players connect/disconnect, so cache a reference if you need to refer to the same snapshot of the playerlist more than once.

int fCraft.Server.Port
staticgetset

Number of the local listening port.

DateTime fCraft.Server.StartTime
staticgetset

Time when the server started (UTC). Used to check uptime.

Uri fCraft.Server.Uri
staticgetset

Minecraft.net connection URL. May be null (if heartbeat is disabled, or first heartbeat has not been sent yet).

Event Documentation

EventHandler fCraft.Server.Initialized
static

Occurs when the server has been initialized.

EventHandler fCraft.Server.Initializing
static

Occurs when the server is about to be initialized.

EventHandler fCraft.Server.PlayerListChanged
static

Occurs when the player list has just changed (any time players connected or disconnected).

EventHandler<SearchingForPlayerEventArgs> fCraft.Server.SearchingForPlayer
static

Occurs when a player is searching for players (with autocompletion). The list of players in the search results may be replaced.

EventHandler<PlayerEventArgs> fCraft.Server.SessionConnected
static

Occurs any time a new session has connected, but before any communication is done.

EventHandler<SessionConnectingEventArgs> fCraft.Server.SessionConnecting
static

Occurs any time the server receives an incoming connection (cancelable).

EventHandler<SessionDisconnectedEventArgs> fCraft.Server.SessionDisconnected
static

Occurs when a connection is closed or lost.

EventHandler<ShutdownEventArgs> fCraft.Server.ShutdownBegan
static

Occurs when the server is about to start shutting down.

EventHandler<ShutdownEventArgs> fCraft.Server.ShutdownEnded
static

Occurs when the server finished shutting down.

EventHandler fCraft.Server.Started
static

Occurs when the server has just started.

EventHandler fCraft.Server.Starting
static

Occurs when the server is about to start.


The documentation for this class was generated from the following files: