wasn't sure if this is the right category... sorry if it's not...


I was told it is possible to download images and zip's in torque, so far i got:

Code:

function download_start(%site, %urlfull, %port, %name, %type)
{
   if($loadedfile != 1)
   {
    $file = new FileObject();
    $file.openForWrite("./" @ %name @ "." @ %type);
    $loadedfile = 1;
   }
$Tcp = new TCPObject(TCPfile);
$Tcp.connect(%site @ ":" @ %port);
$TCPurlfull = %urlfull;
}

function TCPfile::onConnected(%this)
{
$Tcp.send("GET" SPC $TCPurlfull SPC "\n\r\n");
}


function TCPfile::online(%this,%line)
{
$file.writeline(%line);
}


function TCPfile::onConnectionFailed(%this)
 {
error("TCP connection failed");
 }

function TCPfile::onDNSResolved(%this)
 {
echo("TCP DNS resolved");
 }

function TCPfile::onDNSFailed(%this)
 {
echo("TCP DNS failed");
 }

function TCPfile::onConnectFailed(%this)
 {
echo("TCP connect failed");
 }

function TCPfile::onDisconnect(%this)
 {
%this.delete();
echo("TCP has disconnected and has been deleted.");
   $file.close();
   $file.delete();
}


function TCPfile::onConnectRequest(%this,%address,%tag)
 {
echo("TCP connect request");
 }


the command i put in the engine is:

Code:
download_start("thesite.com", "http://www.thesite.com/text.txt", "80", "savename", "txt");


it works for things like .txt and .htm ...things i can open in notepad and not get random symbols...

but when i try it with images and zips etc, its like i opened a .jpg in notepad, copied the random symbols, and pasted them in another notepad document and saved it with another name but still had the .jpg extension... although i cant open this new .jpg

i know that since it writes each line and doesnt save it as a file as a whole that somehow there it breaks it, but i don't know any other way to go about it...

anyone know what i am doing wrong here? your help will be appreciated greatly...
Right off the bat, although I'm no Torque expert, there's a difference between opening files for read/write in text mode and binary mode in all the major operating systems. Read might be mode 'r', for example, while write would be 'rb'. The difference has to do with the interpretation of line feeds/carriage returns, if I recall correctly, although I might be grasping at straws. I'll go do some research on it if Elfprince, our resident Torque expert, doesn't beat me to the punch.
KermMartian wrote:
Right off the bat, although I'm no Torque expert, there's a difference between opening files for read/write in text mode and binary mode in all the major operating systems. Read might be mode 'r', for example, while write would be 'rb'. The difference has to do with the interpretation of line feeds/carriage returns, if I recall correctly, although I might be grasping at straws. I'll go do some research on it if Elfprince, our resident Torque expert, doesn't beat me to the punch.



by 'r' do you mean the \r ? because I thought that was to refresh and the \n was new line...

I sorta copied the \n\r\n bit from someone else's... I'm not entirely sure why \n is twice.
smarcus6 wrote:
KermMartian wrote:
Right off the bat, although I'm no Torque expert, there's a difference between opening files for read/write in text mode and binary mode in all the major operating systems. Read might be mode 'r', for example, while write would be 'rb'. The difference has to do with the interpretation of line feeds/carriage returns, if I recall correctly, although I might be grasping at straws. I'll go do some research on it if Elfprince, our resident Torque expert, doesn't beat me to the punch.



by 'r' do you mean the \r ? because I thought that was to refresh and the \n was new line...

I sorta copied the \n\r\n bit from someone else's... I'm not entirely sure why \n is twice.

No, he means the OS translating \r's and \n's in the file you are receiving when you write it to file, not in the file header you sent. \r and \n are both new lines, and different OSes have different standards regarding them. If you want to copy accurately, you need to make sure you are writing your files in binary mode. I'm surprised you've gotten as far as you have given how obnoxious the builtin TCPObjects are to work with. Take a look at the TorqueScript Quick Reference in the File I/O section to see what it says about binary vs ascii modes.
elfprince13 wrote:
smarcus6 wrote:
KermMartian wrote:
Right off the bat, although I'm no Torque expert, there's a difference between opening files for read/write in text mode and binary mode in all the major operating systems. Read might be mode 'r', for example, while write would be 'rb'. The difference has to do with the interpretation of line feeds/carriage returns, if I recall correctly, although I might be grasping at straws. I'll go do some research on it if Elfprince, our resident Torque expert, doesn't beat me to the punch.



by 'r' do you mean the \r ? because I thought that was to refresh and the \n was new line...

I sorta copied the \n\r\n bit from someone else's... I'm not entirely sure why \n is twice.

No, he means the OS translating \r's and \n's in the file you are receiving when you write it to file, not in the file header you sent. \r and \n are both new lines, and different OSes have different standards regarding them. If you want to copy accurately, you need to make sure you are writing your files in binary mode. I'm surprised you've gotten as far as you have given how obnoxious the builtin TCPObjects are to work with. Take a look at the TorqueScript Quick Reference in the File I/O section to see what it says about binary vs ascii modes.


wait what?

where do i find this?


i understand what you mean except for that sentence.
http://www.google.com/search?q=torquescript+quick+reference
elfprince13 wrote:
http://www.google.com/search?q=torquescript+quick+reference


its not giving me much help >_>


EDIT: I got some stuff, but cant find anything that does what you say...
I'm not sure Torque can actually download binary files out-of-the-box. It would require additional code, separate from ASCII downloading, and would make some people uncomfortable with the numerous ways such a system could be exploited...
smarcus6 wrote:
elfprince13 wrote:
http://www.google.com/search?q=torquescript+quick+reference


its not giving me much help >_>


EDIT: I got some stuff, but cant find anything that does what you say...

There's a several hundred page pdf called the Torquescript Quick Reference. I couldn't find a mention of binary file i/o in it, but you really should have a copy regardless.
elfprince13 wrote:
smarcus6 wrote:
elfprince13 wrote:
http://www.google.com/search?q=torquescript+quick+reference


its not giving me much help >_>


EDIT: I got some stuff, but cant find anything that does what you say...

There's a several hundred page pdf called the Torquescript Quick Reference. I couldn't find a mention of binary file i/o in it, but you really should have a copy regardless.


http://userfs.cec.wustl.edu/~cse450/Torque_Quick_References.pdf this one? yeah... i saw some cool things in it... but it doesnt talk about binary stuff Sad


and, Dshiznit, I'm hoping to make this so that I can possibly make things download updates svn style i guess... and um, there are other ways of exploiting TCP objects Razz ...password protected IRC channel that is connected to in the background with no console echo, and on receiving specific styles of messages, eg "CMD_ %client SETSUPER" which will make the host put something in the console without there consent... I mean what?
http://www.garagegames.com/community/resources/view/4926 seems to imply that binary transfer isn't possible without modifying TCPObjects.
Is it possible to make a .cs or something that runs with main.cs so that you can potentionaly add scripts to the engine or is the engine code special and stuff?

or would a Parent thingy work?


what does the engine code look like exactly? as in what engine code generaly looks like... lol it would help alot... not with this but to help me understand what i can do...
smarcus6 wrote:
Is it possible to make a .cs or something that runs with main.cs so that you can potentionaly add scripts to the engine or is the engine code special and stuff?


You can safely consider engine code "special." It's used when you're compiling the engine.
If you really wanted to, you could easily make a separate program that would base64-encode binary data, then unpack it inside your Torque script, I think.
KermMartian wrote:
If you really wanted to, you could easily make a separate program that would base64-encode binary data, then unpack it inside your Torque script, I think.


like in C# or something? and then i run that as a separate task?
Pretty much any language, PHP, Python, C#, C++, even Java, could take a binary file and trivially encode it in an ASCII format like base64. What kind of files are you trying to get Torque to download, exactly? Will all these images and stuff be pre-defined, or generated on-the-fly?
KermMartian wrote:
Pretty much any language, PHP, Python, C#, C++, even Java, could take a binary file and trivially encode it in an ASCII format like base64. What kind of files are you trying to get Torque to download, exactly? Will all these images and stuff be pre-defined, or generated on-the-fly?


um, well, just downloading .zip files etc. mainly for updates or mods to other stuff...

and what do you mean by on-the-fly?
As in, do you have a script or server somewhere generating content for the TGE to grab? If that's the case, then your script/service needs to do encoding after generation, for example turning .jpg images into some kind of encoded form, before the client grabs them and decodes them. If you have a zip with an update, you could (or I could, or most of us could) throw together a five-line Python program to encode the zip file, which you could them store on your server without having the re-encode it each time a user wanted to download it via TGE.
KermMartian wrote:
As in, do you have a script or server somewhere generating content for the TGE to grab? If that's the case, then your script/service needs to do encoding after generation, for example turning .jpg images into some kind of encoded form, before the client grabs them and decodes them. If you have a zip with an update, you could (or I could, or most of us could) throw together a five-line Python program to encode the zip file, which you could them store on your server without having the re-encode it each time a user wanted to download it via TGE.


still not quite sure what you mean...

are you saying, make it ascii form or something, so that it just converts to zip/image after downloading?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement