Skip to content

EN API UO Disconnect

LIHACHTETAN edited this page Nov 28, 2026 · 3 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

UO.Disconnect

Home · C# · IDE · UO API · A–Z · Examples · Languages

C# signatures

void UO.Disconnect();

Disconnects the current or installed client transport and prepares scripts for reconnection.

Parameters

There are no parameters.

Return value

void - no return value.

Behavior

  • If automatic reconnect is turned off, BeginScriptControlledDisconnect saves the worker making the call for later UO.Connect. The manager session receives RequestDisconnect.
  • The standalone client calls Socket.Disconnect and PrepareForReconnect. When global reconnect is enabled, it explicitly schedules the saved scene transition. In LoginScene clears the popup and returns Main.
  • Returning void does not report the result of the reconnection. The connection status is read separately; Auto reconnect settings can initiate a new login.

Standalone C# scripts

Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.

Simple example

Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.

The command is a separate statement. The message before it marks the start of the call; it does not confirm a server action.

UO.Print("Calling UO.Disconnect");
UO.Disconnect();

1. Disconnect session - direct script

Parameters and execution flow:

  • The command cancels both the active and the installed transport.
UO.Disconnect();

2. Explicit reconnection - script function

Parameters and execution flow:

  • With AR turned off, the calling worker can reach Connect himself.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
    UO.Disconnect();
    await Delay(1000);
    UO.Connect();
    return null;
}

Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));

3. Disable connected session only - script class

Parameters and execution flow:

  • The condition uses a local flag for the current session.
return  new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenario();
class ScriptScenario
{
    private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
    private readonly Func<int, Task> WaitAsync;
    private readonly string[] Args;
    private readonly CancellationToken Cancellation;
    private readonly Action Checkpoint;
    public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
    {
        UO = api;
        WaitAsync = wait;
        Args = args;
        Cancellation = cancellation;
        Checkpoint = checkpoint;
    }

     public object? RunScenario()
    {
        if (Truth(UO.Connected()))
        {
            UO.Disconnect();
        }

        return null;
    }

    bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}

Command implementation

C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.

UO.Disconnect() — UO.Disconnect()

Parameters: No parameters.

Result: void / Unit.

During a call:

Internal implementation code; this is not a standalone script.

case "disconnect": bridge.DisconnectClient(); return InjectionValue.Unit;

Clone this wiki locally