Author Topic: [solved] TCP Help  (Read 2702 times)

I'm trying to authenticate an ip and a name to get a bl_id using the auth.blockland.us server

new TCPObject(authTCP);
%content="NAME="@%name@"&IP="@%ip;
authTCP.send("POST /authQuery.php?"@%content@" HTTP/1.1\r\nHost: auth.blockland.us\r\nUser-Agent: Torque/1.0\r\n\r\n");

(note, ip and name do have values when the code is being run)

When I call this, the "authTCP::onLine" function, it gives me nothing

is the string I'm sending incorrect?
How can I fix this and make it return values?

If it worked correctly, It would return "YES BL_ID"

« Last Edit: July 23, 2013, 06:45:39 PM by MARBLE MAN »

Firstly, are you replacing symbols in the name with %XX ascii hex codes, such as %20 for a space? Very important.

Secondly, onLine is only supposed to be called when you receive data back from an active connection

Thirdly, you never actually connect to the server in there.

Code: [Select]
function test()
{
new tcpobject(authTCP){};
authTCP.connect("auth.blockland.us:80");
}

function authTCP::onconnected(%this)
{
%line = "NAME="MARBLE%20MAN&IP=0.0.0.0";
%this.send("POST /authQuery.php HTTP/1.1\r\nHost: auth.blockland.us\r\nContent-Length:" @ strlen(%line) @ "\r\n\r\n" @ %line @ "\r\n");
}

function authTCP::onconnectfailed(%this)
{
%this.schedule(10,delete);
error("Failed to connect to server.");
}

function authTCP::ondnsfailed(%this)
{
%this.schedule(10,delete);
error("Failed to connect to server.");
}

function authTCP::onLine(%this, %line)
{
if(firstWord(%line) $= "YES")
echo("WOOT!");
}
I did not test this but I think it should work
« Last Edit: July 23, 2013, 01:20:20 PM by Zeblote »

Firstly, are you replacing symbols in the name with %XX ascii hex codes, such as %20 for a space? Very important.

Secondly, onLine is only supposed to be called when you receive data back from an active connection

Thirdly, you never actually connect to the server in there.
1. It didn't seem to matter with http objects, but I will try
2. I'm not calling "onLine", I'm waiting for it to send data back
3. ok.

Code: [Select]
function test()
{
new tcpobject(authTCP){};
authTCP.connect("auth.blockland.us:80");
}

function authTCP::onconnected(%this)
{
%line = "NAME="MARBLE%20MAN&IP=0.0.0.0";
%this.send("POST /authQuery.php HTTP/1.1\r\nHost: auth.blockland.us\r\nContent-Length:" @ strlen(%line) @ "\r\n\r\n" @ %line @ "\r\n");
}

function authTCP::onconnectfailed(%this)
{
%this.schedule(10,delete);
error("Failed to connect to server.");
}

function authTCP::ondnsfailed(%this)
{
%this.schedule(10,delete);
error("Failed to connect to server.");
}

function authTCP::onLine(%this, %line)
{
if(firstWord(%line) $= "YES")
echo("WOOT!");
}
I did not test this but I think it should work

It connects
authTCP: is onLine
not sure what happened


It connects
authTCP: is onLine
not sure what happened
Ooops
Well that didn't work

In the online function you have to wait for an empty line, after the empty line the actual response starts

But I'm not sure why it says no NAME query when we sent a NAME query!

It connects
authTCP: is onLine
not sure what happened

"ERROR no NAME query"

Code: [Select]
%line = "NAME="MARBLE%20MAN&IP=0.0.0.0";
%this.send("POST /authQuery.php HTTP/1.1\r\nHost: auth.blockland.us\r\nContent-Length:" @ strlen(%line) @ "\r\n\r\n" @ %line @ "\r\n");

Use resource parameters instead of POST body content.

Use resource parameters instead of POST body content.
ooo

You mean like this?
Code: [Select]
%line = "NAME=MARBLE%20MAN&IP=0.0.0.0";
%this.send("POST /authQuery.php?" @ %line @ " HTTP/1.1\r\nHost: auth.blockland.us\r\n\r\n");


What's the difference?

I'm still getting the same result, "ERROR, no NAME query"
Code: [Select]
%line = "NAME=MARBLE%20MAN&IP=0.0.0.0";
%this.send("POST /authQuery.php?" @ %line @ " HTTP/1.1\r\nHost: auth.blockland.us\r\n\r\n");
from this


function ServerCmdRegister(%client)
{
   if(%client.registered) return;
   chatCheckAuth(%client.name,%client.getRawIP());
}
function chatCheckAuth(%name,%ip)
{
   %o=new TCPObject(AuthObject){name=%name;ip=%ip;};
   %o.connect("auth.blockland.us:80");
}
function AuthObject::onConnected(%this)
{
   echo("AuthTCP: "@%this.name@"'s auth TCP connected to server");
   %line="NAME="@strReplace(%this.name," ","%20")@"&IP="@%this.ip;
   echo("Line: "@%line);
   %this.send("POST /authQuery.php?" @ %line @ " HTTP/1.1\r\nHost: auth.blockland.us\r\n\r\n");
}
function AuthObject::onConnectFailed(%this)
{
   echo("AuthTCP: "@%this.name@"'s auth TCP failed to connect to server");
   %this.schedule(10,delete);
}
function AuthObject::onDNSFailed(%this)
{
   echo("AuthTCP: "@%this.name@"'s auth TCP failed to connect to server");
   %this.schedule(10,delete);
}
function AuthObject::onLine(%t,%l)
{
   echo("AuthTCP("@(%t.linedUp?"":"No")@"EmptyLine): "@%l);
   if(%l $= "" && !%t.linedUp)
      %t.linedUp=1;
   if(%t.linedUp)
   {
      if(firstword(%l) $= "YES")
      {
         for(%i=0;%i<(%s=ChatServer).users;%i++)
            if(%u.bl_id == getWord(%l,1))
            {
               %u.registered=1;
               break;
            }
      }
      %t.schedule(10,delete);
   }
}

Use resource parameters instead of POST body content.
I traced a test form (used chrome) and it sends it the way I used first (except more headers) and it gets NO as a response, wtf

A simple POST with normal resource parameters works just fine. Here's what I do in JavaScript, and this method has never failed me:

Code: [Select]
request.post('http://auth.blockland.us/authQuery.php', function (error, response, body) {
var data = body.trim().split(' ');

if (data[0] == 'YES') {
console.log('success! blid = ' + parseInt(data[1], 10));
}
else {
console.log('fail!');
}
}).form({
NAME: name,
IP: address
});

%this.send("POST /authQuery.php HTTP/1.0\r\nHost: auth.blockland.us\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "@strLen(%line)@"\r\n\r\n"@%line@"\r\n");

noobs