신고 시스템 추가 솟
MapleAccount.java
public int report(String r, String rip, String v, String re) {
// -2 : GM 신고
// -1 : 존재하지 않는 사용자
// 0 : 자기 자신 신고
Connection con = MYSQL.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String vip = "", vid = null;
int number = 0;
Timestamp time = new Timestamp(new Date().getTime());
try {
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
// 자기 신고 체크
if(v.equals(getPlayer().getName()))
return 0;
// GM 체크
ps = con.prepareStatement("SELECT gm FROM characters where name = ?");
ps.setString(1, v);
rs = ps.executeQuery();
if(rs.next())
if(rs.getInt("gm") != 0)
return -2;
// 캐릭터 존재 확인 여부 작업
ps = con.prepareStatement("SELECT accountid, name FROM characters where name = ?");
ps.setString(1, v);
rs = ps.executeQuery();
if(!rs.next())
return -1;
else
vid = rs.getString("accountid");
// 상대방의 IP를 가져오는 작업
ps = con.prepareStatement("SELECT SessionIP FROM accounts where id = ?");
ps.setString(1, vid);
rs = ps.executeQuery();
if(rs.next())
vip = rs.getString("SessionIP");
// 신고 내용을 데이터베이스에 기록
ps = con.prepareStatement("INSERT INTO report (reporter, reporterIP, vitim, vitimIP, reason, reportTime) VALUES (?, ?, ?, ?, ?, ?)");
ps.setString(1, r);
ps.setString(2, rip);
ps.setString(3, v);
ps.setString(4, vip);
ps.setString(5, re);
ps.setTimestamp(6, time);
ps.executeUpdate();
// 신고 접수번호 반환
ps = con.prepareStatement("SELECT id FROM report where reporter = ? order by id desc");
ps.setString(1, r);
rs = ps.executeQuery();
if(rs.next())
number = rs.getInt("id");
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(con != null)
con = null;
else if(ps != null)
ps.close();
else if(rs != null)
rs.close();
} catch(Exception er) {
er.printStackTrace();
}
}
return number;
}
public int clearReport(int num) {
// -1 : 처리 불가
// 0 : 처리 완료
// 1 : 없는 접수번호
Connection con = MYSQL.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
// 접수번호 존재 확인
ps = con.prepareStatement("SELECT id FROM report where id = ?");
ps.setInt(1, num);
rs = ps.executeQuery();
if(!rs.next())
return 1;
// 신고 처리
ps = con.prepareStatement("DELETE FROM report where id = ?");
ps.setInt(1, num);
ps.executeUpdate();
ps.close();
} catch(Exception e) {
return -1;
}
return 0;
}
public boolean checkReport(String name) {
Connection con = MYSQL.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
// 신고 대상자 체크
ps = con.prepareStatement("SELECT * FROM report where vitim = ?");
ps.setString(1, name);
rs = ps.executeQuery();
if(!rs.next())
return true;
return false;
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(con != null)
con = null;
else if(ps != null)
ps.close();
else if(rs != null)
rs.close();
} catch(Exception er) {
er.printStackTrace();
}
}
return true;
}
public String getNameById(int i) {
String s = "";
Connection con = MYSQL.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
con.setAutoCommit(false);
// Character id -> Name 반환
ps = con.prepareStatement("SELECT name FROM characters where id = ?");
ps.setInt(1, i);
rs = ps.executeQuery();
if(rs.next())
s = rs.getString("name");
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(con != null)
con = null;
else if(ps != null)
ps.close();
else if(rs != null)
rs.close();
} catch(Exception er) {
er.printStackTrace();
}
}
return s;
}
public String showReport(int i) {
Connection con = MYSQL.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 접수번호로 신고 내용 확인
ps = con.prepareStatement("SELECT * FROM report where id = ?");
ps.setInt(1, i);
rs = ps.executeQuery();
if(rs.next()) {
StringBuilder sb = new StringBuilder("접수번호 ");
sb.append(i).append("번");
sb.append("신고자 : ").append(rs.getString("reporter"));
sb.append("\r\n");
sb.append(" 피해자 : ").append(rs.getString("vitim"));
sb.append(" 사유 : ").append(rs.getString("reason"));
return sb.toString();
}
} catch(Exception e) {
e.printStackTrace();
} finally {
try {
if(con != null)
con = null;
else if(ps != null)
ps.close();
else if(rs != null)
rs.close();
} catch(Exception er) {
er.printStackTrace();
}
}
return null;
}
PlayerCommand.java
} else if (splitted[0].equals("@신고")) {
if(splitted.length != 3)
c.getPlayer().dropMessage(5, "신고 유형 : @신고 상대방아이디 신고사유");
else {
int success = c.report(c.getPlayer().getName(), c.getSessionIPAddress().substring(1, c.getSessionIPAddress().length()), splitted[1], splitted[2]);
if(success == -2)
c.getPlayer().dropMessage(5, "운영자를 신고할 수 없습니다.");
else if(success == -1)
c.getPlayer().dropMessage(5, splitted[1] + "님은 존재하지 않는 사용자입니다.");
else if(success == 0)
c.getPlayer().dropMessage(5, "자기 자신을 신고할 수 없습니다.");
else
c.getPlayer().dropMessage(5, splitted[1] + "님에 대한 신고가 완료되었습니다. 접수번호는 " + success + "번 이며, 접수번호가 찍힌 스크린샷을 카페에 올려주세요.");
}
CharCommand.java
} else if (splitted[0].equals("!신고처리")) {
if(splitted.length != 2)
c.getPlayer().dropMessage(5, "신고처리 유형 : !신고처리 접수번호");
else {
int success = c.clearReport(Integer.parseInt(splitted[1]));
if(success == -1)
c.getPlayer().dropMessage(5, "접수번호 " + splitted[1] + "번에 대한 처리에 실패하였습니다.");
else if(success == 0)
c.getPlayer().dropMessage(5, "접수번호 " + splitted[1] + "번에 대한 처리가 완료되었습니다.");
else if (success == 1)
c.getPlayer().dropMessage(5, "접수번호 " + splitted[1] + "번은 존재하지 않는 접수번호 입니다.");
}
} else if (splitted[0].equals("!신고확인")) {
if(splitted.length != 2)
c.getPlayer().dropMessage(5, "신고확인 유형 : !신고확인 접수번호");
else {
c.getPlayer().dropMessage(5, c.showReport(Integer.parseInt(splitted[1])));
}
}
CharLoginHandler.java
if (state == 0) {
if(c.checkReport(c.getNameById(Character_ID))) {
if (!c.deleteCharacter(Character_ID))
state = 1; //actually something else would be good o.o
} else {
state = 0x38;
}
}
c.getSession().write(LoginPacket.deleteCharResponse(Character_ID, state));
[출처] 신고 시스템|작성자 코마

박인성 님의 최근 댓글