-
Notifications
You must be signed in to change notification settings - Fork 1
ScriptBase
The Snipe server library contains a class called snipe.lib.ScriptBase
. This class is intended to serve as a base for making server-side Neko scripts. It contains the methods to make database requests, Snipe server requests (cache or slave servers) and HTTP requests to any webservers.
The first method that the script should call is called init()
. It will load the configuration file and set up the database and server connections (if enabled).
The configuration file is called "script.cfg" and has to be located in the same directory that the script is in. The following configuration variables are supported:
Configuration variable | Description |
---|---|
database.enabled | (0/1) If enabled, the script will establish the connection to the database. Disabled by default. |
database.host | Database host IP address. |
database.name | Database name. |
database.password | Database password. |
database.port | Database port. |
database.user | Database user. |
log.extended | (0/1) If enabled, the script will have a separate thread for logging that will save logs into hourly-rotated files in "logs/" directory. |
log.query | (0/1) If enabled, the script will log all SQL queries to the logfile. |
log.url | (0/1) If enabled, the script will log all HTTP requests and responses to the logfile. |
server.enabled | (0/1) If enabled, the script will establish the socket connection to the given server. Disabled by default. |
server.host | Server host IP address. |
server.port | Server port. |
server.printLog | (0/1) If enabled, log will be printed out to stdout. |
server.writeLog | (0/1) If enabled, log will be written to "log.txt" logfile. |
Example script:
import sys.io.File;
import snipe.script.ScriptBase;
class Script extends ScriptBase
{
public function new()
{
super();
}
// script entry-point
public function run()
{
init();
log('start');
var out = File.write("./output.txt", false);
var res = query(
"SELECT ID, RegDate FROM Users " +
"WHERE RegDate > 'today'");
var cntTotal = 0;
for (row in res)
{
cntTotal++;
out.writeString(row.id + "," + row.regdate + "\n");
}
log(cntTotal + ' users saved.');
out.close();
}
public static function main()
{
var s = new Script();
s.run();
}
}
This script will save all user IDs and registration dates of users that have registered in the game since the start of the day into the output file.