Skip to content

Terminate (disconnect the session)

ts
function Terminate(addToBlockList: boolean): void;

Immediately disconnects the current client session and interrupts the script. When addToBlockList is true, the client's IP address is also added to the server's temporary block list, preventing further connection attempts for the configured block-list duration.

ParameterTypeRequirementExplanation
addToBlockListbooleanrequiredtrue to also block the client IP; false to disconnect only

WARNING

Terminate() forcibly ends the session and any in-progress transfer. Call it only after you have finished all necessary logging or cleanup, because no code after Terminate() will execute.

NOTE

Blocking a client IP via addToBlockList: true blocks ALL connections from that IP address, not just the current user's connection. Use this option carefully in multi-tenant or shared-network environments.

Example

ts
{
  var user = Session.GetUser();
  // Disconnect (and block) a client that is not allowed after-hours
  if (user && isAfterHours()) {
    Log.Warn("after-hours connection from " + Session.GetRemoteAddress() + " — disconnecting");
    Terminate(false); // disconnect without blocking the IP
  }
}

Example (block on repeated failure)

ts
{
  var answered = Session.GetAnsweredQuestions();
  var failures = answered.filter(function(q) { return !q.OK; }).length;
  if (failures >= 3) {
    Log.Warn("too many auth failures from " + Session.GetRemoteAddress() + " — blocking IP");
    Terminate(true); // disconnect AND add to block list
  }
}

See also

  • Exit() — clean script exit without disconnecting the session
  • EventHandler() — identify which event triggered the script