
This is an example script which is intended to run with a "Server Start" Script Type. It demonstrates how to retrieve persisted variables within the system on startup.
function run()
{
// Display a message in the log/server window.
ScriptSession.logInfo("Server Started!");
// Display persisted value when server was last stopped.
var dtLast = ScriptSession.getVariable("LastStopped");
ScriptSession.logInfo("Last Stopped: " + dtLast.toString());
}
Note:
"LastStopped" is the name of the persisted script variable, retrieved using ScriptSession.getVariable(). If no variable can be found, NULL will be returned.
The Server Stopped example below demonstrates how to save the persisted variable.
This is an example script which is intended to run with a "Server Stopped" Script Type. It demonstrates how to persist variables for future server starts.
importClass (java.util.Calendar);
function run()
{
// Display a message in the log/server window.
ScriptSession.logInfo("Server stopped!");
// Save the current time as last server start.
var now = Calendar.getInstance().getTime();
ScriptSession.persistVariable("LastStopped", now);
}
Note:
"LastStopped" is the name of the persisted script variable, saved using ScriptSession.persistVariable(). The value saved is the variable 'now', which is a Date object retrieving the current time.
The Server Start example above demonstrates how to read the persisted variable.
This is an example script which is intended to run with a "User Login" Script Type. It demonstrates how to retrieve and evaluate the username of the user authenticated.
function run()
{
// Produce warning if user meets certain criteria.
var usr = ScriptSession.getUserName();
if (usr == "someuser")
ScriptSession.logWarn("Warning: User " + usr + " logged into system" );
}
Note:
usr is the username of the user, retrieved by the ScriptSession.getUserName() method.
"someuser" is a hard coded string compared the username string used to log in. If the user matches, it will display a warning on the server.
This is an example script which is intended to run with a "User Logout" Script Type. It demonstrates how to determine the user logging out in this scenario.
function run()
{
// Retrieve username.
var usr = ScriptSession.getUserName();
// Perform some kind of clean-up after a user logs off.
doCleanUp(usr);
}
Note:
usr is the username of the user, retrieved by the ScriptSession.getUserName() method.
doCleanUp() is a helper function which would provide any cleanup logic for the user.
This is an example script which is intended to run with a "Authentication" Script Type, run before the user logs in. It arbitrarily checks if the username and password match - if they do, continue with the login, if not, invalidate the login attempt. Also displays username/password in the server log, as well as retrieves user IP address.
function authenticate(name, password)
{
// Display user name and password in log/server window.
ScriptSession.logInfo("Checking credentials for " + name + " [" + password + "]");
ScriptSession.logInfo(name + " IP Address is: " + ScriptSession.getUserRemoteHostAddress());
// Check if username and password are equal, if not, invalidate.
if (name == password)
return true;
return false;
}
Note:
name is the username string, supplied by BrightServer to the function on login attempt.
password is the password string, supplied by BrightServer to the function on login attempt.