GBall Creator is a script to generate a "GBall package". This package can contain multiple files. Essentially, it works as a ZIP file but can be created serverside.
An example of why this is useful is that with one line of code you can backup a server's folder structure (selectively) — it can even be used to backup the accounts folder.
PHP Code:
function onCreated() {
this.version = "1.0"; // eventually used in expander?
temp.mb = 1048576;
this.maxWrite = (mb * 2); // max to write at once; I find mb*9 is the absolute limit
// but below that is usually better to avoid flood alert
this.loopLimit = 5000; // the number of loops before a sleep -- must be less than
// this.maxlooplimit -- 5000 is good but don't expect
// the server to be playable while the files are added to
// the "to write" list (the first part which takes very little
// time, but will lock up the server)
this.delay = 60 * 6; // delay between trying to write, default 60*6 -- this seems not to
// cause flood alert, which, while protected against, can prevent
// other scripts on the server from functioning
}
/*
The way folders work is that if I were to compress
only "weapons/*", there would be a folder called
"weapons" with all of the contents inside.
If I were to compress "weapons/*" and "levels/world/*",
there would be two folders: "weapons" and "world"
*/
public function GBall(description, outputName, folders) {
temp.lines = null;
for (temp.folderName : folders) {
temp.folder.loadFolder(folderName[0], folderName[1]);
temp.p = folderName[0].positions("/");
temp.pathToFolder = folderName[0].substring(0, p[p.size() - 1]);
temp.tokens = pathToFolder.tokenize("/");
temp.bottomFolderName = tokens[tokens.size() - 1];
for (temp.file : folder) {
// add it to the package
temp.str.loadString(pathToFolder @ "/" @ file);
str = " " @ base64encode(bottomFolderName @ "/" @ file) @ " " @ base64encode(str);
lines.add(str);
if (this.loop()) {
echo("GBall: Building file cache...");
}
}
this.loop();
}
// don't save it all at once to save resources + avoid flood alert
temp.line = 0;
temp.c = 0;
while (line < lines.size()) {
temp.chars = 0;
temp.toWrite = {format("GBALL v%s (%s): %s", this.version, base64encode(description), int(timevar2))};
while (chars < this.maxWrite && line < lines.size()) {
toWrite.add(lines[line]);
chars += lines[line].length();
line ++;
this.loop();
}
temp.fileName = outputName @ c @ ".arc";
temp.hasTried = false;
while (! (fileExists(fileName))) {
if (hasTried) {
echo("GBall: Unable to write '" @ fileName @ "'; flood alert or bad permissions. Trying again after delay...");
sleep(this.delay);
}
toWrite.saveLines(outputName @ c @ ".arc", false);
echo("GBall: Writing...");
hasTried = true;
sleep(1); // sometimes it takes a minute for the file to "exist"
}
// sleep to avoid flood alert
if (line < lines.size()) {
sleep(this.delay);
}
c ++;
}
echo("GBall: Saved file (" @ outputName @ "x.arc)!");
}
function loop() {
this.count ++;
if (this.count >= this.loopLimit) {
this.count = 0;
sleep(1);
return true;
}
}
An example of using this:
PHP Code:
// description, file prefix, list of folders
GBall("Backup of accounts", "data/accountsbk_", {{"accounts/*", true}});
This will create a backup of the accounts folder, including the folder structure, and save it in several files (depending on how many accounts you have on the server) in the "data" folder. The reason for saving it in several files is that the max file size is 10 MB for script writing.
The best part of the script is that it is optimized to work on populated servers. Initially the script will load all files needed into memory. This is the only part that will cause the server to lock up. After this, the files will be written every few minutes to evade the flood alert. There is protection so that if the flood alert kicks in and prevents a file from being written it will wait and then attempt to write it after the flood alert has subsided. This stage (file writing) can take hours, depending on the settings you specify at the top of the script, but it will not lag the server.
Once the script has finished you will have files with a ".arc" extension. Download all of these files, then open the GBallExpander Java application included at the end of this post and select the first file. The application will expand the GBall files into the actual folder structure. This should not take long at all. You can also store the files in their GBall form and expand them later (you may wish to ZIP them to save file space).
The Java application which expands the GBall files works fine on Mac and Windows, and probably any other system with the JRE installed.
I should also mention that this script works fine to backup any type of file I've been able to throw at it, from text files to levels to images. Essentially you could backup the entire levels/* folder on your server.
I used this on Era last night to backup the accounts folder and it worked flawlessly, so it should work just about anywhere.
I feel like I've done a ****ty job explaining in this post, so feel free to ask questions.
I haven't yet received permission to post a link to the source code for the Java application so forum PM me if you want it (or decompile the JAR).