- Joined
- Dec 15, 2009
- Messages
- 1,387
- Reaction score
- 236
This is the end of product:
Things you'll need to know before getting started:
1. Java
2. PHP
3. MySQL
3. A brain
4. It's Ducking simple.
--
Let's begin!
1. Open up your MySQL workbench and navigate to your datebase. Next, go to the setting of 'characters'.
2. Insert below codes into MapleClient.java (you might ask where heck to put them? Where? ON WHICH FKING LINE!? Continue to read all the instructions and you'll discover it on your own.)
3. Now we need to call charLoginState() for every time a user log in. Open up PlayerLoggedinHandler.java or similar named file depends of which repacks/source you are using. My case, I'll be using MoopleDev.
4. Now that if a character logs in, the column loginState will be set as 1. However, it will remains as 1, forever because no script is added to define whether the character has logged out or not.
5. Thus, open up MapleClient.java again. Look for player.logOff(); which live under public final void disconnect.
6. Keep in mind, the column will only update to 0 if the player logs out successfully and properly. So what happens if the server shutdown or dc? I'll give you hints.
7. Oh right! Now, we'll need to output the characters which is online. I'll be using MapleBits. It should works on any CMS.
8. Finally, we'll echo out the online players.
Things you'll need to know before getting started:
1. Java
2. PHP
3. MySQL
3. A brain
4. It's Ducking simple.
--
Let's begin!
1. Open up your MySQL workbench and navigate to your datebase. Next, go to the setting of 'characters'.
- Add a new column. Name it as loginState and set default field as 0.
- Apply and that's done. All characters should have a new column.
- Now we need to update that column to define whether a character is logged in or offline.
- 0 = offline and 1 = online.
2. Insert below codes into MapleClient.java (you might ask where heck to put them? Where? ON WHICH FKING LINE!? Continue to read all the instructions and you'll discover it on your own.)
Code:
public void charLoginState(int charLoginNewState) {
try {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE characters SET loginState = ? WHERE id = ?"); //update specific character's row based on character id
ps.setInt(1, charLoginNewState); //charLoginNewState = 0 or 1
ps.setInt(2, player.getId()); //get character id
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
3. Now we need to call charLoginState() for every time a user log in. Open up PlayerLoggedinHandler.java or similar named file depends of which repacks/source you are using. My case, I'll be using MoopleDev.
- Add below codes into that particular file. Look for the proper lines to place the code. READ THROUGH THE ENTIRE CODES AND YOU'LL KNOW.
Code:
c.charLoginState(1); //call for charLoginState() and define charLoginNewState as 1 which is online.
4. Now that if a character logs in, the column loginState will be set as 1. However, it will remains as 1, forever because no script is added to define whether the character has logged out or not.
5. Thus, open up MapleClient.java again. Look for player.logOff(); which live under public final void disconnect.
- Obviously.....
Code:
charLoginState(0); //set column 'loginState' as 0 which is offline.
6. Keep in mind, the column will only update to 0 if the player logs out successfully and properly. So what happens if the server shutdown or dc? I'll give you hints.
- Server.java
- You'll need to figure out where to duplicate the codes and place them on the right spots to get the job done.
7. Oh right! Now, we'll need to output the characters which is online. I'll be using MapleBits. It should works on any CMS.
- So if you're using MapleBits as well, navigate to sidebar.php. Use search if you don't know where it is located.
- However, for those who uses any other CMS, you'll have to locate Server Info and find the appropriate file.
- Look up for Server Info and insert the codes below inside a php tag.
Code:
$onlinePlayers = array(); //create an empty array
$sql = $mysqli->query("SELECT name from characters where loginState = 1"); //pull out characters which fulfill loginState as 1 which is online.
$sonline = $sql->num_rows; //I've replaced the original $sonline from MapleBits so that it works more precisely. What this does is, look up for the number of rows which is online.
if ($sonline != 0) { //if online players not equals 0, the codes will execute.
while ($row = $sql->fetch_assoc()) { //looping through the rows
array_push($onlinePlayers, $row['name']); //pushing online players into array which we just created
}
}
$onlinePlayers = implode(", ", $onlinePlayers); //returns a string from the elements of an array and join each of them with a comma(,)
8. Finally, we'll echo out the online players.
Code:
<?php echo $onlinePlayers; ?>
Attachments
You must be registered for see attachments list
Last edited: