Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-26-2009, 01:18 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
Automated Uploading

So, I toyed around with Graal's personaluploads feature, after reading Dusty's post in the improvement forum. It's pretty straight-forward and I made sure to comment it thoroughly. For security, it checks file extensions and headers against a predefined whitelist. The script requires minimal configuration, but it's meant to be a learning experience, not a full-fledged, out-of-the-box program; in fact, it's pretty bare-bones. Needless to say, if your server is prone to immature kids uploading inappropriate graphics, I would not suggest using this. There is no moderation, whatsoever.

Comments, critiques, suggestions all welcome.

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
  // Edit these to fit your server's file structure
  
temp.bodyfolder "levels/graphics/player/bodies/";
  
temp.headfolder "levels/graphics/player/heads/";
  
temp.hatfolder "levels/graphics/player/hats/";
  
temp.shieldfolder "levels/graphics/player/shields/";
  
temp.packfolder "levels/graphics/player/packs/";
  
  
// 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
      // Check if file starts with correct prefix
      
if(temp.file.starts("valp")) { // Replace with your server's prefix, or remove the check altogether
        // Check type of file, based on file name
        
if(temp.file.pos("head") => 0) {
          
movefile(temp.dir temp.filetemp.headfolder temp.file);
        }
        else if(
temp.file.pos("body") => 0) {
          
movefile(temp.dir temp.filetemp.bodyfolder temp.file);
        }
        else if(
temp.file.pos("hat") => 0) {
          
movefile(temp.dir temp.filetemp.hatfolder temp.file);
        }
        else if(
temp.file.pos("shield") => 0) {
          
movefile(temp.dir temp.filetemp.shieldfolder temp.file);
        }
        else if(
temp.file.pos("pack") => 0) {
          
movefile(temp.dir temp.filetemp.packfolder temp.file);
        }
        else {
          
// If file is not named correctly, delete it.
          
deletefile(temp.dir temp.file);
        }
      }
      else {
        
// If file is not named correctly, delete it.
        
deletefile(temp.dir temp.file);
      }
    }
    else {
      
// If false, delete file: this file is not allowed
      
deletefile(temp.dir temp.file);
    }
  }
  else {
    
// If false, delete file: this file is not allowed
    
deletefile(temp.dir temp.file);
  }
}
function 
analyzeheader(headerwhitelist) {
  for(
temp.itemp.whitelist) {
    if(
temp.header.pos(temp.i) => 0) {
      return 
temp.i;
    }
  }
  return 
false;
}
//#CLIENTSIDE
function onCreated() {
  
// Restriction feature. Add player account to array.
  
temp.restricted = {};
  if(
player.account in temp.restricted) {
    
this.destroy();
  }
}
function 
onPlayerChats() {
  if(
player.chat == "/upload") {
    
requesttext("folder""PERSONAL");
    
selectFileforUpload();
  }
}
function 
onFilesUploaded() {
  
triggerserver("gui"this.name);

__________________
"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, 01:59 AM
Mattehy Mattehy is offline
Developer
Mattehy's Avatar
Join Date: Jul 2009
Posts: 58
Mattehy is on a distinguished road
u were reading my mind
hawt
Reply With Quote
  #3  
Old 07-26-2009, 02:06 AM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
Could you place them into a queue for approval and then move then once approved?
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #4  
Old 07-26-2009, 02:14 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 Rufus View Post
Could you place them into a queue for approval and then move then once approved?
Yes, I suppose so. Simply remove the movefiles() parts. GATs, or whoever handles the files, can go through the personaluploads/ folder, moving files or deleting them. That's not very automated, though.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #5  
Old 07-26-2009, 02:17 AM
Rufus Rufus is offline
Registered User
Join Date: Jun 2004
Location: United Kingdom
Posts: 4,698
Rufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud ofRufus has much to be proud of
Quote:
Originally Posted by LoneAngelIbesu View Post
Yes, I suppose so. Simply remove the movefiles() parts. GATs, or whoever handles the files, can go through the personaluploads/ folder, moving files or deleting them. That's not very automated, though.
Yeah, I'm just thinking hypothetically for those servers that may be "prone to immature kids uploading inappropriate graphics" but would like to centralize their uploading process.
__________________
Quote:
Originally Posted by Loriel View Post
Seriously, you have ****-all for content and you're not exactly pulling in new developer talent, angling for prestigious titles should be your last concern.
Reply With Quote
  #6  
Old 07-26-2009, 03:06 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Era has plans to do something like this eventually. Good idea with the header check, I wouldn't have thought of that (and will certainly copy that ).

If Era uploaded heads and such directly (without approval of some kind), we'd inevitably have inappropriate images, or images that break some kind of rule (e.g. people re-uploading personal heads, uploading invisible heads (which for some reason are against the rules), etc.)
__________________
Reply With Quote
  #7  
Old 07-26-2009, 11:08 AM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by cbk1994 View Post
Era has plans to do something like this eventually. Good idea with the header check, I wouldn't have thought of that (and will certainly copy that ).

If Era uploaded heads and such directly (without approval of some kind), we'd inevitably have inappropriate images, or images that break some kind of rule (e.g. people re-uploading personal heads, uploading invisible heads (which for some reason are against the rules), etc.)
That'd own, then GPs could be finally all fired.

All they do right now is: "Will talk to Squirt about that" and upload.
Reply With Quote
  #8  
Old 07-26-2009, 05:31 PM
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
The way Valikorlia handles automated uploaded is that it first checks to see what time the user last uploaded; there must be 2 minutes between each upload, to deter spamming. Then, it checks to see if the file is greater than 50kb, and deletes it if it is; this is a possible way to determine that a file isn't what the user says it is. We also have logs, but that's obvious.

Perhaps other servers can utilize these checks?
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #9  
Old 07-26-2009, 06:04 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
Quote:
Originally Posted by LoneAngelIbesu View Post
The way Valikorlia handles automated uploaded is that it first checks to see what time the user last uploaded; there must be 2 minutes between each upload, to deter spamming. Then, it checks to see if the file is greater than 50kb, and deletes it if it is; this is a possible way to determine that a file isn't what the user says it is. We also have logs, but that's obvious.

Perhaps other servers can utilize these checks?
Queueing the Uploads into a simple GUI List still seems the best solution to me
Reply With Quote
  #10  
Old 07-26-2009, 06:42 PM
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 Pelikano View Post
Queueing the Uploads into a simple GUI List still seems the best solution to me
To each his own.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #11  
Old 07-26-2009, 08:16 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by LoneAngelIbesu View Post
The way Valikorlia handles automated uploaded is that it first checks to see what time the user last uploaded; there must be 2 minutes between each upload, to deter spamming. Then, it checks to see if the file is greater than 50kb, and deletes it if it is; this is a possible way to determine that a file isn't what the user says it is. We also have logs, but that's obvious.

Perhaps other servers can utilize these checks?
Ultimately they just have to be checked over by a staff member before being uploaded, but once it's simplified into an easy interface, it should just be a click to upload or deny images.

Era players are just too immature to allow them to upload stuff without a manual check.
__________________
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 03:46 PM.


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