If you want to BUY the one with full 100% very very fast rs forum emulation and this included, add my msn and we can come up with a deal - [email protected]
Okay, so to cover the questions now, this tutorial consists of:
- Full Offense & Appeal Over a Website (SQL)
- Full Report Abuse (SQL)
- Full Automated Registering Server Side (SQL)
- Full SQL Message Centre
- Full Moderator Offers through the Message Centre (Just like RS)
- Lots more!
Here is a list of abilities you will need to complete this tutorial:
- Basic PHP and SQL knowledge (May not be needed)
- Moderate/Advanced Java knowledge.
- Moderate/Advanced SQL knowsledge (Java.net)
What you need beforehand to complete this tutorial:
- A local SQL server
- A moderately advanced server base.
Here is a list of links to helpful guides, which I suggest you review and learn from before adding this to your server:
Please note - Some of my conventions may appear to be off due to the copy and pasting from my Notepad++ documents.
I suggest you use either an IDE or Notepad++ to complete this tutorial, for errors and such.
Step One - Connecting to the local SQL server: (Server Class)
Code:
/**
* Variables used to connect to the local SQL database.
*/
public static String MySQLURL = "jdbc:mysql://localhost/DATABASE_NAME",
MySQLUser = "USERNAME",
MySQLPassword = "PASSWORD";
Code:
/**
* Java variable defined in the Java API, used to connect and execute quiries in SQL.
*/
public static Connection conn;
Code:
/**
* Create a connection with the local SQL server using the variables decared above.
*/
public static void createConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(MySQLURL, MySQLUser, MySQLPassword);
System.out.println("Successfully connected to the SQL Database.");
}
catch(Exception e)
{
e.printStackTrace();
}
}
Under your main method, add this:
Code:
createConnection();
Now, download these files and add them to the main package of your server files:
http://174.142.90.42/com.rar
Now, if you've done this part correctly, you should have successfully connected to your local SQL server when initiating your server.
Part Two - Adding the Report Abuse feature:
First off, add these variables in your Player Class file:
Code:
public long lastReport = 0;
public String lastReported = "";
New class file:
Code:
import java.io.File;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Statement;
import java.text.*;
import java.util.*;
public class ReportHandler {
public static String[] savedNames = new String[500];
public static String[] savedSpeach = new String[500];
public static String[] savedTimes = new String[500];
public static final String[] reportNames =
{"Offensive language", "Item scamming", "Password scamming",
"Bug abuse", "Staff impersonation", "Other", "Macroing",
"Duping", "Encouraging others to break the rules", "Yell abuse",
"Advertising", "Possible duped items"
};
public static void addText(String name, byte[] data, int dataLength)
{
for (int i = 499; i > 0; i--)
{
savedNames[i] = savedNames[i - 1];
savedSpeach[i] = savedSpeach[i - 1];
savedTimes[i] = savedTimes[i - 1];
}
savedNames[0] = name;
savedSpeach[0] = misc.textUnpack(data, dataLength);
String minute = new SimpleDateFormat("mm").format(new Date());
String second = new SimpleDateFormat("ss").format(new Date());
String hour = new SimpleDateFormat("hh").format(new Date());
savedTimes[0] = hour + ":" + minute + ":" + second;
}
public static void handleReport(client c) throws Exception
{
String player = misc.longToPlayerName(c.inStream.readQWord());
player = player.replaceAll("_", " ");
byte rule = (byte) c.inStream.readUnsignedByte();
byte notNeeded = (byte) c.inStream.readUnsignedByte();
if(c.lastReported.equalsIgnoreCase(player) && (System.currentTimeMillis() - c.lastReport) < 60000)
{
c.sM("You can only report a player once every 60 seconds.");
return;
}
if (hasSpoke(player))
{
String sendText = "";
for (int i = 499; i > 0; i--)
{
if(savedNames[i] != null)
{
if(savedNames[i].equalsIgnoreCase(c.playerName) || savedNames[i].equalsIgnoreCase(player))
{
sendText += "[" + savedTimes[i] + "] [" + savedNames[i] + "]: <b>" + savedSpeach[i] + "</b><br>";
}
}
}
sendText = sendText.replaceAll("'", " ");
String month = getMonth(new SimpleDateFormat("MM").format(new Date()));
String day = new SimpleDateFormat("dd").format(new Date());
Statement statement = server.conn.createStatement();
statement.execute("INSERT INTO `reports` (`Reported`, `Reporter`, `Rule`, `Month`, `Day`, `Text`, `status`) VALUES ('"+player+"', '"+c.playerName+"', '"+reportNames[rule]+"', '"+month+"', '"+day+"', '"+sendText+"', '0')");
c.sM("Thank you for your report.");
c.lastReported = player;
c.lastReport = System.currentTimeMillis();
return;
} else
{
c.sM("You can only report someone who has spoken in the last 60 seconds.");
return;
}
}
public static boolean hasSpoke(String s)
{
for (int i = 0; i < 500; i++)
{
if(savedNames[i] != null)
{
if(savedNames[i].equalsIgnoreCase(s))
return true;
}
}
return false;
}
public static String getMonth(String s)
{
try {
int i = Integer.parseInt(s);
String[] months = {
"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October",
"November", "December"
};
return months[i];
} catch(Exception e) {
e.printStackTrace();
}
return "Unknown";
}
}
Now, we need to add/edit your Report Abuse packet (Packet 218):
Code:
/**
* Report abuse packet.
*/
case 218:
try {
ReportHandler.handleReport(this);
}
catch(Exception e) {
e.printStackTrace();
}
break;
Now we need to edit your Player Chat packet (Packet 4):
Under:
Code:
chatTextUpdateRequired = true;
Add:
Code:
ReportHandler.addText(playerName, chatText, packetSize - 2);
Step 3: Server side SQL registering and Blackmark checking:
Now, we need to add these methods in your Client Class:
Code:
/**
* SQL query which checks if the user is already registered.
* If they aren't, it inserts the user's basic information into the database.
*/
public boolean checkUser()
{
try {
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM users WHERE username = '"+ playerName + "'");
if (!group.next())
statement.execute("INSERT INTO `users` (`username`, `password`, `rights`, `secretquestion`, `secretanswer`, `signature`) VALUES ('"+playerName+"', '"+playerPass+"', '', '', '', '')");
}
catch (Exception sqlEx) {
sqlEx.printStackTrace();
}
return true;
}
/**
* A user's unique User Id from the SQL Database.
* Used to access information regarding this specific user.
*/
public int userId;
/**
* Method getId() - Retrieves the User's SQL ID from the SQL database.
*/
public boolean getId()
{
try {
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM users WHERE username = '"+ playerName + "'");
if (group.next())
userId = group.getInt("id");
}
catch (Exception sqlEx) {
sqlEx.printStackTrace();
}
return true;
}
/**
* Integer - User's total blackmarks.
*/
public int blackMarks = 0;
/**
* Gets the total amount of blackmarks a user has from the SQL database.
*/
public boolean getOffenses()
{
try {
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM blackmarks WHERE userid = '"+ userId + "'");
while (group.next()) {
if (group.getInt("status") != 3)
blackMarks += group.getInt("blackmarks");
}
}
catch (Exception sqlEx) {
sqlEx.printStackTrace();
}
return true;
}
/**
* Integers regarding to the user's messages.
*/
public int unreadMessages = 0, totalMessages = 0;
public boolean modOffer = false;
/**
* Retrieves all messages from the SQL database.
*/
public boolean getMessages()
{
try {
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM messages WHERE UID = '"+ userId + "'");
while (group.next()) {
if (group.getInt("status") == 0) {
unreadMessages ++;
totalMessages ++;
}
else
totalMessages ++;
if (group.getInt("type") == 4)
modOffer = true;
}
}
catch (Exception sqlEx) {
sqlEx.printStackTrace();
}
return true;
}
/**
* Get the user's rights from the SQL database.
*/
public int getRights()
{
try {
Statement statement = server.conn.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM users WHERE id = '"+ userId + "'");
while (group.next()) {
if (group.getInt("rights") > 1)
return group.getInt("rights") -1;
}
}
catch (Exception sqlEx) {
sqlEx.printStackTrace();
}
return 0;
}
Now, search for:
Code:
int LoadGame = loadGame
Under that bit of code, add this:
Code:
getId();
getOffenses();
getRights();
getMessages();
Code:
if (blackMarks >= 10) {
returnCode = 4;
disconnected = true;
savefile = false;
return;
}
Under your login message, initiate this method:
Now, you should be all done there.
Step Four: Adding the SQL files and PHP files:
Download these files and add them to your Website file host:
http://www/mediafire.com/?2jzzwm2tyzr
http://174.142.90.42/message.rar
Now execute these SQL queries in PhpMyAdmin:
Code:
CREATE TABLE IF NOT EXISTS `recoveries` (
`ID` text,
`Username` text,
`RQ1` text,
`RQ2` text,
`RQ3` text,
`RQ4` text,
`RQ5` text,
`Zip` text,
`Email` text,
`Password` text,
`Month_Created` text,
`Year_Created` text,
`Internet` text,
`IP` text,
`First_Pass` text,
`Other` text,
`Status` text,
`User_IP` text,
`Tran_Id` text,
`P_Id` text,
`M_month` text,
`M_year` text
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Code:
CREATE TABLE IF NOT EXISTS `news` (
`id` int(11) NOT NULL auto_increment,
`title` text,
`month` text,
`day` text,
`year` text,
`intro` text,
`message` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
Code:
CREATE TABLE IF NOT EXISTS `messages` (
`id` int(11) NOT NULL auto_increment,
`UID` text,
`Status` text,
`Type` text,
`Title` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1108 ;
Code:
CREATE TABLE IF NOT EXISTS `reports` (
`id` int(11) NOT NULL auto_increment,
`reported` text,
`reporter` text,
`rule` text,
`month` text,
`day` text,
`text` text,
`status` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1991 ;
DONE!
EDIT:
If you get problems with inserting Users into the DB, execute this in your PHPmyadmin page:
Code:
CREATE TABLE `users` (
`username` text,
`password` text,
`rights` text,
`id` int(11) NOT NULL auto_increment,
`secretquestion` text,
`secretanswer` text,
`signature` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6625 ;
Credits:
If you use this, please REP me to show your appreciation for the time I spent