Repository navigation
EN API UO DisconnectedTime
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
dynamic UO.DisconnectedTime();Returns the calendar stamp of the last time the game connection was lost. It is needed to diagnose a break and estimate the duration of a completed connection, and not to determine the number of login attempts.
There are no parameters.
double: number of days from 1899-12-30 with fractional part of the day. After the break - the time when the client noticed the outage; before the first break is the time when the session owner was created. This is not an offline flag and not milliseconds.
- There are no arguments. The history is common for scripts of the same session owner: late start, pause and close IDE do not change the marks. A new session process begins a new story; it is not a log of all connections.
- A failed login attempt without the character appearing in the world is not considered a successful login. Repeated offline checks do not change the shutdown time. For the current state, use UO.Connected() rather than a non-zero date.
- The clocks are taken from the computer's local clock. The difference multiplied by 86400 gives calendar seconds; Changing the clock/time zone may skew the results. For timeouts, use monotonic Timer(). Individual calls do not form an atomic snapshot; the same mark is not a unique ID connection.
- UO.Wait takes milliseconds. Autopause when the connection is lost and manual pause delay the execution of examples: the timeout check will continue only after the pause is removed. These commands do not unpause themselves and do not enable auto-reconnect.
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.
Run this code as a separate .csx file. Arguments appear directly in the call; replace demonstration names, serials and addresses with your own.
The result of one call is printed in the journal. A number is not converted to bool; an array is displayed as its element count.
object? result = UO.DisconnectedTime();
UO.Print(result is Array values ? "Count: " + values.Length : Convert.ToString(result));Parameters and execution flow:
- CompletedConnectionSeconds() returns seconds or -1 if there is no completed connection or the input has changed between reads. 86400 — seconds in a day. Only the last input/break pair is recalculated; The function does not summarize the history of all sessions.
- UO.Wait takes milliseconds. Autopause when the connection is lost and manual pause delay the execution of examples: the timeout check will continue only after the pause is removed. These commands do not unpause themselves and do not enable auto-reconnect.
var seconds = CompletedConnectionSeconds();
if (Truth(seconds >= 0))
{
UO.AddToSystemJournal("Completed connection seconds: " + Convert.ToString(seconds));
}
dynamic CompletedConnectionSeconds()
{
var login = UO.ConnectedTime();
var loss = UO.DisconnectedTime();
if (Truth(login == 0) || Truth(loss < login) || Truth(UO.Connected()))
{
return -1;
}
if (Truth(UO.ConnectedTime() != login))
{
return -1;
}
return (loss - login) * 86400.0;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;Parameters and execution flow:
- When autopause is enabled, this controller exits immediately; To work offline it must be turned off in advance. After UO.Wait(1000) offline and the previous break mark are checked again. Connect does not guarantee success and does not replace the auto-reconnect setting.
- UO.Wait takes milliseconds. Autopause when the connection is lost and manual pause delay the execution of examples: the timeout check will continue only after the pause is removed. These commands do not unpause themselves and do not enable auto-reconnect.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
if (Truth(UO.GetPauseScriptOnDisconnectStatus()))
{
return null;
}
if (Truth(UO.Connected()))
{
return null;
}
var loss = UO.DisconnectedTime();
await Delay(1000);
if (!(Truth(UO.Connected())) && Truth(UO.DisconnectedTime() == loss))
{
UO.Connect();
}
return null;
}
Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;Parameters and execution flow:
- Comparison with previousLoss notices a break even after re-entry has already taken place. 30 seconds limit monitoring while the script is running, WaitAsync(250) frees the thread between checks. Multiple interruptions can be combined into one notification.
- UO.Wait takes milliseconds. Autopause when the connection is lost and manual pause delay the execution of examples: the timeout check will continue only after the pause is removed. These commands do not unpause themselves and do not enable auto-reconnect.
return await new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenarioAsync();
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;
}
async public Task<object?> RunScenarioAsync()
{
var previousLoss = UO.DisconnectedTime();
var started = Environment.TickCount;
while (Truth(Environment.TickCount - started < 30.0))
{
if (Truth(UO.DisconnectedTime() != previousLoss))
{
UO.AddToSystemJournal("A connection loss occurred; check the session");
return null;
}
await Delay(250);
}
return null;
}
Task Delay(object? milliseconds) => WaitAsync(checked((int)Convert.ToDouble(milliseconds)));
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
}C# is case sensitive. Use the exact UO name. Compare numeric flags with 0; use bool only where the signature returns bool.
Parameters: No parameters.
Result: dynamic / Any.
During a call:
-
InjectionScript.Runtime.InjectionApiUO.ExecuteClientApiCompatibility. -
InjectionScript.Runtime.InjectionApiUO.UpdateConnectionState:UpdateConnectionState().
Internal implementation code; this is not a standalone script.
case "disconnectedtime":
UpdateConnectionState();
return new InjectionValue(state.DisconnectedTime.ToOADate());ClassicUO — Bad Newbie & C# Scripts IDE