Service#

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

KRPC.getClientID()#

Returns the identifier for the current client.

Return type:

Uint8Array

KRPC.getClientName()#

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

Return type:

string

KRPC.getClients()#

The clients that are currently connected to the server.

Property:

Read-only, cannot be set

Return type:

Array of KRPC.ClientInfo

KRPC.getStatus()#

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

Return type:

KRPC.ServerStatus

KRPC.getServices()#

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

Return type:

schema.Services

KRPC.holdTick()#

Hold the game on its current physics tick until KRPC.releaseTick() 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.

KRPC.releaseTick()#

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

KRPC.nextTick()#

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.releaseTick().

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

KRPC.getGameScene()#
KRPC.setGameScene(value)#

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.editorVAB and KRPC.GameScene.editorSPH 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.

Property:

Can be read or written

Return type:

KRPC.GameScene

KRPC.getPaused()#
KRPC.setPaused(value)#

Whether the game is paused.

Property:

Can be read or written

Return type:

boolean

KRPC.getGameStateLoads()#

The number of game states that have finished loading.

Property:

Read-only, cannot be set

Return type:

number

Note

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

class KRPC.GameScene()#

The game scene. See KRPC.getGameScene().

GameScene.spaceCenter#

The game scene showing the Kerbal Space Center buildings.

GameScene.flight#

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

GameScene.trackingStation#

The tracking station.

GameScene.editorVAB#

The Vehicle Assembly Building.

GameScene.editorSPH#

The Space Plane Hangar.

GameScene.missionBuilder#

The mission builder.

GameScene.astronautComplex#

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

GameScene.missionControl#

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

GameScene.researchAndDevelopment#

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

GameScene.administration#

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

class KRPC.ClientInfo(fields)#

A client connected to the server.

Note

See KRPC.getClients().

ClientInfo.id#

The identifier of the client.

Type:

Uint8Array

ClientInfo.name#

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

Type:

string

ClientInfo.address#

The address of the client.

Type:

string

class KRPC.ServerStatus(fields)#

The status of the server.

Note

See KRPC.getStatus().

ServerStatus.version#

The version of the server, or unknown.

Type:

string

ServerStatus.protocolVersion#

The protocol version of the connection.

Type:

number

ServerStatus.settings#

The settings of the server.

Type:

KRPC.ServerSettings

ServerStatus.statistics#

The performance statistics of the server.

Type:

KRPC.ServerStatistics

class KRPC.ServerSettings(fields)#

The settings that control how the server executes calls.

ServerSettings.adaptiveRateControl#

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

Type:

boolean

ServerSettings.targetFrameRate#

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

Type:

number

ServerSettings.maxTimePerFrame#

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

Type:

number

ServerSettings.maxCallWait#

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

Type:

number

ServerSettings.tickHoldTimeout#

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

Type:

number

class KRPC.ServerStatistics(fields)#

The performance statistics of the server.

ServerStatistics.bytesRead#

The number of bytes received from clients.

Type:

bigint

ServerStatistics.bytesWritten#

The number of bytes sent to clients.

Type:

bigint

ServerStatistics.bytesReadRate#

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

Type:

number

ServerStatistics.bytesWrittenRate#

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

Type:

number

ServerStatistics.rpcsExecuted#

The number of calls executed.

Type:

bigint

ServerStatistics.rpcRate#

The number of calls executed per second.

Type:

number

ServerStatistics.frameRate#

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

Type:

number

ServerStatistics.timePerFrame#

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

Type:

number

ServerStatistics.execTimePerFrame#

The time spent executing calls per frame, in seconds.

Type:

number

ServerStatistics.waitTimePerFrame#

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

Type:

number

ServerStatistics.streamTimePerFrame#

The time spent updating streams per frame, in seconds.

Type:

number

ServerStatistics.budgetPerFrame#

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

Type:

number

ServerStatistics.medianTurnaround#

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

Type:

number

ServerStatistics.deferredCalls#

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

Type:

number

ServerStatistics.streams#

The number of open streams, events included.

Type:

number

ServerStatistics.streamEvaluations#

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

Type:

bigint

ServerStatistics.streamEvaluationRate#

The number of stream evaluations per second.

Type:

number

ServerStatistics.streamUpdatesSent#

The number of stream updates sent to clients.

Type:

bigint

class KRPC.InvalidOperationException()#

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

A subclass of ServerError.

class KRPC.ArgumentException()#

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

A subclass of the builtin TypeError alone.

class KRPC.ArgumentNullException()#

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

A subclass of the builtin TypeError alone.

class KRPC.ArgumentOutOfRangeException()#

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

A subclass of the builtin RangeError alone.

class KRPC.NullReferenceException()#

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

A subclass of the builtin TypeError alone.

class KRPC.KeyNotFoundException()#

A key was not found in a dictionary.

A subclass of ServerError.

class KRPC.IndexOutOfRangeException()#

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

A subclass of the builtin RangeError alone.

class KRPC.DivideByZeroException()#

An integer was divided by zero.

A subclass of the builtin RangeError alone.

class KRPC.NotSupportedException()#

A method was invoked that is not supported.

A subclass of ServerError.

class KRPC.TimeoutException()#

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

A subclass of ServerError.

class KRPC.OverflowException()#

An arithmetic or conversion operation overflowed.

A subclass of the builtin RangeError alone.

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.

A subclass of ServerError.

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.

A subclass of ServerError.

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.

A subclass of ServerError.

class KRPC.StreamRemovedException()#

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

An alias of StreamError.

class KRPC.Error()#

A general error, described by its message.

A subclass of ServerError.