Skip to main content

ServerNetworkAPI

ServerNetworkAPI exposes the game's server networking layer — sessions, connections, and the two transport servers (RUDPServer for UDP, SDRServer for Steam relay). Most of this is only meaningful on the host.

How the server is structured

VWorld
├── _rudpServer → RUDPServer (UDP / LiteNetLib)
├── _sdrServer → SDRServer (Steam relay)
└── _sessionManager → SessionManager
└── m_Contexts → Dictionary<long, SessionContext> (connected players)

Server state

IsServerRunning()

public static bool IsServerRunning()

Returns true if VWorld is available. Use this before calling anything else.

if (!ServerNetworkAPI.IsServerRunning())
{
MelonLogger.Msg("Not hosting");
return;
}

GetServerSocket()

public static object? GetServerSocket()

Returns the SDRServer if available, otherwise the RUDPServer. Useful when you need to pass a socket to SetMaximumClients.

GetRudpServer() / GetSdrServer()

public static object? GetRudpServer()
public static object? GetSdrServer()

Access the individual transport servers directly.

Sessions and clients

GetSessionCount() / GetCurrentClientCount()

public static int GetSessionCount()
public static int GetCurrentClientCount()

Number of active sessions from SessionManager.m_Contexts. Both methods return the same value.

GetMaximumClients()

public static int GetMaximumClients()

Calls VRoomManager.GetPlayerCountInSession().

SetMaximumClients()

public static void SetMaximumClients(object serverSocket, int value)

Sets _maximumClients on the socket object.

var socket = ServerNetworkAPI.GetServerSocket();
if (socket != null)
ServerNetworkAPI.SetMaximumClients(socket, 16);

GetAllConnectedPlayers()

public static List<object> GetAllConnectedPlayers()

Returns all SessionContext objects from SessionManager.m_Contexts.

Room helpers

These filter RoomAPI.GetAllRooms() by type name — no separate room lookup needed.

GetWaitingRoom() / GetMaintenanceRoom()

public static object? GetWaitingRoom()
public static object? GetMaintenanceRoom()

GetWaitingRoomMemberCount() / GetMaintenanceRoomMemberCount()

public static int GetWaitingRoomMemberCount()
public static int GetMaintenanceRoomMemberCount()

GetWaitingRoomMaxPlayers() / GetMaintenanceRoomMaxPlayers()

public static int GetWaitingRoomMaxPlayers()
public static int GetMaintenanceRoomMaxPlayers()

CanPlayerEnterWaitingRoom()

public static bool CanPlayerEnterWaitingRoom(long playerUID)

Calls CanEnterChannel(playerUID) on the waiting room and checks for MsgErrorCode.Success.

IsPlayerInRoom()

public static bool IsPlayerInRoom(object room, long playerUID)

Scans _vPlayerDict for a matching UID.

Room player helpers

GetRoomPlayerCount()

public static int GetRoomPlayerCount(object? room)

GetRoomPlayerDictionary()

public static IDictionary? GetRoomPlayerDictionary(object? room)

Assembly helpers

GetGameAssembly()

public static Assembly? GetGameAssembly()

Returns the Assembly-CSharp assembly. Useful for finding types at runtime.

GetIVroomType() / GetGameSessionInfoType()

public static Type? GetIVroomType()
public static Type? GetGameSessionInfoType()

Full example — server status panel

public override void OnGUI()
{
if (!ServerNetworkAPI.IsServerRunning()) return;

int sessions = ServerNetworkAPI.GetSessionCount();
int inSession = ServerNetworkAPI.GetMaximumClients();
int waiting = ServerNetworkAPI.GetWaitingRoomMemberCount();

GUILayout.BeginArea(new Rect(10, 10, 250, 100));
GUILayout.Label($"Sessions: {sessions}");
GUILayout.Label($"In session: {inSession}");
GUILayout.Label($"In lobby: {waiting}");
GUILayout.EndArea();
}
warning

Most methods return 0 or null on a client that is not hosting. Always check IsServerRunning() first.

See also