Service#

Main kRPC service, used by clients to interact with basic server functionality.

staticmethod KRPC.get_client_id(): string#

Returns the identifier for the current client.

staticmethod KRPC.get_client_name(): string#

Returns the name of the current client. This is an empty string if the client has no name.

KRPC.clients: List#

The clients that are currently connected to the server.

Attribute:

Read-only, cannot be set

staticmethod KRPC.get_status(): KRPC.ServerStatus#

Returns the status of the server, with its version, settings and performance statistics.

staticmethod KRPC.get_services(): krpc.schema.Services#

The services the server provides, with their procedures, classes, enumerations, structures and exceptions.

staticmethod KRPC.hold_tick()#

Hold the game on its current physics tick until KRPC.release_tick() is called or the hold times out. Every call made in between is executed before the game advances, so a read, compute and write all happen in the state of one tick.

Note

The game renders no frame, takes no input and runs no physics while the tick is held. Keep a hold as short as possible, and release it even when the code between the two calls fails.

A tick is held once, so this waits for the next tick when the current one has already been released. One client holds the tick at a time, and only a client making a call can hold it: a stream or an event cannot.

A hold ends by itself when it times out, when the client disconnects, and when the client calls a procedure that takes more than one tick to finish, such as staging or warping. Stream updates are sent once the tick is released, so waiting for a stream or an event inside a hold waits out the timeout.

staticmethod KRPC.release_tick()#

Let the game move on from the tick that KRPC.hold_tick() held it on. Does nothing when no tick is held, which is the case once a hold has timed out.

staticmethod KRPC.next_tick()#

Let the game move on from the tick being held and hold the one after it, so that a program acts on consecutive physics ticks. Holds the soonest tick it can if no tick is currently being held.

Note

A release and a hold made as two separate calls let the game advance between them. This takes the next tick without that gap. Call it at the top of a loop that has to act on every tick, work, and come back to it.

The game advances one tick per call, so it runs at the rate of the loop for as long as the loop runs. End the loop with KRPC.release_tick().

Every limit of KRPC.hold_tick() applies, the timeout included. A hold lost to the timeout is not reported, and the next call takes whatever tick it lands on.

KRPC.game_scene: KRPC.GameScene#

The current game scene. Setting this switches the game to the given scene, or opens/closes the corresponding facility for the pseudo-scenes. Scene changes happen asynchronously: setting this property returns immediately, and clients should poll it until it reports the requested scene. Setting it to KRPC.GameScene.flight resumes the save’s active vessel, and fails if there is none. Moving between KRPC.GameScene.editor_vab and KRPC.GameScene.editor_sph keeps the vessel that is being constructed, as the game’s own switch editor button does. Leaving flight saves the game first, unless the game cannot be saved, e.g. while under acceleration.

Attribute:

Can be read or written

KRPC.paused: boolean#

Whether the game is paused.

Attribute:

Can be read or written

KRPC.game_state_loads: number#

The number of game states that have finished loading.

Attribute:

Read-only, cannot be set

Note

Increases once a game load, quickload, revert or scene change has finished.

class KRPC.GameScene#

The game scene. See KRPC.game_scene.

space_center#

The game scene showing the Kerbal Space Center buildings.

flight#

The game scene showing a vessel in flight (or on the launchpad/runway).

tracking_station#

The tracking station.

editor_vab#

The Vehicle Assembly Building.

editor_sph#

The Space Plane Hangar.

mission_builder#

The mission builder.

astronaut_complex#

The astronaut complex. This is a pseudo-scene, shown when the astronaut complex facility is open within the space center scene.

mission_control#

Mission control. This is a pseudo-scene, shown when the mission control facility is open within the space center scene.

research_and_development#

Research and development. This is a pseudo-scene, shown when the research and development facility is open within the space center scene.

administration#

The administration facility. This is a pseudo-scene, shown when the administration facility is open within the space center scene.

class KRPC.ClientInfo#

A client connected to the server.

Note

See KRPC.clients.

id: string#

The identifier of the client.

name: string#

The name of the client, or an empty string if it has no name.

address: string#

The address of the client.

class KRPC.ServerStatus#

The status of the server.

Note

See KRPC.get_status().

version: string#

The version of the server, or unknown.

protocol_version: number#

The protocol version of the connection.

settings: KRPC.ServerSettings#

The settings of the server.

statistics: KRPC.ServerStatistics#

The performance statistics of the server.

class KRPC.ServerSettings#

The settings that control how the server executes calls.

adaptive_rate_control: boolean#

Whether the server adapts its time per frame to hold the frame rate at KRPC.ServerSettings.target_frame_rate.

target_frame_rate: number#

The lowest frame rate the server’s work pushes the game to, in frames per second.

max_time_per_frame: number#

The server’s budget per frame, or its ceiling with adaptive rate control, in microseconds.

max_call_wait: number#

The longest the server waits for a client’s next call, in microseconds.

tick_hold_timeout: number#

The longest time a client may hold the game on one physics tick, in microseconds.

class KRPC.ServerStatistics#

The performance statistics of the server.

bytes_read: number#

The number of bytes received from clients.

bytes_written: number#

The number of bytes sent to clients.

bytes_read_rate: number#

The rate bytes are received from clients, in bytes per second.

bytes_written_rate: number#

The rate bytes are sent to clients, in bytes per second.

rpcs_executed: number#

The number of calls executed.

rpc_rate: number#

The number of calls executed per second.

frame_rate: number#

The game’s frame rate, in frames per second.

time_per_frame: number#

The server’s time per frame, in seconds: executing calls, waiting for them and updating streams.

exec_time_per_frame: number#

The time spent executing calls per frame, in seconds.

wait_time_per_frame: number#

The time spent waiting for calls per frame, in seconds.

stream_time_per_frame: number#

The time spent updating streams per frame, in seconds.

budget_per_frame: number#

The time the server may spend per frame, in seconds.

median_turnaround: number#

The median time between a response and the client’s next call, over the clients’ recent calls, in seconds.

deferred_calls: number#

The number of calls left for the next update, because the update ran out of time or the call yielded.

streams: number#

The number of open streams, events included.

stream_evaluations: number#

The number of stream evaluations, one per stream per update.

stream_evaluation_rate: number#

The number of stream evaluations per second.

stream_updates_sent: number#

The number of stream updates sent to clients.

class KRPC.InvalidOperationException#

A method call was made to a method that is invalid given the current state of the object.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'InvalidOperationException'.

class KRPC.ArgumentException#

A method was invoked where at least one of the passed arguments does not meet the parameter specification of the method.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'ArgumentException'.

class KRPC.ArgumentNullException#

A null reference was passed to a method that does not accept it as a valid argument.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'ArgumentNullException'.

class KRPC.ArgumentOutOfRangeException#

The value of an argument is outside the allowable range of values as defined by the invoked method.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'ArgumentOutOfRangeException'.

class KRPC.NullReferenceException#

A value was null where its type does not allow one.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'NullReferenceException'.

class KRPC.KeyNotFoundException#

A key was not found in a dictionary.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'KeyNotFoundException'.

class KRPC.IndexOutOfRangeException#

An index was outside the bounds of a collection, string or array.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'IndexOutOfRangeException'.

class KRPC.DivideByZeroException#

An integer was divided by zero.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'DivideByZeroException'.

class KRPC.NotSupportedException#

A method was invoked that is not supported.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'NotSupportedException'.

class KRPC.TimeoutException#

An operation did not complete in the time allotted to it.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'TimeoutException'.

class KRPC.OverflowException#

An arithmetic or conversion operation overflowed.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'OverflowException'.

class KRPC.ObjectDestroyedException#

The game object that a service object refers to no longer exists, so the object cannot be used. For example, the part it represents was destroyed, or the vessel it belongs to was recovered.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'ObjectDestroyedException'.

Note

See KRPC.ObjectNotLoadedException for a game object that exists but is not loaded.

class KRPC.ObjectNotLoadedException#

The game object that a service object refers to exists, but is not loaded. For example, the game is loading, or the vessel carrying the part is unloaded.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'ObjectNotLoadedException'.

Note

See KRPC.ObjectDestroyedException for a game object that no longer exists.

class KRPC.UnsupportedSceneException#

The procedure is not available in the current game scene.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'UnsupportedSceneException'.

class KRPC.StreamRemovedException#

A stream was removed by the server, e.g. an event that has finished.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'StreamRemovedException'.

class KRPC.Error#

A general error, described by its message.

Raised as a krpc.ServerError whose service and name are 'KRPC' and 'Error'.