Skip to content

Terminate (disconnect the session)

ts
function Terminate(ban: boolean): void;

Immediately disconnects the current client session and interrupts the script. When ban is true, the client's IP address is also banned by the Shield for the ban length of the virtual site's rules, and the ban carries the rule Added by a script. The address is refused at accept until the ban lifts, and every refused attempt extends it, exactly like an automatic ban.

ParameterTypeRequirementExplanation
banbooleanrequiredtrue to also ban the client IP through the Shield; 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

Banning a client IP with ban: true refuses ALL connections from that address, not just the current user's connection. Use this option carefully on shared networks. An address on the Shield's safe list is never banned, so Terminate(true) only disconnects it.

Example

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

Example (ban 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() + ", banning IP");
    Terminate(true); // disconnect AND ban the address
  }
}

See also

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