Server Side Functions#

A server side function is code that runs inside the game, on the server. It has three main uses:

  • Custom events wait for a condition to become true. The server checks the condition every physics tick, and sends your program a message when it fires. Polling from your program adds a round trip to every check, and can miss a condition that holds for only a few ticks.

  • Function streams stream the result of a computation over several RPC values. The server reads every value in the same physics tick, so the values are consistent. It sends the result to your program when the result changes.

  • Run-once functions run a sequence of calls and computation in a single physics tick, from a single RPC. They can set properties and trigger actions. The same calls made from your program take a round trip each, and the game advances between them.

This guide is in two parts. Using Server Side Functions covers functions written in your own language and compiled by the client, and is all most users need. The Expression API covers the expression trees that compiled code translates into, which every client can build directly.

Every client supports Run. Support for the other features differs:

Client

Compiled functions

Events and function streams

Python

✓

✓

C#

✓

✓

C++

✗

✓

C-nano

✗

✗

Java

✗

✓

Lua

✗

✗

JavaScript

✓

✓

Using Server Side Functions#

A client with a compiler turns a function or lambda into a server side function. It is the simplest way to write one. The constructs a compiler supports depend on the language. Without a compiler, the expression API defines a server side function directly.

A First Custom Event#

This event fires when the vessel’s altitude exceeds 1000 meters:

event = conn.add_event(lambda: flight.mean_altitude > 1000)
with event.condition:
    event.wait()
    print("Altitude reached 1000m")

The client compiles the lambda into a server side function. The mean altitude call becomes an embedded RPC, re-invoked on each check. 1000 becomes a constant.

The server checks the condition every physics tick until it is true. It then sends your program a single message, which ends the wait. Your program makes no polling calls while it waits, so it uses no round trips and no CPU time.

Remote Calls and Captured Values#

The compiler splits a function by what each part depends on:

  • Reading a property or calling a method of a remote object or service becomes part of the function. The server re-invokes it on every evaluation. So does any operation on its result.

  • A sub-expression that uses only client side values, such as captured variables and literals, is evaluated once, when the function is compiled. That includes arithmetic and library calls on those values. The result becomes a constant.

For example:

threshold = 50000
event = conn.add_event(
    lambda: vessel.orbit.apoapsis_altitude > threshold * 2
)

The client computes threshold * 2 when it creates the event, so the function compares the apoapsis with the constant 100000. To use a new value of threshold, compile a new function and remove the old event.

Computed Streams#

A stream created from a function carries the function’s result. The server runs the computation on each stream update:

# The vessel's altitude, in kilometers, computed on the server
stream = conn.add_stream(lambda: flight.mean_altitude / 1000)
print("Altitude:", stream(), "km")

A function can produce a collection. This streams the thrust of every engine on the vessel, read in a single physics tick per update:

engines = vessel.parts.engines
stream = conn.add_stream(lambda: [engine.thrust for engine in engines])
for thrust in stream():
    print(thrust)

Here engines is a captured variable, so the list of engines is fixed when the function is compiled. The server re-reads only their thrusts. Read the engine list inside the function to have the server fetch the list on each update. That follows staging, at the cost of extra work per update.

Collections#

The language’s collection operations, such as mapping, filtering, counting, summing and sorting, compile to the server’s collection operations. This event fires when any engine on the vessel runs out of fuel. The server re-reads the engine list on each check, so the event covers engines that staging reveals:

event = conn.add_event(
    lambda: any(not engine.has_fuel for engine in vessel.parts.engines)
)
with event.condition:
    event.wait()
    print("An engine has run out of fuel")

Strings#

The language’s string operations, such as length, indexing, searching, splitting and case conversion, compile to the server’s string operations. This streams the vessel’s name in upper case:

stream = conn.add_stream(lambda: vessel.name.upper())

Two rules apply to strings:

  • A character is a string of length one. The protocol carries no character type, so indexing a string produces a one character string, which works with every other string operation. In a language where indexing a string produces a character, that index is an unsupported construct. Take a substring instead.

  • Case conversion and comparison are the same in every locale. Case is converted, and strings are compared, by ordinal value. A function produces the same result whatever language the game runs in.

Statements, Loops and Local Variables#

A compiled function can be a sequence of statements, like any other function in your program. This one computes the fraction of liquid fuel left:

def fuel_fraction():
    resources = vessel.resources
    amount = resources.amount("LiquidFuel")
    capacity = resources.max("LiquidFuel")
    return amount / capacity


stream = conn.add_stream(fuel_fraction)

In outline, a compiled function supports these statements:

  • If statements, with else branches.

  • While and for-each loops, with break and continue.

  • Early returns.

  • Local variables, which can be reassigned and changed in place. A loop can build up a collection in one.

The exact set depends on the language. Each client guide lists what its compiler supports: C#, JavaScript and Python.

A collection a call returns is a copy, as it is in your program. Changing the copy in a function leaves the game’s own collection unchanged.

This function collects a rating for each active engine:

def burn_ratings():
    ratings: list[str] = []
    for engine in vessel.parts.engines:
        if not engine.active:
            continue
        if engine.thrust > 0.9 * engine.available_thrust:
            ratings.append("full")
        else:
            ratings.append("partial")
    return ratings


print(conn.run(burn_ratings))

A variable keeps one type for the whole function. How it gets that type depends on the language:

A variable takes its type from its first assignment. A type annotation sets the type, and each value assigned then widens to it, as an integer does to a float:

def total_thrust():
    total: float = 0
    for engine in vessel.parts.engines:
        total += engine.thrust
    return total


print(conn.run(total_thrust))

An empty collection takes its element type the same way, as in ratings: list[str] = [] above.

Side Effects and Run-Once Functions#

A compiled function can also change the game. It can assign to the properties of remote objects and services, and call methods for their effects. Pass such a function to Run, which evaluates it once, with every step in the same physics tick:

def deploy():
    for parachute in vessel.parts.parachutes:
        if not parachute.deployed:
            parachute.deploy()


conn.run(deploy)

Note

An event or stream runs its function on every stream update, effects included. See Control Loops on the Server.

Note

A procedure that runs over several ticks, such as SpaceCenter.WarpTo, is an error in a function. See Errors, Edge Cases and Performance.

Function Arguments#

A compiled function can take parameters, and Run passes it a value for each. One function then serves many inputs. This computes how long a burn takes, for several changes in velocity:

The function is a def with a type annotation on each parameter. Its arguments bind as Python binds them, with defaults and keyword arguments:

@conn.compile
def burn_time(delta_v: float) -> float:
    exhaust_velocity = vessel.specific_impulse * 9.82
    final_mass = vessel.mass / math.exp(delta_v / exhaust_velocity)
    return (
        (vessel.mass - final_mass)
        * exhaust_velocity
        / vessel.available_thrust
    )


for delta_v in (100.0, 250.0, 400.0):
    print(conn.run(burn_time, delta_v))

An event or a stream runs its function with no arguments.

State Between Updates#

A function can keep a value from one evaluation to the next, such as a running total. This stream counts the stream updates in which the engines are firing:

Declare a captured variable nonlocal:

def firing_counter():
    updates = 0

    @conn.compile
    def count():
        nonlocal updates
        if vessel.thrust > 0:
            updates += 1
        return updates

    return count


stream = conn.add_stream(firing_counter())

The variable takes its type from its value when the function is compiled. To give it another type, such as a list that starts empty, start the function with a cast of it: history = cast(List[float], history).

The state lives on the server. It starts with the variable’s value at compile time, and changes to it do not reach the variable in the client program.

A function passed straight to Run or a stream is compiled on each call, so each call gets its own state. A function compiled once with compile keeps one state across every run, stream and event that uses it. Two streams of it advance the state twice per update.

Control Loops on the Server#

A stream of a function with no value runs the function on every stream update, for its effects. Such a stream can run a control loop in the game, with no round trip to the client. This one throttles back as the vertical speed nears 100 m/s:

@conn.compile
def limit_throttle():
    # Throttle back as the vertical speed nears 100 m/s
    control.throttle = max(0, min(1, (100 - flight.vertical_speed) / 20))


with conn.add_stream(limit_throttle):
    time.sleep(60)

The stream’s value is the client’s null value. The server sends it once, after the first run, so a callback is called once. An error from the function ends the stream and stops the loop. Set the stream’s rate to run the function less often.

Exceptions#

A function can raise an exception. It reaches your program as an error when run, or as an error on the stream or event evaluating the function:

@conn.compile
def check_fuel():
    if vessel.resources.amount("LiquidFuel") < 100:
        raise RuntimeError("not enough fuel")

Your program catches the error as an exception, as it does for an error from any other call.

A function can also handle an exception, with the language’s try statement:

@conn.compile
def switch_modes() -> str:
    try:
        for engine in vessel.parts.engines:
            engine.toggle_mode()
        return "switched"
    except Exception as error:
        return "could not switch: " + error

These rules apply to handlers:

  • Only the message of an exception is exposed. The variable a handler binds is a string holding the message. In JavaScript, the handler reads it as e.message.

  • A handler also catches exceptions from the calls in the function. A handler for an exception catches it whether the function raises it, or a remote procedure the function calls does.

  • A procedure that pauses execution passes through every handler, including a catch-all. It is reported as an error.

  • Some errors are caught only by a catch-all handler, as they have no exception class to name. These are a call to a procedure that is unavailable in the current game scene, and a procedure that returns null when its return type does not allow it. Uncaught, each reaches your program as a plain error.

The Standard Library#

The StdLib service is a standard library for server side functions, with mathematics, vector and quaternion operations, and printing. Calls to the language’s math library compile to the matching StdLib procedures when their arguments are computed on the server. Call the service directly for the vector and quaternion operations. This streams the angle between the vessel’s facing direction and its velocity relative to the surface:

stdlib = conn.std_lib
frame = vessel.orbit.body.reference_frame
stream = conn.add_stream(
    lambda: stdlib.radians_to_degrees(
        stdlib.vector_angle(vessel.direction(frame), vessel.velocity(frame))
    )
)

The service covers:

  • Scalar functions, such as square roots, trigonometry and clamping, and the constants pi and e.

  • Vector operations on the position and direction tuples of the SpaceCenter service, such as dot and cross products, magnitudes, angles and interpolation.

  • Quaternion operations on its rotation tuples, such as composition, inverses, rotating vectors and interpolation.

Each midpoint rounding rule has its own procedure, so a function can round the way its language does:

Each takes the number of decimal places, negative for tens and hundreds.

Printing#

The language’s print function compiles to StdLib.print(), which writes a line to the game’s log, KSP.log. This logs the vessel’s mass from the server:

conn.run(lambda: print("Mass:", vessel.mass, "kg"))

A print in an event or stream function writes a line on every stream update.

Supported Constructs#

Each client guide lists the constructs its compiler supports, and where their meaning differs from the language’s: C#, JavaScript and Python. Any other construct is a compilation error that names it.

Reusing Functions#

Passing a new lambda to run in a loop builds a new function on each pass. Each pass reads the lambda’s captured variables again, while a compiled function keeps the values from when it was compiled.

In such cases, compile the function once, and run the compiled function as often as needed. To run it with different values, give it parameters, as in Function Arguments:

step = conn.compile(lambda: vessel.control.toggle_action_group(1))
while True:
    conn.run(step)

A large lambda passed on every call can make the game stutter. The server compiles each one to native code on the game’s main thread. Compile a function before it is needed, such as before launch, and every run is fast.

Errors, Edge Cases and Performance#

Errors. An error raised while evaluating a stream or event function reaches your program when it reads the stream or event. An example is an embedded call reaching a destroyed part.

The server then removes the stream, as it does for any stream whose result is an error. Build a new event or stream once the cause clears.

Loads and unloaded vessels. A stream of a remote procedure pauses while its object is not loaded, and resumes after. A function stream or event ends instead, with KRPC.ObjectNotLoadedException. Examples are a part of an unloaded vessel, and a vessel part way through a load. To keep one running, catch the exception in the function:

import krpc

conn = krpc.connect()
vessel = conn.space_center.active_vessel
flight = vessel.flight()


def above_1000m() -> bool:
    try:
        return flight.mean_altitude > 1000
    except conn.krpc.ObjectNotLoadedException:
        return False


event = conn.add_event(above_1000m)
with event.condition:
    event.wait()
    print("Altitude reached 1000m")

The handler gives False, so the event does not fire while the vessel loads.

Procedures that pause. Some procedures pause execution and resume on a later tick, such as SpaceCenter.WarpTo and SpaceCenter.LaunchVessel. Calling one is an error in any function. The procedure keeps its effects up to the pause, so a WarpTo called this way leaves the game warping.

Note

A future release is planned to support these procedures in server side functions.

Loops run to completion. A while loop runs to its end within a single tick, before the game continues. A loop that never ends freezes the game for good. The only way out is to force quit the game, which loses any progress since the last save. No compiler check can catch such a loop, so bound every loop by a value that is certain to change.

Note

A future release is planned to stop a loop that runs for too long, with a time limit set in the server settings.

Null values. A null where the function needs a value raises a NullReferenceException when the function runs. Examples are a null operand in arithmetic, and a null argument to a call. Your program receives it as the closest built-in exception of its language.

Some procedures return null, such as Part.engine for a part that is not an engine. Compare the result with null before using it.

A function can produce a null. A compiled null takes its type from where it is used, such as the other assignment to a variable or the other branch of a conditional:

def heaviest_engine():
    best = None
    for engine in vessel.parts.engines:
        if best is None or engine.part.mass > best.part.mass:
            best = engine
    return best

Elsewhere, give a null its type with a type annotation or a cast.

Costs. A function is evaluated on the server as native code, and only its result crosses the network. Even a large function evaluates quickly. A function stream can run a full autopilot control loop every physics tick, as in Control Loops on the Server.

The Expression API#

The expression API builds a server side function node by node. The compilers use it under the hood.

Note

The C-nano and Lua clients have no events or streams, so their examples run each function once, with krpc_run_function in C and conn:run in Lua.

Expression Trees#

A server side function is a tree of expression objects held on the server, built with the static methods of the Expression class. The server compiles the tree to native code, so evaluations are fast.

Each node is a constant, an embedded remote procedure call, an operator, a statement or a nested function. Statements are assignments, loops and if statements.

You use a tree in one of three ways:

  • An event, from a function that evaluates to a boolean. The server evaluates the function on each stream update, and triggers the event when it returns true.

  • A stream, from a function whose value can be sent to a client, such as a number, a string, a collection or an object. The value is recomputed on each stream update.

  • A run, which evaluates a function once, within a single physics tick, and returns its value. Useful for a function with side effects.

Two rules hold for every server side function:

  • Embedded remote procedure calls are re-invoked on every evaluation. Constants, and the values your program supplies when building the function, are fixed when the function is created.

  • The whole function is evaluated within a single physics tick. A function that reads the fuel level of every engine reads them all in the same tick.

Expression Objects#

The altitude event from the start of this guide has three nodes: an embedded call, a constant and a comparison:

import krpc

conn = krpc.connect()
vessel = conn.space_center.active_vessel
flight = vessel.flight()

# Convert a remote procedure call to a message,
# so it can be passed to the server
mean_altitude = conn.get_call(getattr, flight, "mean_altitude")

# Build the function on the server
expr = conn.krpc.Expression.greater_than(
    conn.krpc.Expression.call(mean_altitude),
    conn.krpc.Expression.constant_double(1000),
)

# Create an event from the function
event = conn.add_event(expr)

# Wait on the event
with event.condition:
    event.wait()
    print("Altitude reached 1000m")

Two kinds of object appear here:

  • A procedure call message describes an RPC without invoking it. Each client builds one from a call written in its own language, as the examples show. Building a call message is a local operation.

  • An expression object is a node of the tree. Expression.call() embeds a procedure call message, which the server invokes on each evaluation. A procedure with no return value embeds as a statement.

A call message carries its arguments, as the call for a stream does. A call template carries none, for Expression.call_with_arguments() to give each one as an expression. See Functions and Collections.

Each factory method is an RPC that creates one node on the server and returns a handle to it.

The factory methods are static methods of the Expression class, and each needs a connection to send its RPC on:

Reach the class through the connection, as conn.krpc.Expression. Its methods use that connection.

Operators and Types#

This truncates the altitude to a whole number of meters:

# Truncate the altitude to a whole number of meters
expr = expression.cast(expression.call(mean_altitude), types.int())

Expressions are statically typed, with the types of the server’s procedures. Numbers of different types convert to a common type, so an integer multiplies a double directly.

The same conversion applies to a procedure’s arguments, a collection’s elements, a structure’s fields and an assigned variable, and each conversion must widen. Expression.cast() converts a value explicitly, for example to narrow a double to an integer.

The Type class names types, including the classes, enumerations and structures a service defines. Each type of constant has its own factory method, such as Expression.constant_double().

A class, an enumeration, a structure or an exception is named by its service and its name, such as "SpaceCenter", "Engine". Each procedure that takes the names has a variant that takes the ids KRPC.get_services() reports, such as Type.class_type_by_id(). The C examples use them.

Each operator has a factory method, such as Expression.add().

Function Streams#

A function whose value can be sent to a client can be streamed. A function with no value can be streamed too, and runs for its effects, as in Control Loops on the Server:

import time

import krpc

conn = krpc.connect()
vessel = conn.space_center.active_vessel
flight = vessel.flight()

expression = conn.krpc.Expression

# Build a function that computes
# the vessel's altitude in kilometers
expr = expression.divide(
    expression.call(conn.get_call(getattr, flight, "mean_altitude")),
    expression.constant_double(1000),
)

# Stream the value of the function
stream = conn.add_stream(expr)
while True:
    print("Altitude:", stream(), "km")
    time.sleep(1)

Some clients take the type of the stream’s values as a type argument, and others read the function’s return type from the server. A function stream behaves like any other stream, and its rate can be limited in the usual way.

Functions and Collections#

This builds the “any engine out of fuel” event from earlier. The call names the procedure through the Engine class, with no engine:

import krpc

conn = krpc.connect()
expression = conn.krpc.Expression
types = conn.krpc.Type
vessel = conn.space_center.active_vessel

# A function taking an engine, returning true if it is out of fuel
engine = expression.parameter(
    "engine", types.class_type("SpaceCenter", "Engine")
)
has_fuel = conn.space_center.Engine.has_fuel
out_of_fuel = expression.lambda_(
    [engine],
    expression.not_(expression.call_with_arguments(has_fuel, {0: engine})),
)

# Whether any engine satisfies it
engines = conn.get_call(getattr, vessel.parts, "engines")
expr = expression.any(expression.call(engines), out_of_fuel)

event = conn.add_event(expr)
with event.condition:
    event.wait()
    print("An engine has run out of fuel")

A function passed to a collection operation is built from two pieces:

  • Expression.parameter() creates a named, typed parameter. The type can be a class, so a parameter can be an Engine.

  • Expression.lambda_() combines a list of parameters and a body into a function. In the body, the parameter expressions stand for the arguments.

To call an RPC on each element, take the call’s instance from the function’s parameter. Expression.call_with_arguments() embeds a call with its arguments given as expressions. Each expression is keyed by the position of its parameter, and position 0 is the instance.

The call is a call template, which names the procedure through its class and carries no arguments. In Python, Lua and JavaScript, the member itself stands for its call template, as has_fuel does in the Python example. A position without an expression takes the parameter’s default. A call that carries arguments, such as one built from an engine, raises an error.

Expression.invoke() calls a function directly, binding values to its parameters by name.

A function from Expression.lambda_() can also be run on its own. Run passes its arguments to the function’s parameters in order, and Expression.parameter_types gives their types.

Expression.select() applies a function to every element, and Expression.where() filters by a predicate. Both produce lazy sequences, which a client cannot decode. Convert one with Expression.to_list() or Expression.to_set() before streaming it. The aggregations, such as Expression.sum() and Expression.any(), take lazy sequences directly.

The Expression class has the other usual collection operations, such as ordering, grouping and set operations, and a constructor for each kind of collection. A function can change a collection in place, with operations such as Expression.append() and Expression.remove().

A dictionary is iterated through its keys or its values. Expression.dictionary_keys() and Expression.dictionary_values() each produce a list. Passing a dictionary to a collection operation is an error that points at them. Expression.contains_key() tests for a key. Expression.get() of a missing key raises a KeyNotFoundException, and of a list index out of range an IndexOutOfRangeException.

The index into a tuple must be a constant. The elements of a tuple differ in type, and Expression.get() takes its result type from the index. A list or a dictionary takes any index expression.

Structures#

A structure a service defines is a value like any other. A function can return, stream, pass and build one. Expression.get_field() reads a field by name:

# The Name field of a structure a call returns
expr = expression.get_field(expression.call(site_info), "Name")

Expression.create_struct() builds a structure from its type and its field values, in the order the structure declares them. A field’s name is the one the service declares, as shown in the API documentation. Expression.get_field_by_index() reads a field by its position in that order, counting from 0.

The compilers produce both nodes from ordinary syntax. Reading a field of a structure compiles to Expression.get_field(), and constructing one compiles to Expression.create_struct().

Statements, Variables and Loops#

This builds and runs total = 0; for x in [1, 2, 3]: total += x, which returns 6:

import krpc

conn = krpc.connect()
expression = conn.krpc.Expression
types = conn.krpc.Type

# total = 0; for x in [1, 2, 3]: total += x
total = expression.variable("total", types.int())
x = expression.variable("x", types.int())
values = expression.create_list(
    [expression.constant_int(i) for i in [1, 2, 3]]
)
program = expression.block_with_variables(
    [total, x],
    [
        expression.assign(total, expression.constant_int(0)),
        expression.for_each(
            x, values, expression.assign(total, expression.add(total, x))
        ),
        total,
    ],
)

print(conn.run(program))

Statements are ordinary expression nodes. Expression.block_with_variables() sequences statements and declares local variables, and its value is the value of its last statement.

The other statements, such as assignments, if statements, loops and early returns, each have a factory method. A call to a procedure without a return value is a statement, run for its effects.

Match and Switch Statements#

This loop adds 10 to a total for the values 1 and 2, and 1 for any other value. It returns 21:

import krpc

conn = krpc.connect()
expression = conn.krpc.Expression
types = conn.krpc.Type

# total = 0
# for x in [1, 2, 3]:
#     match x:
#         case 1 | 2: total += 10
#         case _: total += 1
total = expression.variable("total", types.int())
x = expression.variable("x", types.int())
values = expression.create_list(
    [expression.constant_int(i) for i in [1, 2, 3]]
)
body = expression.match(
    x,
    [[expression.constant_int(1), expression.constant_int(2)], []],
    [
        expression.assign(
            total, expression.add(total, expression.constant_int(10))
        ),
        expression.assign(
            total, expression.add(total, expression.constant_int(1))
        ),
    ],
)
program = expression.block_with_variables(
    [total, x],
    [
        expression.assign(total, expression.constant_int(0)),
        expression.for_each(x, values, body),
        total,
    ],
)

print(conn.run(program))

Expression.match() takes the value, the test values of each case and the body of each case. It runs the body of the first case with a test value equal to the value, as Expression.equal() compares them. The test values are evaluated in order, up to the first match. A case with no test values is the default. A Expression.break_() in a body ends the enclosing loop, as in Python’s match. The Python client compiles the cases of a match statement that have no guard to it.

Expression.switch() takes the same arguments, and behaves as switch in C, C++, Java and JavaScript. It runs the bodies from the matching case on, and a Expression.break_() in a body ends the switch.

A switch in C, C++, C# or Java becomes a Expression.switch() with its breaks kept. When each case ends in a break, as in the example, it can also become a Expression.match() with the breaks dropped.

Object Constants#

Expression.constant_object() embeds a reference to an object, such as a vessel, a reference frame or an engine. A function can compare it for equality, or pass it to a call built with Expression.call_with_arguments(). This event fires when the vessel’s target changes to a particular vessel:

target = conn.get_call(getattr, conn.space_center, "target_vessel")
expr = expression.equal(
    expression.call(target),
    expression.constant_object(krpc.get_object_id(some_vessel)),
)
event = conn.add_event(expr)

Expression.constant_object() takes the object’s identifier in the communication protocol. Each client has a function that returns it: krpc.get_object_id in Python and Lua, RemoteObject.GetObjectId in C#, krpc::get_object_id in C++, RemoteObject.getObjectId in Java and getObjectId in JavaScript. In C, an object’s handle is its identifier. The compilers embed a captured remote object this way.

Exceptions in the Expression API#

Expression.throw() raises an exception, named by its service and class. This builds the fuel check from Exceptions:

amount = conn.get_call(vessel.resources.amount, "LiquidFuel")
expr = expression.if_then(
    expression.less_than(
        expression.call(amount), expression.constant_double(100)
    ),
    expression.throw(
        "KRPC",
        "InvalidOperationException",
        expression.constant_string("not enough fuel"),
    ),
)
conn.run(expr)

Expression.try_catch(), Expression.try_catch_all() and Expression.try_finally() handle exceptions.

Extensibility#

A server side function can call any remote procedure, including those of services that other mods add. The one exception is the KRPC service, which builds and runs the functions.

To give functions a new capability, write a service. Its procedures are available to server side functions on every client.