I am using DeltaClean 2.0
(It's to fuck around with!) but I cannot find where in God's green earth to add the Code.
I guessed in Server.java, at the beginning. This is my error:
Code:
Compiling Server
.\com\rs2\Server.java:65: cannot find symbol
symbol : variable connection
location: class com.rs2.Server
DataInputStream input = new DataInputStr
eam(connection.getInputStream());//Gets the input stream from the socket(Allows
the server to read)
^
.\com\rs2\Server.java:66: cannot find symbol
symbol : variable connection
location: class com.rs2.Server
DataOutputStream output = new DataOutput
Stream(connection.getOutputStream());//Gets the output stream for the socket(All
ows the server to write)
^
.\com\rs2\Server.java:69: cannot find symbol
symbol : variable connection
location: class com.rs2.Server
ServerEngine.addConnection(connection);//Handles client connecti
on. REPLACE WITH HOWEVER YOUR SERVER HANDLES LOGINS.
^
.\com\rs2\Server.java:69: cannot find symbol
symbol : variable ServerEngine
location: class com.rs2.Server
ServerEngine.addConnection(connection);//Handles client connecti
on. REPLACE WITH HOWEVER YOUR SERVER HANDLES LOGINS.
^
.\com\rs2\Server.java:71: cannot find symbol
symbol : method getPlayersOnline()
location: class com.rs2.GameEngine
output.writeUTF(String.valueOf(GameEngine.getPlayersOnline()));/
/UTF because that's the way php reads and writes data.
^
.\com\rs2\Server.java:74: cannot find symbol
symbol : variable connection
location: class com.rs2.Server
connection.close();
^
.\com\rs2\Server.java:78: cannot find symbol
symbol : variable connection
location: class com.rs2.Server
connection.close();
^
7 errors
Compiling completed.
Press any key to continue . . .
THIS IS THE TUTORIAL ON DOING IT THAT I USED:
Okay, now a while ago, i came to the realization that there had to have been an easier way to get the players online, without creating an ambiguous structure in MySQL or an extraneous file on some ftp server somewhere. So I thought, why not pull the the amount of players directly from the server? So I did just that.
First, you need to add some php to your webcode. Now, go into the page you'd like to display the number of characters online(commonly index.php), and add this php code:
Code:
<?php
$host = "yourserversiphere";#The IP of your
$port = 43594;#The Port your server listens to
$socket = fsockopen($host, $port);#Connect to the server
fputs($socket, pack("i", 15));#Write byte 15
$players = substr(fgets($socket, 128), 2);#Read the data sent by the server
fclose($socket);#Close the connection
echo "There are " . $players . " players online";
?>
Next, in the class where you handle socket connections(Probably somewhere along the lines of SocketListener, or LoginHandler, or ConnectionManger), you should see something that looks like this:
Code: [Select]
Socket connection = serverSocket.accept();
Under that, add this:
Code:
DataInputStream input = new DataInputStream(connection.getInputStream());//Gets the input stream from the socket(Allows the server to read)
DataOutputStream output = new DataOutputStream(connection.getOutputStream());//Gets the output stream for the socket(Allows the server to write)
int connectionType = input.readByte();//Type of connection
And don't forget to import java.io.*;
Now, most clients send byte 14 first, over all other data sent. So we'll use this to our advantage. Next add this right below:
Code:
if(connectionType == 14) {
ServerEngine.addConnection(connection);//Handles client connection. REPLACE WITH HOWEVER YOUR SERVER HANDLES LOGINS.
} else if(connectionType == 15) {//Handle request from webpage
output.writeUTF(String.valueOf(GameEngine.getPlayersOnline()));//UTF because that's the way php reads and writes data.
input.close();
output.close();
connection.close();
} else {//Invalid connection
input.close();
output.close();
connection.close();
}
Now, whenever anyone loads the page, it requests the data from the server, and the web page reads that data and displays it. Hope you enjoyed it. I know that there may be some slight discrepancies in the tutorial, and i will fix it tomorrow. I'm going on 6 days without sleep at the moment.