Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-26-2009, 12:24 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
movefile()

This is a pretty simple question. I just need to know if I'm using movefile() correctly, because the file is not being moved. The npcserver has rights to all the needed folders.

This is a serverside file-checking script, using Graal's personaluploads feature. The movefile() functions are located in the conditional checks.

PHP Code:
function onActionServerside() {
  
// Get personaluploads directory and filename
  
temp.dir player.getPersonalUploadFolder();
  
temp.folder.loadfolder(temp.dir "*"0);
  
temp.file temp.folder[0];

  
// Establish extension and header whitelists
  
temp.extensions = {"gif""png"};
  
temp.headers = {"GIF8""PNG"};

  
// Establish folders
  
temp.bodyfolder "levels/graphics/player/bodies/";
  
temp.headfolder "levels/graphics/player/heads/";

  
// Extract file extension and header
  
temp.fileext temp.file.tokenize(".")[1];
  
temp.rawfilehead.loadlines(temp.dir temp.file);
  
temp.filehead this.analyzeheader(temp.rawfilehead[0], temp.headers);

  
// Check if file extention is in whitelist
  
if(temp.fileext in temp.extensions) {
    
// If true, check if file header is in whitelist
    
if(temp.filehead != false) {
      
// If true, move file to correct directory, based on file name
      
if(temp.file.starts("valp") && temp.file.pos("head") => 0) {
        
movefile(temp.dir temp.filetemp.headfolder);
      }
      else if(
temp.file.starts("valp") && temp.file.pos("body") => 0) {
        
movefile(temp.dir temp.filetemp.bodyfolder);
      }
      else {
        
// If file is not named correctly, delete it.
        
deletefile(temp.dir temp.file);
      }
    }
    else {
      
// If false, stop script: this file is not allowed
      
deletefile(temp.dir temp.file);
      return;
    }
  }
  else {
    
// If false, stop script: this file is not allowed
    
deletefile(temp.dir temp.file);
    return;
  }
}

function 
analyzeheader(headerwhitelist) {
  for(
temp.itemp.whitelist) {
    if(
temp.header.pos(temp.i) => 0) {
      return 
temp.i;
    }
  }
  return 
false;

__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #2  
Old 07-26-2009, 12:31 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
This works for me.

PHP Code:
// Variables
temp.currentfile "whatever.txt";
temp.olddir "levels/";
temp.newdir "levels/other/folder/";
// Movefile
movefile(temp.olddir temp.currentfiletemp.newdir temp.currentfile); 
__________________
Quote:
Reply With Quote
  #3  
Old 07-26-2009, 12:33 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by fowlplay4 View Post
This works for me.

PHP Code:
// Variables
temp.currentfile "whatever.txt";
temp.olddir "levels/";
temp.newdir "levels/other/folder/";
// Movefile
movefile(temp.olddir temp.currentfiletemp.newdir temp.currentfile); 
That's exactly what I'm doing, with temp.dir, temp.file, and temp.[body/head]folder. Could it be that the personaluploads isn't located within the levels directory?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #4  
Old 07-26-2009, 12:39 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by LoneAngelIbesu View Post
That's exactly what I'm doing, with temp.dir, temp.file, and temp.[body/head]folder. Could it be that the personaluploads isn't located within the levels directory?
Read my example again.

movefile("folder/filename", "newfolder/filename");

In your case..

movefile(temp.dir @ temp.file, temp.headfolder @ temp.file);

Should work.

Also it works with any directory, it's not levels specific.
__________________
Quote:
Reply With Quote
  #5  
Old 07-26-2009, 12:45 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
Quote:
Originally Posted by fowlplay4 View Post
Read my example again.

movefile(temp.dir @ temp.file, temp.headfolder @ temp.file);
Oh, I see. The /scripthelp description could be a bit more descriptive. Thanks.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:53 AM.


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