![]() |
fCraft
0.638
Custom Minecraft Server
|
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. | |
Core of an fCraft server. Manages startup/shutdown, online player sessions, global events and scheduled tasks.
|
static |
|
static |
|
static |
Attempts to cancel the shutdown timer.
|
static |
Counts online players, optionally including hidden ones.
|
static |
Counts online players whom the given observer can see.
|
static |
Finds player by name without autocompletion. Returns null if no player with the given name is online.
| player | Player from whose perspective search is performed. Used to determine whether others are hidden. |
| name | Full player name. Case-insensitive. |
| includeHidden | Whether hidden players should be considered in the search. |
|
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.
| player | Player who initiated the search. This is where messages are sent. |
| partialName | Full or partial name of the search target. |
| includeSelf | Whether player themself should be considered in the results. |
| includeHidden | Whether to include hidden players in the search. |
| raiseEvent | Whether to raise Server.SearchingForPlayer event. |
|
static |
Finds a player by name, using autocompletion. Returns ALL matching players, including hidden ones.
|
static |
Finds a player by name, using autocompletion. Does not include hidden players.
| player | Player who initiated the search. Used to determine whether others are hidden or not. |
| name | Full or partial name of the search target. |
| includeSelf | Whether player themself should be considered in the results. |
| includeHidden | Whether hidden players should be considered in the search. |
| raiseEvent | Whether to raise Server.SearchingForPlayer event. |
|
static |
Returns value of a given command-line argument (if present). Use HasArg to check flag arguments.
| key | Command-line argument name (enumerated) |
|
static |
Produces a list of arguments that were passed to this instance of fCraft.
|
static |
Produces a string containing all recognized arguments that wereset/passed to this instance of fCraft.
|
static |
Returns a cryptographically secure random string of given length.
|
static |
Checks whether a command-line argument was set.
| key | Command-line argument name (enumerated) |
|
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.
| rawArgs | string arguments passed to the frontend (if any). |
| System.InvalidOperationException | Library is already initialized. |
| System.IO.IOException | Working path, log path, or map path cannot be set. |
|
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.
| System.InvalidOperationException | Library is not initialized, or server is already initialzied. |
|
static |
|
static |
Broadcasts a message to all online players. Shorthand for Server.Players.Message
|
static |
Broadcasts a message to all online players except one. Shorthand for Server.Players.Except(except).Message
|
static |
Informs the server that garbage collection should be performed. Actual collection is done on the background task thread, asynchronously, as needed.
|
static |
Initiates the server shutdown with given parameters.
| shutdownParams | Shutdown parameters |
| waitForShutdown | If true, blocks the calling thread until shutdown is complete or cancelled. |
|
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.
| System.InvalidOperationException | Server is already running, or server/library have not been initailized. |
|
static |
Whether the server is currently being shut down.
|
staticgetset |
Interval at which Server checks for incoming connections. One player may be accepted per check. Default is 250ms.
|
staticgetset |
Interval at which Server checks for idle players (to kick idlers). Default is 30 seconds.
|
staticgetset |
|
staticgetset |
|
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.
|
staticgetset |
Interval at which Server checks whether forced garbage collection is needed. Default is 60 seconds.
|
staticgetset |
Internal IP address that the server's bound to (0.0.0.0 if not explicitly specified by the user).
|
staticgetset |
|
staticgetset |
Whether the server is currently running (true between Started and ShutdownEnded events).
|
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.
|
staticgetset |
Number of the local listening port.
|
staticgetset |
Time when the server started (UTC). Used to check uptime.
|
staticgetset |
Minecraft.net connection URL. May be null (if heartbeat is disabled, or first heartbeat has not been sent yet).
|
static |
Occurs when the server has been initialized.
|
static |
Occurs when the server is about to be initialized.
|
static |
Occurs when the player list has just changed (any time players connected or disconnected).
|
static |
Occurs when a player is searching for players (with autocompletion). The list of players in the search results may be replaced.
|
static |
Occurs any time a new session has connected, but before any communication is done.
|
static |
Occurs any time the server receives an incoming connection (cancelable).
|
static |
Occurs when a connection is closed or lost.
|
static |
Occurs when the server is about to start shutting down.
|
static |
Occurs when the server finished shutting down.
|
static |
Occurs when the server has just started.
|
static |
Occurs when the server is about to start.