Purpose: To add a really good logging system
Difficulty: 2-3
Assumed Knowledge: Copy/Paste/Brain
Server Base: ShawnZScape v 6 final
Classes Modified: client.java
Procedure
Step 1: Open clinet.java and add these voids:
Code:
public void ChatLog (String text) {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("logs/chatlogs.txt", true));
bw.write(playerName+": "+text);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
misc.println("[Failed to log chat]");
}
}
}
public void YellLog (String text) {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("logs/yellogs.txt", true));
bw.write(playerName+": "+text);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
misc.println([Failed to log yells]");
}
}
}
public void CmdLog (String cmd) {
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter("logs/commandlogs.txt", true));
bw.write(playerName+": "+cmd);
bw.newLine();
bw.flush();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (bw != null) try {
bw.close();
} catch (IOException ioe2) {
misc.println("[Failed to log yells]);
}
}
}
Step 2: search for else if (command.startsWith("yell") && command.length() > 5) and below PlayerHandler.messageToAll = playerName+": "+command.substring(5); or whatever it is on your server add this:
Code:
YellLog(command.substring(5));
then search for case 4: and under:
Code:
inStream.readBytes_reverseA(chatText, chatTextSize, 0);
chatTextUpdateRequired = true;
add this:
Code:
String playerchat = "["+playerName+"]: "+misc.textUnpack(chatText, packetSize-2)+"";
ChatLog(playerchat);
then search for case 103: and under customCommand(playerCommand); add this:
Code:
CmdLog(playerCommand);
Step 3: make 3 txt files called commandlogs yellogs and serverchatlogs in the logs folder if you don't have a logs folder make one and your done save and compile
Credits: me