Author Topic: Revenge of the TCP object [Solved]  (Read 3319 times)

So I made this TCP object but it's not going to the url I want or something.
Code: [Select]
$ColorSetMaker::Version = "0";

function ColorSetMaker_VersionCheck()
{
if(isFile("./RTBinfo.txt") && (isFile("add-ons/System_ReturnToBlockland/client.cs")))
{
return;
}

if(isObject(ColorSetMaker_Downloader))
ColorSetMaker_Downloader.delete();

new TCPObject(ColorSetMaker_Downloader);

ColorSetMaker_Downloader.connect("dl-web.dropbox.com:80");
}

function ColorSetMaker_Downloader::onConnected(%this)
{
//https://dl-web.dropbox.com/get/ColorSetMaker_Version.txt?w=1fc5f9ab

%req = "/get/ColorSetMaker_Version.txt?w=1fc5f9ab";

//%req = "GET/get/ColorSetMaker_Version.txt?w=1fc5f9ab" SPC "HTTP/1.0\nHost: dl-web.dropbox.com\n\n";

%this.send(%req);
}

function ColorSetMaker_Downloader::onConnectFailed(%this)
{
MessageBoxOK("Attention!", "Unable to connect to the online version information.");
}

function ColorSetMaker_Downloader::onDisconnect(%this)
{
if(!$ColorSetMaker_Connected)
{
MessageBoxOK("Attention!", "Unable to connect to the online version information.");
}

else
{
$ColorSetMaker_Connected = "";
}
}

function ColorSetMaker_Downloader::onLine(%this, %line)
{
echo("\c21:" SPC getSubStr(getWord(%line, 6), 0, 6));

echo("\c22:" SPC getSubStr(getWord(%line, 6), 0, 1));

echo("\c23:" SPC %this);

echo("\c24:" SPC %line);


if(getSubStr(getWord(%line, 6), 0, 6) == $ColorSetMaker::Version)
{
$ColorSetMaker_connected = 1;

ColorSetMaker_Downloader.disconnect();

ColorSetMaker_VersionResult(false);
}

else
{
if(getSubStr(getWord(%line, 6), 0, 6) !$= "1 BETA")
{
$ColorSetMaker_AvailableVersion = "1 BETA";
}

else
{
$ColorSetMaker_AvailableVersion = getSubStr(getWord(%line, 6), 0, 1);
}

ColorSetMaker_Downloader.disconnect();

ColorSetMaker_BersionResult(true);
}
}

function ColorSetMaker_VersionResult(%x)
{
if(%x)
{
MessageBoxOk("Good News!", "Your Color Set Maker mod is up to date.");
}

else
{
MessageBoxOK("Attention!", "There is a more current version of your Color Set Maker mod.\n\nYour Version:" SPC $ColorSetMaker::Version @ "\n\nAvailable: " @ $ColorSetMaker_AvailableVersion);
}
}

It echos the following in the console:
1:
2:
3: 8366
4:
1:
2:
3: 8366
4: <html>
1:
2:
3: 8366
4: <head><title>Dropbox - 4xx</title>
1:
2:
3: 8366
4: <link href="https://www.dropbox.com/static/css/main.css" rel="stylesheet" type="text/css">
1:
2:
3: 8366
4: <link rel="shortcut icon" href="/static/images/favicon.ico"/>
1:
2:
3: 8366
4: </head>
1:
2:
3: 8366
4: <body style="background-color:#fff">
1:
2:
3: 8366
4: <br/><br/>
1:
2:
3: 8366
4: <div align="center">
1:
2:
3: 8366
4: <table><tr><td width="600px">
1:
2:
3: 8366
4: <center><img id="errorimage" src="/static/images/psychobox.png"/></center>
1:
2:
3: 8366
4: <div id="errorbox">
1: you're
2: y
3: 8366
4: <h1>Error (4xx)</h1>We can't find the page you're looking for. Check out our <a href="https://www.dropbox.com/help">Help Center</a> and <a href="http://forums.dropbox.com">forums</a> for help, or head back to <a href="https://www.dropbox.com/home">home</a>.
1:
2:
3: 8366
4: </div>
1:
2:
3: 8366
4: </td></tr></table>
1:
2:
3: 8366
4: </div>
1:
2:
3: 8366
4:
1:
2:
3: 8366
4: <script type="text/javascript" src="/static/javascript/external/dropbox-mini.js"></script>
1:
2:
3: 8366
4: <script>
« Last Edit: May 11, 2012, 02:48:57 PM by jes00 »

\r\n for newlines in the HTTP protocol headers

\r\n for newlines in the HTTP protocol headers
What?

Actually that wasn't even the first problem.

   %req = "/get/ColorSetMaker_Version.txt?w=1fc5f9ab";

Not a valid request


I am not an arrow/circumflex.


%Request = "GET" SPC %File SPC "HTTP/1.0\nHost:" SPC %Server @ "\r\n";

\r\n for newlines in the HTTP protocol headers
Would it still work if someone typo'd and wrote \n\n instead? And what about the HTTP/1.0? Is there any difference if you put HTTP/1.1 over 1.0?

%Request = "GET" SPC %File SPC "HTTP/1.0\nHost:" SPC %Server @ "\r\n";
Would it still work if someone typo'd and wrote \n\n instead? And what about the HTTP/1.0? Is there any difference if you put HTTP/1.1 over 1.0?
The server handles the HTTP version, I would use 1.1 just because that's what everything uses. But no, it doesn't really make a difference.

However, \r\n is required. It's how the webserver knows you've ended the line. You could do something like:
Code: [Select]
%tcp.send("Host: www.");
%tcp.send(%domain);
%tcp.send(".com");
%tcp.send("\r\n");
and it would still work, because the webserver knows \r\n is the end of the line, not the end of the transmission.

With that said, your request line:
%Request = "GET" SPC %File SPC "HTTP/1.0\nHost:" SPC %Server @ "\r\n";

needs to be:
%Request = "GET" SPC %File SPC "HTTP/1.0\r\nHost:" SPC %Server @ "\r\n";
« Last Edit: May 05, 2012, 09:46:32 PM by Slicks555 »

%Request = "GET" SPC %File SPC "HTTP/1.0\nHost:" SPC %Server @ "\r\n";

The highlighted parts won't work together. Request headers were introduced in HTTP/1.1.

Actually that wasn't even the first problem.

   %req = "/get/ColorSetMaker_Version.txt?w=1fc5f9ab";

Not a valid request
Is this? %req = "GET /get/ColorSetMaker_Version.txt?w=1fc5f9ab HTTP/1.1\r\n";

Is this? %req = "GET /get/ColorSetMaker_Version.txt?w=1fc5f9ab HTTP/1.1\r\n";

That is a valid request.

That is a valid request.
Now one of the messages boxes comes up saying "Unable to connect to the online version information."

Now one of the messages boxes comes up saying "Unable to connect to the online version information."

Either Blockland is unable to access the internet, the address "dl-web.dropbox.com:80" is invalid or that server was down at the moment.


The highlighted parts won't work together. Request headers were introduced in HTTP/1.1.
Whilst it isn't required in the specification, it doesn't hurt to include one, right!?