Here are an NPC and Weapon script which can be used to dynamically store and download mainfiles.
The database NPC is setup to only scan for mainfiles on first creation or when the NPC-Server is restarted.
The weapon script writes to a text file within the player's Graal folder once the first preload has completed, which will prevent future preloads while that text file remains within the Graal directory.
As this involves thousands of files and currently amounts to about 48 MB of filesize, it is strongly suggested to modify this script to an optional action (which can possibly list the total file size) as opposed to being an action carried out by every "fresh directory" login. Another possibility may be to split preloading in to different categories, particularly as the bulk of the file size is from old Classic images.
Also attached are categorised lists of the files which are currently preloaded. In the past it would have been possible to compile this in to a reliable GUPD, however the v6 client requires that the server directory of update package files matches the user's local Graal directory.
DB NPC:
PHP Code:
function onCreated()
this.onInitialized();
function onInitialized() {
MainfilePreload = this;
if (this.cache != NULL)
return;
this.cache = new TStaticVar();
this.onScanDirectory("levels/mainfiles");
}
//Trigger event used to bypass max loop limit
function onScanDirectory(temp.dir) {
temp.files.loadfolder(temp.dir @ "/*", 0);
for (temp.file : temp.files) {
temp.ext = extractFileExt(temp.file);
if (temp.ext == ".txt")
continue;
if (temp.ext != "") {
this.cache.fileList.add(temp.file);
this.cache.totalFileSize += filesize(temp.file);
}
else
this.trigger("ScanDirectory", temp.dir @ "/" @ temp.file);
}
}
public function getFileList()
return this.cache.fileList;
public function getTotalFileSize()
return this.cache.totalFileSize;
Weapon:
PHP Code:
function onActionServerside(temp.action) {
if (temp.action != "getFilenames")
return;
temp.files = MainfilePreload.getFileList();
player.triggerClient("gui", this.name, "preloadFiles", temp.files);
}
//#CLIENTSIDE
function onCreated() {
temp.preload = new TStaticVar();
temp.preload.loadvars("mainfile_preload.txt");
if (!temp.preload.hasPreloaded)
triggerServer("gui", this.name, "getFilenames");
}
function onActionClientside(temp.action, temp.files) {
if (temp.action != "preloadFiles")
return;
for (temp.file : temp.files)
if (!fileexists(temp.file))
fileupdate(temp.file);
temp.preload = new TStaticVar();
temp.preload.hasPreloaded = true;
temp.preload.savevars("mainfile_preload.txt", 0);
}