Well, you use TCPObjects to connect to the internet. Here is an example of creating one.
new tcpObject(blocklandConnect);
Now that we have the object, we need something to connect to. Lets say Blockland, for instance.
$connectionAddress = "blockland.us:80";
We define this as a global variable so it can be used again later.
Now, lets define some basic functions for our tcp object. We like to have some output as to how its going.
Let's start with the ::onConnect method. It has no arguments.
function blocklandConnect::onConnect()
{
echo("blocklandConnect: Connected!");
}
This is for whenever a connection sucessfully connects to the server. echo("string"); outputs whatever is in that string to the console, which is useful for knowing when things happen, without doing anything complicated. We also define functions using the syntax
function functionName(%argument,%arguments,%argumenta)
{
//stuffHere
}
Next, we will do ::onConnectFailed(). It's when it fails to connect to a server for any reason. I believe it has no arguments.
function blocklandConnect::onConnectFailed()
{
echo("blocklandConnect: Connection FAILED!");
}
One last thing thats also good to know, ::onLine(%line). %line is an argument because we receive data back from the server.
function blocklandConnect::onLine(%line)
{
echo("BLC: " @ %line);
}
Servers usually send back headers when dealing with web pages.
There is also ::onTimeout for when a connection times out, and ::onDisconnect for whenever it disconnects.
Now, let's start connecting.
blocklandConnect.connect($connectionAdress);
This connects us to the address we defined as $connectionAdress. You should receive a message in console saying "blocklandConnect: Connected!". Now, we are connected. We should send something to the server. We do this by calling the .send() method on it like .connect(). After taking a look at RTB, I found that they sent
"GET /blockland/rtbModServer.php?c=GETFILEDL&n="@urlEnc($Pref::Player::NetName)@"&arg1="@%this.SO.file_id@" HTTP/1.1\r\nHost: returntoblockland.com\r\nUser-Agent: Torque/1.0\r\n\r\n"
Now, this is a bit more than we need, so lets trim it down. GET is something that tells the server that we're requesting a page. There is aditionally POST, and probably others. I do not know, I don't work with TCPObjects often. Next we see /blockland/rtbModServer.php?c=GETFILEDL&n="@urlEnc($Pref::Player::NetName)@"&arg1="@%this.SO.file_id@" . Well, this is the file we are requesting. You could basically just say /textfile.txt if you wanted to request a text file. Next is some stuff I don't know what to call, really. In this case, we use HTTP/1.1\r\nHost: - I know that all of this is nessecary, and has to do with something important. Where you see returntoblockland.com, you replace with the host. From what we're working on, we use blockland.us because we're connected to blockland.us. Next is \r\nUser-Agent: Torque/1.0\r\n\r\n - we use this to tell our User-Agent and also have more escape characters. I'm not one to say what the escape characters are, but you can leave this part alone. Now, lets go make our connection string.
$connectionString = "GET /index.php HTTP/1.1\r\nHost: blockland.us\r\nUser-Agent: Torque/1.0\r\n\r\n";
If you listened to what I said, you should understand the important parts you should change. Now, this sends a request for the page "index.php" - the main page. You then use
blocklandConnect.send($connectionString);
to send the request for the page. The server then returns the stuff (which can also be based on user agent, useful) in console from the onLine() method. Now that we have that stuff, we can disconnect.
blocklandConnect.disconnect();
If you need any additional clarification, help, or anything to do with this, just ask. I might be wrong on certain things, so do ask for help from other people like Ephialtes, as they may be more knowledgeable to this.
You should be knowledgeable enough with the PHP server-side code to not need help (your site seems good). Also, don't be afraid to experiment. You may mess something up, but that's just how you should learn - from your mistakes. I really think you may know alot of this stuff, and some stuff you can do. Best of luck with this,
Azimuth