Reformat and clean up "net" package

This commit is contained in:
P0nk
2021-09-09 23:26:02 +02:00
parent 69f4580637
commit 6be6ea9927
235 changed files with 3556 additions and 3398 deletions

View File

@@ -36,66 +36,66 @@ import java.sql.Timestamp;
import java.util.Calendar;
/*
*
*
* @author BubblesDev
*/
public final class ReportHandler extends AbstractPacketHandler {
public final void handlePacket(InPacket p, Client c) {
int type = p.readByte(); //01 = Conversation claim 00 = illegal program
String victim = p.readString();
int reason = p.readByte();
String description = p.readString();
if (type == 0) {
if (c.getPlayer().getPossibleReports() > 0) {
if (c.getPlayer().getMeso() > 299) {
c.getPlayer().decreaseReports();
c.getPlayer().gainMeso(-300, true);
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 4));
return;
}
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 2));
return;
}
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, victim + " was reported for: " + description));
addReport(c.getPlayer().getId(), Character.getIdByName(victim), 0, description, null);
} else if (type == 1) {
String chatlog = p.readString();
if (chatlog == null) {
return;
}
if (c.getPlayer().getPossibleReports() > 0) {
if (c.getPlayer().getMeso() > 299) {
c.getPlayer().decreaseReports();
c.getPlayer().gainMeso(-300, true);
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 4));
return;
}
}
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, victim + " was reported for: " + description));
addReport(c.getPlayer().getId(), Character.getIdByName(victim), reason, description, chatlog);
} else {
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, c.getPlayer().getName() + " is probably packet editing. Got unknown report type, which is impossible."));
}
}
public final void handlePacket(InPacket p, Client c) {
int type = p.readByte(); //01 = Conversation claim 00 = illegal program
String victim = p.readString();
int reason = p.readByte();
String description = p.readString();
if (type == 0) {
if (c.getPlayer().getPossibleReports() > 0) {
if (c.getPlayer().getMeso() > 299) {
c.getPlayer().decreaseReports();
c.getPlayer().gainMeso(-300, true);
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 4));
return;
}
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 2));
return;
}
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, victim + " was reported for: " + description));
addReport(c.getPlayer().getId(), Character.getIdByName(victim), 0, description, null);
} else if (type == 1) {
String chatlog = p.readString();
if (chatlog == null) {
return;
}
if (c.getPlayer().getPossibleReports() > 0) {
if (c.getPlayer().getMeso() > 299) {
c.getPlayer().decreaseReports();
c.getPlayer().gainMeso(-300, true);
} else {
c.sendPacket(PacketCreator.reportResponse((byte) 4));
return;
}
}
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, victim + " was reported for: " + description));
addReport(c.getPlayer().getId(), Character.getIdByName(victim), reason, description, chatlog);
} else {
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(6, c.getPlayer().getName() + " is probably packet editing. Got unknown report type, which is impossible."));
}
}
public void addReport(int reporterid, int victimid, int reason, String description, String chatlog) {
Calendar calendar = Calendar.getInstance();
Timestamp currentTimestamp = new java.sql.Timestamp(calendar.getTime().getTime());
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO reports (`reporttime`, `reporterid`, `victimid`, `reason`, `chatlog`, `description`) VALUES (?, ?, ?, ?, ?, ?)")) {
ps.setString(1, currentTimestamp.toGMTString().toString());
ps.setInt(2, reporterid);
ps.setInt(3, victimid);
ps.setInt(4, reason);
ps.setString(5, chatlog);
ps.setString(6, description);
ps.addBatch();
ps.executeBatch();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public void addReport(int reporterid, int victimid, int reason, String description, String chatlog) {
Calendar calendar = Calendar.getInstance();
Timestamp currentTimestamp = new java.sql.Timestamp(calendar.getTime().getTime());
try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO reports (`reporttime`, `reporterid`, `victimid`, `reason`, `chatlog`, `description`) VALUES (?, ?, ?, ?, ?, ?)")) {
ps.setString(1, currentTimestamp.toGMTString());
ps.setInt(2, reporterid);
ps.setInt(3, victimid);
ps.setInt(4, reason);
ps.setString(5, chatlog);
ps.setString(6, description);
ps.addBatch();
ps.executeBatch();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}