Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GScript File Handling? (https://forums.graalonline.com/forums/showthread.php?t=74788)

Raeiphon 06-22-2007 03:25 PM

GScript File Handling?
 
I'm currently trying to script a CRC check that works on images - basically gets the byte size of the original image and compares it to the player's image, if it's over or under, the file gets deleted and is replaced with the original, if it isn't then it goes on as normal.

I can do this fairly easily - one problem: I don't know of a command/variable that deals with files in gscript. Could someone point me towards a wiki article or the proper syntax/commands to do so? It'd be greatly appreciated.

godofwarares 06-22-2007 04:53 PM

Quote:

Originally Posted by Raeiphon (Post 1321023)
I'm currently trying to script a CRC check that works on images - basically gets the byte size of the original image and compares it to the player's image, if it's over or under, the file gets deleted and is replaced with the original, if it isn't then it goes on as normal.

I can do this fairly easily - one problem: I don't know of a command/variable that deals with files in gscript. Could someone point me towards a wiki article or the proper syntax/commands to do so? It'd be greatly appreciated.

PHP Code:

// Loads the lines of a file to an array
temp.lines.clear();
temp.lines.loadLines("path/to/file");

// Saves the lines to an array
temp.line.saveLines("path/to/file"0); 

Please note that you have to give your NPC server r/w rights if you want to do both, or just read rights if you just want to read the files.

Raeiphon 06-23-2007 05:34 AM

And I could do loadlines on an image file and it'd work fine? I'm doubting that alot - all I'm really after is some way of getting the byte size of the file as a variable I can manipulate a little.

Or would loadlines return the size of the file opened in bytes anyway?

zokemon 06-23-2007 06:28 AM

You can do loadstring() on the image and then return length().

I never managed to get loadstring() to work, though (but I never put more then a few minutes into trying).

I personnally can hardly wait for the next client version so I can loadlines() an image clientside! :D

Raeiphon 06-24-2007 12:29 PM

I tried loadlines() on an image serverside, it returned 0 when sent back in a sendrpgmessage.

I also tried loadstring(), yielding the same result.

I'm not quite sure what to do now. Could I get the byte size of the file through sockets somehow?

EDIT: Not sure the npcserver has r/w access.

Admins 06-24-2007 12:54 PM

You could use var.loadstring(filename) and then checksum(string) or md5(string). For getting the file size you could also simply use filesize(filename)

zokemon 06-24-2007 01:23 PM

Yeah, sounds like the best idea. Just checksum() or md5() the file on both the client and the server and compare. This will reduce the packet size sent in your triggeraction.

Also:
After reading your initial post again, I don't think you can do what you are trying to do just yet. You will be able to get the data on the serverside (add rights to the npcserver; that is probably your problem) but you won't be able to on the client. You gotta wait like everyone else for the new client version. :[

Raeiphon 06-24-2007 01:36 PM

Okay, the checksum is nailed.

Now, is there any way to delete/force a client to delete/download a specific file?

zokemon 06-24-2007 01:58 PM

Try:
reloadfile(filename) clientside.

(http://wiki.graal.net/index.php/Crea...t/Client#Files)

Admins 06-24-2007 03:30 PM

Weird, there is no reloadfile() command, not sure who has added that.
Normally if a file is updated on serverside then it is automatically sent to the players who have already seen the file.

Inverness 06-24-2007 03:44 PM

Quote:

Originally Posted by Stefan (Post 1321837)
Weird, there is no reloadfile() command, not sure who has added that.
Normally if a file is updated on serverside then it is automatically sent to the players who have already seen the file.

Well I do like that change you made to the file system. I always hated having to restart Graal to see changes to a file I uploaded on the server when the file wasn't a new one :(


All times are GMT +2. The time now is 01:43 AM.

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