Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Updage Package (.gupd) updater (https://forums.graalonline.com/forums/showthread.php?t=79350)

xXziroXx 04-09-2008 04:27 AM

Updage Package (.gupd) updater
 
Here's a nifty tool that I made that scans all files of a folder, and creates subpackages and sub-subpackages with all the files in.


First thing you want to do, is to give the (npcserver) rights to .gupd files.

PHP Code:

rw levels/ *.gupd 

(remove the space between / and *)

Also add it as a file in folder options.

PHP Code:

file    *.gupd 

Then, create a class named functions_updatepackages and join it to your Control-NPC as well as add a onRCChat function.

functions_updatepackages
PHP Code:

function updateGUPD(typesub)
{
  echo(
"Updating update packages...");
  
// Checks if subpackages exists, if not, creates them and
  // adds them to other packages.
  
temp.file.loadLines("levels/package_" type ".gupd");
  if (!
checkSubPackage("basepackage"type)) addSubPackage("basepackage"type);
  else if (
temp.file.size() == NULLcreateSubPackage(typetype);
  
temp.file.loadLines("levels/" type "_" sub ".gupd");
  if (!
checkSubPackage("package_" typetypesub) || temp.file.size() == NULLcreateSubPackage(typesub);

  
// Loading files in folder
  
temp.folder = (sub == NULL "levels/" type "/*" "levels/" type "/" sub "/*");
  
temp.data.loadFolder(temp.folder0);
  if (
sub == NULLsub type;
  
  
// Clearing old file entries
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  for (
temp.0temp.<= 6temp.++) temp.newpackage.add(temp.package[temp.i]);
  
temp.newpackage.saveLines("levels/" type "_" sub ".gupd"0);
  
  
// Saving file list
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  
temp.package[2] = getNewVersion(temp.package[2]);
  for (
temp.filetemp.datatemp.package.add("FILE" SPC (sub == NULL "levels/" type "/" "levels/" type "/" sub "/") @ temp.file);
  
temp.package.saveLines("levels/" type "_" sub ".gupd"0);

  echo(
"Done!");
  
sendToRC("/refreshfilelist");
}

function 
checkSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  for (
temp.var: temp.data) {
    if (
temp.var == "SUBPACKAGE" SPC temp.checksum ".gupd") return true;
  }
}

function 
addSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  
temp.data[2] = getNewVersion(temp.data[2]);
  
temp.data.insert((package == "basepackage" 7), "SUBPACKAGE" SPC temp.checksum ".gupd");
  
temp.data.saveLines("levels/" package ".gupd"0);
  
  if (
package == "basepackage"createSubPackage(typetype);
  echo(
"Added sub package \"" type "\" to \"" package "\"");
}

function 
createSubPackage(typesub)
{
  
temp.layout = {
    
"GRPKG001",
    
"NAME" SPC sub.substring(01).upper() @ sub.substring(1),
    
"VERSION 1.00",
    
"PLATFORM any",
    
"DESCRIPTION",
    
sub.substring(01).upper() @ sub.substring(1),
    
"DESCRIPTIONEND"
  
};
  if (
type == sub) {
    
temp.layout.add("USECHECKSUM false");
    
temp.layout.add("PROTECTOVERWRITE false");
    
temp.layout.add("FLAG popupforoptionalpackages=false");
    
temp.layout.saveLines("levels/package_" type ".gupd"0);
    
    echo(
"New sub package created \"package_" type "\"!");
  } else {
    if (
sub == NULLsub type;
    
temp.layout[1] = "NAME" SPC sub.substring(01).upper() @ sub.substring(1);
    
temp.layout[5] = sub.substring(01).upper() @ sub.substring(1);
    
temp.layout.saveLines("levels/" type "_" sub ".gupd"0);
    if (!
checkSubPackage("package_" typetypesub)) addSubPackage("package_" typetypesub);
    
    echo(
"New sub-sub package created \"" type "_" sub "\"!");
  }
}

function 
getNewVersion(arg)
{
  
temp.var = arg.tokenize()[1] + 0.01;
  return 
arg.tokenize()[0SPC temp.var;


Control-NPC
PHP Code:

function onCreated()
{
  
join("functions_updatepackages");
}

function 
onRCChat()
{
  if (
params[0] == "updategupd"updateGUPD(params[1], params[2]);


Then, upload this as a file named basepackage.gupd into your servers levels/ folder:

PHP Code:

GRPKG001
NAME Base Package
VERSION 1.00
PLATFORM any
USECHECKSUM false
PROTECTOVERWRITE false
FLAG popupforoptionalpackages
=false 


To use the tool, I will demonstrate an example. Say that I have 18 images in my levels/images/ folder, then I would say on RC:

/npcupdatepackages images

If I want to update a subfolder such as levels/images/gui/ instead, I'd do:

/npcupdatepackages images gui

Note that only one subfolder is supported at the moment. I haven't tried and use it on a sub-subfolder, but I doubt it would work. Whenever you update a package, it's version gets increased by 0.01, making it download automatically for players that logon (if you use the script provided below). :)


If you want the packages to be forced upon the client instead of optional, a script such as this could be added into a Weapon NPC:

PHP Code:

//#CLIENTSIDE
function onCreated() printPackage(getBasePackage());

function 
printPackage(package) {
  if (
package.localversion package.versionpackage.update();

  for (
temp.subpackagepackage.packagesprintPackage(temp.subpackage);



As always, please, use the forums reputation system. If you like this script, hey why not give me good rep? If not, pleaaaase give me bad rep. Crits and suggestions welcomed too, of course! :)

cbk1994 04-09-2008 05:23 AM

Nice :)

xXziroXx 04-09-2008 05:28 PM

If you fail to understand it (I'm sure one or two of you won't), this tool is basically to update all your downloadable files and make them download for the client when he logs on.

If you upload new heads, for example, and then use this tool to update heads package - they will be downloaded for clients the next time they logon.

I find it very handy for the player to download everything once, instead of each time a new image/sound/gani is ecountered in-game and sorta "blips" out from nowhere if you have a slower connection.

This of course depend on that you use the tool to update the packages whenever you upload something, but I reccon it will become a habit.


All times are GMT +2. The time now is 09:34 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.